mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-29 15:23:02 +05:00
Support arbitrary amount of numberplates
This commit is contained in:
parent
ca1d2c2496
commit
db1481d219
3 changed files with 49 additions and 33 deletions
|
@ -88,20 +88,17 @@ void CVehicleModelInfo::SetCarCustomPlate()
|
|||
m_plateText[0] = '\0';
|
||||
m_nPlateType = -1;
|
||||
|
||||
m_apPlateMaterials = new RpMaterial* [2*CCustomCarPlateMgr::NUM_MAX_PLATES];
|
||||
std::fill_n( m_apPlateMaterials, 2*CCustomCarPlateMgr::NUM_MAX_PLATES, nullptr );
|
||||
m_apPlateMaterials = new PlateMaterialsData;
|
||||
|
||||
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
|
||||
}
|
||||
|
||||
void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials )
|
||||
void CCustomCarPlateMgr::PollPlates( RpClump* clump, PlateMaterialsData* materials )
|
||||
{
|
||||
RpMaterial** carplates = materials;
|
||||
RpMaterial** carpbacks = materials+NUM_MAX_PLATES;
|
||||
std::vector<RpMaterial*> carplates;
|
||||
std::vector<RpMaterial*> carpbacks;
|
||||
|
||||
int numCarplates = 0, numCarpbacks = 0;
|
||||
|
||||
RpClumpForAllAtomics( clump, [carplates, carpbacks, &numCarplates, &numCarpbacks] ( RpAtomic* atomic ) -> RpAtomic* {
|
||||
RpClumpForAllAtomics( clump, [&] ( RpAtomic* atomic ) -> RpAtomic* {
|
||||
RpGeometryForAllMaterials( RpAtomicGetGeometry(atomic), [&] ( RpMaterial* material ) -> RpMaterial* {
|
||||
if ( RwTexture* texture = RpMaterialGetTexture(material) )
|
||||
{
|
||||
|
@ -109,19 +106,11 @@ void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials )
|
|||
{
|
||||
if ( _stricmp( texName, "carplate" ) == 0 )
|
||||
{
|
||||
assert(numCarplates < NUM_MAX_PLATES);
|
||||
if ( numCarplates < NUM_MAX_PLATES )
|
||||
{
|
||||
carplates[numCarplates++] = material;
|
||||
}
|
||||
carplates.push_back( material );
|
||||
}
|
||||
else if ( _stricmp( texName, "carpback" ) == 0 )
|
||||
{
|
||||
assert(numCarpbacks < NUM_MAX_PLATES);
|
||||
if ( numCarpbacks < NUM_MAX_PLATES )
|
||||
{
|
||||
carpbacks[numCarpbacks++] = material;
|
||||
}
|
||||
carpbacks.push_back( material );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,14 +119,29 @@ void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials )
|
|||
} );
|
||||
return atomic;
|
||||
} );
|
||||
|
||||
materials->m_numPlates = carplates.size();
|
||||
materials->m_numPlatebacks = carpbacks.size();
|
||||
|
||||
if ( materials->m_numPlates > 0 )
|
||||
{
|
||||
materials->m_plates = new RpMaterial* [materials->m_numPlates];
|
||||
std::copy( carplates.begin(), carplates.end(), stdext::checked_array_iterator<RpMaterial**>(materials->m_plates, materials->m_numPlates) );
|
||||
}
|
||||
|
||||
if ( materials->m_numPlatebacks > 0 )
|
||||
{
|
||||
materials->m_platebacks = new RpMaterial* [materials->m_numPlatebacks];
|
||||
std::copy( carpbacks.begin(), carpbacks.end(), stdext::checked_array_iterator<RpMaterial**>(materials->m_platebacks, materials->m_numPlatebacks) );
|
||||
}
|
||||
}
|
||||
|
||||
void CCustomCarPlateMgr::SetupClump(RpClump* pClump, RpMaterial** pMatsArray)
|
||||
void CCustomCarPlateMgr::SetupClump(RpClump* pClump, PlateMaterialsData* pMatsArray)
|
||||
{
|
||||
PollPlates( pClump, pMatsArray );
|
||||
}
|
||||
|
||||
void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign)
|
||||
void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, PlateMaterialsData* pMatsArray, signed char nDesign)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(nDesign);
|
||||
if ( pMatsArray != nullptr )
|
||||
|
|
|
@ -222,12 +222,27 @@ public:
|
|||
virtual void SetClump(RpClump* pClump);
|
||||
};
|
||||
|
||||
struct PlateMaterialsData // Added in SilentPatch
|
||||
{
|
||||
RpMaterial** m_plates = nullptr;
|
||||
RpMaterial** m_platebacks = nullptr;
|
||||
|
||||
size_t m_numPlates = 0;
|
||||
size_t m_numPlatebacks = 0;
|
||||
|
||||
~PlateMaterialsData()
|
||||
{
|
||||
delete m_plates;
|
||||
delete m_platebacks;
|
||||
}
|
||||
};
|
||||
|
||||
class NOVMT CVehicleModelInfo : public CClumpModelInfo
|
||||
{
|
||||
public:
|
||||
static const size_t PLATE_TEXT_LEN = 8;
|
||||
|
||||
RpMaterial** m_apPlateMaterials; // Changed in SilentPatchh
|
||||
PlateMaterialsData* m_apPlateMaterials; // Changed in SilentPatch
|
||||
char m_plateText[PLATE_TEXT_LEN];
|
||||
char field_30;
|
||||
signed char m_nPlateType;
|
||||
|
@ -321,11 +336,11 @@ public:
|
|||
static signed char (*GetMapRegionPlateDesign)();
|
||||
static void (*SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign);
|
||||
|
||||
static void SetupClump(RpClump* pClump, RpMaterial** pMatsArray);
|
||||
static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign);
|
||||
static void SetupClump(RpClump* pClump, PlateMaterialsData* pMatsArray);
|
||||
static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, PlateMaterialsData* pMatsArray, signed char nDesign);
|
||||
|
||||
private:
|
||||
static void PollPlates( RpClump* clump, RpMaterial** materials );
|
||||
static void PollPlates( RpClump* clump, PlateMaterialsData* materials );
|
||||
};
|
||||
|
||||
static_assert(sizeof(CBaseModelInfo) == 0x20, "Wrong size: CBaseModelInfo");
|
||||
|
|
|
@ -124,17 +124,14 @@ bool CVehicle::CustomCarPlate_TextureCreate(CVehicleModelInfo* pModelInfo)
|
|||
|
||||
void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo)
|
||||
{
|
||||
for ( ptrdiff_t i = 0; i < CCustomCarPlateMgr::NUM_MAX_PLATES; i++ )
|
||||
for ( size_t i = 0; i < pModelInfo->m_apPlateMaterials->m_numPlates; i++ )
|
||||
{
|
||||
if ( pModelInfo->m_apPlateMaterials[i] != nullptr )
|
||||
{
|
||||
RpMaterialSetTexture(pModelInfo->m_apPlateMaterials[i], PlateTexture);
|
||||
RpMaterialSetTexture(pModelInfo->m_apPlateMaterials->m_plates[i], PlateTexture);
|
||||
}
|
||||
|
||||
if ( pModelInfo->m_apPlateMaterials[CCustomCarPlateMgr::NUM_MAX_PLATES+i] != nullptr )
|
||||
for ( size_t i = 0; i < pModelInfo->m_apPlateMaterials->m_numPlatebacks; i++ )
|
||||
{
|
||||
CCustomCarPlateMgr::SetupMaterialPlatebackTexture(pModelInfo->m_apPlateMaterials[CCustomCarPlateMgr::NUM_MAX_PLATES+i], PlateDesign);
|
||||
}
|
||||
CCustomCarPlateMgr::SetupMaterialPlatebackTexture(pModelInfo->m_apPlateMaterials->m_platebacks[i], PlateDesign);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue