aboutsummaryrefslogtreecommitdiff
path: root/primedev/wsockproxy/loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'primedev/wsockproxy/loader.cpp')
-rw-r--r--primedev/wsockproxy/loader.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/primedev/wsockproxy/loader.cpp b/primedev/wsockproxy/loader.cpp
index 0a299ba8..a3abf11c 100644
--- a/primedev/wsockproxy/loader.cpp
+++ b/primedev/wsockproxy/loader.cpp
@@ -1,4 +1,5 @@
#include "loader.h"
+#include <shlwapi.h>
#include <string>
#include <system_error>
#include <sstream>
@@ -8,6 +9,21 @@
namespace fs = std::filesystem;
+static wchar_t northstarPath[8192];
+static wchar_t exePath[4096];
+
+bool GetExePathWide(wchar_t* dest, DWORD destSize)
+{
+ if (!dest)
+ return NULL;
+ if (destSize < MAX_PATH)
+ return NULL;
+
+ DWORD length = GetModuleFileNameW(NULL, dest, destSize);
+ return length && PathRemoveFileSpecW(dest);
+}
+
+
void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location)
{
char text[4096];
@@ -75,22 +91,30 @@ bool LoadNorthstar()
strProfile = "R2Northstar";
}
- wchar_t buffer[8192];
+ if (!GetExePathWide(exePath, 4096))
+ {
+ MessageBoxA(
+ GetForegroundWindow(),
+ "Failed getting game directory.\nThe game cannot continue and has to exit.",
+ "Northstar Wsock32 Proxy Error",
+ 0);
+ return true;
+ }
// Check if "Northstar.dll" exists in profile directory, if it doesnt fall back to root
- swprintf_s(buffer, L"%s\\%s\\Northstar.dll", exePath, std::wstring(strProfile.begin(), strProfile.end()).c_str());
+ swprintf_s(northstarPath, L"%s\\%s\\Northstar.dll", exePath, std::wstring(strProfile.begin(), strProfile.end()).c_str());
- if (!fs::exists(fs::path(buffer)))
- swprintf_s(buffer, L"%s\\Northstar.dll", exePath);
+ if (!fs::exists(fs::path(northstarPath)))
+ swprintf_s(northstarPath, L"%s\\Northstar.dll", exePath);
- std::wcout << L"[*] Using: " << buffer << std::endl;
+ std::wcout << L"[*] Using: " << northstarPath << std::endl;
- HMODULE hHookModule = LoadLibraryExW(buffer, 0, 8u);
+ HMODULE hHookModule = LoadLibraryExW(northstarPath, 0, 8u);
if (hHookModule)
Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar");
if (!hHookModule || Hook_Init == nullptr)
{
- LibraryLoadError(GetLastError(), L"Northstar.dll", buffer);
+ LibraryLoadError(GetLastError(), L"Northstar.dll", northstarPath);
return false;
}
}