Lyall / MGSHDFix

A fix that adds custom resolutions, ultrawide support and much more to the Metal Gear Solid Master Collection.
MIT License
376 stars 8 forks source link

MG1/2 | MGS3: Add patches to extend texture buffer size #39

Closed emoose closed 8 months ago

emoose commented 8 months ago

Fixes #15

Allows extending the temporary texture buffer that both MG1/2 & MGS3 seem to use, allowing larger texture files to be loaded into the game.

Seems MGS2 doesn't use this kind of temporary buffer, all the same CTexture/CBaseTexture code is there but the code around this temporary buffer stuff is missing, weird (maybe after they worked on MGS2 they added this buffer trick as an optimization during MGS3 work, but then forgot to backport it to MGS2, who knows)

MG1/2 does include the same buffer code but doubtful it can make much difference there, still added it just in case someone wants to use a 50MB intro logo or something :P

Haven't tried comparing memory usage with this yet, AFAIK it should only be allocing the main buffer once per session, so would add 128 - 16 = ~112MB extra usage, there is that weird mip count part which I'm not sure of though, maybe would increase it more.

One small worry with this is that it's kinda tying data files with HDFix, if you installed HDFix along with a larger-than-16MB texture pack, removing HDFix while keeping the texture pack files would cause crashing in the vanilla game...
Can't really see much way to get around that though, and guess users can always verify files in steam to fix it, so maybe not a huge problem.

emoose commented 8 months ago

Seems some are still reporting crashes with larger textures even with this patch enabled, while others have it working fine, guessing it could be related to the timing issues I mentioned in the launcher config thread, game might already be creating texture buffer before we had a chance to patch the size.

~~The "fix" of just running everything from DllMain instead of creating new thread might help with it, here's a build if anyone wants to try (replace the MGSHDFix 0.9 asi with the one here), please let me know here or on NexusMods if it stops the crashing for you: MGSHDFix_0.9_DllMainHack.zip~~

Running from DllMain still isn't ideal though, looking into whether we can hook any of the imports that game calls early on instead.

E: should have a better solution using a IAT hook to load us in instead, seems to work across all the games fine for me, if anyone had crash issues with textures before please give it a try (install on top of MGSHDFix 0.9) MGSHDFix_0.9_IATHook.zip

Code for that is at https://github.com/emoose/MGSHDFix/commit/3dc37b1fde131b77f86adcaccffb4de1b3d49f0b

Klemci commented 8 months ago

You fixed it !

9700F 3060XC (12gb)