aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorp0358 <p0358@users.noreply.github.com>2021-12-30 03:26:08 +0100
committerp0358 <p0358@users.noreply.github.com>2021-12-30 03:26:08 +0100
commit572f4eab6c9fd1098d1945668bfa783bd90aa8d9 (patch)
treee52322402a5f69b0166fe74d610df77e85bb8d5e
parentd2ee389192aa425ef9c81b2c3367ffb0de6976d0 (diff)
downloadNorthstarLauncher-572f4eab6c9fd1098d1945668bfa783bd90aa8d9.tar.gz
NorthstarLauncher-572f4eab6c9fd1098d1945668bfa783bd90aa8d9.zip
Restore the functionality of arguments from command line
-rw-r--r--LauncherInjector/main.cpp1
-rw-r--r--NorthstarDedicatedTest/hooks.cpp54
-rw-r--r--loader_launcher_proxy/dllmain.cpp1
3 files changed, 54 insertions, 2 deletions
diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp
index 4f21b200..1eca067a 100644
--- a/LauncherInjector/main.cpp
+++ b/LauncherInjector/main.cpp
@@ -3,7 +3,6 @@
#include <TlHelp32.h>
#include <filesystem>
#include <sstream>
-#include <iostream>
#include <fstream>
#include <Shlwapi.h>
diff --git a/NorthstarDedicatedTest/hooks.cpp b/NorthstarDedicatedTest/hooks.cpp
index 9d2be61c..e58b7afc 100644
--- a/NorthstarDedicatedTest/hooks.cpp
+++ b/NorthstarDedicatedTest/hooks.cpp
@@ -5,6 +5,12 @@
#include <wchar.h>
#include <iostream>
#include <vector>
+#include <fstream>
+#include <sstream>
+#include <filesystem>
+
+typedef LPSTR(*GetCommandLineAType)();
+LPSTR GetCommandLineAHook();
// note that these load library callbacks only support explicitly loaded dynamic libraries
@@ -20,6 +26,7 @@ HMODULE LoadLibraryExWHook(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
typedef HMODULE(*LoadLibraryWType)(LPCWSTR lpLibFileName);
HMODULE LoadLibraryWHook(LPCWSTR lpLibFileName);
+GetCommandLineAType GetCommandLineAOriginal;
LoadLibraryExAType LoadLibraryExAOriginal;
LoadLibraryAType LoadLibraryAOriginal;
LoadLibraryExWType LoadLibraryExWOriginal;
@@ -31,12 +38,59 @@ void InstallInitialHooks()
spdlog::error("MH_Initialize failed");
HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, &GetCommandLineA, &GetCommandLineAHook, reinterpret_cast<LPVOID*>(&GetCommandLineAOriginal));
ENABLER_CREATEHOOK(hook, &LoadLibraryExA, &LoadLibraryExAHook, reinterpret_cast<LPVOID*>(&LoadLibraryExAOriginal));
ENABLER_CREATEHOOK(hook, &LoadLibraryA, &LoadLibraryAHook, reinterpret_cast<LPVOID*>(&LoadLibraryAOriginal));
ENABLER_CREATEHOOK(hook, &LoadLibraryExW, &LoadLibraryExWHook, reinterpret_cast<LPVOID*>(&LoadLibraryExWOriginal));
ENABLER_CREATEHOOK(hook, &LoadLibraryW, &LoadLibraryWHook, reinterpret_cast<LPVOID*>(&LoadLibraryWOriginal));
}
+char* cmdlineResult;
+LPSTR GetCommandLineAHook()
+{
+ static char* cmdlineOrg;
+
+ if (cmdlineOrg == nullptr || cmdlineResult == nullptr)
+ {
+ cmdlineOrg = GetCommandLineAOriginal();
+ bool isDedi = strstr(cmdlineOrg, "-dedicated"); // well, this one has to be a real argument
+
+ std::string args;
+ std::ifstream cmdlineArgFile;
+
+ // it looks like CommandLine() prioritizes parameters apprearing first, so we want the real commandline to take priority
+ // not to mention that cmdlineOrg starts with the EXE path
+ args.append(cmdlineOrg);
+ args.append(" ");
+
+ // append those from the file
+
+ cmdlineArgFile = std::ifstream(!isDedi ? "ns_startup_args.txt" : "ns_startup_args_dedi.txt");
+
+ if (cmdlineArgFile)
+ {
+ std::stringstream argBuffer;
+ argBuffer << cmdlineArgFile.rdbuf();
+ cmdlineArgFile.close();
+
+ args.append(argBuffer.str());
+ }
+
+ auto len = args.length();
+ cmdlineResult = reinterpret_cast<char*>(malloc(len + 1));
+ if (!cmdlineResult)
+ {
+ spdlog::error("malloc failed for command line");
+ return cmdlineOrg;
+ }
+ memcpy(cmdlineResult, args.c_str(), len + 1);
+
+ spdlog::info("Command line: {}", cmdlineResult);
+ }
+
+ return cmdlineResult;
+}
+
// dll load callback stuff
// this allows for code to register callbacks to be run as soon as a dll is loaded, mainly to allow for patches to be made on dll load
struct DllLoadCallback
diff --git a/loader_launcher_proxy/dllmain.cpp b/loader_launcher_proxy/dllmain.cpp
index 6db50986..7a778208 100644
--- a/loader_launcher_proxy/dllmain.cpp
+++ b/loader_launcher_proxy/dllmain.cpp
@@ -102,7 +102,6 @@ bool LoadNorthstar()
}
}
- printf("WILL CALL HOOK INIT\n");
((bool (*)()) Hook_Init)();
return true;
}