From 918535ff0fa5375b064ee1e0ef58bf5d4562d352 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 31 Jan 2023 00:03:40 +0100 Subject: [PATCH] Fix crash during bots simulation Wrong ptr to 'CUserCmd::Reset'. --- r5dev/game/server/physics_main.cpp | 6 +++--- r5dev/game/server/physics_main.h | 4 ++-- r5dev/game/shared/usercmd.h | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/r5dev/game/server/physics_main.cpp b/r5dev/game/server/physics_main.cpp index f45f4063..851adf41 100644 --- a/r5dev/game/server/physics_main.cpp +++ b/r5dev/game/server/physics_main.cpp @@ -27,7 +27,7 @@ void Physics_RunBotSimulation(bool bSimulating) if (pClient->IsActive() && pClient->IsFakeClient()) { - CPlayer* pPlayer = UTIL_PlayerByIndex(i + 1); + CPlayer* pPlayer = UTIL_PlayerByIndex(pClient->GetHandle()); if (pPlayer) pPlayer->RunNullCommand(); } @@ -37,10 +37,10 @@ void Physics_RunBotSimulation(bool bSimulating) //----------------------------------------------------------------------------- // Purpose: Runs the main physics simulation loop against all entities ( except players ) //----------------------------------------------------------------------------- -void* Physics_RunThinkFunctions(bool bSimulating) +void Physics_RunThinkFunctions(bool bSimulating) { Physics_RunBotSimulation(bSimulating); - return v_Physics_RunThinkFunctions(bSimulating); + v_Physics_RunThinkFunctions(bSimulating); } /////////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/game/server/physics_main.h b/r5dev/game/server/physics_main.h index f6fba56d..261c348f 100644 --- a/r5dev/game/server/physics_main.h +++ b/r5dev/game/server/physics_main.h @@ -8,7 +8,7 @@ #define PHYSICS_MAIN_H inline CMemory p_Physics_RunThinkFunctions; -inline auto v_Physics_RunThinkFunctions = p_Physics_RunThinkFunctions.RCast(); +inline auto v_Physics_RunThinkFunctions = p_Physics_RunThinkFunctions.RCast(); /////////////////////////////////////////////////////////////////////////////// class VPhysics_Main : public IDetour @@ -20,7 +20,7 @@ class VPhysics_Main : public IDetour virtual void GetFun(void) const { p_Physics_RunThinkFunctions = g_GameDll.FindPatternSIMD("88 4C 24 08 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ?? ?? ?? ??"); - v_Physics_RunThinkFunctions = p_Physics_RunThinkFunctions.RCast(); + v_Physics_RunThinkFunctions = p_Physics_RunThinkFunctions.RCast(); } virtual void GetVar(void) const { } virtual void GetCon(void) const { } diff --git a/r5dev/game/shared/usercmd.h b/r5dev/game/shared/usercmd.h index 0490f495..654dab22 100644 --- a/r5dev/game/shared/usercmd.h +++ b/r5dev/game/shared/usercmd.h @@ -33,7 +33,7 @@ class CUserCmd public: CUserCmd() // Cannot be constructed during DLL init. { - v_CUserCmd__Reset(this); + Reset(); } CUserCmd* Copy(CUserCmd* pSource) @@ -41,6 +41,11 @@ public: return v_CUserCmd__Copy(this, pSource); } + void Reset() + { + v_CUserCmd__Reset(this); + } + int32_t command_number; int32_t tick_count; float curtime; @@ -69,7 +74,7 @@ class VUserCmd : public IDetour } virtual void GetFun(void) const { - p_CUserCmd__Reset = g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 83 FD FF 74 0A").FollowNearCallSelf(); + p_CUserCmd__Reset = g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 48 8B DF 66 83 FE FF").FollowNearCallSelf(); v_CUserCmd__Reset = p_CUserCmd__Reset.RCast(); p_CUserCmd__Copy = g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 4C 8B 9B ?? ?? ?? ??").FollowNearCallSelf();