forked from alterware/iw6-mod
Added timescale support for lua ui elements during demo playback.
This commit is contained in:
@@ -13,9 +13,12 @@ namespace demo_timescale
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
utils::hook::detour Com_TimeScaleMsec_hook;
|
utils::hook::detour Com_TimeScaleMsec_hook;
|
||||||
|
utils::hook::detour LUI_Layout_hook;
|
||||||
|
|
||||||
game::dvar_t* demo_timescale;
|
game::dvar_t* demo_timescale;
|
||||||
|
|
||||||
|
std::int32_t latest_delta_time;
|
||||||
|
|
||||||
void generate_pattern(std::array<std::uint8_t, 1000>& pattern, std::size_t ones_count, std::size_t zeros_count)
|
void generate_pattern(std::array<std::uint8_t, 1000>& pattern, std::size_t ones_count, std::size_t zeros_count)
|
||||||
{
|
{
|
||||||
assert(ones_count + zeros_count == pattern.size());
|
assert(ones_count + zeros_count == pattern.size());
|
||||||
@@ -53,7 +56,7 @@ namespace demo_timescale
|
|||||||
generate_pattern(pattern, ones_count, zeros_count);
|
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)
|
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
|
// advance (1ms) or pause (0ms) based on the pattern
|
||||||
return pattern[pattern_index++ % pattern.size()];
|
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<void>(client_num, root_name, delta_time, lua_vm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
@@ -129,7 +149,11 @@ namespace demo_timescale
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add timescale support for demo playback
|
// 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(
|
demo_timescale = game::Dvar_RegisterFloat(
|
||||||
"demotimescale", 1.0f, 0.0f, 1000.0f, game::DVAR_FLAG_NONE, "Set playback speed for demos");
|
"demotimescale", 1.0f, 0.0f, 1000.0f, game::DVAR_FLAG_NONE, "Set playback speed for demos");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<bool(int localClientNum, void* luaVM)> LUI_IntermissionBegan{0, 0x1401CEB40};
|
WEAK symbol<bool(int localClientNum, void* luaVM)> LUI_IntermissionBegan{0, 0x1401CEB40};
|
||||||
WEAK symbol<void(int localClientNum, const char* menuName, int isPopup, int isModal, unsigned int isExclusive)> LUI_OpenMenu{0x1403FD460, 0x1404B3610};
|
WEAK symbol<void(int localClientNum, const char* menuName, int isPopup, int isModal, unsigned int isExclusive)> LUI_OpenMenu{0x1403FD460, 0x1404B3610};
|
||||||
|
WEAK symbol<void(int localClientNum, const char* rootName, int deltaTime, void* luaVM)> LUI_Layout{ 0, 0x1401CF060 };
|
||||||
// Made up name, replaced by ScopedCriticalSection on Black Ops 3
|
// Made up name, replaced by ScopedCriticalSection on Black Ops 3
|
||||||
WEAK symbol<void()> LUI_EnterCriticalSection{0x1401AE940, 0x1401CD040};
|
WEAK symbol<void()> LUI_EnterCriticalSection{0x1401AE940, 0x1401CD040};
|
||||||
WEAK symbol<void()> LUI_LeaveCriticalSection{0x1401B0AA0, 0x1401CF1A0};
|
WEAK symbol<void()> LUI_LeaveCriticalSection{0x1401B0AA0, 0x1401CF1A0};
|
||||||
|
|||||||
Reference in New Issue
Block a user