SilentPatch/SAFix/ModelInfoSA.cpp

186 lines
5.5 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-06-23 06:37:03 +06:00
WRAPPER void CBaseModelInfo::Shutdown() { EAXJMP(0x4C4D50); }
WRAPPER RwTexture* CCustomCarPlateMgr::CreatePlateTexture(const char* pText, signed char nDesign) { EAXJMP(0x6FDEA0); }
WRAPPER bool CCustomCarPlateMgr::GeneratePlateText(char* pBuf, int nLen) { EAXJMP(0x6FD5B0); }
WRAPPER signed char CCustomCarPlateMgr::GetMapRegionPlateDesign() { EAXJMP(0x6FD7A0); }
WRAPPER void CCustomCarPlateMgr::SetupMaterialPlatebackTexture(RpMaterial* pMaterial, signed char nDesign) { EAXJMP(0x6FDE50); }
void CVehicleModelInfo::Shutdown()
{
CBaseModelInfo::Shutdown();
delete m_apPlateMaterials;
}
2014-05-31 00:14:47 +06: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 06:37:03 +06: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-30 02:21:18 +06:00
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
2014-06-23 06:37:03 +06:00
}
2014-05-31 00:14:47 +06: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 06:37:03 +06:00
}
2014-06-30 02:21:18 +06:00
// TODO: FIX IT
2014-06-23 06:37:03 +06:00
static RpMaterial* PollPlateData(RpMaterial* pMaterial, void* pData)
{
if ( RwTexture* pTexture = RpMaterialGetTexture(pMaterial) )
{
2014-06-30 02:21:18 +06:00
const char* pTexName = RwTextureGetName(pTexture);
if ( pTexName )
2014-06-23 06:37:03 +06:00
{
2014-06-30 02:21:18 +06:00
if ( !_strnicmp(pTexName, "carplate", 8) )
2014-06-23 06:37:03 +06:00
{
auto& pCallbackData = *static_cast<std::tuple<RpMaterial**,RpMaterial**,unsigned char,unsigned char>*>(pData);
assert(std::get<2>(pCallbackData) < NUM_MAX_PLATES);
2014-06-30 02:21:18 +06: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 06:37:03 +06:00
}
2014-06-30 02:21:18 +06:00
else if ( !_strnicmp(pTexName, "carpback", 8) )
2014-06-23 06:37:03 +06:00
{
auto& pCallbackData = *static_cast<std::tuple<RpMaterial**,RpMaterial**,unsigned char,unsigned char>*>(pData);
assert(std::get<3>(pCallbackData) < NUM_MAX_PLATES);
2014-06-30 02:21:18 +06: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 06:37:03 +06:00
}
}
}
return pMaterial;
}
static RpAtomic* PollPlateData(RpAtomic* pAtomic, void* pData)
{
RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), PollPlateData, pData);
return pAtomic;
}
2014-06-30 02:21:18 +06: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 06:37:03 +06:00
void CCustomCarPlateMgr::SetupClump(RpClump* pClump, RpMaterial** pMatsArray)
{
// Split pMatsArray
std::tuple<RpMaterial**,RpMaterial**,unsigned char,unsigned char> CallbackData = std::make_tuple(pMatsArray, pMatsArray+NUM_MAX_PLATES, 0, 0);
RpClumpForAllAtomics(pClump, PollPlateData, &CallbackData);
2014-06-30 02:21:18 +06:00
}
void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign)
{
UNREFERENCED_PARAMETER(nDesign);
if ( pMatsArray )
{
// Split pMatsArray
std::tuple<RpMaterial**,RpMaterial**,unsigned char,unsigned char> CallbackData = std::make_tuple(pMatsArray, pMatsArray+NUM_MAX_PLATES, 0, 0);
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-31 00:14:47 +06:00
}