diff --git a/SilentPatchSA/ModelInfoSA.cpp b/SilentPatchSA/ModelInfoSA.cpp index 16beb41..7e895b4 100644 --- a/SilentPatchSA/ModelInfoSA.cpp +++ b/SilentPatchSA/ModelInfoSA.cpp @@ -2,6 +2,8 @@ #include "ModelInfoSA.h" #include +#include +#include static void* BaseModelInfoShutdown = AddressByVersion(0x4C4D50, 0x4C4DD0, 0x4CF590); WRAPPER void CBaseModelInfo::Shutdown() { VARJMP(BaseModelInfoShutdown); } @@ -19,6 +21,56 @@ bool (*CCustomCarPlateMgr::GeneratePlateText)(char* pBuf, int nLen); // Read fro CBaseModelInfo** const ms_modelInfoPtrs = *AddressByVersion(0x509CB1, 0x4C0C96, 0x403DB7); const uint32_t m_numModelInfoPtrs = *AddressByVersion(0x4C5956+2, 0, 0); +static bool IsTextureRegistered( const std::vector& registeredNames, const char* textureName ) +{ + return std::find_if( registeredNames.begin(), registeredNames.end(), [&] ( const auto& texture ) { + return _stricmp(textureName, texture.c_str()) == 0; + }) != registeredNames.end(); +} + +static std::vector< std::string > registeredGrungeTextures = { "vehiclegrunge256" }; +static bool IsGrungeTexture( const char* textureName ) +{ + return IsTextureRegistered( registeredGrungeTextures, textureName ); +} + +static std::vector< std::string > registeredCarplateTextures = { "carplate" }; +static bool IsCarplateTexture( const char* textureName ) +{ + return IsTextureRegistered( registeredCarplateTextures, textureName ); +} + +static std::vector< std::string > registeredCarpbackTextures = { "carpback" }; +static bool IsCarpbackTexture( const char* textureName ) +{ + return IsTextureRegistered( registeredCarpbackTextures, textureName ); +} + +static void RegisterTextureName( std::vector& registeredNames, const char* textureName ) +{ + assert( textureName != nullptr ); + registeredNames.emplace_back( textureName ); +} + +extern "C" { + +__declspec(dllexport) void RegisterGrungeTextureName( const char* textureName ) +{ + RegisterTextureName( registeredGrungeTextures, textureName ); +} + +__declspec(dllexport) void RegisterCarplateTextureName( const char* textureName ) +{ + RegisterTextureName( registeredCarplateTextures, textureName ); +} + +__declspec(dllexport) void RegisterCarpbackTextureName( const char* textureName ) +{ + RegisterTextureName( registeredCarpbackTextures, textureName ); +} + +} + static RwTexture** const ms_aDirtTextures = *AddressByVersion( 0x5D5DCC + 3, 0, 0x5F259C + 3 ); void RemapDirt( CVehicleModelInfo* modelInfo, uint32_t dirtID ) @@ -52,7 +104,7 @@ void CVehicleModelInfo::FindEditableMaterialList() { if ( const char* texName = RwTextureGetName(texture) ) { - if ( _stricmp(texName, "vehiclegrunge256") == 0 ) + if ( IsGrungeTexture(texName) ) { editableMaterials.push_back( material ); } @@ -109,11 +161,11 @@ void CCustomCarPlateMgr::PollPlates( RpClump* clump, PlateMaterialsData* materia { if ( const char* texName = RwTextureGetName(texture) ) { - if ( _stricmp( texName, "carplate" ) == 0 ) + if ( IsCarplateTexture(texName) ) { carplates.push_back( material ); } - else if ( _stricmp( texName, "carpback" ) == 0 ) + else if ( IsCarpbackTexture(texName) ) { carpbacks.push_back( material ); }