Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture buffer size increase from 16MiB #15

Closed
emoose opened this issue Oct 29, 2023 · 5 comments · Fixed by #39
Closed

Texture buffer size increase from 16MiB #15

emoose opened this issue Oct 29, 2023 · 5 comments · Fixed by #39

Comments

@emoose
Copy link
Contributor

emoose commented Oct 29, 2023

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:

image

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!

@emoose
Copy link
Contributor Author

emoose commented Oct 29, 2023

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.

@ShizCalev
Copy link
Contributor

ShizCalev commented Oct 29, 2023

(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

@liqMix
Copy link

liqMix commented Oct 30, 2023

@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

@emoose
Copy link
Contributor Author

emoose commented Nov 1, 2023

@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 5f67637, added INI stuff there too, maybe will wait to see if this does help with larger textures first before PRing.

@liqMix
Copy link

liqMix commented Nov 2, 2023

@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.

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 a pull request may close this issue.

3 participants