diff --git a/games/soulhook/dllmain.c b/games/soulhook/dllmain.c index 2fe3765..0b1378f 100644 --- a/games/soulhook/dllmain.c +++ b/games/soulhook/dllmain.c @@ -40,6 +40,7 @@ #include "soulhook/io4.h" #include "soulhook/soul-dll.h" #include "soulhook/soul-gfx.h" +#include "soulhook/network.h" #include "platform/platform.h" @@ -68,6 +69,7 @@ static DWORD CALLBACK soul_pre_startup(void) touch_screen_hook_init(&soul_hook_cfg.touch, soul_hook_mod); serial_hook_init(); soulgfx_hook_init(); + network_hook_init(&soul_hook_cfg.platform); /* Hook external DLL APIs */ diff --git a/games/soulhook/meson.build b/games/soulhook/meson.build index 1a2eccb..f7f5803 100644 --- a/games/soulhook/meson.build +++ b/games/soulhook/meson.build @@ -24,6 +24,8 @@ shared_library( 'dllmain.c', 'io4.c', 'io4.h', + 'network.c', + 'network.h', 'soul-dll.c', 'soul-dll.h', 'soul-gfx.c', diff --git a/games/soulhook/network.c b/games/soulhook/network.c new file mode 100644 index 0000000..515bc01 --- /dev/null +++ b/games/soulhook/network.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +#include "hook/table.h" + +#include "hooklib/dll.h" + +#include "util/dprintf.h" + +#include "platform/platform.h" + +#include "network.h" + +static int hook_bind(SOCKET s, const struct sockaddr* addr, int namelen); +static int (*next_bind)(SOCKET s, const struct sockaddr* addr, int namelen); +static int local_ip; + +static const struct hook_symbol network_syms[] = {{ + .name = "bind", + .ordinal = 2, + .patch = hook_bind, + .link = (void**)&next_bind, +}}; + +void network_hook_init(struct platform_config* config) +{ + if (config->netenv.enable) { + dprintf("Network: Hooks enabled.\n"); + + local_ip = htonl(config->nusec.subnet | config->netenv.addr_suffix); + + hook_table_apply( + NULL, + "ws2_32.dll", + network_syms, + _countof(network_syms)); + } +} + +static int hook_bind(SOCKET s, const struct sockaddr* addr, int namelen) { + if (addr->sa_family == AF_INET) { + struct sockaddr_in* addr_in = (struct sockaddr_in*)addr; + + if (!memcmp(&addr_in->sin_addr, &local_ip, 4)) { + ZeroMemory(&addr_in->sin_addr, sizeof(struct in_addr)); + } + } + + return next_bind(s, addr, namelen); +} diff --git a/games/soulhook/network.h b/games/soulhook/network.h new file mode 100644 index 0000000..1c742d1 --- /dev/null +++ b/games/soulhook/network.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void network_hook_init(struct platform_config* config);