From d9fa61141890bc8f2f86283ed7553bb76281a7a9 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 25 Apr 2023 00:46:45 +0200 Subject: [PATCH] Add new callbacks to server functions A few new callback hooks which are perhaps useful in the future. --- r5dev/engine/server/sv_main.cpp | 47 ++++++++++++++++++++++++++++++++- r5dev/engine/server/sv_main.h | 25 ++++++++++++------ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/r5dev/engine/server/sv_main.cpp b/r5dev/engine/server/sv_main.cpp index f01d88b5..05913471 100644 --- a/r5dev/engine/server/sv_main.cpp +++ b/r5dev/engine/server/sv_main.cpp @@ -1,6 +1,12 @@ +//===========================================================================// +// +// Purpose: +// +//===========================================================================// #include "core/stdafx.h" #include "tier0/threadtools.h" #include "tier0/frametask.h" +#include "tier1/cvar.h" #include "engine/server/sv_main.h" #include "networksystem/pylon.h" #include "networksystem/bansystem.h" @@ -26,4 +32,43 @@ void SV_IsClientBanned(const string& svIPAddr, const uint64_t nNucleusID) } } -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//----------------------------------------------------------------------------- +// Purpose: loads the game .dll +//----------------------------------------------------------------------------- +void SV_InitGameDLL() +{ + v_SV_InitGameDLL(); +} + +//----------------------------------------------------------------------------- +// Purpose: release resources associated with extension DLLs. +//----------------------------------------------------------------------------- +void SV_ShutdownGameDLL() +{ + v_SV_ShutdownGameDLL(); +} + +//----------------------------------------------------------------------------- +// Purpose: activates the server +// Output : true on success, false on failure +//----------------------------------------------------------------------------- +bool SV_ActivateServer() +{ + return v_SV_ActivateServer(); +} + +/////////////////////////////////////////////////////////////////////////////// + +void HSV_Main::Attach() const +{ + //DetourAttach(&v_SV_InitGameDLL, SV_InitGameDLL); + //DetourAttach(&v_SV_ShutdownGameDLL, SV_ShutdownGameDLL); + //DetourAttach(&v_SV_ActivateServer, SV_ActivateServer); +} + +void HSV_Main::Detach() const +{ + //DetourDetach(&v_SV_InitGameDLL, SV_InitGameDLL); + //DetourDetach(&v_SV_ShutdownGameDLL, SV_ShutdownGameDLL); + //DetourDetach(&v_SV_ActivateServer, SV_ActivateServer); +} \ No newline at end of file diff --git a/r5dev/engine/server/sv_main.h b/r5dev/engine/server/sv_main.h index 0beff5d5..7428c2c5 100644 --- a/r5dev/engine/server/sv_main.h +++ b/r5dev/engine/server/sv_main.h @@ -6,13 +6,16 @@ /* ==== SV_MAIN ======================================================================================================================================================= */ inline CMemory p_SV_InitGameDLL; -inline auto SV_InitGameDLL = p_SV_InitGameDLL.RCast(); +inline auto v_SV_InitGameDLL = p_SV_InitGameDLL.RCast(); inline CMemory p_SV_ShutdownGameDLL; -inline auto SV_ShutdownGameDLL = p_SV_ShutdownGameDLL.RCast(); +inline auto v_SV_ShutdownGameDLL = p_SV_ShutdownGameDLL.RCast(); + +inline CMemory p_SV_ActivateServer; +inline auto v_SV_ActivateServer = p_SV_ActivateServer.RCast(); inline CMemory p_SV_CreateBaseline; -inline auto SV_CreateBaseline = p_SV_CreateBaseline.RCast(); +inline auto v_SV_CreateBaseline = p_SV_CreateBaseline.RCast(); inline CMemory p_CGameServer__SpawnServer; inline auto CGameServer__SpawnServer = p_CGameServer__SpawnServer.RCast(); @@ -21,6 +24,9 @@ inline bool* s_bIsDedicated = nullptr; /////////////////////////////////////////////////////////////////////////////// +void SV_InitGameDLL(); +void SV_ShutdownGameDLL(); +bool SV_ActivateServer(); void SV_IsClientBanned(const string& svIPAddr, const uint64_t nNucleusID); /////////////////////////////////////////////////////////////////////////////// @@ -32,6 +38,7 @@ class HSV_Main : public IDetour LogFunAdr("CGameServer::SpawnServer", p_CGameServer__SpawnServer.GetPtr()); LogFunAdr("SV_InitGameDLL", p_SV_InitGameDLL.GetPtr()); LogFunAdr("SV_ShutdownGameDLL", p_SV_ShutdownGameDLL.GetPtr()); + LogFunAdr("SV_ActivateServer", p_SV_ActivateServer.GetPtr()); LogFunAdr("SV_CreateBaseline", p_SV_CreateBaseline.GetPtr()); LogVarAdr("s_bIsDedicated", reinterpret_cast(s_bIsDedicated)); } @@ -39,6 +46,7 @@ class HSV_Main : public IDetour { p_SV_InitGameDLL = g_GameDll.FindPatternSIMD("48 81 EC ?? ?? ?? ?? E8 ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 0F 85 ?? ?? ?? ??"); p_SV_ShutdownGameDLL = g_GameDll.FindPatternSIMD("48 83 EC 28 80 3D ?? ?? ?? ?? ?? 0F 84 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ?? 48"); + p_SV_CreateBaseline = g_GameDll.FindPatternSIMD("48 8B C4 56 48 81 EC ?? ?? ?? ?? 48 89 ?? ?? 48 8D"); p_SV_CreateBaseline = g_GameDll.FindPatternSIMD("48 83 EC 28 48 8B 0D ?? ?? ?? ?? 48 85 C9 75 07"); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) p_CGameServer__SpawnServer = g_GameDll.FindPatternSIMD("40 53 55 56 57 41 55 41 56 41 57 48 81 EC ?? ?? ?? ??"); @@ -46,9 +54,10 @@ class HSV_Main : public IDetour p_CGameServer__SpawnServer = g_GameDll.FindPatternSIMD("48 8B C4 53 55 56 57 41 54 41 55 41 57"); // 0x140312D80 // 48 8B C4 53 55 56 57 41 54 41 55 41 57 // #endif - SV_InitGameDLL = p_SV_InitGameDLL.RCast(); - SV_ShutdownGameDLL = p_SV_ShutdownGameDLL.RCast(); - SV_CreateBaseline = p_SV_CreateBaseline.RCast(); + v_SV_InitGameDLL = p_SV_InitGameDLL.RCast(); + v_SV_ShutdownGameDLL = p_SV_ShutdownGameDLL.RCast(); + v_SV_ActivateServer = p_SV_CreateBaseline.RCast(); + v_SV_CreateBaseline = p_SV_CreateBaseline.RCast(); CGameServer__SpawnServer = p_CGameServer__SpawnServer.RCast(); } virtual void GetVar(void) const @@ -57,7 +66,7 @@ class HSV_Main : public IDetour .FindPatternSelf("40 38 3D", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); } virtual void GetCon(void) const { } - virtual void Attach(void) const { } - virtual void Detach(void) const { } + virtual void Attach(void) const; + virtual void Detach(void) const; }; ///////////////////////////////////////////////////////////////////////////////