|
1 | 1 | #include "loader.h"
|
2 | 2 |
|
3 |
| -#include <shlwapi.h> |
4 | 3 | #include <filesystem>
|
5 | 4 |
|
6 |
| -HINSTANCE hLThis = 0; |
7 |
| -FARPROC p[857]; |
8 |
| -HINSTANCE hL = 0; |
| 5 | +FARPROC p[73]; |
| 6 | +HMODULE hL = 0; |
9 | 7 |
|
10 |
| -bool GetExePathWide(wchar_t* dest, DWORD destSize) |
11 |
| -{ |
12 |
| - if (!dest) |
13 |
| - return NULL; |
14 |
| - if (destSize < MAX_PATH) |
15 |
| - return NULL; |
16 |
| - |
17 |
| - DWORD length = GetModuleFileNameW(NULL, dest, destSize); |
18 |
| - return length && PathRemoveFileSpecW(dest); |
19 |
| -} |
20 |
| - |
21 |
| -wchar_t exePath[4096]; |
22 |
| -wchar_t buffer1[8192]; |
23 |
| -wchar_t buffer2[12288]; |
| 8 | +static wchar_t wsockPath[4096]; |
24 | 9 |
|
25 | 10 | BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
|
26 | 11 | {
|
27 | 12 | if (reason == DLL_PROCESS_ATTACH)
|
28 | 13 | {
|
29 |
| - hLThis = hInst; |
30 |
| - |
31 |
| - if (!GetExePathWide(exePath, 4096)) |
32 |
| - { |
33 |
| - MessageBoxA( |
34 |
| - GetForegroundWindow(), |
35 |
| - "Failed getting game directory.\nThe game cannot continue and has to exit.", |
36 |
| - "Northstar Wsock32 Proxy Error", |
37 |
| - 0); |
38 |
| - return true; |
39 |
| - } |
40 |
| - |
41 |
| - SetCurrentDirectoryW(exePath); |
| 14 | + // Tell the OS we don't need to know about threads |
| 15 | + DisableThreadLibraryCalls(hInst); |
42 | 16 |
|
43 | 17 | if (!ProvisionNorthstar()) // does not call InitialiseNorthstar yet, will do it on LauncherMain hook
|
44 | 18 | return true;
|
45 | 19 |
|
46 |
| - // copy the original library for system to our local directory, with changed name so that we can load it |
47 |
| - swprintf_s(buffer1, L"%s\\bin\\x64_retail\\wsock32.org.dll", exePath); |
48 |
| - GetSystemDirectoryW(buffer2, 4096); |
49 |
| - swprintf_s(buffer2, L"%s\\wsock32.dll", buffer2); |
50 |
| - try |
51 |
| - { |
52 |
| - std::filesystem::copy_file(buffer2, buffer1); |
53 |
| - } |
54 |
| - catch (const std::exception& e1) |
55 |
| - { |
56 |
| - if (!std::filesystem::exists(buffer1)) |
57 |
| - { |
58 |
| - // fallback by copying to temp dir... |
59 |
| - // because apparently games installed by EA Desktop app don't have write permissions in their directories |
60 |
| - auto temp_dir = std::filesystem::temp_directory_path() / L"wsock32.org.dll"; |
61 |
| - try |
62 |
| - { |
63 |
| - std::filesystem::copy_file(buffer2, temp_dir); |
64 |
| - } |
65 |
| - catch (const std::exception& e2) |
66 |
| - { |
67 |
| - if (!std::filesystem::exists(temp_dir)) |
68 |
| - { |
69 |
| - swprintf_s( |
70 |
| - buffer2, |
71 |
| - L"Failed copying wsock32.dll from system32 to \"%s\"\n\n%S\n\nFurthermore, we failed copying wsock32.dll into " |
72 |
| - L"temporary directory at \"%s\"\n\n%S", |
73 |
| - buffer1, |
74 |
| - e1.what(), |
75 |
| - temp_dir.c_str(), |
76 |
| - e2.what()); |
77 |
| - MessageBoxW(GetForegroundWindow(), buffer2, L"Northstar Wsock32 Proxy Error", 0); |
78 |
| - return false; |
79 |
| - } |
80 |
| - } |
81 |
| - swprintf_s(buffer1, L"%s", temp_dir.c_str()); |
82 |
| - } |
83 |
| - } |
84 |
| - hL = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH); |
| 20 | + GetSystemDirectoryW(wsockPath, 4096); |
| 21 | + swprintf_s(wsockPath, 4096, L"%s\\wsock32.dll", wsockPath); |
| 22 | + |
| 23 | + hL = LoadLibraryExW(wsockPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); |
85 | 24 | if (!hL)
|
86 | 25 | {
|
87 |
| - LibraryLoadError(GetLastError(), L"wsock32.org.dll", buffer1); |
| 26 | + LibraryLoadError(GetLastError(), L"wsock32.dll", wsockPath); |
88 | 27 | return false;
|
89 | 28 | }
|
90 | 29 |
|
@@ -119,64 +58,16 @@ extern "C"
|
119 | 58 | FARPROC PA = NULL;
|
120 | 59 | int RunASM();
|
121 | 60 |
|
122 |
| - void PROXY_EnumProtocolsA() |
123 |
| - { |
124 |
| - PA = p[1]; |
125 |
| - RunASM(); |
126 |
| - } |
127 |
| - void PROXY_EnumProtocolsW() |
128 |
| - { |
129 |
| - PA = p[2]; |
130 |
| - RunASM(); |
131 |
| - } |
132 |
| - void PROXY_GetAddressByNameA() |
133 |
| - { |
134 |
| - PA = p[4]; |
135 |
| - RunASM(); |
136 |
| - } |
137 |
| - void PROXY_GetAddressByNameW() |
138 |
| - { |
139 |
| - PA = p[5]; |
140 |
| - RunASM(); |
141 |
| - } |
142 |
| - void PROXY_WEP() |
143 |
| - { |
144 |
| - PA = p[17]; |
145 |
| - RunASM(); |
146 |
| - } |
147 |
| - void PROXY_WSARecvEx() |
148 |
| - { |
149 |
| - PA = p[30]; |
150 |
| - RunASM(); |
151 |
| - } |
152 |
| - void PROXY___WSAFDIsSet() |
153 |
| - { |
154 |
| - PA = p[36]; |
155 |
| - RunASM(); |
156 |
| - } |
157 |
| - void PROXY_getnetbyname() |
158 |
| - { |
159 |
| - PA = p[45]; |
160 |
| - RunASM(); |
161 |
| - } |
162 |
| - void PROXY_getsockopt() |
163 |
| - { |
164 |
| - PA = p[52]; |
165 |
| - RunASM(); |
166 |
| - } |
167 |
| - void PROXY_inet_network() |
168 |
| - { |
169 |
| - PA = p[56]; |
170 |
| - RunASM(); |
171 |
| - } |
172 |
| - void PROXY_s_perror() |
173 |
| - { |
174 |
| - PA = p[67]; |
175 |
| - RunASM(); |
176 |
| - } |
177 |
| - void PROXY_setsockopt() |
178 |
| - { |
179 |
| - PA = p[72]; |
180 |
| - RunASM(); |
181 |
| - } |
| 61 | + void PROXY_EnumProtocolsA() { p[1](); } |
| 62 | + void PROXY_EnumProtocolsW() { p[2](); } |
| 63 | + void PROXY_GetAddressByNameA() { p[4](); } |
| 64 | + void PROXY_GetAddressByNameW() { p[5](); } |
| 65 | + void PROXY_WEP() { p[17](); } |
| 66 | + void PROXY_WSARecvEx() { p[30](); } |
| 67 | + void PROXY___WSAFDIsSet() { p[36](); } |
| 68 | + void PROXY_getnetbyname() { p[45](); } |
| 69 | + void PROXY_getsockopt() { p[52](); } |
| 70 | + void PROXY_inet_network() { p[56](); } |
| 71 | + void PROXY_s_perror() { p[67](); } |
| 72 | + void PROXY_setsockopt() { p[72](); } |
182 | 73 | }
|
0 commit comments