From 2be613a75bf9e4ea4119da8d1f346cb1d94d6b1e Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 8 Dec 2019 12:27:33 +0100 Subject: [PATCH] III/VC/SA: Disable alpha test for stored shadows too --- SilentPatch/Common.cpp | 19 +++++++++++++++++-- SilentPatchSA/SilentPatchSA.cpp | 21 ++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp index 0f0402f..ddefa14 100644 --- a/SilentPatch/Common.cpp +++ b/SilentPatch/Common.cpp @@ -56,6 +56,18 @@ namespace StaticShadowAlphaFix RwD3D8SetRenderState( 15, alphaTestVal ); } + + static void (*orgRenderStoredShadows)(); + static void RenderStoredShadows_StateFix() + { + RwUInt32 alphaTestVal = 0; + RwD3D8GetRenderState( 15, &alphaTestVal ); // D3DRS_ALPHATESTENABLE + + RwD3D8SetRenderState( 15, FALSE ); + orgRenderStoredShadows(); + + RwD3D8SetRenderState( 15, alphaTestVal ); + } }; // ============= Delayed patches ============= @@ -147,16 +159,19 @@ namespace Common { { using namespace StaticShadowAlphaFix; - // TODO: Offset for III #if _GTA_III constexpr ptrdiff_t offset = 0xF; #elif _GTA_VC constexpr ptrdiff_t offset = 0x14; #endif - void* renderStaticShadows = ReadCallFrom( get_pattern( "E8 ? ? ? ? A1 ? ? ? ? 85 C0 74 05" ), offset ); + uintptr_t renderStaticShadows = reinterpret_cast(ReadCallFrom( get_pattern( "E8 ? ? ? ? A1 ? ? ? ? 85 C0 74 05" ), offset )); ReadCall( renderStaticShadows, orgRenderStaticShadows ); InjectHook( renderStaticShadows, RenderStaticShadows_StateFix ); + + renderStaticShadows += 5; + ReadCall( renderStaticShadows, orgRenderStoredShadows ); + InjectHook( renderStaticShadows, RenderStoredShadows_StateFix ); } } diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index a4844aa..e7d56ac 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1627,6 +1627,15 @@ namespace StaticShadowAlphaFix RwRenderStateSet( rwRENDERSTATEALPHATESTFUNCTION, (void*)rwALPHATESTFUNCTIONALWAYS ); orgRenderStaticShadows(); } + + static void (*orgRenderStoredShadows)(); + static void RenderStoredShadows_StateFix() + { + RwScopedRenderState state(rwRENDERSTATEALPHATESTFUNCTION); + + RwRenderStateSet( rwRENDERSTATEALPHATESTFUNCTION, (void*)rwALPHATESTFUNCTIONALWAYS ); + orgRenderStoredShadows(); + } }; // ============= LS-RP Mode stuff ============= @@ -4210,6 +4219,9 @@ void Patch_SA_10() ReadCall( 0x53E0C3, orgRenderStaticShadows ); InjectHook( 0x53E0C3, RenderStaticShadows_StateFix ); + + ReadCall( 0x53E0C8, orgRenderStoredShadows ); + InjectHook( 0x53E0C8, RenderStoredShadows_StateFix ); } #if FULL_PRECISION_D3D @@ -5647,9 +5659,12 @@ void Patch_SA_NewBinaries_Common() { using namespace StaticShadowAlphaFix; - auto renderStaticShadows = get_pattern( "52 E8 ? ? ? ? E8 ? ? ? ? E8", 1 + 5 + 5 ); - ReadCall( renderStaticShadows, orgRenderStaticShadows ); - InjectHook( renderStaticShadows, RenderStaticShadows_StateFix ); + auto renderStaticShadows = pattern( "52 E8 ? ? ? ? E8 ? ? ? ? E8" ).get_one(); + ReadCall( renderStaticShadows.get( 1 + 5 + 5 ), orgRenderStaticShadows ); + InjectHook( renderStaticShadows.get( 1 + 5 + 5 ), RenderStaticShadows_StateFix ); + + ReadCall( renderStaticShadows.get( 1 + 5 + 5 + 5 ), orgRenderStoredShadows ); + InjectHook( renderStaticShadows.get( 1 + 5 + 5 + 5 ), RenderStoredShadows_StateFix ); } }