aboutsummaryrefslogtreecommitdiff
path: root/primedev/wsockproxy/dllmain.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/dllmain.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/dllmain.cpp')
-rw-r--r--primedev/wsockproxy/dllmain.cpp153
1 files changed, 22 insertions, 131 deletions
diff --git a/primedev/wsockproxy/dllmain.cpp b/primedev/wsockproxy/dllmain.cpp
index 4cc4f26e..5a606e45 100644
--- a/primedev/wsockproxy/dllmain.cpp
+++ b/primedev/wsockproxy/dllmain.cpp
@@ -1,90 +1,29 @@
#include "loader.h"
-#include <shlwapi.h>
#include <filesystem>
-HINSTANCE hLThis = 0;
-FARPROC p[857];
-HINSTANCE hL = 0;
+FARPROC p[73];
+HMODULE hL = 0;
-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);
-}
-
-wchar_t exePath[4096];
-wchar_t buffer1[8192];
-wchar_t buffer2[12288];
+static wchar_t wsockPath[4096];
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
{
if (reason == DLL_PROCESS_ATTACH)
{
- hLThis = hInst;
-
- 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;
- }
-
- SetCurrentDirectoryW(exePath);
+ // Tell the OS we don't need to know about threads
+ DisableThreadLibraryCalls(hInst);
if (!ProvisionNorthstar()) // does not call InitialiseNorthstar yet, will do it on LauncherMain hook
return true;
- // copy the original library for system to our local directory, with changed name so that we can load it
- swprintf_s(buffer1, L"%s\\bin\\x64_retail\\wsock32.org.dll", exePath);
- GetSystemDirectoryW(buffer2, 4096);
- swprintf_s(buffer2, L"%s\\wsock32.dll", buffer2);
- try
- {
- std::filesystem::copy_file(buffer2, buffer1);
- }
- catch (const std::exception& e1)
- {
- if (!std::filesystem::exists(buffer1))
- {
- // fallback by copying to temp dir...
- // because apparently games installed by EA Desktop app don't have write permissions in their directories
- auto temp_dir = std::filesystem::temp_directory_path() / L"wsock32.org.dll";
- try
- {
- std::filesystem::copy_file(buffer2, temp_dir);
- }
- catch (const std::exception& e2)
- {
- if (!std::filesystem::exists(temp_dir))
- {
- swprintf_s(
- buffer2,
- L"Failed copying wsock32.dll from system32 to \"%s\"\n\n%S\n\nFurthermore, we failed copying wsock32.dll into "
- L"temporary directory at \"%s\"\n\n%S",
- buffer1,
- e1.what(),
- temp_dir.c_str(),
- e2.what());
- MessageBoxW(GetForegroundWindow(), buffer2, L"Northstar Wsock32 Proxy Error", 0);
- return false;
- }
- }
- swprintf_s(buffer1, L"%s", temp_dir.c_str());
- }
- }
- hL = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
+ GetSystemDirectoryW(wsockPath, 4096);
+ swprintf_s(wsockPath, 4096, L"%s\\wsock32.dll", wsockPath);
+
+ hL = LoadLibraryExW(wsockPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
if (!hL)
{
- LibraryLoadError(GetLastError(), L"wsock32.org.dll", buffer1);
+ LibraryLoadError(GetLastError(), L"wsock32.dll", wsockPath);
return false;
}
@@ -119,64 +58,16 @@ extern "C"
FARPROC PA = NULL;
int RunASM();
- void PROXY_EnumProtocolsA()
- {
- PA = p[1];
- RunASM();
- }
- void PROXY_EnumProtocolsW()
- {
- PA = p[2];
- RunASM();
- }
- void PROXY_GetAddressByNameA()
- {
- PA = p[4];
- RunASM();
- }
- void PROXY_GetAddressByNameW()
- {
- PA = p[5];
- RunASM();
- }
- void PROXY_WEP()
- {
- PA = p[17];
- RunASM();
- }
- void PROXY_WSARecvEx()
- {
- PA = p[30];
- RunASM();
- }
- void PROXY___WSAFDIsSet()
- {
- PA = p[36];
- RunASM();
- }
- void PROXY_getnetbyname()
- {
- PA = p[45];
- RunASM();
- }
- void PROXY_getsockopt()
- {
- PA = p[52];
- RunASM();
- }
- void PROXY_inet_network()
- {
- PA = p[56];
- RunASM();
- }
- void PROXY_s_perror()
- {
- PA = p[67];
- RunASM();
- }
- void PROXY_setsockopt()
- {
- PA = p[72];
- RunASM();
- }
+ void PROXY_EnumProtocolsA() { p[1](); }
+ void PROXY_EnumProtocolsW() { p[2](); }
+ void PROXY_GetAddressByNameA() { p[4](); }
+ void PROXY_GetAddressByNameW() { p[5](); }
+ void PROXY_WEP() { p[17](); }
+ void PROXY_WSARecvEx() { p[30](); }
+ void PROXY___WSAFDIsSet() { p[36](); }
+ void PROXY_getnetbyname() { p[45](); }
+ void PROXY_getsockopt() { p[52](); }
+ void PROXY_inet_network() { p[56](); }
+ void PROXY_s_perror() { p[67](); }
+ void PROXY_setsockopt() { p[72](); }
}