From 82c914c2fdf14dd9bc99afa0a5c5d047f7fa7130 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 19 Jan 2023 22:53:45 +0100 Subject: [PATCH] Detour 'Physics_RunThinkFunctions' Hook will be used to run simulation for bots. --- r5dev/core/init.cpp | 5 ++++ r5dev/game/server/physics_main.cpp | 28 +++++++++++++++++++++ r5dev/game/server/physics_main.h | 36 +++++++++++++++++++++++++++ r5dev/vproj/dedicated.vcxproj | 2 ++ r5dev/vproj/dedicated.vcxproj.filters | 6 +++++ r5dev/vproj/gamesdk.vcxproj | 2 ++ r5dev/vproj/gamesdk.vcxproj.filters | 6 +++++ 7 files changed, 85 insertions(+) create mode 100644 r5dev/game/server/physics_main.cpp create mode 100644 r5dev/game/server/physics_main.h diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index e5ecea2e..1d5261c8 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -109,6 +109,7 @@ #include "game/server/fairfight_impl.h" #include "game/server/gameinterface.h" #include "game/server/movehelper_server.h" +#include "game/server/physics_main.h" #endif // !CLIENT_DLL #ifndef DEDICATED #include "game/client/viewrender.h" @@ -212,6 +213,8 @@ void Systems_Init() Persistence_Attach(); IVEngineServer_Attach(); CServerGameDLL_Attach(); + + Physics_Main_Attach(); #endif // !CLIENT_DLL SQAPI_Attach(); @@ -347,6 +350,8 @@ void Systems_Shutdown() Persistence_Detach(); IVEngineServer_Detach(); CServerGameDLL_Detach(); + + Physics_Main_Detach(); #endif // !CLIENT_DLL SQAPI_Detach(); SQVM_Detach(); diff --git a/r5dev/game/server/physics_main.cpp b/r5dev/game/server/physics_main.cpp new file mode 100644 index 00000000..0990f820 --- /dev/null +++ b/r5dev/game/server/physics_main.cpp @@ -0,0 +1,28 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======// +// +// Purpose: Physics simulation for non-havok/ipion objects +// +// $NoKeywords: $ +//=============================================================================// +#include "core/stdafx.h" +#include "player.h" +#include "physics_main.h" + +//----------------------------------------------------------------------------- +// Purpose: Runs the main physics simulation loop against all entities ( except players ) +//----------------------------------------------------------------------------- +void Physics_RunThinkFunctions(bool bSimulating) +{ + v_Physics_RunThinkFunctions(bSimulating); +} + +/////////////////////////////////////////////////////////////////////////////// +void Physics_Main_Attach() +{ + DetourAttach(&v_Physics_RunThinkFunctions, &Physics_RunThinkFunctions); +} + +void Physics_Main_Detach() +{ + DetourDetach(&v_Physics_RunThinkFunctions, &Physics_RunThinkFunctions); +} \ No newline at end of file diff --git a/r5dev/game/server/physics_main.h b/r5dev/game/server/physics_main.h new file mode 100644 index 00000000..4499814c --- /dev/null +++ b/r5dev/game/server/physics_main.h @@ -0,0 +1,36 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#ifndef PHYSICS_MAIN_H +#define PHYSICS_MAIN_H + +inline CMemory p_Physics_RunThinkFunctions; +inline auto v_Physics_RunThinkFunctions = p_Physics_RunThinkFunctions.RCast(); + +void Physics_Main_Attach(); +void Physics_Main_Detach(); +/////////////////////////////////////////////////////////////////////////////// +class VPhysics_Main : public IDetour +{ + virtual void GetAdr(void) const + { + spdlog::debug("| FUN: Physics_RunThinkFunctions : {:#18x} |\n", p_Physics_RunThinkFunctions.GetPtr()); + spdlog::debug("+----------------------------------------------------------------+\n"); + } + 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(); + } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(VPhysics_Main); +#endif // PHYSICS_MAIN_H diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index 50c193d3..80690828 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -187,6 +187,7 @@ + @@ -556,6 +557,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index a732d08a..de3c3e52 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1371,6 +1371,9 @@ sdk\game\shared + + sdk\game\server + @@ -1730,6 +1733,9 @@ sdk\game\server + + sdk\game\server + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index 185c64d0..9dd720ef 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -72,6 +72,7 @@ + @@ -265,6 +266,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 9f49ebec..e2ae0704 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -717,6 +717,9 @@ sdk\game\client + + sdk\game\server + @@ -2093,6 +2096,9 @@ sdk\game\client + + sdk\game\server +