From cd3cb01f43e54ccfb177a55ed5a0d06f21f27b46 Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Tue, 17 Dec 2024 23:17:21 -0500 Subject: [PATCH] Bugfix --- changelog.md | 3 +++ mod.json | 2 +- src/Callbacks.cpp | 1 + src/UIModding.cpp | 32 ++++++++++++++++++++++++++++++++ src/nodes/MenuLayer.h | 9 +++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 9f91b7a..5b18ada 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## 1.7.3 +- Fix an issue with MenuLayer::onPlay callbacks not working because apparently it is a meanie head and wanted to be rude :( + ## 1.7.2 - Add the ability to run certain button callbacks anywhere diff --git a/mod.json b/mod.json index dc49aa2..df5260f 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "android": "2.2074", "mac": "2.2074" }, - "version": "v1.7.2", + "version": "v1.7.3", "id": "alphalaneous.happy_textures", "name": "Happy Textures :3", "developer": "Alphalaneous", diff --git a/src/Callbacks.cpp b/src/Callbacks.cpp index f9d1ef2..71d20c0 100644 --- a/src/Callbacks.cpp +++ b/src/Callbacks.cpp @@ -21,6 +21,7 @@ void Callbacks::generateAll() { CCMenuItemSpriteExtra* Callbacks::getDummyButton() { if (!m_dummyButton) { m_dummyButton = CCMenuItemSpriteExtra::create(CCSprite::create(), nullptr, nullptr); + m_dummyButton->setUserObject("dummy"_spr, CCBool::create(true)); } return m_dummyButton; } diff --git a/src/UIModding.cpp b/src/UIModding.cpp index d8f9ee3..24aa080 100644 --- a/src/UIModding.cpp +++ b/src/UIModding.cpp @@ -142,6 +142,38 @@ void UIModding::runAction(CCNode* node, matjson::Value attributes) { } #endif } +std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) { + HMODULE mod; + + if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(addr), &mod) + ) { + mod = nullptr; + } + + wchar_t buffer[MAX_PATH]; + std::string const module_name = (!mod || !GetModuleFileNameW(mod, buffer, MAX_PATH)) ? "Unknown" : std::filesystem::path(buffer).filename().string(); + + if(module) return fmt::format("{} + {:#x}", module_name, addr - reinterpret_cast(mod)); + return fmt::format("{:#x}", addr - reinterpret_cast(mod)); +} + +std::string formatAddressIntoOffset(uintptr_t addr, bool module) { + static std::unordered_map> formatted; + auto it = formatted.find(addr); + if (it != formatted.end()) { + if(module) return it->second.first; + else return it->second.second; + } else { + 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; + } +} void UIModding::runCallback(CCNode* node, matjson::Value attributes) { if (attributes.contains("callback")) { diff --git a/src/nodes/MenuLayer.h b/src/nodes/MenuLayer.h index 5a5b112..43f4301 100644 --- a/src/nodes/MenuLayer.h +++ b/src/nodes/MenuLayer.h @@ -12,6 +12,15 @@ class $modify(MyMenuLayer, MenuLayer) { (void) self.setHookPriority("MenuLayer::init", INT_MIN/2-1); } + void onPlay(CCObject* obj) { + if (static_cast(obj)->getUserObject("dummy"_spr)) { + CCDirector::get()->pushScene(CCTransitionFade::create(0.5, LevelSelectLayer::scene(0))); + } + else { + MenuLayer::onPlay(obj); + } + } + bool init() { UIModding::get()->finishedLoad = true; if (!MenuLayer::init()) return false;