From 3cde64abbc8bf6ab5dd37d95c4e7fc5e2f807ff6 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 19 Jun 2017 20:00:02 +0200 Subject: [PATCH] FLA 32-bit model IDs compatibility --- SilentPatch/TheFLAUtils.cpp | 15 ++++++++++++++ SilentPatch/TheFLAUtils.h | 23 +++++++++++++++++++++ SilentPatchSA/GeneralSA.cpp | 2 +- SilentPatchSA/ModelInfoSA.cpp | 2 +- SilentPatchSA/SilentPatchSA.cpp | 3 +++ SilentPatchSA/SilentPatchSA.vcxproj | 5 +++++ SilentPatchSA/SilentPatchSA.vcxproj.filters | 6 ++++++ SilentPatchSA/StdAfxSA.h | 2 ++ SilentPatchSA/VehicleSA.cpp | 12 ++++++----- 9 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 SilentPatch/TheFLAUtils.cpp create mode 100644 SilentPatch/TheFLAUtils.h diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp new file mode 100644 index 0000000..4a5e9d2 --- /dev/null +++ b/SilentPatch/TheFLAUtils.cpp @@ -0,0 +1,15 @@ +#include "TheFLAUtils.h" + +#define WIN32_LEAN_AND_MEAN +#include + +int32_t (*FLAUtils::GetExtendedIDFunc)(const void* ptr) = nullptr; + +void FLAUtils::Init() +{ + HMODULE hFLA = GetModuleHandle("$fastman92limitAdjuster.asi"); + if ( hFLA != nullptr ) + { + GetExtendedIDFunc = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); + } +} \ No newline at end of file diff --git a/SilentPatch/TheFLAUtils.h b/SilentPatch/TheFLAUtils.h new file mode 100644 index 0000000..e41de87 --- /dev/null +++ b/SilentPatch/TheFLAUtils.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +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; + } + + static void Init(); + +private: + static const int32_t MAX_UINT16_ID = 0xFFFD; + + static int32_t (*GetExtendedIDFunc)(const void* ptr); +}; \ No newline at end of file diff --git a/SilentPatchSA/GeneralSA.cpp b/SilentPatchSA/GeneralSA.cpp index 8895973..62acba2 100644 --- a/SilentPatchSA/GeneralSA.cpp +++ b/SilentPatchSA/GeneralSA.cpp @@ -62,7 +62,7 @@ void CObject::Render() bool bCallRestore; std::pair materialRestoreData[16]; - if ( m_wCarPartModelIndex != -1 && m_nObjectType == 3 && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC ) + if ( FLAUtils::GetExtendedID( &m_wCarPartModelIndex ) != -1 && m_nObjectType == 3 && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC ) { auto* pData = materialRestoreData; diff --git a/SilentPatchSA/ModelInfoSA.cpp b/SilentPatchSA/ModelInfoSA.cpp index b41e934..66aaee5 100644 --- a/SilentPatchSA/ModelInfoSA.cpp +++ b/SilentPatchSA/ModelInfoSA.cpp @@ -10,7 +10,7 @@ signed char (*CCustomCarPlateMgr::GetMapRegionPlateDesign)() = AddressByVersion< void (*CCustomCarPlateMgr::SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign) = AddressByVersion(0x6FDE50, 0x6FE680, 0x736A80); CBaseModelInfo** const ms_modelInfoPtrs = *AddressByVersion(0x509CB1, 0x4C0C96, 0x403DB7); -const uint32_t m_numModelInfoPtrs = *AddressByVersion(0x4C5956+2, 0, 0); +const uint32_t m_numModelInfoPtrs = *AddressByVersion(0x4C5956+2, 0, 0); void CVehicleModelInfo::Shutdown() { diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 20771e0..4f05a88 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2310,6 +2310,7 @@ BOOL InjectDelayedPatches_10() } #endif + FLAUtils::Init(); return FALSE; } return TRUE; @@ -2529,6 +2530,7 @@ BOOL InjectDelayedPatches_11() Patch(0x5B9690, 15000); } + FLAUtils::Init(); return FALSE; } return TRUE; @@ -2735,6 +2737,7 @@ BOOL InjectDelayedPatches_Steam() Patch(0x5D5780, 15000); } + FLAUtils::Init(); return FALSE; } return TRUE; diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index b896c10..d5c421c 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -120,6 +120,10 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio NotUsing NotUsing + + NotUsing + NotUsing + @@ -164,6 +168,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters index a69594e..a450925 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj.filters +++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters @@ -63,6 +63,9 @@ Source Files + + Source Files + @@ -140,6 +143,9 @@ Header Files + + Header Files + diff --git a/SilentPatchSA/StdAfxSA.h b/SilentPatchSA/StdAfxSA.h index 026f2a6..eb74243 100644 --- a/SilentPatchSA/StdAfxSA.h +++ b/SilentPatchSA/StdAfxSA.h @@ -26,6 +26,8 @@ #include "MemoryMgr.h" #include "Maths.h" +#include "TheFLAUtils.h" + // SA operator delete extern void (*GTAdelete)(void* data); extern const char* (*GetFrameNodeName)(RwFrame*); diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 9b82a62..654b32c 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -154,7 +154,7 @@ void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo void CHeli::Render() { double dRotorsSpeed, dMovingRotorSpeed; - bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex ); + bool bDisplayRotors = !ShouldIgnoreRotor( FLAUtils::GetExtendedID( &m_nModelIndex ) ); bool bHasMovingRotor = m_pCarNode[13] != nullptr && bDisplayRotors; bool bHasMovingRotor2 = m_pCarNode[15] != nullptr && bDisplayRotors; @@ -210,7 +210,7 @@ void CHeli::Render() void CPlane::Render() { double dRotorsSpeed, dMovingRotorSpeed; - bool bDisplayRotors = !ShouldIgnoreRotor( m_nModelIndex ); + bool bDisplayRotors = !ShouldIgnoreRotor( FLAUtils::GetExtendedID( &m_nModelIndex ) ); bool bHasMovingProp = m_pCarNode[13] != nullptr && bDisplayRotors; bool bHasMovingProp2 = m_pCarNode[15] != nullptr && bDisplayRotors; @@ -267,7 +267,8 @@ void CPlane::Fix_SilentPatch() { // Reset bouncing panels // No reset on Vortex - for ( ptrdiff_t i = m_nModelIndex == 539 ? 1 : 0; i < 3; i++ ) + const int32_t extID = FLAUtils::GetExtendedID( &m_nModelIndex ); + for ( ptrdiff_t i = extID == 539 ? 1 : 0; i < 3; i++ ) { m_aBouncingPanel[i].m_nNodeIndex = -1; } @@ -278,7 +279,8 @@ void CAutomobile::Fix_SilentPatch() ResetFrames(); // Reset bouncing panels - for ( ptrdiff_t i = (m_nModelIndex == 525 && m_pCarNode[21]) || (m_nModelIndex == 531 && m_pCarNode[17]) ? 1 : 0; i < 3; i++ ) + const int32_t extID = FLAUtils::GetExtendedID( &m_nModelIndex ); + for ( ptrdiff_t i = (extID == 525 && m_pCarNode[21]) || (extID == 531 && m_pCarNode[17]) ? 1 : 0; i < 3; i++ ) { // Towtruck/Tractor fix m_aBouncingPanel[i].m_nNodeIndex = -1; @@ -287,7 +289,7 @@ void CAutomobile::Fix_SilentPatch() void CAutomobile::ResetFrames() { - RpClump* pOrigClump = reinterpret_cast(ms_modelInfoPtrs[m_nModelIndex]->pRwObject); + RpClump* pOrigClump = reinterpret_cast(ms_modelInfoPtrs[ FLAUtils::GetExtendedID( &m_nModelIndex ) ]->pRwObject); if ( pOrigClump ) { // Instead of setting frame rotation to (0,0,0) like R* did, obtain the original frame matrix from CBaseNodelInfo clump