From 9c9afa37b9a410ea14b960c203a91bd8d8c767ca Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Wed, 25 Aug 2021 04:53:17 +0100 Subject: deprecate clc_SetPlaylistVarOverride --- .../NorthstarDedicatedTest.vcxproj | 2 + .../NorthstarDedicatedTest.vcxproj.filters | 6 +++ NorthstarDedicatedTest/concommand.cpp | 11 ----- NorthstarDedicatedTest/dedicated.cpp | 3 +- NorthstarDedicatedTest/dllmain.cpp | 3 ++ NorthstarDedicatedTest/playlist.cpp | 49 ++++++++++++++++++++++ NorthstarDedicatedTest/playlist.h | 1 + NorthstarDedicatedTest/serverauthentication.cpp | 25 ++++++----- 8 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 NorthstarDedicatedTest/playlist.cpp create mode 100644 NorthstarDedicatedTest/playlist.h (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index b6ceebf1..0857c2db 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -313,6 +313,7 @@ + @@ -345,6 +346,7 @@ Create Create + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 041c8e84..4ed01144 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -564,6 +564,9 @@ Header Files\Client + + Header Files\Server + @@ -641,6 +644,9 @@ Source Files\Client + + Source Files\Server + diff --git a/NorthstarDedicatedTest/concommand.cpp b/NorthstarDedicatedTest/concommand.cpp index 8cf52b9d..5e0fab42 100644 --- a/NorthstarDedicatedTest/concommand.cpp +++ b/NorthstarDedicatedTest/concommand.cpp @@ -15,18 +15,7 @@ void RegisterConCommand(const char* name, void(*callback)(const CCommand&), cons conCommandConstructor(newCommand, name, callback, helpString, flags, nullptr); } -void SetPlaylistCommand(const CCommand& args) -{ - if (args.ArgC() < 2) - return; - - SetCurrentPlaylist(args.Arg(1)); -} - void InitialiseConCommands(HMODULE baseAddress) { conCommandConstructor = (ConCommandConstructorType)((char*)baseAddress + 0x415F60); - - // this shouldn't be here but idk where else to put it rn - RegisterConCommand("setplaylist", SetPlaylistCommand, "", FCVAR_NONE); } \ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 67cb66d2..8d7a6f8c 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -276,8 +276,7 @@ void RunServer(CDedicatedExports* dedicated) // set up engine and host states to allow us to enter CHostState::FrameUpdate, with the state HS_NEW_GAME cEnginePtr->m_nNextDllState = EngineState_t::DLL_ACTIVE; - cHostStatePtr->m_currentState = HostState_t::HS_NEW_GAME; - cHostStatePtr->m_nextState = HostState_t::HS_RUN; + cHostStatePtr->m_nextState = HostState_t::HS_NEW_GAME; strcpy(cHostStatePtr->m_levelName, "mp_lobby"); // set map to load into while (true) diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index e5ea9517..3439c6ce 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -16,6 +16,7 @@ #include "gameutils.h" #include "chatcommand.h" #include "modlocalisation.h" +#include "playlist.h" bool initialised = false; @@ -74,6 +75,8 @@ void InitialiseNorthstar() AddDllLoadCallback("engine.dll", InitialiseServerAuthentication); AddDllLoadCallback("engine.dll", InitialiseSharedMasterServer); + AddDllLoadCallback("engine.dll", InitialisePlaylistHooks); + AddDllLoadCallback("filesystem_stdio.dll", InitialiseFilesystem); AddDllLoadCallback("engine.dll", InitialiseKeyValues); diff --git a/NorthstarDedicatedTest/playlist.cpp b/NorthstarDedicatedTest/playlist.cpp new file mode 100644 index 00000000..2a730ee1 --- /dev/null +++ b/NorthstarDedicatedTest/playlist.cpp @@ -0,0 +1,49 @@ +#include "pch.h" +#include "playlist.h" +#include "concommand.h" +#include "convar.h" +#include "gameutils.h" +#include "hookutils.h" + +typedef char(*Onclc_SetPlaylistVarOverrideType)(void* a1, void* a2); +Onclc_SetPlaylistVarOverrideType Onclc_SetPlaylistVarOverride; + +ConVar* Cvar_ns_use_clc_SetPlaylistVarOverride; + +void SetPlaylistCommand(const CCommand& args) +{ + if (args.ArgC() < 2) + return; + + SetCurrentPlaylist(args.Arg(1)); +} + +char Onclc_SetPlaylistVarOverrideHook(void* a1, void* a2) +{ + // the private_match playlist is the only situation where there should be any legitimate sending of this netmessage + // todo: check mp_lobby here too + if (!Cvar_ns_use_clc_SetPlaylistVarOverride->m_nValue || strcmp(GetCurrentPlaylistName(), "private_match")) + return 1; + + return Onclc_SetPlaylistVarOverride(a1, a2); +} + +void InitialisePlaylistHooks(HMODULE baseAddress) +{ + RegisterConCommand("setplaylist", SetPlaylistCommand, "Sets the current playlist", FCVAR_NONE); + // note: clc_SetPlaylistVarOverride is pretty insecure, since it allows for entirely arbitrary playlist var overrides to be sent to the server + // this is somewhat restricted on custom servers to prevent it being done outside of private matches, but ideally it should be disabled altogether, since the custom menus won't use it anyway + // this should only really be accepted if you want vanilla client compatibility + Cvar_ns_use_clc_SetPlaylistVarOverride = RegisterConVar("ns_use_clc_SetPlaylistVarOverride", "0", FCVAR_GAMEDLL, "Whether the server should accept clc_SetPlaylistVarOverride messages"); + + HookEnabler hook; + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x222180, &Onclc_SetPlaylistVarOverrideHook, reinterpret_cast(&Onclc_SetPlaylistVarOverride)); + + // patch to prevent clc_SetPlaylistVarOverride from being able to crash servers if we reach max overrides due to a call to Error (why is this possible respawn, wtf) + // todo: add a warning for this + { + void* ptr = (char*)baseAddress + 0x18ED8D; + TempReadWrite rw(ptr); + *((char*)ptr) = 0xC3; // jmp => ret + } +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/playlist.h b/NorthstarDedicatedTest/playlist.h new file mode 100644 index 00000000..d96a77ee --- /dev/null +++ b/NorthstarDedicatedTest/playlist.h @@ -0,0 +1 @@ +void InitialisePlaylistHooks(HMODULE baseAddress); \ No newline at end of file diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 6dd44284..77990d24 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -98,23 +98,28 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid, std::string strUid = std::to_string(uid); std::lock_guard guard(m_authDataMutex); + + bool authFail = true; if (!m_authData.empty() && m_authData.count(std::string(authToken))) { // use stored auth data AuthData authData = m_authData[authToken]; - if (strcmp(strUid.c_str(), authData.uid)) // connecting client's uid is different from auth's uid - return false; - - // uuid - strcpy((char*)player + 0xF500, strUid.c_str()); + if (!strcmp(strUid.c_str(), authData.uid)) // connecting client's uid is different from auth's uid + { + authFail = false; + // uuid + strcpy((char*)player + 0xF500, strUid.c_str()); - // copy pdata into buffer - memcpy((char*)player + 0x4FA, authData.pdata, authData.pdataSize); + // copy pdata into buffer + memcpy((char*)player + 0x4FA, authData.pdata, authData.pdataSize); - // set persistent data as ready, we use 0x4 internally to mark the client as using remote persistence - *((char*)player + 0x4a0) = (char)0x4; + // set persistent data as ready, we use 0x4 internally to mark the client as using remote persistence + *((char*)player + 0x4a0) = (char)0x4; + } } - else + + + if (authFail) { if (!CVar_ns_auth_allow_insecure->m_nValue) // no auth data and insecure connections aren't allowed, so dc the client return false; -- cgit v1.2.3