From 539398dd684dd2b242f81581845c22debbe41881 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 9 Sep 2017 23:39:30 +0200 Subject: [PATCH] Stuntplane ailerons Programmatically fixed props on Predator and Tropic --- SilentPatchSA/SilentPatchSA.cpp | 17 ++++++++++-- SilentPatchSA/VehicleSA.cpp | 49 +++++++++++++++++++++++++++++++-- SilentPatchSA/VehicleSA.h | 26 +++++++++++++++-- SilentPatchSA/versionmeta.props | 2 +- 4 files changed, 86 insertions(+), 8 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index be14f57..5a3ee7a 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -3431,8 +3431,8 @@ void Patch_SA_10() // Animated Phoenix hood scoop - auto* automobilePreRender = &(*(decltype(CAutomobile::orgPreRender)**)(0x6B0AD2 + 2))[17]; - CAutomobile::orgPreRender = *automobilePreRender; + auto* automobilePreRender = &(*(decltype(CAutomobile::orgAutomobilePreRender)**)(0x6B0AD2 + 2))[17]; + CAutomobile::orgAutomobilePreRender = *automobilePreRender; Patch(automobilePreRender, &CAutomobile::PreRender_Stub); InjectHook(0x6C7E7A, &CAutomobile::PreRender_Stub); @@ -3440,6 +3440,19 @@ void Patch_SA_10() InjectHook(0x6CFADC, &CAutomobile::PreRender_Stub); + // Extra animations for planes + auto* planePreRender = &(*(decltype(CPlane::orgPlanePreRender)**)(0x6C8E5A + 2))[17]; + CPlane::orgPlanePreRender = *planePreRender; + Patch(planePreRender, &CPlane::PreRender_Stub); + + + // Fixed animations for boats + void* vehiclePreRender; + ReadCall( 0x6F119E, vehiclePreRender ); + CVehicle::orgVehiclePreRender = *(decltype(CVehicle::orgVehiclePreRender)*)(&vehiclePreRender); + InjectHook( 0x6F119E, &CBoat::PreRender_SilentPatch ); + + // Stop BF Injection/Bandito/Hotknife rotating engine components when engine is off Patch(0x6AC2BE + 2, &CAutomobile::ms_engineCompSpeed); Patch(0x6ACB91 + 2, &CAutomobile::ms_engineCompSpeed); diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 2326258..7f480a6 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -26,7 +26,10 @@ static void* varVehicleRender = AddressByVersion(0x6D0E60, 0x6D1680, 0x70 WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); } static void* varIsLawEnforcementVehicle = AddressByVersion(0x6D2370, 0x6D2BA0, 0x70D8C0); WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); } -void (CAutomobile::*CAutomobile::orgPreRender)(); + +void (CVehicle::*CVehicle::orgVehiclePreRender)(); +void (CAutomobile::*CAutomobile::orgAutomobilePreRender)(); +void (CPlane::*CPlane::orgPlanePreRender)(); static int32_t random(int32_t from, int32_t to) { @@ -283,12 +286,54 @@ void CPlane::Fix_SilentPatch() } } +void CPlane::PreRender() +{ + (this->*(orgPlanePreRender))(); + + const int32_t extID = m_nModelIndex.Get(); + if ( extID == 513 ) + { + ProcessStuntPlane(); + } +} + +void CPlane::ProcessStuntPlane() +{ + auto copyRotation = [&]( size_t src, size_t dest ) { + if ( m_pCarNode[src] != nullptr && m_pCarNode[dest] != nullptr ) + { + RwMatrix* lhs = RwFrameGetMatrix( m_pCarNode[dest] ); + const RwMatrix* rhs = RwFrameGetMatrix( m_pCarNode[src] ); + + lhs->at = rhs->at; + lhs->up = rhs->up; + lhs->right = rhs->right; + RwMatrixUpdate( lhs ); + } + }; + + copyRotation( 19, 23 ); + copyRotation( 20, 24 ); +} + +void CBoat::PreRender_SilentPatch() +{ + (this->*(orgVehiclePreRender))(); + + // Fixed moving prop for Predator/Tropic/Reefer + const int32_t extID = m_nModelIndex.Get(); + if ( (extID == 430 || extID == 453 || extID == 454) && m_pBoatNode[1] == nullptr ) + { + m_pBoatNode[1] = GetFrameFromName( RpClumpGetFrame(m_pRwObject), "boat_moving" ); + } +} + void CAutomobile::PreRender() { // For rotating engine components ms_engineCompSpeed = m_nVehicleFlags.bEngineOn ? CTimer::m_fTimeStep : 0.0f; - (this->*(orgPreRender))(); + (this->*(orgAutomobilePreRender))(); const int32_t extID = m_nModelIndex.Get(); if ( extID == 603 ) diff --git a/SilentPatchSA/VehicleSA.h b/SilentPatchSA/VehicleSA.h index 2cccf4d..62cc61a 100644 --- a/SilentPatchSA/VehicleSA.h +++ b/SilentPatchSA/VehicleSA.h @@ -154,6 +154,8 @@ public: static void SetComponentRotation( RwFrame* component, eRotAxis axis, float angle, bool absolute = true ); static void SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha); + + static void (CVehicle::*orgVehiclePreRender)(); }; class NOVMT CAutomobile : public CVehicle @@ -179,13 +181,14 @@ public: void Fix_SilentPatch(); + static void (CAutomobile::*orgAutomobilePreRender)(); + static float ms_engineCompSpeed; + +private: void ResetFrames(); void ProcessPhoenixBlower( int32_t modelID ); void ProcessSweeper(); void ProcessNewsvan(); - - static void (CAutomobile::*orgPreRender)(); - static float ms_engineCompSpeed; }; class NOVMT CHeli : public CAutomobile @@ -206,10 +209,27 @@ public: public: inline void Render_Stub() { CPlane::Render(); } + inline void PreRender_Stub() + { CPlane::PreRender(); } virtual void Render() override; + virtual void PreRender() override; void Fix_SilentPatch(); + + static void (CPlane::*orgPlanePreRender)(); + +private: + void ProcessStuntPlane(); +}; + +class NOVMT CBoat : public CVehicle +{ + uint8_t __pad[16]; + RwFrame* m_pBoatNode[12]; + +public: + void PreRender_SilentPatch(); }; void ReadRotorFixExceptions(const wchar_t* pPath); diff --git a/SilentPatchSA/versionmeta.props b/SilentPatchSA/versionmeta.props index 1bade2a..bec4007 100644 --- a/SilentPatchSA/versionmeta.props +++ b/SilentPatchSA/versionmeta.props @@ -6,7 +6,7 @@ .asi SilentPatch for San Andreas 29 - 4 + 5 2014-2017