From 928800795ce2972d3df71480a70939806cd4d2e7 Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 20 Jun 2017 20:35:35 +0200 Subject: [PATCH 1/3] Branchless GetExtendedID --- SilentPatch/TheFLAUtils.cpp | 2 +- SilentPatch/TheFLAUtils.h | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp index 4a5e9d2..5eb375a 100644 --- a/SilentPatch/TheFLAUtils.cpp +++ b/SilentPatch/TheFLAUtils.cpp @@ -3,7 +3,7 @@ #define WIN32_LEAN_AND_MEAN #include -int32_t (*FLAUtils::GetExtendedIDFunc)(const void* ptr) = nullptr; +int32_t (*FLAUtils::GetExtendedIDFunc)(const void* ptr) = FLAUtils::GetExtendedID_Stock; void FLAUtils::Init() { diff --git a/SilentPatch/TheFLAUtils.h b/SilentPatch/TheFLAUtils.h index e41de87..6c9da0e 100644 --- a/SilentPatch/TheFLAUtils.h +++ b/SilentPatch/TheFLAUtils.h @@ -7,11 +7,7 @@ class FLAUtils public: static int32_t GetExtendedID(const void* ptr) { - if ( GetExtendedIDFunc != nullptr ) - return GetExtendedIDFunc(ptr); - - uint16_t uID = *static_cast(ptr); - return uID > MAX_UINT16_ID ? *static_cast(ptr) : uID; + return GetExtendedIDFunc(ptr); } static void Init(); @@ -19,5 +15,11 @@ public: private: static const int32_t MAX_UINT16_ID = 0xFFFD; + static int32_t GetExtendedID_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); }; \ No newline at end of file From 330fa38f4c57fb6dbb19f44a719ab309e61723bd Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 20 Jun 2017 21:40:05 +0200 Subject: [PATCH 2/3] Fix for old FLA --- SilentPatch/TheFLAUtils.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp index 5eb375a..2ba3afa 100644 --- a/SilentPatch/TheFLAUtils.cpp +++ b/SilentPatch/TheFLAUtils.cpp @@ -10,6 +10,10 @@ void FLAUtils::Init() HMODULE hFLA = GetModuleHandle("$fastman92limitAdjuster.asi"); if ( hFLA != nullptr ) { - GetExtendedIDFunc = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); + auto function = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); + if ( function != nullptr ) + { + GetExtendedIDFunc = function; + } } } \ No newline at end of file From 7e30befb6f1cbc4dc02d2b28fc88fb9a53288215 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 7 Sep 2017 21:27:47 +0200 Subject: [PATCH 3/3] Refactored FLA compatibility Car colours compatible with FLA # Conflicts: # SilentPatchSA/ModelInfoSA.h --- SilentPatch/TheFLAUtils.cpp | 15 ++++++++---- SilentPatch/TheFLAUtils.h | 44 +++++++++++++++++++++++++++++++---- SilentPatchSA/GeneralSA.cpp | 19 ++++++--------- SilentPatchSA/GeneralSA.h | 18 ++++---------- SilentPatchSA/ModelInfoSA.cpp | 4 ++++ SilentPatchSA/ModelInfoSA.h | 2 ++ 6 files changed, 67 insertions(+), 35 deletions(-) diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp index 2ba3afa..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("$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 62acba2..e6956ad 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++ ) @@ -62,12 +54,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 0c4f3d8..c7fefb6 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 66aaee5..d2c251b 100644 --- a/SilentPatchSA/ModelInfoSA.cpp +++ b/SilentPatchSA/ModelInfoSA.cpp @@ -4,6 +4,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); bool (*CCustomCarPlateMgr::GeneratePlateText)(char* pBuf, int nLen) = AddressByVersion(0x6FD5B0, 0x6FDDE0, 0x7360F0); signed char (*CCustomCarPlateMgr::GetMapRegionPlateDesign)() = AddressByVersion(0x6FD7A0, 0x6FDFD0, 0x7363E0); diff --git a/SilentPatchSA/ModelInfoSA.h b/SilentPatchSA/ModelInfoSA.h index cfa13a6..85c008d 100644 --- a/SilentPatchSA/ModelInfoSA.h +++ b/SilentPatchSA/ModelInfoSA.h @@ -293,6 +293,8 @@ public: void FindEditableMaterialList(); void SetCarCustomPlate(); + void SetVehicleColour( int32_t color1, int32_t color2, int32_t color3, int32_t color4 ); + static RpAtomic* GetEditableMaterialListCB(RpAtomic* pAtomic, void* pData); static RpMaterial* GetEditableMaterialListCB(RpMaterial* pMaterial, void* pData); };