Closed emoose closed 8 months ago
Changing that size seems to work, at least with a modded konami_720.ctxr file I made, vanilla game would crash at intro logos but patching that size to 4x 16MiB let it work (still would like to test with a proper ctxr file larger than 16MB though, if anyone has one...)
For that it needs 8 different spots patched tho, luckily all use the same pattern, but I'm not sure if the pattern scan code here would allow fetching multiple results? Maybe would need to add something like https://github.com/ThirteenAG/Hooking.Patterns in.
(still would like to test with a proper ctxr file larger than 16MB though, if anyone has one...)
This lets you convert CTXR's to PNG and vice versa, can use it to generate any size you need while testing. :> https://github.com/316austin316/CTXR-Converter
@emoose Here's an example of a >16MB ctxr. It's Snake's default camo sized up at around ~22MB https://litter.catbox.moe/xmf6dq.rar
@liqMix hm, does that crash for you when you load it in? Seemed to work fine in vanilla for me, maybe my game didn't load that camo or something.
Was able to get a patch working for all those malloc spots, if you want to try it here's a build which patches the buffer from 16MiB to 128MiB: MGSHDFix_0.8_MGS3TextureBufferTest.zip (there's no INI setting in this build, will always try patching buffer to 128)
With that my modded ~30MB konami_720.ctxr loads in without crashing, strangely couldn't find those mallocs inside MGS2, so this is MGS3 only atm. Looks like MGS2 maybe allocs buffers for each texture individually while MGS3 allocates this big chunk and then temporarily loads textures into it, do you know if MGS2 has any issue with larger texture files?
E: code for that at https://github.com/Lyall/MGSHDFix/commit/5f67637dae47c3988d359ff96242330e19ae9c99, added INI stuff there too, maybe will wait to see if this does help with larger textures first before PRing.
@emoose Wow! Thank you. That absolutely worked. With this I was able to load in these 4x textures with all their mipmaps. There's several that are around ~85mb and many more above 16mb and I was able to load them without crashing.
Game apparently has a hardcoded texture size limit of 16MiB, mods like https://www.nexusmods.com/metalgearsolidmastercollection/mods/29 have mentioned running into this limit already.
In MGS3 it seems there's a CTextureBuffer class which then gets some buffer part of it malloc'd to 16777216 bytes, possible this is the cause of the texture size limit. At 0x140046BE0 is a GetInstance function that returns the instance of that class, and xrefs to that function then seem to handle mallocing that buffer themselves, eg:
Seems there's around ~6 spots in MGS3 with identical code to above (though I think the buffer is only allocated once per session)
I'm not really sure what files need to be changed for it to crash with >16MB textures though, if anyone has a modded file that does cause crashing an upload would be appreciated to test with!