aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/dedicated.cpp2
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp16
-rw-r--r--NorthstarDedicatedTest/gameutils.cpp9
-rw-r--r--NorthstarDedicatedTest/hooks.cpp26
-rw-r--r--NorthstarDedicatedTest/hooks.h4
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp4
-rw-r--r--NorthstarDedicatedTest/memalloc.cpp6
-rw-r--r--NorthstarDedicatedTest/memalloc.h2
8 files changed, 48 insertions, 21 deletions
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<CreateGlobalMemAllocType>(GetProcAddress(baseAddress, "CreateGlobalMemAlloc"));
IMemAlloc** ppMemAllocSingleton = reinterpret_cast<IMemAlloc**>(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 <fstream>
#include <sstream>
#include <filesystem>
+#include <Psapi.h>
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<char*>(_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::UTF8<>, rapidjson::MemoryPoolAllocator<SourceAllocator>, SourceAllocator> rapidjson_document;
//typedef rapidjson::GenericDocument<rapidjson::UTF8<>, SourceAllocator, SourceAllocator> rapidjson_document;
//typedef rapidjson::Document rapidjson_document;