Skip to content

Commit e64d311

Browse files
authored
Fix walking while aiming on higher fps (#502) (#2663)
1 parent 6b854c4 commit e64d311

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

Client/mods/deathmatch/CClient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ int CClient::ClientInitialize(const char* szArguments, CCoreInterface* pCore)
128128
pCore->GetCommands()->Add("debug2", "debug function 2", COMMAND_Debug2);
129129
pCore->GetCommands()->Add("debug3", "debug function 3", COMMAND_Debug3);
130130
pCore->GetCommands()->Add("debug4", "debug function 4", COMMAND_Debug4);
131+
pCore->GetCommands()->Add("timestep", "timestep", COMMAND_TimeStep);
131132
#endif
132133

133134
// Got any arguments?

Client/mods/deathmatch/ClientCommands.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,12 @@ void COMMAND_Debug4(const char* szCmdLine)
10351035
g_pClientGame->StartPlayback();
10361036
return;
10371037
}
1038+
1039+
void COMMAND_TimeStep(const char* szCmdLine)
1040+
{
1041+
g_pCore->GetConsole()->Printf("TimeStep: %f", *(float*)0xB7CB5C); // CTimer::ms_fTimeStep
1042+
}
1043+
10381044
#endif
10391045

10401046
void COMMAND_ShowCollision(const char* szCmdLine)

Client/mods/deathmatch/ClientCommands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void COMMAND_Debug(const char* szCmdLine);
8080
void COMMAND_Debug2(const char* szCmdLine);
8181
void COMMAND_Debug3(const char* szCmdLine);
8282
void COMMAND_Debug4(const char* szCmdLine);
83+
void COMMAND_TimeStep(const char* szCmdLine);
8384
#endif
8485

8586
// Commands enabled when development mode in on

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,7 @@ void CMultiplayerSA::InitHooks()
15661566
InitHooks_VehicleWeapons();
15671567

15681568
InitHooks_Streaming();
1569+
InitHooks_FrameRateFixes();
15691570
}
15701571

15711572
// Used to store copied pointers for explosions in the FxSystem

Client/multiplayer_sa/CMultiplayerSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CMultiplayerSA : public CMultiplayer
7878
void InitHooks_Direct3D();
7979
void InitHooks_FixLineOfSightArgs();
8080
void InitHooks_Streaming();
81+
void InitHooks_FrameRateFixes();
8182
CRemoteDataStorage* CreateRemoteDataStorage();
8283
void DestroyRemoteDataStorage(CRemoteDataStorage* pData);
8384
void AddRemoteDataStorage(CPlayerPed* pPed, CRemoteDataStorage* pData);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp
6+
*
7+
* Multi Theft Auto is available from https://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#include "StdInc.h"
12+
13+
constexpr float kOriginalTimeStep = 50.0f / 30.0f;
14+
15+
#define HOOKPOS_CTaskSimpleUseGun__SetMoveAnim 0x61E4F2
16+
#define HOOKSIZE_CTaskSimpleUseGun__SetMoveAnim 0x6
17+
const unsigned int RETURN_CTaskSimpleUseGun__SetMoveAnim = 0x61E4F8;
18+
19+
void _declspec(naked) HOOK_CTaskSimpleUseGun__SetMoveAnim()
20+
{
21+
_asm {
22+
fld ds:[0xB7CB5C] // CTimer::ms_fTimeStep
23+
fdiv kOriginalTimeStep // 1.666f
24+
fmul ds:[0x858B1C] // 0.1f
25+
fxch
26+
fcom
27+
fxch
28+
fstp st(0)
29+
jmp RETURN_CTaskSimpleUseGun__SetMoveAnim
30+
}
31+
}
32+
33+
void CMultiplayerSA::InitHooks_FrameRateFixes()
34+
{
35+
EZHookInstall(CTaskSimpleUseGun__SetMoveAnim);
36+
}

0 commit comments

Comments
 (0)