From 811ecade86c12ac1248eb798f68ca6e65cc24bc4 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 5 Nov 2022 00:12:45 +0100 Subject: [PATCH] Replace CServer::Think with CServer::FrameJob Actual hook where we could also run anything in the server frame thread (the earliest function where equality to server thread id could be performed). --- r5dev/engine/server/server.cpp | 15 ++++++++++++++- r5dev/engine/server/server.h | 11 ++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/r5dev/engine/server/server.cpp b/r5dev/engine/server/server.cpp index d990b043..8fece3aa 100644 --- a/r5dev/engine/server/server.cpp +++ b/r5dev/engine/server/server.cpp @@ -122,7 +122,7 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge) //--------------------------------------------------------------------------------- // Purpose: Rejects connection request and sends back a message -// Input : *iSocket - +// Input : iSocket - // *pChallenge - // *szMessage - //--------------------------------------------------------------------------------- @@ -131,15 +131,28 @@ void CServer::RejectConnection(int iSocket, v_netadr_t* pNetAdr, const char* szM v_CServer_RejectConnection(this, iSocket, pNetAdr, szMessage); } +//--------------------------------------------------------------------------------- +// Purpose: Runs the server frame +// Input : flFrameTime - +// bRunOverlays - +// bUniformSnapshotInterval - +//--------------------------------------------------------------------------------- +void CServer::FrameJob(double flFrameTime, bool bRunOverlays, bool bUniformSnapshotInterval) +{ + v_CServer_FrameJob(flFrameTime, bRunOverlays, bUniformSnapshotInterval); +} + /////////////////////////////////////////////////////////////////////////////// void CServer_Attach() { DetourAttach((LPVOID*)&v_CServer_ConnectClient, &CServer::ConnectClient); + DetourAttach((LPVOID*)&v_CServer_FrameJob, &CServer::FrameJob); } void CServer_Detach() { DetourDetach((LPVOID*)&v_CServer_ConnectClient, &CServer::ConnectClient); + DetourDetach((LPVOID*)&v_CServer_FrameJob, &CServer::FrameJob); } /////////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/engine/server/server.h b/r5dev/engine/server/server.h index 3ec032af..2b62ebfe 100644 --- a/r5dev/engine/server/server.h +++ b/r5dev/engine/server/server.h @@ -43,6 +43,7 @@ public: bool AuthClient(user_creds_s* pChallenge); void RejectConnection(int iSocket, v_netadr_t* pNetAdr, const char* szMessage); static CClient* ConnectClient(CServer* pServer, user_creds_s* pChallenge); + static void FrameJob(double flFrameTime, bool bRunOverlays, bool bUniformSnapshotInterval); #endif // !CLIENT_DLL private: @@ -84,8 +85,8 @@ static_assert(sizeof(CServer) == 0x4A4C0); extern CServer* g_pServer; /* ==== CSERVER ========================================================================================================================================================= */ -inline CMemory p_CServer_Think; -inline auto v_CServer_Think = p_CServer_Think.RCast(); +inline CMemory p_CServer_FrameJob; +inline auto v_CServer_FrameJob = p_CServer_FrameJob.RCast(); inline CMemory p_CServer_Authenticate; inline auto v_CServer_ConnectClient = p_CServer_Authenticate.RCast(); @@ -104,7 +105,7 @@ class VServer : public IDetour virtual void GetAdr(void) const { #ifndef CLIENT_DLL - spdlog::debug("| FUN: CServer::Think : {:#18x} |\n", p_CServer_Think.GetPtr()); + spdlog::debug("| FUN: CServer::FrameJob : {:#18x} |\n", p_CServer_FrameJob.GetPtr()); spdlog::debug("| FUN: CServer::ConnectClient : {:#18x} |\n", p_CServer_Authenticate.GetPtr()); spdlog::debug("| FUN: CServer::RejectConnection : {:#18x} |\n", p_CServer_RejectConnection.GetPtr()); spdlog::debug("| VAR: g_pServer[128] : {:#18x} |\n", reinterpret_cast(g_pServer)); @@ -114,7 +115,7 @@ class VServer : public IDetour virtual void GetFun(void) const { #ifndef CLIENT_DLL - p_CServer_Think = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x81\xEC\x00\x00\x00\x00\x80\x3D\x00\x00\x00\x00\x00"), "xxxx?xxxx?xxxx????xx?????"); + p_CServer_FrameJob = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x6C\x24\x00\x56\x41\x54\x41\x56"), "xxxx?xxxxx"); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) p_CServer_Authenticate = g_GameDll.FindPatternSIMD(reinterpret_cast("\x44\x89\x44\x24\x00\x55\x56\x57\x48\x8D\xAC\x24\x00\x00\x00\x00"), "xxxx?xxxxxxx????"); #elif defined (GAMEDLL_S2) @@ -124,7 +125,7 @@ class VServer : public IDetour #endif p_CServer_RejectConnection = g_GameDll.FindPatternSIMD(reinterpret_cast("\x4C\x89\x4C\x24\x00\x53\x55\x56\x57\x48\x81\xEC\x00\x00\x00\x00\x49\x8B\xD9"), "xxxx?xxxxxxx????xxx"); - v_CServer_Think = p_CServer_Think.RCast(); /*48 89 5C 24 ?? 48 89 74 24 ?? 57 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ??*/ + v_CServer_FrameJob = p_CServer_FrameJob.RCast(); /*48 89 6C 24 ?? 56 41 54 41 56*/ v_CServer_ConnectClient = p_CServer_Authenticate.RCast(); /*40 55 57 41 55 41 57 48 8D AC 24 ?? ?? ?? ??*/ v_CServer_RejectConnection = p_CServer_RejectConnection.RCast(); /*4C 89 4C 24 ?? 53 55 56 57 48 81 EC ?? ?? ?? ?? 49 8B D9*/ #endif // !CLIENT_DLL