From 47ea109be0d73120ddfe6896494e1fce986515b3 Mon Sep 17 00:00:00 2001 From: Northstar Date: Wed, 13 Apr 2022 19:29:44 -0300 Subject: Format project --- LauncherInjector/main.cpp | 36 ++- NorthstarDedicatedTest/ExploitFixes.cpp | 29 +- NorthstarDedicatedTest/ExploitFixes.h | 2 +- NorthstarDedicatedTest/ExploitFixes_UTF8Parser.h | 310 ++++++++++----------- NorthstarDedicatedTest/NSMem.h | 216 +++++++------- NorthstarDedicatedTest/audio.cpp | 11 +- NorthstarDedicatedTest/bansystem.cpp | 5 +- NorthstarDedicatedTest/bitbuf.h | 133 +++++++-- NorthstarDedicatedTest/bits.cpp | 30 +- NorthstarDedicatedTest/buildainfile.cpp | 20 +- NorthstarDedicatedTest/clientauthhooks.cpp | 4 +- NorthstarDedicatedTest/color.h | 77 +++-- NorthstarDedicatedTest/concommand.cpp | 45 ++- NorthstarDedicatedTest/concommand.h | 70 +++-- NorthstarDedicatedTest/configurables.cpp | 5 +- NorthstarDedicatedTest/convar.cpp | 87 ++++-- NorthstarDedicatedTest/convar.h | 69 ++--- NorthstarDedicatedTest/cvar.h | 6 +- NorthstarDedicatedTest/dedicated.cpp | 35 ++- NorthstarDedicatedTest/dedicatedmaterialsystem.cpp | 24 +- NorthstarDedicatedTest/gameutils.h | 14 +- NorthstarDedicatedTest/hooks.cpp | 3 +- NorthstarDedicatedTest/languagehooks.cpp | 6 +- NorthstarDedicatedTest/latencyflex.cpp | 4 +- NorthstarDedicatedTest/localchatwriter.cpp | 34 ++- NorthstarDedicatedTest/logging.cpp | 13 +- NorthstarDedicatedTest/masterserver.cpp | 133 ++++++--- NorthstarDedicatedTest/masterserver.h | 10 +- NorthstarDedicatedTest/maxplayers.cpp | 58 ++-- NorthstarDedicatedTest/memalloc.cpp | 10 +- NorthstarDedicatedTest/memalloc.h | 5 +- NorthstarDedicatedTest/misccommands.cpp | 14 +- NorthstarDedicatedTest/modmanager.cpp | 27 +- NorthstarDedicatedTest/pch.h | 7 +- NorthstarDedicatedTest/plugins.cpp | 19 +- NorthstarDedicatedTest/rpakfilesystem.cpp | 5 +- NorthstarDedicatedTest/scriptmodmenu.cpp | 5 +- NorthstarDedicatedTest/scriptserverbrowser.cpp | 155 +++++++---- .../scriptservertoclientstringcommand.cpp | 4 +- NorthstarDedicatedTest/serverauthentication.cpp | 63 ++++- NorthstarDedicatedTest/serverauthentication.h | 2 +- NorthstarDedicatedTest/serverchathooks.cpp | 18 +- NorthstarDedicatedTest/sourceconsole.cpp | 4 +- NorthstarDedicatedTest/sourceinterface.cpp | 12 +- NorthstarDedicatedTest/sourceinterface.h | 10 +- NorthstarDedicatedTest/squirrel.cpp | 49 +++- NorthstarDedicatedTest/squirrel.h | 5 +- 47 files changed, 1246 insertions(+), 657 deletions(-) diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp index 1e3310ff..04aadf03 100644 --- a/LauncherInjector/main.cpp +++ b/LauncherInjector/main.cpp @@ -78,7 +78,10 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs\n\nMake sure you followed the Northstar installation instructions carefully " "before reaching out for help.", - libName, location, dwMessageId, message.c_str()); + libName, + location, + dwMessageId, + message.c_str()); if (dwMessageId == 126 && std::filesystem::exists(location)) { @@ -98,7 +101,9 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* "%s\n\nWe detected that in your case you have extracted the files into a *subdirectory* of your Titanfall 2 " "installation.\nPlease move all the files and folders from current folder (\"%s\") into the Titanfall 2 installation directory " "just above (\"%s\").\n\nPlease try out the above steps by yourself before reaching out to the community for support.", - text, curDir.c_str(), aboveDir.c_str()); + text, + curDir.c_str(), + aboveDir.c_str()); } else if (!fs::exists("Titanfall2.exe")) { @@ -152,7 +157,15 @@ void EnsureOriginStarted() si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_MINIMIZE; CreateProcessA( - originPath, (char*)"", NULL, NULL, false, CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP, NULL, NULL, (LPSTARTUPINFOA)&si, + originPath, + (char*)"", + NULL, + NULL, + false, + CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP, + NULL, + NULL, + (LPSTARTUPINFOA)&si, &pi); printf("[*] Waiting for Origin...\n"); @@ -180,7 +193,8 @@ void PrependPath() GetForegroundWindow(), L"Warning: could not prepend the current directory to app's PATH environment variable. Something may break because of " L"that.", - L"Northstar Launcher Warning", 0); + L"Northstar Launcher Warning", + 0); } free(pPath); } @@ -190,7 +204,8 @@ void PrependPath() GetForegroundWindow(), L"Warning: could not get current PATH environment variable in order to prepend the current directory to it. Something may " L"break because of that.", - L"Northstar Launcher Warning", 0); + L"Northstar Launcher Warning", + 0); } } @@ -267,7 +282,9 @@ int main(int argc, char* argv[]) if (!GetExePathWide(exePath, sizeof(exePath))) { MessageBoxA( - GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Launcher Error", + GetForegroundWindow(), + "Failed getting game directory.\nThe game cannot continue and has to exit.", + "Northstar Launcher Error", 0); return 1; } @@ -313,7 +330,8 @@ int main(int argc, char* argv[]) GetForegroundWindow(), "Failed to load one or more stubs, but could not unload them either.\n" "The game cannot continue and has to exit.", - "Northstar Launcher Error", 0); + "Northstar Launcher Error", + 0); return 1; } } @@ -377,7 +395,9 @@ int main(int argc, char* argv[]) auto LauncherMain = GetLauncherMain(); if (!LauncherMain) MessageBoxA( - GetForegroundWindow(), "Failed loading launcher.dll.\nThe game cannot continue and has to exit.", "Northstar Launcher Error", + GetForegroundWindow(), + "Failed loading launcher.dll.\nThe game cannot continue and has to exit.", + "Northstar Launcher Error", 0); // auto result = ((__int64(__fastcall*)())LauncherMain)(); // auto result = ((signed __int64(__fastcall*)(__int64))LauncherMain)(0i64); diff --git a/NorthstarDedicatedTest/ExploitFixes.cpp b/NorthstarDedicatedTest/ExploitFixes.cpp index 8a80b629..db754ad5 100644 --- a/NorthstarDedicatedTest/ExploitFixes.cpp +++ b/NorthstarDedicatedTest/ExploitFixes.cpp @@ -21,7 +21,10 @@ ConVar* ns_exploitfixes_log; }()) // Make sure 3 or less floats are valid -bool ValidateFloats(float a, float b = 0, float c = 0) { return !isnan(a) && !isnan(b) && !isnan(c); } +bool ValidateFloats(float a, float b = 0, float c = 0) +{ + return !isnan(a) && !isnan(b) && !isnan(c); +} struct Vector { @@ -29,7 +32,10 @@ struct Vector Vector(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z) {} - bool IsValid() { return ValidateFloats(x, y, z); } + bool IsValid() + { + return ValidateFloats(x, y, z); + } }; struct Angle @@ -48,7 +54,10 @@ struct Angle }; #define BLOCK_NETMSG_FUNC(name, pattern) \ - KHOOK(name, ("engine.dll", pattern), bool, __fastcall, (void* thisptr, void* buffer)) { return false; } + KHOOK(name, ("engine.dll", pattern), bool, __fastcall, (void* thisptr, void* buffer)) \ + { \ + return false; \ + } // Servers can literally request a screenshot from any client, yeah no BLOCK_NETMSG_FUNC(CLC_Screenshot_WriteToBuffer, "48 89 5C 24 ? 57 48 83 EC 20 8B 42 10"); @@ -74,7 +83,7 @@ KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 void* unk2; void* m_pMessageHandler; SetConVarEntry* m_ConVars; // convar entry array - void* unk5; // these 2 unks are just vector capacity or whatever + void* unk5; // these 2 unks are just vector capacity or whatever void* unk6; int m_ConVars_count; // amount of cvar entries in array (this will not be out of bounds) }; @@ -96,7 +105,7 @@ KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 areWeServer = offset != CLIENTSTATE_FIRST_VFUNC_OFFSET; } - std::string BLOCK_PREFIX = std::string{"NET_SetConVar ("} + (areWeServer ? "server" : "client") + "): Blocked dangerous/invalid msg: "; + std::string BLOCK_PREFIX = std::string {"NET_SetConVar ("} + (areWeServer ? "server" : "client") + "): Blocked dangerous/invalid msg: "; if (areWeServer) { @@ -132,7 +141,8 @@ KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 if (realVar) memcpy( - entry->name, realVar->m_ConCommandBase.m_pszName, + entry->name, + realVar->m_ConCommandBase.m_pszName, strlen(realVar->m_ConCommandBase.m_pszName) + 1); // Force name to match case bool isValidFlags = true; @@ -315,8 +325,11 @@ KHOOK(IsValveMod, ("engine.dll", "48 83 EC 28 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? // Fix respawn's crappy UTF8 parser so it doesn't crash -_- // This also means you can launch multiplayer with "communities_enabled 1" and not crash, you're welcome KHOOK( - CrashFunc_ParseUTF8, ("engine.dll", "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 54 41 55 41 56 41 57 48 83 EC 20 8B 1A"), bool, - __fastcall, (INT64 * a1, DWORD* a2, char* strData)) + CrashFunc_ParseUTF8, + ("engine.dll", "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 54 41 55 41 56 41 57 48 83 EC 20 8B 1A"), + bool, + __fastcall, + (INT64 * a1, DWORD* a2, char* strData)) { static void* targetRetAddr = NSMem::PatternScan("engine.dll", "84 C0 75 2C 49 8B 16"); diff --git a/NorthstarDedicatedTest/ExploitFixes.h b/NorthstarDedicatedTest/ExploitFixes.h index 16196cbf..7a407a3d 100644 --- a/NorthstarDedicatedTest/ExploitFixes.h +++ b/NorthstarDedicatedTest/ExploitFixes.h @@ -5,5 +5,5 @@ namespace ExploitFixes { -void LoadCallback(HMODULE unused); + void LoadCallback(HMODULE unused); } \ No newline at end of file diff --git a/NorthstarDedicatedTest/ExploitFixes_UTF8Parser.h b/NorthstarDedicatedTest/ExploitFixes_UTF8Parser.h index 09c26293..41242655 100644 --- a/NorthstarDedicatedTest/ExploitFixes_UTF8Parser.h +++ b/NorthstarDedicatedTest/ExploitFixes_UTF8Parser.h @@ -6,170 +6,170 @@ namespace ExploitFixes_UTF8Parser { -bool __fastcall CheckValid(INT64* a1, DWORD* a2, char* strData) -{ - static auto sub_F1320 = (INT64(__fastcall*)(DWORD a1, char* a2))NSMem::PatternScan("engine.dll", "83 F9 7F 77 08 88 0A"); + bool __fastcall CheckValid(INT64* a1, DWORD* a2, char* strData) + { + static auto sub_F1320 = (INT64(__fastcall*)(DWORD a1, char* a2))NSMem::PatternScan("engine.dll", "83 F9 7F 77 08 88 0A"); - DWORD v3; // eax - char* v4; // rbx - char v5; // si - char* _strData; // rdi - char* v7; // rbp - char v11; // al - DWORD v12; // er9 - DWORD v13; // ecx - DWORD v14; // edx - DWORD v15; // er8 - int v16; // eax - DWORD v17; // er9 - int v18; // eax - DWORD v19; // er9 - DWORD v20; // ecx - int v21; // eax - int v22; // er9 - DWORD v23; // edx - int v24; // eax - int v25; // er9 - DWORD v26; // er9 - DWORD v27; // er10 - DWORD v28; // ecx - DWORD v29; // edx - DWORD v30; // er8 - int v31; // eax - DWORD v32; // er10 - int v33; // eax - DWORD v34; // er10 - DWORD v35; // ecx - int v36; // eax - int v37; // er10 - DWORD v38; // edx - int v39; // eax - int v40; // er10 - DWORD v41; // er10 - INT64 v43; // r8 - INT64 v44; // rdx - INT64 v45; // rcx - INT64 v46; // rax - INT64 v47; // rax - char v48; // al - INT64 v49; // r8 - INT64 v50; // rdx - INT64 v51; // rcx - INT64 v52; // rax - INT64 v53; // rax + DWORD v3; // eax + char* v4; // rbx + char v5; // si + char* _strData; // rdi + char* v7; // rbp + char v11; // al + DWORD v12; // er9 + DWORD v13; // ecx + DWORD v14; // edx + DWORD v15; // er8 + int v16; // eax + DWORD v17; // er9 + int v18; // eax + DWORD v19; // er9 + DWORD v20; // ecx + int v21; // eax + int v22; // er9 + DWORD v23; // edx + int v24; // eax + int v25; // er9 + DWORD v26; // er9 + DWORD v27; // er10 + DWORD v28; // ecx + DWORD v29; // edx + DWORD v30; // er8 + int v31; // eax + DWORD v32; // er10 + int v33; // eax + DWORD v34; // er10 + DWORD v35; // ecx + int v36; // eax + int v37; // er10 + DWORD v38; // edx + int v39; // eax + int v40; // er10 + DWORD v41; // er10 + INT64 v43; // r8 + INT64 v44; // rdx + INT64 v45; // rcx + INT64 v46; // rax + INT64 v47; // rax + char v48; // al + INT64 v49; // r8 + INT64 v50; // rdx + INT64 v51; // rcx + INT64 v52; // rax + INT64 v53; // rax - v3 = a2[2]; - v4 = (char*)(a1[1] + *a2); - v5 = 0; - _strData = strData; - v7 = &v4[*((UINT16*)a2 + 2)]; - if (v3 >= 2) - { - ++v4; - --v7; - if (v3 != 2) + v3 = a2[2]; + v4 = (char*)(a1[1] + *a2); + v5 = 0; + _strData = strData; + v7 = &v4[*((UINT16*)a2 + 2)]; + if (v3 >= 2) { - while (1) + ++v4; + --v7; + if (v3 != 2) { + while (1) + { - if (!NSMem::IsMemoryReadable(v4, 1)) - return false; // INVALID + if (!NSMem::IsMemoryReadable(v4, 1)) + return false; // INVALID - v11 = *v4++; // crash potential - if (v11 != 92) - goto LABEL_6; - v11 = *v4++; - if (v11 == 110) - break; - switch (v11) - { - case 't': - v11 = 9; - goto LABEL_6; - case 'r': - v11 = 13; - goto LABEL_6; - case 'b': - v11 = 8; - goto LABEL_6; - case 'f': - v11 = 12; - goto LABEL_6; - } - if (v11 != 117) - goto LABEL_6; - v12 = *v4 | 0x20; - v13 = v4[1] | 0x20; - v14 = v4[2] | 0x20; - v15 = v4[3] | 0x20; - v16 = 87; - if (v12 <= 0x39) - v16 = 48; - v17 = v12 - v16; - v18 = 87; - v19 = v17 << 12; - if (v13 <= 0x39) - v18 = 48; - v20 = v13 - v18; - v21 = 87; - v22 = (v20 << 8) | v19; - if (v14 <= 0x39) - v21 = 48; - v23 = v14 - v21; - v24 = 87; - v25 = (16 * v23) | v22; - if (v15 <= 0x39) - v24 = 48; - v4 += 4; - v26 = (v15 - v24) | v25; - if (v26 - 55296 <= 0x7FF) - { - if (v26 >= 0xDC00) - return true; - if (*v4 != 92 || v4[1] != 117) - return true; + v11 = *v4++; // crash potential + if (v11 != 92) + goto LABEL_6; + v11 = *v4++; + if (v11 == 110) + break; + switch (v11) + { + case 't': + v11 = 9; + goto LABEL_6; + case 'r': + v11 = 13; + goto LABEL_6; + case 'b': + v11 = 8; + goto LABEL_6; + case 'f': + v11 = 12; + goto LABEL_6; + } + if (v11 != 117) + goto LABEL_6; + v12 = *v4 | 0x20; + v13 = v4[1] | 0x20; + v14 = v4[2] | 0x20; + v15 = v4[3] | 0x20; + v16 = 87; + if (v12 <= 0x39) + v16 = 48; + v17 = v12 - v16; + v18 = 87; + v19 = v17 << 12; + if (v13 <= 0x39) + v18 = 48; + v20 = v13 - v18; + v21 = 87; + v22 = (v20 << 8) | v19; + if (v14 <= 0x39) + v21 = 48; + v23 = v14 - v21; + v24 = 87; + v25 = (16 * v23) | v22; + if (v15 <= 0x39) + v24 = 48; + v4 += 4; + v26 = (v15 - v24) | v25; + if (v26 - 55296 <= 0x7FF) + { + if (v26 >= 0xDC00) + return true; + if (*v4 != 92 || v4[1] != 117) + return true; - v27 = v4[2] | 0x20; - v28 = v4[3] | 0x20; - v29 = v4[4] | 0x20; - v30 = v4[5] | 0x20; - v31 = 87; - if (v27 <= 0x39) - v31 = 48; - v32 = v27 - v31; - v33 = 87; - v34 = v32 << 12; - if (v28 <= 0x39) - v33 = 48; - v35 = v28 - v33; - v36 = 87; - v37 = (v35 << 8) | v34; - if (v29 <= 0x39) - v36 = 48; - v38 = v29 - v36; - v39 = 87; - v40 = (16 * v38) | v37; - if (v30 <= 0x39) - v39 = 48; - v4 += 6; - v41 = ((v30 - v39) | v40) - 56320; - if (v41 > 0x3FF) - return true; - v26 = v41 | ((v26 - 55296) << 10); + v27 = v4[2] | 0x20; + v28 = v4[3] | 0x20; + v29 = v4[4] | 0x20; + v30 = v4[5] | 0x20; + v31 = 87; + if (v27 <= 0x39) + v31 = 48; + v32 = v27 - v31; + v33 = 87; + v34 = v32 << 12; + if (v28 <= 0x39) + v33 = 48; + v35 = v28 - v33; + v36 = 87; + v37 = (v35 << 8) | v34; + if (v29 <= 0x39) + v36 = 48; + v38 = v29 - v36; + v39 = 87; + v40 = (16 * v38) | v37; + if (v30 <= 0x39) + v39 = 48; + v4 += 6; + v41 = ((v30 - v39) | v40) - 56320; + if (v41 > 0x3FF) + return true; + v26 = v41 | ((v26 - 55296) << 10); + } + _strData += (DWORD)sub_F1320(v26, _strData); + LABEL_7: + if (v4 == v7) + goto LABEL_48; } - _strData += (DWORD)sub_F1320(v26, _strData); - LABEL_7: - if (v4 == v7) - goto LABEL_48; + v11 = 10; + LABEL_6: + v5 |= v11; + *_strData++ = v11; + goto LABEL_7; } - v11 = 10; - LABEL_6: - v5 |= v11; - *_strData++ = v11; - goto LABEL_7; } + LABEL_48: + return true; } -LABEL_48: - return true; -} } // namespace ExploitFixes_UTF8Parser \ No newline at end of file diff --git a/NorthstarDedicatedTest/NSMem.h b/NorthstarDedicatedTest/NSMem.h index 50928dd2..74df3a84 100644 --- a/NorthstarDedicatedTest/NSMem.h +++ b/NorthstarDedicatedTest/NSMem.h @@ -6,147 +6,147 @@ #pragma region Pattern Scanning namespace NSMem { -inline std::vector HexBytesToString(const char* str) -{ - std::vector patternNums; - int size = strlen(str); - for (int i = 0; i < size; i++) + inline std::vector HexBytesToString(const char* str) { - char c = str[i]; + std::vector patternNums; + int size = strlen(str); + for (int i = 0; i < size; i++) + { + char c = str[i]; - // If this is a space character, ignore it - if (c == ' ' || c == '\t') - continue; + // If this is a space character, ignore it + if (c == ' ' || c == '\t') + continue; - if (c == '?') - { - // Add a wildcard (-1) - patternNums.push_back(-1); - } - else if (i < size - 1) - { - BYTE result = 0; - for (int j = 0; j < 2; j++) + if (c == '?') { - int val = 0; - char c = *(str + i + j); - if (c >= 'a') - { - val = c - 'a' + 0xA; - } - else if (c >= 'A') - { - val = c - 'A' + 0xA; - } - else if (isdigit(c)) - { - val = c - '0'; - } - else + // Add a wildcard (-1) + patternNums.push_back(-1); + } + else if (i < size - 1) + { + BYTE result = 0; + for (int j = 0; j < 2; j++) { - assert(false, "Failed to parse invalid hex string."); - val = -1; + int val = 0; + char c = *(str + i + j); + if (c >= 'a') + { + val = c - 'a' + 0xA; + } + else if (c >= 'A') + { + val = c - 'A' + 0xA; + } + else if (isdigit(c)) + { + val = c - '0'; + } + else + { + assert(false, "Failed to parse invalid hex string."); + val = -1; + } + + result += (j == 0) ? val * 16 : val; } - - result += (j == 0) ? val * 16 : val; + patternNums.push_back(result); } - patternNums.push_back(result); + + i++; } - i++; + return patternNums; } - return patternNums; -} - -inline void* PatternScan(void* module, const int* pattern, int patternSize, int offset) -{ - if (!module) - return NULL; + inline void* PatternScan(void* module, const int* pattern, int patternSize, int offset) + { + if (!module) + return NULL; - auto dosHeader = (PIMAGE_DOS_HEADER)module; - auto ntHeaders = (PIMAGE_NT_HEADERS)((BYTE*)module + dosHeader->e_lfanew); + auto dosHeader = (PIMAGE_DOS_HEADER)module; + auto ntHeaders = (PIMAGE_NT_HEADERS)((BYTE*)module + dosHeader->e_lfanew); - auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage; + auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage; - auto scanBytes = (BYTE*)module; + auto scanBytes = (BYTE*)module; - for (auto i = 0; i < sizeOfImage - patternSize; ++i) - { - bool found = true; - for (auto j = 0; j < patternSize; ++j) + for (auto i = 0; i < sizeOfImage - patternSize; ++i) { - if (scanBytes[i + j] != pattern[j] && pattern[j] != -1) + bool found = true; + for (auto j = 0; j < patternSize; ++j) { - found = false; - break; + if (scanBytes[i + j] != pattern[j] && pattern[j] != -1) + { + found = false; + break; + } } - } - if (found) - { - uintptr_t addressInt = (uintptr_t)(&scanBytes[i]) + offset; - return (uint8_t*)addressInt; + if (found) + { + uintptr_t addressInt = (uintptr_t)(&scanBytes[i]) + offset; + return (uint8_t*)addressInt; + } } - } - return nullptr; -} + return nullptr; + } -inline void* PatternScan(const char* moduleName, const char* pattern, int offset = 0) -{ - std::vector patternNums = HexBytesToString(pattern); + inline void* PatternScan(const char* moduleName, const char* pattern, int offset = 0) + { + std::vector patternNums = HexBytesToString(pattern); - return PatternScan(GetModuleHandleA(moduleName), &patternNums[0], patternNums.size(), offset); -} + return PatternScan(GetModuleHandleA(moduleName), &patternNums[0], patternNums.size(), offset); + } -inline void BytePatch(uintptr_t address, const BYTE* vals, int size) -{ - WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, vals, size, NULL); -} + inline void BytePatch(uintptr_t address, const BYTE* vals, int size) + { + WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, vals, size, NULL); + } -inline void BytePatch(uintptr_t address, std::initializer_list vals) -{ - std::vector bytes = vals; - if (!bytes.empty()) - BytePatch(address, &bytes[0], bytes.size()); -} + inline void BytePatch(uintptr_t address, std::initializer_list vals) + { + std::vector bytes = vals; + if (!bytes.empty()) + BytePatch(address, &bytes[0], bytes.size()); + } -inline void BytePatch(uintptr_t address, const char* bytesStr) -{ - std::vector byteInts = HexBytesToString(bytesStr); - std::vector bytes; - for (int v : byteInts) - bytes.push_back(v); + inline void BytePatch(uintptr_t address, const char* bytesStr) + { + std::vector byteInts = HexBytesToString(bytesStr); + std::vector bytes; + for (int v : byteInts) + bytes.push_back(v); - if (!bytes.empty()) - BytePatch(address, &bytes[0], bytes.size()); -} + if (!bytes.empty()) + BytePatch(address, &bytes[0], bytes.size()); + } -inline void NOP(uintptr_t address, int size) -{ - BYTE* buf = (BYTE*)malloc(size); - memset(buf, 0x90, size); - BytePatch(address, buf, size); - free(buf); -} + inline void NOP(uintptr_t address, int size) + { + BYTE* buf = (BYTE*)malloc(size); + memset(buf, 0x90, size); + BytePatch(address, buf, size); + free(buf); + } -inline bool IsMemoryReadable(void* ptr, size_t size) -{ - static SYSTEM_INFO sysInfo; - if (!sysInfo.dwPageSize) - GetSystemInfo(&sysInfo); // This should always be 4096 unless ur playing on NES or some shit but whatever + inline bool IsMemoryReadable(void* ptr, size_t size) + { + static SYSTEM_INFO sysInfo; + if (!sysInfo.dwPageSize) + GetSystemInfo(&sysInfo); // This should always be 4096 unless ur playing on NES or some shit but whatever - MEMORY_BASIC_INFORMATION memInfo; + MEMORY_BASIC_INFORMATION memInfo; - if (!VirtualQuery(ptr, &memInfo, sizeof(memInfo))) - return false; + if (!VirtualQuery(ptr, &memInfo, sizeof(memInfo))) + return false; - if (memInfo.RegionSize < size) - return false; + if (memInfo.RegionSize < size) + return false; - return (memInfo.State & MEM_COMMIT) && !(memInfo.Protect & PAGE_NOACCESS); -} + return (memInfo.State & MEM_COMMIT) && !(memInfo.Protect & PAGE_NOACCESS); + } } // namespace NSMem #pragma region KHOOK diff --git a/NorthstarDedicatedTest/audio.cpp b/NorthstarDedicatedTest/audio.cpp index f2c8ba65..0b65670f 100644 --- a/NorthstarDedicatedTest/audio.cpp +++ b/NorthstarDedicatedTest/audio.cpp @@ -57,8 +57,10 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa if (dataJson.HasParseError()) { spdlog::error( - "Failed reading audio override file {}: encountered parse error \"{}\" at offset {}", path.string(), - GetParseError_En(dataJson.GetParseError()), dataJson.GetErrorOffset()); + "Failed reading audio override file {}: encountered parse error \"{}\" at offset {}", + path.string(), + GetParseError_En(dataJson.GetParseError()), + dataJson.GetErrorOffset()); return; } @@ -486,7 +488,10 @@ bool __fastcall LoadSampleMetadata_Hook(void* sample, void* audioBuffer, unsigne typedef bool (*MilesLog_Type)(int level, const char* string); MilesLog_Type MilesLog_Original; -void __fastcall MilesLog_Hook(int level, const char* string) { spdlog::info("[MSS] {} - {}", level, string); } +void __fastcall MilesLog_Hook(int level, const char* string) +{ + spdlog::info("[MSS] {} - {}", level, string); +} void InitialiseMilesAudioHooks(HMODULE baseAddress) { diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp index 0a4e9124..93cf9c65 100644 --- a/NorthstarDedicatedTest/bansystem.cpp +++ b/NorthstarDedicatedTest/bansystem.cpp @@ -90,7 +90,10 @@ void UnbanPlayerCommand(const CCommand& args) g_ServerBanSystem->UnbanUID(strtoll(args.Arg(1), nullptr, 10)); } -void ClearBanlistCommand(const CCommand& args) { g_ServerBanSystem->ClearBanlist(); } +void ClearBanlistCommand(const CCommand& args) +{ + g_ServerBanSystem->ClearBanlist(); +} void InitialiseBanSystem(HMODULE baseAddress) { diff --git a/NorthstarDedicatedTest/bitbuf.h b/NorthstarDedicatedTest/bitbuf.h index 902a9976..520e5d0a 100644 --- a/NorthstarDedicatedTest/bitbuf.h +++ b/NorthstarDedicatedTest/bitbuf.h @@ -32,9 +32,15 @@ using iptr = intptr_t; // Endianess, don't use on PPC64 nor ARM64BE #define LittleDWord(val) (val) -static INLINE void StoreLittleDWord(u32* base, size_t dwordIndex, u32 dword) { base[dwordIndex] = LittleDWord(dword); } +static INLINE void StoreLittleDWord(u32* base, size_t dwordIndex, u32 dword) +{ + base[dwordIndex] = LittleDWord(dword); +} -static INLINE u32 LoadLittleDWord(u32* base, size_t dwordIndex) { return LittleDWord(base[dwordIndex]); } +static INLINE u32 LoadLittleDWord(u32* base, size_t dwordIndex) +{ + return LittleDWord(base[dwordIndex]); +} #include @@ -84,13 +90,25 @@ enum EBitCoordType class BitBufferBase { protected: - INLINE void SetName(const char* name) { m_BufferName = name; } + INLINE void SetName(const char* name) + { + m_BufferName = name; + } public: - INLINE bool IsOverflowed() { return m_Overflow; } - INLINE void SetOverflowed() { m_Overflow = true; } + INLINE bool IsOverflowed() + { + return m_Overflow; + } + INLINE void SetOverflowed() + { + m_Overflow = true; + } - INLINE const char* GetName() { return m_BufferName; } + INLINE const char* GetName() + { + return m_BufferName; + } private: const char* m_BufferName = ""; @@ -419,13 +437,28 @@ class BFRead : public BitBufferBase return fReturn; } - INLINE i32 ReadChar() { return ReadSBitLong(sizeof(char) << 3); } - INLINE u32 ReadByte() { return ReadUBitLong(sizeof(unsigned char) << 3); } + INLINE i32 ReadChar() + { + return ReadSBitLong(sizeof(char) << 3); + } + INLINE u32 ReadByte() + { + return ReadUBitLong(sizeof(unsigned char) << 3); + } - INLINE i32 ReadShort() { return ReadSBitLong(sizeof(short) << 3); } - INLINE u32 ReadWord() { return ReadUBitLong(sizeof(unsigned short) << 3); } + INLINE i32 ReadShort() + { + return ReadSBitLong(sizeof(short) << 3); + } + INLINE u32 ReadWord() + { + return ReadUBitLong(sizeof(unsigned short) << 3); + } - INLINE i32 ReadLong() { return (i32)(ReadUBitLong(sizeof(i32) << 3)); } + INLINE i32 ReadLong() + { + return (i32)(ReadUBitLong(sizeof(i32) << 3)); + } INLINE float ReadFloat() { u32 temp = ReadUBitLong(sizeof(float) << 3); @@ -654,23 +687,35 @@ class BFRead : public BitBufferBase return std::min(nCurOfs + nAdjust, m_DataBits); } - INLINE bool SeekRelative(size_t offset) { return Seek(GetNumBitsRead() + offset); } + INLINE bool SeekRelative(size_t offset) + { + return Seek(GetNumBitsRead() + offset); + } - INLINE size_t TotalBytesAvailable() { return m_DataBytes; } + INLINE size_t TotalBytesAvailable() + { + return m_DataBytes; + } - INLINE size_t GetNumBitsLeft() { return m_DataBits - GetNumBitsRead(); } - INLINE size_t GetNumBytesLeft() { return GetNumBitsLeft() >> 3; } + INLINE size_t GetNumBitsLeft() + { + return m_DataBits - GetNumBitsRead(); + } + INLINE size_t GetNumBytesLeft() + { + return GetNumBitsLeft() >> 3; + } private: - size_t m_DataBits; // 0x0010 + size_t m_DataBits; // 0x0010 size_t m_DataBytes; // 0x0018 - u32 m_CachedBufWord; // 0x0020 + u32 m_CachedBufWord; // 0x0020 u32 m_CachedBitsLeft; // 0x0024 - const u32* m_DataIn; // 0x0028 + const u32* m_DataIn; // 0x0028 const u32* m_DataEnd; // 0x0030 - const u32* m_Data; // 0x0038 + const u32* m_Data; // 0x0038 }; class BFWrite : public BitBufferBase @@ -698,7 +743,10 @@ class BFWrite : public BitBufferBase m_DataEnd = reinterpret_cast(reinterpret_cast(m_Data) + m_DataBytes); } - INLINE int GetNumBitsLeft() { return m_OutBitsLeft + (32 * (m_DataEnd - m_DataOut - 1)); } + INLINE int GetNumBitsLeft() + { + return m_OutBitsLeft + (32 * (m_DataEnd - m_DataOut - 1)); + } INLINE void Reset() { @@ -727,7 +775,10 @@ class BFWrite : public BitBufferBase return reinterpret_cast(m_Data); } - INLINE u8* GetData() { return GetBasePointer(); } + INLINE u8* GetData() + { + return GetBasePointer(); + } INLINE void Finish() { @@ -800,7 +851,10 @@ class BFWrite : public BitBufferBase } } - INLINE void WriteSBitLong(i32 data, i32 numBits) { WriteUBitLong((u32)data, numBits, false); } + INLINE void WriteSBitLong(i32 data, i32 numBits) + { + WriteUBitLong((u32)data, numBits, false); + } INLINE void WriteUBitVar(u32 n) { @@ -857,19 +911,40 @@ class BFWrite : public BitBufferBase return !IsOverflowed(); } - INLINE bool WriteBytes(const uptr data, i32 numBytes) { return WriteBits(data, numBytes << 3); } + INLINE bool WriteBytes(const uptr data, i32 numBytes) + { + return WriteBits(data, numBytes << 3); + } - INLINE i32 GetNumBitsWritten() { return (32 - m_OutBitsLeft) + (32 * (m_DataOut - m_Data)); } + INLINE i32 GetNumBitsWritten() + { + return (32 - m_OutBitsLeft) + (32 * (m_DataOut - m_Data)); + } - INLINE i32 GetNumBytesWritten() { return (GetNumBitsWritten() + 7) >> 3; } + INLINE i32 GetNumBytesWritten() + { + return (GetNumBitsWritten() + 7) >> 3; + } - INLINE void WriteChar(i32 val) { WriteSBitLong(val, sizeof(char) << 3); } + INLINE void WriteChar(i32 val) + { + WriteSBitLong(val, sizeof(char) << 3); + } - INLINE void WriteByte(i32 val) { WriteUBitLong(val, sizeof(unsigned char) << 3, false); } + INLINE void WriteByte(i32 val) + { + WriteUBitLong(val, sizeof(unsigned char) << 3, false); + } - INLINE void WriteShort(i32 val) { WriteSBitLong(val, sizeof(short) << 3); } + INLINE void WriteShort(i32 val) + { + WriteSBitLong(val, sizeof(short) << 3); + } - INLINE void WriteWord(i32 val) { WriteUBitLong(val, sizeof(unsigned short) << 3); } + INLINE void WriteWord(i32 val) + { + WriteUBitLong(val, sizeof(unsigned short) << 3); + } INLINE bool WriteString(const char* str) { diff --git a/NorthstarDedicatedTest/bits.cpp b/NorthstarDedicatedTest/bits.cpp index 45375b18..014899f2 100644 --- a/NorthstarDedicatedTest/bits.cpp +++ b/NorthstarDedicatedTest/bits.cpp @@ -10,17 +10,35 @@ //----------------------------------------------------------------------------- // This follows the ANSI/IEEE 754-1985 standard //----------------------------------------------------------------------------- -unsigned long& FloatBits(float& f) { return *reinterpret_cast(&f); } +unsigned long& FloatBits(float& f) +{ + return *reinterpret_cast(&f); +} -unsigned long const& FloatBits(float const& f) { return *reinterpret_cast(&f); } +unsigned long const& FloatBits(float const& f) +{ + return *reinterpret_cast(&f); +} -float BitsToFloat(unsigned long i) { return *reinterpret_cast(&i); } +float BitsToFloat(unsigned long i) +{ + return *reinterpret_cast(&i); +} -bool IsFinite(float f) { return ((FloatBits(f) & 0x7F800000) != 0x7F800000); } +bool IsFinite(float f) +{ + return ((FloatBits(f) & 0x7F800000) != 0x7F800000); +} -unsigned long FloatAbsBits(float f) { return FloatBits(f) & 0x7FFFFFFF; } +unsigned long FloatAbsBits(float f) +{ + return FloatBits(f) & 0x7FFFFFFF; +} -float FloatMakePositive(float f) { return fabsf(f); } +float FloatMakePositive(float f) +{ + return fabsf(f); +} float FloatNegate(float f) { diff --git a/NorthstarDedicatedTest/buildainfile.cpp b/NorthstarDedicatedTest/buildainfile.cpp index 3f30eff3..010f0975 100644 --- a/NorthstarDedicatedTest/buildainfile.cpp +++ b/NorthstarDedicatedTest/buildainfile.cpp @@ -43,23 +43,23 @@ struct CAI_Node float hulls[MAX_HULLS]; float yaw; - int unk0; // always 2 in buildainfile, maps directly to unk0 in disk struct - int unk1; // maps directly to unk1 in disk struct + int unk0; // always 2 in buildainfile, maps directly to unk0 in disk struct + int unk1; // maps directly to unk1 in disk struct int unk2[MAX_HULLS]; // maps directly to unk2 in disk struct, despite being ints rather than shorts // view server.dll+393672 for context and death wish - char unk3[MAX_HULLS]; // hell on earth, should map to unk3 on disk - char pad[3]; // aligns next bytes + char unk3[MAX_HULLS]; // hell on earth, should map to unk3 on disk + char pad[3]; // aligns next bytes float unk4[MAX_HULLS]; // i have no fucking clue, calculated using some kind of demon hell function float magic CAI_NodeLink** links; char unk5[16]; int linkcount; - int unk11; // bad name lmao - short unk6; // should match up to unk4 on disk + int unk11; // bad name lmao + short unk6; // should match up to unk4 on disk char unk7[16]; // padding until next bit - short unk8; // should match up to unk5 on disk - char unk9[8]; // padding until next bit + short unk8; // should match up to unk5 on disk + char unk9[8]; // padding until next bit char unk10[8]; // should match up to unk6 on disk }; @@ -86,7 +86,7 @@ struct UnkNodeStruct0 { int index; char unk0; - char unk1; // maps to unk1 on disk + char unk1; // maps to unk1 on disk char pad0[2]; // padding to +8 float x; @@ -94,7 +94,7 @@ struct UnkNodeStruct0 float z; char pad5[4]; - int* unk2; // maps to unk5 on disk; + int* unk2; // maps to unk5 on disk; char pad1[16]; // pad to +48 int unkcount0; // maps to unkcount0 on disk diff --git a/NorthstarDedicatedTest/clientauthhooks.cpp b/NorthstarDedicatedTest/clientauthhooks.cpp index 40c218c4..5c1c4510 100644 --- a/NorthstarDedicatedTest/clientauthhooks.cpp +++ b/NorthstarDedicatedTest/clientauthhooks.cpp @@ -37,7 +37,9 @@ void InitialiseClientAuthHooks(HMODULE baseAddress) { // this cvar will save to cfg once initially agreed with Cvar_ns_has_agreed_to_send_token = new ConVar( - "ns_has_agreed_to_send_token", "0", FCVAR_ARCHIVE_PLAYERPROFILE, + "ns_has_agreed_to_send_token", + "0", + FCVAR_ARCHIVE_PLAYERPROFILE, "whether the user has agreed to send their origin token to the northstar masterserver"); HookEnabler hook; diff --git a/NorthstarDedicatedTest/color.h b/NorthstarDedicatedTest/color.h index b2d02d1e..e2c1ebba 100644 --- a/NorthstarDedicatedTest/color.h +++ b/NorthstarDedicatedTest/color.h @@ -7,10 +7,22 @@ struct color24 typedef struct color32_s { - bool operator!=(const struct color32_s& other) const { return r != other.r || g != other.g || b != other.b || a != other.a; } - inline unsigned* asInt(void) { return reinterpret_cast(this); } - inline const unsigned* asInt(void) const { return reinterpret_cast(this); } - inline void Copy(const color32_s& rhs) { *asInt() = *rhs.asInt(); } + bool operator!=(const struct color32_s& other) const + { + return r != other.r || g != other.g || b != other.b || a != other.a; + } + inline unsigned* asInt(void) + { + return reinterpret_cast(this); + } + inline const unsigned* asInt(void) const + { + return reinterpret_cast(this); + } + inline void Copy(const color32_s& rhs) + { + *asInt() = *rhs.asInt(); + } uint8_t r, g, b, a; } color32; @@ -43,22 +55,55 @@ class Color _b = _color[2]; _a = _color[3]; } - int GetValue(int index) const { return _color[index]; } - void SetRawColor(int color32) { *((int*)this) = color32; } - int GetRawColor(void) const { return *((int*)this); } + int GetValue(int index) const + { + return _color[index]; + } + void SetRawColor(int color32) + { + *((int*)this) = color32; + } + int GetRawColor(void) const + { + return *((int*)this); + } - inline int r() const { return _color[0]; } - inline int g() const { return _color[1]; } - inline int b() const { return _color[2]; } - inline int a() const { return _color[3]; } + inline int r() const + { + return _color[0]; + } + inline int g() const + { + return _color[1]; + } + inline int b() const + { + return _color[2]; + } + inline int a() const + { + return _color[3]; + } - unsigned char& operator[](int index) { return _color[index]; } + unsigned char& operator[](int index) + { + return _color[index]; + } - const unsigned char& operator[](int index) const { return _color[index]; } + const unsigned char& operator[](int index) const + { + return _color[index]; + } - bool operator==(const Color& rhs) const { return (*((int*)this) == *((int*)&rhs)); } + bool operator==(const Color& rhs) const + { + return (*((int*)this) == *((int*)&rhs)); + } - bool operator!=(const Color& rhs) const { return !(operator==(rhs)); } + bool operator!=(const Color& rhs) const + { + return !(operator==(rhs)); + } Color& operator=(const Color& rhs) { @@ -77,7 +122,7 @@ class Color color32 ToColor32(void) const { - color32 newColor{}; + color32 newColor {}; newColor.r = _color[0]; newColor.g = _color[1]; newColor.b = _color[2]; diff --git a/NorthstarDedicatedTest/concommand.cpp b/NorthstarDedicatedTest/concommand.cpp index b455100f..1bdda91b 100644 --- a/NorthstarDedicatedTest/concommand.cpp +++ b/NorthstarDedicatedTest/concommand.cpp @@ -27,19 +27,28 @@ void InitialiseConCommands(HMODULE baseAddress) // Purpose: Returns true if this is a command // Output : bool //----------------------------------------------------------------------------- -bool ConCommand::IsCommand(void) const { return true; } +bool ConCommand::IsCommand(void) const +{ + return true; +} //----------------------------------------------------------------------------- // Purpose: Returns true if this is a command // Output : bool //----------------------------------------------------------------------------- -bool ConCommandBase::IsCommand(void) const { return true; } +bool ConCommandBase::IsCommand(void) const +{ + return true; +} //----------------------------------------------------------------------------- // Purpose: Has this cvar been registered // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- -bool ConCommandBase::IsRegistered(void) const { return m_bRegistered; } +bool ConCommandBase::IsRegistered(void) const +{ + return m_bRegistered; +} //----------------------------------------------------------------------------- // Purpose: Test each ConCommand query before execution. @@ -56,37 +65,55 @@ bool ConCommandBase::IsFlagSet(int nFlags) const // Input : nFlags - // Output : True if ConCommand has nFlags. //----------------------------------------------------------------------------- -bool ConCommandBase::HasFlags(int nFlags) { return m_nFlags & nFlags; } +bool ConCommandBase::HasFlags(int nFlags) +{ + return m_nFlags & nFlags; +} //----------------------------------------------------------------------------- // Purpose: Add's flags to ConCommand. // Input : nFlags - //----------------------------------------------------------------------------- -void ConCommandBase::AddFlags(int nFlags) { m_nFlags |= nFlags; } +void ConCommandBase::AddFlags(int nFlags) +{ + m_nFlags |= nFlags; +} //----------------------------------------------------------------------------- // Purpose: Removes flags from ConCommand. // Input : nFlags - //----------------------------------------------------------------------------- -void ConCommandBase::RemoveFlags(int nFlags) { m_nFlags &= ~nFlags; } +void ConCommandBase::RemoveFlags(int nFlags) +{ + m_nFlags &= ~nFlags; +} //----------------------------------------------------------------------------- // Purpose: Returns current flags. // Output : int //----------------------------------------------------------------------------- -int ConCommandBase::GetFlags(void) const { return m_nFlags; } +int ConCommandBase::GetFlags(void) const +{ + return m_nFlags; +} //----------------------------------------------------------------------------- // Purpose: // Output : const ConCommandBase //----------------------------------------------------------------------------- -ConCommandBase* ConCommandBase::GetNext(void) const { return m_pNext; } +ConCommandBase* ConCommandBase::GetNext(void) const +{ + return m_pNext; +} //----------------------------------------------------------------------------- // Purpose: Returns the ConCommandBase help text. // Output : const char* //----------------------------------------------------------------------------- -const char* ConCommandBase::GetHelpText(void) const { return m_pszHelpString; } +const char* ConCommandBase::GetHelpText(void) const +{ + return m_pszHelpString; +} //----------------------------------------------------------------------------- // Purpose: Copies string using local new/delete operators diff --git a/NorthstarDedicatedTest/concommand.h b/NorthstarDedicatedTest/concommand.h index 8f5d59e0..ea35ec1f 100644 --- a/NorthstarDedicatedTest/concommand.h +++ b/NorthstarDedicatedTest/concommand.h @@ -17,10 +17,10 @@ class CCommand int64_t ArgC() const; const char** ArgV() const; - const char* ArgS() const; // All args that occur after the 0th arg, in string form - const char* GetCommandString() const; // The entire command in string form, including the 0th arg + const char* ArgS() const; // All args that occur after the 0th arg, in string form + const char* GetCommandString() const; // The entire command in string form, including the 0th arg const char* operator[](int nIndex) const; // Gets at arguments - const char* Arg(int nIndex) const; // Gets at arguments + const char* Arg(int nIndex) const; // Gets at arguments static int MaxCommandLength(); @@ -38,11 +38,26 @@ class CCommand const char* m_ppArgv[COMMAND_MAX_ARGC]; }; -inline int CCommand::MaxCommandLength() { return COMMAND_MAX_LENGTH - 1; } -inline int64_t CCommand::ArgC() const { return m_nArgc; } -inline const char** CCommand::ArgV() const { return m_nArgc ? (const char**)m_ppArgv : NULL; } -inline const char* CCommand::ArgS() const { return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; } -inline const char* CCommand::GetCommandString() const { return m_nArgc ? m_pArgSBuffer : ""; } +inline int CCommand::MaxCommandLength() +{ + return COMMAND_MAX_LENGTH - 1; +} +inline int64_t CCommand::ArgC() const +{ + return m_nArgc; +} +inline const char** CCommand::ArgV() const +{ + return m_nArgc ? (const char**)m_ppArgv : NULL; +} +inline const char* CCommand::ArgS() const +{ + return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; +} +inline const char* CCommand::GetCommandString() const +{ + return m_nArgc ? m_pArgSBuffer : ""; +} inline const char* CCommand::Arg(int nIndex) const { // FIXME: Many command handlers appear to not be particularly careful @@ -52,7 +67,10 @@ inline const char* CCommand::Arg(int nIndex) const return ""; return m_ppArgv[nIndex]; } -inline const char* CCommand::operator[](int nIndex) const { return Arg(nIndex); } +inline const char* CCommand::operator[](int nIndex) const +{ + return Arg(nIndex); +} // From r5reloaded class ConCommandBase @@ -73,16 +91,16 @@ class ConCommandBase char* CopyString(const char* szFrom) const; - void* m_pConCommandBaseVTable; // 0x0000 - ConCommandBase* m_pNext; // 0x0008 - bool m_bRegistered; // 0x0010 - char pad_0011[7]; // 0x0011 <- 3 bytes padding + unk int32. - const char* m_pszName; // 0x0018 - const char* m_pszHelpString; // 0x0020 - int m_nFlags; // 0x0028 - ConCommandBase* s_pConCommandBases; // 0x002C + void* m_pConCommandBaseVTable; // 0x0000 + ConCommandBase* m_pNext; // 0x0008 + bool m_bRegistered; // 0x0010 + char pad_0011[7]; // 0x0011 <- 3 bytes padding + unk int32. + const char* m_pszName; // 0x0018 + const char* m_pszHelpString; // 0x0020 + int m_nFlags; // 0x0028 + ConCommandBase* s_pConCommandBases; // 0x002C IConCommandBaseAccessor* s_pAccessor; // 0x0034 -}; // Size: 0x0040 +}; // Size: 0x0040 // taken from ttf2sdk class ConCommand : public ConCommandBase @@ -90,18 +108,18 @@ class ConCommand : public ConCommandBase friend class CCVar; public: - ConCommand(void){}; // !TODO: Rebuild engine constructor in SDK instead. + ConCommand(void) {}; // !TODO: Rebuild engine constructor in SDK instead. ConCommand(const char* szName, const char* szHelpString, int nFlags, void* pCallback, void* pCommandCompletionCallback); void Init(void); bool IsCommand(void) const; - void* m_pCommandCallback{}; // 0x0040 <- starts from 0x40 since we inherit ConCommandBase. - void* m_pCompletionCallback{}; // 0x0048 <- defaults to sub_180417410 ('xor eax, eax'). - int m_nCallbackFlags{}; // 0x0050 - char pad_0054[4]; // 0x0054 - int unk0; // 0x0058 - int unk1; // 0x005C -}; // Size: 0x0060 + void* m_pCommandCallback {}; // 0x0040 <- starts from 0x40 since we inherit ConCommandBase. + void* m_pCompletionCallback {}; // 0x0048 <- defaults to sub_180417410 ('xor eax, eax'). + int m_nCallbackFlags {}; // 0x0050 + char pad_0054[4]; // 0x0054 + int unk0; // 0x0058 + int unk1; // 0x005C +}; // Size: 0x0060 void RegisterConCommand(const char* name, void (*callback)(const CCommand&), const char* helpString, int flags); void InitialiseConCommands(HMODULE baseAddress); diff --git a/NorthstarDedicatedTest/configurables.cpp b/NorthstarDedicatedTest/configurables.cpp index 6b9f8e26..389e6e0b 100644 --- a/NorthstarDedicatedTest/configurables.cpp +++ b/NorthstarDedicatedTest/configurables.cpp @@ -2,7 +2,10 @@ #include "pch.h" #include "configurables.h" -std::string GetNorthstarPrefix() { return NORTHSTAR_FOLDER_PREFIX; } +std::string GetNorthstarPrefix() +{ + return NORTHSTAR_FOLDER_PREFIX; +} void parseConfigurables() { diff --git a/NorthstarDedicatedTest/convar.cpp b/NorthstarDedicatedTest/convar.cpp index c750bd4d..346e7b69 100644 --- a/NorthstarDedicatedTest/convar.cpp +++ b/NorthstarDedicatedTest/convar.cpp @@ -7,8 +7,16 @@ #include "sourceinterface.h" typedef void (*ConVarRegisterType)( - ConVar* pConVar, const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin, float fMin, - bool bMax, float fMax, void* pCallback); + ConVar* pConVar, + const char* pszName, + const char* pszDefaultValue, + int nFlags, + const char* pszHelpString, + bool bMin, + float fMin, + bool bMax, + float fMax, + void* pCallback); ConVarRegisterType conVarRegister; typedef void (*ConVarMallocType)(void* pConVarMaloc, int a2, int a3); @@ -56,7 +64,14 @@ ConVar::ConVar(const char* pszName, const char* pszDefaultValue, int nFlags, con // Purpose: constructor //----------------------------------------------------------------------------- ConVar::ConVar( - const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin, float fMin, bool bMax, float fMax, + const char* pszName, + const char* pszDefaultValue, + int nFlags, + const char* pszHelpString, + bool bMin, + float fMin, + bool bMax, + float fMax, void* pCallback) { spdlog::info("Registering Convar {}", pszName); @@ -81,43 +96,64 @@ ConVar::~ConVar(void) // Purpose: Returns the base ConVar name. // Output : const char* //----------------------------------------------------------------------------- -const char* ConVar::GetBaseName(void) const { return m_ConCommandBase.m_pszName; } +const char* ConVar::GetBaseName(void) const +{ + return m_ConCommandBase.m_pszName; +} //----------------------------------------------------------------------------- // Purpose: Returns the ConVar help text. // Output : const char* //----------------------------------------------------------------------------- -const char* ConVar::GetHelpText(void) const { return m_ConCommandBase.m_pszHelpString; } +const char* ConVar::GetHelpText(void) const +{ + return m_ConCommandBase.m_pszHelpString; +} //----------------------------------------------------------------------------- // Purpose: Add's flags to ConVar. // Input : nFlags - //----------------------------------------------------------------------------- -void ConVar::AddFlags(int nFlags) { m_ConCommandBase.m_nFlags |= nFlags; } +void ConVar::AddFlags(int nFlags) +{ + m_ConCommandBase.m_nFlags |= nFlags; +} //----------------------------------------------------------------------------- // Purpose: Removes flags from ConVar. // Input : nFlags - //----------------------------------------------------------------------------- -void ConVar::RemoveFlags(int nFlags) { m_ConCommandBase.m_nFlags &= ~nFlags; } +void ConVar::RemoveFlags(int nFlags) +{ + m_ConCommandBase.m_nFlags &= ~nFlags; +} //----------------------------------------------------------------------------- // Purpose: Return ConVar value as a boolean. // Output : bool //----------------------------------------------------------------------------- -bool ConVar::GetBool(void) const { return !!GetInt(); } +bool ConVar::GetBool(void) const +{ + return !!GetInt(); +} //----------------------------------------------------------------------------- // Purpose: Return ConVar value as a float. // Output : float //----------------------------------------------------------------------------- -float ConVar::GetFloat(void) const { return m_Value.m_fValue; } +float ConVar::GetFloat(void) const +{ + return m_Value.m_fValue; +} //----------------------------------------------------------------------------- // Purpose: Return ConVar value as an integer. // Output : int //----------------------------------------------------------------------------- -int ConVar::GetInt(void) const { return m_Value.m_nValue; } +int ConVar::GetInt(void) const +{ + return m_Value.m_nValue; +} //----------------------------------------------------------------------------- // Purpose: Return ConVar value as a color. @@ -170,7 +206,10 @@ bool ConVar::GetMax(float& flMaxVal) const // Purpose: returns the min value. // Output : float //----------------------------------------------------------------------------- -float ConVar::GetMinValue(void) const { return m_fMinVal; } +float ConVar::GetMinValue(void) const +{ + return m_fMinVal; +} //----------------------------------------------------------------------------- // Purpose: returns the max value. @@ -186,13 +225,19 @@ float ConVar::GetMaxValue(void) const // Purpose: checks if ConVar has min value. // Output : bool //----------------------------------------------------------------------------- -bool ConVar::HasMin(void) const { return m_bHasMin; } +bool ConVar::HasMin(void) const +{ + return m_bHasMin; +} //----------------------------------------------------------------------------- // Purpose: checks if ConVar has max value. // Output : bool //----------------------------------------------------------------------------- -bool ConVar::HasMax(void) const { return m_bHasMax; } +bool ConVar::HasMax(void) const +{ + return m_bHasMax; +} //----------------------------------------------------------------------------- // Purpose: sets the ConVar int value. @@ -265,8 +310,8 @@ void ConVar::SetValue(const char* pszValue) } this->m_Value.m_pszString = pszValue; - char szTempValue[32]{}; - const char* pszNewValue{}; + char szTempValue[32] {}; + const char* pszNewValue {}; float flOldValue = m_Value.m_fValue; pszNewValue = (char*)pszValue; @@ -374,7 +419,7 @@ bool ConVar::SetColorFromString(const char* pszValue) bool bColor = false; // Try pulling RGBA color values out of the string. - int nRGBA[4]{}; + int nRGBA[4] {}; int nParamsRead = sscanf_s(pszValue, "%i %i %i %i", &(nRGBA[0]), &(nRGBA[1]), &(nRGBA[2]), &(nRGBA[3])); if (nParamsRead >= 3) @@ -413,13 +458,19 @@ bool ConVar::SetColorFromString(const char* pszValue) // Purpose: Checks if ConVar is registered. // Output : bool //----------------------------------------------------------------------------- -bool ConVar::IsRegistered(void) const { return m_ConCommandBase.m_bRegistered; } +bool ConVar::IsRegistered(void) const +{ + return m_ConCommandBase.m_bRegistered; +} //----------------------------------------------------------------------------- // Purpose: Returns true if this is a command // Output : bool //----------------------------------------------------------------------------- -bool ConVar::IsCommand(void) const { return false; } +bool ConVar::IsCommand(void) const +{ + return false; +} //----------------------------------------------------------------------------- // Purpose: Test each ConVar query before setting the value. diff --git a/NorthstarDedicatedTest/convar.h b/NorthstarDedicatedTest/convar.h index 07e7704b..b1424fb7 100644 --- a/NorthstarDedicatedTest/convar.h +++ b/NorthstarDedicatedTest/convar.h @@ -11,19 +11,19 @@ // Command to ConVars and ConCommands // ConVar Systems -#define FCVAR_UNREGISTERED (1 << 0) // If this is set, don't add to linked list, etc. +#define FCVAR_UNREGISTERED (1 << 0) // If this is set, don't add to linked list, etc. #define FCVAR_DEVELOPMENTONLY (1 << 1) // Hidden in released products. Flag is removed automatically if ALLOW_DEVELOPMENT_CVARS is defined. -#define FCVAR_GAMEDLL (1 << 2) // defined by the game DLL -#define FCVAR_CLIENTDLL (1 << 3) // defined by the client DLL -#define FCVAR_HIDDEN (1 << 4) // Hidden. Doesn't appear in find or auto complete. Like DEVELOPMENTONLY, but can't be compiled out. +#define FCVAR_GAMEDLL (1 << 2) // defined by the game DLL +#define FCVAR_CLIENTDLL (1 << 3) // defined by the client DLL +#define FCVAR_HIDDEN (1 << 4) // Hidden. Doesn't appear in find or auto complete. Like DEVELOPMENTONLY, but can't be compiled out. // ConVar only #define FCVAR_PROTECTED \ (1 << 5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as // value. -#define FCVAR_SPONLY (1 << 6) // This cvar cannot be changed by clients connected to a multiplayer server. -#define FCVAR_ARCHIVE (1 << 7) // set to cause it to be saved to vars.rc -#define FCVAR_NOTIFY (1 << 8) // notifies players when changed +#define FCVAR_SPONLY (1 << 6) // This cvar cannot be changed by clients connected to a multiplayer server. +#define FCVAR_ARCHIVE (1 << 7) // set to cause it to be saved to vars.rc +#define FCVAR_NOTIFY (1 << 8) // notifies players when changed #define FCVAR_USERINFO (1 << 9) // changes the client's info string #define FCVAR_PRINTABLEONLY (1 << 10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ). @@ -32,26 +32,26 @@ // We are changing the default behavior of concommands to disallow execution by remote clients without // this flag due to the number existing concommands that can lag or crash the server when clients abuse them. -#define FCVAR_UNLOGGED (1 << 11) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log +#define FCVAR_UNLOGGED (1 << 11) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log #define FCVAR_NEVER_AS_STRING (1 << 12) // never try to print that cvar // It's a ConVar that's shared between the client and the server. // At signon, the values of all such ConVars are sent from the server to the client (skipped for local client, of course ) // If a change is requested it must come from the console (i.e., no remote client changes) // If a value is changed while a server is active, it's replicated to all connected clients -#define FCVAR_REPLICATED (1 << 13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time -#define FCVAR_CHEAT (1 << 14) // Only useable in singleplayer / debug / multiplayer & sv_cheats -#define FCVAR_SS (1 << 15) // causes varnameN where N == 2 through max splitscreen slots for mod to be autogenerated -#define FCVAR_DEMO (1 << 16) // record this cvar when starting a demo file -#define FCVAR_DONTRECORD (1 << 17) // don't record these command in demofiles -#define FCVAR_SS_ADDED (1 << 18) // This is one of the "added" FCVAR_SS variables for the splitscreen players -#define FCVAR_RELEASE (1 << 19) // Cvars tagged with this are the only cvars avaliable to customers +#define FCVAR_REPLICATED (1 << 13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time +#define FCVAR_CHEAT (1 << 14) // Only useable in singleplayer / debug / multiplayer & sv_cheats +#define FCVAR_SS (1 << 15) // causes varnameN where N == 2 through max splitscreen slots for mod to be autogenerated +#define FCVAR_DEMO (1 << 16) // record this cvar when starting a demo file +#define FCVAR_DONTRECORD (1 << 17) // don't record these command in demofiles +#define FCVAR_SS_ADDED (1 << 18) // This is one of the "added" FCVAR_SS variables for the splitscreen players +#define FCVAR_RELEASE (1 << 19) // Cvars tagged with this are the only cvars avaliable to customers #define FCVAR_RELOAD_MATERIALS (1 << 20) // If this cvar changes, it forces a material reload -#define FCVAR_RELOAD_TEXTURES (1 << 21) // If this cvar changes, if forces a texture reload +#define FCVAR_RELOAD_TEXTURES (1 << 21) // If this cvar changes, if forces a texture reload -#define FCVAR_NOT_CONNECTED (1 << 22) // cvar cannot be changed by a client that is connected to a server +#define FCVAR_NOT_CONNECTED (1 << 22) // cvar cannot be changed by a client that is connected to a server #define FCVAR_MATERIAL_SYSTEM_THREAD (1 << 23) // Indicates this cvar is read from the material system thread -#define FCVAR_ARCHIVE_PLAYERPROFILE (1 << 24) // respawn-defined flag, same as FCVAR_ARCHIVE but writes to profile.cfg +#define FCVAR_ARCHIVE_PLAYERPROFILE (1 << 24) // respawn-defined flag, same as FCVAR_ARCHIVE but writes to profile.cfg #define FCVAR_SERVER_CAN_EXECUTE \ (1 << 28) // the server is allowed to execute this command on clients via @@ -80,11 +80,18 @@ class ConVar; class ConVar { public: - ConVar(void){}; + ConVar(void) {}; ConVar(const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString); ConVar( - const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin, float fMin, bool bMax, - float fMax, void* pCallback); + const char* pszName, + const char* pszDefaultValue, + int nFlags, + const char* pszHelpString, + bool bMin, + float fMin, + bool bMax, + float fMax, + void* pCallback); ~ConVar(void); const char* GetBaseName(void) const; @@ -128,15 +135,15 @@ class ConVar int m_nValue; }; - ConCommandBase m_ConCommandBase{}; // 0x0000 - const char* m_pszDefaultValue{}; // 0x0040 - CVValue_t m_Value{}; // 0x0048 - bool m_bHasMin{}; // 0x005C - float m_fMinVal{}; // 0x0060 - bool m_bHasMax{}; // 0x0064 - float m_fMaxVal{}; // 0x0068 - void* m_pMalloc{}; // 0x0070 - char m_pPad80[10]{}; // 0x0080 -}; // Size: 0x0080 + ConCommandBase m_ConCommandBase {}; // 0x0000 + const char* m_pszDefaultValue {}; // 0x0040 + CVValue_t m_Value {}; // 0x0048 + bool m_bHasMin {}; // 0x005C + float m_fMinVal {}; // 0x0060 + bool m_bHasMax {}; // 0x0064 + float m_fMaxVal {}; // 0x0068 + void* m_pMalloc {}; // 0x0070 + char m_pPad80[10] {}; // 0x0080 +}; // Size: 0x0080 void InitialiseConVars(HMODULE baseAddress); \ No newline at end of file diff --git a/NorthstarDedicatedTest/cvar.h b/NorthstarDedicatedTest/cvar.h index 8e993b19..c4525cef 100644 --- a/NorthstarDedicatedTest/cvar.h +++ b/NorthstarDedicatedTest/cvar.h @@ -15,9 +15,9 @@ class ConVar; class CCVarIteratorInternal // Fully reversed table, just look at the virtual function table and rename the function. { public: - virtual void SetFirst(void) = 0; // 0 - virtual void Next(void) = 0; // 1 - virtual bool IsValid(void) = 0; // 2 + virtual void SetFirst(void) = 0; // 0 + virtual void Next(void) = 0; // 1 + virtual bool IsValid(void) = 0; // 2 virtual ConCommandBase* Get(void) = 0; // 3 }; diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index c00bed07..5099a6d2 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -28,7 +28,10 @@ struct CDedicatedExports DedicatedRunServerType RunServer; }; -void Sys_Printf(CDedicatedExports* dedicated, const char* msg) { spdlog::info("[DEDICATED PRINT] {}", msg); } +void Sys_Printf(CDedicatedExports* dedicated, const char* msg) +{ + spdlog::info("[DEDICATED PRINT] {}", msg); +} typedef void (*CHostState__InitType)(CHostState* self); @@ -77,8 +80,12 @@ void RunServer(CDedicatedExports* dedicated) maxPlayers = "6"; SetConsoleTitleA(fmt::format( - "{} - {} {}/{} players ({})", g_MasterServerManager->ns_auth_srvName, g_pHostState->m_levelName, - g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, GetCurrentPlaylistName()) + "{} - {} {}/{} players ({})", + g_MasterServerManager->ns_auth_srvName, + g_pHostState->m_levelName, + g_ServerAuthenticationManager->m_additionalPlayerData.size(), + maxPlayers, + GetCurrentPlaylistName()) .c_str()); } @@ -89,7 +96,10 @@ void RunServer(CDedicatedExports* dedicated) typedef bool (*IsGameActiveWindowType)(); IsGameActiveWindowType IsGameActiveWindow; -bool IsGameActiveWindowHook() { return true; } +bool IsGameActiveWindowHook() +{ + return true; +} HANDLE consoleInputThreadHandle = NULL; @@ -206,10 +216,12 @@ void InitialiseDedicated(HMODULE engineAddress) // func that checks if origin is inited // always return 1 NSMem::BytePatch( - ea + 0x183B70, { - 0xB0, 0x01, // mov al,01 - 0xC3 // ret - }); + ea + 0x183B70, + { + 0xB0, + 0x01, // mov al,01 + 0xC3 // ret + }); } { @@ -296,9 +308,10 @@ void InitialiseDedicatedOrigin(HMODULE baseAddress) // an origin id as a client for dedi it's fine though, game doesn't care if origin is disabled as long as there's only a server NSMem::BytePatch( - (uintptr_t)GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin"), { - 0xC3 // ret - }); + (uintptr_t)GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin"), + { + 0xC3 // ret + }); } typedef void (*PrintFatalSquirrelErrorType)(void* sqvm); diff --git a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp index b3452fc8..f1a91e22 100644 --- a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp +++ b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp @@ -7,13 +7,29 @@ #include "NSMem.h" typedef HRESULT (*__stdcall D3D11CreateDeviceType)( - void* pAdapter, int DriverType, HMODULE Software, UINT Flags, int* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, void** ppDevice, - int* pFeatureLevel, void** ppImmediateContext); + void* pAdapter, + int DriverType, + HMODULE Software, + UINT Flags, + int* pFeatureLevels, + UINT FeatureLevels, + UINT SDKVersion, + void** ppDevice, + int* pFeatureLevel, + void** ppImmediateContext); D3D11CreateDeviceType D3D11CreateDevice; HRESULT __stdcall D3D11CreateDeviceHook( - void* pAdapter, int DriverType, HMODULE Software, UINT Flags, int* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, void** ppDevice, - int* pFeatureLevel, void** ppImmediateContext) + void* pAdapter, + int DriverType, + HMODULE Software, + UINT Flags, + int* pFeatureLevels, + UINT FeatureLevels, + UINT SDKVersion, + void** ppDevice, + int* pFeatureLevel, + void** ppImmediateContext) { // note: this is super duper temp pretty much just messing around with it // does run surprisingly well on dedi for a software driver tho if you ignore the +1gb ram usage at times, seems like dedi doesn't diff --git a/NorthstarDedicatedTest/gameutils.h b/NorthstarDedicatedTest/gameutils.h index d1ac8380..6d625c16 100644 --- a/NorthstarDedicatedTest/gameutils.h +++ b/NorthstarDedicatedTest/gameutils.h @@ -164,10 +164,10 @@ enum EngineQuitState enum EngineState_t { DLL_INACTIVE = 0, // no dll - DLL_ACTIVE, // engine is focused - DLL_CLOSE, // closing down dll - DLL_RESTART, // engine is shutting down but will restart right away - DLL_PAUSED, // engine is paused, can become active from this state + DLL_ACTIVE, // engine is focused + DLL_CLOSE, // closing down dll + DLL_RESTART, // engine is shutting down but will restart right away + DLL_PAUSED, // engine is paused, can become active from this state }; class CEngine @@ -197,9 +197,9 @@ extern CEngine* g_pEngine; enum server_state_t { ss_dead = 0, // Dead - ss_loading, // Spawning - ss_active, // Running - ss_paused, // Running, but paused + ss_loading, // Spawning + ss_active, // Running + ss_paused, // Running, but paused }; extern server_state_t* sv_m_State; diff --git a/NorthstarDedicatedTest/hooks.cpp b/NorthstarDedicatedTest/hooks.cpp index 055fe4df..cc99341a 100644 --- a/NorthstarDedicatedTest/hooks.cpp +++ b/NorthstarDedicatedTest/hooks.cpp @@ -87,7 +87,8 @@ LPSTR GetCommandLineAHook() "supposed to go into Origin/Steam game launch options, and then you are supposed to launch the original " "Titanfall2.exe " "rather than NorthstarLauncher.exe to make use of it.", - "Northstar Warning", MB_ICONWARNING); + "Northstar Warning", + MB_ICONWARNING); args.append(argBuffer.str()); } diff --git a/NorthstarDedicatedTest/languagehooks.cpp b/NorthstarDedicatedTest/languagehooks.cpp index 95638ef2..c8d43901 100644 --- a/NorthstarDedicatedTest/languagehooks.cpp +++ b/NorthstarDedicatedTest/languagehooks.cpp @@ -15,7 +15,7 @@ GetGameLanguageType GetGameLanguageOriginal; bool CheckLangAudioExists(char* lang) { - std::string path{"r2\\sound\\general_"}; + std::string path {"r2\\sound\\general_"}; path += lang; path += ".mstr"; return fs::exists(path); @@ -31,7 +31,7 @@ std::vector file_list(fs::path dir, std::regex ext_pattern) using iterator = fs::directory_iterator; const iterator end; - for (iterator iter{dir}; iter != end; ++iter) + for (iterator iter {dir}; iter != end; ++iter) { const std::string filename = iter->path().filename().string(); std::smatch matches; @@ -96,7 +96,7 @@ char* GetGameLanguageHook() Tier0_DetectDefaultLanguageType(); // force the global in tier0 to be populated with language inferred from user's system rather than // defaulting to Russian - canOriginDictateLang = false; // Origin has no say anymore, we will fallback to user's system setup language + canOriginDictateLang = false; // Origin has no say anymore, we will fallback to user's system setup language auto lang = GetGameLanguageOriginal(); spdlog::info("Detected system language: {}", lang); if (!CheckLangAudioExists(lang)) diff --git a/NorthstarDedicatedTest/latencyflex.cpp b/NorthstarDedicatedTest/latencyflex.cpp index 623ac06b..4ac1c760 100644 --- a/NorthstarDedicatedTest/latencyflex.cpp +++ b/NorthstarDedicatedTest/latencyflex.cpp @@ -8,9 +8,9 @@ OnRenderStartType OnRenderStart; ConVar* Cvar_r_latencyflex; -HMODULE m_lfxModule{}; +HMODULE m_lfxModule {}; typedef void (*PFN_winelfx_WaitAndBeginFrame)(); -PFN_winelfx_WaitAndBeginFrame m_winelfx_WaitAndBeginFrame{}; +PFN_winelfx_WaitAndBeginFrame m_winelfx_WaitAndBeginFrame {}; void OnRenderStartHook() { diff --git a/NorthstarDedicatedTest/localchatwriter.cpp b/NorthstarDedicatedTest/localchatwriter.cpp index 8f7555b2..72a5afa7 100644 --- a/NorthstarDedicatedTest/localchatwriter.cpp +++ b/NorthstarDedicatedTest/localchatwriter.cpp @@ -81,13 +81,25 @@ LocalChatWriter::SwatchColor swatchColors[4] = { LocalChatWriter::NetworkNameColor, }; -vgui_Color darkColors[8] = {vgui_Color{0, 0, 0, 255}, vgui_Color{205, 49, 49, 255}, vgui_Color{13, 188, 121, 255}, - vgui_Color{229, 229, 16, 255}, vgui_Color{36, 114, 200, 255}, vgui_Color{188, 63, 188, 255}, - vgui_Color{17, 168, 205, 255}, vgui_Color{229, 229, 229, 255}}; - -vgui_Color lightColors[8] = {vgui_Color{102, 102, 102, 255}, vgui_Color{241, 76, 76, 255}, vgui_Color{35, 209, 139, 255}, - vgui_Color{245, 245, 67, 255}, vgui_Color{59, 142, 234, 255}, vgui_Color{214, 112, 214, 255}, - vgui_Color{41, 184, 219, 255}, vgui_Color{255, 255, 255, 255}}; +vgui_Color darkColors[8] = { + vgui_Color {0, 0, 0, 255}, + vgui_Color {205, 49, 49, 255}, + vgui_Color {13, 188, 121, 255}, + vgui_Color {229, 229, 16, 255}, + vgui_Color {36, 114, 200, 255}, + vgui_Color {188, 63, 188, 255}, + vgui_Color {17, 168, 205, 255}, + vgui_Color {229, 229, 229, 255}}; + +vgui_Color lightColors[8] = { + vgui_Color {102, 102, 102, 255}, + vgui_Color {241, 76, 76, 255}, + vgui_Color {35, 209, 139, 255}, + vgui_Color {245, 245, 67, 255}, + vgui_Color {59, 142, 234, 255}, + vgui_Color {214, 112, 214, 255}, + vgui_Color {41, 184, 219, 255}, + vgui_Color {255, 255, 255, 255}}; class AnsiEscapeParser { @@ -132,7 +144,7 @@ class AnsiEscapeParser LocalChatWriter* m_writer; Next m_next = Next::ControlType; - vgui_Color m_expandedColor{0, 0, 0, 0}; + vgui_Color m_expandedColor {0, 0, 0, 0}; Next HandleControlType(unsigned long val) { @@ -208,12 +220,12 @@ class AnsiEscapeParser unsigned char green = ((code - blue) / 6) % 6; unsigned char red = (code - blue - (green * 6)) / 36; m_writer->InsertColorChange( - vgui_Color{(unsigned char)(red * 51), (unsigned char)(green * 51), (unsigned char)(blue * 51), 255}); + vgui_Color {(unsigned char)(red * 51), (unsigned char)(green * 51), (unsigned char)(blue * 51), 255}); } else if (val < UCHAR_MAX) { unsigned char brightness = (val - 232) * 10 + 8; - m_writer->InsertColorChange(vgui_Color{brightness, brightness, brightness, 255}); + m_writer->InsertColorChange(vgui_Color {brightness, brightness, brightness, 255}); } return Next::ControlType; @@ -359,7 +371,7 @@ static vgui_Color GetHudSwatchColor(CHudChat* hud, LocalChatWriter::SwatchColor case LocalChatWriter::NetworkNameColor: return hud->m_networkNameColor; } - return vgui_Color{0, 0, 0, 0}; + return vgui_Color {0, 0, 0, 0}; } void LocalChatWriter::InsertSwatchColorChange(SwatchColor swatchColor) diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index 25b9a530..5936007f 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -192,8 +192,13 @@ long __stdcall ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) dumpExceptionInfo.ClientPointers = false; MiniDumpWriteDump( - GetCurrentProcess(), GetCurrentProcessId(), hMinidumpFile, - MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory), &dumpExceptionInfo, nullptr, nullptr); + GetCurrentProcess(), + GetCurrentProcessId(), + hMinidumpFile, + MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory), + &dumpExceptionInfo, + nullptr, + nullptr); CloseHandle(hMinidumpFile); } else @@ -413,7 +418,9 @@ void InitialiseEngineSpewFuncHooks(HMODULE baseAddress) // Hook CClientState::ProcessPrint ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x1A1530, CClientState_ProcessPrint_Hook, + hook, + (char*)baseAddress + 0x1A1530, + CClientState_ProcessPrint_Hook, reinterpret_cast(&CClientState_ProcessPrint_Original)); Cvar_spewlog_enable = new ConVar("spewlog_enable", "1", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged"); diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 63ae49a9..8cb4f9bb 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -146,8 +146,14 @@ const char* HttplibErrorToString(httplib::Error error) } RemoteServerInfo::RemoteServerInfo( - const char* newId, const char* newName, const char* newDescription, const char* newMap, const char* newPlaylist, int newPlayerCount, - int newMaxPlayers, bool newRequiresPassword) + const char* newId, + const char* newName, + const char* newDescription, + const char* newMap, + const char* newPlaylist, + int newPlayerCount, + int newMaxPlayers, + bool newRequiresPassword) { // passworded servers don't have public ips requiresPassword = newRequiresPassword; @@ -216,7 +222,8 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(char* uid, char* or SetCommonHttpClientOptions(curl); std::string readBuffer; curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format("{}/client/origin_auth?id={}&token={}", Cvar_ns_masterserver_hostname->GetString(), uidStr, tokenStr).c_str()); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback); @@ -363,8 +370,13 @@ void MasterServerManager::RequestServerList() if (!strncmp((const char*)server.id, id, 32)) { server = RemoteServerInfo( - id, serverObj["name"].GetString(), serverObj["description"].GetString(), serverObj["map"].GetString(), - serverObj["playlist"].GetString(), serverObj["playerCount"].GetInt(), serverObj["maxPlayers"].GetInt(), + id, + serverObj["name"].GetString(), + serverObj["description"].GetString(), + serverObj["map"].GetString(), + serverObj["playlist"].GetString(), + serverObj["playerCount"].GetInt(), + serverObj["maxPlayers"].GetInt(), serverObj["hasPassword"].IsTrue()); newServer = &server; createNewServerInfo = false; @@ -375,8 +387,13 @@ void MasterServerManager::RequestServerList() // server didn't exist if (createNewServerInfo) newServer = &m_remoteServers.emplace_back( - id, serverObj["name"].GetString(), serverObj["description"].GetString(), serverObj["map"].GetString(), - serverObj["playlist"].GetString(), serverObj["playerCount"].GetInt(), serverObj["maxPlayers"].GetInt(), + id, + serverObj["name"].GetString(), + serverObj["description"].GetString(), + serverObj["map"].GetString(), + serverObj["playlist"].GetString(), + serverObj["playerCount"].GetInt(), + serverObj["maxPlayers"].GetInt(), serverObj["hasPassword"].IsTrue()); newServer->requiredMods.clear(); @@ -406,7 +423,8 @@ void MasterServerManager::RequestServerList() } std::sort( - m_remoteServers.begin(), m_remoteServers.end(), + m_remoteServers.begin(), + m_remoteServers.end(), [](RemoteServerInfo& a, RemoteServerInfo& b) { return a.playerCount > b.playerCount; }); } else @@ -557,7 +575,8 @@ void MasterServerManager::AuthenticateWithOwnServer(char* uid, char* playerToken std::string readBuffer; curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format("{}/client/auth_with_self?id={}&playerToken={}", Cvar_ns_masterserver_hostname->GetString(), uidStr, tokenStr) .c_str()); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); @@ -697,10 +716,15 @@ void MasterServerManager::AuthenticateWithServer(char* uid, char* playerToken, c char* escapedPassword = curl_easy_escape(curl, passwordStr.c_str(), passwordStr.length()); curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format( - "{}/client/auth_with_server?id={}&playerToken={}&server={}&password={}", Cvar_ns_masterserver_hostname->GetString(), - uidStr, tokenStr, serverIdStr, escapedPassword) + "{}/client/auth_with_server?id={}&playerToken={}&server={}&password={}", + Cvar_ns_masterserver_hostname->GetString(), + uidStr, + tokenStr, + serverIdStr, + escapedPassword) .c_str()); curl_free(escapedPassword); @@ -830,11 +854,19 @@ void MasterServerManager::AddSelfToServerList( char* passwordEscaped = curl_easy_escape(curl, strPassword.c_str(), strPassword.length()); curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format( "{}/server/add_server?port={}&authPort={}&name={}&description={}&map={}&playlist={}&maxPlayers={}&password={}", - Cvar_ns_masterserver_hostname->GetString(), port, authPort, nameEscaped, descEscaped, mapEscaped, playlistEscaped, - maxPlayers, passwordEscaped) + Cvar_ns_masterserver_hostname->GetString(), + port, + authPort, + nameEscaped, + descEscaped, + mapEscaped, + playlistEscaped, + maxPlayers, + passwordEscaped) .c_str()); curl_free(nameEscaped); @@ -930,14 +962,22 @@ void MasterServerManager::AddSelfToServerList( maxPlayers = std::stoi(maxPlayersVar); curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format( "{}/server/" "update_values?id={}&port={}&authPort={}&name={}&description={}&map={}&playlist={}&playerCount={}&" "maxPlayers={}&password={}", - Cvar_ns_masterserver_hostname->GetString(), m_ownServerId, Cvar_hostport->GetInt(), - Cvar_ns_player_auth_port->GetInt(), escapedNameNew, escapedDescNew, escapedMapNew, - escapedPlaylistNew, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, + Cvar_ns_masterserver_hostname->GetString(), + m_ownServerId, + Cvar_hostport->GetInt(), + Cvar_ns_player_auth_port->GetInt(), + escapedNameNew, + escapedDescNew, + escapedMapNew, + escapedPlaylistNew, + g_ServerAuthenticationManager->m_additionalPlayerData.size(), + maxPlayers, escapedPasswordNew) .c_str()); @@ -980,7 +1020,8 @@ void MasterServerManager::AddSelfToServerList( if (serverAddedJson.HasMember("serverAuthToken") && serverAddedJson["serverAuthToken"].IsString()) { strncpy( - m_ownServerAuthToken, serverAddedJson["serverAuthToken"].GetString(), + m_ownServerAuthToken, + serverAddedJson["serverAuthToken"].GetString(), sizeof(m_ownServerAuthToken)); m_ownServerAuthToken[sizeof(m_ownServerAuthToken) - 1] = 0; } @@ -1036,10 +1077,15 @@ void MasterServerManager::UpdateServerMapAndPlaylist(char* map, char* playlist, char* playlistEscaped = curl_easy_escape(curl, strPlaylist.c_str(), strPlaylist.length()); curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format( - "{}/server/update_values?id={}&map={}&playlist={}&maxPlayers={}", Cvar_ns_masterserver_hostname->GetString(), - m_ownServerId, mapEscaped, playlistEscaped, maxPlayers) + "{}/server/update_values?id={}&map={}&playlist={}&maxPlayers={}", + Cvar_ns_masterserver_hostname->GetString(), + m_ownServerId, + mapEscaped, + playlistEscaped, + maxPlayers) .c_str()); curl_free(mapEscaped); @@ -1076,7 +1122,8 @@ void MasterServerManager::UpdateServerPlayerCount(int playerCount) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format( "{}/server/update_values?id={}&playerCount={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId, playerCount) .c_str()); @@ -1115,9 +1162,12 @@ void MasterServerManager::WritePlayerPersistentData(char* playerId, char* pdata, std::string readBuffer; curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format( - "{}/accounts/write_persistence?id={}&serverId={}", Cvar_ns_masterserver_hostname->GetString(), strPlayerId, + "{}/accounts/write_persistence?id={}&serverId={}", + Cvar_ns_masterserver_hostname->GetString(), + strPlayerId, m_ownServerId) .c_str()); curl_easy_setopt(curl, CURLOPT_POST, 1L); @@ -1166,7 +1216,8 @@ void MasterServerManager::RemoveSelfFromServerList() curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); curl_easy_setopt( - curl, CURLOPT_URL, + curl, + CURLOPT_URL, fmt::format("{}/server/remove_server?id={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId).c_str()); *m_ownServerId = 0; @@ -1183,7 +1234,10 @@ void MasterServerManager::RemoveSelfFromServerList() requestThread.detach(); } -void ConCommand_ns_fetchservers(const CCommand& args) { g_MasterServerManager->RequestServerList(); } +void ConCommand_ns_fetchservers(const CCommand& args) +{ + g_MasterServerManager->RequestServerList(); +} void CHostState__State_NewGameHook(CHostState* hostState) { @@ -1215,8 +1269,13 @@ void CHostState__State_NewGameHook(CHostState* hostState) UpdateServerInfoFromUnicodeToUTF8(); g_MasterServerManager->AddSelfToServerList( - Cvar_hostport->GetInt(), Cvar_ns_player_auth_port->GetInt(), (char*)Cvar_ns_server_name->GetString(), - (char*)Cvar_ns_server_desc->GetString(), hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers, + Cvar_hostport->GetInt(), + Cvar_ns_player_auth_port->GetInt(), + (char*)Cvar_ns_server_name->GetString(), + (char*)Cvar_ns_server_desc->GetString(), + hostState->m_levelName, + (char*)GetCurrentPlaylistName(), + maxPlayers, (char*)Cvar_ns_server_password->GetString()); g_ServerAuthenticationManager->StartPlayerAuthServer(); g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false; @@ -1264,7 +1323,7 @@ void CHostState__State_GameShutdownHook(CHostState* hostState) CHostState__State_GameShutdown(hostState); } -MasterServerManager::MasterServerManager() : m_pendingConnectionInfo{}, m_ownServerId{""}, m_ownClientAuthToken{""} {} +MasterServerManager::MasterServerManager() : m_pendingConnectionInfo {}, m_ownServerId {""}, m_ownClientAuthToken {""} {} void InitialiseSharedMasterServer(HMODULE baseAddress) { @@ -1290,12 +1349,18 @@ void InitialiseSharedMasterServer(HMODULE baseAddress) ENABLER_CREATEHOOK( hook, (char*)baseAddress + 0x16E7D0, CHostState__State_NewGameHook, reinterpret_cast(&CHostState__State_NewGame)); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x16E520, CHostState__State_ChangeLevelMPHook, + hook, + (char*)baseAddress + 0x16E520, + CHostState__State_ChangeLevelMPHook, reinterpret_cast(&CHostState__State_ChangeLevelMP)); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x16E5D0, CHostState__State_ChangeLevelSPHook, + hook, + (char*)baseAddress + 0x16E5D0, + CHostState__State_ChangeLevelSPHook, reinterpret_cast(&CHostState__State_ChangeLevelSP)); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x16E640, CHostState__State_GameShutdownHook, + hook, + (char*)baseAddress + 0x16E640, + CHostState__State_GameShutdownHook, reinterpret_cast(&CHostState__State_GameShutdown)); } diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index c8fd0cb5..10f91356 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -30,8 +30,14 @@ class RemoteServerInfo public: RemoteServerInfo( - const char* newId, const char* newName, const char* newDescription, const char* newMap, const char* newPlaylist, int newPlayerCount, - int newMaxPlayers, bool newRequiresPassword); + const char* newId, + const char* newName, + const char* newDescription, + const char* newMap, + const char* newPlaylist, + int newPlayerCount, + int newMaxPlayers, + bool newRequiresPassword); }; struct RemoteServerConnectionInfo diff --git a/NorthstarDedicatedTest/maxplayers.cpp b/NorthstarDedicatedTest/maxplayers.cpp index 9550553c..32f3b2ec 100644 --- a/NorthstarDedicatedTest/maxplayers.cpp +++ b/NorthstarDedicatedTest/maxplayers.cpp @@ -9,7 +9,7 @@ #define PAD_NUMBER(number, boundary) (((number) + ((boundary)-1)) / (boundary)) * (boundary) // this is horrible -constexpr int PlayerResource_Name_Start = 0; // Start of modded allocated space. +constexpr int PlayerResource_Name_Start = 0; // Start of modded allocated space. constexpr int PlayerResource_Name_Size = ((NEW_MAX_PLAYERS + 1) * 8); // const char* m_szName[MAX_PLAYERS + 1]; constexpr int PlayerResource_Ping_Start = PlayerResource_Name_Start + PlayerResource_Name_Size; @@ -46,7 +46,10 @@ constexpr int Team_PlayerArray_AddedSize = PAD_NUMBER(Team_PlayerArray_AddedLeng constexpr int Team_AddedSize = Team_PlayerArray_AddedSize; #include "NSMem.h" -template void ChangeOffset(void* addr, unsigned int offset) { NSMem::BytePatch((uintptr_t)addr, (BYTE*)&offset, sizeof(T)); } +template void ChangeOffset(void* addr, unsigned int offset) +{ + NSMem::BytePatch((uintptr_t)addr, (BYTE*)&offset, sizeof(T)); +} /* typedef bool(*MatchRecvPropsToSendProps_R_Type)(__int64 lookup, __int64 tableNameBroken, __int64 sendTable, __int64 recvTable); @@ -100,7 +103,10 @@ void* StringTables_CreateStringTable_Hook( return StringTables_CreateStringTable_Original(thisptr, name, maxentries, userdatafixedsize, userdatanetworkbits, flags); } -bool MaxPlayersIncreaseEnabled() { return CommandLine() && CommandLine()->CheckParm("-experimentalmaxplayersincrease"); } +bool MaxPlayersIncreaseEnabled() +{ + return CommandLine() && CommandLine()->CheckParm("-experimentalmaxplayersincrease"); +} void InitialiseMaxPlayersOverride_Engine(HMODULE baseAddress) { @@ -148,7 +154,9 @@ void InitialiseMaxPlayersOverride_Engine(HMODULE baseAddress) // &DataTable_SetupReceiveTableFromSendTable_Hook, reinterpret_cast(&DataTable_SetupReceiveTableFromSendTable_Original)); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x22E220, &StringTables_CreateStringTable_Hook, + hook, + (char*)baseAddress + 0x22E220, + &StringTables_CreateStringTable_Hook, reinterpret_cast(&StringTables_CreateStringTable_Original)); } @@ -161,27 +169,27 @@ auto RandomIntZeroMax = (__int64(__fastcall*)())0; // lazy rebuild void RunUserCmds_Hook(bool a1, float a2) { - unsigned char v3; // bl - int v5; // er14 - int i; // edi - __int64 v7; // rax - DWORD* v8; // rbx - int v9; // edi - __int64* v10; // rsi - __int64 v11; // rax - int v12; // er12 - __int64 v13; // rdi - int v14; // ebx - int v15; // eax - __int64 v16; // r8 - int v17; // edx - char v18; // r15 - char v19; // bp - int v20; // esi - __int64* v21; // rdi - __int64 v22; // rcx - bool v23; // al - __int64 v24; // rax + unsigned char v3; // bl + int v5; // er14 + int i; // edi + __int64 v7; // rax + DWORD* v8; // rbx + int v9; // edi + __int64* v10; // rsi + __int64 v11; // rax + int v12; // er12 + __int64 v13; // rdi + int v14; // ebx + int v15; // eax + __int64 v16; // r8 + int v17; // edx + char v18; // r15 + char v19; // bp + int v20; // esi + __int64* v21; // rdi + __int64 v22; // rcx + bool v23; // al + __int64 v24; // rax __int64 v25[NEW_MAX_PLAYERS]; // [rsp+20h] [rbp-138h] BYREF uintptr_t base = (__int64)serverBase; diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp index f9186110..4ba54c73 100644 --- a/NorthstarDedicatedTest/memalloc.cpp +++ b/NorthstarDedicatedTest/memalloc.cpp @@ -65,6 +65,12 @@ extern "C" char* _strdup_base(const char* src) return str; } -void* operator new(size_t n) { return _malloc_base(n); } +void* operator new(size_t n) +{ + return _malloc_base(n); +} -void operator delete(void* p) { _free_base(p); } // /FORCE:MULTIPLE \ No newline at end of file +void operator delete(void* p) +{ + _free_base(p); +} // /FORCE:MULTIPLE \ No newline at end of file diff --git a/NorthstarDedicatedTest/memalloc.h b/NorthstarDedicatedTest/memalloc.h index 4ea080b4..a1b16ad4 100644 --- a/NorthstarDedicatedTest/memalloc.h +++ b/NorthstarDedicatedTest/memalloc.h @@ -36,7 +36,10 @@ class SourceAllocator } return _realloc_base(originalPtr, newSize); } - static void Free(void* ptr) { _free_base(ptr); } + static void Free(void* ptr) + { + _free_base(ptr); + } }; typedef rapidjson::GenericDocument, rapidjson::MemoryPoolAllocator, SourceAllocator> rapidjson_document; diff --git a/NorthstarDedicatedTest/misccommands.cpp b/NorthstarDedicatedTest/misccommands.cpp index cdadff8d..df2f4a3d 100644 --- a/NorthstarDedicatedTest/misccommands.cpp +++ b/NorthstarDedicatedTest/misccommands.cpp @@ -9,7 +9,9 @@ void AddMiscConCommands() { MAKE_CONCMD( - "force_newgame", "forces a map load through directly setting g_pHostState->m_iNextState to HS_NEW_GAME", FCVAR_NONE, + "force_newgame", + "forces a map load through directly setting g_pHostState->m_iNextState to HS_NEW_GAME", + FCVAR_NONE, [](const CCommand& arg) { if (arg.ArgC() < 2) @@ -20,7 +22,8 @@ void AddMiscConCommands() }); MAKE_CONCMD( - "ns_start_reauth_and_leave_to_lobby", "called by the server, used to reauth and return the player to lobby when leaving a game", + "ns_start_reauth_and_leave_to_lobby", + "called by the server, used to reauth and return the player to lobby when leaving a game", FCVAR_SERVER_CAN_EXECUTE, [](const CCommand& arg) { @@ -31,11 +34,14 @@ void AddMiscConCommands() // this is a concommand because we make a deferred call to it from another thread MAKE_CONCMD( - "ns_end_reauth_and_leave_to_lobby", "", FCVAR_NONE, + "ns_end_reauth_and_leave_to_lobby", + "", + FCVAR_NONE, [](const CCommand& arg) { Cbuf_AddText( - Cbuf_GetCurrentPlayer(), fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), + Cbuf_GetCurrentPlayer(), + fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), cmd_source_t::kCommandSrcCode); Cbuf_Execute(); diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp index f28f87c6..50c7b371 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -32,8 +32,10 @@ Mod::Mod(fs::path modDir, char* jsonBuf) if (modJson.HasParseError()) { spdlog::error( - "Failed reading mod file {}: encountered parse error \"{}\" at offset {}", (modDir / "mod.json").string(), - GetParseError_En(modJson.GetParseError()), modJson.GetErrorOffset()); + "Failed reading mod file {}: encountered parse error \"{}\" at offset {}", + (modDir / "mod.json").string(), + GetParseError_En(modJson.GetParseError()), + modJson.GetErrorOffset()); return; } @@ -360,7 +362,8 @@ void ModManager::LoadMods() if (bUseRpakJson && dRpakJson.HasMember("Aliases") && dRpakJson["Aliases"].IsObject()) { for (rapidjson::Value::ConstMemberIterator iterator = dRpakJson["Aliases"].MemberBegin(); - iterator != dRpakJson["Aliases"].MemberEnd(); iterator++) + iterator != dRpakJson["Aliases"].MemberEnd(); + iterator++) { if (!iterator->name.IsString() || !iterator->value.IsString()) continue; @@ -521,7 +524,8 @@ void ModManager::UnloadMods() // what we wanna do if (!m_enabledModsCfg.HasMember(mod.Name.c_str())) m_enabledModsCfg.AddMember( - rapidjson_document::StringRefType(mod.Name.c_str()), rapidjson_document::GenericValue(false), + rapidjson_document::StringRefType(mod.Name.c_str()), + rapidjson_document::GenericValue(false), m_enabledModsCfg.GetAllocator()); m_enabledModsCfg[mod.Name.c_str()].SetBool(mod.Enabled); @@ -561,7 +565,10 @@ void ModManager::CompileAssetsForFile(const char* filename) } } -void ReloadModsCommand(const CCommand& args) { g_ModManager->LoadMods(); } +void ReloadModsCommand(const CCommand& args) +{ + g_ModManager->LoadMods(); +} void InitialiseModManager(HMODULE baseAddress) { @@ -570,5 +577,11 @@ void InitialiseModManager(HMODULE baseAddress) RegisterConCommand("reload_mods", ReloadModsCommand, "idk", FCVAR_NONE); } -fs::path GetModFolderPath() { return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX); } -fs::path GetCompiledAssetsPath() { return fs::path(GetNorthstarPrefix() + COMPILED_ASSETS_SUFFIX); } \ No newline at end of file +fs::path GetModFolderPath() +{ + return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX); +} +fs::path GetCompiledAssetsPath() +{ + return fs::path(GetNorthstarPrefix() + COMPILED_ASSETS_SUFFIX); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/pch.h b/NorthstarDedicatedTest/pch.h index c5c78dc7..1955071c 100644 --- a/NorthstarDedicatedTest/pch.h +++ b/NorthstarDedicatedTest/pch.h @@ -4,7 +4,7 @@ #define WIN32_LEAN_AND_MEAN #define _CRT_SECURE_NO_WARNINGS #define RAPIDJSON_NOMEMBERITERATORCLASS // need this for rapidjson -#define NOMINMAX // this too +#define NOMINMAX // this too #define _WINSOCK_DEPRECATED_NO_WARNINGS // temp because i'm very lazy and want to use inet_addr, remove later #define RAPIDJSON_HAS_STDSTRING 1 @@ -40,6 +40,9 @@ template constexpr T CallVFunc_Alt( // Example usage: M_VMETHOD(int, GetEntityIndex, 8, (CBaseEntity* ent), (this, ent)) #define M_VMETHOD(returnType, name, index, args, argsRaw) \ - FORCEINLINE returnType name args noexcept { return CallVFunc_Alt argsRaw; } + FORCEINLINE returnType name args noexcept \ + { \ + return CallVFunc_Alt argsRaw; \ + } #endif \ No newline at end of file diff --git a/NorthstarDedicatedTest/plugins.cpp b/NorthstarDedicatedTest/plugins.cpp index 62d781bb..70535a32 100644 --- a/NorthstarDedicatedTest/plugins.cpp +++ b/NorthstarDedicatedTest/plugins.cpp @@ -392,18 +392,25 @@ void InitialisePluginCommands(HMODULE baseAddress) if (g_UISquirrelManager && g_ClientSquirrelManager) { g_UISquirrelManager->AddFuncRegistration( - "void", "NSUpdateGameStateUI", "string gamemode, string gamemodeName, string map, string mapName, bool connected, bool loading", - "", SQ_UpdateGameStateUI); + "void", + "NSUpdateGameStateUI", + "string gamemode, string gamemodeName, string map, string mapName, bool connected, bool loading", + "", + SQ_UpdateGameStateUI); g_ClientSquirrelManager->AddFuncRegistration( - "void", "NSUpdateGameStateClient", - "int playerCount, int maxPlayers, int outScore, int secondHighestScore, int highestScore, bool roundBased, int scoreLimit", "", + "void", + "NSUpdateGameStateClient", + "int playerCount, int maxPlayers, int outScore, int secondHighestScore, int highestScore, bool roundBased, int scoreLimit", + "", SQ_UpdateGameStateClient); g_UISquirrelManager->AddFuncRegistration( - "void", "NSUpdateServerInfo", + "void", + "NSUpdateServerInfo", "string id, string name, string password, int players, int maxPlayers, string map, string mapDisplayName, string playlist, " "string " "playlistDisplayName", - "", SQ_UpdateServerInfo); + "", + SQ_UpdateServerInfo); g_ClientSquirrelManager->AddFuncRegistration( "void", "NSUpdateServerInfoReload", "int maxPlayers", "", SQ_UpdateServerInfoBetweenRounds); g_ClientSquirrelManager->AddFuncRegistration("void", "NSUpdateTimeInfo", "float timeInFuture", "", SQ_UpdateTimeInfo); diff --git a/NorthstarDedicatedTest/rpakfilesystem.cpp b/NorthstarDedicatedTest/rpakfilesystem.cpp index b4ddcd1a..d52f9ef1 100644 --- a/NorthstarDedicatedTest/rpakfilesystem.cpp +++ b/NorthstarDedicatedTest/rpakfilesystem.cpp @@ -28,7 +28,10 @@ PakLoadFuncs* g_pakLoadApi; void** pUnknownPakLoadSingleton; PakLoadManager* g_PakLoadManager; -void PakLoadManager::LoadPakSync(const char* path) { g_pakLoadApi->LoadPakSync(path, *pUnknownPakLoadSingleton, 0); } +void PakLoadManager::LoadPakSync(const char* path) +{ + g_pakLoadApi->LoadPakSync(path, *pUnknownPakLoadSingleton, 0); +} void PakLoadManager::LoadPakAsync(const char* path, bool bMarkForUnload) { int handle = g_pakLoadApi->LoadPakAsync(path, *pUnknownPakLoadSingleton, 2, nullptr, nullptr); diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index 44b3f1c9..ca3cfed4 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -189,7 +189,10 @@ void InitialiseScriptModMenu(HMODULE baseAddress) g_UISquirrelManager->AddFuncRegistration( "string", "NSGetModDownloadLinkByModName", "string modName", "Returns a given mod's download link", SQ_GetModDownloadLink); g_UISquirrelManager->AddFuncRegistration( - "bool", "NSIsModRequiredOnClient", "string modName", "Returns whether a given mod is required on connecting clients", + "bool", + "NSIsModRequiredOnClient", + "string modName", + "Returns whether a given mod is required on connecting clients", SQ_IsModRequiredOnClient); g_UISquirrelManager->AddFuncRegistration( "int", "NSGetModLoadPriority", "string modName", "Returns a given mod's load priority", SQ_GetModLoadPriority); diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp index c70cf248..aec47c3b 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.cpp +++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp @@ -50,10 +50,12 @@ SQRESULT SQ_GetServerName(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get name of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get name of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -69,10 +71,12 @@ SQRESULT SQ_GetServerDescription(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get description of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get description of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -88,10 +92,12 @@ SQInteger SQ_GetServerMap(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get map of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get map of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -107,10 +113,12 @@ SQRESULT SQ_GetServerPlaylist(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get playlist of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get playlist of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -126,10 +134,12 @@ SQRESULT SQ_GetServerPlayerCount(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get playercount of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get playercount of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -145,10 +155,12 @@ SQRESULT SQ_GetServerMaxPlayerCount(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get max playercount of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get max playercount of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -164,10 +176,12 @@ SQRESULT SQ_GetServerID(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get id of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get id of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -183,10 +197,12 @@ SQRESULT SQ_ServerRequiresPassword(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get hasPassword of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -202,10 +218,12 @@ SQRESULT SQ_GetServerRequiredModsCount(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get required mods count of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get required mods count of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -222,20 +240,24 @@ SQRESULT SQ_GetServerRequiredModName(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get hasPassword of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get hasPassword of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } if (modIndex >= g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get required mod name of mod index {} when only {} mod are available", modIndex, - g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get required mod name of mod index {} when only {} mod are available", + modIndex, + g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()) + .c_str()); return SQRESULT_ERROR; } @@ -252,20 +274,24 @@ SQRESULT SQ_GetServerRequiredModVersion(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get required mod version of server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get required mod version of server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } if (modIndex >= g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to get required mod version of mod index {} when only {} mod are available", modIndex, - g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to get required mod version of mod index {} when only {} mod are available", + modIndex, + g_MasterServerManager->m_remoteServers[serverIndex].requiredMods.size()) + .c_str()); return SQRESULT_ERROR; } @@ -291,10 +317,12 @@ SQRESULT SQ_TryAuthWithServer(void* sqvm) if (serverIndex >= g_MasterServerManager->m_remoteServers.size()) { ClientSq_pusherror( - sqvm, fmt::format( - "Tried to auth with server index {} when only {} servers are available", serverIndex, - g_MasterServerManager->m_remoteServers.size()) - .c_str()); + sqvm, + fmt::format( + "Tried to auth with server index {} when only {} servers are available", + serverIndex, + g_MasterServerManager->m_remoteServers.size()) + .c_str()); return SQRESULT_ERROR; } @@ -305,7 +333,9 @@ SQRESULT SQ_TryAuthWithServer(void* sqvm) // do auth g_MasterServerManager->AuthenticateWithServer( - g_LocalPlayerUserID, g_MasterServerManager->m_ownClientAuthToken, g_MasterServerManager->m_remoteServers[serverIndex].id, + g_LocalPlayerUserID, + g_MasterServerManager->m_ownClientAuthToken, + g_MasterServerManager->m_remoteServers[serverIndex].id, (char*)password); return SQRESULT_NULL; @@ -342,8 +372,12 @@ SQRESULT SQ_ConnectToAuthedServer(void* sqvm) Cbuf_AddText( Cbuf_GetCurrentPlayer(), fmt::format( - "connect {}.{}.{}.{}:{}", info.ip.S_un.S_un_b.s_b1, info.ip.S_un.S_un_b.s_b2, info.ip.S_un.S_un_b.s_b3, - info.ip.S_un.S_un_b.s_b4, info.port) + "connect {}.{}.{}.{}:{}", + info.ip.S_un.S_un_b.s_b1, + info.ip.S_un.S_un_b.s_b2, + info.ip.S_un.S_un_b.s_b3, + info.ip.S_un.S_un_b.s_b4, + info.port) .c_str(), cmd_source_t::kCommandSrcCode); @@ -366,7 +400,8 @@ SQRESULT SQ_CompleteAuthWithLocalServer(void* sqvm) // literally just set serverfilter // note: this assumes we have no authdata other than our own Cbuf_AddText( - Cbuf_GetCurrentPlayer(), fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), + Cbuf_GetCurrentPlayer(), + fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), cmd_source_t::kCommandSrcCode); return SQRESULT_NULL; diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp index 2abcb575..084db1e4 100644 --- a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp +++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp @@ -17,6 +17,8 @@ void ConCommand_ns_script_servertoclientstringcommand(const CCommand& arg) void InitialiseScriptServerToClientStringCommands(HMODULE baseAddress) { RegisterConCommand( - "ns_script_servertoclientstringcommand", ConCommand_ns_script_servertoclientstringcommand, "", + "ns_script_servertoclientstringcommand", + ConCommand_ns_script_servertoclientstringcommand, + "", FCVAR_CLIENTDLL | FCVAR_SERVER_CAN_EXECUTE); } diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 46fa6491..3417b938 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -21,8 +21,23 @@ const char* AUTHSERVER_VERIFY_STRING = "I am a northstar server!"; // hook types 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); + 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 bool (*CBaseClient__ConnectType)( @@ -84,7 +99,8 @@ void ServerAuthenticationManager::StartPlayerAuthServer() // this is just a super basic way to verify that servers have ports open, masterserver will try to read this before ensuring // server is legit m_playerAuthServer.Get( - "/verify", [](const httplib::Request& request, httplib::Response& response) + "/verify", + [](const httplib::Request& request, httplib::Response& response) { response.set_content(AUTHSERVER_VERIFY_STRING, "text/plain"); }); m_playerAuthServer.Post( @@ -314,8 +330,23 @@ char* nextPlayerToken; uint64_t nextPlayerUid; void* CBaseServer__ConnectClientHook( - 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) + 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) { // auth tokens are sent with serverfilter, can't be accessed from player struct to my knowledge, so have to do this here nextPlayerToken = serverFilter; @@ -488,7 +519,8 @@ char __fastcall CNetChan___ProcessMessagesHook(void* self, void* buf) Cvar_net_chan_limit_msec_per_sec->GetInt()) { spdlog::warn( - "Client {} hit netchan processing limit with {}ms of processing time this second (max is {})", (char*)sender + 0x16, + "Client {} hit netchan processing limit with {}ms of processing time this second (max is {})", + (char*)sender + 0x16, g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime, Cvar_net_chan_limit_msec_per_sec->GetInt()); @@ -551,7 +583,8 @@ bool ProcessConnectionlessPacketHook(void* a1, netpacket_t* packet) if (sendData->packetCount >= Cvar_sv_querylimit_per_sec->GetInt()) { spdlog::warn( - "Client went over connectionless ratelimit of {} per sec with packet of type {}", Cvar_sv_querylimit_per_sec->GetInt(), + "Client went over connectionless ratelimit of {} per sec with packet of type {}", + Cvar_sv_querylimit_per_sec->GetInt(), packet->data[4]); // timeout for a minute @@ -584,17 +617,23 @@ void InitialiseServerAuthentication(HMODULE baseAddress) CVar_ns_auth_allow_insecure = new ConVar("ns_auth_allow_insecure", "0", FCVAR_GAMEDLL, "Whether this server will allow unauthenicated players to connect"); CVar_ns_auth_allow_insecure_write = new ConVar( - "ns_auth_allow_insecure_write", "0", FCVAR_GAMEDLL, + "ns_auth_allow_insecure_write", + "0", + FCVAR_GAMEDLL, "Whether the pdata of unauthenticated clients will be written to disk when changed"); // literally just stolen from a fix valve used in csgo CVar_sv_quota_stringcmdspersecond = new ConVar( - "sv_quota_stringcmdspersecond", "60", FCVAR_GAMEDLL, + "sv_quota_stringcmdspersecond", + "60", + FCVAR_GAMEDLL, "How many string commands per second clients are allowed to submit, 0 to disallow all string commands"); // https://blog.counter-strike.net/index.php/2019/07/24922/ but different because idk how to check what current tick number is Cvar_net_chan_limit_mode = new ConVar("net_chan_limit_mode", "0", FCVAR_GAMEDLL, "The mode for netchan processing limits: 0 = log, 1 = kick"); Cvar_net_chan_limit_msec_per_sec = new ConVar( - "net_chan_limit_msec_per_sec", "0", FCVAR_GAMEDLL, + "net_chan_limit_msec_per_sec", + "0", + FCVAR_GAMEDLL, "Netchannel processing is limited to so many milliseconds, abort connection if exceeding budget"); Cvar_ns_player_auth_port = new ConVar("ns_player_auth_port", "8081", FCVAR_GAMEDLL, ""); Cvar_sv_querylimit_per_sec = new ConVar("sv_querylimit_per_sec", "15", FCVAR_GAMEDLL, ""); @@ -613,7 +652,9 @@ void InitialiseServerAuthentication(HMODULE baseAddress) ENABLER_CREATEHOOK( hook, (char*)baseAddress + 0x1012C0, &CBaseClient__DisconnectHook, reinterpret_cast(&CBaseClient__Disconnect)); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x1022E0, &CGameClient__ExecuteStringCommandHook, + hook, + (char*)baseAddress + 0x1022E0, + &CGameClient__ExecuteStringCommandHook, reinterpret_cast(&CGameClient__ExecuteStringCommand)); ENABLER_CREATEHOOK( hook, (char*)baseAddress + 0x2140A0, &CNetChan___ProcessMessagesHook, reinterpret_cast(&CNetChan___ProcessMessages)); diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h index 06834d30..41e771b8 100644 --- a/NorthstarDedicatedTest/serverauthentication.h +++ b/NorthstarDedicatedTest/serverauthentication.h @@ -57,7 +57,7 @@ typedef struct netpacket_s char unk[10]; double received_time; unsigned char* data; // pointer to raw packet data - void* message; // easy bitbuf data access // 'inpacket.message' etc etc (pointer) + void* message; // easy bitbuf data access // 'inpacket.message' etc etc (pointer) char unk2[16]; int size; diff --git a/NorthstarDedicatedTest/serverchathooks.cpp b/NorthstarDedicatedTest/serverchathooks.cpp index 4766bf9b..985d3d1b 100644 --- a/NorthstarDedicatedTest/serverchathooks.cpp +++ b/NorthstarDedicatedTest/serverchathooks.cpp @@ -93,7 +93,9 @@ void ChatSendMessage(unsigned int playerIndex, const char* text, bool isteam) CServerGameDLL__OnReceivedSayTextMessage( g_pServerGameDLL, // Ensure the first bit isn't set, since this indicates a custom message - (playerIndex + 1) & CUSTOM_MESSAGE_INDEX_MASK, text, isteam); + (playerIndex + 1) & CUSTOM_MESSAGE_INDEX_MASK, + text, + isteam); } void ChatBroadcastMessage(int fromPlayerIndex, int toPlayerIndex, const char* text, bool isTeam, bool isDead, CustomMessageType messageType) @@ -168,7 +170,10 @@ SQRESULT SQ_BroadcastMessage(void* sqvm) return SQRESULT_NULL; } -void InitialiseServerChatHooks_Engine(HMODULE baseAddress) { g_pServerGameDLL = (CServerGameDLL*)((char*)baseAddress + 0x13F0AA98); } +void InitialiseServerChatHooks_Engine(HMODULE baseAddress) +{ + g_pServerGameDLL = (CServerGameDLL*)((char*)baseAddress + 0x13F0AA98); +} void InitialiseServerChatHooks_Server(HMODULE baseAddress) { @@ -188,12 +193,17 @@ void InitialiseServerChatHooks_Server(HMODULE baseAddress) HookEnabler hook; ENABLER_CREATEHOOK( - hook, CServerGameDLL__OnReceivedSayTextMessage, &CServerGameDLL__OnReceivedSayTextMessageHook, + hook, + CServerGameDLL__OnReceivedSayTextMessage, + &CServerGameDLL__OnReceivedSayTextMessageHook, reinterpret_cast(&CServerGameDLL__OnReceivedSayTextMessageHookBase)); // Chat sending functions g_ServerSquirrelManager->AddFuncRegistration("void", "NSSendMessage", "int playerIndex, string text, bool isTeam", "", SQ_SendMessage); g_ServerSquirrelManager->AddFuncRegistration( - "void", "NSBroadcastMessage", "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", "", + "void", + "NSBroadcastMessage", + "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", + "", SQ_BroadcastMessage); } diff --git a/NorthstarDedicatedTest/sourceconsole.cpp b/NorthstarDedicatedTest/sourceconsole.cpp index 7bc68598..a6d54989 100644 --- a/NorthstarDedicatedTest/sourceconsole.cpp +++ b/NorthstarDedicatedTest/sourceconsole.cpp @@ -41,7 +41,9 @@ void InitialiseConsoleOnInterfaceCreation() // hook OnCommandSubmitted so we print inputted commands HookEnabler hook; ENABLER_CREATEHOOK( - hook, (void*)((*g_SourceGameConsole)->m_pConsole->m_vtable->OnCommandSubmitted), &OnCommandSubmittedHook, + hook, + (void*)((*g_SourceGameConsole)->m_pConsole->m_vtable->OnCommandSubmitted), + &OnCommandSubmittedHook, reinterpret_cast(&onCommandSubmittedOriginal)); } diff --git a/NorthstarDedicatedTest/sourceinterface.cpp b/NorthstarDedicatedTest/sourceinterface.cpp index 427bee63..2cc4733d 100644 --- a/NorthstarDedicatedTest/sourceinterface.cpp +++ b/NorthstarDedicatedTest/sourceinterface.cpp @@ -46,7 +46,9 @@ void HookClientCreateInterface(HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK( - hook, GetProcAddress(baseAddress, "CreateInterface"), &ClientCreateInterfaceHook, + hook, + GetProcAddress(baseAddress, "CreateInterface"), + &ClientCreateInterfaceHook, reinterpret_cast(&clientCreateInterfaceOriginal)); } @@ -54,7 +56,9 @@ void HookServerCreateInterface(HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK( - hook, GetProcAddress(baseAddress, "CreateInterface"), &ServerCreateInterfaceHook, + hook, + GetProcAddress(baseAddress, "CreateInterface"), + &ServerCreateInterfaceHook, reinterpret_cast(&serverCreateInterfaceOriginal)); } @@ -62,7 +66,9 @@ void HookEngineCreateInterface(HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK( - hook, GetProcAddress(baseAddress, "CreateInterface"), &EngineCreateInterfaceHook, + hook, + GetProcAddress(baseAddress, "CreateInterface"), + &EngineCreateInterfaceHook, reinterpret_cast(&engineCreateInterfaceOriginal)); } diff --git a/NorthstarDedicatedTest/sourceinterface.h b/NorthstarDedicatedTest/sourceinterface.h index a00f165e..05318963 100644 --- a/NorthstarDedicatedTest/sourceinterface.h +++ b/NorthstarDedicatedTest/sourceinterface.h @@ -19,9 +19,15 @@ template class SourceInterface spdlog::error("Failed to call CreateInterface for %s in %s", interfaceName, moduleName); } - T* operator->() const { return m_interface; } + T* operator->() const + { + return m_interface; + } - operator T*() const { return m_interface; } + operator T*() const + { + return m_interface; + } }; // functions for interface creation callbacks diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index f2ee6e8f..84caa389 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -93,7 +93,10 @@ SquirrelManager* g_ClientSquirrelManager; SquirrelManager* g_ServerSquirrelManager; SquirrelManager* g_UISquirrelManager; -SQInteger NSTestFunc(void* sqvm) { return 1; } +SQInteger NSTestFunc(void* sqvm) +{ + return 1; +} void InitialiseClientSquirrel(HMODULE baseAddress) { @@ -103,7 +106,9 @@ void InitialiseClientSquirrel(HMODULE baseAddress) g_ClientSquirrelManager = new SquirrelManager(); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x12B00, &SQPrintHook, + hook, + (char*)baseAddress + 0x12B00, + &SQPrintHook, reinterpret_cast(&ClientSQPrint)); // client print function RegisterConCommand( "script_client", ExecuteCodeCommand, "Executes script code on the client vm", FCVAR_CLIENTDLL); @@ -138,16 +143,24 @@ void InitialiseClientSquirrel(HMODULE baseAddress) ClientSq_sq_get = (sq_getType)((char*)baseAddress + 0x7C30); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x26130, &CreateNewVMHook, + hook, + (char*)baseAddress + 0x26130, + &CreateNewVMHook, reinterpret_cast(&ClientCreateNewVM)); // client createnewvm function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x26E70, &DestroyVMHook, + hook, + (char*)baseAddress + 0x26E70, + &DestroyVMHook, reinterpret_cast(&ClientDestroyVM)); // client destroyvm function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x79A50, &ScriptCompileErrorHook, + hook, + (char*)baseAddress + 0x79A50, + &ScriptCompileErrorHook, reinterpret_cast(&ClientSQCompileError)); // client compileerror function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x10190, &CallScriptInitCallbackHook, + hook, + (char*)baseAddress + 0x10190, + &CallScriptInitCallbackHook, reinterpret_cast(&ClientCallScriptInitCallback)); // client callscriptinitcallback function } @@ -179,25 +192,37 @@ void InitialiseServerSquirrel(HMODULE baseAddress) ServerSq_sq_get = (sq_getType)((char*)baseAddress + 0x7C00); ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x1FE90, &SQPrintHook, + hook, + (char*)baseAddress + 0x1FE90, + &SQPrintHook, reinterpret_cast(&ServerSQPrint)); // server print function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x260E0, &CreateNewVMHook, + hook, + (char*)baseAddress + 0x260E0, + &CreateNewVMHook, reinterpret_cast(&ServerCreateNewVM)); // server createnewvm function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x26E20, &DestroyVMHook, + hook, + (char*)baseAddress + 0x26E20, + &DestroyVMHook, reinterpret_cast(&ServerDestroyVM)); // server destroyvm function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x799E0, &ScriptCompileErrorHook, + hook, + (char*)baseAddress + 0x799E0, + &ScriptCompileErrorHook, reinterpret_cast(&ServerSQCompileError)); // server compileerror function ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x1D5C0, &CallScriptInitCallbackHook, + hook, + (char*)baseAddress + 0x1D5C0, + &CallScriptInitCallbackHook, reinterpret_cast(&ServerCallScriptInitCallback)); // server callscriptinitcallback function // cheat and clientcmd_can_execute allows clients to execute this, but since it's unsafe we only allow it when cheats are enabled // for script_client and script_ui, we don't use cheats, so clients can execute them on themselves all they want RegisterConCommand( - "script", ExecuteCodeCommand, "Executes script code on the server vm", + "script", + ExecuteCodeCommand, + "Executes script code on the server vm", FCVAR_GAMEDLL | FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_CHEAT); } diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index 7801ada7..cc39cc2a 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -156,7 +156,10 @@ template class SquirrelManager } } - void VMDestroyed() { sqvm = nullptr; } + void VMDestroyed() + { + sqvm = nullptr; + } void ExecuteCode(const char* code) { -- cgit v1.2.3