diff options
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters | 21 | ||||
-rw-r--r-- | NorthstarDedicatedTest/dllmain.cpp | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/emit_blocker.cpp | 26 | ||||
-rw-r--r-- | NorthstarDedicatedTest/emit_blocker.h | 3 | ||||
-rw-r--r-- | NorthstarDedicatedTest/serverauthentication.cpp | 37 | ||||
-rw-r--r-- | NorthstarDedicatedTest/serverauthentication.h | 4 |
7 files changed, 88 insertions, 7 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 4151a7e5..3fe2da06 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -121,6 +121,7 @@ <ClInclude Include="debugoverlay.h" /> <ClInclude Include="clientruihooks.h" /> <ClInclude Include="clientvideooverrides.h" /> + <ClInclude Include="emit_blocker.h" /> <ClInclude Include="localchatwriter.h" /> <ClInclude Include="ns_version.h" /> <ClInclude Include="plugins.h" /> @@ -602,6 +603,7 @@ <ClCompile Include="dedicated.cpp" /> <ClCompile Include="dedicatedmaterialsystem.cpp" /> <ClCompile Include="dllmain.cpp" /> + <ClCompile Include="emit_blocker.cpp" /> <ClCompile Include="filesystem.cpp" /> <ClCompile Include="gameutils.cpp" /> <ClCompile Include="hooks.cpp" /> diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 19d60e62..1845c3ea 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -133,6 +133,9 @@ <Filter Include="Source Files\Shared\Exploit Fixes\UTF8Parser"> <UniqueIdentifier>{b30e08b1-b962-4264-8cbb-a0a31924b93e}</UniqueIdentifier> </Filter> + <Filter Include="Header Files\Shared\ExploitFixes"> + <UniqueIdentifier>{7f609cee-d2c0-46a2-b06e-83b9f0511915}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClInclude Include="pch.h"> @@ -1527,12 +1530,6 @@ <ClInclude Include="clientvideooverrides.h"> <Filter>Header Files\Client</Filter> </ClInclude> - <ClInclude Include="ExploitFixes.h"> - <Filter>Source Files\Shared\Exploit Fixes</Filter> - </ClInclude> - <ClInclude Include="NSMem.h"> - <Filter>Source Files\Shared\Exploit Fixes</Filter> - </ClInclude> <ClInclude Include="ExploitFixes_UTF8Parser.h"> <Filter>Source Files\Shared\Exploit Fixes\UTF8Parser</Filter> </ClInclude> @@ -1545,6 +1542,15 @@ <ClInclude Include="ns_version.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ExploitFixes.h"> + <Filter>Header Files\Shared\ExploitFixes</Filter> + </ClInclude> + <ClInclude Include="NSMem.h"> + <Filter>Header Files\Shared\ExploitFixes</Filter> + </ClInclude> + <ClInclude Include="emit_blocker.h"> + <Filter>Header Files\Shared\ExploitFixes</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="dllmain.cpp"> @@ -1742,6 +1748,9 @@ <ClCompile Include="clientruihooks.cpp"> <Filter>Source Files\Client</Filter> </ClCompile> + <ClCompile Include="emit_blocker.cpp"> + <Filter>Source Files\Shared\Exploit Fixes</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <MASM Include="audio_asm.asm"> diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 733e2fd6..77dd4957 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -49,6 +49,7 @@ #include "rapidjson/writer.h" #include "rapidjson/error/en.h" #include "ExploitFixes.h" +#include "emit_blocker.h" typedef void (*initPluginFuncPtr)(void* getPluginObject); @@ -288,6 +289,7 @@ bool InitialiseNorthstar() // activate exploit fixes AddDllLoadCallback("server.dll", ExploitFixes::LoadCallback); + AddDllLoadCallback("server.dll", InitialiseServerEmit_Blocker); // run callbacks for any libraries that are already loaded by now CallAllPendingDLLLoadCallbacks(); diff --git a/NorthstarDedicatedTest/emit_blocker.cpp b/NorthstarDedicatedTest/emit_blocker.cpp new file mode 100644 index 00000000..3f996c69 --- /dev/null +++ b/NorthstarDedicatedTest/emit_blocker.cpp @@ -0,0 +1,26 @@ +#include "pch.h" +#include "cvar.h" + +ConVar* sv_cheats; + +typedef char(__fastcall* function_containing_emit_t)(uint64_t a1, uint64_t a2); +function_containing_emit_t function_containing_emit; + +char function_containing_emit_hook(uint64_t unknown_value, uint64_t command_ptr) +{ + char* command_string = *(char**)(command_ptr + 1040); // From decompile + if (!sv_cheats->m_Value.m_nValue && !strncmp(command_string, "emit", 5)) + { + spdlog::info("Blocking command \"emit\" because sv_cheats was 0"); + return 1; + } + return function_containing_emit(unknown_value, command_ptr); +} + +void InitialiseServerEmit_Blocker(HMODULE baseAddress) +{ + HookEnabler hook; + sv_cheats = g_pCVar->FindVar("sv_cheats"); + ENABLER_CREATEHOOK( + hook, (char*)baseAddress + 0x5889A0, &function_containing_emit_hook, reinterpret_cast<LPVOID*>(&function_containing_emit)); +}
\ No newline at end of file diff --git a/NorthstarDedicatedTest/emit_blocker.h b/NorthstarDedicatedTest/emit_blocker.h new file mode 100644 index 00000000..43991927 --- /dev/null +++ b/NorthstarDedicatedTest/emit_blocker.h @@ -0,0 +1,3 @@ +#pragma once + +void InitialiseServerEmit_Blocker(HMODULE baseAddress);
\ No newline at end of file diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 4af18612..730c601d 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -127,6 +127,12 @@ void ServerAuthenticationManager::StartPlayerAuthServer() return; } + // Log playername and UID from request + spdlog::info( + "Player \"{}\" with UID \"{}\" requested to join", + request.get_param_value("username").c_str(), + request.get_param_value("id").c_str()); + AuthData newAuthData {}; strncpy(newAuthData.uid, request.get_param_value("id").c_str(), sizeof(newAuthData.uid)); newAuthData.uid[sizeof(newAuthData.uid) - 1] = 0; @@ -194,6 +200,9 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid, // use stored auth data AuthData authData = m_authData[authToken]; + // Log playnername and UID from request + spdlog::info("Comparing connecting UID \"{}\" against stored UID from ms auth request \"{}\"", strUid.c_str(), authData.uid); + if (!strcmp(strUid.c_str(), authData.uid)) // connecting client's uid is the same as auth's uid { authFail = false; @@ -278,6 +287,8 @@ bool ServerAuthenticationManager::RemovePlayerAuthData(void* player) { if (!strcmp((char*)player + 0xF500, auth.second.uid)) { + // Log UID + spdlog::info("Erasing auth data from UID \"{}\"", auth.second.uid); // pretty sure this is fine, since we don't iterate after the erase // i think if we iterated after it'd be undefined behaviour tho std::lock_guard<std::mutex> guard(m_authDataMutex); @@ -350,6 +361,9 @@ void* CBaseServer__ConnectClientHook( nextPlayerToken = serverFilter; nextPlayerUid = uid; + // Random UID log + spdlog::info("CBaseServer__ConnectClientHook says UID \"{}\"", uid); + return CBaseServer__ConnectClient(server, a2, a3, a4, a5, a6, a7, a8, serverFilter, a10, a11, a12, a13, a14, uid, a16, a17); } @@ -362,6 +376,9 @@ bool CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, c // we connect irregardless of auth, because returning bad from this function can fuck client state p bad bool ret = CBaseClient__Connect(self, name, netchan_ptr_arg, b_fake_player_arg, a5, Buffer, a7); + // Another UID log + spdlog::info("CBaseClient__ConnectHook says UID \"{}\"", nextPlayerUid); + if (!ret) return ret; @@ -385,6 +402,8 @@ bool CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, c additionalData.usingLocalPdata = *((char*)self + 0x4a0) == (char)0x3; g_ServerAuthenticationManager->m_additionalPlayerData.insert(std::make_pair(self, additionalData)); + + g_ServerAuthenticationManager->m_additionalPlayerData[self].uid = nextPlayerUid; } return ret; @@ -392,6 +411,21 @@ bool CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, c void CBaseClient__ActivatePlayerHook(void* self) { + bool uidMatches = false; + if (g_ServerAuthenticationManager->m_additionalPlayerData.count(self)) + { + std::string strUid = std::to_string(g_ServerAuthenticationManager->m_additionalPlayerData[self].uid); + if (!strcmp(strUid.c_str(), (char*)self + 0xF500)) // connecting client's uid is the same as auth's uid + { + uidMatches = true; + } + } + if (!uidMatches) + { + CBaseClient__Disconnect(self, 1, "Authentication Failed"); + return; + } + // if we're authed, write our persistent data // RemovePlayerAuthData returns true if it removed successfully, i.e. on first call only, and we only want to write on >= second call // (since this func is called on map loads) @@ -401,6 +435,8 @@ void CBaseClient__ActivatePlayerHook(void* self) g_ServerAuthenticationManager->WritePersistentData(self); g_MasterServerManager->UpdateServerPlayerCount(g_ServerAuthenticationManager->m_additionalPlayerData.size()); } + // Log UID + spdlog::info("In CBaseClient__ActivatePlayerHook, activating UID \"{}\"", (char*)self + 0xF500); CBaseClient__ActivatePlayer(self); } @@ -682,6 +718,7 @@ void InitialiseServerAuthentication(HMODULE baseAddress) } // patch to allow same of multiple account + if (CommandLine()->CheckParm("-allowdupeaccounts")) { NSMem::BytePatch( ba + 0x114510, diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h index c0960a6b..3292c70c 100644 --- a/NorthstarDedicatedTest/serverauthentication.h +++ b/NorthstarDedicatedTest/serverauthentication.h @@ -27,6 +27,8 @@ struct AdditionalPlayerData double lastSayTextLimitStart = -1.0; int sayTextLimitCount = 0; + + uint64_t uid; }; #pragma pack(push, 1) @@ -98,4 +100,4 @@ extern CBaseClient__DisconnectType CBaseClient__Disconnect; void InitialiseServerAuthentication(HMODULE baseAddress); extern ServerAuthenticationManager* g_ServerAuthenticationManager; -extern ConVar* Cvar_ns_player_auth_port;
\ No newline at end of file +extern ConVar* Cvar_ns_player_auth_port; |