From 4f7c3d02943a38941b79a638c5607b2b7f668956 Mon Sep 17 00:00:00 2001 From: p0358 Date: Thu, 30 Dec 2021 06:26:10 +0100 Subject: actually use custom allocation, override allocators of curl and rapidjson --- NorthstarDedicatedTest/memalloc.h | 40 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'NorthstarDedicatedTest/memalloc.h') diff --git a/NorthstarDedicatedTest/memalloc.h b/NorthstarDedicatedTest/memalloc.h index fe3c5255..d9277694 100644 --- a/NorthstarDedicatedTest/memalloc.h +++ b/NorthstarDedicatedTest/memalloc.h @@ -1,6 +1,44 @@ #pragma once +#include "include/rapidjson/document.h" +//#include "include/rapidjson/allocators.h" + extern size_t g_iStaticAllocated; +extern "C" { + char* _strdup_base(const char* src); +} + void* operator new(size_t n); -void operator delete(void* p); \ No newline at end of file +void operator delete(void* p); + +void* _malloc_base(size_t n); +//void* malloc(size_t n); + +class SourceAllocator { +public: + static const bool kNeedFree = true; + void* Malloc(size_t size) { + if (size) // behavior of malloc(0) is implementation defined. + return _malloc_base(size); + else + return NULL; // standardize to returning NULL. + } + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { + (void)originalSize; + if (newSize == 0) { + _free_base(originalPtr); + return NULL; + } + return _realloc_base(originalPtr, newSize); + } + static void Free(void* ptr) { _free_base(ptr); } +}; + +extern SourceAllocator* g_SourceAllocator; + +typedef rapidjson::GenericDocument, rapidjson::MemoryPoolAllocator, SourceAllocator> rapidjson_document; +//typedef rapidjson::GenericDocument, SourceAllocator, SourceAllocator> rapidjson_document; +//typedef rapidjson::Document rapidjson_document; +//using MyDocument = rapidjson::GenericDocument, MemoryAllocator>; +//using rapidjson_document = rapidjson::GenericDocument, SourceAllocator, SourceAllocator>; -- cgit v1.2.3 From 32b1257cd62ee6ec7f1087355a2d9e181429d165 Mon Sep 17 00:00:00 2001 From: geni Date: Fri, 31 Dec 2021 14:44:15 +0200 Subject: Remove linear allocator --- LauncherInjector/main.cpp | 22 +++++------ NorthstarDedicatedTest/dllmain.cpp | 6 +-- NorthstarDedicatedTest/gameutils.cpp | 2 - NorthstarDedicatedTest/memalloc.cpp | 75 ++++++++---------------------------- NorthstarDedicatedTest/memalloc.h | 12 +++--- 5 files changed, 35 insertions(+), 82 deletions(-) (limited to 'NorthstarDedicatedTest/memalloc.h') diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp index f35a3015..761f443e 100644 --- a/LauncherInjector/main.cpp +++ b/LauncherInjector/main.cpp @@ -192,6 +192,15 @@ int main(int argc, char* argv[]) { PrependPath(); + printf("[*] Loading tier0.dll\n"); + swprintf_s(buffer, L"%s\\bin\\x64_retail\\tier0.dll", exePath); + hTier0Module = LoadLibraryExW(buffer, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!hTier0Module) + { + LibraryLoadError(GetLastError(), L"tier0.dll", buffer); + return 1; + } + bool loadNorthstar = ShouldLoadNorthstar(argc, argv); if (loadNorthstar) { @@ -204,23 +213,12 @@ int main(int argc, char* argv[]) { printf("[*] Loading launcher.dll\n"); swprintf_s(buffer, L"%s\\bin\\x64_retail\\launcher.dll", exePath); - hLauncherModule = LoadLibraryExW(buffer, 0i64, 8u); + hLauncherModule = LoadLibraryExW(buffer, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (!hLauncherModule) { LibraryLoadError(GetLastError(), L"launcher.dll", buffer); return 1; } - - printf("[*] Loading tier0.dll\n"); - // this makes zero sense given tier0.dll is already loaded via imports on launcher.dll, but we do it for full consistency with original launcher exe - // and to also let load callbacks in Northstar work for tier0.dll - swprintf_s(buffer, L"%s\\bin\\x64_retail\\tier0.dll", exePath); - hTier0Module = LoadLibraryW(buffer); - if (!hTier0Module) - { - LibraryLoadError(GetLastError(), L"tier0.dll", buffer); - return 1; - } } printf("[*] Launching the game...\n"); diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 4f8a445c..07741801 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -58,7 +58,6 @@ void WaitForDebugger(HMODULE baseAddress) if (strstr(GetCommandLineA(), "-waitfordebugger")) { spdlog::info("waiting for debugger..."); - spdlog::info("{} bytes have been statically allocated", g_iStaticAllocated); while (!IsDebuggerPresent()) Sleep(100); @@ -71,7 +70,7 @@ bool InitialiseNorthstar() { if (initialised) { - fprintf(stderr, "[info] Called InitialiseNorthstar more than once!\n"); + spdlog::warn("Called InitialiseNorthstar more than once!"); return false; } initialised = true; @@ -85,7 +84,6 @@ bool InitialiseNorthstar() g_SourceAllocator = new SourceAllocator; curl_global_init(CURL_GLOBAL_DEFAULT); - AddDllLoadCallback("tier0.dll", InitialiseTier0GameUtilFunctions); AddDllLoadCallback("engine.dll", WaitForDebugger); AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions); @@ -93,8 +91,8 @@ bool InitialiseNorthstar() // dedi patches { + AddDllLoadCallback("launcher.dll", InitialiseDedicatedOrigin); AddDllLoadCallback("engine.dll", InitialiseDedicated); - AddDllLoadCallback("tier0.dll", InitialiseDedicatedOrigin); AddDllLoadCallback("server.dll", InitialiseDedicatedServerGameDLL); AddDllLoadCallback("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 diff --git a/NorthstarDedicatedTest/gameutils.cpp b/NorthstarDedicatedTest/gameutils.cpp index 3e62037c..b2c88e49 100644 --- a/NorthstarDedicatedTest/gameutils.cpp +++ b/NorthstarDedicatedTest/gameutils.cpp @@ -94,8 +94,6 @@ void InitialiseTier0GameUtilFunctions(HMODULE baseAddress) else { g_pMemAllocSingleton = *ppMemAllocSingleton; - extern size_t g_iStaticAllocated; - spdlog::info("Using existing g_pMemAllocSingleton for memory allocations, preallocated {} bytes beforehand", g_iStaticAllocated); } Error = reinterpret_cast(GetProcAddress(baseAddress, "Error")); diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp index c1fb70e7..c9cf4d60 100644 --- a/NorthstarDedicatedTest/memalloc.cpp +++ b/NorthstarDedicatedTest/memalloc.cpp @@ -2,43 +2,16 @@ #include "memalloc.h" #include "gameutils.h" -// so for anyone reading this code, you may be curious why the fuck i'm overriding new to alloc into a static 100k buffer -// pretty much, the issue here is that we need to use the game's memory allocator (g_pMemAllocSingleton) or risk heap corruptions, but this allocator is defined in tier0 -// as such, it doesn't exist when we inject -// initially i wanted to just call malloc and free until g_pMemAllocSingleton was initialised, but the issue then becomes that we might try to -// call g_pMemAllocSingleton->Free on memory that was allocated with malloc, which will cause game to crash -// so, the best idea i had for this was to just alloc 100k of memory, have all pre-tier0 allocations use that -// (from what i can tell we hit about 12k before tier0 is loaded atm in debug builds, so it's more than enough) -// then just use the game's allocator after that -// yes, this means we leak 100k of memory, idk how else to do this without breaking stuff - -const int STATIC_ALLOC_SIZE = 100000; // alot more than we need, could reduce to 50k or even 25k later potentially - -size_t g_iStaticAllocated = 0; -void* g_pLastAllocated = nullptr; -char pStaticAllocBuf[STATIC_ALLOC_SIZE]; - // TODO: rename to malloc and free after removing statically compiled .libs extern "C" void* _malloc_base(size_t n) { // allocate into static buffer if g_pMemAllocSingleton isn't initialised - if (g_pMemAllocSingleton) - { - //printf("Northstar malloc (g_pMemAllocSingleton): %llu\n", n); - return g_pMemAllocSingleton->m_vtable->Alloc(g_pMemAllocSingleton, n); - } - else + if (!g_pMemAllocSingleton) { - if (g_iStaticAllocated + n > STATIC_ALLOC_SIZE) - { - throw "Ran out of prealloc space"; // we could log, but spdlog probably does use allocations as well... - } - //printf("Northstar malloc (prealloc): %llu\n", n); - void* ret = pStaticAllocBuf + g_iStaticAllocated; - g_iStaticAllocated += n; - return ret; + InitialiseTier0GameUtilFunctions(GetModuleHandleA("tier0.dll")); } + return g_pMemAllocSingleton->m_vtable->Alloc(g_pMemAllocSingleton, n); } /*extern "C" void* malloc(size_t n) @@ -48,44 +21,30 @@ extern "C" void* _malloc_base(size_t n) extern "C" void _free_base(void* p) { - // if it was allocated into the static buffer, just do nothing, safest way to deal with it - if (p >= pStaticAllocBuf && p <= pStaticAllocBuf + STATIC_ALLOC_SIZE) + if (!g_pMemAllocSingleton) { - //printf("Northstar free (prealloc): %p\n", p); - return; + InitialiseTier0GameUtilFunctions(GetModuleHandleA("tier0.dll")); } - - //printf("Northstar free (g_pMemAllocSingleton): %p\n", p); g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p); } -extern "C" void* _realloc_base(void* old_ptr, size_t size) { - // it was allocated into the static buffer - if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE) + +extern "C" void* _realloc_base(void* oldPtr, size_t size) { + if (!g_pMemAllocSingleton) { - if (g_pLastAllocated == old_ptr) - { - // nothing was allocated after this - size_t old_size = g_iStaticAllocated - ((size_t)g_pLastAllocated - (size_t)pStaticAllocBuf); - size_t diff = size - old_size; - if (diff > 0) - g_iStaticAllocated += diff; - return old_ptr; - } - else - { - return _malloc_base(size); - } + InitialiseTier0GameUtilFunctions(GetModuleHandleA("tier0.dll")); } - - if (g_pMemAllocSingleton) - return g_pMemAllocSingleton->m_vtable->Realloc(g_pMemAllocSingleton, old_ptr, size); - return nullptr; + return g_pMemAllocSingleton->m_vtable->Realloc(g_pMemAllocSingleton, oldPtr, size); } extern "C" void* _calloc_base(size_t n, size_t size) { - return _malloc_base(n * size); + size_t bytes = n * size; + void* memory = _malloc_base(bytes); + if (memory) { + memset(memory, 0, bytes); + } + return memory; } extern "C" char* _strdup_base(const char* src) @@ -96,7 +55,7 @@ extern "C" char* _strdup_base(const char* src) while (src[len]) len++; - str = reinterpret_cast(_malloc_base(len + 1)); + str = (char*)(_malloc_base(len + 1)); p = str; while (*src) *p++ = *src++; diff --git a/NorthstarDedicatedTest/memalloc.h b/NorthstarDedicatedTest/memalloc.h index d9277694..86d2ff58 100644 --- a/NorthstarDedicatedTest/memalloc.h +++ b/NorthstarDedicatedTest/memalloc.h @@ -3,16 +3,16 @@ #include "include/rapidjson/document.h" //#include "include/rapidjson/allocators.h" -extern size_t g_iStaticAllocated; - -extern "C" { - char* _strdup_base(const char* src); -} +extern "C" void* _malloc_base(size_t size); +extern "C" void* _calloc_base(size_t const count, size_t const size); +extern "C" void* _realloc_base(void* block, size_t size); +extern "C" void* _recalloc_base(void* const block, size_t const count, size_t const size); +extern "C" void _free_base(void* const block); +extern "C" char* _strdup_base(const char* src); void* operator new(size_t n); void operator delete(void* p); -void* _malloc_base(size_t n); //void* malloc(size_t n); class SourceAllocator { -- cgit v1.2.3 From d658c0c8374f8491e062fabe031f79185169c414 Mon Sep 17 00:00:00 2001 From: geni Date: Fri, 31 Dec 2021 16:07:09 +0200 Subject: Clean up --- LauncherInjector/LauncherInjector.vcxproj | 1 - LauncherInjector/LauncherInjector.vcxproj.filters | 3 --- NorthstarDedicatedTest/dllmain.cpp | 7 ++----- NorthstarDedicatedTest/memalloc.h | 2 +- 4 files changed, 3 insertions(+), 10 deletions(-) (limited to 'NorthstarDedicatedTest/memalloc.h') diff --git a/LauncherInjector/LauncherInjector.vcxproj b/LauncherInjector/LauncherInjector.vcxproj index 30fa690e..8870c732 100644 --- a/LauncherInjector/LauncherInjector.vcxproj +++ b/LauncherInjector/LauncherInjector.vcxproj @@ -90,7 +90,6 @@ - diff --git a/LauncherInjector/LauncherInjector.vcxproj.filters b/LauncherInjector/LauncherInjector.vcxproj.filters index 449381ca..87e25fa8 100644 --- a/LauncherInjector/LauncherInjector.vcxproj.filters +++ b/LauncherInjector/LauncherInjector.vcxproj.filters @@ -23,9 +23,6 @@ Header Files - - Header Files - diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 07741801..81bae847 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -64,8 +64,6 @@ void WaitForDebugger(HMODULE baseAddress) } } -SourceAllocator* g_SourceAllocator; - bool InitialiseNorthstar() { if (initialised) @@ -75,15 +73,14 @@ bool InitialiseNorthstar() } initialised = true; + curl_global_init(CURL_GLOBAL_DEFAULT); + InitialiseLogging(); // apply initial hooks InstallInitialHooks(); InitialiseInterfaceCreationHooks(); - g_SourceAllocator = new SourceAllocator; - curl_global_init(CURL_GLOBAL_DEFAULT); - AddDllLoadCallback("engine.dll", WaitForDebugger); AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions); diff --git a/NorthstarDedicatedTest/memalloc.h b/NorthstarDedicatedTest/memalloc.h index 86d2ff58..b98fe3c8 100644 --- a/NorthstarDedicatedTest/memalloc.h +++ b/NorthstarDedicatedTest/memalloc.h @@ -35,7 +35,7 @@ public: static void Free(void* ptr) { _free_base(ptr); } }; -extern SourceAllocator* g_SourceAllocator; +static SourceAllocator g_SourceAllocator; typedef rapidjson::GenericDocument, rapidjson::MemoryPoolAllocator, SourceAllocator> rapidjson_document; //typedef rapidjson::GenericDocument, SourceAllocator, SourceAllocator> rapidjson_document; -- cgit v1.2.3 From 9b13df7bc6f4c09c3fdab27cd51fe76d30b756b8 Mon Sep 17 00:00:00 2001 From: p0358 Date: Fri, 31 Dec 2021 22:46:45 +0100 Subject: some post-merge changes combined with my local changes --- LauncherInjector/main.cpp | 6 +++--- NorthstarDedicatedTest/dedicated.cpp | 2 +- NorthstarDedicatedTest/dllmain.cpp | 16 ++++++---------- NorthstarDedicatedTest/gameutils.cpp | 9 ++++++++- NorthstarDedicatedTest/hooks.cpp | 26 ++++++++++++++++++++++++-- NorthstarDedicatedTest/hooks.h | 4 +++- NorthstarDedicatedTest/masterserver.cpp | 4 ++-- NorthstarDedicatedTest/memalloc.cpp | 6 ++++-- NorthstarDedicatedTest/memalloc.h | 2 -- 9 files changed, 51 insertions(+), 24 deletions(-) (limited to 'NorthstarDedicatedTest/memalloc.h') diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp index 761f443e..0f70fd4b 100644 --- a/LauncherInjector/main.cpp +++ b/LauncherInjector/main.cpp @@ -81,7 +81,7 @@ void EnsureOriginStarted() HKEY key; if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Origin", 0, KEY_READ, &key) != ERROR_SUCCESS) { - MessageBoxA(0, "Error: failed reading origin path!", "", MB_OK); + MessageBoxA(0, "Error: failed reading Origin path!", "", MB_OK); return; } @@ -89,7 +89,7 @@ void EnsureOriginStarted() DWORD originPathLength = 520; if (RegQueryValueExA(key, "ClientPath", 0, 0, (LPBYTE)&originPath, &originPathLength) != ERROR_SUCCESS) { - MessageBoxA(0, "Error: failed reading origin path!", "", MB_OK); + MessageBoxA(0, "Error: failed reading Origin path!", "", MB_OK); return; } @@ -122,7 +122,7 @@ void PrependPath() { MessageBoxW(GetForegroundWindow(), L"Warning: could not prepend the current directory to app's PATH environment variable. Something may break because of that.", L"Northstar Launcher Warning", 0); } - //free(pPath); + free(pPath); } else { diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 0ecc1dba..8dedcdd9 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -394,7 +394,7 @@ void InitialiseDedicatedOrigin(HMODULE baseAddress) char* ptr = (char*)GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin"); TempReadWrite rw(ptr); - *ptr = (char)0xC3; + *ptr = (char)0xC3; // ret } typedef void(*PrintFatalSquirrelErrorType)(void* sqvm); diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 81bae847..87fb4d5f 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -43,11 +43,6 @@ BOOL APIENTRY DllMain( HMODULE hModule, break; } - // pls no xD - //if (!initialised) - // InitialiseNorthstar(); - //initialised = true; - return TRUE; } @@ -71,9 +66,10 @@ bool InitialiseNorthstar() spdlog::warn("Called InitialiseNorthstar more than once!"); return false; } + initialised = true; - curl_global_init(CURL_GLOBAL_DEFAULT); + curl_global_init_mem(CURL_GLOBAL_DEFAULT, _malloc_base, _free_base, _realloc_base, _strdup_base, _calloc_base); InitialiseLogging(); @@ -81,6 +77,7 @@ bool InitialiseNorthstar() InstallInitialHooks(); InitialiseInterfaceCreationHooks(); + AddDllLoadCallback("tier0.dll", InitialiseTier0GameUtilFunctions); AddDllLoadCallback("engine.dll", WaitForDebugger); AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions); @@ -88,7 +85,7 @@ bool InitialiseNorthstar() // dedi patches { - AddDllLoadCallback("launcher.dll", InitialiseDedicatedOrigin); + AddDllLoadCallback("tier0.dll", InitialiseDedicatedOrigin); AddDllLoadCallback("engine.dll", InitialiseDedicated); AddDllLoadCallback("server.dll", InitialiseDedicatedServerGameDLL); AddDllLoadCallback("materialsystem_dx11.dll", InitialiseDedicatedMaterialSystem); @@ -128,9 +125,8 @@ bool InitialiseNorthstar() // mod manager after everything else AddDllLoadCallback("engine.dll", InitialiseModManager); - // TODO: If you wanna make it more flexible and for example injectable with old Icepick injector - // in this place you should iterate over all already loaded DLLs and execute their callbacks and mark them as executed - // (as they will never get called otherwise and stuff will fail) + // run callbacks for any libraries that are already loaded by now + CallAllPendingDLLLoadCallbacks(); return true; } \ No newline at end of file diff --git a/NorthstarDedicatedTest/gameutils.cpp b/NorthstarDedicatedTest/gameutils.cpp index b2c88e49..1cbd8648 100644 --- a/NorthstarDedicatedTest/gameutils.cpp +++ b/NorthstarDedicatedTest/gameutils.cpp @@ -78,6 +78,13 @@ void InitialiseServerGameUtilFunctions(HMODULE baseAddress) void InitialiseTier0GameUtilFunctions(HMODULE baseAddress) { + if (!baseAddress) + { + spdlog::critical("tier0 base address is null, but it should be already loaded"); + throw "tier0 base address is null, but it should be already loaded"; + } + if (g_pMemAllocSingleton) + return; // seems this function was already called CreateGlobalMemAlloc = reinterpret_cast(GetProcAddress(baseAddress, "CreateGlobalMemAlloc")); IMemAlloc** ppMemAllocSingleton = reinterpret_cast(GetProcAddress(baseAddress, "g_pMemAllocSingleton")); if (!ppMemAllocSingleton) @@ -89,7 +96,7 @@ void InitialiseTier0GameUtilFunctions(HMODULE baseAddress) { g_pMemAllocSingleton = CreateGlobalMemAlloc(); *ppMemAllocSingleton = g_pMemAllocSingleton; - spdlog::warn("Created new g_pMemAllocSingleton"); + spdlog::info("Created new g_pMemAllocSingleton"); } else { diff --git a/NorthstarDedicatedTest/hooks.cpp b/NorthstarDedicatedTest/hooks.cpp index 19010e83..0e653d4e 100644 --- a/NorthstarDedicatedTest/hooks.cpp +++ b/NorthstarDedicatedTest/hooks.cpp @@ -8,12 +8,11 @@ #include #include #include +#include typedef LPSTR(*GetCommandLineAType)(); LPSTR GetCommandLineAHook(); -// note that these load library callbacks only support explicitly loaded dynamic libraries - typedef HMODULE(*LoadLibraryExAType)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); HMODULE LoadLibraryExAHook(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); @@ -138,6 +137,29 @@ void CallLoadLibraryWCallbacks(LPCWSTR lpLibFileName, HMODULE moduleAddress) } } +void CallAllPendingDLLLoadCallbacks() +{ + HMODULE hMods[1024]; + HANDLE hProcess = GetCurrentProcess(); + DWORD cbNeeded; + unsigned int i; + + // Get a list of all the modules in this process. + if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) + { + for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) + { + wchar_t szModName[MAX_PATH]; + + // Get the full path to the module's file. + if (GetModuleFileNameExW(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) + { + CallLoadLibraryWCallbacks(szModName, hMods[i]); + } + } + } +} + HMODULE LoadLibraryExAHook(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) { HMODULE moduleAddress = LoadLibraryExAOriginal(lpLibFileName, hFile, dwFlags); diff --git a/NorthstarDedicatedTest/hooks.h b/NorthstarDedicatedTest/hooks.h index 972b38a6..10e4d4ba 100644 --- a/NorthstarDedicatedTest/hooks.h +++ b/NorthstarDedicatedTest/hooks.h @@ -4,4 +4,6 @@ void InstallInitialHooks(); typedef void(*DllLoadCallbackFuncType)(HMODULE moduleAddress); -void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback); \ No newline at end of file +void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback); + +void CallAllPendingDLLLoadCallbacks(); \ No newline at end of file diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 2fec6c82..e25be8ab 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -1022,9 +1022,9 @@ void CHostState__State_GameShutdownHook(CHostState* hostState) CHostState__State_GameShutdown(hostState); } -MasterServerManager::MasterServerManager() +MasterServerManager::MasterServerManager() : m_pendingConnectionInfo{}, m_ownServerId{ "" }, m_ownClientAuthToken{ "" } { - curl_global_init_mem(CURL_GLOBAL_DEFAULT, _malloc_base, _free_base, _realloc_base, _strdup_base, _calloc_base); + } void InitialiseSharedMasterServer(HMODULE baseAddress) diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp index 86215e3f..1b9eaae8 100644 --- a/NorthstarDedicatedTest/memalloc.cpp +++ b/NorthstarDedicatedTest/memalloc.cpp @@ -23,13 +23,15 @@ extern "C" void _free_base(void* p) { if (!g_pMemAllocSingleton) { + spdlog::warn("Trying to free something before g_pMemAllocSingleton was ready, this should never happen"); InitialiseTier0GameUtilFunctions(GetModuleHandleA("tier0.dll")); } g_pMemAllocSingleton->m_vtable->Free(g_pMemAllocSingleton, p); } -extern "C" void* _realloc_base(void* oldPtr, size_t size) { +extern "C" void* _realloc_base(void* oldPtr, size_t size) +{ if (!g_pMemAllocSingleton) { InitialiseTier0GameUtilFunctions(GetModuleHandleA("tier0.dll")); @@ -56,7 +58,7 @@ extern "C" char* _strdup_base(const char* src) while (src[len]) len++; - str = (char*)(_malloc_base(len + 1)); + str = reinterpret_cast(_malloc_base(len + 1)); p = str; while (*src) *p++ = *src++; diff --git a/NorthstarDedicatedTest/memalloc.h b/NorthstarDedicatedTest/memalloc.h index b98fe3c8..92ab9672 100644 --- a/NorthstarDedicatedTest/memalloc.h +++ b/NorthstarDedicatedTest/memalloc.h @@ -35,8 +35,6 @@ public: static void Free(void* ptr) { _free_base(ptr); } }; -static SourceAllocator g_SourceAllocator; - typedef rapidjson::GenericDocument, rapidjson::MemoryPoolAllocator, SourceAllocator> rapidjson_document; //typedef rapidjson::GenericDocument, SourceAllocator, SourceAllocator> rapidjson_document; //typedef rapidjson::Document rapidjson_document; -- cgit v1.2.3