diff --git a/Extension/CDetour/detours.h b/Extension/CDetour/detours.h index 42c55a5..c68d299 100644 --- a/Extension/CDetour/detours.h +++ b/Extension/CDetour/detours.h @@ -60,6 +60,10 @@ ret name(p1type p1name) ret (*name##_Actual)(p1type, p2type, p3type, p4type) = NULL; \ ret name(p1type p1name, p2type p2name, p3type p3name, p4type p4name) +#define DETOUR_DECL_STATIC6(name, ret, p1type, p1name, p2type, p2name, p3type, p3name, p4type, p4name, p5type, p5name, p6type, p6name) \ +ret (*name##_Actual)(p1type, p2type, p3type, p4type, p5type, p6type) = NULL; \ +ret name(p1type p1name, p2type p2name, p3type p3name, p4type p4name, p5type p5name, p6type p6name) + #define DETOUR_DECL_MEMBER0(name, ret) \ class name##Class \ { \ diff --git a/Extension/swgsdetours.cpp b/Extension/swgsdetours.cpp index 225dbdc..03b3119 100644 --- a/Extension/swgsdetours.cpp +++ b/Extension/swgsdetours.cpp @@ -34,6 +34,13 @@ DETOUR_DECL_STATIC0(SteamAPIShutdown, void) DETOUR_STATIC_CALL(SteamAPIShutdown)(); /* We're not a monster. */ } +DETOUR_DECL_STATIC6(SteamGameServer_InitSafe, bool, uint32, unIP, uint16, usSteamPort, uint16, usGamePort, uint16, usQueryPort, EServerMode, eServerMode, const char *, pchVersionString) +{ + bool bRet = DETOUR_STATIC_CALL(SteamGameServer_InitSafe)(unIP, usSteamPort, usGamePort, usQueryPort, eServerMode, pchVersionString); /* Call to init game interfaces. */ + + return bRet; +} + SteamWorksGSDetours::SteamWorksGSDetours() { #if defined POSIX @@ -53,29 +60,50 @@ SteamWorksGSDetours::SteamWorksGSDetours() } ILibrary *pLibrary = libsys->OpenLibrary(pLibSteamPath, NULL, 0); - void *pAddress = NULL; + void *pSteamSafeInitAddress = NULL; + void *pSteamShutdownAddress = NULL; if (pLibrary != NULL) { - const char *pFunctionName = "SteamGameServer_Shutdown"; - if (pConfig == NULL || pConfig->GetMemSig(pFunctionName, &pAddress) == false) + const char *pInitSafeFuncName = "SteamGameServer_InitSafe"; + const char *pShutdownFuncName = "SteamGameServer_Shutdown"; + if (pConfig != NULL) { - pAddress = pLibrary->GetSymbolAddress(pFunctionName); + pConfig->GetMemSig(pShutdownFuncName, &pSteamShutdownAddress); + pConfig->GetMemSig(pInitSafeFuncName, &pSteamSafeInitAddress); + } + + if (pSteamShutdownAddress == NULL) + { + pSteamShutdownAddress = pLibrary->GetSymbolAddress(pShutdownFuncName); + } + + if (pSteamSafeInitAddress == NULL) + { + pSteamSafeInitAddress = pLibrary->GetSymbolAddress(pInitSafeFuncName); } pLibrary->CloseLibrary(); } - if (pAddress == NULL) + CDetourManager::Init(g_pSM->GetScriptingEngine(), pConfig); + if (pSteamShutdownAddress != NULL) + { + this->m_pShutdownDetour = DETOUR_CREATE_STATIC_FIXED(SteamAPIShutdown, pSteamShutdownAddress); + this->m_pShutdownDetour->EnableDetour(); + } + else { this->m_pShutdownDetour = NULL; - return; } - CDetourManager::Init(g_pSM->GetScriptingEngine(), pConfig); - this->m_pShutdownDetour = DETOUR_CREATE_STATIC_FIXED(SteamAPIShutdown, pAddress); - if (this->m_pShutdownDetour != NULL) + if (pSteamSafeInitAddress != NULL) { - this->m_pShutdownDetour->EnableDetour(); + this->m_pSafeInitDetour = DETOUR_CREATE_STATIC_FIXED(SteamGameServer_InitSafe, pSteamSafeInitAddress); + this->m_pSafeInitDetour->EnableDetour(); + } + else + { + this->m_pSafeInitDetour = NULL; } } @@ -86,4 +114,10 @@ SteamWorksGSDetours::~SteamWorksGSDetours() this->m_pShutdownDetour->Destroy(); this->m_pShutdownDetour = NULL; } + + if (this->m_pSafeInitDetour != NULL) + { + this->m_pSafeInitDetour->Destroy(); + this->m_pSafeInitDetour = NULL; + } } diff --git a/Extension/swgsdetours.h b/Extension/swgsdetours.h index 678030b..b9d74d0 100644 --- a/Extension/swgsdetours.h +++ b/Extension/swgsdetours.h @@ -29,6 +29,7 @@ class SteamWorksGSDetours ~SteamWorksGSDetours(); private: + CDetour *m_pSafeInitDetour; CDetour *m_pShutdownDetour; };