Skip to content

Support loading texture from loose files#1669

Open
hcdd0304 wants to merge 5 commits intopraydog:masterfrom
hcdd0304:loose_tex_load_n
Open

Support loading texture from loose files#1669
hcdd0304 wants to merge 5 commits intopraydog:masterfrom
hcdd0304:loose_tex_load_n

Conversation

@hcdd0304
Copy link
Copy Markdown
Contributor

Fix #1227

  • Separate module: LooseTextureLoader (not putting it in LooseFileLoader) since the logic is not small
  • Rely on semantic and strings to search for needed hooks, avoid byte patterns
  • Works from TDB_VER >= 81, people on Haven Discord tested it on MHWilds and RE9 (#re-coding)

Intentions

  • Textures from new RE Engine games can only be loaded by packing in PAK file, they will fail to load if they are loose files
  • Allowing loose file texture to load, which enables modders to iterate and make changes during their mod-making process more quickly

Logic overview

Try to be as non-intrusive as possible by loading a loose texture file using the game's existing texture load path (DirectStorage)

  1. Force creation of an IDStorageFile handle from the game, by bypassing the "sub_000.pak" path check: hook handle_path_check_to_open_dstorage_file_wrapper
    • Engine code only creates IDStorageFile if the filename contains "sub_000.pak"
  2. During the function where the game prepares texture upload, fake our texture file to make it seem like the file is inside the PAK , by setting a fake metadata: hook handle_prepare_enqueue_texture_upload
    • Engine code checks if the texture's file stream contains PAK file entry's metadata or not. We have to fake that metadata.
    • The structure of the metadata depends on reverse engineering, it's quite hard to build offsets and elements of that struct at runtime
    • IMPORTANT: Faking that metadata requires valid IDStorageFile handle, that's why step 1 is necessary
  3. When the game starts to enqueue texture upload, revert the fake metadata we just set to our texture file: hook handle_start_enqueue_texture_upload
    • If we dont, other functions of the engine use it, and crash the game
  4. When the texture is done uploading, the file stream is closed, which automatically closes both Win32 file handle and IDStorageFile, so we don't need to worry about file handle leaking

Logic allows disabling the texture cache (RE Engine)

  • Textures and resources in general are cached by their XXHash of the paths, to avoid frequent resource recreation from disk
  • Allow disabling the cache by making each create_resource call have a unique XXHash value (see hook handle_resource_hash_path)
  • This is not efficient, but its the least intrusive, maintainable path, and this feature is only intended for modders anyway

@praydog
Copy link
Copy Markdown
Owner

praydog commented Mar 22, 2026

This should definitely be part of LooseFileLoader, or at least be enabled with it. Not separate menu options. Everything should be under LooseFileLoader.

@hcdd0304
Copy link
Copy Markdown
Contributor Author

I still keep it a separate class, since I feel embedding it will bloat LooseFileLoader a lot. But its now owned by LooseFileLoader, not a separate Mod anymore. Let me know if embedding it is better option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MHWILDS game never reaches menu when having loose textures

2 participants