From d701f286bfcd6d26f8b6959900bc37f76b4dcb60 Mon Sep 17 00:00:00 2001 From: KyleSanderson Date: Wed, 5 Feb 2014 22:05:06 -0700 Subject: [PATCH] Add SteamWorks_TokenRequested for authenticated GameServer logins. --- Extension/swgsdetours.cpp | 5 +++++ Extension/swgshooks.cpp | 29 +++++++++++++++++++++++++++++ Extension/swgshooks.h | 2 ++ 3 files changed, 36 insertions(+) diff --git a/Extension/swgsdetours.cpp b/Extension/swgsdetours.cpp index 03b3119..4d04557 100644 --- a/Extension/swgsdetours.cpp +++ b/Extension/swgsdetours.cpp @@ -38,6 +38,11 @@ DETOUR_DECL_STATIC6(SteamGameServer_InitSafe, bool, uint32, unIP, uint16, usStea { bool bRet = DETOUR_STATIC_CALL(SteamGameServer_InitSafe)(unIP, usSteamPort, usGamePort, usQueryPort, eServerMode, pchVersionString); /* Call to init game interfaces. */ + if (g_SteamWorks.pSWGameServer != NULL && g_SteamWorks.pGSHooks != NULL) + { + g_SteamWorks.pGSHooks->AddHooks(g_SteamWorks.pSWGameServer->GetGameServer()); + } + return bRet; } diff --git a/Extension/swgshooks.cpp b/Extension/swgshooks.cpp index f0c280f..90e18b9 100644 --- a/Extension/swgshooks.cpp +++ b/Extension/swgshooks.cpp @@ -27,6 +27,7 @@ enum }; SH_DECL_HOOK0(ISteamGameServer, WasRestartRequested, SH_NOATTRIB, 0, bool); /* From SteamTools. */ +SH_DECL_HOOK0_void(ISteamGameServer, LogOnAnonymous, SH_NOATTRIB, 0); /* From VoiDeD's MM:S plugin. */ static ISteamGameServer *GetGameServerPointer() { @@ -37,6 +38,7 @@ SteamWorksGSHooks::SteamWorksGSHooks() { this->uHooked = eHooking; this->pFORR = forwards->CreateForward("SteamWorks_RestartRequested", ET_Hook, 0, NULL); + this->pFOTR = forwards->CreateForward("SteamWorks_TokenRequested", ET_Ignore, 2, NULL, Param_String, Param_Cell); smutils->AddGameFrameHook(OurGameFrameHook); } @@ -46,6 +48,31 @@ SteamWorksGSHooks::~SteamWorksGSHooks() this->RemoveHooks(GetGameServerPointer(), true); smutils->RemoveGameFrameHook(OurGameFrameHook); forwards->ReleaseForward(this->pFORR); + forwards->ReleaseForward(this->pFOTR); +} + +void SteamWorksGSHooks::LogOnAnonymous(void) +{ + ISteamGameServer *pGameServer = GetGameServerPointer(); + if (pGameServer == NULL) + { + /* Go away, this wrecks us if we want to use it later. Also; impossible. */ + RETURN_META(MRES_SUPERCEDE); + } + + char pToken[256]; + pToken[0] = '\0'; + + if (this->pFOTR->GetFunctionCount() != 0) + { + cell_t result = Pl_Continue; + this->pFOTR->PushStringEx(pToken, sizeof(pToken), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + this->pFOTR->PushCell(sizeof(pToken)); + this->pFOTR->Execute(&result); + } + + pGameServer->LogOn("", pToken); + RETURN_META(MRES_SUPERCEDE); } bool SteamWorksGSHooks::WasRestartRequested(void) /* Mimic SteamTools. */ @@ -71,6 +98,7 @@ void SteamWorksGSHooks::AddHooks(ISteamGameServer *pGameServer) this->uHooked = eHooked; SH_ADD_HOOK(ISteamGameServer, WasRestartRequested, pGameServer, SH_MEMBER(this, &SteamWorksGSHooks::WasRestartRequested), false); + SH_ADD_HOOK(ISteamGameServer, LogOnAnonymous, pGameServer, SH_MEMBER(this, &SteamWorksGSHooks::LogOnAnonymous), false); } void SteamWorksGSHooks::RemoveHooks(ISteamGameServer *pGameServer, bool destroyed) @@ -81,6 +109,7 @@ void SteamWorksGSHooks::RemoveHooks(ISteamGameServer *pGameServer, bool destroye } SH_REMOVE_HOOK(ISteamGameServer, WasRestartRequested, pGameServer, SH_MEMBER(this, &SteamWorksGSHooks::WasRestartRequested), false); + SH_REMOVE_HOOK(ISteamGameServer, LogOnAnonymous, pGameServer, SH_MEMBER(this, &SteamWorksGSHooks::LogOnAnonymous), false); if (destroyed) { this->uHooked = eUnhooked; diff --git a/Extension/swgshooks.h b/Extension/swgshooks.h index 654924f..b78c2e3 100644 --- a/Extension/swgshooks.h +++ b/Extension/swgshooks.h @@ -35,9 +35,11 @@ class SteamWorksGSHooks public: bool WasRestartRequested(void); + void LogOnAnonymous(void); private: IForward *pFORR; /* On Restart Requested. */ + IForward *pFOTR; /* On Token Requested. */ unsigned char uHooked; };