Skip to content

Commit bc45e8a

Browse files
authored
Fix invisible weapon particles at high FPS (#4149)
1 parent 8e8a21b commit bc45e8a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Client/multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,38 @@ static void _declspec(naked) HOOK_CTaskSimpleSwim__ProcessEffectsBubbleFix()
578578
}
579579
}
580580

581+
// Fixes invisible weapon particles (extinguisher, spraycan, flamethrower) at high FPS
582+
#define HOOKPOS_CWeapon_Update 0x73DC3D
583+
#define HOOKSIZE_CWeapon_Update 5
584+
static constexpr std::uintptr_t RETURN_CWeapon_Update = 0x073DC42;
585+
static void __declspec(naked) HOOK_CWeapon_Update()
586+
{
587+
_asm
588+
{
589+
// timeStep / kOriginalTimeStep
590+
fld ds:[0xB7CB5C] // CTimer::ms_fTimeStep
591+
fdiv kOriginalTimeStep
592+
593+
mov eax, [esi+10h] // m_timeToNextShootInMS
594+
mov ebx, ds:[0xB7CB84] // CTimer::m_snTimeInMilliseconds
595+
596+
sub eax, ebx // m_timeToNextShootInMS - CTimer::m_snTimeInMilliseconds
597+
598+
push eax
599+
fild dword ptr [esp]
600+
add esp, 4
601+
602+
fmul st(0), st(1) // (m_timeToNextShootInMS - CTimer::m_snTimeInMilliseconds) * (timeStep / kOriginalTimeStep)
603+
fadd st(0), ebx // + m_snTimeInMilliseconds
604+
fistp [esi+10h]
605+
606+
mov eax, ebx
607+
608+
xor ebx, ebx
609+
jmp RETURN_CWeapon_Update
610+
}
611+
}
612+
581613
void CMultiplayerSA::InitHooks_FrameRateFixes()
582614
{
583615
EZHookInstall(CTaskSimpleUseGun__SetMoveAnim);
@@ -619,4 +651,6 @@ void CMultiplayerSA::InitHooks_FrameRateFixes()
619651
EZHookInstall(CVehicle__AddExhaustParticles);
620652
EZHookInstall(CTaskSimpleSwim__ProcessEffects);
621653
EZHookInstall(CTaskSimpleSwim__ProcessEffectsBubbleFix);
654+
655+
EZHookInstall(CWeapon_Update);
622656
}

0 commit comments

Comments
 (0)