[Slowmotion] Cleanup functions defs (#551)

This commit is contained in:
Edo 2022-11-04 00:28:44 +00:00 committed by GitHub
parent eddfb895a2
commit 0d22bc482a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 21 deletions

View File

@ -4,27 +4,29 @@ namespace Components
{
int SlowMotion::Delay = 0;
void SlowMotion::ApplySlowMotion(int timePassed)
const Game::dvar_t* SlowMotion::cg_drawDisconnect;
void SlowMotion::Com_UpdateSlowMotion(int msec)
{
if (Delay <= 0)
{
Utils::Hook::Call<void(int)>(0x60B2D0)(timePassed);
Game::Com_UpdateSlowMotion(msec);
}
else
{
Delay -= timePassed;
Delay -= msec;
}
}
__declspec(naked) void SlowMotion::ApplySlowMotionStub()
__declspec(naked) void SlowMotion::Com_UpdateSlowMotion_Stub()
{
__asm
{
pushad
push [esp + 24h]
call ApplySlowMotion
add esp, 4h
push [esp + 0x20 + 0x4]
call Com_UpdateSlowMotion
add esp, 0x4
popad
@ -32,18 +34,18 @@ namespace Components
}
}
void SlowMotion::SetSlowMotion()
void SlowMotion::ScrCmd_SetSlowMotion_Stub()
{
auto duration = 1000;
auto start = Game::Scr_GetFloat(0);
auto end = 1.0f;
if (Game::Scr_GetNumParam() >= 2u)
if (Game::Scr_GetNumParam() >= 2)
{
end = Game::Scr_GetFloat(1);
}
if (Game::Scr_GetNumParam() >= 3u)
if (Game::Scr_GetNumParam() >= 3)
{
duration = static_cast<int>(Game::Scr_GetFloat(2) * 1000.0f);
}
@ -67,21 +69,30 @@ namespace Components
Game::Com_SetSlowMotion(start, end, duration);
Delay = delay;
// set snapshot num to 1 behind (T6 does this, why shouldn't we?)
// Set snapshot num to 1 behind (T6 does this, why shouldn't we?)
for (auto i = 0; i < *Game::svs_clientCount; ++i)
{
Game::svs_clients[i].nextSnapshotTime = *Game::svs_time - 1;
}
}
void SlowMotion::CG_DrawDisconnect_Stub(const int localClientNum)
{
if (cg_drawDisconnect->current.enabled)
{
Game::CG_DrawDisconnect(localClientNum);
}
}
SlowMotion::SlowMotion()
{
cg_drawDisconnect = Game::Dvar_RegisterBool("cg_drawDisconnect", false, Game::DVAR_NONE, "Draw connection interrupted");
Delay = 0;
Utils::Hook(0x5F5FF2, SetSlowMotion, HOOK_JUMP).install()->quick();
Utils::Hook(0x60B38A, ApplySlowMotionStub, HOOK_CALL).install()->quick();
Utils::Hook(0x5F5FF2, ScrCmd_SetSlowMotion_Stub, HOOK_JUMP).install()->quick();
Utils::Hook(0x60B38A, Com_UpdateSlowMotion_Stub, HOOK_CALL).install()->quick();
Utils::Hook::Nop(0x4A54ED, 5);
Utils::Hook::Nop(0x4A54FB, 5);
Utils::Hook(0x4A54ED, CG_DrawDisconnect_Stub, HOOK_CALL).install()->quick();
Utils::Hook(0x4A54FB, CG_DrawDisconnect_Stub, HOOK_CALL).install()->quick();
}
}

View File

@ -10,8 +10,13 @@ namespace Components
private:
static int Delay;
static void SetSlowMotion();
static void ApplySlowMotion(int timePassed);
static void ApplySlowMotionStub();
static const Game::dvar_t* cg_drawDisconnect;
static void Com_UpdateSlowMotion(int timePassed);
static void Com_UpdateSlowMotion_Stub();
static void ScrCmd_SetSlowMotion_Stub();
static void CG_DrawDisconnect_Stub(int localClientNum);
};
}

View File

@ -22,6 +22,7 @@ namespace Game
Com_SetSlowMotion_t Com_SetSlowMotion = Com_SetSlowMotion_t(0x446E20);
Com_Quitf_t Com_Quit_f = Com_Quitf_t(0x4D4000);
Com_OpenLogFile_t Com_OpenLogFile = Com_OpenLogFile_t(0x60A8D0);
Com_UpdateSlowMotion_t Com_UpdateSlowMotion = Com_UpdateSlowMotion_t(0x60B2D0);
int* com_frameTime = reinterpret_cast<int*>(0x1AD8F3C);

View File

@ -59,6 +59,9 @@ namespace Game
typedef void(*Com_OpenLogFile_t)();
extern Com_OpenLogFile_t Com_OpenLogFile;
typedef void(*Com_UpdateSlowMotion_t)(int msec);
extern Com_UpdateSlowMotion_t Com_UpdateSlowMotion;
extern int* com_frameTime;
extern int* com_fixedConsolePosition;

View File

@ -9,6 +9,7 @@ namespace Game
Cbuf_AddText_t Cbuf_AddText = Cbuf_AddText_t(0x404B20);
Cbuf_InsertText_t Cbuf_InsertText = Cbuf_InsertText_t(0x4940B0);
CG_DrawDisconnect_t CG_DrawDisconnect = CG_DrawDisconnect_t(0x454A70);
CG_NextWeapon_f_t CG_NextWeapon_f = CG_NextWeapon_f_t(0x449DE0);
CG_GetClientNum_t CG_GetClientNum = CG_GetClientNum_t(0x433700);
CG_PlayBoltedEffect_t CG_PlayBoltedEffect = CG_PlayBoltedEffect_t(0x430E10);

View File

@ -15,12 +15,15 @@ namespace Game
typedef void(*Cbuf_InsertText_t)(int localClientNum, const char* text);
extern Cbuf_InsertText_t Cbuf_InsertText;
typedef int(*CG_GetClientNum_t)();
extern CG_GetClientNum_t CG_GetClientNum;
typedef void(*CG_DrawDisconnect_t)(int localClientNum);
extern CG_DrawDisconnect_t CG_DrawDisconnect;
typedef void(*CG_NextWeapon_f_t)();
extern CG_NextWeapon_f_t CG_NextWeapon_f;
typedef int(*CG_GetClientNum_t)();
extern CG_GetClientNum_t CG_GetClientNum;
typedef void(*CG_PlayBoltedEffect_t)(int localClientNum, FxEffectDef* fxDef, int dobjHandle, unsigned int boneName);
extern CG_PlayBoltedEffect_t CG_PlayBoltedEffect;