diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp index e95a842..61015f9 100644 --- a/SilentPatch/TheFLAUtils.cpp +++ b/SilentPatch/TheFLAUtils.cpp @@ -3,17 +3,24 @@ #define WIN32_LEAN_AND_MEAN #include -int32_t (*FLAUtils::GetExtendedIDFunc)(const void* ptr) = FLAUtils::GetExtendedID_Stock; +int32_t (*FLAUtils::GetExtendedID8Func)(const void* ptr) = FLAUtils::GetExtendedID8_Stock; +int32_t (*FLAUtils::GetExtendedID16Func)(const void* ptr) = FLAUtils::GetExtendedID16_Stock; void FLAUtils::Init() { - HMODULE hFLA = GetModuleHandle(TEXT("$fastman92limitAdjuster.asi")); + HMODULE hFLA = GetModuleHandle("$fastman92limitAdjuster.asi"); if ( hFLA != nullptr ) { - auto function = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); - if ( function != nullptr ) + auto function8 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom8bitBefore" )); + if ( function8 != nullptr ) { - GetExtendedIDFunc = function; + GetExtendedID8Func = function8; + } + + auto function16 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); + if ( function16 != nullptr ) + { + GetExtendedID16Func = function16; } } } \ No newline at end of file diff --git a/SilentPatch/TheFLAUtils.h b/SilentPatch/TheFLAUtils.h index 6c9da0e..0ceb891 100644 --- a/SilentPatch/TheFLAUtils.h +++ b/SilentPatch/TheFLAUtils.h @@ -5,21 +5,55 @@ class FLAUtils { public: - static int32_t GetExtendedID(const void* ptr) + class int8 { - return GetExtendedIDFunc(ptr); + private: + int8() = delete; + int8& operator =( const int8& ) = delete; + + uint8_t value; + }; + + class int16 + { + private: + int16() = delete; + int16& operator =( const int16& ) = delete; + + uint16_t value; + }; + + static_assert( sizeof(int8) == sizeof(uint8_t) ); + static_assert( sizeof(int16) == sizeof(uint16_t) ); + + static int32_t GetExtendedID(const int8* ptr) + { + return GetExtendedID8Func(ptr); + } + + static int32_t GetExtendedID(const int16* ptr) + { + return GetExtendedID16Func(ptr); } static void Init(); private: - static const int32_t MAX_UINT16_ID = 0xFFFD; + static constexpr int32_t MAX_UINT8_ID = 0xFF; + static constexpr int32_t MAX_UINT16_ID = 0xFFFD; - static int32_t GetExtendedID_Stock(const void* ptr) + static int32_t GetExtendedID8_Stock(const void* ptr) + { + uint8_t uID = *static_cast(ptr); + return uID == MAX_UINT8_ID ? -1 : uID; + } + + static int32_t GetExtendedID16_Stock(const void* ptr) { uint16_t uID = *static_cast(ptr); return uID > MAX_UINT16_ID ? *static_cast(ptr) : uID; } - static int32_t (*GetExtendedIDFunc)(const void* ptr); + static int32_t (*GetExtendedID8Func)(const void* ptr); + static int32_t (*GetExtendedID16Func)(const void* ptr); }; \ No newline at end of file diff --git a/SilentPatchSA/GeneralSA.cpp b/SilentPatchSA/GeneralSA.cpp index e352518..762da4c 100644 --- a/SilentPatchSA/GeneralSA.cpp +++ b/SilentPatchSA/GeneralSA.cpp @@ -2,6 +2,7 @@ #include "GeneralSA.h" #include "PedSA.h" +#include "ModelInfoSA.h" // Wrappers static void* EntityRender = AddressByVersion(0x534310, 0x5347B0, 0x545B30); @@ -12,19 +13,10 @@ WRAPPER void CShadowCamera::InvertRaster() { VARJMP(varInvertRaster); } CWeaponInfo* (*CWeaponInfo::GetWeaponInfo)(eWeaponType, signed char) = AddressByVersion(0x743C60, 0x744490, 0x77D940); -static RwTexture*& ms_pRemapTexture = **AddressByVersion(0x59F1BD, 0x6D6E53, 0x5B811D); -static unsigned char* ms_currentCol = *AddressByVersion(0x4C84C8, 0x4C86C8, 0x4D2DC8); +static RwTexture*& ms_pRemapTexture = **AddressByVersion(0x59F1BD, 0x6D6E53, 0x5B811D); auto SetEditableMaterialsCB = AddressByVersion(0x4C83E0, 0x4C8460, 0x4D2CE0); -static void SetVehicleColour(unsigned char primaryColour, unsigned char secondaryColour, unsigned char tertiaryColour, unsigned char quaternaryColour) -{ - ms_currentCol[0] = primaryColour; - ms_currentCol[1] = secondaryColour; - ms_currentCol[2] = tertiaryColour; - ms_currentCol[3] = quaternaryColour; -} - static void ResetEditableMaterials(std::pair* pData) { for ( auto* i = pData; i->first != nullptr; i++ ) @@ -60,12 +52,15 @@ void CObject::Render() bool bCallRestore; std::pair materialRestoreData[16]; - if ( FLAUtils::GetExtendedID( &m_wCarPartModelIndex ) != -1 && m_nObjectType == 3 && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC ) + const int32_t carPartModelIndex = FLAUtils::GetExtendedID( &m_wCarPartModelIndex ); + if ( carPartModelIndex != -1 && m_nObjectType == 3 && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC ) { auto* pData = materialRestoreData; ms_pRemapTexture = m_pPaintjobTex; - SetVehicleColour(m_nCarColor[0], m_nCarColor[1], m_nCarColor[2], m_nCarColor[3]); + + static_cast(ms_modelInfoPtrs[ carPartModelIndex ])->SetVehicleColour( FLAUtils::GetExtendedID( &m_nCarColor[0] ), + FLAUtils::GetExtendedID( &m_nCarColor[1] ), FLAUtils::GetExtendedID( &m_nCarColor[2] ), FLAUtils::GetExtendedID( &m_nCarColor[3] ) ); SetEditableMaterialsCB(reinterpret_cast(m_pRwObject), &pData); pData->first = nullptr; diff --git a/SilentPatchSA/GeneralSA.h b/SilentPatchSA/GeneralSA.h index cc9699e..cd35096 100644 --- a/SilentPatchSA/GeneralSA.h +++ b/SilentPatchSA/GeneralSA.h @@ -2,6 +2,7 @@ #define __GENERAL #include +#include "TheFLAUtils.h" class CSimpleTransform { @@ -163,7 +164,7 @@ public: /********** END CFLAGS **************/ WORD RandomSeed; // 0x20 - unsigned short m_nModelIndex; // 0x22 + FLAUtils::int16 m_nModelIndex; // 0x22 void* pReferences; // 0x24 void* m_pLastRenderedLink; // 0x28 WORD m_nScanCode; // 0x2C @@ -179,12 +180,6 @@ public: //********* END CEntityInfo ************// public: - explicit inline CEntity(int dummy) - : CPlaceable(dummy) - { - // Dummy ctor - } - void UpdateRW(); void RegisterReference(CEntity** pAddress); void CleanUpOldReference(CEntity** pAddress); @@ -266,11 +261,6 @@ private: float fLighting; // 0x12C col lighting? CPhysical::GetLightingFromCol float fLighting_2; // 0x130 added to col lighting in CPhysical::GetTotalLighting BYTE pad3a[4]; // 0x134 - -public: - // Temp - CPhysical() - : CEntity(0) {} }; class NOVMT CObject : public CPhysical @@ -318,9 +308,9 @@ public: __int8 field_147; unsigned char m_nLastWeaponDamage; unsigned char m_nColBrightness; - __int16 m_wCarPartModelIndex; + FLAUtils::int16 m_wCarPartModelIndex; // this is used for detached car parts - unsigned __int8 m_nCarColor[4]; + FLAUtils::int8 m_nCarColor[4]; // time when this object must be deleted unsigned __int32 m_dwRemovalTime; float m_fHealth; diff --git a/SilentPatchSA/ModelInfoSA.cpp b/SilentPatchSA/ModelInfoSA.cpp index b76c17b..e329c34 100644 --- a/SilentPatchSA/ModelInfoSA.cpp +++ b/SilentPatchSA/ModelInfoSA.cpp @@ -6,6 +6,10 @@ static void* BaseModelInfoShutdown = AddressByVersion(0x4C4D50, 0x4C4DD0, 0x4CF590); WRAPPER void CBaseModelInfo::Shutdown() { VARJMP(BaseModelInfoShutdown); } +// static unsigned char* ms_currentCol = *AddressByVersion(0x4C84C8, 0x4C86C8, 0x4D2DC8); +static void* varSetVehicleColour = AddressByVersion( 0x4C84B0, 0, 0 ); // TODO: DO +WRAPPER void CVehicleModelInfo::SetVehicleColour( int32_t color1, int32_t color2, int32_t color3, int32_t color4 ) { VARJMP(varSetVehicleColour); } + RwTexture* (*CCustomCarPlateMgr::CreatePlateTexture)(const char* pText, signed char nDesign) = AddressByVersion(0x6FDEA0, 0x6FE6D0, 0x736AC0); signed char (*CCustomCarPlateMgr::GetMapRegionPlateDesign)() = AddressByVersion(0x6FD7A0, 0x6FDFD0, 0x7363E0); void (*CCustomCarPlateMgr::SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign) = AddressByVersion(0x6FDE50, 0x6FE680, 0x736A80); diff --git a/SilentPatchSA/ModelInfoSA.h b/SilentPatchSA/ModelInfoSA.h index 0d65779..bdf6db8 100644 --- a/SilentPatchSA/ModelInfoSA.h +++ b/SilentPatchSA/ModelInfoSA.h @@ -318,6 +318,8 @@ public: void FindEditableMaterialList(); void SetCarCustomPlate(); + void SetVehicleColour( int32_t color1, int32_t color2, int32_t color3, int32_t color4 ); + }; extern CBaseModelInfo** const ms_modelInfoPtrs;