aboutsummaryrefslogtreecommitdiff
path: root/primedev/wsockproxy/loader.cpp
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2024-02-18 22:11:09 +0100
committerGitHub <noreply@github.com>2024-02-18 22:11:09 +0100
commit30e58ac08b6ee122de3130f3f02d6a855130ae51 (patch)
tree9f7abd79db5af2191ea7df1b9046c4378182e092 /primedev/wsockproxy/loader.cpp
parentfc63948e092b3495461e7aab4748af27c6dfa5ee (diff)
downloadNorthstarLauncher-30e58ac08b6ee122de3130f3f02d6a855130ae51.tar.gz
NorthstarLauncher-30e58ac08b6ee122de3130f3f02d6a855130ae51.zip
Clean up wsock proxy code and move wsock build system logic (#671)v1.24.1-rc2v1.24.1-rc1v1.24.1
- moves `WSockProxy` to `wsockproxy/CmakeLists` - remove exepath stuff from dllmain + its still done in loader.cpp because its used when reporting failure - Disabled any Thread Library calls + we don't need to know about threads at all in the proxy - yoink `wsock32.asm` into outer space + turns out, we can just call the function in a void shim since that wont touch the registers - stop copying `wsock32.dll` to the game directory + this should improve the state of things when using the EA App
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;
}
}