From b6df6316e4e3a02f7c9cb4cf368d6decd19d53ea Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 21 Apr 2024 19:56:06 +0200 Subject: [PATCH] Lift the limit of materials in CObject::Render from 16 to 256 --- SilentPatchSA/GeneralSA.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/SilentPatchSA/GeneralSA.cpp b/SilentPatchSA/GeneralSA.cpp index 4b7d07a..773defc 100644 --- a/SilentPatchSA/GeneralSA.cpp +++ b/SilentPatchSA/GeneralSA.cpp @@ -25,10 +25,10 @@ auto SetEditableMaterialsCB = AddressByVersion(0x void* (CEntity::*CEntity::orgGetColModel)(); -static void ResetEditableMaterials(std::pair* pData) +static void ResetEditableMaterials(std::pair pData[], size_t num) { - for ( auto* i = pData; i->first != nullptr; i++ ) - *static_cast(i->first) = i->second; + for (size_t i = 0; i < num; ++i) + *pData[i].first = pData[i].second; } RpAtomic* ShadowCameraRenderCB(RpAtomic* pAtomic) @@ -66,8 +66,8 @@ void CObject::Render() if ( m_bDoNotRender || !m_pRwObject ) return; - bool bCallRestore = false; - std::pair materialRestoreData[16]; + std::pair materialRestoreData[256]; + size_t numMaterialsToRestore = 0; RwScopedRenderState cullState(rwRENDERSTATECULLMODE); @@ -83,20 +83,15 @@ void CObject::Render() SetEditableMaterialsCB(reinterpret_cast(m_pRwObject), &pData); assert( pData >= std::begin(materialRestoreData) && pData < std::end(materialRestoreData) ); - pData->first = nullptr; + numMaterialsToRestore = std::distance(materialRestoreData, pData); // Disable backface culling for the part RwRenderStateSet(rwRENDERSTATECULLMODE, reinterpret_cast(rwCULLMODECULLNONE)); - - bCallRestore = true; } CEntity::Render(); - if ( bCallRestore ) - { - ResetEditableMaterials(materialRestoreData); - } + ResetEditableMaterials(materialRestoreData, numMaterialsToRestore); } extern void (*WorldRemove)(CEntity*);