aboutsummaryrefslogtreecommitdiff
path: root/loader_launcher_proxy
diff options
context:
space:
mode:
Diffstat (limited to 'loader_launcher_proxy')
-rw-r--r--loader_launcher_proxy/Memory.cpp22
-rw-r--r--loader_launcher_proxy/dllmain.cpp76
-rw-r--r--loader_launcher_proxy/loader_launcher_proxy.vcxproj2
3 files changed, 76 insertions, 24 deletions
diff --git a/loader_launcher_proxy/Memory.cpp b/loader_launcher_proxy/Memory.cpp
index d5642ca5..6c69d80f 100644
--- a/loader_launcher_proxy/Memory.cpp
+++ b/loader_launcher_proxy/Memory.cpp
@@ -1,11 +1,11 @@
#include "pch.h"
-HMODULE hTier0Module;
+extern HMODULE hTier0Module;
IMemAlloc** g_ppMemAllocSingleton;
void LoadTier0Handle()
{
- hTier0Module = GetModuleHandleA("tier0.dll");
+ if (!hTier0Module) hTier0Module = GetModuleHandleA("tier0.dll");
if (!hTier0Module) return;
g_ppMemAllocSingleton = (IMemAlloc**)GetProcAddress(hTier0Module, "g_pMemAllocSingleton");
@@ -16,9 +16,9 @@ const int STATIC_ALLOC_SIZE = 4096;
size_t g_iStaticAllocated = 0;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
-// they should never be used here, except in LibraryLoadError
+// they should never be used here, except in LibraryLoadError?
-void* operator new(size_t n)
+void* malloc(size_t n)
{
// allocate into static buffer
if (g_iStaticAllocated + n <= STATIC_ALLOC_SIZE)
@@ -30,7 +30,7 @@ void* operator new(size_t n)
else
{
// try to fallback to g_pMemAllocSingleton
- if (!hTier0Module) LoadTier0Handle();
+ if (!hTier0Module || !g_ppMemAllocSingleton) LoadTier0Handle();
if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
return (*g_ppMemAllocSingleton)->m_vtable->Alloc(*g_ppMemAllocSingleton, n);
else
@@ -38,7 +38,7 @@ void* operator new(size_t n)
}
}
-void operator delete(void* p)
+void free(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)
@@ -47,3 +47,13 @@ void operator delete(void* p)
if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
(*g_ppMemAllocSingleton)->m_vtable->Free(*g_ppMemAllocSingleton, p);
}
+
+void* operator new(size_t n)
+{
+ return malloc(n);
+}
+
+void operator delete(void* p)
+{
+ return free(p);
+}
diff --git a/loader_launcher_proxy/dllmain.cpp b/loader_launcher_proxy/dllmain.cpp
index 31360a8e..6db50986 100644
--- a/loader_launcher_proxy/dllmain.cpp
+++ b/loader_launcher_proxy/dllmain.cpp
@@ -3,9 +3,12 @@
#include <string>
#include <system_error>
#include <Shlwapi.h>
+#include <sstream>
+#include <fstream>
HMODULE hLauncherModule;
HMODULE hHookModule;
+HMODULE hTier0Module;
using CreateInterfaceFn = void* (*)(const char* pName, int* pReturnCode);
@@ -44,7 +47,7 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t*
char text[2048];
std::string message = std::system_category().message(dwMessageId);
sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs", libName, location, dwMessageId, message.c_str());
- MessageBoxA(GetForegroundWindow(), text, "Launcher Error", 0);
+ MessageBoxA(GetForegroundWindow(), text, "Northstar Launcher Proxy Error", 0);
}
BOOL APIENTRY DllMain( HMODULE hModule,
@@ -66,32 +69,61 @@ BOOL APIENTRY DllMain( HMODULE hModule,
wchar_t exePath[4096];
wchar_t dllPath[4096];
+bool ShouldLoadNorthstar()
+{
+ bool loadNorthstar = !strstr(GetCommandLineA(), "-vanilla");
+
+ if (!loadNorthstar)
+ return loadNorthstar;
+
+ auto runNorthstarFile = std::ifstream("run_northstar.txt");
+ if (runNorthstarFile)
+ {
+ std::stringstream runNorthstarFileBuffer;
+ runNorthstarFileBuffer << runNorthstarFile.rdbuf();
+ runNorthstarFile.close();
+ if (runNorthstarFileBuffer.str()._Starts_with("0"))
+ loadNorthstar = false;
+ }
+ return loadNorthstar;
+}
+
+bool LoadNorthstar()
+{
+ FARPROC Hook_Init = nullptr;
+ {
+ swprintf_s(dllPath, L"%s\\Northstar.dll", exePath);
+ hHookModule = LoadLibraryExW(dllPath, 0i64, 8u);
+ if (hHookModule) Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar");
+ if (!hHookModule || Hook_Init == nullptr)
+ {
+ LibraryLoadError(GetLastError(), L"Northstar.dll", dllPath);
+ return false;
+ }
+ }
+
+ printf("WILL CALL HOOK INIT\n");
+ ((bool (*)()) Hook_Init)();
+ return true;
+}
+
extern "C" __declspec(dllexport) int LauncherMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
{
if (!GetExePathWide(exePath, 4096))
{
- MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Launcher Error", 0);
+ MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Launcher Proxy Error", 0);
return 1;
}
- bool loadNorthstar = !strstr(GetCommandLineA(), "-vanilla");
+ bool loadNorthstar = ShouldLoadNorthstar();
+
if (loadNorthstar)
{
- FARPROC Hook_Init = nullptr;
- {
- swprintf_s(dllPath, L"%s\\Northstar.dll", exePath);
- hHookModule = LoadLibraryExW(dllPath, 0i64, 8u);
- if (hHookModule) Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar");
- if (!hHookModule || Hook_Init == nullptr)
- {
- LibraryLoadError(GetLastError(), L"Northstar.dll", dllPath);
- return 1;
- }
- }
-
- ((bool (*)()) Hook_Init)();
+ if (!LoadNorthstar())
+ return 1;
}
+ //else printf("\n\n WILL !!!NOT!!! LOAD NORTHSTAR\n\n");
swprintf_s(dllPath, L"%s\\bin\\x64_retail\\launcher.org.dll", exePath);
hLauncherModule = LoadLibraryExW(dllPath, 0i64, 8u);
@@ -100,11 +132,21 @@ 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();
if (!LauncherMain)
- MessageBoxA(GetForegroundWindow(), "Failed loading launcher.org.dll.\nThe game cannot continue and has to exit.", "Launcher Error", 0);
+ MessageBoxA(GetForegroundWindow(), "Failed loading launcher.org.dll.\nThe game cannot continue and has to exit.", "Northstar Launcher Proxy Error", 0);
//auto result = ((__int64(__fastcall*)())LauncherMain)();
//auto result = ((signed __int64(__fastcall*)(__int64))LauncherMain)(0i64);
return ((int(__fastcall*)(HINSTANCE, HINSTANCE, LPSTR, int))LauncherMain)(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
diff --git a/loader_launcher_proxy/loader_launcher_proxy.vcxproj b/loader_launcher_proxy/loader_launcher_proxy.vcxproj
index 65ef19ba..9cc7a4c7 100644
--- a/loader_launcher_proxy/loader_launcher_proxy.vcxproj
+++ b/loader_launcher_proxy/loader_launcher_proxy.vcxproj
@@ -78,7 +78,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
- <LanguageStandard>Default</LanguageStandard>
+ <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>