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
109bool g_disable_render = false ;
1110float 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-
7874bool _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
131127void _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
215211void 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 );
0 commit comments