Skip to content

Commit f2471a7

Browse files
committed
remove uneeded hooks from hooks.hpp
1 parent fc2eee4 commit f2471a7

File tree

4 files changed

+51
-79
lines changed

4 files changed

+51
-79
lines changed

src/dllmain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <fstream>
33
#include <matdash.hpp>
44
#include <matdash/boilerplate.hpp>
5+
#include <matdash/minhook.hpp>
56

67
#include "hooks.hpp"
78

src/hooks.cpp

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
#include "overlay_layer.hpp"
44
#include "recorder.hpp"
55
#include <chrono>
6-
#include <matdash/minhook.hpp>
76

87
// yes these are global, too lazy to store them in replaysystem or smth
98
// not like theyre used anywhere else atm
109
bool g_disable_render = false;
1110
float g_left_over = 0.f;
1211

13-
void Hooks::CCScheduler_update(CCScheduler* self, float dt) {
12+
void CCScheduler_update(CCScheduler* self, float dt) {
1413
auto& rs = ReplaySystem::get();
1514
if (rs.recorder.m_recording || rs.is_playing() || rs.is_recording() && gd::GameManager::sharedState()->getPlayLayer()) {
1615
const auto fps = rs.get_replay().get_fps();
@@ -44,14 +43,23 @@ void Hooks::CCScheduler_update(CCScheduler* self, float dt) {
4443
}
4544
}
4645

47-
void Hooks::CCKeyboardDispatcher_dispatchKeyboardMSG(CCKeyboardDispatcher* self, int key, bool down) {
46+
void PlayLayer_update(gd::PlayLayer* self, float dt) {
47+
auto& rs = ReplaySystem::get();
48+
if (rs.get_frame_advance()) return;
49+
if (rs.is_playing()) rs.handle_playing();
50+
if (rs.recorder.m_recording)
51+
rs.recorder.handle_recording(self, dt);
52+
orig<&PlayLayer_update, Thiscall>(self, dt);
53+
}
54+
55+
void CCKeyboardDispatcher_dispatchKeyboardMSG(CCKeyboardDispatcher* self, int key, bool down) {
4856
auto& rs = ReplaySystem::get();
4957
if (down) {
5058
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
5159
if (rs.is_recording() && play_layer) {
5260
if (key == 'C') {
5361
rs.set_frame_advance(false);
54-
PlayLayer::update(play_layer, 1.f / rs.get_default_fps());
62+
PlayLayer_update(play_layer, 1.f / rs.get_default_fps());
5563
rs.set_frame_advance(true);
5664
} else if (key == 'F') {
5765
rs.set_frame_advance(false);
@@ -63,18 +71,6 @@ void Hooks::CCKeyboardDispatcher_dispatchKeyboardMSG(CCKeyboardDispatcher* self,
6371
orig<&CCKeyboardDispatcher_dispatchKeyboardMSG>(self, key, down);
6472
}
6573

66-
float g_xpos_time = 0.f;
67-
68-
void Hooks::PlayLayer::update(gd::PlayLayer* self, float dt) {
69-
auto& rs = ReplaySystem::get();
70-
if (rs.get_frame_advance()) return;
71-
if (rs.is_playing()) rs.handle_playing();
72-
if (rs.recorder.m_recording)
73-
rs.recorder.handle_recording(self, dt);
74-
orig<&update, Thiscall>(self, dt);
75-
}
76-
77-
7874
bool _player_button_handler(bool hold, bool button) {
7975
if (gd::GameManager::sharedState()->getPlayLayer()) {
8076
auto& rs = ReplaySystem::get();
@@ -84,25 +80,25 @@ bool _player_button_handler(bool hold, bool button) {
8480
return false;
8581
}
8682

87-
void Hooks::PlayLayer::pushButton(gd::PlayLayer* self, int idk, bool button) {
83+
void Hooks::PlayLayer_pushButton(gd::PlayLayer* self, int idk, bool button) {
8884
if (_player_button_handler(true, button)) return;
89-
orig<&pushButton>(self, idk, button);
85+
orig<&PlayLayer_pushButton>(self, idk, button);
9086
}
9187

92-
void Hooks::PlayLayer::releaseButton(gd::PlayLayer* self, int idk, bool button) {
88+
void Hooks::PlayLayer_releaseButton(gd::PlayLayer* self, int idk, bool button) {
9389
if (_player_button_handler(false, button)) return;
94-
orig<&releaseButton>(self, idk, button);
90+
orig<&PlayLayer_releaseButton>(self, idk, button);
9591
}
9692

97-
void Hooks::PlayLayer::resetLevel(gd::PlayLayer* self) {
98-
orig<&resetLevel>(self);
93+
void PlayLayer_resetLevel(gd::PlayLayer* self) {
94+
orig<&PlayLayer_resetLevel>(self);
9995
auto& rs = ReplaySystem::get();
10096
rs.on_reset();
10197
rs.recorder.update_song_offset(self);
10298
}
10399

104100

105-
void Hooks::PlayLayer::pauseGame(gd::PlayLayer* self, bool idk) {
101+
void PlayLayer_pauseGame(gd::PlayLayer* self, bool idk) {
106102
auto addr = cast<void*>(gd::base + 0x20D43C);
107103
auto& rs = ReplaySystem::get();
108104
if (rs.is_recording())
@@ -112,45 +108,45 @@ void Hooks::PlayLayer::pauseGame(gd::PlayLayer* self, bool idk) {
112108
if (should_patch)
113109
patch(addr, {0x83, 0xC4, 0x04, 0x90, 0x90});
114110

115-
orig<&pauseGame>(self, idk);
111+
orig<&PlayLayer_pauseGame>(self, idk);
116112

117113
if (should_patch)
118114
patch(addr, {0xe8, 0x2f, 0x7b, 0xfe, 0xff});
119115
}
120116

121117

122-
CCObject* Hooks::CheckpointObject_create() {
118+
CCObject* CheckpointObject_create() {
123119
return CheckpointObjectMod::create();
124120
}
125121

126-
void Hooks::PlayLayer::levelComplete(gd::PlayLayer* self) {
122+
void PlayLayer_levelComplete(gd::PlayLayer* self) {
127123
ReplaySystem::get().reset_state();
128-
return orig<&levelComplete>(self);
124+
return orig<&PlayLayer_levelComplete>(self);
129125
}
130126

131127
void _on_exit_level() {
132128
ReplaySystem::get().reset_state();
133129
}
134130

135-
void Hooks::PlayLayer::onQuit(gd::PlayLayer* self) {
131+
void PlayLayer_onQuit(gd::PlayLayer* self) {
136132
_on_exit_level();
137-
orig<&onQuit>(self);
133+
orig<&PlayLayer_onQuit>(self);
138134
}
139135

140-
void Hooks::PauseLayer_onEditor(gd::PauseLayer* self, CCObject* idk) {
136+
void PauseLayer_onEditor(gd::PauseLayer* self, CCObject* idk) {
141137
_on_exit_level();
142138
orig<&PauseLayer_onEditor>(self, idk);
143139
}
144140

145-
bool Hooks::PauseLayer_init(gd::PauseLayer* self) {
141+
bool PauseLayer_init(gd::PauseLayer* self) {
146142
static bool placed_hooks = false;
147143
if (!placed_hooks) {
148144
placed_hooks = true;
149145
// this is stupid lol, but should hopefully
150146
// stop it breaking when loading from extensions
151-
add_hook<&PlayLayer::pushButton>(gd::base + 0x111500);
152-
add_hook<&PlayLayer::releaseButton>(gd::base + 0x111660);
153-
add_hook<&PlayLayer::resetLevel>(gd::base + 0x20BF00);
147+
add_hook<&Hooks::PlayLayer_pushButton>(gd::base + 0x111500);
148+
add_hook<&Hooks::PlayLayer_releaseButton>(gd::base + 0x111660);
149+
add_hook<&PlayLayer_resetLevel>(gd::base + 0x20BF00);
154150
add_hook<&CheckpointObject_create, Optfastcall>(gd::base + 0x20ddd0);
155151
}
156152
if (orig<&PauseLayer_init>(self)) {
@@ -186,30 +182,30 @@ void _handle_activated_object(bool a, bool b, gd::GameObject* object) {
186182
}
187183
}
188184

189-
void Hooks::PlayerObject_ringJump(gd::PlayerObject* self, gd::GameObject* ring) {
185+
void PlayerObject_ringJump(gd::PlayerObject* self, gd::GameObject* ring) {
190186
bool a = ring->m_hasBeenActivated;
191187
bool b = ring->m_hasBeenActivatedP2;
192188
orig<&PlayerObject_ringJump>(self, ring);
193189
_handle_activated_object(a, b, ring);
194190
}
195191

196-
void Hooks::GameObject_activateObject(gd::GameObject* self, gd::PlayerObject* player) {
192+
void GameObject_activateObject(gd::GameObject* self, gd::PlayerObject* player) {
197193
bool a = self->m_hasBeenActivated;
198194
bool b = self->m_hasBeenActivatedP2;
199195
orig<&GameObject_activateObject>(self, player);
200196
_handle_activated_object(a, b, self);
201197
}
202198

203-
void Hooks::GJBaseGameLayer_bumpPlayer(gd::GJBaseGameLayer* self, gd::PlayerObject* player, gd::GameObject* object) {
199+
void GJBaseGameLayer_bumpPlayer(gd::GJBaseGameLayer* self, gd::PlayerObject* player, gd::GameObject* object) {
204200
bool a = object->m_hasBeenActivated;
205201
bool b = object->m_hasBeenActivatedP2;
206202
orig<&GJBaseGameLayer_bumpPlayer>(self, player, object);
207203
_handle_activated_object(a, b, object);
208204
}
209205

210-
void Hooks::PlayLayer::updateVisiblity(gd::PlayLayer* self) {
206+
void PlayLayer_updateVisiblity(gd::PlayLayer* self) {
211207
if (!g_disable_render)
212-
orig<&updateVisiblity>(self);
208+
orig<&PlayLayer_updateVisiblity>(self);
213209
}
214210

215211
void PauseLayer_onResume(gd::PauseLayer* self, CCObject* sender) {
@@ -238,15 +234,15 @@ void Hooks::init() {
238234
add_hook<&CCScheduler_update, Thiscall>(cocos("?update@CCScheduler@cocos2d@@UAEXM@Z"));
239235
add_hook<&CCKeyboardDispatcher_dispatchKeyboardMSG>(cocos("?dispatchKeyboardMSG@CCKeyboardDispatcher@cocos2d@@QAE_NW4enumKeyCodes@2@_N@Z"));
240236

241-
add_hook<&PlayLayer::update, Thiscall>(gd::base + 0x2029C0);
237+
add_hook<&PlayLayer_update, Thiscall>(gd::base + 0x2029C0);
242238

243-
add_hook<&PlayLayer::pauseGame>(gd::base + 0x20D3C0);
239+
add_hook<&PlayLayer_pauseGame>(gd::base + 0x20D3C0);
244240

245-
add_hook<&PlayLayer::levelComplete>(gd::base + 0x1FD3D0);
246-
add_hook<&PlayLayer::onQuit>(gd::base + 0x20D810);
241+
add_hook<&PlayLayer_levelComplete>(gd::base + 0x1FD3D0);
242+
add_hook<&PlayLayer_onQuit>(gd::base + 0x20D810);
247243
add_hook<&PauseLayer_onEditor>(gd::base + 0x1E60E0);
248244

249-
add_hook<&PlayLayer::updateVisiblity>(gd::base + 0x205460);
245+
add_hook<&PlayLayer_updateVisiblity>(gd::base + 0x205460);
250246

251247
add_hook<&PauseLayer_init>(gd::base + 0x1E4620);
252248
add_hook<&PauseLayer_onResume>(gd::base + 0x1e5fa0);

src/hooks.hpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,6 @@
66
namespace Hooks {
77
void init();
88

9-
void CCScheduler_update(CCScheduler*, float dt);
10-
void CCKeyboardDispatcher_dispatchKeyboardMSG(CCKeyboardDispatcher*, int key, bool down);
11-
CCObject* CheckpointObject_create();
12-
13-
namespace PlayLayer {
14-
void update(gd::PlayLayer*, float dt);
15-
16-
void pushButton(gd::PlayLayer*, int, bool);
17-
void releaseButton(gd::PlayLayer*, int, bool);
18-
void resetLevel(gd::PlayLayer*);
19-
20-
void pauseGame(gd::PlayLayer*, bool);
21-
22-
void levelComplete(gd::PlayLayer*);
23-
// these are only for stopping recording/playing
24-
// maybe hook the destructor instead ?
25-
void onQuit(gd::PlayLayer*);
26-
27-
void updateVisiblity(gd::PlayLayer*);
28-
}
29-
30-
void PauseLayer_onEditor(gd::PauseLayer*, CCObject*);
31-
bool PauseLayer_init(gd::PauseLayer*);
32-
33-
void PlayerObject_ringJump(gd::PlayerObject*, gd::GameObject* ring);
34-
void GameObject_activateObject(gd::GameObject*, gd::PlayerObject* player);
35-
void GJBaseGameLayer_bumpPlayer(gd::GJBaseGameLayer*, gd::PlayerObject* player, gd::GameObject* object);
9+
void PlayLayer_pushButton(gd::PlayLayer*, int, bool);
10+
void PlayLayer_releaseButton(gd::PlayLayer*, int, bool);
3611
}

src/replay_system.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ void ReplaySystem::record_action(bool hold, bool player1, bool flip) {
2121
void ReplaySystem::play_action(const Action& action) {
2222
auto gm = gd::GameManager::sharedState();
2323
auto flip = gm->getGameVariable("0010");
24-
if (action.hold) orig<&Hooks::PlayLayer::pushButton>(gm->getPlayLayer(), 0, !action.player2 ^ flip);
25-
else orig<&Hooks::PlayLayer::releaseButton>(gm->getPlayLayer(), 0, !action.player2 ^ flip);
24+
if (action.hold) orig<&Hooks::PlayLayer_pushButton>(gm->getPlayLayer(), 0, !action.player2 ^ flip);
25+
else orig<&Hooks::PlayLayer_releaseButton>(gm->getPlayLayer(), 0, !action.player2 ^ flip);
2626
}
2727

2828
unsigned ReplaySystem::get_frame() {
@@ -69,8 +69,8 @@ void ReplaySystem::on_reset() {
6969
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
7070
if (is_playing()) {
7171
update_frame_offset();
72-
orig<&Hooks::PlayLayer::releaseButton>(play_layer, 0, false);
73-
orig<&Hooks::PlayLayer::releaseButton>(play_layer, 0, true);
72+
orig<&Hooks::PlayLayer_releaseButton>(play_layer, 0, false);
73+
orig<&Hooks::PlayLayer_releaseButton>(play_layer, 0, true);
7474
action_index = 0;
7575
practice_fixes.activated_objects.clear();
7676
practice_fixes.activated_objects_p2.clear();
@@ -107,13 +107,13 @@ void ReplaySystem::on_reset() {
107107
if ((holding && actions.empty()) || (!actions.empty() && actions.back().hold != holding)) {
108108
record_action(holding, true, false);
109109
if (holding) {
110-
orig<&Hooks::PlayLayer::releaseButton>(play_layer, 0, true);
111-
orig<&Hooks::PlayLayer::pushButton>(play_layer, 0, true);
110+
orig<&Hooks::PlayLayer_releaseButton>(play_layer, 0, true);
111+
orig<&Hooks::PlayLayer_pushButton>(play_layer, 0, true);
112112
play_layer->m_player1->m_hasJustHeld = true;
113113
}
114114
} else if (!actions.empty() && actions.back().hold && holding && has_checkpoints && checkpoint.player1.buffer_orb) {
115-
orig<&Hooks::PlayLayer::releaseButton>(play_layer, 0, true);
116-
orig<&Hooks::PlayLayer::pushButton>(play_layer, 0, true);
115+
orig<&Hooks::PlayLayer_releaseButton>(play_layer, 0, true);
116+
orig<&Hooks::PlayLayer_pushButton>(play_layer, 0, true);
117117
}
118118
if (play_layer->m_levelSettings->m_twoPlayerMode)
119119
record_action(false, false, false);

0 commit comments

Comments
 (0)