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 24
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>
using namespace geode::prelude;
#define OPENHACK_OPTIONAL
#include <prevter.openhack/api/openhack.hpp>
static bool s_addCustomButton = false;
class $modify(MenuLayer) {
bool init() {
if (!MenuLayer::init()) {
return false;
}
// Return early if the custom button is disabled
if (!s_addCustomButton) {
return true;
}
// Everything else is the same as in example geode mod
auto 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();
return true;
}
};
$execute {
using namespace openhack; // for convenience
// Check if OpenHack is actually loaded
if (!isLoaded()) return;
// Register our own custom window
ui::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();
}
});
}