diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2024-05-21 22:55:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-21 22:55:26 +0200 |
commit | d1d4f2a086209f041fa357e03fdf93614a7a9fd7 (patch) | |
tree | 290b09ba4b9eec05deaf6dd44d7bd8afad86c31b /primedev/wsockproxy/loader.cpp | |
parent | 60d872d3756854d29b65b63fb146aa4f638dd29e (diff) | |
parent | 220b7a1bf7915a336b9c2a08806e60c1c32bde8e (diff) | |
download | NorthstarLauncher-chore/revert-zlib-cmake-fix.tar.gz NorthstarLauncher-chore/revert-zlib-cmake-fix.zip |
Merge branch 'main' into chore/revert-zlib-cmake-fixchore/revert-zlib-cmake-fix
Diffstat (limited to 'primedev/wsockproxy/loader.cpp')
-rw-r--r-- | primedev/wsockproxy/loader.cpp | 38 |
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; } } |