This repository was archived by the owner on Oct 7, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 39
Example mod
Oleksandr Nemesh edited this page Apr 18, 2024
·
1 revision
Here's a modified example mod for Geode with some custom API used to change the hook behaviour.
#include<Geode/Geode.hpp>usingnamespacegeode::prelude;
#defineOPENHACK_OPTIONAL
#include<prevter.openhack/api/openhack.hpp>staticbool s_addCustomButton = false;
class $modify(MenuLayer) {
boolinit() {
if (!MenuLayer::init()) {
returnfalse;
}
// Return early if the custom button is disabledif (!s_addCustomButton) {
returntrue;
}
// Everything else is the same as in example geode modauto myButton = CCMenuItemSpriteExtra::create(
CCSprite::createWithSpriteFrameName("GJ_likeBtn_001.png"),
this,
menu_selector(MyMenuLayer::onMyButton)
);
auto menu = this->getChildByID("bottom-menu");
menu->addChild(myButton);
myButton->setID("my-button"_spr);
menu->updateLayout();
returntrue;
}
};
$execute {
usingnamespaceopenhack;// for convenience// Check if OpenHack is actually loadedif (!isLoaded()) return;
// Register our own custom windowui::createWindow("My cool feature", []() {
if (ui::button("Show alert")) {
FLAlertLayer::create(
"OpenHack API",
"Hello from my custom mod!",
"OK"
)->show();
}
if (ui::checkbox("Add custom button", &s_addCustomButton)) {
FLAlertLayer::create(
"Custom Button",
fmt::format("Custom button is now {}!", s_addCustomButton ? "enabled" : "disabled").c_str(),
"OK"
)->show();
}
});
}