Replace file overwrite with CreateFileW hook for mod texture loading

Instead of backing up and overwriting vanilla terrain.png/items.png,
hook CreateFileW to redirect file opens to merged atlases in
mods/ModLoader/generated/. The hook is active only during init and
removed once textures are loaded into GPU memory. Vanilla game files
are never modified.
This commit is contained in:
Jacobwasbeast
2026-03-07 00:14:06 -06:00
parent 455abc155a
commit b2664e0f19
4 changed files with 111 additions and 60 deletions

View File

@@ -157,12 +157,15 @@ namespace GameHooks
ModAtlas::BuildAtlases(base + "mods", gameResPath);
atlas_done:
// Overwrite the game's atlas PNGs with our merged versions BEFORE init
// loads them. The originals are backed up and restored after init.
ModAtlas::InstallAtlasFiles(gameResPath);
// Redirect terrain.png/items.png file opens to our merged atlases
// so the game loads mod textures without modifying vanilla files.
ModAtlas::InstallCreateFileHook(gameResPath);
Original_MinecraftInit(thisPtr);
// Textures are loaded into GPU memory now; remove the redirect.
ModAtlas::RemoveCreateFileHook();
// After init, vanilla icons have their source-image pointer (field_0x48)
// fully populated. Copy it to our mod icons so getSourceHeight() works.
ModAtlas::FixupModIcons();