From ba825b9a6e2e4e53a5cf4374941da36a3b2c7ef9 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Sun, 24 Apr 2016 16:50:44 -0700 Subject: [PATCH] CS:GO fix for unreleased SteamWorks SDK (untested). --- Extension/swgameserver.cpp | 64 +++++++++++++++++++++++++++++++++++++- Extension/swgameserver.h | 1 + Extension/swgsdetours.cpp | 14 +-------- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/Extension/swgameserver.cpp b/Extension/swgameserver.cpp index c097be6..6829eae 100644 --- a/Extension/swgameserver.cpp +++ b/Extension/swgameserver.cpp @@ -60,7 +60,39 @@ void SteamWorksGameServer::Reset(void) ISteamClient *SteamWorksGameServer::GetSteamClient(void) { - return g_pSteamClientGameServer; + if (g_pSteamClientGameServer != NULL) + return g_pSteamClientGameServer; + + /* + The following is assumed from an unreleased version of the SteamWorks SDK, first seen (and reversed) in CS:GO. + Thanks CS:GO team! @:| + */ + + static ISteamClient *pSteamClient = NULL; + if (pSteamClient == NULL) + { + const char *pLibSteamPath = g_SteamWorks.pSWGameServer->GetLibraryPath(); + + ILibrary *pLibrary = libsys->OpenLibrary(pLibSteamPath, NULL, 0); + void *(*pGSInternalCreateAddress)(const char *) = NULL; + + if (pLibrary != NULL) + { + const char *pGSInternalFuncName = "SteamGameServerInternal_CreateInterface"; + + if (pGSInternalCreateAddress == NULL) + { + pGSInternalCreateAddress = static_cast(pLibrary->GetSymbolAddress(pGSInternalFuncName)); + } + + pLibrary->CloseLibrary(); + } + + if (pGSInternalCreateAddress != NULL) + pSteamClient = (*pGSInternalCreateAddress)(STEAMCLIENT_INTERFACE_VERSION); + } + + return pSteamClient; } ISteamGameServer *SteamWorksGameServer::GetGameServer(void) @@ -178,3 +210,33 @@ void SteamWorksGameServer::GetUserAndPipe(HSteamUser &hSteamUser, HSteamPipe &hS hSteamUser = SteamGameServer_GetHSteamUser(); hSteamPipe = SteamGameServer_GetHSteamPipe(); } + +const char *SteamWorksGameServer::GetLibraryPath(void) +{ + static const char *pLibSteamPath = NULL; + + if (pLibSteamPath == NULL) + { +#if defined POSIX + pLibSteamPath = "./bin/libsteam_api.so"; +#elif defined WIN32_LEAN_AND_MEAN + pLibSteamPath = "./bin/steam_api.dll"; /* Naming from SteamTools. */ +#endif + + IGameConfig *pConfig = NULL; + if (g_SteamWorks.pSWGameData) + { + pConfig = g_SteamWorks.pSWGameData->GetGameData(); + if (pConfig) + { + const char *kvLibSteamAPI = pConfig->GetKeyValue("LibSteamAPI"); + if (kvLibSteamAPI) + { + pLibSteamPath = kvLibSteamAPI; + } + } + } + } + + return pLibSteamPath; +} diff --git a/Extension/swgameserver.h b/Extension/swgameserver.h index ae56bde..90b5b52 100644 --- a/Extension/swgameserver.h +++ b/Extension/swgameserver.h @@ -39,6 +39,7 @@ class SteamWorksGameServer public: void Reset(void); + const char *GetLibraryPath(void); private: void GetUserAndPipe(HSteamUser &hSteamUser, HSteamPipe &hSteamPipe); private: diff --git a/Extension/swgsdetours.cpp b/Extension/swgsdetours.cpp index 1f73525..e1148ea 100644 --- a/Extension/swgsdetours.cpp +++ b/Extension/swgsdetours.cpp @@ -47,24 +47,12 @@ DETOUR_DECL_STATIC6(SteamGameServer_InitSafeDetour, bool, uint32, unIP, uint16, SteamWorksGSDetours::SteamWorksGSDetours() { -#if defined POSIX - const char *pLibSteamPath = "./bin/libsteam_api.so"; -#elif defined WIN32_LEAN_AND_MEAN - const char *pLibSteamPath = "./bin/steam_api.dll"; /* Naming from SteamTools. */ -#endif + const char *pLibSteamPath = g_SteamWorks.pSWGameServer->GetLibraryPath(); IGameConfig *pConfig = NULL; if (g_SteamWorks.pSWGameData) { pConfig = g_SteamWorks.pSWGameData->GetGameData(); - if (pConfig) - { - const char *kvLibSteamAPI = pConfig->GetKeyValue("LibSteamAPI"); - if (kvLibSteamAPI) - { - pLibSteamPath = kvLibSteamAPI; - } - } } ILibrary *pLibrary = libsys->OpenLibrary(pLibSteamPath, NULL, 0);