From 0a9a44ce15bb772b3193fbee481768e7327db1a9 Mon Sep 17 00:00:00 2001 From: BobTheBob9 Date: Sun, 10 Jul 2022 22:21:29 +0100 Subject: completely remove old hooking --- NorthstarDLL/ExploitFixes.cpp | 176 +++++++++------------ NorthstarDLL/ExploitFixes.h | 4 - NorthstarDLL/NSMem.h | 3 +- NorthstarDLL/NorthstarDLL.vcxproj | 7 +- NorthstarDLL/NorthstarDLL.vcxproj.filters | 36 ++--- NorthstarDLL/audio.cpp | 6 +- NorthstarDLL/bansystem.cpp | 6 +- NorthstarDLL/buildainfile.cpp | 4 +- NorthstarDLL/chatcommand.cpp | 4 +- NorthstarDLL/clientauthhooks.cpp | 4 +- NorthstarDLL/clientchathooks.cpp | 4 +- NorthstarDLL/clientruihooks.cpp | 4 +- NorthstarDLL/clientvideooverrides.cpp | 4 +- NorthstarDLL/concommand.cpp | 4 +- NorthstarDLL/configurables.cpp | 38 ----- NorthstarDLL/configurables.h | 7 - NorthstarDLL/convar.cpp | 4 +- NorthstarDLL/crashhandler.cpp | 2 +- NorthstarDLL/debugoverlay.cpp | 4 +- NorthstarDLL/dedicated.cpp | 14 +- NorthstarDLL/dedicatedmaterialsystem.cpp | 6 +- NorthstarDLL/demofixes.cpp | 8 +- NorthstarDLL/dllmain.cpp | 4 +- NorthstarDLL/filesystem.cpp | 4 +- NorthstarDLL/hooks.cpp | 18 +++ NorthstarDLL/hooks.h | 25 +-- NorthstarDLL/hookutils.cpp | 44 ------ NorthstarDLL/hookutils.h | 22 --- NorthstarDLL/host.cpp | 4 +- NorthstarDLL/hoststate.cpp | 12 +- NorthstarDLL/keyvalues.cpp | 6 +- NorthstarDLL/languagehooks.cpp | 4 +- NorthstarDLL/latencyflex.cpp | 4 +- NorthstarDLL/localchatwriter.cpp | 4 +- NorthstarDLL/logging.cpp | 23 +-- NorthstarDLL/masterserver.cpp | 12 +- NorthstarDLL/masterserver.h | 2 +- NorthstarDLL/maxplayers.cpp | 12 +- NorthstarDLL/miscclientfixes.cpp | 5 +- NorthstarDLL/misccommands.cpp | 4 +- NorthstarDLL/miscserverfixes.cpp | 4 +- NorthstarDLL/miscserverscript.cpp | 12 +- NorthstarDLL/modlocalisation.cpp | 4 +- NorthstarDLL/modmanager.cpp | 6 +- NorthstarDLL/pch.h | 3 +- NorthstarDLL/playlist.cpp | 4 +- NorthstarDLL/plugins.cpp | 4 +- NorthstarDLL/r2client.cpp | 4 +- NorthstarDLL/r2engine.cpp | 4 +- NorthstarDLL/r2server.cpp | 8 +- NorthstarDLL/rpakfilesystem.cpp | 4 +- NorthstarDLL/scriptbrowserhooks.cpp | 4 +- NorthstarDLL/scriptmainmenupromos.cpp | 4 +- NorthstarDLL/scriptmodmenu.cpp | 4 +- NorthstarDLL/scriptserverbrowser.cpp | 10 +- NorthstarDLL/scriptservertoclientstringcommand.cpp | 4 +- NorthstarDLL/serverauthentication.cpp | 85 +++++----- NorthstarDLL/serverauthentication.h | 2 +- NorthstarDLL/serverchathooks.cpp | 10 +- NorthstarDLL/sigscanning.cpp | 2 +- NorthstarDLL/sourceconsole.cpp | 5 +- NorthstarDLL/sourceinterface.cpp | 12 +- NorthstarDLL/squirrel.cpp | 110 ++++--------- NorthstarDLL/squirrel.h | 11 +- NorthstarDLL/tier0.cpp | 4 +- loader_wsock32_proxy/hookutils.cpp | 54 ------- loader_wsock32_proxy/loader.cpp | 8 +- loader_wsock32_proxy/loader_wsock32_proxy.vcxproj | 2 +- .../loader_wsock32_proxy.vcxproj.filters | 9 +- 69 files changed, 358 insertions(+), 597 deletions(-) delete mode 100644 NorthstarDLL/ExploitFixes.h delete mode 100644 NorthstarDLL/configurables.cpp delete mode 100644 NorthstarDLL/configurables.h delete mode 100644 NorthstarDLL/hookutils.cpp delete mode 100644 NorthstarDLL/hookutils.h delete mode 100644 loader_wsock32_proxy/hookutils.cpp diff --git a/NorthstarDLL/ExploitFixes.cpp b/NorthstarDLL/ExploitFixes.cpp index 8f41ac32..b347310c 100644 --- a/NorthstarDLL/ExploitFixes.cpp +++ b/NorthstarDLL/ExploitFixes.cpp @@ -1,11 +1,12 @@ #include "pch.h" -#include "ExploitFixes.h" #include "ExploitFixes_UTF8Parser.h" #include "NSMem.h" #include "cvar.h" #include "tier0.h" +AUTOHOOK_INIT() + ConVar* ns_exploitfixes_log; #define SHOULD_LOG (ns_exploitfixes_log->m_Value.m_nValue > 0) #define BLOCKED_INFO(s) \ @@ -56,20 +57,29 @@ struct Angle } }; -#define BLOCK_NETMSG_FUNC(name, pattern) \ - KHOOK(name, ("engine.dll", pattern), bool, __fastcall, (void* thisptr, void* buffer)) \ - { \ - return false; \ - } - +// block bad netmessages // 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"); -BLOCK_NETMSG_FUNC(CLC_Screenshot_ReadFromBuffer, "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 20 48 8B DA 48 8B 52 38"); +AUTOHOOK(CLC_Screenshot_WriteToBuffer, engine.dll + 0x22AF20, +bool, __fastcall, (void* thisptr, void* buffer)) // 48 89 5C 24 ? 57 48 83 EC 20 8B 42 10 +{ + return false; +} -// This is unused ingame and a big exploit vector -BLOCK_NETMSG_FUNC(Base_CmdKeyValues_ReadFromBuffer, "40 55 48 81 EC ? ? ? ? 48 8D 6C 24 ? 48 89 5D 70"); +AUTOHOOK(CLC_Screenshot_ReadFromBuffer, engine.dll + 0x221F00, +bool, __fastcall, (void* thisptr, void* buffer)) // 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 20 48 8B DA 48 8B 52 38 +{ + return false; +} + +// This is unused ingame and a big client=>client exploit vector +AUTOHOOK(Base_CmdKeyValues_ReadFromBuffer, engine.dll + 0x220040, +bool, __fastcall, (void* thisptr, void* buffer)) // 40 55 48 81 EC ? ? ? ? 48 8D 6C 24 ? 48 89 5D 70 +{ + return false; +} -KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 FF 60 10"), bool, __fastcall, (void* pMsg)) +AUTOHOOK(CClient_ProcessSetConVar, engine.dll + 0x75CF0, +bool, __fastcall, (void* pMsg)) // 48 8B D1 48 8B 49 18 48 8B 01 48 FF 60 10 { constexpr int ENTRY_STR_LEN = 260; @@ -92,25 +102,11 @@ KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 }; auto msg = (NET_SetConVar*)pMsg; + bool bIsServerFrame = Tier0::ThreadInServerFrameThread(); - bool areWeServer; + std::string BLOCK_PREFIX = std::string {"NET_SetConVar ("} + (bIsServerFrame ? "server" : "client") + "): Blocked dangerous/invalid msg: "; - { - // Figure out of we are the client or the server - // To do this, we utilize the msg's m_pMessageHandler pointer - // m_pMessageHandler points to a virtual class that handles all net messages - // The first virtual table function of our m_pMessageHandler will differ if it is IServerMessageHandler or IClientMessageHandler - void* msgHandlerVTableFirstFunc = **(void****)(msg->m_pMessageHandler); - static auto engineBaseAddress = (uintptr_t)GetModuleHandleA("engine.dll"); - auto offset = uintptr_t(msgHandlerVTableFirstFunc) - engineBaseAddress; - - constexpr uintptr_t CLIENTSTATE_FIRST_VFUNC_OFFSET = 0x8A15C; - areWeServer = offset != CLIENTSTATE_FIRST_VFUNC_OFFSET; - } - - std::string BLOCK_PREFIX = std::string {"NET_SetConVar ("} + (areWeServer ? "server" : "client") + "): Blocked dangerous/invalid msg: "; - - if (areWeServer) + if (bIsServerFrame) { constexpr int SETCONVAR_SANITY_AMOUNT_LIMIT = 69; if (msg->m_ConVars_count < 1 || msg->m_ConVars_count > SETCONVAR_SANITY_AMOUNT_LIMIT) @@ -149,7 +145,7 @@ KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 strlen(realVar->m_ConCommandBase.m_pszName) + 1); // Force name to match case bool isValidFlags = true; - if (areWeServer) + if (bIsServerFrame) { if (realVar) isValidFlags = realVar->IsFlagSet(FCVAR_USERINFO); // ConVar MUST be userinfo var @@ -178,11 +174,12 @@ KHOOK(CClient_ProcessSetConVar, ("engine.dll", "48 8B D1 48 8B 49 18 48 8B 01 48 } } - return oCClient_ProcessSetConVar(msg); + return CClient_ProcessSetConVar(msg); } -// Purpose: prevent invalid user CMDs -KHOOK(CClient_ProcessUsercmds, ("engine.dll", "40 55 56 48 83 EC 58"), bool, __fastcall, (void* thisptr, void* pMsg)) +// prevent invalid user CMDs +AUTOHOOK(CClient_ProcessUsercmds, engine.dll + 0x1040F0, +bool, __fastcall, (void* thisptr, void* pMsg)) // 40 55 56 48 83 EC 58 { struct CLC_Move { @@ -208,7 +205,7 @@ KHOOK(CClient_ProcessUsercmds, ("engine.dll", "40 55 56 48 83 EC 58"), bool, __f { return BLOCKED_INFO("Invalid m_nNewCommands (" << msg->m_nNewCommands << ")"); } - + // removing, as vanilla already limits num usercmds per frame /*constexpr int NUMCMD_SANITY_LIMIT = 16; if ((msg->m_nNewCommands + msg->m_nBackupCommands) > NUMCMD_SANITY_LIMIT) @@ -220,13 +217,14 @@ KHOOK(CClient_ProcessUsercmds, ("engine.dll", "40 55 56 48 83 EC 58"), bool, __f if (msg->m_nLength <= 0) return BLOCKED_INFO("Invalid message length (" << msg->m_nLength << ")"); - return oCClient_ProcessUsercmds(thisptr, pMsg); + return CClient_ProcessUsercmds(thisptr, pMsg); } -KHOOK(ReadUsercmd, ("server.dll", "4C 89 44 24 ? 53 55 56 57"), void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) +AUTOHOOK(ReadUsercmd, server.dll + 0x2603F0, +void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24 ? 53 55 56 57 { // Let normal usercmd read happen first, it's safe - oReadUsercmd(buf, pCmd_move, pCmd_from); + ReadUsercmd(buf, pCmd_move, pCmd_from); // Now let's make sure the CMD we read isnt messed up to prevent numerous exploits (including server crashing) struct __declspec(align(4)) SV_CUserCmd @@ -307,6 +305,7 @@ KHOOK(ReadUsercmd, ("server.dll", "4C 89 44 24 ? 53 55 56 57"), void, __fastcall } return; + INVALID_CMD: // Fix any gameplay-affecting cmd properties @@ -318,26 +317,22 @@ INVALID_CMD: cmd->meleetarget = 0; } -// basically: by default r2 isn't set as a valve mod, meaning that m_bRestrictServerCommands is false -// this is HORRIBLE for security, because it means servers can run arbitrary concommands on clients -// especially since we have script commands this could theoretically be awful -KHOOK(IsValveMod, ("engine.dll", "48 83 EC 28 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? E8 ? ? ? ? 85 C0 74 63"), bool, __fastcall, ()) +// ensure that GetLocalBaseClient().m_bRestrictServerCommands is set correctly, which the return value of this function controls +// this is IsValveMod in source, but we're making it IsRespawnMod now since valve didn't make this one +AUTOHOOK(IsRespawnMod, engine.dll + 0x1C6360, +bool, __fastcall, (const char* pModName)) // 48 83 EC 28 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? E8 ? ? ? ? 85 C0 74 63 { - return !Tier0::CommandLine()->CheckParm("-norestrictservercommands"); + return (!strcmp("r2", pModName) || !strcmp("r1", pModName)) + && !Tier0::CommandLine()->CheckParm("-norestrictservercommands"); } -// 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)) +// prevent utf8 parser from crashing when provided bad data, which can be sent through user-controlled openinvites +AUTOHOOK(Rson_ParseUTF8, engine.dll + 0xEF670, +bool, __fastcall, (INT64 * a1, DWORD* a2, char* strData)) // 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 { - static void* targetRetAddr = NSMem::PatternScan("engine.dll", "84 C0 75 2C 49 8B 16"); + // only call if we're parsing utf8 data from the network (i.e. communities), otherwise we get perf issues if (_ReturnAddress() == targetRetAddr) { if (!ExploitFixes_UTF8Parser::CheckValid(a1, a2, strData)) @@ -348,68 +343,45 @@ KHOOK( } } - return oCrashFunc_ParseUTF8(a1, a2, strData); + return Rson_ParseUTF8(a1, a2, strData); } -////////////////////////////////////////////////// - -void DoBytePatches() +ON_DLL_LOAD("engine.dll", EngineExploitFixes, (HMODULE baseAddress)) { - uintptr_t engineBase = (uintptr_t)GetModuleHandleA("engine.dll"); - uintptr_t serverBase = (uintptr_t)GetModuleHandleA("server.dll"); - - // patches to make commands run from client/ui script still work - // note: this is likely preventable in a nicer way? test prolly - NSMem::BytePatch(engineBase + 0x4FB65, "EB 11"); - NSMem::BytePatch(engineBase + 0x4FBAC, "EB 16"); - - { // Dumb ANTITAMPER patches (they negatively impact performance and security) + AUTOHOOK_DISPATCH_MODULE(engine.dll) - constexpr const char* ANTITAMPER_EXPORTS[] = { - "ANTITAMPER_SPOTCHECK_CODEMARKER", - "ANTITAMPER_TESTVALUE_CODEMARKER", - "ANTITAMPER_TRIGGER_CODEMARKER", - }; - - // Prevent thesefrom actually doing anything - for (auto exportName : ANTITAMPER_EXPORTS) - { - - auto address = (uintptr_t)GetProcAddress(GetModuleHandleA("server.dll"), exportName); - if (!address) - { - spdlog::warn("Failed to find AntiTamper function export \"{}\"", exportName); - } - else - { - // Just return, none of them have any args or are userpurge - NSMem::BytePatch(address, "C3"); - spdlog::info("Patched AntiTamper function export \"{}\"", exportName); - } - } - } + // allow client/ui to run clientcommands despite restricting servercommands + NSMem::BytePatch((uintptr_t)baseAddress + 0x4FB65, "EB 11"); + NSMem::BytePatch((uintptr_t)baseAddress + 0x4FBAC, "EB 16"); } -ON_DLL_LOAD_RELIESON("server.dll", ExploitFixes, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", ServerExploitFixes, ConVar, (HMODULE baseAddress)) { - spdlog::info("ExploitFixes::LoadCallback ..."); + AUTOHOOK_DISPATCH_MODULE(server.dll) - spdlog::info("\tByte patching..."); - DoBytePatches(); + // Dumb ANTITAMPER patches (they negatively impact performance and security) + constexpr const char* ANTITAMPER_EXPORTS[] = { + "ANTITAMPER_SPOTCHECK_CODEMARKER", + "ANTITAMPER_TESTVALUE_CODEMARKER", + "ANTITAMPER_TRIGGER_CODEMARKER", + }; - if (KHook::InitAllHooks()) - { - spdlog::info("\tInitialized " + std::to_string(KHook::_allHooks.size()) + " exploit-patch hooks."); - } - else + // Prevent these from actually doing anything + for (auto exportName : ANTITAMPER_EXPORTS) { - spdlog::critical("\tFAILED to initialize all exploit patches."); - - // Force exit? - MessageBoxA(0, "FAILED to initialize all exploit patches.", "Northstar", MB_ICONERROR); - exit(0); + uintptr_t address = (uintptr_t)GetProcAddress(baseAddress, exportName); + if (!address) + { + spdlog::warn("Failed to find AntiTamper function export \"{}\"", exportName); + } + else + { + // Just return, none of them have any args or are userpurge + NSMem::BytePatch(address, "C3"); + spdlog::info("Patched AntiTamper function export \"{}\"", exportName); + } } ns_exploitfixes_log = new ConVar("ns_exploitfixes_log", "1", FCVAR_GAMEDLL, "Whether to log whenever ExploitFixes.cpp blocks/corrects something"); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/ExploitFixes.h b/NorthstarDLL/ExploitFixes.h deleted file mode 100644 index 2f585755..00000000 --- a/NorthstarDLL/ExploitFixes.h +++ /dev/null @@ -1,4 +0,0 @@ -// KittenPopo's exploit fix hooks, feel free to add more here - -#pragma once -#include "pch.h" \ No newline at end of file diff --git a/NorthstarDLL/NSMem.h b/NorthstarDLL/NSMem.h index 3e633c6b..e28ccdf3 100644 --- a/NorthstarDLL/NSMem.h +++ b/NorthstarDLL/NSMem.h @@ -192,7 +192,8 @@ struct KHook { if (hook->Setup()) { - spdlog::info("KHook hooked at {}", hook->targetFuncAddr); + //spdlog::info("KHook hooked at {}", hook->targetFuncAddr); + spdlog::info("KHOOK {} at {}", hook->targetFunc.pattern, hook->targetFuncAddr); } else { diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index a8a23665..4f880642 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -133,13 +133,12 @@ - + - @@ -554,7 +553,6 @@ - @@ -571,7 +569,7 @@ - + @@ -582,7 +580,6 @@ - diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index 35af20a8..1b7603c3 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -121,9 +121,6 @@ {4a8a695a-a103-4b1f-b314-0ec19a253119} - - {b30e08b1-b962-4264-8cbb-a0a31924b93e} - {14fc0931-acad-46ec-a55e-94f4469d4235} @@ -165,9 +162,6 @@ Header Files\Shared\Hooks - - Header Files\Shared\Hooks - Header Files @@ -1410,9 +1404,6 @@ Header Files\Shared - - Header Files\Client - Header Files\Shared\Convar @@ -1431,15 +1422,9 @@ Header Files - - Source Files\Shared\Exploit Fixes - Source Files\Shared\Exploit Fixes - - Source Files\Shared\Exploit Fixes\UTF8Parser - Header Files @@ -1488,20 +1473,20 @@ Header Files\Shared\Filesystem + + Header Files + + + Source Files\Shared\Exploit Fixes + - - Source Files - Source Files Source Files\Shared\Hooks - - Source Files\Shared\Hooks - Source Files\Server\Dedicated Server @@ -1583,9 +1568,6 @@ Source Files\Server - - Source Files\Client - Source Files\Shared\Convar @@ -1679,6 +1661,12 @@ Source Files\Shared\Filesystem + + Source Files + + + Source Files + diff --git a/NorthstarDLL/audio.cpp b/NorthstarDLL/audio.cpp index 64e67218..629d9179 100644 --- a/NorthstarDLL/audio.cpp +++ b/NorthstarDLL/audio.cpp @@ -487,16 +487,16 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal( return res; } -AUTOHOOK(MilesLog, mileswin64.dll + 0x57DAD0, +AUTOHOOK(MilesLog, client.dll + 0x57DAD0, void, __fastcall, (int level, const char* string)) { spdlog::info("[MSS] {} - {}", level, string); } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", AudioHooks, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", AudioHooks, ConVar, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() Cvar_ns_print_played_sounds = new ConVar("ns_print_played_sounds", "0", FCVAR_NONE, ""); MilesStopAll = (MilesStopAll_Type)((char*)GetModuleHandleA("mileswin64.dll") + 0x580850); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/bansystem.cpp b/NorthstarDLL/bansystem.cpp index 8a129b89..2a277874 100644 --- a/NorthstarDLL/bansystem.cpp +++ b/NorthstarDLL/bansystem.cpp @@ -4,7 +4,7 @@ #include "serverauthentication.h" #include "concommand.h" #include "miscserverscript.h" -#include "configurables.h" +#include "nsprefix.h" #include @@ -96,7 +96,7 @@ void ConCommand_clearbanlist(const CCommand& args) g_ServerBanSystem->ClearBanlist(); } -ON_DLL_LOAD_RELIESON("engine.dll", BanSystem, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", BanSystem, ConCommand, (HMODULE baseAddress)) { g_ServerBanSystem = new ServerBanSystem; g_ServerBanSystem->OpenBanlist(); @@ -104,4 +104,4 @@ ON_DLL_LOAD_RELIESON("engine.dll", BanSystem, ConCommand, [](HMODULE baseAddress RegisterConCommand("ban", ConCommand_ban, "bans a given player by uid or name", FCVAR_GAMEDLL); RegisterConCommand("unban", ConCommand_unban, "unbans a given player by uid", FCVAR_NONE); RegisterConCommand("clearbanlist", ConCommand_clearbanlist, "clears all uids on the banlist", FCVAR_NONE); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/buildainfile.cpp b/NorthstarDLL/buildainfile.cpp index c0e97fd8..6659677e 100644 --- a/NorthstarDLL/buildainfile.cpp +++ b/NorthstarDLL/buildainfile.cpp @@ -370,7 +370,7 @@ void,, (void* aimanager, void* buf, const char* filename)) } } -ON_DLL_LOAD("server.dll", BuildAINFile, [](HMODULE baseAddress) +ON_DLL_LOAD("server.dll", BuildAINFile, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() @@ -382,4 +382,4 @@ ON_DLL_LOAD("server.dll", BuildAINFile, [](HMODULE baseAddress) pUnkLinkStruct1Count = (int*)((char*)baseAddress + 0x1063AA8); pppUnkStruct1s = (UnkLinkStruct1***)((char*)baseAddress + 0x1063A90); pUnkServerMapversionGlobal = (char**)((char*)baseAddress + 0xBFBE08); -}); \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/chatcommand.cpp b/NorthstarDLL/chatcommand.cpp index 96c52161..2973711c 100644 --- a/NorthstarDLL/chatcommand.cpp +++ b/NorthstarDLL/chatcommand.cpp @@ -28,10 +28,10 @@ void ConCommand_log(const CCommand& args) } } -ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientChatCommand, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientChatCommand, ConCommand, (HMODULE baseAddress)) { ClientSayText = (ClientSayTextType)((char*)baseAddress + 0x54780); RegisterConCommand("say", ConCommand_say, "Enters a message in public chat", FCVAR_CLIENTDLL); RegisterConCommand("say_team", ConCommand_say_team, "Enters a message in team chat", FCVAR_CLIENTDLL); RegisterConCommand("log", ConCommand_log, "Log a message to the local chat window", FCVAR_CLIENTDLL); -}) +} diff --git a/NorthstarDLL/clientauthhooks.cpp b/NorthstarDLL/clientauthhooks.cpp index 1d260d46..2ddee855 100644 --- a/NorthstarDLL/clientauthhooks.cpp +++ b/NorthstarDLL/clientauthhooks.cpp @@ -31,7 +31,7 @@ void,, (void* a1)) AuthWithStryder(a1); } -ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientAuthHooks, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientAuthHooks, ConVar, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() @@ -41,4 +41,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientAuthHooks, ConVar, [](HMODULE ba "0", FCVAR_ARCHIVE_PLAYERPROFILE, "whether the user has agreed to send their origin token to the northstar masterserver"); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/clientchathooks.cpp b/NorthstarDLL/clientchathooks.cpp index bf113443..8e1f7c77 100644 --- a/NorthstarDLL/clientchathooks.cpp +++ b/NorthstarDLL/clientchathooks.cpp @@ -77,11 +77,11 @@ static SQRESULT SQ_ChatWriteLine(void* sqvm) return SQRESULT_NOTNULL; } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() g_pClientSquirrel->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); g_pClientSquirrel->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); g_pClientSquirrel->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); -}) +} \ No newline at end of file diff --git a/NorthstarDLL/clientruihooks.cpp b/NorthstarDLL/clientruihooks.cpp index f5d5500f..4c4d54d2 100644 --- a/NorthstarDLL/clientruihooks.cpp +++ b/NorthstarDLL/clientruihooks.cpp @@ -14,9 +14,9 @@ bool,, (void* a1, float* a2)) return DrawRUIFunc(a1, a2); } -ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", RUI, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", RUI, ConVar, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() Cvar_rui_drawEnable = new ConVar("rui_drawEnable", "1", FCVAR_CLIENTDLL, "Controls whether RUI should be drawn"); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/clientvideooverrides.cpp b/NorthstarDLL/clientvideooverrides.cpp index 74209fb5..7729c9c8 100644 --- a/NorthstarDLL/clientvideooverrides.cpp +++ b/NorthstarDLL/clientvideooverrides.cpp @@ -30,7 +30,7 @@ void*,, (const char* path, uint32_t flags)) return BinkOpen(path, flags); } -ON_DLL_LOAD_CLIENT("client.dll", BinkVideo, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("client.dll", BinkVideo, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/concommand.cpp b/NorthstarDLL/concommand.cpp index f9337064..616294f5 100644 --- a/NorthstarDLL/concommand.cpp +++ b/NorthstarDLL/concommand.cpp @@ -144,8 +144,8 @@ void RegisterConCommand( newCommand->m_pCompletionCallback = completionCallback; } -ON_DLL_LOAD("engine.dll", ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", ConCommand, (HMODULE baseAddress)) { ConCommandConstructor = (ConCommandConstructorType)((char*)baseAddress + 0x415F60); AddMiscConCommands(); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/configurables.cpp b/NorthstarDLL/configurables.cpp deleted file mode 100644 index 2488515c..00000000 --- a/NorthstarDLL/configurables.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include "pch.h" -#include "configurables.h" - -std::string GetNorthstarPrefix() -{ - return NORTHSTAR_FOLDER_PREFIX; -} - -void parseConfigurables() -{ - char* clachar = strstr(GetCommandLineA(), "-profile="); - if (clachar) - { - std::string cla = std::string(clachar); - if (strncmp(cla.substr(9, 1).c_str(), "\"", 1)) - { - int space = cla.find(" "); - std::string dirname = cla.substr(9, space - 9); - spdlog::info("Found profile in command line arguments: " + dirname); - NORTHSTAR_FOLDER_PREFIX = dirname; - } - else - { - std::string quote = "\""; - int quote1 = cla.find(quote); - int quote2 = (cla.substr(quote1 + 1)).find(quote); - std::string dirname = cla.substr(quote1 + 1, quote2); - spdlog::info("Found profile in command line arguments: " + dirname); - NORTHSTAR_FOLDER_PREFIX = dirname; - } - } - else - { - spdlog::info("Profile was not found in command line arguments. Using default: R2Northstar"); - NORTHSTAR_FOLDER_PREFIX = "R2Northstar"; - } -} diff --git a/NorthstarDLL/configurables.h b/NorthstarDLL/configurables.h deleted file mode 100644 index 6a6069d1..00000000 --- a/NorthstarDLL/configurables.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include - -static std::string NORTHSTAR_FOLDER_PREFIX; - -std::string GetNorthstarPrefix(); -void parseConfigurables(); diff --git a/NorthstarDLL/convar.cpp b/NorthstarDLL/convar.cpp index 3b3c6c20..7bef2f6d 100644 --- a/NorthstarDLL/convar.cpp +++ b/NorthstarDLL/convar.cpp @@ -26,7 +26,7 @@ void* g_pIConVar_Vtable = nullptr; //----------------------------------------------------------------------------- // Purpose: ConVar interface initialization //----------------------------------------------------------------------------- -ON_DLL_LOAD("engine.dll", ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", ConVar, (HMODULE baseAddress)) { conVarMalloc = (ConVarMallocType)((char*)baseAddress + 0x415C20); conVarRegister = (ConVarRegisterType)((char*)baseAddress + 0x417230); @@ -36,7 +36,7 @@ ON_DLL_LOAD("engine.dll", ConVar, [](HMODULE baseAddress) R2::g_pCVarInterface = new SourceInterface("vstdlib.dll", "VEngineCvar007"); R2::g_pCVar = *R2::g_pCVarInterface; -}) +} //----------------------------------------------------------------------------- // Purpose: constructor diff --git a/NorthstarDLL/crashhandler.cpp b/NorthstarDLL/crashhandler.cpp index 01f854e9..d0f87a7b 100644 --- a/NorthstarDLL/crashhandler.cpp +++ b/NorthstarDLL/crashhandler.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "crashhandler.h" #include "dedicated.h" -#include "configurables.h" +#include "nsprefix.h" #include diff --git a/NorthstarDLL/debugoverlay.cpp b/NorthstarDLL/debugoverlay.cpp index 50c91a96..2004dae1 100644 --- a/NorthstarDLL/debugoverlay.cpp +++ b/NorthstarDLL/debugoverlay.cpp @@ -131,7 +131,7 @@ void, __fastcall, (OverlayBase_t * pOverlay)) LeaveCriticalSection((LPCRITICAL_SECTION)((char*)sEngineModule + 0x10DB0A38)); } -ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() @@ -145,4 +145,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, [](HMODULE baseA Cvar_enable_debug_overlays->SetValue(false); Cvar_enable_debug_overlays->m_pszDefaultValue = (char*)"0"; Cvar_enable_debug_overlays->AddFlags(FCVAR_CHEAT); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/dedicated.cpp b/NorthstarDLL/dedicated.cpp index a73a9cf9..cf0d68f1 100644 --- a/NorthstarDLL/dedicated.cpp +++ b/NorthstarDLL/dedicated.cpp @@ -83,7 +83,7 @@ void RunServer(CDedicatedExports* dedicated) "{} - {} {}/{} players ({})", g_MasterServerManager->m_sUnicodeServerName, g_pHostState->m_levelName, - g_ServerAuthenticationManager->m_additionalPlayerData.size(), + g_pServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, GetCurrentPlaylistName()) .c_str()); @@ -128,7 +128,7 @@ DWORD WINAPI ConsoleInputThread(PVOID pThreadParameter) } #include "NSMem.h" -ON_DLL_LOAD_DEDI("engine.dll", DedicatedServer, [](HMODULE engineAddress) +ON_DLL_LOAD_DEDI("engine.dll", DedicatedServer, (HMODULE engineAddress)) { spdlog::info("InitialiseDedicated"); @@ -268,9 +268,9 @@ ON_DLL_LOAD_DEDI("engine.dll", DedicatedServer, [](HMODULE engineAddress) consoleInputThreadHandle = CreateThread(0, 0, ConsoleInputThread, 0, 0, NULL); else spdlog::info("Console input disabled by user request"); -}) +} -ON_DLL_LOAD_DEDI("tier0.dll", DedicatedServerOrigin, [](HMODULE baseAddress) +ON_DLL_LOAD_DEDI("tier0.dll", DedicatedServerOrigin, (HMODULE baseAddress)) { // disable origin on dedicated // for any big ea lawyers, this can't be used to play the game without origin, game will throw a fit if you try to do anything without @@ -280,7 +280,7 @@ ON_DLL_LOAD_DEDI("tier0.dll", DedicatedServerOrigin, [](HMODULE baseAddress) { 0xC3 // ret }); -}) +} AUTOHOOK(PrintFatalSquirrelError, server.dll + 0x794D0, void, , (void* sqvm)) @@ -289,7 +289,7 @@ void, , (void* sqvm)) g_pEngine->m_nQuitting = EngineQuitState::QUIT_TODESKTOP; } -ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, [](HMODULE baseAddress) +ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE("server.dll") -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/dedicatedmaterialsystem.cpp b/NorthstarDLL/dedicatedmaterialsystem.cpp index 14c15bbb..70a07ba1 100644 --- a/NorthstarDLL/dedicatedmaterialsystem.cpp +++ b/NorthstarDLL/dedicatedmaterialsystem.cpp @@ -23,8 +23,6 @@ HRESULT, __stdcall, ( // 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 // really call gpu much even with renderthread still being a thing will be using this hook for actual d3d stubbing and stuff later - // atm, i think the play might be to run d3d in software, and then just stub out any calls that allocate memory/use alot of resources - // (e.g. createtexture and that sorta thing) // note: this has been succeeded by the d3d11 and gfsdk stubs, and is only being kept around for posterity and as a fallback option if (Tier0::CommandLine()->CheckParm("-softwared3d11")) DriverType = 5; // D3D_DRIVER_TYPE_WARP @@ -33,11 +31,11 @@ HRESULT, __stdcall, ( pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext); } -ON_DLL_LOAD_DEDI("materialsystem_dx11.dll", DedicatedServerMaterialSystem, [](HMODULE baseAddress) +ON_DLL_LOAD_DEDI("materialsystem_dx11.dll", DedicatedServerMaterialSystem, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() // CMaterialSystem::FindMaterial // make the game always use the error material NSMem::BytePatch((uintptr_t)baseAddress + 0x5F0F1, {0xE9, 0x34, 0x03, 0x00}); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/demofixes.cpp b/NorthstarDLL/demofixes.cpp index 293c101c..fbd14d45 100644 --- a/NorthstarDLL/demofixes.cpp +++ b/NorthstarDLL/demofixes.cpp @@ -2,14 +2,14 @@ #include "convar.h" #include "NSMem.h" -ON_DLL_LOAD_CLIENT("engine.dll", EngineDemoFixes, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("engine.dll", EngineDemoFixes, (HMODULE baseAddress)) { // allow demo recording on loopback NSMem::NOP((uintptr_t)baseAddress + 0x8E1B1, 2); NSMem::NOP((uintptr_t)baseAddress + 0x56CC3, 2); -}) +} -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientDemoFixes, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientDemoFixes, ConVar, (HMODULE baseAddress)) { // change default values of demo cvars to enable them by default, but not autorecord // this is before Host_Init, the setvalue calls here will get overwritten by custom cfgs/launch options @@ -24,4 +24,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientDemoFixes, ConVar, [](HMODULE ba ConVar* Cvar_demo_autoRecord = R2::g_pCVar->FindVar("demo_autoRecord"); Cvar_demo_autoRecord->m_pszDefaultValue = "0"; Cvar_demo_autoRecord->SetValue(false); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/dllmain.cpp b/NorthstarDLL/dllmain.cpp index 0e032f88..1c9acf54 100644 --- a/NorthstarDLL/dllmain.cpp +++ b/NorthstarDLL/dllmain.cpp @@ -3,7 +3,7 @@ #include "logging.h" #include "crashhandler.h" #include "memalloc.h" -#include "configurables.h" +#include "nsprefix.h" #include "plugin_abi.h" #include "plugins.h" #include "version.h" @@ -146,7 +146,7 @@ bool InitialiseNorthstar() bInitialised = true; - parseConfigurables(); + InitialiseNorthstarPrefix(); InitialiseVersion(); // Fix some users' failure to connect to respawn datacenters diff --git a/NorthstarDLL/filesystem.cpp b/NorthstarDLL/filesystem.cpp index cc22db31..18ff3d84 100644 --- a/NorthstarDLL/filesystem.cpp +++ b/NorthstarDLL/filesystem.cpp @@ -167,7 +167,7 @@ VPKData*,, (IFileSystem* fileSystem, const char* pVpkPath)) return ret; } -ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, [](HMODULE baseAddress) +ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() @@ -176,4 +176,4 @@ ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, [](HMODULE baseAddress) AddSearchPathHook.Dispatch((*g_pFilesystem)->m_vtable->AddSearchPath); ReadFromCacheHook.Dispatch((*g_pFilesystem)->m_vtable->ReadFromCache); MountVPKHook.Dispatch((*g_pFilesystem)->m_vtable->MountVPK); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/hooks.cpp b/NorthstarDLL/hooks.cpp index d41f0f74..3c5438cd 100644 --- a/NorthstarDLL/hooks.cpp +++ b/NorthstarDLL/hooks.cpp @@ -140,6 +140,24 @@ void AddDllLoadCallbackForClient(std::string dll, DllLoadCallbackFuncType callba AddDllLoadCallback(dll, callback, tag, reliesOn); } +void MakeHook(LPVOID pTarget, LPVOID pDetour, void* ppOriginal, const char* pFuncName) +{ + char* pStrippedFuncName = (char*)pFuncName; + // strip & char from funcname + if (*pStrippedFuncName == '&') + pStrippedFuncName++; + + if (MH_CreateHook(pTarget, pDetour, (LPVOID*)ppOriginal) == MH_OK) + { + if (MH_EnableHook(pTarget) == MH_OK) + spdlog::info("Enabling hook {}", pStrippedFuncName); + else + spdlog::error("MH_EnableHook failed for function {}", pStrippedFuncName); + } + else + spdlog::error("MH_CreateHook failed for function {}", pStrippedFuncName); +} + AUTOHOOK_ABSOLUTEADDR(_GetCommandLineA, GetCommandLineA, LPSTR, WINAPI, ()) { diff --git a/NorthstarDLL/hooks.h b/NorthstarDLL/hooks.h index ccfdd411..7b5c7a67 100644 --- a/NorthstarDLL/hooks.h +++ b/NorthstarDLL/hooks.h @@ -39,15 +39,17 @@ class __dllLoadCallback #define __STR(s) #s // adds a callback to be called when a given dll is loaded, for creating hooks and such -#define __ON_DLL_LOAD(dllName, func, side, uniquestr, reliesOn) \ -namespace { __dllLoadCallback CONCAT2(__dllLoadCallbackInstance, __LINE__)(side, dllName, func, __STR(uniquestr), reliesOn); } - -#define ON_DLL_LOAD(dllName, uniquestr, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::UNSIDED, uniquestr, "") -#define ON_DLL_LOAD_RELIESON(dllName, uniquestr, reliesOn, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::UNSIDED, uniquestr, __STR(reliesOn)) -#define ON_DLL_LOAD_CLIENT(dllName, uniquestr, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::CLIENT, uniquestr, "") -#define ON_DLL_LOAD_CLIENT_RELIESON(dllName, uniquestr, reliesOn, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::CLIENT, uniquestr, __STR(reliesOn)) -#define ON_DLL_LOAD_DEDI(dllName, uniquestr, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::DEDICATED_SERVER, uniquestr, "") -#define ON_DLL_LOAD_DEDI_RELIESON(dllName, uniquestr, reliesOn, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::DEDICATED_SERVER, uniquestr, __STR(reliesOn)) +#define __ON_DLL_LOAD(dllName, side, uniquestr, reliesOn, args) \ +void CONCAT2(__dllLoadCallback, uniquestr) args; \ +namespace { __dllLoadCallback CONCAT2(__dllLoadCallbackInstance, __LINE__)(side, dllName, CONCAT2(__dllLoadCallback, uniquestr), __STR(uniquestr), reliesOn); } \ +void CONCAT2(__dllLoadCallback, uniquestr) args \ + +#define ON_DLL_LOAD(dllName, uniquestr, args) __ON_DLL_LOAD(dllName, eDllLoadCallbackSide::UNSIDED, uniquestr, "", args) +#define ON_DLL_LOAD_RELIESON(dllName, uniquestr, reliesOn, args) __ON_DLL_LOAD(dllName, eDllLoadCallbackSide::UNSIDED, uniquestr, __STR(reliesOn), args) +#define ON_DLL_LOAD_CLIENT(dllName, uniquestr, args) __ON_DLL_LOAD(dllName, eDllLoadCallbackSide::CLIENT, uniquestr, "", args) +#define ON_DLL_LOAD_CLIENT_RELIESON(dllName, uniquestr, reliesOn, args) __ON_DLL_LOAD(dllName, eDllLoadCallbackSide::CLIENT, uniquestr, __STR(reliesOn), args) +#define ON_DLL_LOAD_DEDI(dllName, uniquestr, args) __ON_DLL_LOAD(dllName, eDllLoadCallbackSide::DEDICATED_SERVER, uniquestr, "", args) +#define ON_DLL_LOAD_DEDI_RELIESON(dllName, uniquestr, reliesOn, args) __ON_DLL_LOAD(dllName, eDllLoadCallbackSide::DEDICATED_SERVER, uniquestr, __STR(reliesOn), args) // new macro hook stuff class __autohook; @@ -278,4 +280,7 @@ type callingConvention CONCAT2(__manualhookfunc, varName) args \ #define HOOK_NOORIG(varName, type, callingConvention, args) \ type callingConvention CONCAT2(__manualhookfunc, varName) args; \ ManualHook varName = ManualHook(__STR(varName), (LPVOID)CONCAT2(__manualhookfunc, varName)); \ -type callingConvention CONCAT2(__manualhookfunc, varName) args \ \ No newline at end of file +type callingConvention CONCAT2(__manualhookfunc, varName) args \ + +void MakeHook(LPVOID pTarget, LPVOID pDetour, void* ppOriginal, const char* pFuncName = ""); +#define MAKEHOOK(pTarget, pDetour, ppOriginal) MakeHook(pTarget, pDetour, ppOriginal, __STR(pDetour)) \ No newline at end of file diff --git a/NorthstarDLL/hookutils.cpp b/NorthstarDLL/hookutils.cpp deleted file mode 100644 index 3e8209e2..00000000 --- a/NorthstarDLL/hookutils.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "pch.h" -#include "hookutils.h" - -#include - -void HookEnabler::CreateHook(LPVOID ppTarget, LPVOID ppDetour, LPVOID* ppOriginal, const char* targetName) -{ - // the macro for this uses ppTarget's name as targetName, and this typically starts with & - // targetname is used for debug stuff and debug output is nicer if we don't have this - if (*targetName == '&') - targetName++; - - if (MH_CreateHook(ppTarget, ppDetour, ppOriginal) == MH_OK) - { - HookTarget* target = new HookTarget; - target->targetAddress = ppTarget; - target->targetName = (char*)targetName; - - m_hookTargets.push_back(target); - } - else - { - if (targetName != nullptr) - spdlog::error("MH_CreateHook failed for function {}", targetName); - else - spdlog::error("MH_CreateHook failed for unknown function"); - } -} - -HookEnabler::~HookEnabler() -{ - for (auto& hook : m_hookTargets) - { - if (MH_EnableHook(hook->targetAddress) != MH_OK) - { - if (hook->targetName != nullptr) - spdlog::error("MH_EnableHook failed for function {}", hook->targetName); - else - spdlog::error("MH_EnableHook failed for unknown function"); - } - else - spdlog::info("Enabling hook {}", hook->targetName); - } -} \ No newline at end of file diff --git a/NorthstarDLL/hookutils.h b/NorthstarDLL/hookutils.h deleted file mode 100644 index cae93f0a..00000000 --- a/NorthstarDLL/hookutils.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include - -// Enables all hooks created with the HookEnabler object when it goes out of scope and handles hook errors -class HookEnabler -{ - private: - struct HookTarget - { - char* targetName; - LPVOID targetAddress; - }; - - std::vector m_hookTargets; - - public: - void CreateHook(LPVOID ppTarget, LPVOID ppDetour, LPVOID* ppOriginal, const char* targetName = nullptr); - ~HookEnabler(); -}; - -// macro to call HookEnabler::CreateHook with the hook's name -#define ENABLER_CREATEHOOK(enabler, ppTarget, ppDetour, ppOriginal) enabler.CreateHook(ppTarget, ppDetour, ppOriginal, #ppDetour) diff --git a/NorthstarDLL/host.cpp b/NorthstarDLL/host.cpp index 8199a0c0..fe5da2c5 100644 --- a/NorthstarDLL/host.cpp +++ b/NorthstarDLL/host.cpp @@ -65,7 +65,7 @@ void,, (bool bDedicated)) R2::Cbuf_AddText(R2::Cbuf_GetCurrentPlayer(), "exec autoexec_ns_client", R2::cmd_source_t::kCommandSrcCode); } -ON_DLL_LOAD("engine.dll", Host_Init, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", Host_Init, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/hoststate.cpp b/NorthstarDLL/hoststate.cpp index 886728ce..248f7259 100644 --- a/NorthstarDLL/hoststate.cpp +++ b/NorthstarDLL/hoststate.cpp @@ -25,7 +25,7 @@ void,, (CHostState* hostState)) Cbuf_Execute(); // need to do this to ensure we don't go to private match - if (g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame) + if (g_pServerAuthenticationManager->m_bNeedLocalAuthForNewgame) SetCurrentPlaylist("tdm"); // net_data_block_enabled is required for sp, force it if we're on an sp map @@ -54,8 +54,8 @@ void,, (CHostState* hostState)) GetCurrentPlaylistName(), maxPlayers, Cvar_ns_server_password->GetString()); - g_ServerAuthenticationManager->StartPlayerAuthServer(); - g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false; + g_pServerAuthenticationManager->StartPlayerAuthServer(); + g_pServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false; } AUTOHOOK(CHostState__State_ChangeLevelMP, engine.dll + 0x16E520, @@ -86,14 +86,14 @@ void,, (CHostState* hostState)) spdlog::info("HostState: GameShutdown"); g_MasterServerManager->RemoveSelfFromServerList(); - g_ServerAuthenticationManager->StopPlayerAuthServer(); + g_pServerAuthenticationManager->StopPlayerAuthServer(); CHostState__State_GameShutdown(hostState); } -ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() g_pHostState = (CHostState*)((char*)baseAddress + 0x7CF180); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/keyvalues.cpp b/NorthstarDLL/keyvalues.cpp index 0c52dfd6..3dabf227 100644 --- a/NorthstarDLL/keyvalues.cpp +++ b/NorthstarDLL/keyvalues.cpp @@ -114,6 +114,8 @@ char,, (void* self, const char* resourceName, const char* pBuffer, void* pFileSy // this is just to allow playlists to get a valid pFileSystem ptr for kv building, other functions that call this particular overload of // LoadFromBuffer seem to get called on network stuff exclusively not exactly sure what the address wanted here is, so just taking it // from a function call that always happens before playlists is loaded + + // note: would be better if we could serialize this to disk for playlists, as this method breaks saving playlists in demos if (pFileSystem != nullptr) pSavedFilesystemPtr = pFileSystem; if (!pFileSystem && !strcmp(resourceName, "playlists")) @@ -122,7 +124,7 @@ char,, (void* self, const char* resourceName, const char* pBuffer, void* pFileSy return KeyValues__LoadFromBuffer(self, resourceName, pBuffer, pFileSystem, a5, a6, a7); } -ON_DLL_LOAD("engine.dll", KeyValues, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", KeyValues, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/languagehooks.cpp b/NorthstarDLL/languagehooks.cpp index e74f6635..89db5e8d 100644 --- a/NorthstarDLL/languagehooks.cpp +++ b/NorthstarDLL/languagehooks.cpp @@ -110,7 +110,7 @@ char*,, ()) return lang; } -ON_DLL_LOAD_CLIENT("tier0.dll", LanguageHooks, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("tier0.dll", LanguageHooks, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/latencyflex.cpp b/NorthstarDLL/latencyflex.cpp index 4e30a71a..608261aa 100644 --- a/NorthstarDLL/latencyflex.cpp +++ b/NorthstarDLL/latencyflex.cpp @@ -18,7 +18,7 @@ void,, ()) OnRenderStart(); } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, (HMODULE baseAddress)) { // Connect to the LatencyFleX service // LatencyFleX is an open source vendor agnostic replacement for Nvidia Reflex input latency reduction technology. @@ -38,4 +38,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, [](HMODULE baseAd spdlog::info("LatencyFleX initialized."); Cvar_r_latencyflex = new ConVar("r_latencyflex", "1", FCVAR_ARCHIVE, "Whether or not to use LatencyFleX input latency reduction."); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/localchatwriter.cpp b/NorthstarDLL/localchatwriter.cpp index 5881c8e9..42c72373 100644 --- a/NorthstarDLL/localchatwriter.cpp +++ b/NorthstarDLL/localchatwriter.cpp @@ -436,7 +436,7 @@ void LocalChatWriter::InsertDefaultFade() } } -ON_DLL_LOAD_CLIENT("client.dll", LocalChatWriter, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("client.dll", LocalChatWriter, (HMODULE baseAddress)) { gGameSettings = (CGameSettings**)((char*)baseAddress + 0x11BAA48); gChatFadeLength = (CGameFloatVar**)((char*)baseAddress + 0x11BAB78); @@ -444,4 +444,4 @@ ON_DLL_LOAD_CLIENT("client.dll", LocalChatWriter, [](HMODULE baseAddress) CHudChat::allHuds = (CHudChat**)((char*)baseAddress + 0x11BA9E8); ConvertANSIToUnicode = (ConvertANSIToUnicodeType)((char*)baseAddress + 0x7339A0); -}) +} diff --git a/NorthstarDLL/logging.cpp b/NorthstarDLL/logging.cpp index ac22f58c..d1a4f5fd 100644 --- a/NorthstarDLL/logging.cpp +++ b/NorthstarDLL/logging.cpp @@ -2,7 +2,7 @@ #include "logging.h" #include "convar.h" #include "concommand.h" -#include "configurables.h" +#include "nsprefix.h" #include "bitbuf.h" #include "spdlog/sinks/basic_file_sink.h" @@ -225,34 +225,25 @@ void InitialiseLogging() { AllocConsole(); - // don't redirect conout if already open - /* FILE* pConoutFile = fopen("CONOUT$", "w"); - if (pConoutFile) - { - fclose(pConoutFile); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - }*/ - - // Bind stdin to receive console input. + // Bind stdout to receive console output. FILE* fp; freopen_s(&fp, "CONOUT$", "w", stdout); - freopen_s(&fp, "CONOUT$", "W", stderr); + _dup2(_fileno(stdout), _fileno(stderr)); spdlog::default_logger()->set_pattern("[%H:%M:%S] [%l] %v"); } -ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", EngineSpewFuncHooks, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", EngineSpewFuncHooks, ConCommand, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(engine.dll) Cvar_spewlog_enable = new ConVar("spewlog_enable", "1", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged"); -}) +} -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientPrintHooks, ConVar, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientPrintHooks, ConVar, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(client.dll) Cvar_cl_showtextmsg = new ConVar("cl_showtextmsg", "1", FCVAR_NONE, "Enable/disable text messages printing on the screen."); pInternalCenterPrint = (ICenterPrint*)((char*)baseAddress + 0x216E940); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/masterserver.cpp b/NorthstarDLL/masterserver.cpp index 192a27f9..37a67c21 100644 --- a/NorthstarDLL/masterserver.cpp +++ b/NorthstarDLL/masterserver.cpp @@ -600,9 +600,9 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* newAuthData.pdata[i++] = static_cast(byte.GetUint()); } - std::lock_guard guard(g_ServerAuthenticationManager->m_authDataMutex); - g_ServerAuthenticationManager->m_authData.clear(); - g_ServerAuthenticationManager->m_authData.insert(std::make_pair(authInfoJson["authToken"].GetString(), newAuthData)); + std::lock_guard guard(g_pServerAuthenticationManager->m_authDataMutex); + g_pServerAuthenticationManager->m_authData.clear(); + g_pServerAuthenticationManager->m_authData.insert(std::make_pair(authInfoJson["authToken"].GetString(), newAuthData)); m_bSuccessfullyAuthenticatedWithGameServer = true; } @@ -934,7 +934,7 @@ void MasterServerManager::AddSelfToServerList( escapedDescNew, escapedMapNew, escapedPlaylistNew, - g_ServerAuthenticationManager->m_additionalPlayerData.size(), + g_pServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, escapedPasswordNew) .c_str()); @@ -1199,7 +1199,7 @@ void ConCommand_ns_fetchservers(const CCommand& args) MasterServerManager::MasterServerManager() : m_pendingConnectionInfo {}, m_sOwnServerId {""}, m_sOwnClientAuthToken {""} {} -ON_DLL_LOAD_RELIESON("engine.dll", MasterServer, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", MasterServer, ConCommand, (HMODULE baseAddress)) { g_MasterServerManager = new MasterServerManager; @@ -1222,4 +1222,4 @@ ON_DLL_LOAD_RELIESON("engine.dll", MasterServer, ConCommand, [](HMODULE baseAddr Cvar_hostport = (ConVar*)((char*)baseAddress + 0x13FA6070); RegisterConCommand("ns_fetchservers", ConCommand_ns_fetchservers, "Fetch all servers from the masterserver", FCVAR_CLIENTDLL); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/masterserver.h b/NorthstarDLL/masterserver.h index 5fd8aff4..bb2348ca 100644 --- a/NorthstarDLL/masterserver.h +++ b/NorthstarDLL/masterserver.h @@ -125,6 +125,7 @@ class MasterServerManager public: MasterServerManager(); + void ClearServerList(); void RequestServerList(); void RequestMainMenuPromos(); @@ -146,7 +147,6 @@ class MasterServerManager void RemoveSelfFromServerList(); }; std::string unescape_unicode(const std::string& str); -void UpdateServerInfoFromUnicodeToUTF8(); extern MasterServerManager* g_MasterServerManager; extern ConVar* Cvar_ns_masterserver_hostname; diff --git a/NorthstarDLL/maxplayers.cpp b/NorthstarDLL/maxplayers.cpp index c79284cc..2bede85e 100644 --- a/NorthstarDLL/maxplayers.cpp +++ b/NorthstarDLL/maxplayers.cpp @@ -74,7 +74,7 @@ void*,, (__int64 thisptr, const char* name, int maxentries, int userdatafixedsiz return StringTables_CreateStringTable(thisptr, name, maxentries, userdatafixedsize, userdatanetworkbits, flags); } -ON_DLL_LOAD("engine.dll", MaxPlayersOverride_Engine, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", MaxPlayersOverride_Engine, (HMODULE baseAddress)) { if (!MaxPlayersIncreaseEnabled()) return; @@ -114,7 +114,7 @@ ON_DLL_LOAD("engine.dll", MaxPlayersOverride_Engine, [](HMODULE baseAddress) // do not load prebaked SendTable message list ChangeOffset((char*)baseAddress + 0x75859, 0xEB); // jnz -> jmp -}) +} typedef void (*RunUserCmds_Type)(bool a1, float a2); RunUserCmds_Type RunUserCmds_Original; @@ -275,7 +275,7 @@ __int64, __fastcall, (__int64 recvProp, int elements, int flags, const char* nam return SendPropArray2(recvProp, elements, flags, name, proxyFn, unk1); } -ON_DLL_LOAD("server.dll", MaxPlayersOverride_Server, [](HMODULE baseAddress) +ON_DLL_LOAD("server.dll", MaxPlayersOverride_Server, (HMODULE baseAddress)) { if (!MaxPlayersIncreaseEnabled()) return; @@ -432,7 +432,7 @@ ON_DLL_LOAD("server.dll", MaxPlayersOverride_Server, [](HMODULE baseAddress) *(DWORD*)((char*)baseAddress + 0xC945A0) = 0; auto DT_Team_Construct = (__int64(__fastcall*)())((char*)baseAddress + 0x238F50); DT_Team_Construct(); -}) +} AUTOHOOK(RecvPropArray2, client.dll + 0x1CEDA0, __int64, __fastcall, (__int64 recvProp, int elements, int flags, const char* name, __int64 proxyFn)) @@ -444,7 +444,7 @@ __int64, __fastcall, (__int64 recvProp, int elements, int flags, const char* nam return RecvPropArray2(recvProp, elements, flags, name, proxyFn); } -ON_DLL_LOAD("client.dll", MaxPlayersOverride_Client, [](HMODULE baseAddress) +ON_DLL_LOAD("client.dll", MaxPlayersOverride_Client, (HMODULE baseAddress)) { if (!MaxPlayersIncreaseEnabled()) return; @@ -622,4 +622,4 @@ ON_DLL_LOAD("client.dll", MaxPlayersOverride_Client, [](HMODULE baseAddress) *(DWORD*)((char*)baseAddress + 0xC3AFF8) = 0; auto DT_Team_Construct = (__int64(__fastcall*)())((char*)baseAddress + 0x17F950); DT_Team_Construct(); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/miscclientfixes.cpp b/NorthstarDLL/miscclientfixes.cpp index f18204cd..475b0efa 100644 --- a/NorthstarDLL/miscclientfixes.cpp +++ b/NorthstarDLL/miscclientfixes.cpp @@ -2,6 +2,5 @@ #include "convar.h" #include "NSMem.h" -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", MiscClientFixes, ConVar, [](HMODULE baseAddress) -{ -}) \ No newline at end of file +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", MiscClientFixes, ConVar, (HMODULE baseAddress)) { +} \ No newline at end of file diff --git a/NorthstarDLL/misccommands.cpp b/NorthstarDLL/misccommands.cpp index c578e7c5..55c0a147 100644 --- a/NorthstarDLL/misccommands.cpp +++ b/NorthstarDLL/misccommands.cpp @@ -29,14 +29,14 @@ void ConCommand_ns_end_reauth_and_leave_to_lobby(const CCommand& arg) { R2::Cbuf_AddText( R2::Cbuf_GetCurrentPlayer(), - fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), + fmt::format("serverfilter {}", g_pServerAuthenticationManager->m_authData.begin()->first).c_str(), R2::cmd_source_t::kCommandSrcCode); R2::Cbuf_Execute(); // weird way of checking, but check if client script vm is initialised, mainly just to allow players to cancel this if (g_pClientSquirrel->sqvm) { - g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = true; + g_pServerAuthenticationManager->m_bNeedLocalAuthForNewgame = true; // this won't set playlist correctly on remote clients, don't think they can set playlist until they've left which sorta // fucks things should maybe set this in HostState_NewGame? diff --git a/NorthstarDLL/miscserverfixes.cpp b/NorthstarDLL/miscserverfixes.cpp index 7ab0c1de..b5eebac8 100644 --- a/NorthstarDLL/miscserverfixes.cpp +++ b/NorthstarDLL/miscserverfixes.cpp @@ -2,7 +2,7 @@ #include "NSMem.h" -ON_DLL_LOAD("server.dll", MiscServerFixes, [](HMODULE baseAddress) +ON_DLL_LOAD("server.dll", MiscServerFixes, (HMODULE baseAddress)) { uintptr_t ba = (uintptr_t)baseAddress; @@ -12,4 +12,4 @@ ON_DLL_LOAD("server.dll", MiscServerFixes, [](HMODULE baseAddress) // ret at the start of CServerGameClients::ClientCommandKeyValues as it has no benefit and is forwarded to client (i.e. security issue) // this prevents the attack vector of client=>server=>client, however server=>client also has clientside patches NSMem::BytePatch(ba + 0x153920, "C3"); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/miscserverscript.cpp b/NorthstarDLL/miscserverscript.cpp index 32fd8a84..25a0cd1a 100644 --- a/NorthstarDLL/miscserverscript.cpp +++ b/NorthstarDLL/miscserverscript.cpp @@ -24,14 +24,14 @@ SQRESULT SQ_EarlyWritePlayerIndexPersistenceForLeave(void* sqvm) int playerIndex = g_pServerSquirrel->getinteger(sqvm, 1); void* player = GetPlayerByIndex(playerIndex); - if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) + if (!g_pServerAuthenticationManager->m_additionalPlayerData.count(player)) { g_pServerSquirrel->raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); return SQRESULT_ERROR; } - g_ServerAuthenticationManager->m_additionalPlayerData[player].needPersistenceWriteOnLeave = false; - g_ServerAuthenticationManager->WritePersistentData(player); + g_pServerAuthenticationManager->m_additionalPlayerData[player].needPersistenceWriteOnLeave = false; + g_pServerAuthenticationManager->WritePersistentData(player); return SQRESULT_NULL; } @@ -47,7 +47,7 @@ SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm) { int playerIndex = g_pServerSquirrel->getinteger(sqvm, 1); void* player = GetPlayerByIndex(playerIndex); - if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(player)) + if (!g_pServerAuthenticationManager->m_additionalPlayerData.count(player)) { g_pServerSquirrel->raiseerror(sqvm, fmt::format("Invalid playerindex {}", playerIndex).c_str()); return SQRESULT_ERROR; @@ -57,10 +57,10 @@ SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm) return SQRESULT_NOTNULL; } -ON_DLL_LOAD_RELIESON("server.dll", MiscServerScriptCommands, ServerSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", MiscServerScriptCommands, ServerSquirrel, (HMODULE baseAddress)) { g_pServerSquirrel->AddFuncRegistration( "void", "NSEarlyWritePlayerIndexPersistenceForLeave", "int playerIndex", "", SQ_EarlyWritePlayerIndexPersistenceForLeave); g_pServerSquirrel->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence); g_pServerSquirrel->AddFuncRegistration("bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/modlocalisation.cpp b/NorthstarDLL/modlocalisation.cpp index af5ffc6e..e1820e4c 100644 --- a/NorthstarDLL/modlocalisation.cpp +++ b/NorthstarDLL/modlocalisation.cpp @@ -27,7 +27,7 @@ bool,, (void* pVguiLocalize, const char* path, const char* pathId, char unknown) return ret; } -ON_DLL_LOAD_CLIENT("localize.dll", Localize, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("localize.dll", Localize, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/modmanager.cpp b/NorthstarDLL/modmanager.cpp index bf523a16..3fa6eb14 100644 --- a/NorthstarDLL/modmanager.cpp +++ b/NorthstarDLL/modmanager.cpp @@ -6,7 +6,7 @@ #include "masterserver.h" #include "filesystem.h" #include "rpakfilesystem.h" -#include "configurables.h" +#include "nsprefix.h" #include "rapidjson/error/en.h" #include "rapidjson/document.h" @@ -636,9 +636,9 @@ fs::path GetCompiledAssetsPath() return fs::path(GetNorthstarPrefix() + COMPILED_ASSETS_SUFFIX); } -ON_DLL_LOAD_RELIESON("engine.dll", ModManager, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", ModManager, ConCommand, (HMODULE baseAddress)) { g_pModManager = new ModManager; RegisterConCommand("reload_mods", ConCommand_reload_mods, "reloads mods", FCVAR_NONE); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/pch.h b/NorthstarDLL/pch.h index 561c5706..e76bd75f 100644 --- a/NorthstarDLL/pch.h +++ b/NorthstarDLL/pch.h @@ -19,11 +19,10 @@ #include #include "logging.h" -#include "include/MinHook.h" +#include "MinHook.h" #include "spdlog/spdlog.h" #include "libcurl/include/curl/curl.h" #include "hooks.h" -//#include "hookutils.h" template ReturnType CallVFunc(int index, void* thisPtr, Args... args) { diff --git a/NorthstarDLL/playlist.cpp b/NorthstarDLL/playlist.cpp index 68f345a4..c6bee74d 100644 --- a/NorthstarDLL/playlist.cpp +++ b/NorthstarDLL/playlist.cpp @@ -84,7 +84,7 @@ void ConCommand_setplaylistvaroverride(const CCommand& args) R2::SetPlaylistVarOverride(args.Arg(i), args.Arg(i + 1)); } -ON_DLL_LOAD_RELIESON("engine.dll", PlaylistHooks, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", PlaylistHooks, ConCommand, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() @@ -111,4 +111,4 @@ ON_DLL_LOAD_RELIESON("engine.dll", PlaylistHooks, ConCommand, [](HMODULE baseAdd // patch to allow setplaylistvaroverride to be called before map init on dedicated and private match launched through the game NSMem::NOP((uintptr_t)baseAddress + 0x18ED17, 6); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/plugins.cpp b/NorthstarDLL/plugins.cpp index 6d3b1723..2d52d4ab 100644 --- a/NorthstarDLL/plugins.cpp +++ b/NorthstarDLL/plugins.cpp @@ -385,7 +385,7 @@ int getPlayerInfoBool(bool* out_ptr, PlayerInfoType var) return n; } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", PluginCommands, ClientSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", PluginCommands, ClientSquirrel, (HMODULE baseAddress)) { // i swear there's a way to make this not have be run in 2 contexts but i can't figure it out // some funcs i need are just not available in UI or CLIENT @@ -418,4 +418,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", PluginCommands, ClientSquirrel, [](HMO g_pUISquirrel->AddFuncRegistration("void", "NSSetLoading", "bool loading", "", SQ_SetConnected); g_pUISquirrel->AddFuncRegistration("void", "NSUpdateListenServer", "", "", SQ_UpdateListenServer); } -}) +} \ No newline at end of file diff --git a/NorthstarDLL/r2client.cpp b/NorthstarDLL/r2client.cpp index 7f731eb7..e973ff79 100644 --- a/NorthstarDLL/r2client.cpp +++ b/NorthstarDLL/r2client.cpp @@ -11,10 +11,10 @@ namespace R2 GetBaseLocalClientType GetBaseLocalClient; } // namespace R2 -ON_DLL_LOAD("engine.dll", R2EngineClient, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", R2EngineClient, (HMODULE baseAddress)) { g_pLocalPlayerUserID = (char*)baseAddress + 0x13F8E688; g_pLocalPlayerOriginToken = (char*)baseAddress + 0x13979C80; GetBaseLocalClient = (GetBaseLocalClientType)((char*)baseAddress + 0x78200); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/r2engine.cpp b/NorthstarDLL/r2engine.cpp index 8bae9082..8d4390e6 100644 --- a/NorthstarDLL/r2engine.cpp +++ b/NorthstarDLL/r2engine.cpp @@ -13,11 +13,11 @@ namespace R2 CEngine* g_pEngine; } // namespace R2 -ON_DLL_LOAD("engine.dll", R2Engine, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", R2Engine, (HMODULE baseAddress)) { Cbuf_GetCurrentPlayer = (Cbuf_GetCurrentPlayerType)((char*)baseAddress + 0x120630); Cbuf_AddText = (Cbuf_AddTextType)((char*)baseAddress + 0x1203B0); Cbuf_Execute = (Cbuf_ExecuteType)((char*)baseAddress + 0x1204B0); g_pEngine = *(CEngine**)((char*)baseAddress + 0x7D70C8); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/r2server.cpp b/NorthstarDLL/r2server.cpp index 6a13ea9b..7a6ebe90 100644 --- a/NorthstarDLL/r2server.cpp +++ b/NorthstarDLL/r2server.cpp @@ -10,12 +10,12 @@ namespace R2 Server_GetEntityByIndexType Server_GetEntityByIndex; } // namespace R2 -ON_DLL_LOAD("engine.dll", R2EngineServer, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", R2EngineServer, (HMODULE baseAddress)) { g_pServerState = (server_state_t*)((char*)baseAddress + 0x12A53D48); -}) +} -ON_DLL_LOAD("server.dll", R2GameServer, [](HMODULE baseAddress) +ON_DLL_LOAD("server.dll", R2GameServer, (HMODULE baseAddress)) { Server_GetEntityByIndex = (Server_GetEntityByIndexType)((char*)baseAddress + 0xFB820); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/rpakfilesystem.cpp b/NorthstarDLL/rpakfilesystem.cpp index ff555e49..4d35aa8e 100644 --- a/NorthstarDLL/rpakfilesystem.cpp +++ b/NorthstarDLL/rpakfilesystem.cpp @@ -203,7 +203,7 @@ void*, , (const char* pPath, void* a2)) } -ON_DLL_LOAD("engine.dll", RpakFilesystem, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", RpakFilesystem, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH(); @@ -215,4 +215,4 @@ ON_DLL_LOAD("engine.dll", RpakFilesystem, [](HMODULE baseAddress) LoadPakAsyncHook.Dispatch(g_pakLoadApi->LoadPakAsync); UnloadPakHook.Dispatch(g_pakLoadApi->UnloadPak); ReadFullFileFromDiskHook.Dispatch(g_pakLoadApi->ReadFullFileFromDisk); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/scriptbrowserhooks.cpp b/NorthstarDLL/scriptbrowserhooks.cpp index f863a013..63f97bb7 100644 --- a/NorthstarDLL/scriptbrowserhooks.cpp +++ b/NorthstarDLL/scriptbrowserhooks.cpp @@ -15,9 +15,9 @@ void,, (char* pUrl, char flags)) *bIsOriginOverlayEnabled = bIsOriginOverlayEnabledOriginal; } -ON_DLL_LOAD_CLIENT("engine.dll", ScriptExternalBrowserHooks, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("engine.dll", ScriptExternalBrowserHooks, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() bIsOriginOverlayEnabled = (bool*)baseAddress + 0x13978255; -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/scriptmainmenupromos.cpp b/NorthstarDLL/scriptmainmenupromos.cpp index bf1bb9ac..c0fc42bb 100644 --- a/NorthstarDLL/scriptmainmenupromos.cpp +++ b/NorthstarDLL/scriptmainmenupromos.cpp @@ -127,9 +127,9 @@ SQRESULT SQ_GetCustomMainMenuPromoData(void* sqvm) return SQRESULT_NOTNULL; } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptMainMenuPrograms, ClientSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptMainMenuPrograms, ClientSquirrel, (HMODULE baseAddress)) { g_pUISquirrel->AddFuncRegistration("void", "NSRequestCustomMainMenuPromos", "", "", SQ_RequestCustomMainMenuPromos); g_pUISquirrel->AddFuncRegistration("bool", "NSHasCustomMainMenuPromoData", "", "", SQ_HasCustomMainMenuPromoData); g_pUISquirrel->AddFuncRegistration("var", "NSGetCustomMainMenuPromoData", "int promoDataKey", "", SQ_GetCustomMainMenuPromoData); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/scriptmodmenu.cpp b/NorthstarDLL/scriptmodmenu.cpp index f243c344..77866e84 100644 --- a/NorthstarDLL/scriptmodmenu.cpp +++ b/NorthstarDLL/scriptmodmenu.cpp @@ -174,7 +174,7 @@ SQRESULT SQ_ReloadMods(void* sqvm) return SQRESULT_NULL; } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, (HMODULE baseAddress)) { g_pUISquirrel->AddFuncRegistration("array", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames); g_pUISquirrel->AddFuncRegistration( @@ -199,4 +199,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, [](HMOD "array", "NSGetModConvarsByModName", "string modName", "Returns the names of all a given mod's cvars", SQ_GetModConvars); g_pUISquirrel->AddFuncRegistration("void", "NSReloadMods", "", "Reloads mods", SQ_ReloadMods); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/scriptserverbrowser.cpp b/NorthstarDLL/scriptserverbrowser.cpp index 1e54cb18..a42e9b14 100644 --- a/NorthstarDLL/scriptserverbrowser.cpp +++ b/NorthstarDLL/scriptserverbrowser.cpp @@ -328,8 +328,8 @@ SQRESULT SQ_TryAuthWithServer(void* sqvm) // send off persistent data first, don't worry about server/client stuff, since m_additionalPlayerData should only have entries when // we're a local server note: this seems like it could create a race condition, test later - for (auto& pair : g_ServerAuthenticationManager->m_additionalPlayerData) - g_ServerAuthenticationManager->WritePersistentData(pair.first); + for (auto& pair : g_pServerAuthenticationManager->m_additionalPlayerData) + g_pServerAuthenticationManager->WritePersistentData(pair.first); // do auth g_MasterServerManager->AuthenticateWithServer( @@ -403,13 +403,13 @@ SQRESULT SQ_CompleteAuthWithLocalServer(void* sqvm) // note: this assumes we have no authdata other than our own R2::Cbuf_AddText( R2::Cbuf_GetCurrentPlayer(), - fmt::format("serverfilter {}", g_ServerAuthenticationManager->m_authData.begin()->first).c_str(), + fmt::format("serverfilter {}", g_pServerAuthenticationManager->m_authData.begin()->first).c_str(), R2::cmd_source_t::kCommandSrcCode); return SQRESULT_NULL; } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerBrowser, ClientSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerBrowser, ClientSquirrel, (HMODULE baseAddress)) { g_pUISquirrel->AddFuncRegistration("bool", "NSIsMasterServerAuthenticated", "", "", SQ_IsMasterServerAuthenticated); g_pUISquirrel->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList); @@ -440,4 +440,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerBrowser, ClientSquirrel, [ g_pUISquirrel->AddFuncRegistration("void", "NSTryAuthWithLocalServer", "", "", SQ_TryAuthWithLocalServer); g_pUISquirrel->AddFuncRegistration("void", "NSCompleteAuthWithLocalServer", "", "", SQ_CompleteAuthWithLocalServer); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/scriptservertoclientstringcommand.cpp b/NorthstarDLL/scriptservertoclientstringcommand.cpp index 33acfb05..ecd44175 100644 --- a/NorthstarDLL/scriptservertoclientstringcommand.cpp +++ b/NorthstarDLL/scriptservertoclientstringcommand.cpp @@ -13,11 +13,11 @@ void ConCommand_ns_script_servertoclientstringcommand(const CCommand& arg) } } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerToClientStringCommand, ClientSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerToClientStringCommand, ClientSquirrel, (HMODULE baseAddress)) { RegisterConCommand( "ns_script_servertoclientstringcommand", ConCommand_ns_script_servertoclientstringcommand, "", FCVAR_CLIENTDLL | FCVAR_SERVER_CAN_EXECUTE); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/serverauthentication.cpp b/NorthstarDLL/serverauthentication.cpp index 4903f5f4..7dc840a1 100644 --- a/NorthstarDLL/serverauthentication.cpp +++ b/NorthstarDLL/serverauthentication.cpp @@ -8,7 +8,7 @@ #include "miscserverscript.h" #include "concommand.h" #include "dedicated.h" -#include "configurables.h" +#include "nsprefix.h" #include "NSMem.h" #include "tier0.h" #include "r2engine.h" @@ -26,7 +26,7 @@ AUTOHOOK_INIT() const char* AUTHSERVER_VERIFY_STRING = "I am a northstar server!"; // global vars -ServerAuthenticationManager* g_ServerAuthenticationManager; +ServerAuthenticationManager* g_pServerAuthenticationManager; ConVar* Cvar_ns_player_auth_port; ConVar* Cvar_ns_erase_auth_info; @@ -71,23 +71,12 @@ void ServerAuthenticationManager::StartPlayerAuthServer() "/authenticate_incoming_player", [this](const httplib::Request& request, httplib::Response& response) { - // can't just do request.remote_addr == Cvar_ns_masterserver_hostname->GetString() because the cvar can be a url, gotta - // resolve an ip from it for comparisons - // unsigned long remoteAddr = inet_addr(request.remote_addr.c_str()); - // - // char* addrPtr = Cvar_ns_masterserver_hostname->GetString(); - // char* typeStart = strstr(addrPtr, "://"); - // if (typeStart) - // addrPtr = typeStart + 3; - // hostent* resolvedRemoteAddr = gethostbyname((const char*)addrPtr); - if (!request.has_param("id") || !request.has_param("authToken") || request.body.size() >= 65335 || !request.has_param("serverAuthToken") || strcmp( g_MasterServerManager->m_sOwnServerAuthToken, request.get_param_value("serverAuthToken") - .c_str())) // || !resolvedRemoteAddr || ((in_addr**)resolvedRemoteAddr->h_addr_list)[0]->S_un.S_addr != - // remoteAddr) + .c_str())) { response.set_content("{\"success\":false}", "application/json"); return; @@ -324,7 +313,7 @@ AUTOHOOK(CBaseClient__Connect, engine.dll + 0x101740, bool,, (void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, __int64 a5, char* Buffer, void* a7)) { // try changing name before all else - name = g_ServerAuthenticationManager->VerifyPlayerName(self, pNextPlayerToken, name); + name = g_pServerAuthenticationManager->VerifyPlayerName(self, pNextPlayerToken, name); // try to auth player, dc if it fails // we connect irregardless of auth, because returning bad from this function can fuck client state p bad @@ -342,17 +331,17 @@ bool,, (void* self, char* name, __int64 netchan_ptr_arg, char b_fake_player_arg, if (strlen(name) >= 64) // fix for name overflow bug R2::CBaseClient__Disconnect(self, 1, "Invalid name"); else if ( - !g_ServerAuthenticationManager->AuthenticatePlayer(self, iNextPlayerUid, pNextPlayerToken) && + !g_pServerAuthenticationManager->AuthenticatePlayer(self, iNextPlayerUid, pNextPlayerToken) && g_MasterServerManager->m_bRequireClientAuth) R2::CBaseClient__Disconnect(self, 1, "Authentication Failed"); - if (!g_ServerAuthenticationManager->m_additionalPlayerData.count(self)) + if (!g_pServerAuthenticationManager->m_additionalPlayerData.count(self)) { AdditionalPlayerData additionalData; - additionalData.pdataSize = g_ServerAuthenticationManager->m_authData[pNextPlayerToken].pdataSize; + additionalData.pdataSize = g_pServerAuthenticationManager->m_authData[pNextPlayerToken].pdataSize; additionalData.usingLocalPdata = *((char*)self + 0x4a0) == (char)0x3; - g_ServerAuthenticationManager->m_additionalPlayerData.insert(std::make_pair(self, additionalData)); + g_pServerAuthenticationManager->m_additionalPlayerData.insert(std::make_pair(self, additionalData)); } return ret; @@ -364,11 +353,11 @@ void,, (void* self)) // if we're authed, write our persistent data // RemovePlayerAuthData returns true if it removed successfully, i.e. on first call only, and we only want to write on >= second call // (since this func is called on map loads) - if (*((char*)self + 0x4A0) >= (char)0x3 && !g_ServerAuthenticationManager->RemovePlayerAuthData(self)) + if (*((char*)self + 0x4A0) >= (char)0x3 && !g_pServerAuthenticationManager->RemovePlayerAuthData(self)) { - g_ServerAuthenticationManager->m_bForceReadLocalPlayerPersistenceFromDisk = false; - g_ServerAuthenticationManager->WritePersistentData(self); - g_MasterServerManager->UpdateServerPlayerCount(g_ServerAuthenticationManager->m_additionalPlayerData.size()); + g_pServerAuthenticationManager->m_bForceReadLocalPlayerPersistenceFromDisk = false; + g_pServerAuthenticationManager->WritePersistentData(self); + g_MasterServerManager->UpdateServerPlayerCount(g_pServerAuthenticationManager->m_additionalPlayerData.size()); } CBaseClient__ActivatePlayer(self); @@ -391,15 +380,15 @@ void,, (void* self, uint32_t unknownButAlways1, const char* pReason, ...)) spdlog::info("Player {} disconnected: \"{}\"", (char*)self + 0x16, buf); // dcing, write persistent data - if (g_ServerAuthenticationManager->m_additionalPlayerData[self].needPersistenceWriteOnLeave) - g_ServerAuthenticationManager->WritePersistentData(self); - g_ServerAuthenticationManager->RemovePlayerAuthData(self); // won't do anything 99% of the time, but just in case + if (g_pServerAuthenticationManager->m_additionalPlayerData[self].needPersistenceWriteOnLeave) + g_pServerAuthenticationManager->WritePersistentData(self); + g_pServerAuthenticationManager->RemovePlayerAuthData(self); // won't do anything 99% of the time, but just in case } - if (g_ServerAuthenticationManager->m_additionalPlayerData.count(self)) + if (g_pServerAuthenticationManager->m_additionalPlayerData.count(self)) { - g_ServerAuthenticationManager->m_additionalPlayerData.erase(self); - g_MasterServerManager->UpdateServerPlayerCount(g_ServerAuthenticationManager->m_additionalPlayerData.size()); + g_pServerAuthenticationManager->m_additionalPlayerData.erase(self); + g_MasterServerManager->UpdateServerPlayerCount(g_pServerAuthenticationManager->m_additionalPlayerData.size()); } _CBaseClient__Disconnect(self, unknownButAlways1, buf); @@ -415,15 +404,15 @@ char,, (void* self, uint32_t unknown, const char* pCommandString)) { // note: this isn't super perfect, legit clients can trigger it in lobby, mostly good enough tho imo // https://github.com/perilouswithadollarsign/cstrike15_src/blob/f82112a2388b841d72cb62ca48ab1846dfcc11c8/engine/sv_client.cpp#L1513 - if (Tier0::Plat_FloatTime() - g_ServerAuthenticationManager->m_additionalPlayerData[self].lastClientCommandQuotaStart >= 1.0) + if (Tier0::Plat_FloatTime() - g_pServerAuthenticationManager->m_additionalPlayerData[self].lastClientCommandQuotaStart >= 1.0) { // reset quota - g_ServerAuthenticationManager->m_additionalPlayerData[self].lastClientCommandQuotaStart = Tier0::Plat_FloatTime(); - g_ServerAuthenticationManager->m_additionalPlayerData[self].numClientCommandsInQuota = 0; + g_pServerAuthenticationManager->m_additionalPlayerData[self].lastClientCommandQuotaStart = Tier0::Plat_FloatTime(); + g_pServerAuthenticationManager->m_additionalPlayerData[self].numClientCommandsInQuota = 0; } - g_ServerAuthenticationManager->m_additionalPlayerData[self].numClientCommandsInQuota++; - if (g_ServerAuthenticationManager->m_additionalPlayerData[self].numClientCommandsInQuota > + g_pServerAuthenticationManager->m_additionalPlayerData[self].numClientCommandsInQuota++; + if (g_pServerAuthenticationManager->m_additionalPlayerData[self].numClientCommandsInQuota > CVar_sv_quota_stringcmdspersecond->GetInt()) { // too many stringcmds, dc player @@ -482,26 +471,26 @@ char, __fastcall, (void* self, void* buf)) // if no sender, return // relatively certain this is fine? - if (!sender || !g_ServerAuthenticationManager->m_additionalPlayerData.count(sender)) + if (!sender || !g_pServerAuthenticationManager->m_additionalPlayerData.count(sender)) return ret; // reset every second - if (startTime - g_ServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart >= 1.0 || - g_ServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart == -1.0) + if (startTime - g_pServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart >= 1.0 || + g_pServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart == -1.0) { - g_ServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart = startTime; - g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime = 0.0; + g_pServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart = startTime; + g_pServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime = 0.0; } - g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime += + g_pServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime += (Tier0::Plat_FloatTime() * 1000) - (startTime * 1000); - if (g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime >= + if (g_pServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime >= 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, - g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime, + g_pServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime, Cvar_net_chan_limit_msec_per_sec->GetInt()); // nonzero = kick, 0 = warn, but never kick local player @@ -524,7 +513,7 @@ bool,, (void* a1, netpacket_t* packet)) { // bad lookup: optimise later tm UnconnectedPlayerSendData* sendData = nullptr; - for (UnconnectedPlayerSendData& foundSendData : g_ServerAuthenticationManager->m_unconnectedPlayerSendData) + for (UnconnectedPlayerSendData& foundSendData : g_pServerAuthenticationManager->m_unconnectedPlayerSendData) { if (!memcmp(packet->adr.ip, foundSendData.ip, 16)) { @@ -535,7 +524,7 @@ bool,, (void* a1, netpacket_t* packet)) if (!sendData) { - sendData = &g_ServerAuthenticationManager->m_unconnectedPlayerSendData.emplace_back(); + sendData = &g_pServerAuthenticationManager->m_unconnectedPlayerSendData.emplace_back(); memcpy(sendData->ip, packet->adr.ip, 16); } @@ -575,14 +564,14 @@ void ConCommand_ns_resetpersistence(const CCommand& args) } spdlog::info("resetting persistence on next lobby load..."); - g_ServerAuthenticationManager->m_bForceReadLocalPlayerPersistenceFromDisk = true; + g_pServerAuthenticationManager->m_bForceReadLocalPlayerPersistenceFromDisk = true; } -ON_DLL_LOAD_RELIESON("engine.dll", ServerAuthentication, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", ServerAuthentication, ConCommand, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH() - g_ServerAuthenticationManager = new ServerAuthenticationManager; + g_pServerAuthenticationManager = new ServerAuthenticationManager; Cvar_ns_erase_auth_info = new ConVar("ns_erase_auth_info", "1", FCVAR_GAMEDLL, "Whether auth info should be erased from this server on disconnect or crash"); @@ -651,4 +640,4 @@ ON_DLL_LOAD_RELIESON("engine.dll", ServerAuthentication, ConCommand, [](HMODULE NSMem::NOP(addr + 10, 5); } -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/serverauthentication.h b/NorthstarDLL/serverauthentication.h index 4a7281d5..b70ba2cf 100644 --- a/NorthstarDLL/serverauthentication.h +++ b/NorthstarDLL/serverauthentication.h @@ -107,5 +107,5 @@ namespace R2 extern void (*CBaseClient__Disconnect)(void* self, uint32_t unknownButAlways1, const char* reason, ...); } // namespace R2 -extern ServerAuthenticationManager* g_ServerAuthenticationManager; +extern ServerAuthenticationManager* g_pServerAuthenticationManager; extern ConVar* Cvar_ns_player_auth_port; diff --git a/NorthstarDLL/serverchathooks.cpp b/NorthstarDLL/serverchathooks.cpp index b9246f83..8340948a 100644 --- a/NorthstarDLL/serverchathooks.cpp +++ b/NorthstarDLL/serverchathooks.cpp @@ -53,7 +53,7 @@ void,, (CServerGameDLL* self, unsigned int senderPlayerId, const char* text, boo void* sender = GetPlayerByIndex(senderPlayerId - 1); // check chat ratelimits - if (!g_ServerAuthenticationManager->CheckPlayerChatRatelimit(sender)) + if (!g_pServerAuthenticationManager->CheckPlayerChatRatelimit(sender)) return; if (g_pServerSquirrel->setupfunc("CServerGameDLL_ProcessMessageStartThread") != SQRESULT_ERROR) @@ -152,12 +152,12 @@ SQRESULT SQ_BroadcastMessage(void* sqvm) return SQRESULT_NULL; } -ON_DLL_LOAD("engine.dll", EngineServerChatHooks, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", EngineServerChatHooks, (HMODULE baseAddress)) { g_pServerGameDLL = (CServerGameDLL*)((char*)baseAddress + 0x13F0AA98); -}) +} -ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(server.dll) @@ -183,4 +183,4 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, [](HMODULE b "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", "", SQ_BroadcastMessage); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/sigscanning.cpp b/NorthstarDLL/sigscanning.cpp index 159d0f66..bd94aa33 100644 --- a/NorthstarDLL/sigscanning.cpp +++ b/NorthstarDLL/sigscanning.cpp @@ -7,7 +7,7 @@ size_t GetModuleLength(HMODULE moduleHandle) { - // based on sigscn code from ttf2sdk, which is in turn based on CSigScan from https://wiki.alliedmods.net/Signature_Scanning + // based on sigscan code from ttf2sdk, which is in turn based on CSigScan from https://wiki.alliedmods.net/Signature_Scanning MEMORY_BASIC_INFORMATION mem; VirtualQuery(moduleHandle, &mem, sizeof(mem)); diff --git a/NorthstarDLL/sourceconsole.cpp b/NorthstarDLL/sourceconsole.cpp index 1f6f8dd9..02216898 100644 --- a/NorthstarDLL/sourceconsole.cpp +++ b/NorthstarDLL/sourceconsole.cpp @@ -62,10 +62,11 @@ void InitialiseConsoleOnInterfaceCreation() spdlog::default_logger()->sinks().push_back(consoleLogger); } -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, (HMODULE baseAddress)) { g_pSourceGameConsole = new SourceInterface("client.dll", "GameConsole004"); + RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "Show/hide the console.", FCVAR_DONTRECORD); RegisterConCommand("showconsole", ConCommand_showconsole, "Show the console.", FCVAR_DONTRECORD); RegisterConCommand("hideconsole", ConCommand_hideconsole, "Hide the console.", FCVAR_DONTRECORD); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/sourceinterface.cpp b/NorthstarDLL/sourceinterface.cpp index 7cb8867f..08de9628 100644 --- a/NorthstarDLL/sourceinterface.cpp +++ b/NorthstarDLL/sourceinterface.cpp @@ -36,17 +36,17 @@ void*,, (const char* pName, const int* pReturnCode)) return ret; } -ON_DLL_LOAD("client.dll", ClientInterface, [](HMODULE baseAddress) +ON_DLL_LOAD("client.dll", ClientInterface, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(client.dll) -}) +} -ON_DLL_LOAD("server.dll", ServerInterface, [](HMODULE baseAddress) +ON_DLL_LOAD("server.dll", ServerInterface, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(server.dll) -}) +} -ON_DLL_LOAD("engine.dll", EngineInterface, [](HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", EngineInterface, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(engine.dll) -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/squirrel.cpp b/NorthstarDLL/squirrel.cpp index 3d9493a5..2db944e8 100644 --- a/NorthstarDLL/squirrel.cpp +++ b/NorthstarDLL/squirrel.cpp @@ -39,11 +39,10 @@ const char* GetContextName(ScriptContext context) } // hooks -typedef SQInteger (*SQPrintType)(void* sqvm, char* fmt, ...); -SQPrintType ClientSQPrint; -SQPrintType UISQPrint; -SQPrintType ServerSQPrint; -template SQInteger SQPrintHook(void* sqvm, char* fmt, ...) +SQInteger (*ClientSQPrint)(void* sqvm, const char* fmt); +SQInteger (*UISQPrint)(void* sqvm, const char* fmt); +SQInteger (*ServerSQPrint)(void* sqvm, const char* fmt); +template SQInteger SQPrintHook(void* sqvm, const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -63,9 +62,8 @@ template SQInteger SQPrintHook(void* sqvm, char* fmt, .. return 0; } -typedef void* (*CreateNewVMType)(void* a1, ScriptContext contextArg); -CreateNewVMType ClientCreateNewVM; -CreateNewVMType ServerCreateNewVM; +void* (*ClientCreateNewVM)(void* a1, ScriptContext contextArg); +void* (*ServerCreateNewVM)(void* a1, ScriptContext contextArg); template void* CreateNewVMHook(void* a1, ScriptContext realContext) { void* sqvm; @@ -89,9 +87,8 @@ template void* CreateNewVMHook(void* a1, ScriptContext r return sqvm; } -typedef void (*DestroyVMType)(void* a1, void* sqvm); -DestroyVMType ClientDestroyVM; -DestroyVMType ServerDestroyVM; +void (*ClientDestroyVM)(void* a1, void* sqvm); +void (*ServerDestroyVM)(void* a1, void* sqvm); template void DestroyVMHook(void* a1, void* sqvm) { ScriptContext realContext = context; // ui and client use the same function so we use this for prints @@ -117,9 +114,8 @@ template void DestroyVMHook(void* a1, void* sqvm) spdlog::info("DestroyVM {} {}", GetContextName(realContext), sqvm); } -typedef void (*ScriptCompileError)(void* sqvm, const char* error, const char* file, int line, int column); -ScriptCompileError ClientSQCompileError; -ScriptCompileError ServerSQCompileError; +void (*ClientSQCompileError)(void* sqvm, const char* error, const char* file, int line, int column); +void (*ServerSQCompileError)(void* sqvm, const char* error, const char* file, int line, int column); template void ScriptCompileErrorHook(void* sqvm, const char* error, const char* file, int line, int column) { ScriptContext realContext = context; // ui and client use the same function so we use this for prints @@ -140,7 +136,7 @@ template void ScriptCompileErrorHook(void* sqvm, const c .c_str(), R2::cmd_source_t::kCommandSrcCode); - if (realContext == ScriptContext::UI) // likely temp: show console so user can see any errors + if (realContext == ScriptContext::UI) // likely temp: show console so user can see any errors, as error message wont display if ui is dead R2::Cbuf_AddText(R2::Cbuf_GetCurrentPlayer(), "showconsole", R2::cmd_source_t::kCommandSrcCode); } @@ -232,31 +228,12 @@ template void ConCommand_script(const CCommand& args) g_pServerSquirrel->ExecuteCode(args.ArgS()); } -ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(client.dll) - HookEnabler hook; - - // client inits g_pClientSquirrel = new SquirrelManager; - - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x12B00, - &SQPrintHook, - reinterpret_cast(&ClientSQPrint)); // client print function - RegisterConCommand("script_client", ConCommand_script, "Executes script code on the client vm", FCVAR_CLIENTDLL); - - // ui inits g_pUISquirrel = new SquirrelManager; - - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x12BA0, - &SQPrintHook, - reinterpret_cast(&UISQPrint)); // ui print function - RegisterConCommand("script_ui", ConCommand_script, "Executes script code on the ui vm", FCVAR_CLIENTDLL); g_pClientSquirrel->RegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x108E0); g_pUISquirrel->RegisterSquirrelFunc = (RegisterSquirrelFuncType)((char*)baseAddress + 0x108E0); @@ -299,29 +276,25 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, [](HMODULE baseAd // uiscript_reset concommand: don't loop forever if compilation fails NSMem::NOP((uintptr_t)baseAddress + 0x3C6E4C, 6); - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x26130, - &CreateNewVMHook, - reinterpret_cast(&ClientCreateNewVM)); // client createnewvm function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x26E70, - &DestroyVMHook, - reinterpret_cast(&ClientDestroyVM)); // client destroyvm function - ENABLER_CREATEHOOK( - hook, + MAKEHOOK((char*)baseAddress + 0x12B00, &SQPrintHook, &ClientSQPrint); // client print function + MAKEHOOK((char*)baseAddress + 0x12BA0, &SQPrintHook, &UISQPrint); // ui print function + + MAKEHOOK((char*)baseAddress + 0x26130, &CreateNewVMHook, &ClientCreateNewVM); // client createnewvm function + MAKEHOOK((char*)baseAddress + 0x26E70, &DestroyVMHook, &ClientDestroyVM); // client destroyvm function + MAKEHOOK( (char*)baseAddress + 0x79A50, &ScriptCompileErrorHook, - reinterpret_cast(&ClientSQCompileError)); // client compileerror function - ENABLER_CREATEHOOK( - hook, + &ClientSQCompileError); // client compileerror function + MAKEHOOK( (char*)baseAddress + 0x10190, &CallScriptInitCallbackHook, - reinterpret_cast(&ClientCallScriptInitCallback)); // client callscriptinitcallback function -}) + &ClientCallScriptInitCallback); // client callscriptinitcallback function + + RegisterConCommand("script_client", ConCommand_script, "Executes script code on the client vm", FCVAR_CLIENTDLL); + RegisterConCommand("script_ui", ConCommand_script, "Executes script code on the ui vm", FCVAR_CLIENTDLL); +} -ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, [](HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (HMODULE baseAddress)) { AUTOHOOK_DISPATCH_MODULE(server.dll) @@ -348,32 +321,17 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, [](HMODULE baseAd g_pServerSquirrel->__sq_getbool = (sq_getboolType)((char*)baseAddress + 0x6110); g_pServerSquirrel->__sq_get = (sq_getType)((char*)baseAddress + 0x7C00); - HookEnabler hook; - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x1FE90, - &SQPrintHook, - reinterpret_cast(&ServerSQPrint)); // server print function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x260E0, - &CreateNewVMHook, - reinterpret_cast(&ServerCreateNewVM)); // server createnewvm function - ENABLER_CREATEHOOK( - hook, - (char*)baseAddress + 0x26E20, - &DestroyVMHook, - reinterpret_cast(&ServerDestroyVM)); // server destroyvm function - ENABLER_CREATEHOOK( - hook, + MAKEHOOK((char*)baseAddress + 0x1FE90, &SQPrintHook, &ServerSQPrint); // server print function + MAKEHOOK((char*)baseAddress + 0x260E0, &CreateNewVMHook, &ServerCreateNewVM); // server createnewvm function + MAKEHOOK((char*)baseAddress + 0x26E20, &DestroyVMHook, &ServerDestroyVM); // server destroyvm function + MAKEHOOK( (char*)baseAddress + 0x799E0, &ScriptCompileErrorHook, - reinterpret_cast(&ServerSQCompileError)); // server compileerror function - ENABLER_CREATEHOOK( - hook, + &ServerSQCompileError); // server compileerror function + MAKEHOOK( (char*)baseAddress + 0x1D5C0, &CallScriptInitCallbackHook, - reinterpret_cast(&ServerCallScriptInitCallback)); // server callscriptinitcallback function + &ServerCallScriptInitCallback); // server callscriptinitcallback function // FCVAR_CHEAT and FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS 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 @@ -382,4 +340,4 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, [](HMODULE baseAd ConCommand_script, "Executes script code on the server vm", FCVAR_GAMEDLL | FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS | FCVAR_CHEAT); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/NorthstarDLL/squirrel.h b/NorthstarDLL/squirrel.h index a32ad5a9..d5c39827 100644 --- a/NorthstarDLL/squirrel.h +++ b/NorthstarDLL/squirrel.h @@ -14,6 +14,12 @@ enum SQRESULT : SQInteger SQRESULT_NOTNULL = 1, }; +const std::map PrintSQRESULT = { + {SQRESULT_ERROR, "SQRESULT_ERROR"}, + {SQRESULT_NULL, "SQRESULT_NULL"}, + {SQRESULT_NOTNULL, "SQRESULT_NOTNULL"} +}; + typedef SQRESULT (*SQFunction)(void* sqvm); struct CompileBufferState @@ -158,12 +164,13 @@ template class SquirrelManager CompileBufferState bufferState = CompileBufferState(strCode); SQRESULT compileResult = compilebuffer(&bufferState, "console"); - spdlog::info("sq_compilebuffer returned {}", compileResult); + spdlog::info("sq_compilebuffer returned {}", PrintSQRESULT.at(compileResult)); + if (compileResult != SQRESULT_ERROR) { pushroottable(sqvm2); SQRESULT callResult = call(sqvm2, 0); - spdlog::info("sq_call returned {}", callResult); + spdlog::info("sq_call returned {}", PrintSQRESULT.at(callResult)); } } diff --git a/NorthstarDLL/tier0.cpp b/NorthstarDLL/tier0.cpp index 00482c70..a4ac7752 100644 --- a/NorthstarDLL/tier0.cpp +++ b/NorthstarDLL/tier0.cpp @@ -23,7 +23,7 @@ void TryCreateGlobalMemAlloc() Tier0::g_pMemAllocSingleton = CreateGlobalMemAlloc(); // if it already exists, this returns the preexisting IMemAlloc instance } -ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, [](HMODULE baseAddress) +ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, (HMODULE baseAddress)) { // shouldn't be necessary, but do this just in case TryCreateGlobalMemAlloc(); @@ -34,4 +34,4 @@ ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, [](HMODULE baseAddress) Tier0::Plat_FloatTime = reinterpret_cast(GetProcAddress(baseAddress, "Plat_FloatTime")); Tier0::ThreadInServerFrameThread = reinterpret_cast(GetProcAddress(baseAddress, "ThreadInServerFrameThread")); -}) \ No newline at end of file +} \ No newline at end of file diff --git a/loader_wsock32_proxy/hookutils.cpp b/loader_wsock32_proxy/hookutils.cpp deleted file mode 100644 index 7792a78e..00000000 --- a/loader_wsock32_proxy/hookutils.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "pch.h" -#include "../NorthstarDLL/hookutils.h" - -#define ERROR(...) { char err[2048]; sprintf_s(err, __VA_ARGS__); MessageBoxA(GetForegroundWindow(), err, "Northstar Wsock32 Proxy Error", 0); } - -void HookEnabler::CreateHook(LPVOID ppTarget, LPVOID ppDetour, LPVOID* ppOriginal, const char* targetName) -{ - // the macro for this uses ppTarget's name as targetName, and this typically starts with & - // targetname is used for debug stuff and debug output is nicer if we don't have this - if (*targetName == '&') - targetName++; - - if (MH_CreateHook(ppTarget, ppDetour, ppOriginal) == MH_OK) - { - HookTarget* target = new HookTarget; - target->targetAddress = ppTarget; - target->targetName = (char*)targetName; - - m_hookTargets.push_back(target); - } - else - { - if (targetName != nullptr) - { - ERROR("MH_CreateHook failed for function %s", targetName); - } - else - { - ERROR("MH_CreateHook failed for unknown function"); - } - } -} - -HookEnabler::~HookEnabler() -{ - for (auto& hook : m_hookTargets) - { - if (MH_EnableHook(hook->targetAddress) != MH_OK) - { - if (hook->targetName != nullptr) - { - ERROR("MH_EnableHook failed for function %s", hook->targetName); - } - else - { - ERROR("MH_EnableHook failed for unknown function"); - } - } - else - { - //ERROR("Enabling hook %s", hook->targetName); - } - } -} \ No newline at end of file diff --git a/loader_wsock32_proxy/loader.cpp b/loader_wsock32_proxy/loader.cpp index ab89a615..663f1f7b 100644 --- a/loader_wsock32_proxy/loader.cpp +++ b/loader_wsock32_proxy/loader.cpp @@ -1,6 +1,6 @@ #include "pch.h" #include "loader.h" -#include "../NorthstarDLL/hookutils.h" +#include "include/MinHook.h" #include #include #include @@ -84,8 +84,10 @@ bool ProvisionNorthstar() return false; } - HookEnabler hook; - ENABLER_CREATEHOOK(hook, GetProcAddress(launcherHandle, "LauncherMain"), &LauncherMainHook, reinterpret_cast(&LauncherMainOriginal)); + LPVOID pTarget = GetProcAddress(launcherHandle, "LauncherMain"); + if (MH_CreateHook(pTarget, &LauncherMainHook, reinterpret_cast(&LauncherMainOriginal)) != MH_OK || MH_EnableHook(pTarget) != MH_OK) + MessageBoxA( + GetForegroundWindow(), "Hook creation failed for function LauncherMain.", "Northstar Wsock32 Proxy Error", 0); return true; } \ No newline at end of file diff --git a/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj b/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj index 3fed5a8a..2b257de8 100644 --- a/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj +++ b/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj @@ -95,12 +95,12 @@ + - Create diff --git a/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj.filters b/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj.filters index 83ed7ac6..4c6b1ba1 100644 --- a/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj.filters +++ b/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj.filters @@ -13,6 +13,9 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {1b1575f7-3332-478b-9e85-9c0978249a70} + @@ -21,6 +24,9 @@ Header Files + + Header Files\include + @@ -32,9 +38,6 @@ Source Files - - Source Files - -- cgit v1.2.3