aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LauncherInjector/LauncherInjector.vcxproj2
-rw-r--r--LauncherInjector/LauncherInjector.vcxproj.filters6
-rw-r--r--LauncherInjector/main.cpp36
-rw-r--r--LauncherInjector/memalloc.cpp90
-rw-r--r--LauncherInjector/memalloc.h24
-rw-r--r--NorthstarDedicatedTest/convar.cpp2
-rw-r--r--NorthstarDedicatedTest/dedicated.cpp19
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp12
-rw-r--r--NorthstarDedicatedTest/gameutils.cpp2
-rw-r--r--NorthstarDedicatedTest/hooks.cpp18
-rw-r--r--NorthstarDedicatedTest/hookutils.cpp4
-rw-r--r--NorthstarDedicatedTest/memalloc.cpp76
-rw-r--r--NorthstarDedicatedTest/memalloc.h14
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp4
-rw-r--r--loader_launcher_proxy/dllmain.cpp18
-rw-r--r--loader_launcher_proxy/framework.h4
-rw-r--r--loader_launcher_proxy/loader_launcher_proxy.vcxproj4
-rw-r--r--loader_launcher_proxy/loader_launcher_proxy.vcxproj.filters6
-rw-r--r--loader_launcher_proxy/pch.h2
19 files changed, 76 insertions, 267 deletions
diff --git a/LauncherInjector/LauncherInjector.vcxproj b/LauncherInjector/LauncherInjector.vcxproj
index 289d66ae..8870c732 100644
--- a/LauncherInjector/LauncherInjector.vcxproj
+++ b/LauncherInjector/LauncherInjector.vcxproj
@@ -88,10 +88,8 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
- <ClCompile Include="memalloc.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="memalloc.h" />
<ClInclude Include="resource1.h" />
</ItemGroup>
<ItemGroup>
diff --git a/LauncherInjector/LauncherInjector.vcxproj.filters b/LauncherInjector/LauncherInjector.vcxproj.filters
index 2e935b08..87e25fa8 100644
--- a/LauncherInjector/LauncherInjector.vcxproj.filters
+++ b/LauncherInjector/LauncherInjector.vcxproj.filters
@@ -18,17 +18,11 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="memalloc.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource1.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="memalloc.h">
- <Filter>Header Files</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resources.rc">
diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp
index 1eca067a..761f443e 100644
--- a/LauncherInjector/main.cpp
+++ b/LauncherInjector/main.cpp
@@ -18,7 +18,7 @@ HMODULE hHookModule;
HMODULE hTier0Module;
wchar_t exePath[4096];
-wchar_t buffer[8196];
+wchar_t buffer[8192];
DWORD GetProcessByName(std::wstring processName)
{
@@ -173,24 +173,18 @@ bool LoadNorthstar()
int main(int argc, char* argv[]) {
// checked to avoid starting origin, Northstar.dll will check for -dedicated as well on its own
- bool isDedicated = false;
- for (int i = 0; i < argc; i++)
- if (!strcmp(argv[i], "-dedicated"))
- isDedicated = true;
-
bool noOriginStartup = false;
for (int i = 0; i < argc; i++)
- if (!strcmp(argv[i], "-noOriginStartup"))
+ if (!strcmp(argv[i], "-noOriginStartup") || !strcmp(argv[i], "-dedicated"))
noOriginStartup = true;
- if (!isDedicated && !noOriginStartup)
+ if (!noOriginStartup)
{
EnsureOriginStarted();
}
{
-
- if (!GetExePathWide(exePath, 4096))
+ if (!GetExePathWide(exePath, sizeof(exePath)))
{
MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Launcher Error", 0);
return 1;
@@ -198,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)
{
@@ -210,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/LauncherInjector/memalloc.cpp b/LauncherInjector/memalloc.cpp
deleted file mode 100644
index af334acf..00000000
--- a/LauncherInjector/memalloc.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#include "memalloc.h"
-#include <stdio.h>
-
-extern HMODULE hTier0Module;
-IMemAlloc** g_ppMemAllocSingleton;
-
-void LoadTier0Handle()
-{
- if (!hTier0Module) hTier0Module = GetModuleHandleA("tier0.dll");
- if (!hTier0Module) return;
-
- g_ppMemAllocSingleton = (IMemAlloc**)GetProcAddress(hTier0Module, "g_pMemAllocSingleton");
-}
-
-const int STATIC_ALLOC_SIZE = 16384;
-
-size_t g_iStaticAllocated = 0;
-void* g_pLastAllocated = nullptr;
-char pStaticAllocBuf[STATIC_ALLOC_SIZE];
-
-// they should never be used here, except in LibraryLoadError // haha not true
-
-void* malloc(size_t n)
-{
- //printf("NorthstarLauncher malloc: %llu\n", n);
- // allocate into static buffer
- if (g_iStaticAllocated + n <= STATIC_ALLOC_SIZE)
- {
- void* ret = pStaticAllocBuf + g_iStaticAllocated;
- g_iStaticAllocated += n;
- g_pLastAllocated = ret;
- return ret;
- }
- else
- {
- // try to fallback to g_pMemAllocSingleton
- if (!hTier0Module || !g_ppMemAllocSingleton) LoadTier0Handle();
- if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
- return (*g_ppMemAllocSingleton)->m_vtable->Alloc(*g_ppMemAllocSingleton, n);
- else
- throw "Cannot allocate";
- }
-}
-
-void free(void* p)
-{
- //printf("NorthstarLauncher free: %p\n", 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)
- return;
-
- if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
- (*g_ppMemAllocSingleton)->m_vtable->Free(*g_ppMemAllocSingleton, p);
-}
-
-void* realloc(void* old_ptr, size_t size) {
- // it was allocated into the static buffer
- if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE)
- {
- 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(size);
- }
- }
-
- if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
- return (*g_ppMemAllocSingleton)->m_vtable->Realloc(*g_ppMemAllocSingleton, old_ptr, size);
- return nullptr;
-}
-
-void* operator new(size_t n)
-{
- return malloc(n);
-}
-
-void operator delete(void* p)
-{
- free(p);
-}
diff --git a/LauncherInjector/memalloc.h b/LauncherInjector/memalloc.h
deleted file mode 100644
index c983966c..00000000
--- a/LauncherInjector/memalloc.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-class IMemAlloc
-{
-public:
- struct VTable
- {
- void* unknown[1]; // alloc debug
- void* (*Alloc) (IMemAlloc* memAlloc, size_t nSize);
- void* unknown2[1]; // realloc debug
- void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize);
- void* unknown3[1]; // free #1
- void (*Free) (IMemAlloc* memAlloc, void* pMem);
- void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag
- size_t(*GetSize) (IMemAlloc* memAlloc, void* pMem);
- void* unknown5[9]; // they all do literally nothing
- void (*DumpStats) (IMemAlloc* memAlloc);
- void (*DumpStatsFileBase) (IMemAlloc* memAlloc, const char* pchFileBase);
- void* unknown6[4];
- int (*heapchk) (IMemAlloc* memAlloc);
- };
-
- VTable* m_vtable;
-};
diff --git a/NorthstarDedicatedTest/convar.cpp b/NorthstarDedicatedTest/convar.cpp
index ed7e8dac..de460662 100644
--- a/NorthstarDedicatedTest/convar.cpp
+++ b/NorthstarDedicatedTest/convar.cpp
@@ -20,7 +20,7 @@ ConVar* RegisterConVar(const char* name, const char* defaultValue, int flags, co
ConVar* newVar = new ConVar;
conVarConstructor(newVar, name, defaultValue, flags, helpString);
- g_CustomConvars.insert(std::make_pair(name, newVar));
+ g_CustomConvars.emplace(name, newVar);
return newVar;
}
diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp
index 851ab861..0ecc1dba 100644
--- a/NorthstarDedicatedTest/dedicated.cpp
+++ b/NorthstarDedicatedTest/dedicated.cpp
@@ -13,7 +13,7 @@ bool IsDedicated()
// CDedidcatedExports defs
struct CDedicatedExports; // forward declare
-typedef void (*DedicatedSys_PrintfType)(CDedicatedExports* dedicated, char* msg);
+typedef void (*DedicatedSys_PrintfType)(CDedicatedExports* dedicated, const char* msg);
typedef void (*DedicatedRunServerType)(CDedicatedExports* dedicated);
// would've liked to just do this as a class but have not been able to get it to work
@@ -27,7 +27,7 @@ struct CDedicatedExports
DedicatedRunServerType RunServer;
};
-void Sys_Printf(CDedicatedExports* dedicated, char* msg)
+void Sys_Printf(CDedicatedExports* dedicated, const char* msg)
{
spdlog::info("[DEDICATED PRINT] {}", msg);
}
@@ -36,7 +36,7 @@ typedef void(*CHostState__InitType)(CHostState* self);
void RunServer(CDedicatedExports* dedicated)
{
- Sys_Printf(dedicated, (char*)"CDedicatedExports::RunServer(): starting");
+ Sys_Printf(dedicated, "CDedicatedExports::RunServer(): starting");
// init hoststate, if we don't do this, we get a crash later on
CHostState__InitType CHostState__Init = (CHostState__InitType)((char*)GetModuleHandleA("engine.dll") + 0x16E110);
@@ -383,23 +383,18 @@ void InitialiseDedicated(HMODULE engineAddress)
CommandLine()->AppendParm("+exec", "autoexec_ns_server");
}
-typedef void(*Tier0_InitOriginType)();
-Tier0_InitOriginType Tier0_InitOrigin;
-void Tier0_InitOriginHook()
+void InitialiseDedicatedOrigin(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 an origin id as a client
// for dedi it's fine though, game doesn't care if origin is disabled as long as there's only a server
- Tier0_InitOrigin();
-}
-void InitialiseDedicatedOrigin(HMODULE baseAddress)
-{
if (!IsDedicated())
return;
- HookEnabler hook;
- ENABLER_CREATEHOOK(hook, GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin"), &Tier0_InitOriginHook, reinterpret_cast<LPVOID*>(&Tier0_InitOrigin));
+ char* ptr = (char*)GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin");
+ TempReadWrite rw(ptr);
+ *ptr = (char)0xC3;
}
typedef void(*PrintFatalSquirrelErrorType)(void* sqvm);
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 691c9bc7..81bae847 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -58,33 +58,29 @@ 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);
}
}
-SourceAllocator* g_SourceAllocator;
-
bool InitialiseNorthstar()
{
if (initialised)
{
- fprintf(stderr, "[info] Called InitialiseNorthstar more than once!\n");
+ spdlog::warn("Called InitialiseNorthstar more than once!");
return false;
}
initialised = true;
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+
InitialiseLogging();
// apply initial hooks
InstallInitialHooks();
InitialiseInterfaceCreationHooks();
- g_SourceAllocator = new SourceAllocator;
-
- AddDllLoadCallback("tier0.dll", InitialiseTier0GameUtilFunctions);
AddDllLoadCallback("engine.dll", WaitForDebugger);
AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions);
AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions);
@@ -92,8 +88,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<ErrorType>(GetProcAddress(baseAddress, "Error"));
diff --git a/NorthstarDedicatedTest/hooks.cpp b/NorthstarDedicatedTest/hooks.cpp
index 5723a8ab..19010e83 100644
--- a/NorthstarDedicatedTest/hooks.cpp
+++ b/NorthstarDedicatedTest/hooks.cpp
@@ -45,12 +45,12 @@ void InstallInitialHooks()
ENABLER_CREATEHOOK(hook, &LoadLibraryW, &LoadLibraryWHook, reinterpret_cast<LPVOID*>(&LoadLibraryWOriginal));
}
-char* cmdlineResult;
LPSTR GetCommandLineAHook()
{
+ static char* cmdlineModified;
static char* cmdlineOrg;
- if (cmdlineOrg == nullptr || cmdlineResult == nullptr)
+ if (cmdlineOrg == nullptr || cmdlineModified == nullptr)
{
cmdlineOrg = GetCommandLineAOriginal();
bool isDedi = strstr(cmdlineOrg, "-dedicated"); // well, this one has to be a real argument
@@ -77,18 +77,18 @@ LPSTR GetCommandLineAHook()
}
auto len = args.length();
- cmdlineResult = reinterpret_cast<char*>(_malloc_base(len + 1));
- if (!cmdlineResult)
+ cmdlineModified = new char[len + 1];
+ if (!cmdlineModified)
{
spdlog::error("malloc failed for command line");
return cmdlineOrg;
}
- memcpy(cmdlineResult, args.c_str(), len + 1);
+ memcpy(cmdlineModified, args.c_str(), len + 1);
- spdlog::info("Command line: {}", cmdlineResult);
+ spdlog::info("Command line: {}", cmdlineModified);
}
- return cmdlineResult;
+ return cmdlineModified;
}
// dll load callback stuff
@@ -116,7 +116,7 @@ void CallLoadLibraryACallbacks(LPCSTR lpLibFileName, HMODULE moduleAddress)
{
for (auto& callbackStruct : dllLoadCallbacks)
{
- if (!callbackStruct->called && strstr(lpLibFileName + (strlen(lpLibFileName) - strlen(callbackStruct->dll.c_str())), callbackStruct->dll.c_str()) != nullptr)
+ if (!callbackStruct->called && strstr(lpLibFileName + (strlen(lpLibFileName) - callbackStruct->dll.length()), callbackStruct->dll.c_str()) != nullptr)
{
callbackStruct->callback(moduleAddress);
callbackStruct->called = true;
@@ -130,7 +130,7 @@ void CallLoadLibraryWCallbacks(LPCWSTR lpLibFileName, HMODULE moduleAddress)
{
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) - wcslen(callbackDll)), callbackDll) != nullptr)
+ if (!callbackStruct->called && wcsstr(lpLibFileName + (wcslen(lpLibFileName) - wcharStrDll.length()), callbackDll) != nullptr)
{
callbackStruct->callback(moduleAddress);
callbackStruct->called = true;
diff --git a/NorthstarDedicatedTest/hookutils.cpp b/NorthstarDedicatedTest/hookutils.cpp
index e86c671c..8ab24a3b 100644
--- a/NorthstarDedicatedTest/hookutils.cpp
+++ b/NorthstarDedicatedTest/hookutils.cpp
@@ -38,7 +38,7 @@ void HookEnabler::CreateHook(LPVOID ppTarget, LPVOID ppDetour, LPVOID* ppOrigina
else
{
if (targetName != nullptr)
- spdlog::error("MH_CreateHook failed for function %s", targetName);
+ spdlog::error("MH_CreateHook failed for function {}", targetName);
else
spdlog::error("MH_CreateHook failed for unknown function");
}
@@ -51,7 +51,7 @@ HookEnabler::~HookEnabler()
if (MH_EnableHook(hook->targetAddress) != MH_OK)
{
if (hook->targetName != nullptr)
- spdlog::error("MH_EnableHook failed for function %s", hook->targetName);
+ spdlog::error("MH_EnableHook failed for function {}", hook->targetName);
else
spdlog::error("MH_EnableHook failed for unknown function");
}
diff --git a/NorthstarDedicatedTest/memalloc.cpp b/NorthstarDedicatedTest/memalloc.cpp
index c1fb70e7..86215e3f 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,31 @@ 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 +56,7 @@ extern "C" char* _strdup_base(const char* src)
while (src[len])
len++;
- str = reinterpret_cast<char*>(_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..b98fe3c8 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 {
@@ -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::UTF8<>, rapidjson::MemoryPoolAllocator<SourceAllocator>, SourceAllocator> rapidjson_document;
//typedef rapidjson::GenericDocument<rapidjson::UTF8<>, SourceAllocator, SourceAllocator> rapidjson_document;
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index a9119075..23dd2d6e 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -309,7 +309,7 @@ void ModManager::LoadMods()
if (fs::is_regular_file(file))
{
std::string kvStr = file.path().lexically_relative(mod.ModDirectory / "keyvalues").lexically_normal().string();
- mod.KeyValues.insert(std::make_pair(std::hash<std::string>{}(kvStr), kvStr));
+ mod.KeyValues.emplace(std::hash<std::string>{}(kvStr), kvStr);
}
}
}
@@ -333,7 +333,7 @@ void ModManager::LoadMods()
}
// in a seperate loop because we register mod files in reverse order, since mods loaded later should have their files prioritised
- for (size_t i = m_loadedMods.size() - 1; i > -1; i--)
+ for (int64_t i = m_loadedMods.size() - 1; i > -1; i--)
{
if (!m_loadedMods[i].Enabled)
continue;
diff --git a/loader_launcher_proxy/dllmain.cpp b/loader_launcher_proxy/dllmain.cpp
index 7a778208..9fddc8d4 100644
--- a/loader_launcher_proxy/dllmain.cpp
+++ b/loader_launcher_proxy/dllmain.cpp
@@ -119,6 +119,14 @@ extern "C" __declspec(dllexport) int LauncherMain(HINSTANCE hInstance, HINSTANCE
if (loadNorthstar)
{
+ swprintf_s(dllPath, L"%s\\bin\\x64_retail\\tier0.dll", exePath);
+ hTier0Module = LoadLibraryW(dllPath);
+ if (!hTier0Module)
+ {
+ LibraryLoadError(GetLastError(), L"tier0.dll", dllPath);
+ return 1;
+ }
+
if (!LoadNorthstar())
return 1;
}
@@ -131,16 +139,6 @@ extern "C" __declspec(dllexport) int LauncherMain(HINSTANCE hInstance, HINSTANCE
LibraryLoadError(GetLastError(), L"launcher.org.dll", dllPath);
return 1;
}
-
- // 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(dllPath, L"%s\\bin\\x64_retail\\tier0.dll", exePath);
- hTier0Module = LoadLibraryW(dllPath);
- if (!hTier0Module)
- {
- LibraryLoadError(GetLastError(), L"tier0.dll", dllPath);
- return 1;
- }
}
auto LauncherMain = GetLauncherMain();
diff --git a/loader_launcher_proxy/framework.h b/loader_launcher_proxy/framework.h
index 54b83e94..d1b49600 100644
--- a/loader_launcher_proxy/framework.h
+++ b/loader_launcher_proxy/framework.h
@@ -1,5 +1,7 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#define WIN32_EXTRA_LEAN
+#define VC_EXTRALEAN
// Windows Header Files
-#include <windows.h>
+#include <Windows.h>
diff --git a/loader_launcher_proxy/loader_launcher_proxy.vcxproj b/loader_launcher_proxy/loader_launcher_proxy.vcxproj
index 9cc7a4c7..24cdabc0 100644
--- a/loader_launcher_proxy/loader_launcher_proxy.vcxproj
+++ b/loader_launcher_proxy/loader_launcher_proxy.vcxproj
@@ -21,7 +21,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@@ -92,12 +92,10 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
- <ClInclude Include="Memory.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
- <ClCompile Include="Memory.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
diff --git a/loader_launcher_proxy/loader_launcher_proxy.vcxproj.filters b/loader_launcher_proxy/loader_launcher_proxy.vcxproj.filters
index 519ed674..1e57c7b1 100644
--- a/loader_launcher_proxy/loader_launcher_proxy.vcxproj.filters
+++ b/loader_launcher_proxy/loader_launcher_proxy.vcxproj.filters
@@ -21,9 +21,6 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="Memory.h">
- <Filter>Header Files</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@@ -32,8 +29,5 @@
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="Memory.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/loader_launcher_proxy/pch.h b/loader_launcher_proxy/pch.h
index 30257bb2..885d5d62 100644
--- a/loader_launcher_proxy/pch.h
+++ b/loader_launcher_proxy/pch.h
@@ -7,8 +7,6 @@
#ifndef PCH_H
#define PCH_H
-#include "Memory.h"
-
// add headers that you want to pre-compile here
#include "framework.h"