mirror of
https://gitea.tendokyu.moe/TeamTofuShop/segatools.git
synced 2026-09-22 22:37:59 +03:00
soul: Add network hooks
This commit is contained in:
@@ -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 */
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
void network_hook_init(struct platform_config* config);
|
||||
Reference in New Issue
Block a user