From 181f492a03603df795e3018e881f61b190a4bbcf Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 24 Apr 2016 22:00:51 +0200 Subject: [PATCH] Reduce stencil shadows memory usage --- SilentPatchSA/SilentPatchSA.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 42f30b7..2288696 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -863,6 +863,20 @@ void UpdateEscalators() } +static char** pStencilShadowsPad = *AddressByVersion(0x70FC4F, 0, 0); +void StencilShadowAlloc( ) +{ + static char* pMemory = nullptr; + if ( pMemory == nullptr ) + { + pMemory = static_cast( orgNewAlloc( 3 * 0x6000 ) ); + pStencilShadowsPad[0] = pMemory; + pStencilShadowsPad[1] = pMemory+0x6000; + pStencilShadowsPad[2] = pMemory+(2*0x6000); + } +} + + #include static void* pNVCShader = nullptr; @@ -2918,6 +2932,13 @@ void Patch_SA_10() orgEscalatorsUpdate = (void(*)())(*(int*)(pUpdateEscalators+1) + pUpdateEscalators + 5); InjectHook(0x7185B5, UpdateEscalators); InjectHook(0x71791F, &CEscalator::SwitchOffNoRemove); + + + // Don't allocate constant memory for stencil shadows every frame + InjectHook(0x711DD5, StencilShadowAlloc, PATCH_CALL); + Nop(0x711E0D, 3); + Patch(0x711DDA, 0x2CEB); + Patch(0x711E5F, 0x90C35D5F); // pop edi, pop ebp, ret