diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-05-09 00:40:53 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-05-09 00:40:53 +0100 |
commit | f230156cbebc1b93db5e254410ee2ab3a8dcb27c (patch) | |
tree | e98c72fabbff37a55e7f9216c52e4f8ef2084073 | |
parent | 6c8112a6c368dd36d21fd94689e9682bc3b012a5 (diff) | |
download | NorthstarLauncher-f230156cbebc1b93db5e254410ee2ab3a8dcb27c.tar.gz NorthstarLauncher-f230156cbebc1b93db5e254410ee2ab3a8dcb27c.zip |
use in-file macros rather than global funcs for registering dll load callbacks
80 files changed, 411 insertions, 420 deletions
diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp index 04aadf03..0fb025a7 100644 --- a/LauncherInjector/main.cpp +++ b/LauncherInjector/main.cpp @@ -7,6 +7,11 @@ #include <Shlwapi.h> #include <iostream> +#pragma comment(lib, "Ws2_32.lib") + +#include <winsock2.h> +#include <WS2tcpip.h> + namespace fs = std::filesystem; extern "C" @@ -125,6 +130,34 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* MessageBoxA(GetForegroundWindow(), text, "Northstar Launcher Error", 0); } +void AwaitOriginStartup() +{ + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); + SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (sock != INVALID_SOCKET) + { + const int LSX_PORT = 3216; + + sockaddr_in lsxAddr; + lsxAddr.sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &(lsxAddr.sin_addr)); + lsxAddr.sin_port = htons(LSX_PORT); + + std::cout << "LSX: connect()" << std::endl; + connect(sock, (struct sockaddr*)&lsxAddr, sizeof(lsxAddr)); + + char buf[4096]; + recv(sock, buf, 4096, 0); + std::cout << buf << std::endl; + + Sleep(8000); + } + + WSACleanup(); +} + void EnsureOriginStarted() { if (GetProcessByName(L"Origin.exe") || GetProcessByName(L"EADesktop.exe")) @@ -147,7 +180,7 @@ void EnsureOriginStarted() return; } - printf("[*] Starting Origin...\n"); + std::cout << "[*] Starting Origin..." << std::endl; PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); @@ -168,11 +201,16 @@ void EnsureOriginStarted() (LPSTARTUPINFOA)&si, &pi); - printf("[*] Waiting for Origin...\n"); + std::cout << "[*] Waiting for Origin..." << std::endl; + + // wait for origin process to boot + do + { + Sleep(500); + } while (!GetProcessByName(L"OriginClientService.exe") && !GetProcessByName(L"EADesktop.exe")); - // wait for origin to be ready, this process is created when origin is ready enough to launch game without any errors - while (!GetProcessByName(L"OriginClientService.exe") && !GetProcessByName(L"EADesktop.exe")) - Sleep(200); + // wait for origin to be ready to start + AwaitOriginStartup(); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); @@ -253,7 +291,7 @@ bool LoadNorthstar() LoadPlugins = GetProcAddress(hHookModule, "LoadPlugins"); if (!hHookModule || LoadPlugins == nullptr) { - printf("Failed to get function pointer to LoadPlugins of Northstar.dll\n"); + std::cout << "Failed to get function pointer to LoadPlugins of Northstar.dll" << std::endl; LibraryLoadError(GetLastError(), L"Northstar.dll", buffer); return false; } @@ -266,7 +304,7 @@ bool LoadNorthstar() HMODULE LoadDediStub(const char* name) { // this works because materialsystem_dx11.dll uses relative imports, and even a DLL loaded with an absolute path will take precedence - printf("[*] Loading %s\n", name); + std::cout << "[*] Loading " << name << std::endl; swprintf_s(buffer, L"%s\\bin\\x64_dedi\\%hs", exePath, name); HMODULE h = LoadLibraryExW(buffer, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (!h) @@ -310,7 +348,7 @@ int main(int argc, char* argv[]) if (dedicated && !nostubs) { - printf("[*] Loading stubs\n"); + std::cout << "[*] Loading stubs" << std::endl; HMODULE gssao, gtxaa, d3d11; if (!(gssao = GetModuleHandleA("GFSDK_SSAO.win64.dll")) && !(gtxaa = GetModuleHandleA("GFSDK_TXAA.win64.dll")) && !(d3d11 = GetModuleHandleA("d3d11.dll"))) @@ -320,8 +358,8 @@ int main(int argc, char* argv[]) { if ((!gssao || FreeLibrary(gssao)) && (!gtxaa || FreeLibrary(gtxaa)) && (!d3d11 || FreeLibrary(d3d11))) { - printf("[*] WARNING: Failed to load d3d11/gfsdk stubs from bin/x64_dedi. " - "The stubs have been unloaded and the original libraries will be used instead.\n"); + std::cout <<"[*] WARNING: Failed to load d3d11/gfsdk stubs from bin/x64_dedi. " + "The stubs have been unloaded and the original libraries will be used instead" << std::endl; } else { @@ -339,8 +377,8 @@ int main(int argc, char* argv[]) else { // this should never happen - printf("[*] WARNING: Failed to load stubs because conflicting modules are already loaded, so those will be used instead " - "(did Northstar initialize too late?).\n"); + std::cout << "[*] WARNING: Failed to load stubs because conflicting modules are already loaded, so those will be used instead " + "(did Northstar initialize too late?)." << std::endl; } } @@ -362,7 +400,7 @@ int main(int argc, char* argv[]) file.close(); } - printf("[*] Loading tier0.dll\n"); + std::cout << "[*] Loading tier0.dll" << std::endl; swprintf_s(buffer, L"%s\\bin\\x64_retail\\tier0.dll", exePath); hTier0Module = LoadLibraryExW(buffer, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (!hTier0Module) @@ -374,14 +412,14 @@ int main(int argc, char* argv[]) bool loadNorthstar = ShouldLoadNorthstar(argc, argv); if (loadNorthstar) { - printf("[*] Loading Northstar\n"); + std::cout << "[*] Loading Northstar" << std::endl; if (!LoadNorthstar()) return 1; } else - printf("[*] Going to load the vanilla game\n"); + std::cout << "[*] Going to load the vanilla game" << std::endl; - printf("[*] Loading launcher.dll\n"); + std::cout << "[*] Loading launcher.dll" << std::endl; swprintf_s(buffer, L"%s\\bin\\x64_retail\\launcher.dll", exePath); hLauncherModule = LoadLibraryExW(buffer, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (!hLauncherModule) @@ -391,7 +429,7 @@ int main(int argc, char* argv[]) } } - printf("[*] Launching the game...\n"); + std::cout << "[*] Launching the game..." << std::endl; auto LauncherMain = GetLauncherMain(); if (!LauncherMain) MessageBoxA( @@ -402,6 +440,7 @@ int main(int argc, char* argv[]) // auto result = ((__int64(__fastcall*)())LauncherMain)(); // auto result = ((signed __int64(__fastcall*)(__int64))LauncherMain)(0i64); + std::cout.flush(); return ((int(/*__fastcall*/*)(HINSTANCE, HINSTANCE, LPSTR, int))LauncherMain)( NULL, NULL, NULL, 0); // the parameters aren't really used anyways } diff --git a/LauncherInjector/ns_startup_args.txt b/LauncherInjector/ns_startup_args.txt new file mode 100644 index 00000000..0713aef2 --- /dev/null +++ b/LauncherInjector/ns_startup_args.txt @@ -0,0 +1 @@ +-multiple
\ No newline at end of file diff --git a/LauncherInjector/ns_startup_args_dedi.txt b/LauncherInjector/ns_startup_args_dedi.txt new file mode 100644 index 00000000..ce1dcf5f --- /dev/null +++ b/LauncherInjector/ns_startup_args_dedi.txt @@ -0,0 +1 @@ ++setplaylist private_match
\ No newline at end of file diff --git a/NorthstarDedicatedTest/ExploitFixes.cpp b/NorthstarDedicatedTest/ExploitFixes.cpp index db754ad5..257ec428 100644 --- a/NorthstarDedicatedTest/ExploitFixes.cpp +++ b/NorthstarDedicatedTest/ExploitFixes.cpp @@ -2,6 +2,7 @@ #include "ExploitFixes.h" #include "ExploitFixes_UTF8Parser.h" +#include "hooks.h" #include "NSMem.h" #include "cvar.h" @@ -46,6 +47,8 @@ struct Angle bool IsInvalid() { + return !ValidateFloats(pitch, yaw, roll); + if (!ValidateFloats(pitch, yaw, roll)) return false; @@ -205,12 +208,14 @@ KHOOK(CClient_ProcessUsercmds, ("engine.dll", "40 55 56 48 83 EC 58"), bool, __f { return BLOCKED_INFO("Invalid m_nNewCommands (" << msg->m_nNewCommands << ")"); } - - constexpr int NUMCMD_SANITY_LIMIT = 16; + + // 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) { return BLOCKED_INFO("Command count is too high (new: " << msg->m_nNewCommands << ", backup: " << msg->m_nBackupCommands << ")"); - } + + }*/ if (msg->m_nLength <= 0) return BLOCKED_INFO("Invalid message length (" << msg->m_nLength << ")"); @@ -394,7 +399,7 @@ void DoBytePatches() } } -void ExploitFixes::LoadCallback(HMODULE unused) +ON_DLL_LOAD_RELIESON("server.dll", ExploitFixes, ConVar, (HMODULE baseAddress) { spdlog::info("ExploitFixes::LoadCallback ..."); @@ -416,4 +421,4 @@ void ExploitFixes::LoadCallback(HMODULE unused) 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/NorthstarDedicatedTest/ExploitFixes.h b/NorthstarDedicatedTest/ExploitFixes.h index 7a407a3d..ae30a899 100644 --- a/NorthstarDedicatedTest/ExploitFixes.h +++ b/NorthstarDedicatedTest/ExploitFixes.h @@ -1,9 +1,4 @@ // KittenPopo's exploit fix hooks, feel free to add more here #pragma once -#include "pch.h" - -namespace ExploitFixes -{ - void LoadCallback(HMODULE unused); -}
\ No newline at end of file +#include "pch.h"
\ No newline at end of file diff --git a/NorthstarDedicatedTest/audio.cpp b/NorthstarDedicatedTest/audio.cpp index 0b65670f..982e42ab 100644 --- a/NorthstarDedicatedTest/audio.cpp +++ b/NorthstarDedicatedTest/audio.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "audio.h" #include "dedicated.h" @@ -493,7 +494,7 @@ void __fastcall MilesLog_Hook(int level, const char* string) spdlog::info("[MSS] {} - {}", level, string); } -void InitialiseMilesAudioHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", AudioHooks, ConVar, (HMODULE baseAddress) { Cvar_ns_print_played_sounds = new ConVar("ns_print_played_sounds", "0", FCVAR_NONE, ""); @@ -512,4 +513,4 @@ void InitialiseMilesAudioHooks(HMODULE baseAddress) ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x57DAD0, &MilesLog_Hook, reinterpret_cast<LPVOID*>(&MilesLog_Original)); MilesStopAll = (MilesStopAll_Type)((char*)baseAddress + 0x580850); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/audio.h b/NorthstarDedicatedTest/audio.h index 6ed3ce57..98da2fa1 100644 --- a/NorthstarDedicatedTest/audio.h +++ b/NorthstarDedicatedTest/audio.h @@ -45,6 +45,4 @@ class CustomAudioManager std::unordered_map<std::string, std::shared_ptr<EventOverrideData>> m_loadedAudioOverridesRegex = {}; }; -extern CustomAudioManager g_CustomAudioManager; - -void InitialiseMilesAudioHooks(HMODULE baseAddress);
\ No newline at end of file +extern CustomAudioManager g_CustomAudioManager;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp index 93cf9c65..3f62db38 100644 --- a/NorthstarDedicatedTest/bansystem.cpp +++ b/NorthstarDedicatedTest/bansystem.cpp @@ -1,6 +1,7 @@ #pragma once #include "pch.h" #include "bansystem.h" +#include "hooks.h" #include "serverauthentication.h" #include "concommand.h" #include "miscserverscript.h" @@ -95,7 +96,7 @@ void ClearBanlistCommand(const CCommand& args) g_ServerBanSystem->ClearBanlist(); } -void InitialiseBanSystem(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", BanSystem, ConCommand, (HMODULE baseAddress) { g_ServerBanSystem = new ServerBanSystem; g_ServerBanSystem->OpenBanlist(); @@ -103,4 +104,4 @@ void InitialiseBanSystem(HMODULE baseAddress) RegisterConCommand("ban", BanPlayerCommand, "bans a given player by uid or name", FCVAR_GAMEDLL); RegisterConCommand("unban", UnbanPlayerCommand, "unbans a given player by uid", FCVAR_NONE); RegisterConCommand("clearbanlist", ClearBanlistCommand, "clears all uids on the banlist", FCVAR_NONE); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h index 0f618843..ed4d2aed 100644 --- a/NorthstarDedicatedTest/bansystem.h +++ b/NorthstarDedicatedTest/bansystem.h @@ -15,6 +15,4 @@ class ServerBanSystem bool IsUIDAllowed(uint64_t uid); }; -extern ServerBanSystem* g_ServerBanSystem; - -void InitialiseBanSystem(HMODULE baseAddress);
\ No newline at end of file +extern ServerBanSystem* g_ServerBanSystem;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/buildainfile.cpp b/NorthstarDedicatedTest/buildainfile.cpp index 010f0975..13660dc6 100644 --- a/NorthstarDedicatedTest/buildainfile.cpp +++ b/NorthstarDedicatedTest/buildainfile.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "buildainfile.h" #include "convar.h" +#include "hooks.h" #include "hookutils.h" #include <fstream> #include <filesystem> @@ -373,7 +374,7 @@ void LoadAINFileHook(void* aimanager, void* buf, const char* filename) } } -void InitialiseBuildAINFileHooks(HMODULE baseAddress) +ON_DLL_LOAD("server.dll", BuildAINFile, (HMODULE baseAddress) { Cvar_ns_ai_dumpAINfileFromLoad = new ConVar( "ns_ai_dumpAINfileFromLoad", "0", FCVAR_NONE, "For debugging: whether we should dump ain data for ains loaded from disk"); @@ -397,4 +398,4 @@ void InitialiseBuildAINFileHooks(HMODULE baseAddress) // due to the sheer amount of logging this is a massive perf hit to generation, but spewlog_enable 0 exists so whatever NSMem::NOP(base + 0x3889B6, 6); NSMem::NOP(base + 0x3889BF, 6); -}
\ No newline at end of file +});
\ No newline at end of file diff --git a/NorthstarDedicatedTest/buildainfile.h b/NorthstarDedicatedTest/buildainfile.h index a3c0e090..7b9637ef 100644 --- a/NorthstarDedicatedTest/buildainfile.h +++ b/NorthstarDedicatedTest/buildainfile.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseBuildAINFileHooks(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/chatcommand.cpp b/NorthstarDedicatedTest/chatcommand.cpp index 2aa51737..0cbfec74 100644 --- a/NorthstarDedicatedTest/chatcommand.cpp +++ b/NorthstarDedicatedTest/chatcommand.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "convar.h" #include "concommand.h" #include "chatcommand.h" @@ -29,10 +30,10 @@ void ConCommand_log(const CCommand& args) } } -void InitialiseChatCommands(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/NorthstarDedicatedTest/chatcommand.h b/NorthstarDedicatedTest/chatcommand.h index 546d0126..7b9637ef 100644 --- a/NorthstarDedicatedTest/chatcommand.h +++ b/NorthstarDedicatedTest/chatcommand.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseChatCommands(HMODULE baseAddress); +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientauthhooks.cpp b/NorthstarDedicatedTest/clientauthhooks.cpp index 5c1c4510..29ecbd69 100644 --- a/NorthstarDedicatedTest/clientauthhooks.cpp +++ b/NorthstarDedicatedTest/clientauthhooks.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "clientauthhooks.h" #include "hookutils.h" #include "gameutils.h" @@ -33,7 +34,7 @@ void AuthWithStryderHook(void* a1) AuthWithStryder(a1); } -void InitialiseClientAuthHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientAuthHooks, ConVar, (HMODULE baseAddress) { // this cvar will save to cfg once initially agreed with Cvar_ns_has_agreed_to_send_token = new ConVar( @@ -44,4 +45,4 @@ void InitialiseClientAuthHooks(HMODULE baseAddress) HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1843A0, &AuthWithStryderHook, reinterpret_cast<LPVOID*>(&AuthWithStryder)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientauthhooks.h b/NorthstarDedicatedTest/clientauthhooks.h index e40a68a5..7b9637ef 100644 --- a/NorthstarDedicatedTest/clientauthhooks.h +++ b/NorthstarDedicatedTest/clientauthhooks.h @@ -1,2 +1 @@ -#pragma once -void InitialiseClientAuthHooks(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientchathooks.cpp b/NorthstarDedicatedTest/clientchathooks.cpp index 74418c06..ef40c634 100644 --- a/NorthstarDedicatedTest/clientchathooks.cpp +++ b/NorthstarDedicatedTest/clientchathooks.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "clientchathooks.h" #include <rapidjson/document.h> #include "squirrel.h" @@ -84,7 +85,7 @@ static SQRESULT SQ_ChatWriteLine(void* sqvm) return SQRESULT_NOTNULL; } -void InitialiseClientChatHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientChatHooks, ClientSquirrel, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x22E580, &CHudChat__AddGameLineHook, reinterpret_cast<LPVOID*>(&CHudChat__AddGameLine)); @@ -92,4 +93,4 @@ void InitialiseClientChatHooks(HMODULE baseAddress) g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWrite", "int context, string text", "", SQ_ChatWrite); g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWriteRaw", "int context, string text", "", SQ_ChatWriteRaw); g_ClientSquirrelManager->AddFuncRegistration("void", "NSChatWriteLine", "int context, string text", "", SQ_ChatWriteLine); -} +}) diff --git a/NorthstarDedicatedTest/clientchathooks.h b/NorthstarDedicatedTest/clientchathooks.h index 79a1b3e2..d8f831c2 100644 --- a/NorthstarDedicatedTest/clientchathooks.h +++ b/NorthstarDedicatedTest/clientchathooks.h @@ -1,5 +1,2 @@ #pragma once -#include "pch.h" -#include "serverchathooks.h" - -void InitialiseClientChatHooks(HMODULE baseAddress); +#include "pch.h"
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientruihooks.cpp b/NorthstarDedicatedTest/clientruihooks.cpp index bc6c7aa7..0bbcaaa3 100644 --- a/NorthstarDedicatedTest/clientruihooks.cpp +++ b/NorthstarDedicatedTest/clientruihooks.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "clientruihooks.h" #include "convar.h" @@ -15,10 +16,10 @@ char DrawRUIFuncHook(void* a1, float* a2) return DrawRUIFunc(a1, a2); } -void InitialiseEngineClientRUIHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", RUI, ConVar, (HMODULE baseAddress) { Cvar_rui_drawEnable = new ConVar("rui_drawEnable", "1", FCVAR_CLIENTDLL, "Controls whether RUI should be drawn"); HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xFC500, &DrawRUIFuncHook, reinterpret_cast<LPVOID*>(&DrawRUIFunc)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientruihooks.h b/NorthstarDedicatedTest/clientruihooks.h index 967ccefe..6f70f09b 100644 --- a/NorthstarDedicatedTest/clientruihooks.h +++ b/NorthstarDedicatedTest/clientruihooks.h @@ -1,2 +1 @@ #pragma once -void InitialiseEngineClientRUIHooks(HMODULE baseAddress);
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientvideooverrides.cpp b/NorthstarDedicatedTest/clientvideooverrides.cpp index d5674f51..687d6714 100644 --- a/NorthstarDedicatedTest/clientvideooverrides.cpp +++ b/NorthstarDedicatedTest/clientvideooverrides.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "clientvideooverrides.h" #include "modmanager.h" @@ -31,9 +32,9 @@ void* BinkOpenHook(const char* path, uint32_t flags) return BinkOpen(path, flags); } -void InitialiseClientVideoOverrides(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("client.dll", BinkVideo, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK( hook, GetProcAddress(GetModuleHandleA("bink2w64.dll"), "BinkOpen"), &BinkOpenHook, reinterpret_cast<LPVOID*>(&BinkOpen)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/clientvideooverrides.h b/NorthstarDedicatedTest/clientvideooverrides.h index 8819e404..7b9637ef 100644 --- a/NorthstarDedicatedTest/clientvideooverrides.h +++ b/NorthstarDedicatedTest/clientvideooverrides.h @@ -1,2 +1 @@ -#pragma once -void InitialiseClientVideoOverrides(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/concommand.cpp b/NorthstarDedicatedTest/concommand.cpp index 1bdda91b..f7ce3b75 100644 --- a/NorthstarDedicatedTest/concommand.cpp +++ b/NorthstarDedicatedTest/concommand.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "concommand.h" #include "gameutils.h" #include "misccommands.h" @@ -17,11 +18,11 @@ void RegisterConCommand(const char* name, void (*callback)(const CCommand&), con conCommandConstructor(newCommand, name, callback, helpString, flags, nullptr); } -void InitialiseConCommands(HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", ConCommand, (HMODULE baseAddress) { conCommandConstructor = (ConCommandConstructorType)((char*)baseAddress + 0x415F60); AddMiscConCommands(); -} +}) //----------------------------------------------------------------------------- // Purpose: Returns true if this is a command diff --git a/NorthstarDedicatedTest/concommand.h b/NorthstarDedicatedTest/concommand.h index ea35ec1f..90eb5b01 100644 --- a/NorthstarDedicatedTest/concommand.h +++ b/NorthstarDedicatedTest/concommand.h @@ -122,6 +122,5 @@ class ConCommand : public ConCommandBase }; // Size: 0x0060 void RegisterConCommand(const char* name, void (*callback)(const CCommand&), const char* helpString, int flags); -void InitialiseConCommands(HMODULE baseAddress); #define MAKE_CONCMD(name, helpStr, flags, fn) RegisterConCommand(name, fn, helpStr, flags);
\ No newline at end of file diff --git a/NorthstarDedicatedTest/convar.cpp b/NorthstarDedicatedTest/convar.cpp index 346e7b69..5a261edb 100644 --- a/NorthstarDedicatedTest/convar.cpp +++ b/NorthstarDedicatedTest/convar.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "bits.h" #include "cvar.h" #include "convar.h" @@ -31,7 +32,7 @@ CvarIsFlagSetType CvarIsFlagSet; //----------------------------------------------------------------------------- // Purpose: ConVar interface initialization //----------------------------------------------------------------------------- -void InitialiseConVars(HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", ConVar, (HMODULE baseAddress) { conVarMalloc = (ConVarMallocType)((char*)baseAddress + 0x415C20); conVarRegister = (ConVarRegisterType)((char*)baseAddress + 0x417230); @@ -44,7 +45,7 @@ void InitialiseConVars(HMODULE baseAddress) HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x417FA0, &ConVar::IsFlagSet, reinterpret_cast<LPVOID*>(&CvarIsFlagSet)); -} +}) //----------------------------------------------------------------------------- // Purpose: constructor diff --git a/NorthstarDedicatedTest/convar.h b/NorthstarDedicatedTest/convar.h index b1424fb7..9b27aabe 100644 --- a/NorthstarDedicatedTest/convar.h +++ b/NorthstarDedicatedTest/convar.h @@ -144,6 +144,4 @@ class ConVar float m_fMaxVal {}; // 0x0068 void* m_pMalloc {}; // 0x0070 char m_pPad80[10] {}; // 0x0080 -}; // Size: 0x0080 - -void InitialiseConVars(HMODULE baseAddress);
\ No newline at end of file +}; // Size: 0x0080
\ No newline at end of file diff --git a/NorthstarDedicatedTest/debugoverlay.cpp b/NorthstarDedicatedTest/debugoverlay.cpp index e29da96b..db0f09fa 100644 --- a/NorthstarDedicatedTest/debugoverlay.cpp +++ b/NorthstarDedicatedTest/debugoverlay.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "debugoverlay.h" #include "dedicated.h" #include "cvar.h" @@ -151,11 +152,8 @@ void __fastcall DrawOverlayHook(OverlayBase_t* pOverlay) LeaveCriticalSection((LPCRITICAL_SECTION)((char*)sEngineModule + 0x10DB0A38)); } -void InitialiseDebugOverlay(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, (HMODULE baseAddress) { - if (IsDedicated()) - return; - HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xABCB0, &DrawOverlayHook, reinterpret_cast<LPVOID*>(&DrawOverlay)); @@ -172,4 +170,4 @@ void InitialiseDebugOverlay(HMODULE baseAddress) 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/NorthstarDedicatedTest/debugoverlay.h b/NorthstarDedicatedTest/debugoverlay.h index a300018c..7b9637ef 100644 --- a/NorthstarDedicatedTest/debugoverlay.h +++ b/NorthstarDedicatedTest/debugoverlay.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseDebugOverlay(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 5099a6d2..8f43c506 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "dedicated.h" #include "hookutils.h" #include "gameutils.h" @@ -128,7 +129,7 @@ DWORD WINAPI ConsoleInputThread(PVOID pThreadParameter) } #include "NSMem.h" -void InitialiseDedicated(HMODULE engineAddress) +ON_DLL_LOAD_DEDI("engine.dll", DedicatedServer, (HMODULE engineAddress) { spdlog::info("InitialiseDedicated"); @@ -141,6 +142,12 @@ void InitialiseDedicated(HMODULE engineAddress) } { + // Host_Init + // don't call Key_Init to avoid loading some extra rsons from rpak (will be necessary to boot if we ever wanna disable rpaks entirely) + NSMem::NOP(ea + 0x1565B0, 5); + } + + { // CModAppSystemGroup::Create // force the engine into dedicated mode by changing the first comparison to IsServerOnly to an assignment auto ptr = ea + 0x1C4EBD; @@ -299,9 +306,9 @@ void InitialiseDedicated(HMODULE engineAddress) consoleInputThreadHandle = CreateThread(0, 0, ConsoleInputThread, 0, 0, NULL); else spdlog::info("Console input disabled by user request"); -} +}) -void InitialiseDedicatedOrigin(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 @@ -312,7 +319,7 @@ void InitialiseDedicatedOrigin(HMODULE baseAddress) { 0xC3 // ret }); -} +}) typedef void (*PrintFatalSquirrelErrorType)(void* sqvm); PrintFatalSquirrelErrorType PrintFatalSquirrelError; @@ -322,8 +329,8 @@ void PrintFatalSquirrelErrorHook(void* sqvm) g_pEngine->m_nQuitting = EngineQuitState::QUIT_TODESKTOP; } -void InitialiseDedicatedServerGameDLL(HMODULE baseAddress) +ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK(hook, baseAddress + 0x794D0, &PrintFatalSquirrelErrorHook, reinterpret_cast<LPVOID*>(&PrintFatalSquirrelError)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicated.h b/NorthstarDedicatedTest/dedicated.h index 0b4d9188..3339523a 100644 --- a/NorthstarDedicatedTest/dedicated.h +++ b/NorthstarDedicatedTest/dedicated.h @@ -1,7 +1,3 @@ #pragma once -bool IsDedicated(); - -void InitialiseDedicated(HMODULE moduleAddress); -void InitialiseDedicatedOrigin(HMODULE baseAddress); -void InitialiseDedicatedServerGameDLL(HMODULE baseAddress);
\ No newline at end of file +bool IsDedicated();
\ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp index f1a91e22..da6ce7d3 100644 --- a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp +++ b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp @@ -1,5 +1,6 @@ #pragma once #include "pch.h" +#include "hooks.h" #include "dedicated.h" #include "dedicatedmaterialsystem.h" #include "hookutils.h" @@ -45,7 +46,7 @@ HRESULT __stdcall D3D11CreateDeviceHook( pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext); } -void InitialiseDedicatedMaterialSystem(HMODULE baseAddress) +ON_DLL_LOAD_DEDI("materialsystem_dx11.dll", DedicatedServerMaterialSystem, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xD9A0E, &D3D11CreateDeviceHook, reinterpret_cast<LPVOID*>(&D3D11CreateDevice)); @@ -82,42 +83,4 @@ void InitialiseDedicatedMaterialSystem(HMODULE baseAddress) // previously had DisableDedicatedWindowCreation stuff here, removing for now since shit and unstable // check commit history if needed -} - -typedef void* (*PakLoadAPI__LoadRpakType)(char* filename, void* unknown, int flags); -PakLoadAPI__LoadRpakType PakLoadAPI__LoadRpak; - -void* PakLoadAPI__LoadRpakHook(char* filename, void* unknown, int flags) -{ - spdlog::info("PakLoadAPI__LoadRpakHook {}", filename); - - // on dedi, don't load any paks that aren't required - if (strncmp(filename, "common", 6)) - return 0; - - return PakLoadAPI__LoadRpak(filename, unknown, flags); -} - -typedef void* (*PakLoadAPI__LoadRpak2Type)(char* filename, void* unknown, int flags, void* callback, void* callback2); -PakLoadAPI__LoadRpak2Type PakLoadAPI__LoadRpak2; - -void* PakLoadAPI__LoadRpak2Hook(char* filename, void* unknown, int flags, void* callback, void* callback2) -{ - spdlog::info("PakLoadAPI__LoadRpak2Hook {}", filename); - - // on dedi, don't load any paks that aren't required - if (strncmp(filename, "common", 6)) - return 0; - - return PakLoadAPI__LoadRpak2(filename, unknown, flags, callback, callback2); -} - -void InitialiseDedicatedRtechGame(HMODULE baseAddress) -{ - baseAddress = GetModuleHandleA("rtech_game.dll"); - - HookEnabler hook; - // unfortunately this is unstable, seems to freeze when changing maps - // ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xB0F0, &PakLoadAPI__LoadRpakHook, reinterpret_cast<LPVOID*>(&PakLoadAPI__LoadRpak)); - // ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xB170, &PakLoadAPI__LoadRpak2Hook, reinterpret_cast<LPVOID*>(&PakLoadAPI__LoadRpak2)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicatedmaterialsystem.h b/NorthstarDedicatedTest/dedicatedmaterialsystem.h index 38343d17..7b9637ef 100644 --- a/NorthstarDedicatedTest/dedicatedmaterialsystem.h +++ b/NorthstarDedicatedTest/dedicatedmaterialsystem.h @@ -1,3 +1 @@ -#pragma once -void InitialiseDedicatedMaterialSystem(HMODULE baseAddress); -void InitialiseDedicatedRtechGame(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index fc403e95..d73fa9d5 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -1,48 +1,15 @@ #include "pch.h" #include "hooks.h" #include "main.h" -#include "squirrel.h" -#include "dedicated.h" -#include "dedicatedmaterialsystem.h" -#include "sourceconsole.h" #include "logging.h" -#include "concommand.h" -#include "modmanager.h" -#include "filesystem.h" -#include "serverauthentication.h" -#include "scriptmodmenu.h" -#include "scriptserverbrowser.h" #include "keyvalues.h" #include "masterserver.h" #include "gameutils.h" -#include "chatcommand.h" -#include "modlocalisation.h" -#include "playlist.h" -#include "miscserverscript.h" -#include "clientauthhooks.h" -#include "latencyflex.h" -#include "scriptbrowserhooks.h" -#include "scriptmainmenupromos.h" -#include "miscclientfixes.h" -#include "miscserverfixes.h" -#include "rpakfilesystem.h" -#include "bansystem.h" #include "memalloc.h" #include "maxplayers.h" -#include "languagehooks.h" -#include "audio.h" -#include "buildainfile.h" #include "configurables.h" -#include "serverchathooks.h" -#include "clientchathooks.h" -#include "localchatwriter.h" -#include "scriptservertoclientstringcommand.h" #include "plugin_abi.h" #include "plugins.h" -#include "debugoverlay.h" -#include "clientvideooverrides.h" -#include "clientruihooks.h" -#include <string.h> #include "version.h" #include "pch.h" @@ -50,7 +17,10 @@ #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" #include "rapidjson/error/en.h" -#include "ExploitFixes.h" + +#include <string.h> +#include <filesystem> +namespace fs = std::filesystem; typedef void (*initPluginFuncPtr)(void* getPluginObject); @@ -218,76 +188,17 @@ bool InitialiseNorthstar() AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions); - // dedi patches - { - AddDllLoadCallbackForDedicatedServer("tier0.dll", InitialiseDedicatedOrigin); - AddDllLoadCallbackForDedicatedServer("engine.dll", InitialiseDedicated); - AddDllLoadCallbackForDedicatedServer("server.dll", InitialiseDedicatedServerGameDLL); - AddDllLoadCallbackForDedicatedServer("materialsystem_dx11.dll", InitialiseDedicatedMaterialSystem); - // this fucking sucks, but seemingly we somehow load after rtech_game???? unsure how, but because of this we have to apply patches - // here, not on rtech_game load - AddDllLoadCallbackForDedicatedServer("engine.dll", InitialiseDedicatedRtechGame); - } - - AddDllLoadCallback("engine.dll", InitialiseConVars); - AddDllLoadCallback("engine.dll", InitialiseConCommands); - // client-exclusive patches { - AddDllLoadCallbackForClient("tier0.dll", InitialiseTier0LanguageHooks); - AddDllLoadCallbackForClient("client.dll", InitialiseClientSquirrel); - AddDllLoadCallbackForClient("client.dll", InitialiseSourceConsole); - AddDllLoadCallbackForClient("engine.dll", InitialiseChatCommands); - AddDllLoadCallbackForClient("client.dll", InitialiseScriptModMenu); - AddDllLoadCallbackForClient("client.dll", InitialiseScriptServerBrowser); - AddDllLoadCallbackForClient("localize.dll", InitialiseModLocalisation); - AddDllLoadCallbackForClient("engine.dll", InitialiseClientAuthHooks); - AddDllLoadCallbackForClient("client.dll", InitialiseLatencyFleX); - AddDllLoadCallbackForClient("engine.dll", InitialiseScriptExternalBrowserHooks); - AddDllLoadCallbackForClient("client.dll", InitialiseScriptMainMenuPromos); - AddDllLoadCallbackForClient("client.dll", InitialiseMiscClientFixes); - AddDllLoadCallbackForClient("client.dll", InitialiseClientPrintHooks); AddDllLoadCallbackForClient("client.dll", InitialisePluginCommands); - AddDllLoadCallbackForClient("client.dll", InitialiseClientChatHooks); - AddDllLoadCallbackForClient("client.dll", InitialiseLocalChatWriter); - AddDllLoadCallbackForClient("client.dll", InitialiseScriptServerToClientStringCommands); - AddDllLoadCallbackForClient("client.dll", InitialiseClientVideoOverrides); - AddDllLoadCallbackForClient("engine.dll", InitialiseEngineClientRUIHooks); - AddDllLoadCallbackForClient("engine.dll", InitialiseDebugOverlay); - // audio hooks - AddDllLoadCallbackForClient("client.dll", InitialiseMilesAudioHooks); } - AddDllLoadCallback("engine.dll", InitialiseEngineSpewFuncHooks); - AddDllLoadCallback("server.dll", InitialiseServerSquirrel); - AddDllLoadCallback("engine.dll", InitialiseBanSystem); - AddDllLoadCallback("engine.dll", InitialiseServerAuthentication); - AddDllLoadCallback("engine.dll", InitialiseSharedMasterServer); - AddDllLoadCallback("server.dll", InitialiseMiscServerScriptCommand); - AddDllLoadCallback("server.dll", InitialiseMiscServerFixes); - AddDllLoadCallback("server.dll", InitialiseBuildAINFileHooks); - - AddDllLoadCallback("engine.dll", InitialisePlaylistHooks); - - AddDllLoadCallback("filesystem_stdio.dll", InitialiseFilesystem); - AddDllLoadCallback("engine.dll", InitialiseEngineRpakFilesystem); - AddDllLoadCallback("engine.dll", InitialiseKeyValues); - - AddDllLoadCallback("engine.dll", InitialiseServerChatHooks_Engine); - AddDllLoadCallback("server.dll", InitialiseServerChatHooks_Server); - // maxplayers increase AddDllLoadCallback("engine.dll", InitialiseMaxPlayersOverride_Engine); AddDllLoadCallback("client.dll", InitialiseMaxPlayersOverride_Client); AddDllLoadCallback("server.dll", InitialiseMaxPlayersOverride_Server); - // mod manager after everything else - AddDllLoadCallback("engine.dll", InitialiseModManager); - - // activate exploit fixes - AddDllLoadCallback("server.dll", ExploitFixes::LoadCallback); - // run callbacks for any libraries that are already loaded by now CallAllPendingDLLLoadCallbacks(); diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp index 702141bb..f53f4b9e 100644 --- a/NorthstarDedicatedTest/filesystem.cpp +++ b/NorthstarDedicatedTest/filesystem.cpp @@ -34,7 +34,7 @@ bool readingOriginalFile; std::string currentModPath; SourceInterface<IFileSystem>* g_Filesystem; -void InitialiseFilesystem(HMODULE baseAddress) +ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (HMODULE baseAddress) { g_Filesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017"); @@ -46,7 +46,7 @@ void InitialiseFilesystem(HMODULE baseAddress) hook, (*g_Filesystem)->m_vtable->AddSearchPath, &AddSearchPathHook, reinterpret_cast<LPVOID*>(&addSearchPathOriginal)); ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x15F20, &ReadFileFromFilesystemHook, reinterpret_cast<LPVOID*>(&readFileFromFilesystem)); ENABLER_CREATEHOOK(hook, (*g_Filesystem)->m_vtable->MountVPK, &MountVPKHook, reinterpret_cast<LPVOID*>(&mountVPK)); -} +}) std::string ReadVPKFile(const char* path) { diff --git a/NorthstarDedicatedTest/filesystem.h b/NorthstarDedicatedTest/filesystem.h index 960c2836..803a2d23 100644 --- a/NorthstarDedicatedTest/filesystem.h +++ b/NorthstarDedicatedTest/filesystem.h @@ -70,5 +70,4 @@ class IFileSystem std::string ReadVPKFile(const char* path); std::string ReadVPKOriginalFile(const char* path); -void InitialiseFilesystem(HMODULE baseAddress); extern SourceInterface<IFileSystem>* g_Filesystem;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/hooks.cpp b/NorthstarDedicatedTest/hooks.cpp index cc99341a..5ced6046 100644 --- a/NorthstarDedicatedTest/hooks.cpp +++ b/NorthstarDedicatedTest/hooks.cpp @@ -4,6 +4,7 @@ #include "sigscanning.h" #include "dedicated.h" +#include <iostream> #include <wchar.h> #include <iostream> #include <vector> @@ -12,6 +13,8 @@ #include <filesystem> #include <Psapi.h> +namespace fs = std::filesystem; + typedef LPSTR (*GetCommandLineAType)(); LPSTR GetCommandLineAHook(); @@ -46,6 +49,34 @@ void InstallInitialHooks() ENABLER_CREATEHOOK(hook, &LoadLibraryW, &LoadLibraryWHook, reinterpret_cast<LPVOID*>(&LoadLibraryWOriginal)); } +// called from the ON_DLL_LOAD macros +__dllLoadCallback::__dllLoadCallback( + eDllLoadCallbackSide side, const std::string dllName, DllLoadCallbackFuncType callback, std::string uniqueStr, std::string reliesOn) +{ + spdlog::info("calling loadcallback {} for dll {}", uniqueStr, dllName); + + switch (side) + { + case eDllLoadCallbackSide::UNSIDED: + { + AddDllLoadCallback(dllName, callback, uniqueStr, reliesOn); + break; + } + + case eDllLoadCallbackSide::CLIENT: + { + AddDllLoadCallbackForClient(dllName, callback, uniqueStr, reliesOn); + break; + } + + case eDllLoadCallbackSide::DEDICATED_SERVER: + { + AddDllLoadCallbackForDedicatedServer(dllName, callback, uniqueStr, reliesOn); + break; + } + } +} + LPSTR GetCommandLineAHook() { static char* cmdlineModified; @@ -115,71 +146,117 @@ struct DllLoadCallback { std::string dll; DllLoadCallbackFuncType callback; + std::string tag; + std::string reliesOn; bool called; }; -std::vector<DllLoadCallback*> dllLoadCallbacks; +bool how = false; +std::vector<DllLoadCallback> dllLoadCallbacks = std::vector<DllLoadCallback>(); -void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback) +void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback, std::string tag, std::string reliesOn) { - DllLoadCallback* callbackStruct = new DllLoadCallback; - callbackStruct->dll = dll; - callbackStruct->callback = callback; - callbackStruct->called = false; + if (!how) // WHY IS THIS A THING WE NEED ON DEBUG????? + { + dllLoadCallbacks = std::vector<DllLoadCallback>(); + how = true; + } + + DllLoadCallback& callbackStruct = dllLoadCallbacks.emplace_back(); - dllLoadCallbacks.push_back(callbackStruct); + callbackStruct.dll = dll; + callbackStruct.callback = callback; + callbackStruct.tag = tag; + callbackStruct.reliesOn = reliesOn; + callbackStruct.called = false; } -void AddDllLoadCallbackForDedicatedServer(std::string dll, DllLoadCallbackFuncType callback) +void AddDllLoadCallbackForDedicatedServer( + std::string dll, DllLoadCallbackFuncType callback, std::string tag, std::string reliesOn) { if (!IsDedicated()) return; - DllLoadCallback* callbackStruct = new DllLoadCallback; - callbackStruct->dll = dll; - callbackStruct->callback = callback; - callbackStruct->called = false; - - dllLoadCallbacks.push_back(callbackStruct); + AddDllLoadCallback(dll, callback, tag, reliesOn); } -void AddDllLoadCallbackForClient(std::string dll, DllLoadCallbackFuncType callback) +void AddDllLoadCallbackForClient(std::string dll, DllLoadCallbackFuncType callback, std::string tag, std::string reliesOn) { if (IsDedicated()) return; - DllLoadCallback* callbackStruct = new DllLoadCallback; - callbackStruct->dll = dll; - callbackStruct->callback = callback; - callbackStruct->called = false; - - dllLoadCallbacks.push_back(callbackStruct); + AddDllLoadCallback(dll, callback, tag, reliesOn); } +std::vector<std::string> calledTags; + void CallLoadLibraryACallbacks(LPCSTR lpLibFileName, HMODULE moduleAddress) { - for (auto& callbackStruct : dllLoadCallbacks) + spdlog::info((char*)lpLibFileName); + + while (true) { - if (!callbackStruct->called && - strstr(lpLibFileName + (strlen(lpLibFileName) - callbackStruct->dll.length()), callbackStruct->dll.c_str()) != nullptr) + bool doneCalling = true; + + for (auto& callbackStruct : dllLoadCallbacks) { - callbackStruct->callback(moduleAddress); - callbackStruct->called = true; + spdlog::info("{} {}", callbackStruct.tag, callbackStruct.reliesOn); + + if (!callbackStruct.called && fs::path(lpLibFileName).filename() == fs::path(callbackStruct.dll).filename()) + { + //spdlog::info(callbackStruct.tag); + //spdlog::info(callbackStruct.reliesOn); + + if (callbackStruct.reliesOn != "" && + std::find(calledTags.begin(), calledTags.end(), callbackStruct.reliesOn) == calledTags.end()) + { + doneCalling = false; + continue; + } + + callbackStruct.callback(moduleAddress); + calledTags.push_back(callbackStruct.tag); + callbackStruct.called = true; + } } + + if (doneCalling) + break; } } void CallLoadLibraryWCallbacks(LPCWSTR lpLibFileName, HMODULE moduleAddress) { - for (auto& callbackStruct : dllLoadCallbacks) + spdlog::info((char*)lpLibFileName); + + while (true) { - std::wstring wcharStrDll = std::wstring(callbackStruct->dll.begin(), callbackStruct->dll.end()); - const wchar_t* callbackDll = wcharStrDll.c_str(); - if (!callbackStruct->called && wcsstr(lpLibFileName + (wcslen(lpLibFileName) - wcharStrDll.length()), callbackDll) != nullptr) + bool doneCalling = true; + + for (auto& callbackStruct : dllLoadCallbacks) { - callbackStruct->callback(moduleAddress); - callbackStruct->called = true; + spdlog::info("{} {}", callbackStruct.tag, callbackStruct.reliesOn); + + if (!callbackStruct.called && fs::path(lpLibFileName).filename() == fs::path(callbackStruct.dll).filename()) + { + //spdlog::info(callbackStruct.tag); + //spdlog::info(callbackStruct.reliesOn); + + if (callbackStruct.reliesOn != "" && + std::find(calledTags.begin(), calledTags.end(), callbackStruct.reliesOn) == calledTags.end()) + { + doneCalling = false; + continue; + } + + callbackStruct.callback(moduleAddress); + calledTags.push_back(callbackStruct.tag); + callbackStruct.called = true; + } } + + if (doneCalling) + break; } } diff --git a/NorthstarDedicatedTest/hooks.h b/NorthstarDedicatedTest/hooks.h index ab7b3d64..7f4eefbc 100644 --- a/NorthstarDedicatedTest/hooks.h +++ b/NorthstarDedicatedTest/hooks.h @@ -1,11 +1,48 @@ #pragma once #include <string> +#include <iostream> void InstallInitialHooks(); typedef void (*DllLoadCallbackFuncType)(HMODULE moduleAddress); -void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback); -void AddDllLoadCallbackForDedicatedServer(std::string dll, DllLoadCallbackFuncType callback); -void AddDllLoadCallbackForClient(std::string dll, DllLoadCallbackFuncType callback); +void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback, std::string tag = "", std::string reliesOn = ""); +void AddDllLoadCallbackForDedicatedServer( + std::string dll, DllLoadCallbackFuncType callback, std::string tag = "", std::string reliesOn = ""); +void AddDllLoadCallbackForClient(std::string dll, DllLoadCallbackFuncType callback, std::string tag = "", std::string reliesOn = ""); -void CallAllPendingDLLLoadCallbacks();
\ No newline at end of file +void CallAllPendingDLLLoadCallbacks(); + +// new dll load callback stuff +enum class eDllLoadCallbackSide +{ + UNSIDED, + CLIENT, + DEDICATED_SERVER +}; + +class __dllLoadCallback +{ + public: + __dllLoadCallback() = delete; + __dllLoadCallback( + eDllLoadCallbackSide side, + const std::string dllName, + DllLoadCallbackFuncType callback, + std::string uniqueStr, + std::string reliesOn); +}; + +#define CONCAT_(x, y, z) x##y##z +#define CONCAT(x, y, z) CONCAT_(x, y, z) +#define __STR(s) #s + +#define __ON_DLL_LOAD(dllName, func, side, counter, uniquestr, reliesOn) \ +void CONCAT(__callbackFunc, uniquestr, counter) func \ +__dllLoadCallback CONCAT(__dllLoadCallbackInstance, uniquestr, counter)(side, dllName, CONCAT(__callbackFunc, uniquestr, counter), __STR(uniquestr), reliesOn); + +#define ON_DLL_LOAD(dllName, uniquestr, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::UNSIDED, __LINE__, uniquestr, "") +#define ON_DLL_LOAD_RELIESON(dllName, uniquestr, reliesOn, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::UNSIDED, __LINE__, uniquestr, __STR(reliesOn)) +#define ON_DLL_LOAD_CLIENT(dllName, uniquestr, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::CLIENT, __LINE__, uniquestr, "") +#define ON_DLL_LOAD_CLIENT_RELIESON(dllName, uniquestr, reliesOn, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::CLIENT, __LINE__, uniquestr, __STR(reliesOn)) +#define ON_DLL_LOAD_DEDI(dllName, uniquestr, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::DEDICATED_SERVER, __LINE__, uniquestr, "") +#define ON_DLL_LOAD_DEDI_RELIESON(dllName, uniquestr, reliesOn, func) __ON_DLL_LOAD(dllName, func, eDllLoadCallbackSide::DEDICATED_SERVER, __LINE__, uniquestr, __STR(reliesOn))
\ No newline at end of file diff --git a/NorthstarDedicatedTest/keyvalues.cpp b/NorthstarDedicatedTest/keyvalues.cpp index 2063be62..880089a3 100644 --- a/NorthstarDedicatedTest/keyvalues.cpp +++ b/NorthstarDedicatedTest/keyvalues.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "keyvalues.h" #include "modmanager.h" +#include "hooks.h" #include "filesystem.h" #include "hookutils.h" @@ -13,24 +14,24 @@ KeyValues__LoadFromBufferType KeyValues__LoadFromBuffer; char KeyValues__LoadFromBufferHook( void* self, const char* resourceName, const char* pBuffer, void* pFileSystem, void* a5, void* a6, int a7); -void InitialiseKeyValues(HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", KeyValues, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK( hook, (char*)baseAddress + 0x426C30, &KeyValues__LoadFromBufferHook, reinterpret_cast<LPVOID*>(&KeyValues__LoadFromBuffer)); -} - -void* savedFilesystemPtr; +}) char KeyValues__LoadFromBufferHook(void* self, const char* resourceName, const char* pBuffer, void* pFileSystem, void* a5, void* a6, int a7) { + static void* pSavedFilesystemPtr = nullptr; + // 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 if (pFileSystem != nullptr) - savedFilesystemPtr = pFileSystem; + pSavedFilesystemPtr = pFileSystem; if (!pFileSystem && !strcmp(resourceName, "playlists")) - pFileSystem = savedFilesystemPtr; + pFileSystem = pSavedFilesystemPtr; return KeyValues__LoadFromBuffer(self, resourceName, pBuffer, pFileSystem, a5, a6, a7); } diff --git a/NorthstarDedicatedTest/languagehooks.cpp b/NorthstarDedicatedTest/languagehooks.cpp index c8d43901..1ca22d89 100644 --- a/NorthstarDedicatedTest/languagehooks.cpp +++ b/NorthstarDedicatedTest/languagehooks.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "languagehooks.h" #include "gameutils.h" #include <filesystem> @@ -112,8 +113,8 @@ char* GetGameLanguageHook() return lang; } -void InitialiseTier0LanguageHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("tier0.dll", LanguageHooks, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0xF560, &GetGameLanguageHook, reinterpret_cast<LPVOID*>(&GetGameLanguageOriginal)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/languagehooks.h b/NorthstarDedicatedTest/languagehooks.h index 55b591e0..7b9637ef 100644 --- a/NorthstarDedicatedTest/languagehooks.h +++ b/NorthstarDedicatedTest/languagehooks.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseTier0LanguageHooks(HMODULE baseAddress); +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/latencyflex.cpp b/NorthstarDedicatedTest/latencyflex.cpp index 4ac1c760..3ef9d21d 100644 --- a/NorthstarDedicatedTest/latencyflex.cpp +++ b/NorthstarDedicatedTest/latencyflex.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "latencyflex.h" #include "hookutils.h" #include "convar.h" @@ -20,7 +21,7 @@ void OnRenderStartHook() OnRenderStart(); } -void InitialiseLatencyFleX(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. @@ -41,4 +42,4 @@ void InitialiseLatencyFleX(HMODULE baseAddress) HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1952C0, &OnRenderStartHook, reinterpret_cast<LPVOID*>(&OnRenderStart)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/latencyflex.h b/NorthstarDedicatedTest/latencyflex.h index db801261..7b9637ef 100644 --- a/NorthstarDedicatedTest/latencyflex.h +++ b/NorthstarDedicatedTest/latencyflex.h @@ -1,2 +1 @@ -#pragma once -void InitialiseLatencyFleX(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/localchatwriter.cpp b/NorthstarDedicatedTest/localchatwriter.cpp index 72a5afa7..05d8be2e 100644 --- a/NorthstarDedicatedTest/localchatwriter.cpp +++ b/NorthstarDedicatedTest/localchatwriter.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "localchatwriter.h" class vgui_BaseRichText_vtable; @@ -436,7 +437,7 @@ void LocalChatWriter::InsertDefaultFade() } } -void InitialiseLocalChatWriter(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("client.dll", LocalChatWriter, (HMODULE baseAddress) { gGameSettings = (CGameSettings**)((char*)baseAddress + 0x11BAA48); gChatFadeLength = (CGameFloatVar**)((char*)baseAddress + 0x11BAB78); @@ -444,4 +445,4 @@ void InitialiseLocalChatWriter(HMODULE baseAddress) CHudChat::allHuds = (CHudChat**)((char*)baseAddress + 0x11BA9E8); ConvertANSIToUnicode = (ConvertANSIToUnicodeType)((char*)baseAddress + 0x7339A0); -} +}) diff --git a/NorthstarDedicatedTest/localchatwriter.h b/NorthstarDedicatedTest/localchatwriter.h index 8048e084..e9ab1efc 100644 --- a/NorthstarDedicatedTest/localchatwriter.h +++ b/NorthstarDedicatedTest/localchatwriter.h @@ -69,6 +69,4 @@ class LocalChatWriter const char* ApplyAnsiEscape(const char* escape); void InsertDefaultFade(); -}; - -void InitialiseLocalChatWriter(HMODULE baseAddress); +};
\ No newline at end of file diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index 5936007f..16b1e5b5 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "logging.h" +#include "hooks.h" #include "sourceconsole.h" #include "spdlog/sinks/basic_file_sink.h" #include "hookutils.h" @@ -407,7 +408,7 @@ bool CClientState_ProcessPrint_Hook(__int64 thisptr, __int64 msg) return true; } -void InitialiseEngineSpewFuncHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", EngineSpewFuncHooks, ConVar, (HMODULE baseAddress) { HookEnabler hook; @@ -424,7 +425,7 @@ void InitialiseEngineSpewFuncHooks(HMODULE baseAddress) reinterpret_cast<LPVOID*>(&CClientState_ProcessPrint_Original)); Cvar_spewlog_enable = new ConVar("spewlog_enable", "1", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged"); -} +}) #include "bitbuf.h" @@ -474,7 +475,7 @@ void TextMsgHook(BFRead* msg) } } -void InitialiseClientPrintHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientPrintHooks, ConVar, (HMODULE baseAddress) { HookEnabler hook; @@ -484,4 +485,4 @@ void InitialiseClientPrintHooks(HMODULE baseAddress) ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x198710, TextMsgHook, reinterpret_cast<LPVOID*>(&TextMsg_Original)); Cvar_cl_showtextmsg = new ConVar("cl_showtextmsg", "1", FCVAR_NONE, "Enable/disable text messages printing on the screen."); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/logging.h b/NorthstarDedicatedTest/logging.h index 2e78c81a..f9a287b5 100644 --- a/NorthstarDedicatedTest/logging.h +++ b/NorthstarDedicatedTest/logging.h @@ -2,6 +2,4 @@ #include "context.h" void CreateLogFiles(); -void InitialiseLogging(); -void InitialiseEngineSpewFuncHooks(HMODULE baseAddress); -void InitialiseClientPrintHooks(HMODULE baseAddress);
\ No newline at end of file +void InitialiseLogging();
\ No newline at end of file diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 38268e60..7767ea88 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "masterserver.h" +#include "hooks.h" #include "concommand.h" #include "gameutils.h" #include "hookutils.h" @@ -1239,6 +1240,8 @@ void ConCommand_ns_fetchservers(const CCommand& args) g_MasterServerManager->RequestServerList(); } +// todo: this should be somewhere else, not masterserver code + void CHostState__State_NewGameHook(CHostState* hostState) { Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode); @@ -1256,7 +1259,9 @@ void CHostState__State_NewGameHook(CHostState* hostState) Cbuf_Execute(); } + double dStartTime = Plat_FloatTime(); CHostState__State_NewGame(hostState); + spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime); int maxPlayers = 6; char* maxPlayersVar = GetCurrentPlaylistVar("max_players", false); @@ -1297,7 +1302,10 @@ void CHostState__State_ChangeLevelMPHook(CHostState* hostState) } g_MasterServerManager->UpdateServerMapAndPlaylist(hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers); + + double dStartTime = Plat_FloatTime(); CHostState__State_ChangeLevelMP(hostState); + spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime); } void CHostState__State_ChangeLevelSPHook(CHostState* hostState) @@ -1325,7 +1333,7 @@ void CHostState__State_GameShutdownHook(CHostState* hostState) MasterServerManager::MasterServerManager() : m_pendingConnectionInfo {}, m_ownServerId {""}, m_ownClientAuthToken {""} {} -void InitialiseSharedMasterServer(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", MasterServer, ConCommand, (HMODULE baseAddress) { Cvar_ns_masterserver_hostname = new ConVar("ns_masterserver_hostname", "127.0.0.1", FCVAR_NONE, ""); // unfortunately lib doesn't let us specify a port and still have https work @@ -1363,4 +1371,4 @@ void InitialiseSharedMasterServer(HMODULE baseAddress) (char*)baseAddress + 0x16E640, CHostState__State_GameShutdownHook, reinterpret_cast<LPVOID*>(&CHostState__State_GameShutdown)); -} +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index 10f91356..9f1818d5 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -126,7 +126,6 @@ class MasterServerManager }; std::string unescape_unicode(const std::string& str); void UpdateServerInfoFromUnicodeToUTF8(); -void InitialiseSharedMasterServer(HMODULE baseAddress); extern MasterServerManager* g_MasterServerManager; extern ConVar* Cvar_ns_masterserver_hostname; diff --git a/NorthstarDedicatedTest/miscclientfixes.cpp b/NorthstarDedicatedTest/miscclientfixes.cpp index 62ffd4a4..68f83550 100644 --- a/NorthstarDedicatedTest/miscclientfixes.cpp +++ b/NorthstarDedicatedTest/miscclientfixes.cpp @@ -1,12 +1,16 @@ #include "pch.h" +#include "hooks.h" #include "miscclientfixes.h" +#include "convar.h" #include "hookutils.h" -#include "dedicated.h" +#include "NSMem.h" typedef void* (*CrashingWeaponActivityFuncType)(void* a1); CrashingWeaponActivityFuncType CrashingWeaponActivityFunc0; CrashingWeaponActivityFuncType CrashingWeaponActivityFunc1; +ConVar* Cvar_ns_cl_move_always_send; + void* CrashingWeaponActivityFunc0Hook(void* a1) { // this return is safe, other functions that use this value seemingly dont care about it being null @@ -25,11 +29,8 @@ void* CrashingWeaponActivityFunc1Hook(void* a1) return CrashingWeaponActivityFunc1(a1); } -void InitialiseMiscClientFixes(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", MiscClientFixes, ConVar, (HMODULE baseAddress) { - if (IsDedicated()) - return; - HookEnabler hook; // these functions will occasionally pass a null pointer on respawn, unsure what causes this but seems easiest just to return null if @@ -46,4 +47,22 @@ void InitialiseMiscClientFixes(HMODULE baseAddress) void* ptr = (char*)baseAddress + 0x275F9D9; *((char*)ptr) = (char)0; } -}
\ No newline at end of file + + // allow demo recording on loopback + NSMem::NOP((uintptr_t)GetModuleHandleA("engine.dll") + 0x8E1B1, 2); + NSMem::NOP((uintptr_t)GetModuleHandleA("engine.dll") + 0x56CC3, 2); + + // 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 + ConVar* Cvar_demo_enableDemos = g_pCVar->FindVar("demo_enabledemos"); + Cvar_demo_enableDemos->m_pszDefaultValue = "1"; + Cvar_demo_enableDemos->SetValue(true); + + ConVar* Cvar_demo_writeLocalFile = g_pCVar->FindVar("demo_writeLocalFile"); + Cvar_demo_writeLocalFile->m_pszDefaultValue = "1"; + Cvar_demo_writeLocalFile->SetValue(true); + + ConVar* Cvar_demo_autoRecord = g_pCVar->FindVar("demo_autoRecord"); + Cvar_demo_autoRecord->m_pszDefaultValue = "0"; + Cvar_demo_autoRecord->SetValue(false); +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/miscclientfixes.h b/NorthstarDedicatedTest/miscclientfixes.h index 1f0ad807..7b9637ef 100644 --- a/NorthstarDedicatedTest/miscclientfixes.h +++ b/NorthstarDedicatedTest/miscclientfixes.h @@ -1,2 +1 @@ -#pragma once -void InitialiseMiscClientFixes(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/miscserverfixes.cpp b/NorthstarDedicatedTest/miscserverfixes.cpp index 30cd5777..94e56e5d 100644 --- a/NorthstarDedicatedTest/miscserverfixes.cpp +++ b/NorthstarDedicatedTest/miscserverfixes.cpp @@ -1,10 +1,11 @@ #include "pch.h" +#include "hooks.h" #include "miscserverfixes.h" #include "hookutils.h" #include "NSMem.h" -void InitialiseMiscServerFixes(HMODULE baseAddress) +ON_DLL_LOAD("server.dll", MiscServerFixes, (HMODULE baseAddress) { uintptr_t ba = (uintptr_t)baseAddress; @@ -23,6 +24,4 @@ void InitialiseMiscServerFixes(HMODULE baseAddress) { NSMem::BytePatch(ba + 0x153920, "C3"); } -} - -void InitialiseMiscEngineServerFixes(HMODULE baseAddress) {}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/miscserverfixes.h b/NorthstarDedicatedTest/miscserverfixes.h index d1c05a6b..e69de29b 100644 --- a/NorthstarDedicatedTest/miscserverfixes.h +++ b/NorthstarDedicatedTest/miscserverfixes.h @@ -1 +0,0 @@ -void InitialiseMiscServerFixes(HMODULE baseAddress);
\ No newline at end of file diff --git a/NorthstarDedicatedTest/miscserverscript.cpp b/NorthstarDedicatedTest/miscserverscript.cpp index b2bf52ec..f8884e7c 100644 --- a/NorthstarDedicatedTest/miscserverscript.cpp +++ b/NorthstarDedicatedTest/miscserverscript.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "miscserverscript.h" +#include "hooks.h" #include "squirrel.h" #include "masterserver.h" #include "serverauthentication.h" @@ -57,10 +58,10 @@ SQRESULT SQ_IsPlayerIndexLocalPlayer(void* sqvm) return SQRESULT_NOTNULL; } -void InitialiseMiscServerScriptCommand(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", MiscServerScriptCommands, ServerSquirrel, (HMODULE baseAddress) { g_ServerSquirrelManager->AddFuncRegistration( "void", "NSEarlyWritePlayerIndexPersistenceForLeave", "int playerIndex", "", SQ_EarlyWritePlayerIndexPersistenceForLeave); g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsWritingPlayerPersistence", "", "", SQ_IsWritingPlayerPersistence); g_ServerSquirrelManager->AddFuncRegistration("bool", "NSIsPlayerIndexLocalPlayer", "int playerIndex", "", SQ_IsPlayerIndexLocalPlayer); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/miscserverscript.h b/NorthstarDedicatedTest/miscserverscript.h index 8197e502..59c77ddc 100644 --- a/NorthstarDedicatedTest/miscserverscript.h +++ b/NorthstarDedicatedTest/miscserverscript.h @@ -1,2 +1 @@ -void InitialiseMiscServerScriptCommand(HMODULE baseAddress); void* GetPlayerByIndex(int playerIndex);
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modlocalisation.cpp b/NorthstarDedicatedTest/modlocalisation.cpp index a3c45e40..45f5a289 100644 --- a/NorthstarDedicatedTest/modlocalisation.cpp +++ b/NorthstarDedicatedTest/modlocalisation.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "modlocalisation.h" #include "hookutils.h" #include "modmanager.h" @@ -30,8 +31,8 @@ bool AddLocalisationFileHook(void* g_pVguiLocalize, const char* path, const char return ret; } -void InitialiseModLocalisation(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("localize.dll", Localize, (HMODULE baseAddress) { HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x6D80, AddLocalisationFileHook, reinterpret_cast<LPVOID*>(&AddLocalisationFile)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modlocalisation.h b/NorthstarDedicatedTest/modlocalisation.h index b7d9cd50..7b9637ef 100644 --- a/NorthstarDedicatedTest/modlocalisation.h +++ b/NorthstarDedicatedTest/modlocalisation.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseModLocalisation(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp index 50c7b371..f19e64d6 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "modmanager.h" +#include "hooks.h" #include "convar.h" #include "concommand.h" #include "audio.h" @@ -570,12 +571,12 @@ void ReloadModsCommand(const CCommand& args) g_ModManager->LoadMods(); } -void InitialiseModManager(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", ModManager, ConCommand, (HMODULE baseAddress) { g_ModManager = new ModManager; - RegisterConCommand("reload_mods", ReloadModsCommand, "idk", FCVAR_NONE); -} + RegisterConCommand("reload_mods", ReloadModsCommand, "reloads mods", FCVAR_NONE); +}) fs::path GetModFolderPath() { diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h index 798c2306..5c325d7c 100644 --- a/NorthstarDedicatedTest/modmanager.h +++ b/NorthstarDedicatedTest/modmanager.h @@ -142,7 +142,6 @@ class ModManager void BuildPdef(); }; -void InitialiseModManager(HMODULE baseAddress); fs::path GetModFolderPath(); fs::path GetCompiledAssetsPath(); diff --git a/NorthstarDedicatedTest/playlist.cpp b/NorthstarDedicatedTest/playlist.cpp index fdb23893..c1598825 100644 --- a/NorthstarDedicatedTest/playlist.cpp +++ b/NorthstarDedicatedTest/playlist.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "playlist.h" +#include "hooks.h" #include "concommand.h" #include "convar.h" #include "gameutils.h" @@ -72,7 +73,7 @@ int GetCurrentGamemodeMaxPlayersHook() } #include "NSMem.h" -void InitialisePlaylistHooks(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", PlaylistHooks, ConCommand, (HMODULE baseAddress) { RegisterConCommand("setplaylist", SetPlaylistCommand, "Sets the current playlist", FCVAR_NONE); RegisterConCommand("setplaylistvaroverrides", SetPlaylistVarOverrideCommand, "sets a playlist var override", FCVAR_NONE); @@ -103,4 +104,4 @@ void InitialisePlaylistHooks(HMODULE baseAddress) // patch to allow setplaylistvaroverride to be called before map init on dedicated and private match launched through the game NSMem::NOP(ba + 0x18ED17, 6); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/playlist.h b/NorthstarDedicatedTest/playlist.h index bf827ff4..7b9637ef 100644 --- a/NorthstarDedicatedTest/playlist.h +++ b/NorthstarDedicatedTest/playlist.h @@ -1,2 +1 @@ -#pragma once -void InitialisePlaylistHooks(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/rpakfilesystem.cpp b/NorthstarDedicatedTest/rpakfilesystem.cpp index d52f9ef1..c7bab5ee 100644 --- a/NorthstarDedicatedTest/rpakfilesystem.cpp +++ b/NorthstarDedicatedTest/rpakfilesystem.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "rpakfilesystem.h" +#include "hooks.h" #include "hookutils.h" #include "modmanager.h" #include "dedicated.h" @@ -119,36 +120,6 @@ void LoadCustomMapPaks(char** pakName, bool* bNeedToFreePakName) } } -LoadPakSyncType LoadPakSyncOriginal; -void* LoadPakSyncHook(char* path, void* unknownSingleton, int flags) -{ - HandlePakAliases(&path); - - bool bNeedToFreePakName = false; - - // note: we don't handle loading any preloaded custom paks synchronously since LoadPakSync is never actually called in retail, just load - // them async instead - static bool bShouldLoadPaks = true; - if (bShouldLoadPaks) - { - // disable preloading while we're doing this - bShouldLoadPaks = false; - - LoadPreloadPaks(); - LoadCustomMapPaks(&path, &bNeedToFreePakName); - - bShouldLoadPaks = true; - } - - spdlog::info("LoadPakSync {}", path); - void* ret = LoadPakSyncOriginal(path, unknownSingleton, flags); - - if (bNeedToFreePakName) - delete[] path; - - return ret; -} - LoadPakAsyncType LoadPakAsyncOriginal; int LoadPakAsyncHook(char* path, void* unknownSingleton, int flags, void* callback0, void* callback1) { @@ -159,6 +130,9 @@ int LoadPakAsyncHook(char* path, void* unknownSingleton, int flags, void* callba static bool bShouldLoadPaks = true; if (bShouldLoadPaks) { + // make a copy of the path for comparing to determine whether we should load this pak on dedi, before it could get overwritten by LoadCustomMapPaks + std::string originalPath(path); + // disable preloading while we're doing this bShouldLoadPaks = false; @@ -169,8 +143,11 @@ int LoadPakAsyncHook(char* path, void* unknownSingleton, int flags, void* callba // do this after custom paks load and in bShouldLoadPaks so we only ever call this on the root pakload call // todo: could probably add some way to flag custom paks to not be loaded on dedicated servers in rpak.json - if (IsDedicated() && strncmp(path, "common", 6)) // dedicated only needs common and common_mp - return -1; + if (IsDedicated() && strncmp(&originalPath[0], "common", 6)) // dedicated only needs common and common_mp + { + spdlog::info("Not loading pak {} for dedicated server", originalPath); + return -1; + } } int ret = LoadPakAsyncOriginal(path, unknownSingleton, flags, callback0, callback1); @@ -230,7 +207,7 @@ void* ReadFullFileFromDiskHook(const char* requestedPath, void* a2) return ret; } -void InitialiseEngineRpakFilesystem(HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", RpakFilesystem, (HMODULE baseAddress) { g_PakLoadManager = new PakLoadManager; @@ -238,9 +215,8 @@ void InitialiseEngineRpakFilesystem(HMODULE baseAddress) pUnknownPakLoadSingleton = (void**)((char*)baseAddress + 0x7C5E20); HookEnabler hook; - ENABLER_CREATEHOOK(hook, g_pakLoadApi->LoadPakSync, &LoadPakSyncHook, reinterpret_cast<LPVOID*>(&LoadPakSyncOriginal)); ENABLER_CREATEHOOK(hook, g_pakLoadApi->LoadPakAsync, &LoadPakAsyncHook, reinterpret_cast<LPVOID*>(&LoadPakAsyncOriginal)); ENABLER_CREATEHOOK(hook, g_pakLoadApi->UnloadPak, &UnloadPakHook, reinterpret_cast<LPVOID*>(&UnloadPakOriginal)); ENABLER_CREATEHOOK( hook, g_pakLoadApi->ReadFullFileFromDisk, &ReadFullFileFromDiskHook, reinterpret_cast<LPVOID*>(&ReadFullFileFromDiskOriginal)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/rpakfilesystem.h b/NorthstarDedicatedTest/rpakfilesystem.h index 3c104822..b711800e 100644 --- a/NorthstarDedicatedTest/rpakfilesystem.h +++ b/NorthstarDedicatedTest/rpakfilesystem.h @@ -1,7 +1,5 @@ #pragma once -void InitialiseEngineRpakFilesystem(HMODULE baseAddress); - class PakLoadManager { public: diff --git a/NorthstarDedicatedTest/scriptbrowserhooks.cpp b/NorthstarDedicatedTest/scriptbrowserhooks.cpp index d90bc998..d27c9e0e 100644 --- a/NorthstarDedicatedTest/scriptbrowserhooks.cpp +++ b/NorthstarDedicatedTest/scriptbrowserhooks.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "scriptbrowserhooks.h" #include "hookutils.h" @@ -17,11 +18,11 @@ void OpenExternalWebBrowserHook(char* url, char flags) *bIsOriginOverlayEnabled = bIsOriginOverlayEnabledOriginal; } -void InitialiseScriptExternalBrowserHooks(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT("engine.dll", ScriptExternalBrowserHooks, (HMODULE baseAddress) { bIsOriginOverlayEnabled = (bool*)baseAddress + 0x13978255; HookEnabler hook; ENABLER_CREATEHOOK( hook, (char*)baseAddress + 0x184E40, &OpenExternalWebBrowserHook, reinterpret_cast<LPVOID*>(&OpenExternalWebBrowser)); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptbrowserhooks.h b/NorthstarDedicatedTest/scriptbrowserhooks.h index 919cc92e..7b9637ef 100644 --- a/NorthstarDedicatedTest/scriptbrowserhooks.h +++ b/NorthstarDedicatedTest/scriptbrowserhooks.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseScriptExternalBrowserHooks(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmainmenupromos.cpp b/NorthstarDedicatedTest/scriptmainmenupromos.cpp index c63d58d3..0d425b65 100644 --- a/NorthstarDedicatedTest/scriptmainmenupromos.cpp +++ b/NorthstarDedicatedTest/scriptmainmenupromos.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "scriptmainmenupromos.h" #include "squirrel.h" #include "masterserver.h" @@ -128,9 +129,9 @@ SQRESULT SQ_GetCustomMainMenuPromoData(void* sqvm) return SQRESULT_NOTNULL; } -void InitialiseScriptMainMenuPromos(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptMainMenuPrograms, ClientSquirrel, (HMODULE baseAddress) { g_UISquirrelManager->AddFuncRegistration("void", "NSRequestCustomMainMenuPromos", "", "", SQ_RequestCustomMainMenuPromos); g_UISquirrelManager->AddFuncRegistration("bool", "NSHasCustomMainMenuPromoData", "", "", SQ_HasCustomMainMenuPromoData); g_UISquirrelManager->AddFuncRegistration("var", "NSGetCustomMainMenuPromoData", "int promoDataKey", "", SQ_GetCustomMainMenuPromoData); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmainmenupromos.h b/NorthstarDedicatedTest/scriptmainmenupromos.h index 2719e647..7b9637ef 100644 --- a/NorthstarDedicatedTest/scriptmainmenupromos.h +++ b/NorthstarDedicatedTest/scriptmainmenupromos.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseScriptMainMenuPromos(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index ca3cfed4..5332449e 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "scriptmodmenu.h" #include "modmanager.h" #include "squirrel.h" @@ -175,7 +176,7 @@ SQRESULT SQ_ReloadMods(void* sqvm) return SQRESULT_NULL; } -void InitialiseScriptModMenu(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, (HMODULE baseAddress) { g_UISquirrelManager->AddFuncRegistration("array<string>", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames); g_UISquirrelManager->AddFuncRegistration( @@ -200,4 +201,4 @@ void InitialiseScriptModMenu(HMODULE baseAddress) "array<string>", "NSGetModConvarsByModName", "string modName", "Returns the names of all a given mod's cvars", SQ_GetModConvars); g_UISquirrelManager->AddFuncRegistration("void", "NSReloadMods", "", "Reloads mods", SQ_ReloadMods); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmodmenu.h b/NorthstarDedicatedTest/scriptmodmenu.h index 019346d3..7b9637ef 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.h +++ b/NorthstarDedicatedTest/scriptmodmenu.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseScriptModMenu(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp index aec47c3b..64ffacfc 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.cpp +++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "scriptserverbrowser.h" #include "squirrel.h" #include "masterserver.h" @@ -407,7 +408,7 @@ SQRESULT SQ_CompleteAuthWithLocalServer(void* sqvm) return SQRESULT_NULL; } -void InitialiseScriptServerBrowser(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptServerBrowser, ClientSquirrel, (HMODULE baseAddress) { g_UISquirrelManager->AddFuncRegistration("bool", "NSIsMasterServerAuthenticated", "", "", SQ_IsMasterServerAuthenticated); g_UISquirrelManager->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList); @@ -438,4 +439,4 @@ void InitialiseScriptServerBrowser(HMODULE baseAddress) g_UISquirrelManager->AddFuncRegistration("void", "NSTryAuthWithLocalServer", "", "", SQ_TryAuthWithLocalServer); g_UISquirrelManager->AddFuncRegistration("void", "NSCompleteAuthWithLocalServer", "", "", SQ_CompleteAuthWithLocalServer); -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptserverbrowser.h b/NorthstarDedicatedTest/scriptserverbrowser.h index 55776de0..7b9637ef 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.h +++ b/NorthstarDedicatedTest/scriptserverbrowser.h @@ -1,4 +1 @@ -#pragma once -#include <minwindef.h> - -void InitialiseScriptServerBrowser(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp index 084db1e4..b73932ed 100644 --- a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp +++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "scriptservertoclientstringcommand.h" #include "squirrel.h" #include "convar.h" @@ -14,11 +15,11 @@ void ConCommand_ns_script_servertoclientstringcommand(const CCommand& arg) } } -void InitialiseScriptServerToClientStringCommands(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 diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.h b/NorthstarDedicatedTest/scriptservertoclientstringcommand.h index 609c6105..7b9637ef 100644 --- a/NorthstarDedicatedTest/scriptservertoclientstringcommand.h +++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.h @@ -1,3 +1 @@ -#pragma once - -void InitialiseScriptServerToClientStringCommands(HMODULE baseAddress);
\ No newline at end of file +#pragma once
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp index 91a12737..25a2f5f9 100644 --- a/NorthstarDedicatedTest/scriptsrson.cpp +++ b/NorthstarDedicatedTest/scriptsrson.cpp @@ -12,9 +12,6 @@ void ModManager::BuildScriptsRson() fs::path MOD_SCRIPTS_RSON_PATH = fs::path(GetCompiledAssetsPath() / MOD_SCRIPTS_RSON_SUFFIX); fs::remove(MOD_SCRIPTS_RSON_PATH); - // not really important since it doesn't affect actual functionality at all, but the rson we output is really weird - // has a shitload of newlines added, even in places where we don't modify it at all - std::string scriptsRson = ReadVPKOriginalFile(VPK_SCRIPTS_RSON_PATH); scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 19253fdb..b7360d2f 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "serverauthentication.h" +#include "hooks.h" #include "cvar.h" #include "convar.h" #include "hookutils.h" @@ -608,7 +609,7 @@ void ResetPdataCommand(const CCommand& args) g_ServerAuthenticationManager->m_bForceReadLocalPlayerPersistenceFromDisk = true; } -void InitialiseServerAuthentication(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("engine.dll", ServerAuthentication, ConCommand, (HMODULE baseAddress) { g_ServerAuthenticationManager = new ServerAuthenticationManager; @@ -703,4 +704,4 @@ void InitialiseServerAuthentication(HMODULE baseAddress) NSMem::NOP(addr + 10, 5); } -} +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h index 41e771b8..2cd0948b 100644 --- a/NorthstarDedicatedTest/serverauthentication.h +++ b/NorthstarDedicatedTest/serverauthentication.h @@ -104,7 +104,5 @@ class ServerAuthenticationManager typedef void (*CBaseClient__DisconnectType)(void* self, uint32_t unknownButAlways1, const char* reason, ...); extern CBaseClient__DisconnectType CBaseClient__Disconnect; -void InitialiseServerAuthentication(HMODULE baseAddress); - extern ServerAuthenticationManager* g_ServerAuthenticationManager; extern ConVar* Cvar_ns_player_auth_port;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/serverchathooks.cpp b/NorthstarDedicatedTest/serverchathooks.cpp index 985d3d1b..ad037a5f 100644 --- a/NorthstarDedicatedTest/serverchathooks.cpp +++ b/NorthstarDedicatedTest/serverchathooks.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "serverchathooks.h" +#include "hooks.h" #include <rapidjson/document.h> #include <rapidjson/stringbuffer.h> #include <rapidjson/writer.h> @@ -170,12 +171,12 @@ SQRESULT SQ_BroadcastMessage(void* sqvm) return SQRESULT_NULL; } -void InitialiseServerChatHooks_Engine(HMODULE baseAddress) +ON_DLL_LOAD("engine.dll", EngineServerChatHooks, (HMODULE baseAddress) { g_pServerGameDLL = (CServerGameDLL*)((char*)baseAddress + 0x13F0AA98); -} +}) -void InitialiseServerChatHooks_Server(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", ServerChatHooks, ServerSquirrel, (HMODULE baseAddress) { CServerGameDLL__OnReceivedSayTextMessage = (CServerGameDLL__OnReceivedSayTextMessageType)((char*)baseAddress + 0x1595C0); UTIL_PlayerByIndex = (UTIL_PlayerByIndexType)((char*)baseAddress + 0x26AA10); @@ -206,4 +207,4 @@ void InitialiseServerChatHooks_Server(HMODULE baseAddress) "int fromPlayerIndex, int toPlayerIndex, string text, bool isTeam, bool isDead, int messageType", "", SQ_BroadcastMessage); -} +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/serverchathooks.h b/NorthstarDedicatedTest/serverchathooks.h index f3425ae6..04262d83 100644 --- a/NorthstarDedicatedTest/serverchathooks.h +++ b/NorthstarDedicatedTest/serverchathooks.h @@ -22,8 +22,4 @@ void ChatSendMessage(unsigned int playerIndex, const char* text, bool isteam); // isDead: display a [DEAD] badge // messageType: send a specific message type void ChatBroadcastMessage( - int fromPlayerIndex, int toPlayerIndex, const char* text, bool isTeam, bool isDead, CustomMessageType messageType); - -void InitialiseServerChatHooks_Engine(HMODULE baseAddress); - -void InitialiseServerChatHooks_Server(HMODULE baseAddress); + int fromPlayerIndex, int toPlayerIndex, const char* text, bool isTeam, bool isDead, CustomMessageType messageType);
\ No newline at end of file diff --git a/NorthstarDedicatedTest/sourceconsole.cpp b/NorthstarDedicatedTest/sourceconsole.cpp index a6d54989..ed986af8 100644 --- a/NorthstarDedicatedTest/sourceconsole.cpp +++ b/NorthstarDedicatedTest/sourceconsole.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "hooks.h" #include "convar.h" #include "sourceconsole.h" #include "sourceinterface.h" @@ -47,11 +48,11 @@ void InitialiseConsoleOnInterfaceCreation() reinterpret_cast<LPVOID*>(&onCommandSubmittedOriginal)); } -void InitialiseSourceConsole(HMODULE baseAddress) +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, (HMODULE baseAddress) { g_SourceGameConsole = new SourceInterface<CGameConsole>("client.dll", "GameConsole004"); RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "toggles the console", FCVAR_DONTRECORD); -} +}) // logging stuff diff --git a/NorthstarDedicatedTest/sourceconsole.h b/NorthstarDedicatedTest/sourceconsole.h index cf65cbd3..dc45d5b1 100644 --- a/NorthstarDedicatedTest/sourceconsole.h +++ b/NorthstarDedicatedTest/sourceconsole.h @@ -102,5 +102,4 @@ class SourceConsoleSink : public spdlog::sinks::base_sink<std::mutex> void flush_() override; }; -void InitialiseSourceConsole(HMODULE baseAddress); void InitialiseConsoleOnInterfaceCreation();
\ No newline at end of file diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 84caa389..835e4bd9 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -93,12 +93,7 @@ SquirrelManager<ScriptContext::CLIENT>* g_ClientSquirrelManager; SquirrelManager<ScriptContext::SERVER>* g_ServerSquirrelManager; SquirrelManager<ScriptContext::UI>* g_UISquirrelManager; -SQInteger NSTestFunc(void* sqvm) -{ - return 1; -} - -void InitialiseClientSquirrel(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (HMODULE baseAddress) { HookEnabler hook; @@ -162,9 +157,9 @@ void InitialiseClientSquirrel(HMODULE baseAddress) (char*)baseAddress + 0x10190, &CallScriptInitCallbackHook<ScriptContext::CLIENT>, reinterpret_cast<LPVOID*>(&ClientCallScriptInitCallback)); // client callscriptinitcallback function -} +}) -void InitialiseServerSquirrel(HMODULE baseAddress) +ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (HMODULE baseAddress) { g_ServerSquirrelManager = new SquirrelManager<ScriptContext::SERVER>(); @@ -224,7 +219,7 @@ void InitialiseServerSquirrel(HMODULE baseAddress) ExecuteCodeCommand<ScriptContext::SERVER>, "Executes script code on the server vm", FCVAR_GAMEDLL | FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_CHEAT); -} +}) // hooks template <ScriptContext context> SQInteger SQPrintHook(void* sqvm, char* fmt, ...) diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index cc39cc2a..dc99ac04 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -1,8 +1,5 @@ #pragma once -void InitialiseClientSquirrel(HMODULE baseAddress); -void InitialiseServerSquirrel(HMODULE baseAddress); - // stolen from ttf2sdk: sqvm types typedef float SQFloat; typedef long SQInteger; |