Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Dec 18, 2024
1 parent 6ce496e commit cd3cb01
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 32 additions & 0 deletions src/UIModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(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<uintptr_t>(mod));
return fmt::format("{:#x}", addr - reinterpret_cast<uintptr_t>(mod));
}

std::string formatAddressIntoOffset(uintptr_t addr, bool module) {
static std::unordered_map<uintptr_t, std::pair<std::string, std::string>> 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")) {
Expand Down
9 changes: 9 additions & 0 deletions src/nodes/MenuLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class $modify(MyMenuLayer, MenuLayer) {
(void) self.setHookPriority("MenuLayer::init", INT_MIN/2-1);
}

void onPlay(CCObject* obj) {
if (static_cast<CCNode*>(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;
Expand Down

0 comments on commit cd3cb01

Please sign in to comment.