Use exact decorated symbol names verified against Minecraft.Client.pdb

Verified all hook targets exist in the compiled game's PDB:
- ?MinecraftWorld_RunStaticCtors@@YAXXZ
- ?tick@Minecraft@@QEAAX_N0@Z
- ?init@Minecraft@@QEAAXXZ
- ?ExitGame@CConsoleMinecraftApp@@UEAAXXZ (replaces destroy which is inlined)

Minecraft::destroy/run_end/stop are not public symbols (likely inlined),
so the shutdown hook now targets CConsoleMinecraftApp::ExitGame instead.
This commit is contained in:
Jacobwasbeast
2026-03-06 15:16:06 -06:00
parent de22a24100
commit 65ef99fc11
6 changed files with 67 additions and 95 deletions

View File

@@ -22,6 +22,7 @@ bool HookManager::Install(const SymbolResolver& symbols)
printf("[LegacyForge] Failed to hook RunStaticCtors\n");
return false;
}
printf("[LegacyForge] Hooked RunStaticCtors\n");
}
// Hook Minecraft::tick
@@ -34,6 +35,7 @@ bool HookManager::Install(const SymbolResolver& symbols)
printf("[LegacyForge] Failed to hook Minecraft::tick\n");
return false;
}
printf("[LegacyForge] Hooked Minecraft::tick\n");
}
// Hook Minecraft::init
@@ -46,17 +48,21 @@ bool HookManager::Install(const SymbolResolver& symbols)
printf("[LegacyForge] Failed to hook Minecraft::init\n");
return false;
}
printf("[LegacyForge] Hooked Minecraft::init\n");
}
// Hook Minecraft::destroy
if (symbols.pMinecraftDestroy)
// Hook CConsoleMinecraftApp::ExitGame (optional -- for graceful shutdown)
if (symbols.pExitGame)
{
if (MH_CreateHook(symbols.pMinecraftDestroy,
reinterpret_cast<void*>(&GameHooks::Hooked_MinecraftDestroy),
reinterpret_cast<void**>(&GameHooks::Original_MinecraftDestroy)) != MH_OK)
if (MH_CreateHook(symbols.pExitGame,
reinterpret_cast<void*>(&GameHooks::Hooked_ExitGame),
reinterpret_cast<void**>(&GameHooks::Original_ExitGame)) != MH_OK)
{
printf("[LegacyForge] Failed to hook Minecraft::destroy\n");
return false;
printf("[LegacyForge] Warning: Failed to hook ExitGame (shutdown hook unavailable)\n");
}
else
{
printf("[LegacyForge] Hooked ExitGame\n");
}
}