diff --git a/src/pages/Attributes.cpp b/src/pages/Attributes.cpp index c5e7bef..bd3f50a 100644 --- a/src/pages/Attributes.cpp +++ b/src/pages/Attributes.cpp @@ -63,11 +63,12 @@ void DevTools::drawNodeAttributes(CCNode* node) { std::string addr = "N/A"; ImGui::Text("CCMenuItem selector: %s", addr.c_str()); } else { - const auto addr = formatAddressIntoOffset(addresser::getNonVirtual(selector)); + const auto addr = formatAddressIntoOffset(addresser::getNonVirtual(selector), true); ImGui::Text("CCMenuItem selector: %s", addr.c_str()); ImGui::SameLine(); if (ImGui::Button(U8STR(FEATHER_COPY " Copy##copymenuitem"))) { - clipboard::write(addr); + const auto addrNoModule = formatAddressIntoOffset(addresser::getNonVirtual(selector), false); + clipboard::write(addrNoModule); } } } diff --git a/src/platform/Android.cpp b/src/platform/Android.cpp index a70fbfb..288f683 100644 --- a/src/platform/Android.cpp +++ b/src/platform/Android.cpp @@ -6,9 +6,10 @@ using namespace geode::prelude; #include "utils.hpp" -std::string formatAddressIntoOffsetImpl(uintptr_t addr) { +std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) { if (addr > base::get() && addr - 0x1000000 < base::get()) - return fmt::format("libcocos2d.so + {:#x}", addr - base::get()); + if(module) return fmt::format("libcocos2d.so + {:#x}", addr - base::get()); + else return fmt::format("{:#x}", addr - base::get()); return fmt::format("{:#x}", addr); } diff --git a/src/platform/Mac.mm b/src/platform/Mac.mm index 77f13a8..bde8b4d 100644 --- a/src/platform/Mac.mm +++ b/src/platform/Mac.mm @@ -70,7 +70,7 @@ return ghc::filesystem::path(imageName).filename().string(); } -std::string formatAddressIntoOffsetImpl(uintptr_t addr) { +std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) { auto image = imageFromAddress(reinterpret_cast(addr)); std::string imageName; uintptr_t base; @@ -82,7 +82,8 @@ imageName = getImageName(image); } - return fmt::format("{} + {:#x}", imageName, addr - base); + if(module) return fmt::format("{} + {:#x}", imageName, addr - base); + else return fmt::format("{:#x}", addr - base); } #endif \ No newline at end of file diff --git a/src/platform/Win32.cpp b/src/platform/Win32.cpp index 951f92a..e82871c 100644 --- a/src/platform/Win32.cpp +++ b/src/platform/Win32.cpp @@ -49,7 +49,7 @@ class $modify(CCEGLView) { #include "utils.hpp" -std::string formatAddressIntoOffsetImpl(uintptr_t addr) { +std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) { HMODULE mod; if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | @@ -62,7 +62,8 @@ std::string formatAddressIntoOffsetImpl(uintptr_t addr) { wchar_t buffer[MAX_PATH]; std::string const module_name = (!mod || !GetModuleFileNameW(mod, buffer, MAX_PATH)) ? "Unknown" : std::filesystem::path(buffer).filename().string(); - return fmt::format("{} + {:#x}", module_name, addr - reinterpret_cast(mod)); + if(module) return fmt::format("{} + {:#x}", module_name, addr - reinterpret_cast(mod)); + return fmt::format("{:#x}", addr - reinterpret_cast(mod)); } #endif \ No newline at end of file diff --git a/src/platform/utils.cpp b/src/platform/utils.cpp index 9362d2d..2aca9ae 100644 --- a/src/platform/utils.cpp +++ b/src/platform/utils.cpp @@ -2,14 +2,18 @@ #include -std::string formatAddressIntoOffset(uintptr_t addr) { - static std::unordered_map formatted; +std::string formatAddressIntoOffset(uintptr_t addr, bool module) { + static std::unordered_map> formatted; auto it = formatted.find(addr); if (it != formatted.end()) { - return it->second; + if(module) return it->second.first; + else return it->second.second; } else { - auto const txt = formatAddressIntoOffsetImpl(addr); - formatted.insert({ addr, txt }); - return txt; + auto const txt = formatAddressIntoOffsetImpl(addr, true); + auto const txtNoModule = formatAddressIntoOffsetImpl(addr, false); + auto const pair = std::make_pair(txt, txtNoModule); + formatted.insert({ addr, pair }); + if(module) return pair.first; + else return pair.second; } } \ No newline at end of file diff --git a/src/platform/utils.hpp b/src/platform/utils.hpp index 568ea6b..6653d53 100644 --- a/src/platform/utils.hpp +++ b/src/platform/utils.hpp @@ -3,6 +3,6 @@ #include #include -std::string formatAddressIntoOffset(uintptr_t addr); +std::string formatAddressIntoOffset(uintptr_t addr, bool module); -std::string formatAddressIntoOffsetImpl(uintptr_t addr); +std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module);