Skip to content

Commit 5b9943e

Browse files
Memory viewer overhaul (#46)
* better rtti i think * Update mod.json * bump actions * man * thanks capeling * I think I'm done * ye ok * finally * AAAAAAAAAAAAAAAAAAAAA * I hope this works * Update Memory.cpp * grand finale * forgot that include * unbump version (I'll let the devs do it) * crackpot idea * that didn't work * test my stuff out * revert * recomp * typeinfo_cast moment * fix copy pointer button * copy as pointer button * remove warnings i think * add back includes because maybe macos needs them * we're done now * scaled back * one more thing * amazing * bump bump * jesse we need to merge * please i need this * nuh uh * i'll try this for a few * okay now put it back * uhhh * ok --------- Co-authored-by: Cvolton <[email protected]>
1 parent 6aac3dc commit 5b9943e

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ${{ matrix.config.os }}
3131

3232
steps:
33-
- uses: actions/checkout@v3
33+
- uses: actions/checkout@v4
3434

3535
- name: Build the mod
3636
uses: geode-sdk/build-geode-mod@main
@@ -47,7 +47,7 @@ jobs:
4747
- uses: geode-sdk/build-geode-mod/combine@main
4848
id: build
4949

50-
- uses: actions/upload-artifact@v3
50+
- uses: actions/upload-artifact@v4
5151
with:
5252
name: Build Output
5353
path: ${{ steps.build.outputs.build-output }}

src/pages/Memory.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@ void DevTools::drawMemory() {
285285

286286
static char buffer[256] = {'0', '\0'};
287287
bool changed = ImGui::InputText("Addr", buffer, sizeof(buffer));
288+
ImGui::SameLine();
289+
if (ImGui::Button("Paste")) {
290+
auto str = string::trim(clipboard::read());
291+
auto stripped = false;
292+
if (string::startsWith(str, "0x")) {
293+
str = str.substr(2);
294+
stripped = true;
295+
}
296+
if (std::all_of(str.begin(), str.end(), [](char c) {
297+
return std::isxdigit(c);
298+
})) {
299+
if (stripped) str = "0x" + str;
300+
std::memcpy(buffer, str.c_str(), str.size() + 1);
301+
changed = true;
302+
}
303+
}
288304
static int size = 0x100;
289305
changed |= ImGui::DragInt("Size", &size, 16.f, 0, 0, "%x");
290306
if (size < 4) {
@@ -327,11 +343,26 @@ void DevTools::drawMemory() {
327343
RttiInfo info(ptr.read_ptr());
328344
auto name = info.class_name();
329345
if (name) {
330-
texts.push_back(fmt::format("[{:04x}] {}", offset, *name));
331-
textSaving.push_back(fmt::format("{:x}: p {}", offset, *name));
332-
// if (typeinfo_cast<CCArray*>(ptr.as_ptr())) {
333-
// // look at types..
334-
// }
346+
auto voidPtr = reinterpret_cast<void**>(ptr.as_ptr());
347+
auto objectPtr = reinterpret_cast<CCObject*>(*voidPtr);
348+
auto formattedPtr = fmt::ptr(*voidPtr);
349+
if (auto arr = typeinfo_cast<CCArray*>(objectPtr)) {
350+
texts.push_back(fmt::format("[{:04x}] cocos2d::CCArray ({}, size {}, data {})", offset, formattedPtr, arr->count(), fmt::ptr(arr->data->arr)));
351+
textSaving.push_back(fmt::format("{:x}: a cocos2d::CCArray ({}, size {}, data {})", offset, formattedPtr, arr->count(), fmt::ptr(arr->data->arr)));
352+
} else if (auto dict = typeinfo_cast<CCDictionary*>(objectPtr)) {
353+
texts.push_back(fmt::format("[{:04x}] cocos2d::CCDictionary ({}, size {}, data {})", offset, formattedPtr, dict->count(), fmt::ptr(dict->m_pElements)));
354+
textSaving.push_back(fmt::format("{:x}: d cocos2d::CCDictionary ({}, size {}, data {})", offset, formattedPtr, dict->count(), fmt::ptr(dict->m_pElements)));
355+
} else {
356+
std::string nodeID;
357+
auto type = "p";
358+
if (auto node = typeinfo_cast<CCNode*>(objectPtr)) {
359+
auto foundID = node->getID();
360+
if (!foundID.empty()) nodeID = fmt::format(" \"{}\"", foundID);
361+
type = "n";
362+
}
363+
texts.push_back(fmt::format("[{:04x}] {} ({}){}", offset, *name, formattedPtr, nodeID));
364+
textSaving.push_back(fmt::format("{:x}: {} {} ({}){}", offset, type, *name, formattedPtr, nodeID));
365+
}
335366
} else if (auto maybeStr = findStdString(ptr); maybeStr) {
336367
auto str = maybeStr->substr(0, 30);
337368
// escapes new lines and stuff for me :3

src/pages/Settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ void DevTools::drawSettings() {
200200

201201
ImGui::TextWrapped(
202202
"Running Geode %s, DevTools %s",
203-
Loader::get()->getVersion().toVString().c_str(),
204-
Mod::get()->getVersion().toVString().c_str()
203+
Loader::get()->getVersion().toVString().c_str(),
204+
Mod::get()->getVersion().toVString().c_str()
205205
);
206206

207207
if (ImGui::Button("Reset Layout")) {

0 commit comments

Comments
 (0)