III/VC: Remade static shadow alpha fix to be compatible with SkyGfx

This commit is contained in:
Silent 2019-12-23 22:49:00 +01:00
parent fe37cd7c88
commit 4959204f53
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 42 additions and 24 deletions

View File

@ -45,28 +45,23 @@ namespace CoronaLinesFix
// ============= Static shadow alpha fix ============= // ============= Static shadow alpha fix =============
namespace StaticShadowAlphaFix namespace StaticShadowAlphaFix
{ {
static void (*orgRenderStaticShadows)(); static RwUInt32 alphaTestVal;
static void RenderStaticShadows_StateFix()
{
RwUInt32 alphaTestVal = 0;
RwD3D8GetRenderState( 15, &alphaTestVal ); // D3DRS_ALPHATESTENABLE
RwD3D8SetRenderState( 15, FALSE );
orgRenderStaticShadows();
RwD3D8SetRenderState( 15, alphaTestVal ); static RwBool RenderStateSet_StoreAlphaTest( RwRenderState state, void* value )
{
RwD3D8GetRenderState( 15, &alphaTestVal ); // D3DRS_ALPHATESTENABLE
RwD3D8SetRenderState( 15, FALSE );
return RwRenderStateSet( state, value );
} }
static void (*orgRenderStoredShadows)(); static RwBool RenderStateSet_RestoreAlphaTest( RwRenderState state, void* value )
static void RenderStoredShadows_StateFix()
{ {
RwUInt32 alphaTestVal = 0; RwBool result = RwRenderStateSet( state, value );
RwD3D8GetRenderState( 15, &alphaTestVal ); // D3DRS_ALPHATESTENABLE
RwD3D8SetRenderState( 15, FALSE );
orgRenderStoredShadows();
RwD3D8SetRenderState( 15, alphaTestVal ); RwD3D8SetRenderState( 15, alphaTestVal );
return result;
} }
}; };
@ -185,18 +180,36 @@ namespace Common {
using namespace StaticShadowAlphaFix; using namespace StaticShadowAlphaFix;
#if _GTA_III #if _GTA_III
constexpr ptrdiff_t offset = 0xF; void* disableAlphaTestAndSetState[] = {
get_pattern( "E8 ? ? ? ? 59 59 6A 00 6A 0E E8 ? ? ? ? 31 C0" ),
get_pattern( "E8 ? ? ? ? 0F B7 2D ? ? ? ? 31 C0" )
};
void* setStateAndReenableAlphaTest[] = {
get_pattern( "E8 ? ? ? ? 59 59 6A 01 6A 08 E8 ? ? ? ? 59 59 83 C4 38" ),
get_pattern( "39 44 24 38 0F 8C ? ? ? ? 6A 00 6A 0C", 14 )
};
#elif _GTA_VC #elif _GTA_VC
constexpr ptrdiff_t offset = 0x14; void* disableAlphaTestAndSetState[] = {
get_pattern( "E8 ? ? ? ? 59 59 6A 00 6A 0E E8 ? ? ? ? 31 C0" ),
get_pattern( "6A 01 6A 0C E8 ? ? ? ? 59 59 6A 03", 4 )
};
void* setStateAndReenableAlphaTest[] = {
get_pattern( "0F 77 6A 00 6A 0C E8 ? ? ? ? 59", 6 ),
get_pattern( "39 44 24 34 0F 8C ? ? ? ? 6A 00 6A 0C", 14 )
};
#endif #endif
uintptr_t renderStaticShadows = reinterpret_cast<uintptr_t>(ReadCallFrom( get_pattern( "E8 ? ? ? ? A1 ? ? ? ? 85 C0 74 05" ), offset )); for ( auto match : disableAlphaTestAndSetState )
ReadCall( renderStaticShadows, orgRenderStaticShadows ); {
InjectHook( renderStaticShadows, RenderStaticShadows_StateFix ); InjectHook( match, RenderStateSet_StoreAlphaTest );
}
renderStaticShadows += 5; for ( auto match : setStateAndReenableAlphaTest )
ReadCall( renderStaticShadows, orgRenderStoredShadows ); {
InjectHook( renderStaticShadows, RenderStoredShadows_StateFix ); InjectHook( match, RenderStateSet_RestoreAlphaTest );
}
} }
// Corrected taxi light placement for Taxi // Corrected taxi light placement for Taxi

View File

@ -45,6 +45,11 @@ void RwD3D8GetRenderState(RwUInt32 state, void* value)
*valuePtr = _rwD3D8RenderStates[ 2 * state ]; *valuePtr = _rwD3D8RenderStates[ 2 * state ];
} }
RwBool RwRenderStateSet(RwRenderState state, void *value)
{
return GTARWSRCGLOBAL(dOpenDevice).fpRenderStateSet( state, value );
}
RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2) RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2)
{ {