Files
WT-Offline/native/wto-net/src/dll_main.c
T
N0VAN0M4LY 2428b34497 feat(native): route client traffic to the loopback service
Build the socket library and client-local port configuration for redirecting
traffic to the offline service. Accept HTTPS and the existing matching and
HTTP protocols on the same port. Route requests by the original host.
2026-11-25 05:02:34 +08:00

58 lines
1.9 KiB
C

/*
* wto_ws.dll: the network hook library of WTOffline.
*
* aces.exe imports its network functions from this DLL instead of WS2_32.dll
* (exe-patches/online/network-hook-library). Every export is forwarded to the system's
* ws2_32.dll (wto_ws.def); on load the DLL hooks the resolution, connection and datagram
* functions of the system's ws2_32.dll itself with MinHook, so the calls of every module in
* the process pass through the hooks, not only the executable's.
*
* If the hooks cannot be installed the DLL fails to load and the game does not start: running
* unhooked would let the game reach Gaijin's servers.
*/
#include "hooks.h"
#include "hook_config.h"
#include "MinHook.h"
static HMODULE g_ws2;
int hook_export(const char *name, void *replacement, void **original)
{
void *target = (void *)GetProcAddress(g_ws2, name);
if (target == NULL) {
log_line("hook %s: not exported by ws2_32.dll", name);
return 0;
}
if (MH_CreateHook(target, replacement, original) != MH_OK || MH_EnableHook(target) != MH_OK) {
log_line("hook %s: failed", name);
return 0;
}
return 1;
}
static int install(void)
{
/* ws2_32.dll is already loaded: this DLL links against it. */
g_ws2 = GetModuleHandleW(L"ws2_32.dll");
if (g_ws2 == NULL || MH_Initialize() != MH_OK)
return 0;
return install_resolver_hooks() && install_connection_hooks();
}
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
{
(void)reserved;
if (reason != DLL_PROCESS_ATTACH)
return TRUE;
DisableThreadLibraryCalls(instance);
config_load(instance);
if (!install()) {
/* Failing DllMain makes the loader refuse to start the game. */
log_line("wto_ws: hooks not installed, refusing to load so the game cannot go online");
return FALSE;
}
log_line("wto_ws: hooks installed");
return TRUE;
}