2014-08-03 15:38:53 +02:00
|
|
|
#include "StdAfxSA.h"
|
2014-05-30 20:14:47 +02:00
|
|
|
#include "ModelInfoSA.h"
|
|
|
|
|
2014-08-22 00:10:23 +02:00
|
|
|
static void* BaseModelInfoShutdown = AddressByVersion<void*>(0x4C4D50, 0x4C4DD0, 0x4CF590);
|
2014-08-04 14:30:16 +02:00
|
|
|
WRAPPER void CBaseModelInfo::Shutdown() { VARJMP(BaseModelInfoShutdown); }
|
2014-06-23 02:37:03 +02:00
|
|
|
|
2014-08-22 00:10:23 +02: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 02:37:03 +02:00
|
|
|
|
2014-08-22 00:10:23 +02:00
|
|
|
CBaseModelInfo** const ms_modelInfoPtrs = *AddressByVersion<CBaseModelInfo***>(0x509CB1, 0x4C0C96, 0x403DB7);
|
2017-03-25 13:46:07 +01:00
|
|
|
const uint32_t m_numModelInfoPtrs = *AddressByVersion<uint16_t*>(0x4C5956+2, 0, 0);
|
2014-08-12 22:30:37 +02:00
|
|
|
|
2014-06-23 02:37:03 +02:00
|
|
|
void CVehicleModelInfo::Shutdown()
|
|
|
|
{
|
|
|
|
CBaseModelInfo::Shutdown();
|
|
|
|
|
|
|
|
delete m_apPlateMaterials;
|
|
|
|
}
|
|
|
|
|
2014-05-30 20:14:47 +02:00
|
|
|
void CVehicleModelInfo::FindEditableMaterialList()
|
|
|
|
{
|
|
|
|
std::pair<CVehicleModelInfo*,int> MatsPair = std::make_pair(this, 0);
|
|
|
|
|
|
|
|
RpClumpForAllAtomics(reinterpret_cast<RpClump*>(pRwObject), GetEditableMaterialListCB, &MatsPair);
|
|
|
|
|
|
|
|
if ( m_pVehicleStruct->m_nNumExtras > 0 )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < m_pVehicleStruct->m_nNumExtras; i++ )
|
|
|
|
GetEditableMaterialListCB(m_pVehicleStruct->m_apExtras[i], &MatsPair);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_nPrimaryColor = -1;
|
|
|
|
m_nSecondaryColor = -1;
|
|
|
|
m_nTertiaryColor = -1;
|
|
|
|
m_nQuaternaryColor = -1;
|
|
|
|
}
|
|
|
|
|
2014-06-23 02:37:03 +02:00
|
|
|
void CVehicleModelInfo::SetCarCustomPlate()
|
|
|
|
{
|
|
|
|
m_plateText[0] = '\0';
|
|
|
|
m_nPlateType = -1;
|
|
|
|
|
|
|
|
m_apPlateMaterials = reinterpret_cast<RpMaterial**>(new DWORD_PTR[2*NUM_MAX_PLATES]);
|
|
|
|
|
|
|
|
for ( int i = 0; i < 2*NUM_MAX_PLATES; i++ )
|
|
|
|
m_apPlateMaterials[i] = nullptr;
|
2014-06-29 22:21:18 +02:00
|
|
|
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
|
2014-06-23 02:37:03 +02:00
|
|
|
}
|
|
|
|
|
2014-05-30 20:14:47 +02:00
|
|
|
RpAtomic* CVehicleModelInfo::GetEditableMaterialListCB(RpAtomic* pAtomic, void* pData)
|
|
|
|
{
|
|
|
|
RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), GetEditableMaterialListCB, pData);
|
|
|
|
return pAtomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpMaterial* CVehicleModelInfo::GetEditableMaterialListCB(RpMaterial* pMaterial, void* pData)
|
|
|
|
{
|
|
|
|
if ( RpMaterialGetTexture(pMaterial) )
|
|
|
|
{
|
|
|
|
if ( !strncmp(RwTextureGetName(RpMaterialGetTexture(pMaterial)), "vehiclegrunge256", 16) )
|
|
|
|
{
|
|
|
|
std::pair<CVehicleModelInfo*,int>* pMats = static_cast<std::pair<CVehicleModelInfo*,int>*>(pData);
|
|
|
|
|
|
|
|
if ( pMats->second < 32 )
|
|
|
|
pMats->first->m_apDirtMaterials[pMats->second++] = pMaterial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pMaterial;
|
2014-06-23 02:37:03 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 22:21:18 +02:00
|
|
|
// TODO: FIX IT
|
2017-03-08 16:34:00 +01:00
|
|
|
typedef std::tuple<RpMaterial**, RpMaterial**, int, int> PlateDataTuple;
|
2014-06-23 02:37:03 +02:00
|
|
|
static RpMaterial* PollPlateData(RpMaterial* pMaterial, void* pData)
|
|
|
|
{
|
|
|
|
if ( RwTexture* pTexture = RpMaterialGetTexture(pMaterial) )
|
|
|
|
{
|
2014-06-29 22:21:18 +02:00
|
|
|
const char* pTexName = RwTextureGetName(pTexture);
|
|
|
|
if ( pTexName )
|
2014-06-23 02:37:03 +02:00
|
|
|
{
|
2014-06-29 22:21:18 +02:00
|
|
|
if ( !_strnicmp(pTexName, "carplate", 8) )
|
2014-06-23 02:37:03 +02:00
|
|
|
{
|
2017-03-08 16:34:00 +01:00
|
|
|
auto& pCallbackData = *static_cast<PlateDataTuple*>(pData);
|
2014-06-23 02:37:03 +02:00
|
|
|
|
|
|
|
assert(std::get<2>(pCallbackData) < NUM_MAX_PLATES);
|
2014-06-29 22:21:18 +02:00
|
|
|
if ( std::get<2>(pCallbackData) < NUM_MAX_PLATES )
|
|
|
|
{
|
|
|
|
// Append data
|
|
|
|
for ( auto ptr = std::get<0>(pCallbackData); *ptr; ptr++ )
|
|
|
|
{
|
|
|
|
if ( *ptr == pMaterial )
|
|
|
|
return pMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( std::get<0>(pCallbackData)[std::get<2>(pCallbackData)] )
|
|
|
|
std::get<2>(pCallbackData)++;
|
|
|
|
|
|
|
|
std::get<0>(pCallbackData)[std::get<2>(pCallbackData)++] = pMaterial;
|
|
|
|
}
|
2014-06-23 02:37:03 +02:00
|
|
|
}
|
2014-06-29 22:21:18 +02:00
|
|
|
else if ( !_strnicmp(pTexName, "carpback", 8) )
|
2014-06-23 02:37:03 +02:00
|
|
|
{
|
2017-03-08 16:34:00 +01:00
|
|
|
auto& pCallbackData = *static_cast<PlateDataTuple*>(pData);
|
2014-06-23 02:37:03 +02:00
|
|
|
|
|
|
|
assert(std::get<3>(pCallbackData) < NUM_MAX_PLATES);
|
2014-06-29 22:21:18 +02:00
|
|
|
if ( std::get<3>(pCallbackData) < NUM_MAX_PLATES )
|
|
|
|
{
|
|
|
|
// Append data
|
|
|
|
for ( auto ptr = std::get<0>(pCallbackData); *ptr; ptr++ )
|
|
|
|
{
|
|
|
|
if ( *ptr == pMaterial )
|
|
|
|
return pMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( std::get<1>(pCallbackData)[std::get<3>(pCallbackData)] )
|
|
|
|
std::get<3>(pCallbackData)++;
|
|
|
|
|
|
|
|
std::get<1>(pCallbackData)[std::get<3>(pCallbackData)] = pMaterial;
|
|
|
|
|
|
|
|
}
|
2014-06-23 02:37:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
static RpAtomic* PollPlateData(RpAtomic* pAtomic, void* pData)
|
|
|
|
{
|
|
|
|
RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), PollPlateData, pData);
|
|
|
|
return pAtomic;
|
|
|
|
}
|
|
|
|
|
2014-06-29 22:21:18 +02:00
|
|
|
static RpMaterial* SetPlateData(RpMaterial* pMaterial, void* pData)
|
|
|
|
{
|
|
|
|
if ( RwTexture* pTexture = RpMaterialGetTexture(pMaterial) )
|
|
|
|
{
|
|
|
|
if ( RwTextureGetName(pTexture) )
|
|
|
|
{
|
|
|
|
if ( !_strnicmp(RwTextureGetName(pTexture), "carplate", 8) )
|
|
|
|
{
|
|
|
|
auto& pCallbackData = *static_cast<std::pair<RwTexture*,signed char>*>(pData);
|
|
|
|
|
|
|
|
RpMaterialSetTexture(pMaterial, pCallbackData.first);
|
|
|
|
}
|
|
|
|
else if ( !_strnicmp(RwTextureGetName(pTexture), "carpback", 8) )
|
|
|
|
{
|
|
|
|
auto& pCallbackData = *static_cast<std::pair<RwTexture*,signed char>*>(pData);
|
|
|
|
|
|
|
|
CCustomCarPlateMgr::SetupMaterialPlatebackTexture(pMaterial, pCallbackData.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return pMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
static RpAtomic* SetPlateData(RpAtomic* pAtomic, void* pData)
|
|
|
|
{
|
|
|
|
RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), SetPlateData, pData);
|
|
|
|
return pAtomic;
|
|
|
|
}
|
|
|
|
|
2014-06-23 02:37:03 +02:00
|
|
|
void CCustomCarPlateMgr::SetupClump(RpClump* pClump, RpMaterial** pMatsArray)
|
|
|
|
{
|
|
|
|
// Split pMatsArray
|
2017-03-08 16:34:00 +01:00
|
|
|
PlateDataTuple CallbackData = std::make_tuple(pMatsArray, pMatsArray+NUM_MAX_PLATES, 0, 0);
|
2014-06-23 02:37:03 +02:00
|
|
|
|
|
|
|
RpClumpForAllAtomics(pClump, PollPlateData, &CallbackData);
|
2014-06-29 22:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(nDesign);
|
|
|
|
if ( pMatsArray )
|
|
|
|
{
|
|
|
|
// Split pMatsArray
|
2017-03-08 16:34:00 +01:00
|
|
|
PlateDataTuple CallbackData = std::make_tuple(pMatsArray, pMatsArray+NUM_MAX_PLATES, 0, 0);
|
2014-06-29 22:21:18 +02:00
|
|
|
|
|
|
|
RpClumpForAllAtomics(pClump, PollPlateData, &CallbackData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCustomCarPlateMgr::SetupPlates(RpClump* pClump, RwTexture* pTexture, signed char nDesign)
|
|
|
|
{
|
|
|
|
std::pair<RwTexture*,signed char> CallbackData = std::make_pair(pTexture, nDesign);
|
|
|
|
|
|
|
|
RpClumpForAllAtomics(pClump, SetPlateData, &CallbackData);
|
2014-05-30 20:14:47 +02:00
|
|
|
}
|