diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp index 790cc80..f814ab6 100644 --- a/SilentPatch/Common.cpp +++ b/SilentPatch/Common.cpp @@ -4,6 +4,9 @@ #include "Utils/Patterns.h" #include "StoredCar.h" +#include + +RwCamera*& Camera = **hook::get_pattern( "A1 ? ? ? ? D8 88 ? ? ? ?", 1 ); // ============= handling.cfg name matching fix ============= namespace HandlingNameLoadFix @@ -19,6 +22,26 @@ namespace HandlingNameLoadFix } }; +// ============= Corona lines rendering fix ============= +namespace CoronaLinesFix +{ + static RwBool RenderLine_SetRecipZ( RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2 ) + { + const RwReal nearScreenZ = RwIm2DGetNearScreenZ(); + const RwReal nearZ = RwCameraGetNearClipPlane( Camera ); + const RwReal recipZ = 1.0f / nearZ; + + for ( RwInt32 i = 0; i < numVertices; i++ ) + { + RwIm2DVertexSetScreenZ( &vertices[i], nearScreenZ ); + RwIm2DVertexSetCameraZ( &vertices[i], nearZ ); + RwIm2DVertexSetRecipCameraZ( &vertices[i], recipZ ); + } + + return RwIm2DRenderLine( vertices, numVertices, vert1, vert2 ); + } +} + // ============= Delayed patches ============= namespace DelayedPatches { @@ -92,6 +115,17 @@ namespace Common { InjectHook( findExactWord.get( -5 ), strncpy_Fix ); InjectHook( findExactWord.get( 0xD ), strncmp_Fix ); } + + + // Fixed corona lines rendering on non-nvidia cards + { + using namespace CoronaLinesFix; + + auto renderLine = get_pattern( "E8 ? ? ? ? 83 C4 10 FF 44 24 1C 43" ); + + InjectHook( renderLine, RenderLine_SetRecipZ ); + } + } void III_VC_SetDelayedPatchesFunc( void(*func)() ) diff --git a/SilentPatch/RWGTA.cpp b/SilentPatch/RWGTA.cpp index 922a1a9..15220a9 100644 --- a/SilentPatch/RWGTA.cpp +++ b/SilentPatch/RWGTA.cpp @@ -34,3 +34,14 @@ void** GTARwEngineInstance = []() -> void** { assert(!"Could not locate RwEngineInstance!"); return nullptr; }(); + + +RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2) +{ + return GTARWSRCGLOBAL(dOpenDevice).fpIm2DRenderLine( vertices, numVertices, vert1, vert2 ); +} + +RwReal RwIm2DGetNearScreenZ() +{ + return GTARWSRCGLOBAL(dOpenDevice).zBufferNear; +} \ No newline at end of file