aboutsummaryrefslogtreecommitdiff
path: root/loader_wsock32_proxy
diff options
context:
space:
mode:
Diffstat (limited to 'loader_wsock32_proxy')
-rw-r--r--loader_wsock32_proxy/dllmain.cpp64
-rw-r--r--loader_wsock32_proxy/hookutils.cpp91
-rw-r--r--loader_wsock32_proxy/loader.cpp32
-rw-r--r--loader_wsock32_proxy/loader_wsock32_proxy.vcxproj4
-rw-r--r--loader_wsock32_proxy/pch.h4
5 files changed, 121 insertions, 74 deletions
diff --git a/loader_wsock32_proxy/dllmain.cpp b/loader_wsock32_proxy/dllmain.cpp
index f4c0d604..7feb278d 100644
--- a/loader_wsock32_proxy/dllmain.cpp
+++ b/loader_wsock32_proxy/dllmain.cpp
@@ -1,7 +1,7 @@
#include "pch.h"
#include "loader.h"
-#include <Shlwapi.h>
+#include <shlwapi.h>
#include <filesystem>
HINSTANCE hLThis = 0;
@@ -10,8 +10,10 @@ HINSTANCE hL = 0;
bool GetExePathWide(wchar_t* dest, DWORD destSize)
{
- if (!dest) return NULL;
- if (destSize < MAX_PATH) return NULL;
+ if (!dest)
+ return NULL;
+ if (destSize < MAX_PATH)
+ return NULL;
DWORD length = GetModuleFileNameW(NULL, dest, destSize);
return length && PathRemoveFileSpecW(dest);
@@ -29,7 +31,11 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
if (!GetExePathWide(exePath, 4096))
{
- MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Wsock32 Proxy Error", 0);
+ MessageBoxA(
+ GetForegroundWindow(),
+ "Failed getting game directory.\nThe game cannot continue and has to exit.",
+ "Northstar Wsock32 Proxy Error",
+ 0);
return true;
}
@@ -59,7 +65,14 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
{
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 temporary directory at \"%s\"\n\n%S", buffer1, e1.what(), temp_dir.c_str(), e2.what());
+ 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;
}
@@ -68,7 +81,8 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
}
}
hL = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
- if (!hL) {
+ if (!hL)
+ {
LibraryLoadError(GetLastError(), L"wsock32.org.dll", buffer1);
return false;
}
@@ -104,52 +118,64 @@ extern "C"
FARPROC PA = NULL;
int RunASM();
- void PROXY_EnumProtocolsA() {
+ void PROXY_EnumProtocolsA()
+ {
PA = p[1];
RunASM();
}
- void PROXY_EnumProtocolsW() {
+ void PROXY_EnumProtocolsW()
+ {
PA = p[2];
RunASM();
}
- void PROXY_GetAddressByNameA() {
+ void PROXY_GetAddressByNameA()
+ {
PA = p[4];
RunASM();
}
- void PROXY_GetAddressByNameW() {
+ void PROXY_GetAddressByNameW()
+ {
PA = p[5];
RunASM();
}
- void PROXY_WEP() {
+ void PROXY_WEP()
+ {
PA = p[17];
RunASM();
}
- void PROXY_WSARecvEx() {
+ void PROXY_WSARecvEx()
+ {
PA = p[30];
RunASM();
}
- void PROXY___WSAFDIsSet() {
+ void PROXY___WSAFDIsSet()
+ {
PA = p[36];
RunASM();
}
- void PROXY_getnetbyname() {
+ void PROXY_getnetbyname()
+ {
PA = p[45];
RunASM();
}
- void PROXY_getsockopt() {
+ void PROXY_getsockopt()
+ {
PA = p[52];
RunASM();
}
- void PROXY_inet_network() {
+ void PROXY_inet_network()
+ {
PA = p[56];
RunASM();
}
- void PROXY_s_perror() {
+ void PROXY_s_perror()
+ {
PA = p[67];
RunASM();
}
- void PROXY_setsockopt() {
+ void PROXY_setsockopt()
+ {
PA = p[72];
RunASM();
}
-} \ No newline at end of file
+}
diff --git a/loader_wsock32_proxy/hookutils.cpp b/loader_wsock32_proxy/hookutils.cpp
index f933f993..ed2b6c3a 100644
--- a/loader_wsock32_proxy/hookutils.cpp
+++ b/loader_wsock32_proxy/hookutils.cpp
@@ -1,54 +1,61 @@
+#include <cstdio>
+
#include "pch.h"
#include "../NorthstarDedicatedTest/hookutils.h"
-#define ERROR(...) { char err[2048]; sprintf_s(err, __VA_ARGS__); MessageBoxA(GetForegroundWindow(), err, "Northstar Wsock32 Proxy Error", 0); }
+#define HU_ERROR(...) \
+ { \
+ char err[2048]; \
+ snprintf(err, sizeof(err), __VA_ARGS__); \
+ MessageBoxA(GetForegroundWindow(), err, "Northstar Wsock32 Proxy Error", 0); \
+ }
void HookEnabler::CreateHook(LPVOID ppTarget, LPVOID ppDetour, LPVOID* ppOriginal, const char* targetName)
{
- // the macro for this uses ppTarget's name as targetName, and this typically starts with &
- // targetname is used for debug stuff and debug output is nicer if we don't have this
- if (*targetName == '&')
- targetName++;
+ // the macro for this uses ppTarget's name as targetName, and this typically starts with &
+ // targetname is used for debug stuff and debug output is nicer if we don't have this
+ if (*targetName == '&')
+ targetName++;
- if (MH_CreateHook(ppTarget, ppDetour, ppOriginal) == MH_OK)
- {
- HookTarget* target = new HookTarget;
- target->targetAddress = ppTarget;
- target->targetName = (char*)targetName;
+ if (MH_CreateHook(ppTarget, ppDetour, ppOriginal) == MH_OK)
+ {
+ HookTarget* target = new HookTarget;
+ target->targetAddress = ppTarget;
+ target->targetName = (char*)targetName;
- m_hookTargets.push_back(target);
- }
- else
- {
- if (targetName != nullptr)
- {
- ERROR("MH_CreateHook failed for function %s", targetName);
- }
- else
- {
- ERROR("MH_CreateHook failed for unknown function");
- }
- }
+ m_hookTargets.push_back(target);
+ }
+ else
+ {
+ if (targetName != nullptr)
+ {
+ HU_ERROR("MH_CreateHook failed for function %s", targetName);
+ }
+ else
+ {
+ HU_ERROR("MH_CreateHook failed for unknown function");
+ }
+ }
}
HookEnabler::~HookEnabler()
{
- for (auto& hook : m_hookTargets)
- {
- if (MH_EnableHook(hook->targetAddress) != MH_OK)
- {
- if (hook->targetName != nullptr)
- {
- ERROR("MH_EnableHook failed for function %s", hook->targetName);
- }
- else
- {
- ERROR("MH_EnableHook failed for unknown function");
- }
- }
- else
- {
- //ERROR("Enabling hook %s", hook->targetName);
- }
- }
-} \ No newline at end of file
+ for (auto& hook : m_hookTargets)
+ {
+ if (MH_EnableHook(hook->targetAddress) != MH_OK)
+ {
+ if (hook->targetName != nullptr)
+ {
+ HU_ERROR("MH_EnableHook failed for function %s", hook->targetName);
+ }
+ else
+ {
+ HU_ERROR("MH_EnableHook failed for unknown function");
+ }
+ }
+ else
+ {
+ // HU_ERROR("Enabling hook %s", hook->targetName);
+ }
+ }
+}
diff --git a/loader_wsock32_proxy/loader.cpp b/loader_wsock32_proxy/loader.cpp
index 61b4daf3..c53f5c00 100644
--- a/loader_wsock32_proxy/loader.cpp
+++ b/loader_wsock32_proxy/loader.cpp
@@ -14,7 +14,11 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t*
sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs", libName, location, dwMessageId, message.c_str());
if (dwMessageId == 126 && std::filesystem::exists(location))
{
- sprintf_s(text, "%s\n\nThe file at the specified location DOES exist, so this error indicates that one of its *dependencies* failed to be found.", text);
+ sprintf_s(
+ text,
+ "%s\n\nThe file at the specified location DOES exist, so this error indicates that one of its *dependencies* failed to be "
+ "found.",
+ text);
}
MessageBoxA(GetForegroundWindow(), text, "Northstar Wsock32 Proxy Error", 0);
}
@@ -32,7 +36,7 @@ bool ShouldLoadNorthstar()
std::stringstream runNorthstarFileBuffer;
runNorthstarFileBuffer << runNorthstarFile.rdbuf();
runNorthstarFile.close();
- if (!runNorthstarFileBuffer.str()._Starts_with("0"))
+ if (!runNorthstarFileBuffer.str().starts_with("0"))
loadNorthstar = true;
}
return loadNorthstar;
@@ -44,7 +48,8 @@ bool LoadNorthstar()
{
swprintf_s(buffer1, L"%s\\Northstar.dll", exePath);
auto hHookModule = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
- if (hHookModule) Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar");
+ if (hHookModule)
+ Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar");
if (!hHookModule || Hook_Init == nullptr)
{
LibraryLoadError(GetLastError(), L"Northstar.dll", buffer1);
@@ -52,11 +57,11 @@ bool LoadNorthstar()
}
}
- ((bool (*)()) Hook_Init)();
+ ((bool (*)())Hook_Init)();
return true;
}
-typedef int(*LauncherMainType)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
+typedef int (*LauncherMainType)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LauncherMainType LauncherMainOriginal;
int LauncherMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
@@ -73,19 +78,28 @@ bool ProvisionNorthstar()
if (MH_Initialize() != MH_OK)
{
- MessageBoxA(GetForegroundWindow(), "MH_Initialize failed\nThe game cannot continue and has to exit.", "Northstar Wsock32 Proxy Error", 0);
+ MessageBoxA(
+ GetForegroundWindow(), "MH_Initialize failed\nThe game cannot continue and has to exit.", "Northstar Wsock32 Proxy Error", 0);
return false;
}
auto launcherHandle = GetModuleHandleA("launcher.dll");
if (!launcherHandle)
{
- MessageBoxA(GetForegroundWindow(), "Launcher isn't loaded yet.\nThe game cannot continue and has to exit.", "Northstar Wsock32 Proxy Error", 0);
+ MessageBoxA(
+ GetForegroundWindow(),
+ "Launcher isn't loaded yet.\nThe game cannot continue and has to exit.",
+ "Northstar Wsock32 Proxy Error",
+ 0);
return false;
}
HookEnabler hook;
- ENABLER_CREATEHOOK(hook, GetProcAddress(launcherHandle, "LauncherMain"), &LauncherMainHook, reinterpret_cast<LPVOID*>(&LauncherMainOriginal));
+ ENABLER_CREATEHOOK(
+ hook,
+ reinterpret_cast<void*>(GetProcAddress(launcherHandle, "LauncherMain")),
+ &LauncherMainHook,
+ reinterpret_cast<LPVOID*>(&LauncherMainOriginal));
return true;
-} \ No newline at end of file
+}
diff --git a/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj b/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj
index 9866d368..34a80c13 100644
--- a/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj
+++ b/loader_wsock32_proxy/loader_wsock32_proxy.vcxproj
@@ -60,7 +60,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
- <LanguageStandard>stdcpp17</LanguageStandard>
+ <LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>..\NorthstarDedicatedTest\</AdditionalIncludeDirectories>
</ClCompile>
<Link>
@@ -82,7 +82,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\NorthstarDedicatedTest\</AdditionalIncludeDirectories>
- <LanguageStandard>stdcpp17</LanguageStandard>
+ <LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
diff --git a/loader_wsock32_proxy/pch.h b/loader_wsock32_proxy/pch.h
index 0103ff59..6e8873a1 100644
--- a/loader_wsock32_proxy/pch.h
+++ b/loader_wsock32_proxy/pch.h
@@ -7,10 +7,10 @@
#ifndef PCH_H
#define PCH_H
-#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
#include "include/MinHook.h"
-#endif //PCH_H
+#endif // PCH_H