Initial commit: LegacyForge mod loader for Minecraft Legacy Edition

SKSE-style external mod loader with zero game source modifications.
- LegacyForge.Launcher: C# console app that injects runtime DLL into game process
- LegacyForgeRuntime: C++ DLL with PDB symbol resolution, MinHook function hooking, and .NET CoreCLR hosting
- LegacyForge.Core: C# mod discovery and lifecycle management
- LegacyForge.API: Fabric-style mod API with namespaced string IDs, fluent property builders, and event system
- ExampleMod: Sample mod demonstrating block/item registration
This commit is contained in:
Jacobwasbeast
2026-03-06 15:11:53 -06:00
commit de22a24100
45 changed files with 2489 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
#include "HookManager.h"
#include "GameHooks.h"
#include "SymbolResolver.h"
#include <MinHook.h>
#include <cstdio>
bool HookManager::Install(const SymbolResolver& symbols)
{
if (MH_Initialize() != MH_OK)
{
printf("[LegacyForge] MH_Initialize failed\n");
return false;
}
// Hook MinecraftWorld_RunStaticCtors
if (symbols.pRunStaticCtors)
{
if (MH_CreateHook(symbols.pRunStaticCtors,
reinterpret_cast<void*>(&GameHooks::Hooked_RunStaticCtors),
reinterpret_cast<void**>(&GameHooks::Original_RunStaticCtors)) != MH_OK)
{
printf("[LegacyForge] Failed to hook RunStaticCtors\n");
return false;
}
}
// Hook Minecraft::tick
if (symbols.pMinecraftTick)
{
if (MH_CreateHook(symbols.pMinecraftTick,
reinterpret_cast<void*>(&GameHooks::Hooked_MinecraftTick),
reinterpret_cast<void**>(&GameHooks::Original_MinecraftTick)) != MH_OK)
{
printf("[LegacyForge] Failed to hook Minecraft::tick\n");
return false;
}
}
// Hook Minecraft::init
if (symbols.pMinecraftInit)
{
if (MH_CreateHook(symbols.pMinecraftInit,
reinterpret_cast<void*>(&GameHooks::Hooked_MinecraftInit),
reinterpret_cast<void**>(&GameHooks::Original_MinecraftInit)) != MH_OK)
{
printf("[LegacyForge] Failed to hook Minecraft::init\n");
return false;
}
}
// Hook Minecraft::destroy
if (symbols.pMinecraftDestroy)
{
if (MH_CreateHook(symbols.pMinecraftDestroy,
reinterpret_cast<void*>(&GameHooks::Hooked_MinecraftDestroy),
reinterpret_cast<void**>(&GameHooks::Original_MinecraftDestroy)) != MH_OK)
{
printf("[LegacyForge] Failed to hook Minecraft::destroy\n");
return false;
}
}
if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK)
{
printf("[LegacyForge] MH_EnableHook(MH_ALL_HOOKS) failed\n");
return false;
}
printf("[LegacyForge] All hooks installed and enabled\n");
return true;
}
void HookManager::Cleanup()
{
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
}