Skip to content

Commit 7c8a1ab

Browse files
authored
Fix various high fps issues (PR #2784)
1 parent d085fb9 commit 7c8a1ab

File tree

1 file changed

+147
-1
lines changed

1 file changed

+147
-1
lines changed

Client/multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ constexpr float kOriginalTimeStep = 50.0f / 30.0f;
1818
#define HOOKPOS_CTaskSimpleUseGun__SetMoveAnim 0x61E4F2
1919
#define HOOKSIZE_CTaskSimpleUseGun__SetMoveAnim 0x6
2020
const unsigned int RETURN_CTaskSimpleUseGun__SetMoveAnim = 0x61E4F8;
21-
2221
void _declspec(naked) HOOK_CTaskSimpleUseGun__SetMoveAnim()
2322
{
2423
_asm {
@@ -74,6 +73,133 @@ static void _declspec(naked) HOOK_CHeli__ProcessFlyingCarStuff()
7473
}
7574
}
7675

76+
#define HOOKPOS_CClouds__MovingFog_Update 0x716BA6
77+
#define HOOKSIZE_CClouds__MovingFog_Update 0x16
78+
static const unsigned int RETURN_CClouds__MovingFog_Update = 0x716BBC;
79+
static void _declspec(naked) HOOK_CClouds__MovingFog_Update()
80+
{
81+
_asm {
82+
fmul [edi*4+0xC6E394] // CClouds::ms_mf.fSpeedFactor
83+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
84+
fdiv kOriginalTimeStep // 1.666f
85+
fadd [esi]
86+
fstp [esi]
87+
fld [esp+0x18]
88+
fmul [edi*4+0xC6E394] // CClouds::ms_mf.fSpeedFactor
89+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
90+
fdiv kOriginalTimeStep // 1.666f
91+
jmp RETURN_CClouds__MovingFog_Update
92+
}
93+
}
94+
95+
#define HOOKPOS_CFallingGlassPane__Update_A 0x71AABF
96+
#define HOOKSIZE_CFallingGlassPane__Update_A 0x6
97+
static const unsigned int RETURN_CFallingGlassPane__Update_A = 0x71AAC5;
98+
static void _declspec(naked) HOOK_CFallingGlassPane__Update_A()
99+
{
100+
_asm {
101+
fld [esp+0x28]
102+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
103+
fdiv kOriginalTimeStep // 1.666f
104+
fstp [esp+0x28]
105+
fld [esp+0x24]
106+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
107+
fdiv kOriginalTimeStep // 1.666f
108+
fstp [esp+0x24]
109+
fld [esp+0x20]
110+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
111+
fdiv kOriginalTimeStep // 1.666f
112+
fadd [esi]
113+
jmp RETURN_CFallingGlassPane__Update_A
114+
}
115+
}
116+
117+
#define HOOKPOS_CFallingGlassPane__Update_B 0x71AAEA
118+
#define HOOKSIZE_CFallingGlassPane__Update_B 0x6
119+
static const unsigned int RETURN_CFallingGlassPane__Update_B = 0x71AAF0;
120+
static void _declspec(naked) HOOK_CFallingGlassPane__Update_B()
121+
{
122+
_asm {
123+
fld [eax]
124+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
125+
fdiv kOriginalTimeStep // 1.666f
126+
fstp [eax]
127+
fld [eax+0x4]
128+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
129+
fdiv kOriginalTimeStep // 1.666f
130+
fstp [eax+0x4]
131+
fld [eax+0x8]
132+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
133+
fdiv kOriginalTimeStep // 1.666f
134+
fstp [eax+0x8]
135+
mov ecx, [eax]
136+
mov [esp+0x2C], ecx
137+
jmp RETURN_CFallingGlassPane__Update_B
138+
}
139+
}
140+
141+
#define HOOKPOS_CFallingGlassPane__Update_C 0x71AB29
142+
#define HOOKSIZE_CFallingGlassPane__Update_C 0x6
143+
static const unsigned int RETURN_CFallingGlassPane__Update_C = 0x71AB2F;
144+
static void _declspec(naked) HOOK_CFallingGlassPane__Update_C()
145+
{
146+
_asm {
147+
fld [eax]
148+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
149+
fdiv kOriginalTimeStep // 1.666f
150+
fstp [eax]
151+
fld [eax+0x4]
152+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
153+
fdiv kOriginalTimeStep // 1.666f
154+
fstp [eax+0x4]
155+
fld [eax+0x8]
156+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
157+
fdiv kOriginalTimeStep // 1.666f
158+
fstp [eax+0x8]
159+
mov edx, [eax]
160+
mov [esp+0x38], edx
161+
jmp RETURN_CFallingGlassPane__Update_C
162+
}
163+
}
164+
165+
#define HOOKPOS_CPhysical__ApplyAirResistance 0x544D29
166+
#define HOOKSIZE_CPhysical__ApplyAirResistance 5
167+
static const unsigned int RETURN_CPhysical__ApplyAirResistance = 0x544D4D;
168+
static void _declspec(naked) HOOK_CPhysical__ApplyAirResistance()
169+
{
170+
_asm {
171+
fld ds:[0x862CD0] // 0.99000001f
172+
fld ds:[0xB7CB5C] // CTimer::ms_fTimeStep
173+
fdiv kOriginalTimeStep // 1.666f
174+
mov eax, 0x822130 // powf
175+
call eax
176+
177+
fld st(0)
178+
fmul [esi+0x50]
179+
fstp [esi+0x50]
180+
181+
fld st(0)
182+
fmul [esi+0x54]
183+
fstp [esi+0x54]
184+
185+
fmul [esi+0x58]
186+
fstp [esi+0x58]
187+
jmp RETURN_CPhysical__ApplyAirResistance
188+
}
189+
}
190+
191+
template <unsigned int returnAddress>
192+
static void _declspec(naked) HOOK_VehicleRapidStopFix()
193+
{
194+
static unsigned int RETURN_VehicleRapidStopFix = returnAddress;
195+
_asm {
196+
fld ds:[0xC2B9CC] // mod_HandlingManager.m_fWheelFriction
197+
fmul ds:[0xB7CB5C] // CTimer::ms_fTimeStep
198+
fdiv kOriginalTimeStep // 1.666f
199+
jmp RETURN_VehicleRapidStopFix
200+
}
201+
}
202+
77203
#define HOOKPOS_CTimer__Update 0x561C5D
78204
#define HOOKSIZE_CTimer__Update 0xE
79205
static void _declspec(naked) HOOK_CTimer__Update()
@@ -470,6 +596,26 @@ void CMultiplayerSA::InitHooks_FrameRateFixes()
470596
EZHookInstall(CTaskSimpleUseGun__SetMoveAnim);
471597
EZHookInstall(CCamera__Process);
472598
EZHookInstall(CHeli__ProcessFlyingCarStuff);
599+
EZHookInstall(CClouds__MovingFog_Update);
600+
EZHookInstall(CFallingGlassPane__Update_A);
601+
EZHookInstall(CFallingGlassPane__Update_B);
602+
EZHookInstall(CFallingGlassPane__Update_C);
603+
EZHookInstall(CPhysical__ApplyAirResistance);
604+
605+
// CVehicle::ProcessWheel
606+
HookInstall(0x6D6E69, (DWORD)HOOK_VehicleRapidStopFix<0x6D6E6F>, 6);
607+
HookInstall(0x6D6EA8, (DWORD)HOOK_VehicleRapidStopFix<0x6D6EAE>, 6);
608+
609+
// CVehicle::ProcessBikeWheel
610+
HookInstall(0x6D767F, (DWORD)HOOK_VehicleRapidStopFix<0x6D7685>, 6);
611+
HookInstall(0x6D76AB, (DWORD)HOOK_VehicleRapidStopFix<0x6D76B1>, 6);
612+
HookInstall(0x6D76CD, (DWORD)HOOK_VehicleRapidStopFix<0x6D76D3>, 6);
613+
614+
// CCam::Process_FollowCar_SA
615+
MemSet((void*)0x524FD7, 0x90, 0x1B);
616+
617+
// CVehicle::ProcessBoatControl
618+
MemPut(0x6DC23F, &kOriginalTimeStep);
473619

474620
// CTimer::m_FrameCounter fixes
475621
EZHookInstall(CTimer__Update);

0 commit comments

Comments
 (0)