Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit c7ab164

Browse files
committed
fix crash and add auto safe mode
1 parent 66c4079 commit c7ab164

File tree

9 files changed

+40
-14
lines changed

9 files changed

+40
-14
lines changed

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"gd": {
44
"win": "2.204"
55
},
6-
"version": "v2.2.7",
6+
"version": "v2.2.9",
77
"id": "maxnu.gd_mega_overlay",
88
"name": "GD Mega Overlay",
99
"developer": "maxnu & SpaghettDev",

src/Common.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void Common::onAudioPitchChange()
140140
AudioChannelControl::setPitch(enabled ? pitch : 1.f);
141141
}
142142

143-
void Common::updateCheathing()
143+
void Common::updateCheating()
144144
{
145145
auto checkPatchGroup = [&](JsonPatches::patch_group_type group)
146146
{
@@ -152,10 +152,8 @@ void Common::updateCheathing()
152152
return true;
153153
}
154154
}
155-
156155
return false;
157156
};
158-
159157
if(checkPatchGroup(JsonPatches::bypass))
160158
return;
161159
if(checkPatchGroup(JsonPatches::creator))
@@ -166,16 +164,13 @@ void Common::updateCheathing()
166164
return;
167165
if(checkPatchGroup(JsonPatches::player))
168166
return;
169-
170167
float speedhack =
171168
Settings::get<bool>("general/speedhack/enabled") ? Settings::get<float>("general/speedhack/value") : 1.f;
172-
173-
if(speedhack != 1.f)
169+
if(speedhack != 1.f || Macrobot::playerMode == 0)
174170
{
175171
isCheating = true;
176172
return;
177173
}
178-
179174
isCheating = false;
180175
}
181176

src/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ namespace Common
2121
void saveIcons();
2222
void loadIcons();
2323

24-
void updateCheathing();
24+
void updateCheating();
2525
};

src/GUI/GUI.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "ConstData.h"
1414

1515
#include "Common.h"
16+
#include "Hacks/SafeMode.h"
1617

1718
using namespace geode::prelude;
1819

@@ -43,7 +44,8 @@ class $modify(CCKeyboardDispatcher) {
4344
GUI::draw();
4445
GUI::shortcutLoop = false;
4546

46-
Common::updateCheathing();
47+
Common::updateCheating();
48+
SafeMode::updateAuto();
4749
}
4850
}
4951
}
@@ -150,7 +152,8 @@ void GUI::toggle()
150152
if (!canToggle)
151153
return;
152154

153-
Common::updateCheathing();
155+
Common::updateCheating();
156+
SafeMode::updateAuto();
154157

155158
isVisible = true;
156159
static bool toggle = false;

src/Hacks/Labels.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../GUI/GUI.h"
44
#include "../JsonPatches/JsonPatches.h"
55
#include "../Settings.hpp"
6+
#include "Hacks/SafeMode.h"
67

78
#include <Geode/modify/PlayLayer.hpp>
89
#include <Geode/modify/PlayerObject.hpp>
@@ -173,7 +174,8 @@ class $modify(PlayLayer)
173174

174175
void resetLevel()
175176
{
176-
Common::updateCheathing();
177+
Common::updateCheating();
178+
SafeMode::updateAuto();
177179
noclipDead = false;
178180
dead = false;
179181
totalClicks = 0;

src/Hacks/SafeMode.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "../util.hpp"
1111
#include "../Settings.hpp"
1212

13+
#include "Common.h"
14+
1315
using namespace geode::prelude;
1416
using namespace SafeMode;
1517

@@ -58,6 +60,14 @@ class $modify(EndLevelLayer)
5860
}
5961
};
6062

63+
void SafeMode::updateAuto()
64+
{
65+
if(Settings::get<bool>("level/safe_mode/auto", false))
66+
Mod::get()->setSavedValue<bool>("level/safe_mode/enabled", Common::isCheating);
67+
68+
updateState();
69+
}
70+
6171
void SafeMode::updateState()
6272
{
6373
for (auto& patch : patches)

src/Hacks/SafeMode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace SafeMode
1414
using opcode = std::pair<unsigned long, std::vector<uint8_t>>;
1515

1616
void updateState();
17+
void updateAuto();
1718

1819
// move to JsonHacks
1920
inline const std::array<opcode, PATCHES_SIZE> opcodes{

src/Hacks/StartposSwitcher.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Geode/modify/PlayLayer.hpp>
1212
#include <Geode/modify/StartPosObject.hpp>
1313
#include <Geode/modify/CCKeyboardDispatcher.hpp>
14+
#include <Geode/modify/LevelEditorLayer.hpp>
1415

1516
#include "ConstData.h"
1617

@@ -45,6 +46,17 @@ class $modify(StartPosObject)
4546
}
4647
};
4748

49+
class $modify(LevelEditorLayer)
50+
{
51+
bool init(GJGameLevel* level, bool unk)
52+
{
53+
startposObjects.clear();
54+
55+
bool res = LevelEditorLayer::init(level, unk);
56+
return res;
57+
}
58+
};
59+
4860
class $modify(PlayLayer)
4961
{
5062
void onQuit()
@@ -55,6 +67,7 @@ class $modify(PlayLayer)
5567

5668
bool init(GJGameLevel* p0, bool p1, bool p2)
5769
{
70+
CC_SAFE_RELEASE_NULL(startPosLabel);
5871
startposObjects.clear();
5972
bool res = PlayLayer::init(p0, p1, p2);
6073

src/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ void init()
3636
DiscordRPCManager::init();
3737
Macrobot::getMacros();
3838
Clickpacks::init();
39-
Common::updateCheathing();
39+
Common::updateCheating();
4040

4141
GUI::setLateInit([] {
4242
Common::calculateFramerate();
4343
Common::setPriority();
4444
Common::onAudioSpeedChange();
4545
Common::loadIcons();
46-
SafeMode::updateState();
46+
SafeMode::updateAuto();
4747
});
4848
}
4949

@@ -188,6 +188,8 @@ void initGUI()
188188

189189
GUI::checkbox("Replay Last Checkpoint", "level/replay_checkpoint");
190190

191+
GUI::checkbox("Auto Safe Mode", "level/safe_mode/auto");
192+
191193
if (GUI::checkbox("Safe Mode", "level/safe_mode/enabled"))
192194
SafeMode::updateState();
193195
GUI::checkbox("Safe Mode Endscreen Label", "level/safe_mode/endscreen_enabled", true);

0 commit comments

Comments
 (0)