diff options
author | Jan <sentrycraft123@gmail.com> | 2023-08-05 18:56:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 18:56:33 +0200 |
commit | 07e76e3a8e2738dbb7a1d5a6aeaa908a838f5a02 (patch) | |
tree | e666d5aeae0535214f99c0a52aaecc06da0775bf | |
parent | 300521638f6600f23bfea433e8069c049af42388 (diff) | |
download | NorthstarLauncher-07e76e3a8e2738dbb7a1d5a6aeaa908a838f5a02.tar.gz NorthstarLauncher-07e76e3a8e2738dbb7a1d5a6aeaa908a838f5a02.zip |
Support DLLs in Profile from wsock32 proxy (#527)v1.18.2-rc1v1.18.2
* Copy LoadNorthstar from NorthstarLauncher to wsock proxy
* add missing bits
-rw-r--r-- | loader_wsock32_proxy/loader.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/loader_wsock32_proxy/loader.cpp b/loader_wsock32_proxy/loader.cpp index f8b3052b..3e46c1a6 100644 --- a/loader_wsock32_proxy/loader.cpp +++ b/loader_wsock32_proxy/loader.cpp @@ -4,6 +4,9 @@ #include <sstream> #include <fstream> #include <filesystem> +#include <iostream> + +namespace fs = std::filesystem; void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location) { @@ -44,18 +47,55 @@ bool LoadNorthstar() { FARPROC Hook_Init = nullptr; { - swprintf_s(buffer1, L"%s\\Northstar.dll", exePath); - auto hHookModule = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + std::string strProfile = "R2Northstar"; + char* clachar = strstr(GetCommandLineA(), "-profile="); + if (clachar) + { + std::string cla = std::string(clachar); + if (strncmp(cla.substr(9, 1).c_str(), "\"", 1)) + { + int space = cla.find(" "); + std::string dirname = cla.substr(9, space - 9); + std::cout << "[*] Found profile in command line arguments: " << dirname << std::endl; + strProfile = dirname.c_str(); + } + else + { + std::string quote = "\""; + int quote1 = cla.find(quote); + int quote2 = (cla.substr(quote1 + 1)).find(quote); + std::string dirname = cla.substr(quote1 + 1, quote2); + std::cout << "[*] Found profile in command line arguments: " << dirname << std::endl; + strProfile = dirname; + } + } + else + { + std::cout << "[*] Profile was not found in command line arguments. Using default: R2Northstar" << std::endl; + strProfile = "R2Northstar"; + } + + wchar_t buffer[8192]; + + // 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()); + + if (!fs::exists(fs::path(buffer))) + swprintf_s(buffer, L"%s\\Northstar.dll", exePath); + + std::wcout << L"[*] Using: " << buffer << std::endl; + + HMODULE hHookModule = LoadLibraryExW(buffer, 0, 8u); if (hHookModule) Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar"); if (!hHookModule || Hook_Init == nullptr) { - LibraryLoadError(GetLastError(), L"Northstar.dll", buffer1); + LibraryLoadError(GetLastError(), L"Northstar.dll", buffer); return false; } } - ((bool (*)())Hook_Init)(); + return true; } |