From 3cde64abbc8bf6ab5dd37d95c4e7fc5e2f807ff6 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 19 Jun 2017 20:00:02 +0200 Subject: [PATCH 1/4] 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 From 625720904d94ac474990cd30b52f7e23fd8aa68c Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 20 Jun 2017 16:20:59 +0200 Subject: [PATCH 2/4] Only patch IMG sizes if FLA isn't doing so already --- SilentPatchSA/SilentPatchSA.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 4f05a88..1e214a1 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2310,7 +2310,20 @@ BOOL InjectDelayedPatches_10() } #endif + if ( *(DWORD*)0x4065BB == 0x3B0BE1C1 ) + { + // Handle IMGs bigger than 4GB + Nop( 0x4065BB, 3 ); + Nop( 0x4065C2, 1 ); + InjectHook( 0x4065C2+1, CdStreamThreadHighSize, PATCH_CALL ); + Patch( 0x406620+2, &pCdStreamSetFilePointer ); + } + FLAUtils::Init(); + + const uint8_t bytes[] = { 0x8B, 0x4C, 0x24, 0x64, 0x51 }; + memcpy((void*)0x5B6FCC, bytes, sizeof(bytes)); + return FALSE; } return TRUE; @@ -3150,12 +3163,6 @@ void Patch_SA_10() strcpy(pScannerNames + (8*113), "WESTP"); strcpy(pScannerNames + (8*134), "????"); - // Handle IMGs bigger than 4GB - Nop( 0x4065BB, 3 ); - Nop( 0x4065C2, 1 ); - InjectHook( 0x4065C2+1, CdStreamThreadHighSize, PATCH_CALL ); - Patch( 0x406620+2, &pCdStreamSetFilePointer ); - // AI accuracy issue Nop(0x73B3AE, 1); From 4b42bf8f10bd5f67665d5f74b1e1a7c0cd8f1940 Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 20 Jun 2017 16:58:21 +0200 Subject: [PATCH 3/4] Lightbeam fix compatible with FLA --- SilentPatchSA/SilentPatchSA.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 1e214a1..075f24a 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2854,8 +2854,7 @@ void Patch_SA_10() //Patch(0x5B3ADD, 4); // Lightbeam fix - Patch(0x6A2E88, 0x0EEB); - Nop(0x6A2E9C, 3); + Nop(0x6A2E95, 3); Patch(0x6E0F63, 0x0AEB); Patch(0x6E0F7C, 0x0BEB); Patch(0x6E0F95, 0x0BEB); @@ -3284,8 +3283,7 @@ void Patch_SA_11() InjectHook(0x7142FB, HandleMoonStuffStub, PATCH_JUMP); // Lightbeam fix - Patch(0x6A36A8, 0x0EEB); - Nop(0x6A36BC, 3); + Nop(0x6A36B5, 3); Patch(0x6E1793, 0x0AEB); Patch(0x6E17AC, 0x0BEB); Patch(0x6E17C5, 0x0BEB); From 35cc3a15628410ceeff49a7a508aa480b5b8eace Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 20 Jun 2017 17:15:44 +0200 Subject: [PATCH 4/4] use int32 instead of uint32 for model IDs --- SilentPatchSA/SilentPatchSA.cpp | 2 +- SilentPatchSA/VehicleSA.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 075f24a..cc6a1c0 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1048,7 +1048,7 @@ void ReadDoubleRearWheels(const wchar_t* pPath) token = wcstok_s( textLine, L"=", &context ); int toList = _wtoi( token ); - if ( toList != 0 ) + if ( toList > 0 ) { bool value = _wtoi( wcstok_s( nullptr, L"=", &context ) ) != 0; doubleRearWheelsList.emplace_back( toList, value ); diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 654b32c..90abff7 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -6,9 +6,9 @@ #include "TimerSA.h" #include "DelimStringReader.h" -std::vector vecRotorExceptions; +std::vector vecRotorExceptions; -static bool ShouldIgnoreRotor( unsigned int id ) +static bool ShouldIgnoreRotor( int32_t id ) { return std::find( vecRotorExceptions.begin(), vecRotorExceptions.end(), id ) != vecRotorExceptions.end(); } @@ -62,8 +62,8 @@ void ReadRotorFixExceptions(const wchar_t* pPath) GetPrivateProfileSectionW( L"RotorFixExceptions", reader.GetBuffer(), reader.GetSize(), pPath ); while ( const wchar_t* str = reader.GetString() ) { - unsigned int toList = _wtoi( str ); - if ( toList != 0 ) + int toList = _wtoi( str ); + if ( toList > 0 ) vecRotorExceptions.push_back( toList ); } }