From 3e246a9d27fb7c9ecad80c237c6e85b182d78303 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 18 Feb 2023 11:42:36 +0100 Subject: [PATCH] CServer improvements * Added new member 'm_nSpawnCount'. * Added hook for 'CServer::RunFrame'. * Abstract class 'IServer' no longer exists in this engine, inherit from 'IConnectionlessPacketHandler' instead (see RTTI in engine executable). --- r5dev/engine/server/server.cpp | 13 ++++++++++++- r5dev/engine/server/server.h | 32 +++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/r5dev/engine/server/server.cpp b/r5dev/engine/server/server.cpp index 0cc35222..fe617180 100644 --- a/r5dev/engine/server/server.cpp +++ b/r5dev/engine/server/server.cpp @@ -152,7 +152,7 @@ void CServer::RejectConnection(int iSocket, netadr_t* pNetAdr, const char* szMes } //--------------------------------------------------------------------------------- -// Purpose: Runs the server frame +// Purpose: Runs the server frame job // Input : flFrameTime - // bRunOverlays - // bUniformSnapshotInterval - @@ -162,9 +162,19 @@ void CServer::FrameJob(double flFrameTime, bool bRunOverlays, bool bUniformSnaps v_CServer_FrameJob(flFrameTime, bRunOverlays, bUniformSnapshotInterval); } +//--------------------------------------------------------------------------------- +// Purpose: Runs the server frame +// Input : *pServer - +//--------------------------------------------------------------------------------- +void CServer::RunFrame(CServer* pServer) +{ + v_CServer_RunFrame(pServer); +} + /////////////////////////////////////////////////////////////////////////////// void VServer::Attach() const { + DetourAttach(&v_CServer_RunFrame, &CServer::RunFrame); #if defined(GAMEDLL_S3) DetourAttach((LPVOID*)&v_CServer_ConnectClient, &CServer::ConnectClient); DetourAttach((LPVOID*)&v_CServer_FrameJob, &CServer::FrameJob); @@ -173,6 +183,7 @@ void VServer::Attach() const void VServer::Detach() const { + DetourDetach(&v_CServer_RunFrame, &CServer::RunFrame); #if defined(GAMEDLL_S3) 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 bcfcba80..7f428a52 100644 --- a/r5dev/engine/server/server.h +++ b/r5dev/engine/server/server.h @@ -26,7 +26,7 @@ struct user_creds_s char* m_pUserID; }; -class CServer : public IServer +class CServer : public IConnectionlessPacketHandler { public: int GetTick(void) const { return m_nTickCount; } @@ -45,6 +45,7 @@ public: bool AuthClient(user_creds_s* pChallenge); void RejectConnection(int iSocket, netadr_t* pNetAdr, const char* szMessage); static CClient* ConnectClient(CServer* pServer, user_creds_s* pChallenge); + static void RunFrame(CServer* pServer); static void FrameJob(double flFrameTime, bool bRunOverlays, bool bUniformSnapshotInterval); #endif // !CLIENT_DLL @@ -72,13 +73,15 @@ private: int m_nServerClasses; // number of unique server classes int m_nServerClassBits; // log2 of serverclasses char m_szHostInfo[128]; // see '[r5apex_ds.exe + 0x237740]' for more details. fmt: '[IPv6]:PORT:TIMEi64u' - char m_nGap0[640]; + char m_nGap0[520]; + int m_nSpawnCount; + char m_nGap1[116]; float m_fCPUPercent; float m_fStartTime; float m_fLastCPUCheckTime; - char m_nGap1[303108]; // TODO: Reverse the rest in this gap. + char m_nGap2[303108]; // TODO: Reverse the rest in this gap. #if defined (GAMEDLL_S2) || defined (GAMEDLL_S3) - char m_nGap2[0x80]; + char m_nGap3[0x80]; #endif }; #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) @@ -93,8 +96,11 @@ extern CServer* g_pServer; 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(); +inline CMemory p_CServer_RunFrame; +inline auto v_CServer_RunFrame = p_CServer_RunFrame.RCast(); + +inline CMemory p_CServer_ConnectClient; +inline auto v_CServer_ConnectClient = p_CServer_ConnectClient.RCast(); inline CMemory p_CServer_RejectConnection; inline auto v_CServer_RejectConnection = p_CServer_RejectConnection.RCast(); @@ -106,7 +112,8 @@ class VServer : public IDetour { #ifndef CLIENT_DLL LogFunAdr("CServer::FrameJob", p_CServer_FrameJob.GetPtr()); - LogFunAdr("CServer::ConnectClient", p_CServer_Authenticate.GetPtr()); + LogFunAdr("CServer::RunFrame", p_CServer_RunFrame.GetPtr()); + LogFunAdr("CServer::ConnectClient", p_CServer_ConnectClient.GetPtr()); LogFunAdr("CServer::RejectConnection", p_CServer_RejectConnection.GetPtr()); LogVarAdr("g_Server[128]", reinterpret_cast(g_pServer)); #endif // !CLIENT_DLL @@ -120,12 +127,19 @@ class VServer : public IDetour #elif defined (GAMEDLL_S2) p_CServer_Authenticate = g_GameDll.FindPatternSIMD("44 89 44 24 ?? 56 57 48 81 EC ?? ?? ?? ??"); #else - p_CServer_Authenticate = g_GameDll.FindPatternSIMD("40 55 57 41 55 41 57 48 8D AC 24 ?? ?? ?? ??"); + p_CServer_ConnectClient = g_GameDll.FindPatternSIMD("40 55 57 41 55 41 57 48 8D AC 24 ?? ?? ?? ??"); +#endif + +#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) + p_CServer_RunFrame = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 55 56 57 48 81 EC ?? ?? ?? ?? 0F 29 B4 24 ?? ?? ?? ??"); +#else + p_CServer_RunFrame = g_GameDll.FindPatternSIMD("40 53 55 56 57 41 56 48 81 EC ?? ?? ?? ?? 0F 29 B4 24 ?? ?? ?? ??"); #endif p_CServer_RejectConnection = g_GameDll.FindPatternSIMD("4C 89 4C 24 ?? 53 55 56 57 48 81 EC ?? ?? ?? ?? 49 8B D9"); 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_RunFrame = p_CServer_RunFrame.RCast(); + v_CServer_ConnectClient = p_CServer_ConnectClient.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 }