From 53debb778bc1a4fe2141e228bccadf17051b33a8 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 28 Sep 2017 21:43:16 +0200 Subject: [PATCH] Removed two pass rendering --- SilentPatchSA/SilentPatchSA.cpp | 290 ++++---------------------------- 1 file changed, 32 insertions(+), 258 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 2a4e388..26fbb6b 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -283,7 +283,6 @@ RpHAnimHierarchy* (*GetAnimHierarchyFromSkinClump)(RpClump*) = AddressByVersion auto InitializeUtrax = AddressByVersion(0x4F35B0, 0x4F3A10, 0x4FFA80); auto CanSeeOutSideFromCurrArea = AddressByVersion(0x53C4A0, 0x53C940, 0x54E440); -auto __rwD3D9TextureHasAlpha = AddressByVersion(0x4C9EA0, 0x4CA090, 0x4D47E0); auto RenderOneXLUSprite = AddressByVersion(0x70D000, 0x70D830, 0x7592C0); static void (__thiscall* SetVolume)(void*,float); @@ -301,7 +300,6 @@ void** rwengine = *AddressByVersion(0x58FFC0, 0x53F032, 0x48C194, 0 unsigned char& nGameClockDays = **AddressByVersion(0x4E841D, 0x4E886D, 0x4F3871); unsigned char& nGameClockMonths = **AddressByVersion(0x4E842D, 0x4E887D, 0x4F3861); void*& pUserTracksStuff = **AddressByVersion(0x4D9B7B, 0x4DA06C, 0x4E4A43); -bool& CCutsceneMgr__ms_running = **AddressByVersion(0x53F92D, 0x434241, 0x422061); float& fFarClipZ = **AddressByVersion(0x70D21F, 0x70DA4F, 0x421AB2); RwTexture** const gpCoronaTexture = *AddressByVersion(0x6FAA8C, 0x6FB2BC, 0x5480BF); @@ -333,136 +331,15 @@ static struct // Regular functions -static bool AtomicAlphaTest( RpAtomic* atomic ) -{ - bool hasAlpha = false; - RpGeometryForAllMaterials( RpAtomicGetGeometry(atomic), [&hasAlpha]( RpMaterial* material ) -> RpMaterial* { - if ( RpMaterialGetTexture(material) != nullptr ) - { - if ( __rwD3D9TextureHasAlpha(RpMaterialGetTexture(material)) ) - { - hasAlpha = true; - return nullptr; - } - } - else if ( RpMaterialGetColor(material)->alpha < 255 ) - { - hasAlpha = true; - return nullptr; - } - - return material; - } ); - - return hasAlpha; -} - static RpAtomic* RenderAtomic(RpAtomic* pAtomic, float fComp) { UNREFERENCED_PARAMETER(fComp); return AtomicDefaultRenderCallBack(pAtomic); } -RpAtomic* OnePassAlphaRender(RpAtomic* atomic) +static RpAtomic* StaticPropellerRender(RpAtomic* pAtomic) { - BOOL nAlphaBlending; - - RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); - - atomic = AtomicDefaultRenderCallBack(atomic); - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); - return atomic; -} - -RpAtomic* TwoPassAlphaRender_aap(RpAtomic* atomic) -{ - // For cutscenes, fall back to one-pass render - if ( CCutsceneMgr__ms_running && !CanSeeOutSideFromCurrArea() ) - return AtomicDefaultRenderCallBack(atomic); - - int nPushedAlpha, nAlphaFunction; - int nAlphaBlending; - - RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); - RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); - RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); - - // 1st pass - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); - if (nPushedAlpha == 100) // or should we just force it? do we ever use something else anyway? - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(128)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONGREATEREQUAL)); - - atomic = AtomicDefaultRenderCallBack(atomic); - - if ( atomic != nullptr ) - { - // 2nd pass - int nZWrite; - RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); - - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - - atomic = AtomicDefaultRenderCallBack(atomic); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); - } - - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); - - return atomic; -} - -RpAtomic* TwoPassAlphaRender_Silent(RpAtomic* atomic) -{ - // For cutscenes, fall back to one-pass render - if ( CCutsceneMgr__ms_running && !CanSeeOutSideFromCurrArea() ) - return AtomicDefaultRenderCallBack(atomic); - - int nPushedAlpha, nAlphaFunction; - int nAlphaBlending; - - RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); - RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); - RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); - - // 1st pass - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(FALSE)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONEQUAL)); - - atomic = AtomicDefaultRenderCallBack(atomic); - - if ( atomic != nullptr ) - { - int nZWrite; - RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); - - // 2nd pass - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - - atomic = AtomicDefaultRenderCallBack(atomic); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); - } - - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); - - return atomic; -} - -RpAtomic* StaticPropellerRender(RpAtomic* pAtomic) -{ - int nPushedAlpha; + int nPushedAlpha; RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); @@ -473,17 +350,31 @@ RpAtomic* StaticPropellerRender(RpAtomic* pAtomic) return pAtomic; } -template -RpAtomic* RenderBigVehicleActomic(RpAtomic* pAtomic, float fComp) +static RpAtomic* MovingPropellerRender(RpAtomic* pAtomic) { - UNREFERENCED_PARAMETER(fComp); + int nPushedAlpha, nAlphaBlending; + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); + + pAtomic = AtomicDefaultRenderCallBack(pAtomic); + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); + return pAtomic; +} + +RpAtomic* RenderBigVehicleActomic(RpAtomic* pAtomic, float) +{ const char* pNodeName = GetFrameNodeName(RpAtomicGetFrame(pAtomic)); - if ( !strncmp(pNodeName, "moving_prop", 11) ) - return renderer(pAtomic); + if ( _strnicmp(pNodeName, "moving_prop", 11) == 0 ) + return MovingPropellerRender(pAtomic); - if ( !strncmp(pNodeName, "static_prop", 11) ) + if ( _strnicmp(pNodeName, "static_prop", 11) == 0 ) return StaticPropellerRender(pAtomic); return AtomicDefaultRenderCallBack(pAtomic); @@ -500,19 +391,6 @@ void RenderVehicleHiDetailAlphaCB_HunterDoor(RpAtomic* pAtomic) m_alphaList.InsertFront(NewObject); } -template -void SetRendererForAtomic(RpAtomic* pAtomic) -{ - if ( AtomicAlphaTest( pAtomic ) ) - RpAtomicSetRenderCallBack(pAtomic, renderer); -} - -template -void SetRendererForAtomic_NoTest(RpAtomic* pAtomic) -{ - RpAtomicSetRenderCallBack(pAtomic, renderer); -} - void RenderWeapon(CPed* pPed) { pPed->RenderWeapon(false, false); @@ -562,15 +440,6 @@ void RenderWeaponPedsForPC() RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); }*/ -template -RpAtomic* RenderPedCB(RpAtomic* pAtomic) -{ - if ( AtomicAlphaTest( pAtomic ) ) - return renderer(pAtomic); - - return AtomicDefaultRenderCallBack(pAtomic); -} - static CAEFLACDecoder* __stdcall DecoderCtor(CAEDataStream* pData) { return new CAEFLACDecoder(pData); @@ -2345,40 +2214,10 @@ BOOL InjectDelayedPatches_10() if ( !bSARender ) { // Twopass rendering (experimental) - int dwTwoPassMethod = GetPrivateProfileIntW(L"SilentPatch", L"TwoPassRendering", -1, wcModulePath); - if ( dwTwoPassMethod != -1 ) - { - Patch(0x4C441E, 0x57); - Patch(0x4C4424, 0x5F04C483); - Patch(0x4C4428, 0x0004C25E); - if ( dwTwoPassMethod == 1 ) - { - // Silent's twopass - InjectHook(0x4C441F, SetRendererForAtomic, PATCH_CALL); - Patch(0x7341D9, TwoPassAlphaRender_Silent); - Patch(0x734127, TwoPassAlphaRender_Silent); - Patch(0x73445E, RenderBigVehicleActomic); - // Twopass for peds - InjectHook(0x733614, RenderPedCB); - } - else if ( dwTwoPassMethod == 2 ) - { - // aap's twopass - InjectHook(0x4C441F, SetRendererForAtomic_NoTest, PATCH_CALL); - Patch(0x7341D9, TwoPassAlphaRender_aap); - Patch(0x734127, TwoPassAlphaRender_aap); - Patch(0x73445E, RenderBigVehicleActomic); - // Twopass for peds - InjectHook(0x733614, RenderPedCB); - } - else - { - Patch(0x7341D9, TwoPassAlphaRender_aap); - Patch(0x734127, TwoPassAlphaRender_aap); - Patch(0x73445E, RenderBigVehicleActomic); - InjectHook(0x4C441F, SetRendererForAtomic, PATCH_CALL); - } - } + Patch(0x7341D9, MovingPropellerRender); + Patch(0x734127, MovingPropellerRender); + Patch(0x73445E, RenderBigVehicleActomic); + // Weapons rendering InjectHook(0x5E7859, RenderWeapon); @@ -2696,41 +2535,9 @@ BOOL InjectDelayedPatches_11() if ( !bSARender ) { // Twopass rendering (experimental) - int dwTwoPassMethod = GetPrivateProfileIntW(L"SilentPatch", L"TwoPassRendering", -1, wcModulePath); - if ( dwTwoPassMethod != -1 ) - { - Patch(0x4C449E, 0x57); - Patch(0x4C44A4, 0x5F04C483); - Patch(0x4C44A8, 0x0004C25E); - - if ( dwTwoPassMethod == 1 ) - { - // Silent's twopass - InjectHook(0x4C449F, SetRendererForAtomic, PATCH_CALL); - Patch(0x734A09, TwoPassAlphaRender_Silent); - Patch(0x734957, TwoPassAlphaRender_Silent); - Patch(0x734C8E, RenderBigVehicleActomic); - // Twopass for peds - InjectHook(0x733E44, RenderPedCB); - } - else if ( dwTwoPassMethod == 2 ) - { - // aap's twopass - InjectHook(0x4C449F, SetRendererForAtomic_NoTest, PATCH_CALL); - Patch(0x734A09, TwoPassAlphaRender_aap); - Patch(0x734957, TwoPassAlphaRender_aap); - Patch(0x734C8E, RenderBigVehicleActomic); - // Twopass for peds - InjectHook(0x733E44, RenderPedCB); - } - else - { - InjectHook(0x4C449F, SetRendererForAtomic, PATCH_CALL); - Patch(0x734A09, TwoPassAlphaRender_aap); - Patch(0x734957, TwoPassAlphaRender_aap); - Patch(0x734C8E, RenderBigVehicleActomic); - } - } + Patch(0x734A09, MovingPropellerRender); + Patch(0x734957, MovingPropellerRender); + Patch(0x734C8E, RenderBigVehicleActomic); // Weapons rendering InjectHook(0x5E8079, RenderWeapon); @@ -2881,41 +2688,10 @@ BOOL InjectDelayedPatches_Steam() if ( !bSARender ) { // Twopass rendering (experimental) - int dwTwoPassMethod = GetPrivateProfileIntW(L"SilentPatch", L"TwoPassRendering", -1, wcModulePath); - if ( dwTwoPassMethod != -1 ) - { - Patch(0x4CEBF3, 0x57); - Patch(0x4CEBF9, 0xC25E5F5F); - Patch(0x4CEBFD, 0x0004); + Patch(0x76E230, MovingPropellerRender); + Patch(0x76E160, MovingPropellerRender); + Patch(0x76E4F0, RenderBigVehicleActomic); - if ( dwTwoPassMethod == 1 ) - { - // Silent's twopass - InjectHook(0x4CEBF4, SetRendererForAtomic, PATCH_CALL); - Patch(0x76E230, TwoPassAlphaRender_Silent); - Patch(0x76E160, TwoPassAlphaRender_Silent); - Patch(0x76E4F0, RenderBigVehicleActomic); - // Twopass for peds - InjectHook(0x76D88E, RenderPedCB); - } - else if ( dwTwoPassMethod == 2 ) - { - // aap's twopass - InjectHook(0x4CEBF4, SetRendererForAtomic_NoTest, PATCH_CALL); - Patch(0x76E230, TwoPassAlphaRender_aap); - Patch(0x76E160, TwoPassAlphaRender_aap); - Patch(0x76E4F0, RenderBigVehicleActomic); - // Twopass for peds - InjectHook(0x76D88E, RenderPedCB); - } - else - { - InjectHook(0x4CEBF4, SetRendererForAtomic, PATCH_CALL); - Patch(0x76E230, TwoPassAlphaRender_aap); - Patch(0x76E160, TwoPassAlphaRender_aap); - Patch(0x76E4F0, RenderBigVehicleActomic); - } - } // Weapons rendering InjectHook(0x604DD9, RenderWeapon); @@ -3066,8 +2842,6 @@ void Patch_SA_10() // Heli rotors InjectHook(0x6CAB70, &CPlane::Render_Stub, PATCH_JUMP); InjectHook(0x6C4400, &CHeli::Render_Stub, PATCH_JUMP); - //InjectHook(0x553318, RenderAlphaAtomics); - //Patch(0x73406E, TwoPassAlphaRender); // Boats /*Patch(0x4C79DF, 0x19);