refactor(native): batch MinHook enable calls and log status codes
Switch ws2_32 and LocalMP hook installers to MH_QueueEnableHook with two MH_ApplyQueued passes (mandatory network hooks first, then all LocalMP modules), reducing DllMain thread-freeze cycles from 26 to 2. Roll back partial module hooks on error and log MH_StatusToString diagnostics to wto_ws.log. Checked: native/wto-net/build.ps1 compiles cleanly with zero warnings in project sources, and PE inspection confirms WS2_32/KERNEL32 imports and 49 exports. In-game verification pending.
This commit is contained in:
1 parent
90bd5a315d
commit
96077153c6
11 files changed
+120
-105
No files matched your search
@@ -20,12 +20,20 @@ static HMODULE g_ws2;
|
||||
int hook_export(const char *name, void *replacement, void **original)
|
||||
{
|
||||
void *target = (void *)GetProcAddress(g_ws2, name);
|
||||
MH_STATUS status;
|
||||
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);
|
||||
status = MH_CreateHook(target, replacement, original);
|
||||
if (status != MH_OK) {
|
||||
log_line("hook %s: MH_CreateHook failed (%s)", name, MH_StatusToString(status));
|
||||
return 0;
|
||||
}
|
||||
status = MH_QueueEnableHook(target);
|
||||
if (status != MH_OK) {
|
||||
log_line("hook %s: MH_QueueEnableHook failed (%s)", name, MH_StatusToString(status));
|
||||
MH_RemoveHook(target);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -33,12 +41,26 @@ int hook_export(const char *name, void *replacement, void **original)
|
||||
|
||||
static int install(void)
|
||||
{
|
||||
MH_STATUS status;
|
||||
/* 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)
|
||||
if (g_ws2 == NULL) {
|
||||
log_line("wto_ws: ws2_32.dll module handle unavailable");
|
||||
return 0;
|
||||
}
|
||||
status = MH_Initialize();
|
||||
if (status != MH_OK) {
|
||||
log_line("wto_ws: MH_Initialize failed (%s)", MH_StatusToString(status));
|
||||
return 0;
|
||||
}
|
||||
if (!install_resolver_hooks() || !install_connection_hooks())
|
||||
return 0;
|
||||
/* Enable all mandatory network hooks in one thread-freeze pass before touching LocalMP hooks. */
|
||||
status = MH_ApplyQueued();
|
||||
if (status != MH_OK) {
|
||||
log_line("wto_ws: MH_ApplyQueued for ws2_32 failed (%s)", MH_StatusToString(status));
|
||||
return 0;
|
||||
}
|
||||
install_local_mp_hooks();
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user