diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp index 81c7545..0e1615f 100644 --- a/SilentPatch/TheFLAUtils.cpp +++ b/SilentPatch/TheFLAUtils.cpp @@ -3,21 +3,21 @@ #define WIN32_LEAN_AND_MEAN #include -int32_t (*FLAUtils::GetExtendedID8Func)(const void* ptr) = FLAUtils::GetExtendedID8_Stock; -int32_t (*FLAUtils::GetExtendedID16Func)(const void* ptr) = FLAUtils::GetExtendedID16_Stock; +int32_t (*FLAUtils::GetExtendedID8Func)(const uint8_t* ptr) = FLAUtils::GetExtendedID8_Stock; +int32_t (*FLAUtils::GetExtendedID16Func)(const uint16_t* ptr) = FLAUtils::GetExtendedID16_Stock; void FLAUtils::Init() { - HMODULE hFLA = GetModuleHandle(TEXT("$fastman92limitAdjuster.asi")); + const HMODULE hFLA = GetModuleHandle(TEXT("$fastman92limitAdjuster.asi")); if ( hFLA != nullptr ) { - auto function8 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom8bitBefore" )); + const auto function8 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom8bitBefore" )); if ( function8 != nullptr ) { GetExtendedID8Func = function8; } - auto function16 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); + const auto function16 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); if ( function16 != nullptr ) { GetExtendedID16Func = function16; diff --git a/SilentPatch/TheFLAUtils.h b/SilentPatch/TheFLAUtils.h index 0ceb891..fc3eaa5 100644 --- a/SilentPatch/TheFLAUtils.h +++ b/SilentPatch/TheFLAUtils.h @@ -7,6 +7,12 @@ class FLAUtils public: class int8 { + public: + inline int32_t Get() const + { + return GetExtendedID8Func( &value ); + } + private: int8() = delete; int8& operator =( const int8& ) = delete; @@ -16,6 +22,12 @@ public: class int16 { + public: + inline int32_t Get() const + { + return GetExtendedID16Func( &value ); + } + private: int16() = delete; int16& operator =( const int16& ) = delete; @@ -23,37 +35,27 @@ public: 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 constexpr int32_t MAX_UINT8_ID = 0xFF; static constexpr int32_t MAX_UINT16_ID = 0xFFFD; - static int32_t GetExtendedID8_Stock(const void* ptr) + static int32_t GetExtendedID8_Stock(const uint8_t* ptr) { - uint8_t uID = *static_cast(ptr); + const uint8_t uID = *ptr; return uID == MAX_UINT8_ID ? -1 : uID; } - static int32_t GetExtendedID16_Stock(const void* ptr) + static int32_t GetExtendedID16_Stock(const uint16_t* ptr) { - uint16_t uID = *static_cast(ptr); - return uID > MAX_UINT16_ID ? *static_cast(ptr) : uID; + const uint16_t uID = *ptr; + return uID > MAX_UINT16_ID ? *reinterpret_cast(ptr) : uID; } - static int32_t (*GetExtendedID8Func)(const void* ptr); - static int32_t (*GetExtendedID16Func)(const void* ptr); + static int32_t (*GetExtendedID8Func)(const uint8_t* ptr); + static int32_t (*GetExtendedID16Func)(const uint16_t* ptr); + + static_assert( sizeof(int8) == sizeof(uint8_t) ); + static_assert( sizeof(int16) == sizeof(uint16_t) ); }; \ No newline at end of file diff --git a/SilentPatchSA/GeneralSA.cpp b/SilentPatchSA/GeneralSA.cpp index cedbf33..7c09bc8 100644 --- a/SilentPatchSA/GeneralSA.cpp +++ b/SilentPatchSA/GeneralSA.cpp @@ -56,15 +56,15 @@ void CObject::Render() bool bCallRestore; std::pair materialRestoreData[16]; - const int32_t carPartModelIndex = FLAUtils::GetExtendedID( &m_wCarPartModelIndex ); + const int32_t carPartModelIndex = m_wCarPartModelIndex.Get(); if ( carPartModelIndex != -1 && m_objectCreatedBy == TEMP_OBJECT && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC ) { auto* pData = materialRestoreData; ms_pRemapTexture = m_pPaintjobTex; - 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] ) ); + static_cast(ms_modelInfoPtrs[ carPartModelIndex ])->SetVehicleColour( m_nCarColor[0].Get(), + m_nCarColor[1].Get(), m_nCarColor[2].Get(), m_nCarColor[3].Get() ); SetEditableMaterialsCB(reinterpret_cast(m_pRwObject), &pData); pData->first = nullptr; diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 50762cd..2326258 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -172,7 +172,7 @@ void CVehicle::SetComponentRotation( RwFrame* component, eRotAxis axis, float an void CHeli::Render() { double dRotorsSpeed, dMovingRotorSpeed; - bool bDisplayRotors = !ShouldIgnoreRotor( FLAUtils::GetExtendedID( &m_nModelIndex ) ); + bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex.Get() ); bool bHasMovingRotor = m_pCarNode[13] != nullptr && bDisplayRotors; bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && bDisplayRotors; @@ -224,7 +224,7 @@ void CHeli::Render() void CPlane::Render() { double dRotorsSpeed, dMovingRotorSpeed; - bool bDisplayRotors = !ShouldIgnoreRotor( FLAUtils::GetExtendedID( &m_nModelIndex ) ); + bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex.Get() ); bool bHasMovingProp = m_pCarNode[13] != nullptr && bDisplayRotors; bool bHasMovingProp2 = m_pCarNode[15] != nullptr && bDisplayRotors; @@ -277,8 +277,7 @@ void CPlane::Fix_SilentPatch() { // Reset bouncing panels // No reset on Vortex - const int32_t extID = FLAUtils::GetExtendedID( &m_nModelIndex ); - for ( ptrdiff_t i = extID == 539 ? 1 : 0; i < 3; i++ ) + for ( ptrdiff_t i = m_nModelIndex.Get() == 539 ? 1 : 0; i < 3; i++ ) { m_aBouncingPanel[i].m_nNodeIndex = -1; } @@ -291,17 +290,18 @@ void CAutomobile::PreRender() (this->*(orgPreRender))(); - if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 603 ) + const int32_t extID = m_nModelIndex.Get(); + if ( extID == 603 ) { - ProcessPhoenixBlower( 603 ); + ProcessPhoenixBlower( extID ); } - if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 574 ) + if ( extID == 574 ) { ProcessSweeper(); } - if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 582 ) + if ( extID == 582 ) { ProcessNewsvan(); } @@ -312,7 +312,7 @@ void CAutomobile::Fix_SilentPatch() ResetFrames(); // Reset bouncing panels - const int32_t extID = FLAUtils::GetExtendedID( &m_nModelIndex ); + const int32_t extID = m_nModelIndex.Get(); for ( ptrdiff_t i = (extID == 525 && m_pCarNode[21]) || (extID == 531 && m_pCarNode[17]) ? 1 : 0; i < 3; i++ ) { // Towtruck/Tractor fix @@ -322,7 +322,7 @@ void CAutomobile::Fix_SilentPatch() void CAutomobile::ResetFrames() { - RpClump* pOrigClump = reinterpret_cast(ms_modelInfoPtrs[ FLAUtils::GetExtendedID( &m_nModelIndex ) ]->pRwObject); + RpClump* pOrigClump = reinterpret_cast(ms_modelInfoPtrs[ m_nModelIndex.Get() ]->pRwObject); if ( pOrigClump != nullptr ) { // Instead of setting frame rotation to (0,0,0) like R* did, obtain the original frame matrix from CBaseNodelInfo clump