From 9236463f88be4dcb276b824f898a3411341d1728 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 23 Jun 2017 00:11:17 +0200 Subject: [PATCH] Animated Phoenix hood scoop --- SilentPatchSA/SilentPatchSA.cpp | 10 ++++++++ SilentPatchSA/TimerSA.cpp | 3 ++- SilentPatchSA/TimerSA.h | 1 + SilentPatchSA/VehicleSA.cpp | 43 ++++++++++++++++++++++++++++++++- SilentPatchSA/VehicleSA.h | 19 +++++++++++++-- 5 files changed, 72 insertions(+), 4 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 8b922f7..4a5dc0f 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -3423,6 +3423,16 @@ void Patch_SA_10() // Properly initialize all CVehicleModelInfo fields ReadCall( 0x4C75E4, orgVehicleModelInfoCtor ); InjectHook( 0x4C75E4, VehicleModelInfoCtor ); + + + // Animated Phoenix hood scoop + auto* automobilePreRender = &(*(decltype(CAutomobile::orgPreRender)**)(0x6B0AD2 + 2))[17]; + CAutomobile::orgPreRender = *automobilePreRender; + Patch(automobilePreRender, &CAutomobile::PreRender_Stub); + + InjectHook(0x6C7E7A, &CAutomobile::PreRender_Stub); + InjectHook(0x6CEAEC, &CAutomobile::PreRender_Stub); + InjectHook(0x6CFADC, &CAutomobile::PreRender_Stub); } void Patch_SA_11() diff --git a/SilentPatchSA/TimerSA.cpp b/SilentPatchSA/TimerSA.cpp index 6f2615f..406f01f 100644 --- a/SilentPatchSA/TimerSA.cpp +++ b/SilentPatchSA/TimerSA.cpp @@ -1,4 +1,5 @@ #include "StdAfxSA.h" #include "TimerSA.h" -int& CTimer::m_snTimeInMilliseconds = **AddressByVersion(0x4242D1, 0x53F6A1, 0x406FA1); \ No newline at end of file +int& CTimer::m_snTimeInMilliseconds = **AddressByVersion(0x4242D1, 0x53F6A1, 0x406FA1); +float& CTimer::m_fTimeStep = **AddressByVersion(0x41DE4F + 2, 0, 0); \ No newline at end of file diff --git a/SilentPatchSA/TimerSA.h b/SilentPatchSA/TimerSA.h index 3ca2360..e5e821f 100644 --- a/SilentPatchSA/TimerSA.h +++ b/SilentPatchSA/TimerSA.h @@ -5,6 +5,7 @@ class CTimer { public: static int& m_snTimeInMilliseconds; + static float& m_fTimeStep; }; #endif \ No newline at end of file diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 93bb54f..5c86d3d 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -18,6 +18,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); } +static void* varSetComponentRotation = AddressByVersion(0x6DBA30, 0, 0); +WRAPPER void CVehicle::SetComponentRotation( RwFrame* component, int axis, float angle, bool absolute ) { VARJMP(varSetComponentRotation); } + +void (CAutomobile::*CAutomobile::orgPreRender)(); static int32_t random(int32_t from, int32_t to) { @@ -250,6 +254,16 @@ void CPlane::Fix_SilentPatch() } } +void CAutomobile::PreRender() +{ + (this->*(orgPreRender))(); + + if ( FLAUtils::GetExtendedID( &m_nModelIndex ) == 603 ) + { + ProcessPhoenixBlower(); + } +} + void CAutomobile::Fix_SilentPatch() { ResetFrames(); @@ -284,4 +298,31 @@ void CAutomobile::ResetFrames() } } } -} \ No newline at end of file +} + +void CAutomobile::ProcessPhoenixBlower() +{ + if ( m_pCarNode[20] == nullptr ) return; + + float finalAngle = 0.0f; + if ( m_fGasPedal > 0.0f ) + { + if ( m_fSpecialComponentAngle < 1.3f ) + { + finalAngle = m_fSpecialComponentAngle = std::min( m_fSpecialComponentAngle + 0.1f * CTimer::m_fTimeStep, 1.3f ); + } + else + { + finalAngle = m_fSpecialComponentAngle + (std::sin( (CTimer::m_snTimeInMilliseconds % 10000) / 70.0f ) * 0.13f); + } + } + else + { + if ( m_fSpecialComponentAngle > 0.0f ) + { + finalAngle = m_fSpecialComponentAngle = std::max( m_fSpecialComponentAngle - 0.05f * CTimer::m_fTimeStep, 0.0f ); + } + } + + SetComponentRotation( m_pCarNode[20], 0, finalAngle, true ); +} diff --git a/SilentPatchSA/VehicleSA.h b/SilentPatchSA/VehicleSA.h index 02765a6..9b00fd8 100644 --- a/SilentPatchSA/VehicleSA.h +++ b/SilentPatchSA/VehicleSA.h @@ -117,7 +117,10 @@ class NOVMT CVehicle : public CPhysical protected: BYTE __pad1[752]; CVehicleFlags m_nVehicleFlags; - BYTE __pad2[160]; + BYTE __pad2[108]; + float m_fGasPedal; + float m_fBrakePedal; + BYTE __pad6[44]; signed int m_nTimeTillWeNeedThisCar; BYTE __pad4[56]; CEntity* pDamagingEntity; @@ -134,12 +137,14 @@ public: { return pDamagingEntity; } virtual void Render() override; + virtual void PreRender() override; bool CustomCarPlate_TextureCreate(CVehicleModelInfo* pModelInfo); void CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo); //void CustomCarPlate_AfterRenderingStop(CVehicleModelInfo* pModelInfo); bool IsLawEnforcementVehicle(); + void SetComponentRotation( RwFrame* component, int axis, float angle, bool absolute ); static void SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha); }; @@ -152,12 +157,22 @@ public: CBouncingPanel m_aBouncingPanel[3]; BYTE padding[320]; float m_fRotorSpeed; - BYTE __moarpad[312]; + BYTE __moarpad[264]; + float m_fSpecialComponentAngle; + BYTE __pad3[44]; public: + inline void PreRender_Stub() + { CAutomobile::PreRender(); } + + virtual void PreRender() override; + void Fix_SilentPatch(); void ResetFrames(); + void ProcessPhoenixBlower(); + + static void (CAutomobile::*orgPreRender)(); }; class NOVMT CHeli : public CAutomobile