From 39df8343ca607b70ac083ed61db5ae3a2f939513 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 7 Dec 2019 19:29:08 +0100 Subject: [PATCH] III/VC: Remade static shadow alpha fix properly Now disables alpha test for these shadows instead of tweaking intensity "until it works" --- SilentPatch/Common.cpp | 32 +++++++++++++++++++++++++++++++ SilentPatch/RWGTA.cpp | 10 ++++++++++ SilentPatchIII/SilentPatchIII.cpp | 21 -------------------- SilentPatchVC/SilentPatchVC.cpp | 24 ----------------------- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp index f814ab6..0f0402f 100644 --- a/SilentPatch/Common.cpp +++ b/SilentPatch/Common.cpp @@ -42,6 +42,22 @@ namespace CoronaLinesFix } } +// ============= Static shadow alpha fix ============= +namespace StaticShadowAlphaFix +{ + static void (*orgRenderStaticShadows)(); + static void RenderStaticShadows_StateFix() + { + RwUInt32 alphaTestVal = 0; + RwD3D8GetRenderState( 15, &alphaTestVal ); // D3DRS_ALPHATESTENABLE + + RwD3D8SetRenderState( 15, FALSE ); + orgRenderStaticShadows(); + + RwD3D8SetRenderState( 15, alphaTestVal ); + } +}; + // ============= Delayed patches ============= namespace DelayedPatches { @@ -126,6 +142,22 @@ namespace Common { InjectHook( renderLine, RenderLine_SetRecipZ ); } + + // Fixed static shadows not rendering under fire and pickups + { + 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 ); + ReadCall( renderStaticShadows, orgRenderStaticShadows ); + InjectHook( renderStaticShadows, RenderStaticShadows_StateFix ); + } } void III_VC_SetDelayedPatchesFunc( void(*func)() ) diff --git a/SilentPatch/RWGTA.cpp b/SilentPatch/RWGTA.cpp index 15220a9..64b3456 100644 --- a/SilentPatch/RWGTA.cpp +++ b/SilentPatch/RWGTA.cpp @@ -35,6 +35,16 @@ void** GTARwEngineInstance = []() -> void** { return nullptr; }(); +static void* varRwD3D8SetRenderState = Memory::ReadCallFrom( hook::get_pattern( "0F 8C ? ? ? ? 6A 05 6A 19", 10 ) ); +WRAPPER RwBool RwD3D8SetRenderState(RwUInt32 state, RwUInt32 value) { VARJMP(varRwD3D8SetRenderState); } + +static RwUInt32* _rwD3D8RenderStates = *static_cast(Memory::ReadCallFrom( hook::get_pattern( "0F 8C ? ? ? ? 6A 05 6A 19", 10 ), 8 + 3 )); +void RwD3D8GetRenderState(RwUInt32 state, void* value) +{ + RwUInt32* valuePtr = static_cast(value); + *valuePtr = _rwD3D8RenderStates[ 2 * state ]; +} + RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2) { diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index 6fdc3f4..ffb9e7c 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -551,13 +551,6 @@ void Patch_III_10(const RECT& desktop) Patch(0x490F83, 1); - Patch(0x43177D, 16); - Patch(0x431DBB, 16); - Patch(0x432083, 16); - Patch(0x432303, 16); - Patch(0x479C9A, 16); - Patch(0x4FAD35, 16); - Patch(0x5382BF, 0x0EEB); InjectHook(0x5382EC, HeadlightsFix, PATCH_JUMP); @@ -696,13 +689,6 @@ void Patch_III_11(const RECT& desktop) Patch(0x491043, 1); - Patch(0x43177D, 16); - Patch(0x431DBB, 16); - Patch(0x432083, 16); - Patch(0x432303, 16); - Patch(0x479C9A, 16); - Patch(0x4FAE15, 16); - Patch(0x5384FF, 0x0EEB); InjectHook(0x53852C, HeadlightsFix, PATCH_JUMP); @@ -820,13 +806,6 @@ void Patch_III_Steam(const RECT& desktop) Patch(0x490FD3, 1); - Patch(0x43177D, 16); - Patch(0x431DBB, 16); - Patch(0x432083, 16); - Patch(0x432303, 16); - Patch(0x479C9A, 16); - Patch(0x4FADA5, 16); - InjectHook(0x4A58F0, ShowRadarTrace, PATCH_JUMP); InjectHook(0x4209A7, SetScaleProperly); InjectHook(0x420A1F, SetScaleProperly); diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 80d47ec..605b0d3 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -379,14 +379,6 @@ void Patch_VC_10(const RECT& desktop) RosieAudioFix_JumpBack = (void*)0x42BFFE; SubtitlesShadowFix_JumpBack = (void*)0x551701; - Patch(0x43E983, 16); - Patch(0x43EC03, 16); - Patch(0x43EECB, 16); - Patch(0x43F52B, 16); - Patch(0x43F842, 16); - Patch(0x48EB27, 16); - Patch(0x541E7E, 16); - InjectHook(0x5433BD, FixedRefValue); InjectHook(0x42BFF7, RosiesAudioFix, PATCH_JUMP); @@ -494,14 +486,6 @@ void Patch_VC_11(const RECT& desktop) RosieAudioFix_JumpBack = (void*)0x42BFFE; SubtitlesShadowFix_JumpBack = (void*)0x551721; - Patch(0x43E983, 16); - Patch(0x43EC03, 16); - Patch(0x43EECB, 16); - Patch(0x43F52B, 16); - Patch(0x43F842, 16); - Patch(0x48EB37, 16); - Patch(0x541E9E, 16); - InjectHook(0x5433DD, FixedRefValue); InjectHook(0x42BFF7, RosiesAudioFix, PATCH_JUMP); @@ -599,14 +583,6 @@ void Patch_VC_Steam(const RECT& desktop) RosieAudioFix_JumpBack = (void*)0x42BFCE; SubtitlesShadowFix_JumpBack = (void*)0x5515F1; - Patch(0x43E8F3, 16); - Patch(0x43EB73, 16); - Patch(0x43EE3B, 16); - Patch(0x43F49B, 16); - Patch(0x43F7B2, 16); - Patch(0x48EA37, 16); - Patch(0x541D6E, 16); - InjectHook(0x5432AD, FixedRefValue); InjectHook(0x42BFC7, RosiesAudioFix, PATCH_JUMP);