A fix for numplates with tuningparts

This commit is contained in:
Silent 2014-06-29 22:21:18 +02:00
parent b5e5d140f7
commit d28ad95d5c
4 changed files with 91 additions and 10 deletions

View file

@ -42,7 +42,7 @@ void CVehicleModelInfo::SetCarCustomPlate()
for ( int i = 0; i < 2*NUM_MAX_PLATES; i++ )
m_apPlateMaterials[i] = nullptr;
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
}
RpAtomic* CVehicleModelInfo::GetEditableMaterialListCB(RpAtomic* pAtomic, void* pData)
@ -66,32 +66,58 @@ RpMaterial* CVehicleModelInfo::GetEditableMaterialListCB(RpMaterial* pMaterial,
return pMaterial;
}
// TODO: FIX IT
static RpMaterial* PollPlateData(RpMaterial* pMaterial, void* pData)
{
if ( RwTexture* pTexture = RpMaterialGetTexture(pMaterial) )
{
if ( RwTextureGetName(pTexture) )
const char* pTexName = RwTextureGetName(pTexture);
if ( pTexName )
{
if ( !_strnicmp(RwTextureGetName(pTexture), "carplate", 8) )
if ( !_strnicmp(pTexName, "carplate", 8) )
{
auto& pCallbackData = *static_cast<std::tuple<RpMaterial**,RpMaterial**,unsigned char,unsigned char>*>(pData);
assert(std::get<2>(pCallbackData) < NUM_MAX_PLATES);
if ( std::get<2>(pCallbackData)++ < NUM_MAX_PLATES )
*(std::get<0>(pCallbackData)++) = pMaterial;
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;
}
}
else if ( !_strnicmp(RwTextureGetName(pTexture), "carpback", 8) )
else if ( !_strnicmp(pTexName, "carpback", 8) )
{
auto& pCallbackData = *static_cast<std::tuple<RpMaterial**,RpMaterial**,unsigned char,unsigned char>*>(pData);
assert(std::get<3>(pCallbackData) < NUM_MAX_PLATES);
if ( std::get<3>(pCallbackData)++ < NUM_MAX_PLATES )
*(std::get<1>(pCallbackData)++) = pMaterial;
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;
}
}
}
}
return pMaterial;
}
@ -101,10 +127,60 @@ static RpAtomic* PollPlateData(RpAtomic* pAtomic, void* pData)
return pAtomic;
}
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;
}
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);
}
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);
}

View file

@ -281,7 +281,7 @@ public:
static RpMaterial* GetEditableMaterialListCB(RpMaterial* pMaterial, void* pData);
};
#define NUM_MAX_PLATES 6
#define NUM_MAX_PLATES 12
class CCustomCarPlateMgr
{
@ -298,6 +298,9 @@ public:
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 SetupPlates(RpClump* pClump, RwTexture* pTexture, signed char nDesign);
};
static_assert(sizeof(CBaseModelInfo) == 0x20, "Wrong size: CBaseModelInfo");

View file

@ -48,6 +48,7 @@ bool CVehicle::CustomCarPlate_TextureCreate(CVehicleModelInfo* pModelInfo)
void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo)
{
//CCustomCarPlateMgr::SetupPlates(reinterpret_cast<RpClump*>(pModelInfo->pRwObject), PlateTexture, PlateDesign);
for ( int i = 0; i < NUM_MAX_PLATES; i++ )
{
if ( pModelInfo->m_apPlateMaterials[i] )

View file

@ -2392,6 +2392,7 @@ __forceinline void Patch_SA_10()
InjectMethodVP(0x4C9660, CVehicleModelInfo::SetCarCustomPlate, PATCH_NOTHING);
InjectMethodVP(0x6D6A58, CVehicle::CustomCarPlate_TextureCreate, PATCH_NOTHING);
InjectMethodVP(0x6D651C, CVehicle::CustomCarPlate_BeforeRenderingStart, PATCH_NOTHING);
InjectHook(0x6FDFE0, CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade, PATCH_JUMP);
//InjectMethodVP(0x6D0E53, CVehicle::CustomCarPlate_AfterRenderingStop, PATCH_NOTHING);
Nop(0x6D6517, 2);