From 8ee27654d4f8c70206983164d2c4ac692ebed5de Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Thu, 13 Jan 2022 02:20:28 +0000 Subject: unbreak sp --- NorthstarDedicatedTest/gameutils.cpp | 2 ++ NorthstarDedicatedTest/gameutils.h | 1 + NorthstarDedicatedTest/masterserver.cpp | 24 ++++++++++++++++++++++-- NorthstarDedicatedTest/serverauthentication.cpp | 13 ++++++++----- 4 files changed, 33 insertions(+), 7 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/gameutils.cpp b/NorthstarDedicatedTest/gameutils.cpp index b5a13928..f9fd4d95 100644 --- a/NorthstarDedicatedTest/gameutils.cpp +++ b/NorthstarDedicatedTest/gameutils.cpp @@ -22,6 +22,7 @@ server_state_t* sv_m_State; // network stuff ConVar* Cvar_hostport; +ConVar* Cvar_net_datablock_enabled; // playlist stuff GetCurrentPlaylistType GetCurrentPlaylistName; @@ -60,6 +61,7 @@ void InitialiseEngineGameUtilFunctions(HMODULE baseAddress) sv_m_State = (server_state_t*)((char*)baseAddress + 0x12A53D48); Cvar_hostport = (ConVar*)((char*)baseAddress + 0x13FA6070); + Cvar_net_datablock_enabled = (ConVar*)((char*)baseAddress + 0x12A4F6D0); GetCurrentPlaylistName = (GetCurrentPlaylistType)((char*)baseAddress + 0x18C640); SetCurrentPlaylist = (SetCurrentPlaylistType)((char*)baseAddress + 0x18EB20); diff --git a/NorthstarDedicatedTest/gameutils.h b/NorthstarDedicatedTest/gameutils.h index aaa1dfb9..48ad75e4 100644 --- a/NorthstarDedicatedTest/gameutils.h +++ b/NorthstarDedicatedTest/gameutils.h @@ -205,6 +205,7 @@ extern server_state_t* sv_m_State; // network stuff extern ConVar* Cvar_hostport; +extern ConVar* Cvar_net_datablock_enabled; // playlist stuff typedef const char*(*GetCurrentPlaylistType)(); diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index d34065c0..c040a239 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -1026,6 +1026,14 @@ void CHostState__State_NewGameHook(CHostState* hostState) if (g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame) SetCurrentPlaylist("tdm"); + // net_data_block_enabled is required for sp, force it if we're on an sp map + // sucks for security but just how it be + if (!strncmp(g_pHostState->m_levelName, "sp_", 3)) + { + Cbuf_AddText(Cbuf_GetCurrentPlayer(), "net_data_block_enabled 1", cmd_source_t::kCommandSrcCode); + Cbuf_Execute(); + } + CHostState__State_NewGame(hostState); int maxPlayers = 6; @@ -1049,12 +1057,24 @@ void CHostState__State_ChangeLevelMPHook(CHostState* hostState) if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this maxPlayers = std::stoi(maxPlayersVar); + // net_data_block_enabled is required for sp, force it if we're on an sp map + // sucks for security but just how it be + if (!strncmp(g_pHostState->m_levelName, "sp_", 3)) + { + Cbuf_AddText(Cbuf_GetCurrentPlayer(), "net_data_block_enabled 1", cmd_source_t::kCommandSrcCode); + Cbuf_Execute(); + } + g_MasterServerManager->UpdateServerMapAndPlaylist(hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers); CHostState__State_ChangeLevelMP(hostState); } void CHostState__State_ChangeLevelSPHook(CHostState* hostState) { + // is this even called? genuinely i don't think so + // from what i can tell, it's not called on mp=>sp change or sp=>sp change + // so idk it's fucked + int maxPlayers = 6; char* maxPlayersVar = GetCurrentPlaylistVar("max_players", false); if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this @@ -1097,7 +1117,7 @@ void InitialiseSharedMasterServer(HMODULE baseAddress) HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x16E7D0, CHostState__State_NewGameHook, reinterpret_cast(&CHostState__State_NewGame)); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x16E5D0, CHostState__State_ChangeLevelMPHook, reinterpret_cast(&CHostState__State_ChangeLevelMP)); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x16E520, CHostState__State_ChangeLevelSPHook, reinterpret_cast(&CHostState__State_ChangeLevelSP)); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x16E520, CHostState__State_ChangeLevelMPHook, reinterpret_cast(&CHostState__State_ChangeLevelMP)); + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x16E5D0, CHostState__State_ChangeLevelSPHook, reinterpret_cast(&CHostState__State_ChangeLevelSP)); ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x16E640, CHostState__State_GameShutdownHook, reinterpret_cast(&CHostState__State_GameShutdown)); } diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 7253f31b..794c6c1d 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -20,7 +20,7 @@ const char* AUTHSERVER_VERIFY_STRING = "I am a northstar server!"; typedef void*(*CBaseServer__ConnectClientType)(void* server, void* a2, void* a3, uint32_t a4, uint32_t a5, int32_t a6, void* a7, void* a8, char* serverFilter, void* a10, char a11, void* a12, char a13, char a14, int64_t uid, uint32_t a16, uint32_t a17); CBaseServer__ConnectClientType CBaseServer__ConnectClient; -typedef char(*CBaseClient__ConnectType)(void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, __int64 a5, char* Buffer, int a7); +typedef bool(*CBaseClient__ConnectType)(void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, __int64 a5, char* Buffer, void* a7); CBaseClient__ConnectType CBaseClient__Connect; typedef void(*CBaseClient__ActivatePlayerType)(void* self); @@ -241,11 +241,14 @@ void* CBaseServer__ConnectClientHook(void* server, void* a2, void* a3, uint32_t return CBaseServer__ConnectClient(server, a2, a3, a4, a5, a6, a7, a8, serverFilter, a10, a11, a12, a13, a14, uid, a16, a17); } -char CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, __int64 a5, char* Buffer, int a7) +bool CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, __int64 a5, char* Buffer, void* a7) { // try to auth player, dc if it fails // we connect irregardless of auth, because returning bad from this function can fuck client state p bad - char ret = CBaseClient__Connect(self, name, netchan_ptr_arg, b_fake_player_arg, a5, Buffer, a7); + bool ret = CBaseClient__Connect(self, name, netchan_ptr_arg, b_fake_player_arg, a5, Buffer, a7); + + if (!ret) + return ret; if (!g_ServerBanSystem->IsUIDAllowed(nextPlayerUid)) { @@ -348,7 +351,7 @@ char CGameClient__ExecuteStringCommandHook(void* self, uint32_t unknown, const c void ConCommand__DispatchHook(ConCommand* command, const CCommand& args, void* a3) { // patch to ensure FCVAR_GAMEDLL concommands without FCVAR_CLIENTCMD_CAN_EXECUTE can't be executed by remote clients - if (*sv_m_State == server_state_t::ss_active && command->GetFlags() & FCVAR_GAMEDLL && !(command->GetFlags() & FCVAR_CLIENTCMD_CAN_EXECUTE)) + if (*sv_m_State == server_state_t::ss_active && command->IsFlagSet(FCVAR_GAMEDLL) && !command->IsFlagSet(FCVAR_CLIENTCMD_CAN_EXECUTE)) { if (IsDedicated()) return; @@ -413,7 +416,7 @@ void CBaseClient__SendServerInfoHook(void* self) bool ProcessConnectionlessPacketHook(void* a1, netpacket_t* packet) { - if (packet->adr.type == NA_IP) + if (packet->adr.type == NA_IP && (!(packet->data[4] == 'N' && Cvar_net_datablock_enabled->m_nValue) || !Cvar_net_datablock_enabled->m_nValue)) { // bad lookup: optimise later tm UnconnectedPlayerSendData* sendData = nullptr; -- cgit v1.2.3