diff --git a/src/client/component/demo_timescale.cpp b/src/client/component/demo_timescale.cpp index dc37194..7feb83f 100644 --- a/src/client/component/demo_timescale.cpp +++ b/src/client/component/demo_timescale.cpp @@ -13,9 +13,12 @@ namespace demo_timescale namespace { utils::hook::detour Com_TimeScaleMsec_hook; + utils::hook::detour LUI_Layout_hook; game::dvar_t* demo_timescale; + std::int32_t latest_delta_time; + void generate_pattern(std::array& pattern, std::size_t ones_count, std::size_t zeros_count) { assert(ones_count + zeros_count == pattern.size()); @@ -53,7 +56,7 @@ namespace demo_timescale generate_pattern(pattern, ones_count, zeros_count); } - std::int32_t Com_TimeScaleMsec_stub(std::int32_t msec) + std::int32_t get_delta_time_internal(std::int32_t msec) { if (!demo_playback::playing() || !demo_timescale || demo_timescale->current.value == 1.0f) { @@ -116,6 +119,23 @@ namespace demo_timescale // advance (1ms) or pause (0ms) based on the pattern return pattern[pattern_index++ % pattern.size()]; } + + std::int32_t get_delta_time(std::int32_t msec) + { + latest_delta_time = get_delta_time_internal(msec); + + return latest_delta_time; + } + + void set_delta_time_ui_elements(const std::int32_t client_num, const char* root_name, std::int32_t delta_time, void* lua_vm) + { + if (demo_playback::playing()) + { + delta_time = latest_delta_time; + } + + LUI_Layout_hook.invoke(client_num, root_name, delta_time, lua_vm); + } } class component final : public component_interface @@ -129,7 +149,11 @@ namespace demo_timescale } // add timescale support for demo playback - Com_TimeScaleMsec_hook.create(game::Com_TimeScaleMsec, Com_TimeScaleMsec_stub); + Com_TimeScaleMsec_hook.create(game::Com_TimeScaleMsec, get_delta_time); + + // add timescale support for lua ui elements during demo playback + LUI_Layout_hook.create(game::LUI_Layout, set_delta_time_ui_elements); + demo_timescale = game::Dvar_RegisterFloat( "demotimescale", 1.0f, 0.0f, 1000.0f, game::DVAR_FLAG_NONE, "Set playback speed for demos"); } diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index c017872..652d532 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -158,6 +158,7 @@ namespace game WEAK symbol LUI_IntermissionBegan{0, 0x1401CEB40}; WEAK symbol LUI_OpenMenu{0x1403FD460, 0x1404B3610}; + WEAK symbol LUI_Layout{ 0, 0x1401CF060 }; // Made up name, replaced by ScopedCriticalSection on Black Ops 3 WEAK symbol LUI_EnterCriticalSection{0x1401AE940, 0x1401CD040}; WEAK symbol LUI_LeaveCriticalSection{0x1401B0AA0, 0x1401CF1A0};