SilentPatch/SilentPatchSA/ModelInfoSA.cpp

118 lines
3.8 KiB
C++
Raw Normal View History

2014-08-03 19:38:53 +06:00
#include "StdAfxSA.h"
2014-05-31 00:14:47 +06:00
#include "ModelInfoSA.h"
2014-08-22 04:10:23 +06:00
static void* BaseModelInfoShutdown = AddressByVersion<void*>(0x4C4D50, 0x4C4DD0, 0x4CF590);
WRAPPER void CBaseModelInfo::Shutdown() { VARJMP(BaseModelInfoShutdown); }
2014-06-23 06:37:03 +06:00
2014-08-22 04:10:23 +06:00
RwTexture* (*CCustomCarPlateMgr::CreatePlateTexture)(const char* pText, signed char nDesign) = AddressByVersion<RwTexture*(*)(const char*,signed char)>(0x6FDEA0, 0x6FE6D0, 0x736AC0);
bool (*CCustomCarPlateMgr::GeneratePlateText)(char* pBuf, int nLen) = AddressByVersion<bool(*)(char*,int)>(0x6FD5B0, 0x6FDDE0, 0x7360F0);
signed char (*CCustomCarPlateMgr::GetMapRegionPlateDesign)() = AddressByVersion<signed char(*)()>(0x6FD7A0, 0x6FDFD0, 0x7363E0);
void (*CCustomCarPlateMgr::SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign) = AddressByVersion<void(*)(RpMaterial*,signed char)>(0x6FDE50, 0x6FE680, 0x736A80);
2014-06-23 06:37:03 +06:00
2014-08-22 04:10:23 +06:00
CBaseModelInfo** const ms_modelInfoPtrs = *AddressByVersion<CBaseModelInfo***>(0x509CB1, 0x4C0C96, 0x403DB7);
2017-03-25 17:46:07 +05:00
const uint32_t m_numModelInfoPtrs = *AddressByVersion<uint16_t*>(0x4C5956+2, 0, 0);
2014-06-23 06:37:03 +06:00
void CVehicleModelInfo::Shutdown()
{
CBaseModelInfo::Shutdown();
delete m_apPlateMaterials;
m_apPlateMaterials = nullptr;
2014-06-23 06:37:03 +06:00
}
2014-05-31 00:14:47 +06:00
void CVehicleModelInfo::FindEditableMaterialList()
{
size_t materialCount = 0;
2014-05-31 00:14:47 +06:00
auto GetEditableMaterialListCB = [&]( RpAtomic* atomic ) -> RpAtomic* {
RpGeometryForAllMaterials( RpAtomicGetGeometry(atomic), [&]( RpMaterial* material ) -> RpMaterial* {
if ( RwTexture* texture = RpMaterialGetTexture(material) )
{
if ( const char* texName = RwTextureGetName(texture) )
{
2017-04-09 23:25:19 +05:00
if ( _stricmp(texName, "vehiclegrunge256") == 0 )
{
if ( materialCount < _countof(m_apDirtMaterials) )
m_apDirtMaterials[materialCount++] = material;
}
}
}
return material;
} );
return atomic;
};
RpClumpForAllAtomics(reinterpret_cast<RpClump*>(pRwObject), GetEditableMaterialListCB);
2014-05-31 00:14:47 +06:00
for ( uint32_t i = 0; i < m_pVehicleStruct->m_nNumExtras; i++ )
GetEditableMaterialListCB(m_pVehicleStruct->m_apExtras[i]);
2014-05-31 00:14:47 +06:00
m_nPrimaryColor = -1;
m_nSecondaryColor = -1;
m_nTertiaryColor = -1;
m_nQuaternaryColor = -1;
}
2014-06-23 06:37:03 +06:00
void CVehicleModelInfo::SetCarCustomPlate()
{
m_plateText[0] = '\0';
m_nPlateType = -1;
m_apPlateMaterials = new RpMaterial* [2*CCustomCarPlateMgr::NUM_MAX_PLATES];
2014-06-23 06:37:03 +06:00
for ( int i = 0; i < 2*CCustomCarPlateMgr::NUM_MAX_PLATES; i++ )
2014-06-23 06:37:03 +06:00
m_apPlateMaterials[i] = nullptr;
2014-06-30 02:21:18 +06:00
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
2014-06-23 06:37:03 +06:00
}
void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials )
2014-05-31 00:14:47 +06:00
{
RpMaterial** carplates = materials;
RpMaterial** carpbacks = materials+NUM_MAX_PLATES;
2014-05-31 00:14:47 +06:00
int numCarplates = 0, numCarpbacks = 0;
2014-06-23 06:37:03 +06:00
RpClumpForAllAtomics( clump, [carplates, carpbacks, &numCarplates, &numCarpbacks] ( RpAtomic* atomic ) -> RpAtomic* {
RpGeometryForAllMaterials( RpAtomicGetGeometry(atomic), [&] ( RpMaterial* material ) -> RpMaterial* {
if ( RwTexture* texture = RpMaterialGetTexture(material) )
2014-06-23 06:37:03 +06:00
{
if ( const char* texName = RwTextureGetName(texture) )
2014-06-30 02:21:18 +06:00
{
2017-04-09 23:25:19 +05:00
if ( _stricmp( texName, "carplate" ) == 0 )
2014-06-30 02:21:18 +06:00
{
assert(numCarplates < NUM_MAX_PLATES);
2017-04-02 21:58:32 +05:00
if ( numCarplates < NUM_MAX_PLATES )
{
carplates[numCarplates++] = material;
}
2014-06-30 02:21:18 +06:00
}
2017-04-09 23:25:19 +05:00
else if ( _stricmp( texName, "carpback" ) == 0 )
2014-06-30 02:21:18 +06:00
{
assert(numCarpbacks < NUM_MAX_PLATES);
2017-04-02 21:58:32 +05:00
if ( numCarpbacks < NUM_MAX_PLATES )
{
carpbacks[numCarpbacks++] = material;
}
2014-06-30 02:21:18 +06:00
}
}
2014-06-23 06:37:03 +06:00
}
2014-06-30 02:21:18 +06:00
return material;
} );
return atomic;
} );
2014-06-30 02:21:18 +06:00
}
2014-06-23 06:37:03 +06:00
void CCustomCarPlateMgr::SetupClump(RpClump* pClump, RpMaterial** pMatsArray)
{
PollPlates( pClump, pMatsArray );
2014-06-30 02:21:18 +06:00
}
void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign)
{
UNREFERENCED_PARAMETER(nDesign);
if ( pMatsArray != nullptr )
2014-06-30 02:21:18 +06:00
{
PollPlates( pClump, pMatsArray );
2014-06-30 02:21:18 +06:00
}
2014-05-31 00:14:47 +06:00
}