@@ -32,21 +32,50 @@ void Hooks::init() {
3232 ADD_GD_HOOK (0x20D810 , PlayLayer::onQuit);
3333 ADD_GD_HOOK (0x1E60E0 , PlayLayer::onEditor);
3434
35+ ADD_GD_HOOK (0x205460 , PlayLayer::updateVisiblity);
36+
3537 ADD_GD_HOOK (0x1E4620 , PauseLayer_init);
3638
3739 ADD_GD_HOOK (0x1f4ff0 , PlayerObject_ringJump);
3840 ADD_GD_HOOK (0xef0e0 , GameObject_activateObject);
3941 ADD_GD_HOOK (0x10ed50 , GJBaseGameLayer_bumpPlayer);
4042}
4143
44+ // yes these are global, too lazy to store them in replaysystem or smth
45+ // not like theyre used anywhere else atm
46+ bool g_disable_render = false ;
47+ float g_left_over = 0 .f;
48+
4249void __fastcall Hooks::CCScheduler_update_H (CCScheduler* self, int , float dt) {
4350 auto & rs = ReplaySystem::get_instance ();
4451 if (rs.is_playing () || rs.is_recording () && gd::GameManager::sharedState ()->getPlayLayer ()) {
45- auto fps = rs.get_replay ().get_fps ();
52+ const auto fps = rs.get_replay ().get_fps ();
4653 auto speedhack = self->getTimeScale ();
47- dt = 1 .f / fps / speedhack;
54+
55+ const float target_dt = 1 .f / fps / speedhack;
56+
57+ if (!rs.real_time_mode )
58+ return CCScheduler_update (self, target_dt);
59+
60+ // todo: find ways to disable more render stuff
61+ g_disable_render = true ;
62+
63+ // TODO: not have this min()
64+ // doing the commented out if below causes really weird stutters for some reason
65+ const int times = min (static_cast <int >((dt + g_left_over) / target_dt), 150 );
66+ // if the fps is really low then dont run it a lot of times
67+ // if (dt > 1.f / 10.f) {
68+ // times = min(times, 100);
69+ // }
70+ for (int i = 0 ; i < times; ++i) {
71+ if (i == times - 1 )
72+ g_disable_render = false ;
73+ CCScheduler_update (self, target_dt);
74+ }
75+ g_left_over += dt - target_dt * times;
76+ } else {
77+ CCScheduler_update (self, dt);
4878 }
49- CCScheduler_update (self, dt);
5079}
5180
5281void __fastcall Hooks::CCKeyboardDispatcher_dispatchKeyboardMSG_H (CCKeyboardDispatcher* self, int , int key, bool down) {
@@ -211,4 +240,9 @@ void __fastcall Hooks::GJBaseGameLayer_bumpPlayer_H(gd::GJBaseGameLayer* self, i
211240 bool b = object->m_hasBeenActivatedP2 ;
212241 GJBaseGameLayer_bumpPlayer (self, player, object);
213242 _handle_activated_object (a, b, object);
214- }
243+ }
244+
245+ void __fastcall Hooks::PlayLayer::updateVisiblity_H (gd::PlayLayer* self, int ) {
246+ if (!g_disable_render)
247+ updateVisiblity (self);
248+ }
0 commit comments