Skip to content

Commit f0aa33a

Browse files
committed
hook tweaks
1 parent fd56adf commit f0aa33a

File tree

9 files changed

+118
-66
lines changed

9 files changed

+118
-66
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# for clangd users
1+
# for our beloved clangd users
22
BasedOnStyle: Google
33

44
NamespaceIndentation: All

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
- name: Send Discord webhook
4242
if: ${{ steps.check-discord.outputs.has-webhook == 'true' }}
43-
uses: BlueWitherer/mod-discord-webhooks/fabric@main
43+
uses: BlueWitherer/mod-discord-webhooks/geode@main
4444
with:
4545
webhook-url: ${{ steps.check-discord.outputs.webhook-url }}
4646
content: "-# <@&1478754024240054292>" # release alert role
@@ -57,4 +57,4 @@ jobs:
5757
- name: Publish to Geode
5858
uses: hiimjasmine00/release-geode-mod/publish@main
5959
with:
60-
token: ${{ secrets.GITHUB_TOKEN }}
60+
token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [<img src="logo.png" width="25" alt="The mod's logo." />](https://www.geode-sdk.org/mods/arcticwoof.horribleideas) Horrible Ideas
2-
A plethora of ways to ruin your gaming experience...
2+
A plethora of ways to ruin your experience...
33

44
> [<img alt="Latest Version" src="https://img.shields.io/github/v/release/DumbCaveSpider/HorribleIdeas?include_prereleases&sort=semver&display_name=release&style=for-the-badge&logo=github&logoColor=ffffff&label=Version">](../../releases/) [<img alt="Code License" src="https://img.shields.io/github/license/DumbCaveSpider/HorribleIdeas?style=for-the-badge&logo=gnu&logoColor=ffffff&label=License">](LICENSE.md)
55
>
@@ -8,7 +8,7 @@ A plethora of ways to ruin your gaming experience...
88
---
99

1010
## About
11-
This silly lil' mod adds a funny mod menu filled to the brim with **over 30 crazy troll options** to mes around with! Spice up your gameplay by adding some truly terrible features to absolutely wreck your entire game.
11+
This silly lil' mod adds a funny mod menu filled to the brim with **over 30 crazy troll options** to mess around with! Spice up your gameplay by adding some truly terrible features to absolutely wreck your entire game.
1212

1313
---
1414

src/Utils.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// Additional utility methods for Horrible Ideas
2222
namespace horrible {
23-
// Pointer reference to this Geode mod
23+
// Pointer to this Geode mod
2424
inline Mod* horribleMod = geode::Mod::get();
2525

2626
/**
@@ -46,6 +46,12 @@ namespace horrible {
4646

4747
namespace str = geode::utils::string; // Shortcut for geode::utils::string
4848

49+
// For convenience
50+
namespace setting {
51+
inline constexpr auto SafeMode = "safe-mode";
52+
inline constexpr auto FloatingBtn = "floating-button";
53+
};
54+
4955
// Default option categories
5056
namespace category {
5157
inline constexpr auto playerlife = "Player Life";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <Geode/Geode.hpp>
44

5+
#include <Geode/modify/MenuLayer.hpp>
56
#include <Geode/modify/PlayLayer.hpp>
67

78
using namespace geode::prelude;
@@ -18,6 +19,24 @@ inline static Option const o = {
1819
};
1920
HORRIBLE_REGISTER_OPTION(o);
2021

22+
class $modify(FreezeMenuLayer, MenuLayer) {
23+
HORRIBLE_DELEGATE_HOOKS(id);
24+
25+
bool init() {
26+
if (!MenuLayer::init()) return false;
27+
28+
if (auto gm = GameManager::get()) {
29+
// get and store user current fps
30+
float currentFPS = gm->m_customFPSTarget;
31+
(void)horribleMod->setSavedValue<float>("fps", currentFPS);
32+
33+
log::debug("Stored current FPS: {}", currentFPS);
34+
};
35+
36+
return true;
37+
};
38+
};
39+
2140
class $modify(FreezePlayLayer, PlayLayer) {
2241
HORRIBLE_DELEGATE_HOOKS(id);
2342

src/hooks/Mock.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ class $modify(MockMenuLayer, MenuLayer) {
4848
auto const mockConfig = file::readJson(fs::path(mockConfigPath));
4949

5050
log::trace("Reading path {}...", mockConfigPath);
51-
("Reading path {}...", mockConfigPath);
5251

5352
if (mockConfig.isOk()) {
5453
log::trace("Reading path {}...", mockConfigPath);
55-
("Read mocking config file");
5654

5755
auto const mockConfigUnwr = mockConfig.unwrapOr(matjson::Value());
5856

src/include/Horrible.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ size_t OptionManager::getDelegateCount(std::string_view id) const noexcept {
8989
void OptionManager::setOption(ZStringView id, bool enable, bool pin) {
9090
auto it = m_delegates.find(id);
9191
if (it != m_delegates.end()) {
92-
for (auto& cb : it->second)
93-
cb(enable);
92+
for (auto& cb : it->second) cb(enable);
9493
};
9594

9695
log::trace("Called {} delegates {} for option {}", it != m_delegates.end() ? it->second.size() : 0, enable ? "on" : "off", id);

src/main.cpp

Lines changed: 84 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,69 @@
33
#include <menu/OptionMenuButton.hpp>
44
#include <menu/SettingV3.hpp>
55

6-
#include <Geode/modify/MenuLayer.hpp>
6+
#include <ranges>
7+
78
#include <Geode/modify/PlayLayer.hpp>
89
#include <Geode/modify/PauseLayer.hpp>
910
#include <Geode/modify/GJGameLevel.hpp>
1011

1112
using namespace horrible::prelude;
1213

14+
inline static std::vector<Hook*> safeModeHooks;
15+
inline static std::vector<Hook*> floatingBtnHooks;
16+
17+
#define HORRIBLE_HOOK_SAFEMODE(hookName) \
18+
static void onModify(auto& self) { \
19+
Result<Hook*> hookRes = self.getHook(hookName); \
20+
\
21+
if (auto hook = hookRes.unwrap()) { \
22+
auto safe = horribleMod->getSettingValue<bool>(setting::SafeMode); \
23+
\
24+
hook->setAutoEnable(safe); \
25+
(void)hook->toggle(safe); \
26+
\
27+
safeModeHooks.push_back(hook); \
28+
}; \
29+
}
30+
31+
#define HORRIBLE_HOOK_FLOATINGBTN \
32+
static void onModify(auto& self) { \
33+
utils::StringMap<std::shared_ptr<Hook>>& hooks = self.m_hooks; \
34+
auto enable = horribleMod->getSettingValue<bool>(setting::FloatingBtn); \
35+
\
36+
for (auto& hook : hooks | std::views::values) { \
37+
(void)hook->toggle(enable); \
38+
hook->setAutoEnable(enable); \
39+
\
40+
floatingBtnHooks.push_back(hook.get()); \
41+
}; \
42+
}
43+
1344
$on_game(Loaded) {
45+
listenForSettingChanges<bool>(
46+
setting::SafeMode,
47+
[](bool value) {
48+
for (auto& hook : safeModeHooks) {
49+
log::trace("Toggling safe mode hook '{}' {}...", hook->getDisplayName(), value ? "ON" : "OFF");
50+
(void)hook->toggle(value);
51+
};
52+
});
53+
1454
listenForKeybindSettingPresses(
1555
"key-popup",
1656
[](Keybind const&, bool down, bool repeat, double) {
1757
if (down && !repeat) menu::open();
1858
});
1959

2060
listenForSettingChanges<bool>(
21-
"floating-button",
61+
setting::FloatingBtn,
2262
[](bool value) {
2363
if (auto fb = OptionMenuButton::get()) fb->setVisible(value);
64+
65+
for (auto& hook : floatingBtnHooks) {
66+
log::trace("Toggling floating button hook '{}' {}...", hook->getDisplayName(), value ? "ON" : "OFF");
67+
(void)hook->toggle(value);
68+
};
2469
});
2570

2671
listenForSettingChanges<bool>(
@@ -52,84 +97,69 @@ using namespace horrible::prelude;
5297
if (auto fb = OptionMenuButton::get()) OverlayManager::get()->addChild(fb);
5398
};
5499

55-
class $modify(HIMenuLayer, MenuLayer) {
56-
bool init() {
57-
if (!MenuLayer::init()) return false;
100+
// safe mode
101+
class $modify(HISafeGJGameLevel, GJGameLevel) {
102+
HORRIBLE_HOOK_SAFEMODE("GJGameLevel::savePercentage");
103+
104+
void savePercentage(int, bool, int, int, bool) {
105+
log::warn("Safe mode is enabled, your progress will not be saved!");
106+
};
107+
};
108+
109+
// safe mode
110+
class $modify(HISafePlayLayer, PlayLayer) {
111+
HORRIBLE_HOOK_SAFEMODE("PlayLayer::levelComplete");
58112

59-
if (auto gm = GameManager::get()) {
60-
// get and store user current fps
61-
float currentFPS = gm->m_customFPSTarget;
62-
(void)horribleMod->setSavedValue<float>("fps", currentFPS);
113+
// safe mode prevents level completion
114+
void levelComplete() {
115+
log::info("Safe mode is enabled");
63116

64-
log::debug("Stored current FPS: {}", currentFPS);
65-
};
117+
bool testMode = m_isTestMode;
66118

67-
return true;
119+
m_isTestMode = true;
120+
PlayLayer::levelComplete();
121+
m_isTestMode = testMode;
68122
};
69123
};
70124

71-
class $modify(HIPlayLayer, PlayLayer) {
72-
struct Fields {
73-
bool safeMode = horribleMod->getSettingValue<bool>("safe-mode");
125+
class $modify(HIFloatBtnPauseLayer, PauseLayer) {
126+
HORRIBLE_HOOK_FLOATINGBTN;
127+
128+
void customSetup() {
129+
if (auto fb = OptionMenuButton::get()) fb->setVisible(horribleMod->getSettingValue<bool>(setting::FloatingBtn));
130+
PauseLayer::customSetup();
74131
};
132+
};
133+
134+
class $modify(HIFloatBtnPlayLayer, PlayLayer) {
135+
HORRIBLE_HOOK_FLOATINGBTN;
75136

76137
void setupHasCompleted() {
77-
PlayLayer::setupHasCompleted();
78138
toggleButton();
139+
PlayLayer::setupHasCompleted();
79140
};
80141

81142
void resume() {
82-
PlayLayer::resume();
83143
toggleButton();
144+
PlayLayer::resume();
84145
};
85146

86147
void resumeAndRestart(bool fromStart) {
148+
toggleButton();
87149
PlayLayer::resumeAndRestart(fromStart);
150+
};
151+
152+
void onQuit() {
88153
toggleButton();
154+
PlayLayer::onQuit();
89155
};
90156

91157
void showEndLayer() {
92158
PlayLayer::showEndLayer();
93159
toggleButton(true);
94160
};
95161

96-
// safe mode prevents level completion
97-
void levelComplete() {
98-
auto f = m_fields.self();
99-
100-
if (f->safeMode) {
101-
log::info("Safe mode is enabled");
102-
103-
bool testMode = m_isTestMode;
104-
105-
m_isTestMode = f->safeMode;
106-
PlayLayer::levelComplete();
107-
m_isTestMode = testMode;
108-
} else {
109-
log::warn("Safe mode is disabled");
110-
PlayLayer::levelComplete();
111-
};
112-
};
113-
114162
void toggleButton(bool toggle = false) {
115-
if (auto fb = OptionMenuButton::get()) fb->setVisible(horribleMod->getSettingValue<bool>("floating-button") && (fb->showInLevel() || toggle));
116-
};
117-
};
118-
119-
class $modify(HIPauseLayer, PauseLayer) {
120-
void customSetup() {
121-
PauseLayer::customSetup();
122-
if (auto fb = OptionMenuButton::get()) fb->setVisible(horribleMod->getSettingValue<bool>("floating-button"));
123-
};
124-
};
125-
126-
// safe mode
127-
class $modify(HIGJGameLevel, GJGameLevel) {
128-
void savePercentage(int percent, bool isPracticeMode, int clicks, int attempts, bool isChkValid) {
129-
if (horribleMod->getSettingValue<bool>("safe-mode")) {
130-
log::warn("Safe mode is enabled, your progress will not be saved!");
131-
} else {
132-
GJGameLevel::savePercentage(percent, isPracticeMode, clicks, attempts, isChkValid);
133-
};
163+
if (auto fb = OptionMenuButton::get()) fb->setVisible(horribleMod->getSettingValue<bool>(setting::FloatingBtn) && (fb->showInLevel() || toggle));
134164
};
135165
};

src/menu/src/OptionMenu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ bool OptionMenu::init() {
394394

395395
m_mainLayer->addChild(m_impl->safeModeContainer, 9);
396396

397-
setupSafeModeNode(horribleMod->getSettingValue<bool>("safe-mode"));
397+
setupSafeModeNode(horribleMod->getSettingValue<bool>(setting::SafeMode));
398398

399399
addEventListener(
400400
CategoryEvent(),
@@ -410,7 +410,7 @@ bool OptionMenu::init() {
410410
});
411411

412412
addEventListener(
413-
SettingChangedEvent(horribleMod, "safe-mode"),
413+
SettingChangedEvent(horribleMod, setting::SafeMode),
414414
[this](std::shared_ptr<SettingV3> setting) {
415415
auto settingBool = std::static_pointer_cast<BoolSettingV3>(setting);
416416
setupSafeModeNode(settingBool->getValue());

0 commit comments

Comments
 (0)