iw4x-client/src/Components/Modules/SlowMotion.cpp

99 lines
1.8 KiB
C++
Raw Normal View History

2022-02-27 07:53:44 -05:00
#include <STDInclude.hpp>
2017-01-19 16:23:59 -05:00
namespace Components
{
int SlowMotion::Delay = 0;
const Game::dvar_t* SlowMotion::cg_drawDisconnect;
void SlowMotion::Com_UpdateSlowMotion(int msec)
2017-01-19 16:23:59 -05:00
{
if (Delay <= 0)
2017-01-19 16:23:59 -05:00
{
Game::Com_UpdateSlowMotion(msec);
2017-01-19 16:23:59 -05:00
}
else
2021-08-15 20:01:21 -04:00
{
Delay -= msec;
2021-08-15 20:01:21 -04:00
}
2017-01-19 16:23:59 -05:00
}
2021-08-15 20:01:21 -04:00
__declspec(naked) void SlowMotion::Com_UpdateSlowMotion_Stub()
2021-08-15 20:01:21 -04:00
{
__asm
{
pushad
push [esp + 0x20 + 0x4]
call Com_UpdateSlowMotion
add esp, 0x4
2021-08-15 20:01:21 -04:00
popad
retn
}
}
void SlowMotion::ScrCmd_SetSlowMotion_Stub()
2017-01-19 16:23:59 -05:00
{
auto duration = 1000;
auto start = Game::Scr_GetFloat(0);
auto end = 1.0f;
2017-01-19 16:23:59 -05:00
if (Game::Scr_GetNumParam() >= 2)
2017-01-19 16:23:59 -05:00
{
end = Game::Scr_GetFloat(1);
}
if (Game::Scr_GetNumParam() >= 3)
2017-01-19 16:23:59 -05:00
{
duration = static_cast<int>(Game::Scr_GetFloat(2) * 1000.0f);
2017-01-19 16:23:59 -05:00
}
auto delay = 0;
2017-01-19 16:23:59 -05:00
if (start > end)
{
if (duration < 150)
{
delay = duration;
}
else
{
delay = 150;
}
}
duration = duration - delay;
Game::Com_SetSlowMotion(start, end, duration);
Delay = delay;
2017-01-19 16:23:59 -05:00
// Set snapshot num to 1 behind (T6 does this, why shouldn't we?)
for (auto i = 0; i < *Game::svs_clientCount; ++i)
2017-01-19 16:23:59 -05:00
{
2022-08-20 06:30:34 -04:00
Game::svs_clients[i].nextSnapshotTime = *Game::svs_time - 1;
2017-01-19 16:23:59 -05:00
}
}
void SlowMotion::CG_DrawDisconnect_Stub(const int localClientNum)
{
if (cg_drawDisconnect->current.enabled)
{
Game::CG_DrawDisconnect(localClientNum);
}
}
2017-06-29 17:03:57 -04:00
SlowMotion::SlowMotion()
{
cg_drawDisconnect = Game::Dvar_RegisterBool("cg_drawDisconnect", false, Game::DVAR_NONE, "Draw connection interrupted");
Delay = 0;
Utils::Hook(0x5F5FF2, ScrCmd_SetSlowMotion_Stub, HOOK_JUMP).install()->quick();
Utils::Hook(0x60B38A, Com_UpdateSlowMotion_Stub, HOOK_CALL).install()->quick();
2017-06-29 17:03:57 -04:00
Utils::Hook(0x4A54ED, CG_DrawDisconnect_Stub, HOOK_CALL).install()->quick();
Utils::Hook(0x4A54FB, CG_DrawDisconnect_Stub, HOOK_CALL).install()->quick();
2017-06-29 17:03:57 -04:00
}
}