From fa33d11d645a34051027373816f87c7c0509debb Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 31 Jul 2024 22:21:30 +0200 Subject: [PATCH 1/7] Fix bug --- Client/game_sa/CHeliSA.cpp | 2 +- Client/game_sa/CHeliSA.h | 39 ++++++++++++++ Client/game_sa/CVehicleSA.cpp | 54 +++++++++++++++++++ Client/game_sa/CVehicleSA.h | 9 +++- .../mods/deathmatch/logic/CClientVehicle.cpp | 30 +++++++++++ Client/mods/deathmatch/logic/CClientVehicle.h | 3 ++ .../logic/luadefs/CLuaVehicleDefs.cpp | 19 +++++++ .../logic/luadefs/CLuaVehicleDefs.h | 3 ++ Client/sdk/game/CHeli.h | 3 ++ 9 files changed, 159 insertions(+), 3 deletions(-) diff --git a/Client/game_sa/CHeliSA.cpp b/Client/game_sa/CHeliSA.cpp index 986e3e9764..fccae9f5ec 100644 --- a/Client/game_sa/CHeliSA.cpp +++ b/Client/game_sa/CHeliSA.cpp @@ -11,7 +11,7 @@ #include "StdInc.h" #include "CHeliSA.h" -CHeliSA::CHeliSA(CHeliSAInterface* pInterface) +CHeliSA::CHeliSA(CHeliSAInterface* pInterface) : m_rotorState(true) { SetInterface(pInterface); Init(); diff --git a/Client/game_sa/CHeliSA.h b/Client/game_sa/CHeliSA.h index 49fc0d866d..4f4c948322 100644 --- a/Client/game_sa/CHeliSA.h +++ b/Client/game_sa/CHeliSA.h @@ -15,10 +15,49 @@ class CHeliSAInterface : public CAutomobileSAInterface { +public: + std::uint8_t m_nHeliFlags; // 0x988 + std::uint8_t ___pad1[3]; // 0x989 + float m_fLeftRightSkid; // 0x98C + float m_fSteeringUpDown; // 0x990 + float m_fSteeringLeftRight; // 0x994 + float m_fAccelerationBreakStatus; // 0x998 + std::int32_t field_99C; // 0x99C + float m_fRotorZ; // 0x9A0 + float m_fSecondRotorZ; // 0x9A4 + float m_fMaxAltitude; // 0x9A8 + std::int32_t field_9AC; // 0x9AC + float m_fMinAltitude; // 0x9B0 + std::int32_t field_9B4; // 0x9B4 + std::uint8_t field_9B8; // 0x9B8 + std::uint8_t m_nNumSwatOccupants; // 0x9B9 + std::uint8_t m_anSwatIDs[4]; // 0x9BA + std::uint8_t ___pad2[2]; // 0x9BE + std::uint32_t field_9C0[4]; // 0x9C0 + std::int32_t field_9D0; // 0x9D0 + FxSystem_c** m_pParticlesList; // 0x9D4 + std::uint8_t field_9D8[24]; // 0x9D8 + std::int32_t field_9F0; // 0x9F0 + CVector m_vecSearchLightTarget; // 0x9F4 + float m_fSearchLightIntensity; // 0xA00 + std::int32_t field_A04; // 0xA04 + std::int32_t field_A08; // 0xA08 + FxSystem_c** m_ppGunflashFx; // 0xA0C + std::uint8_t m_nFiringMultiplier; // 0xA10 + bool m_bSearchLightEnabled; // 0xA11 + std::uint8_t ___pad3[2]; // 0xA12 + std::int32_t field_A14; // 0xA14 }; class CHeliSA final : public virtual CHeli, public virtual CAutomobileSA { public: CHeliSA(CHeliSAInterface* pInterface); + + // Not SA + bool GetHeliRotorState() noexcept override { return m_rotorState; } + void SetHeliRotorState(bool state) noexcept override { m_rotorState = state; } + +private: + bool m_rotorState; }; diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index c2c612d5c7..5a9a5b3dfd 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -20,6 +20,7 @@ #include "CProjectileInfoSA.h" #include "CTrainSA.h" #include "CPlaneSA.h" +#include "CHeliSA.h" #include "CVehicleSA.h" #include "CVisibilityPluginsSA.h" #include "CWorldSA.h" @@ -51,6 +52,44 @@ void _declspec(naked) HOOK_Vehicle_PreRender(void) } } +bool CanProcessFlyingCarStuff(CHeliSAInterface* heliInterface) +{ + SClientEntity* vehicle = pGame->GetPools()->GetVehicle((DWORD*)heliInterface); + if (!vehicle || !vehicle->pEntity) + return true; + + auto* heli = reinterpret_cast(vehicle->pEntity); + if (!heli) + return true; + + return heli->GetHeliRotorState(); +} + +void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff() +{ + _asm + { + mov esi, ecx + mov al, [esi+36h] + + pushad + push ecx + call CanProcessFlyingCarStuff + add esp, 4 + + movzx eax, al + test eax, eax + jz skip + + popad + jmp CONTINUE_CHeli_ProcessFlyingCarStuff + + skip: + popad + jmp RETURN_CHeli_ProcessFlyingCarStuff + } +} + namespace { bool ClumpDumpCB(RpAtomic* pAtomic, void* data) @@ -489,6 +528,18 @@ void CVehicleSA::SetTrainSpeed(float fSpeed) pInterface->m_fTrainSpeed = fSpeed; } +float CVehicleSA::GetHeliRotorSpeed() +{ + auto* heliInterface = static_cast(GetInterface()); + return heliInterface->m_wheelSpeed[1]; +} + +void CVehicleSA::SetHeliRotorSpeed(float speed) +{ + auto* heliInterface = static_cast(GetInterface()); + heliInterface->m_wheelSpeed[1] = speed; +} + void CVehicleSA::SetPlaneRotorSpeed(float fSpeed) { auto pInterface = static_cast(GetInterface()); @@ -1774,6 +1825,9 @@ void CVehicleSA::StaticSetHooks() { // Setup vehicle sun glare hook HookInstall(FUNC_CAutomobile_OnVehiclePreRender, (DWORD)HOOK_Vehicle_PreRender, 5); + + // + HookInstall(FUNC_CHeli_ProcessFlyingCarStuff, (DWORD)HOOK_CHeli_ProcessFlyingCarStuff, 5); } void CVehicleSA::SetVehiclesSunGlareEnabled(bool bEnabled) diff --git a/Client/game_sa/CVehicleSA.h b/Client/game_sa/CVehicleSA.h index f9847d4c33..dcb92dd43f 100644 --- a/Client/game_sa/CVehicleSA.h +++ b/Client/game_sa/CVehicleSA.h @@ -94,6 +94,11 @@ struct RwTexture; #define FUNC_CAutomobile_OnVehiclePreRender 0x6ABCFD #define FUNC_CVehicle_DoSunGlare 0x6DD6F0 +#define FUNC_CHeli_ProcessFlyingCarStuff 0x6C4E7D + +static constexpr DWORD CONTINUE_CHeli_ProcessFlyingCarStuff = 0x6C4E82; +static constexpr DWORD RETURN_CHeli_ProcessFlyingCarStuff = 0x6C5404; + struct SRailNodeSA { short sX; // x coordinate times 8 @@ -540,7 +545,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA bool GetTakeLessDamage() { return GetVehicleInterface()->m_nVehicleFlags.bTakeLessDamage; }; bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; }; unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156); }; - float GetHeliRotorSpeed() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 2124); }; + float GetHeliRotorSpeed(); float GetPlaneRotorSpeed(); unsigned long GetExplodeTime() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 1240); }; @@ -566,7 +571,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA { *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156) = usAdjustableProperty; }; - void SetHeliRotorSpeed(float fSpeed) { *reinterpret_cast(reinterpret_cast(m_pInterface) + 2124) = fSpeed; }; + void SetHeliRotorSpeed(float speed); void SetPlaneRotorSpeed(float fSpeed); bool SetVehicleWheelRotation(float fWheelRot1, float fWheelRot2, float fWheelRot3, float fWheelRot4) noexcept; void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast(reinterpret_cast(m_pInterface) + 1240) = ulTime; }; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index b1b00cfba3..f8bb4d208c 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using std::list; @@ -170,6 +171,7 @@ CClientVehicle::CClientVehicle(CClientManager* pManager, ElementID ID, unsigned m_fNitroLevel = 1.0f; m_cNitroCount = 0; m_fWheelScale = 1.0f; + m_heliRotorState = m_eVehicleType == CLIENTVEHICLE_HELI; for (unsigned int i = 0; i < MAX_WINDOWS; ++i) { @@ -1576,6 +1578,34 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed) m_fHeliRotorSpeed = fSpeed; } +bool CClientVehicle::GetHeliRotorState() +{ + if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI) + { + auto* heli = reinterpret_cast(m_pVehicle); + if (heli) + return heli->GetHeliRotorState(); + } + + return m_heliRotorState; +} + +void CClientVehicle::SetHeliRotorState(bool state) +{ + if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI) + { + auto* heli = reinterpret_cast(m_pVehicle); + if (heli) + { + heli->SetHeliRotorState(state); + if (!state) + heli->SetHeliRotorSpeed(0.0f); + } + } + + m_heliRotorState = state; +} + void CClientVehicle::SetPlaneRotorSpeed(float fSpeed) { if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_PLANE) diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index e2c83c618e..cc897d0596 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -299,10 +299,12 @@ class CClientVehicle : public CClientStreamElement // TODO: Make the class remember on virtualization float GetHeliRotorSpeed(); float GetPlaneRotorSpeed(); + bool GetHeliRotorState(); bool GetRotorSpeed(float&); bool SetRotorSpeed(float); bool SetWheelsRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept; + void SetHeliRotorState(bool state); void SetHeliRotorSpeed(float fSpeed); void SetPlaneRotorSpeed(float fSpeed); bool IsHeliSearchLightVisible(); @@ -671,6 +673,7 @@ class CClientVehicle : public CClientStreamElement uchar m_ucTrackID; bool m_bJustStreamedIn; bool m_bWheelScaleChanged; + bool m_heliRotorState; // Time dependent error compensation interpolation struct diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index b35bfee24b..28299348b1 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -92,6 +92,7 @@ void CLuaVehicleDefs::LoadFunctions() {"getVehicleModelWheelSize", ArgumentParser}, {"getVehicleWheelFrictionState", ArgumentParser}, {"getVehicleEntryPoints", ArgumentParser}, + {"getHelicopterRotorState", ArgumentParser}, // Vehicle set funcs {"createVehicle", CreateVehicle}, @@ -155,6 +156,7 @@ void CLuaVehicleDefs::LoadFunctions() {"setVehicleVariant", ArgumentParser}, {"setVehicleWheelScale", ArgumentParser}, {"setVehicleModelWheelSize", ArgumentParser}, + {"setHelicopterRotorState", ArgumentParser}, }; // Add functions @@ -243,6 +245,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getModelWheelSize", "getVehicleModelWheelSize"); lua_classfunction(luaVM, "getWheelFrictionState", "getVehicleWheelFrictionState"); lua_classfunction(luaVM, "getEntryPoints", ArgumentParser); + lua_classfunction(luaVM, "getRotorState", "getHelicopterRotorState"); lua_classfunction(luaVM, "setComponentVisible", "setVehicleComponentVisible"); lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn"); @@ -291,6 +294,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setVariant", "setVehicleVariant"); lua_classfunction(luaVM, "setWheelScale", "setVehicleWheelScale"); lua_classfunction(luaVM, "setModelWheelSize", "setVehicleModelWheelSize"); + lua_classfunction(luaVM, "setRotorState", "setHelicopterRotorState"); lua_classfunction(luaVM, "resetComponentPosition", "resetVehicleComponentPosition"); lua_classfunction(luaVM, "resetComponentRotation", "resetVehicleComponentRotation"); @@ -347,6 +351,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "gravity", SetVehicleGravity, OOP_GetVehicleGravity); lua_classvariable(luaVM, "turnVelocity", SetVehicleTurnVelocity, OOP_GetVehicleTurnVelocity); lua_classvariable(luaVM, "wheelScale", "setVehicleWheelScale", "getVehicleWheelScale"); + lua_classvariable(luaVM, "rotorState", "setHelicopterRotorState", "getHelicopterRotorState"); lua_registerclass(luaVM, "Vehicle", "Element"); } @@ -4273,3 +4278,17 @@ std::variant> CLuaVehicleDefs::OOP_GetVehicleEntryP return entryPoints; } + +bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state) +{ + if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI) + return false; + + vehicle->SetHeliRotorState(state); + return true; +} + +bool CLuaVehicleDefs::GetHeliRotorState(CClientVehicle* vehicle) +{ + return vehicle->GetHeliRotorState(); +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 5c2e908d58..05670cf026 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -166,6 +166,9 @@ class CLuaVehicleDefs : public CLuaDefs static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize); static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel); + static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state); + static bool GetHeliRotorState(CClientVehicle* const vehicle); + // Components LUA_DECLARE(SetVehicleComponentPosition); LUA_DECLARE_OOP(GetVehicleComponentPosition); diff --git a/Client/sdk/game/CHeli.h b/Client/sdk/game/CHeli.h index a7783a89ca..8a3a539a9d 100644 --- a/Client/sdk/game/CHeli.h +++ b/Client/sdk/game/CHeli.h @@ -16,4 +16,7 @@ class CHeli : public virtual CAutomobile { public: virtual ~CHeli(){}; + + virtual void SetHeliRotorState(bool state) = 0; + virtual bool GetHeliRotorState() = 0; }; From 0f89a907431efb0dbd3512169c1ac4f8cbc1d5d4 Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 31 Jul 2024 23:46:11 +0200 Subject: [PATCH 2/7] New argument --- Client/game_sa/CHeliSA.cpp | 2 +- Client/game_sa/CHeliSA.h | 7 ------ Client/game_sa/CVehicleSA.cpp | 14 +++++++---- Client/game_sa/CVehicleSA.h | 3 +++ .../mods/deathmatch/logic/CClientVehicle.cpp | 24 ++++--------------- Client/mods/deathmatch/logic/CClientVehicle.h | 6 ++--- .../logic/luadefs/CLuaVehicleDefs.cpp | 4 ++-- .../logic/luadefs/CLuaVehicleDefs.h | 2 +- Client/sdk/game/CHeli.h | 3 --- Client/sdk/game/CVehicle.h | 2 ++ 10 files changed, 25 insertions(+), 42 deletions(-) diff --git a/Client/game_sa/CHeliSA.cpp b/Client/game_sa/CHeliSA.cpp index fccae9f5ec..986e3e9764 100644 --- a/Client/game_sa/CHeliSA.cpp +++ b/Client/game_sa/CHeliSA.cpp @@ -11,7 +11,7 @@ #include "StdInc.h" #include "CHeliSA.h" -CHeliSA::CHeliSA(CHeliSAInterface* pInterface) : m_rotorState(true) +CHeliSA::CHeliSA(CHeliSAInterface* pInterface) { SetInterface(pInterface); Init(); diff --git a/Client/game_sa/CHeliSA.h b/Client/game_sa/CHeliSA.h index 4f4c948322..f1b4df9961 100644 --- a/Client/game_sa/CHeliSA.h +++ b/Client/game_sa/CHeliSA.h @@ -53,11 +53,4 @@ class CHeliSA final : public virtual CHeli, public virtual CAutomobileSA { public: CHeliSA(CHeliSAInterface* pInterface); - - // Not SA - bool GetHeliRotorState() noexcept override { return m_rotorState; } - void SetHeliRotorState(bool state) noexcept override { m_rotorState = state; } - -private: - bool m_rotorState; }; diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 5a9a5b3dfd..a397d66b4f 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -58,11 +58,7 @@ bool CanProcessFlyingCarStuff(CHeliSAInterface* heliInterface) if (!vehicle || !vehicle->pEntity) return true; - auto* heli = reinterpret_cast(vehicle->pEntity); - if (!heli) - return true; - - return heli->GetHeliRotorState(); + return vehicle->pEntity->GetHeliRotorState(); } void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff() @@ -540,6 +536,14 @@ void CVehicleSA::SetHeliRotorSpeed(float speed) heliInterface->m_wheelSpeed[1] = speed; } +void CVehicleSA::SetHeliRotorState(bool state, bool stopRotor) noexcept +{ + m_heliRotorState = state; + + if (!state && stopRotor) + SetHeliRotorSpeed(0.0f); +} + void CVehicleSA::SetPlaneRotorSpeed(float fSpeed) { auto pInterface = static_cast(GetInterface()); diff --git a/Client/game_sa/CVehicleSA.h b/Client/game_sa/CVehicleSA.h index dcb92dd43f..fba10c9b8a 100644 --- a/Client/game_sa/CVehicleSA.h +++ b/Client/game_sa/CVehicleSA.h @@ -415,6 +415,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA unsigned char m_ucVariant2; unsigned char m_ucVariantCount{0}; bool m_doorsUndamageable{false}; + bool m_heliRotorState{true}; std::array m_dummyPositions; @@ -546,6 +547,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; }; unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156); }; float GetHeliRotorSpeed(); + bool GetHeliRotorState() const noexcept override { return m_heliRotorState; } float GetPlaneRotorSpeed(); unsigned long GetExplodeTime() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 1240); }; @@ -572,6 +574,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156) = usAdjustableProperty; }; void SetHeliRotorSpeed(float speed); + void SetHeliRotorState(bool state, bool stopRotor) noexcept override; void SetPlaneRotorSpeed(float fSpeed); bool SetVehicleWheelRotation(float fWheelRot1, float fWheelRot2, float fWheelRot3, float fWheelRot4) noexcept; void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast(reinterpret_cast(m_pInterface) + 1240) = ulTime; }; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index f8bb4d208c..69f80df88e 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -171,7 +171,6 @@ CClientVehicle::CClientVehicle(CClientManager* pManager, ElementID ID, unsigned m_fNitroLevel = 1.0f; m_cNitroCount = 0; m_fWheelScale = 1.0f; - m_heliRotorState = m_eVehicleType == CLIENTVEHICLE_HELI; for (unsigned int i = 0; i < MAX_WINDOWS; ++i) { @@ -1578,30 +1577,15 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed) m_fHeliRotorSpeed = fSpeed; } -bool CClientVehicle::GetHeliRotorState() +bool CClientVehicle::GetHeliRotorState() const noexcept { - if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI) - { - auto* heli = reinterpret_cast(m_pVehicle); - if (heli) - return heli->GetHeliRotorState(); - } - - return m_heliRotorState; + return m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI ? m_pVehicle->GetHeliRotorState() : m_heliRotorState; } -void CClientVehicle::SetHeliRotorState(bool state) +void CClientVehicle::SetHeliRotorState(bool state, bool stopRotor) noexcept { if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI) - { - auto* heli = reinterpret_cast(m_pVehicle); - if (heli) - { - heli->SetHeliRotorState(state); - if (!state) - heli->SetHeliRotorSpeed(0.0f); - } - } + m_pVehicle->SetHeliRotorState(state, stopRotor); m_heliRotorState = state; } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index cc897d0596..731b99c2d6 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -299,12 +299,12 @@ class CClientVehicle : public CClientStreamElement // TODO: Make the class remember on virtualization float GetHeliRotorSpeed(); float GetPlaneRotorSpeed(); - bool GetHeliRotorState(); + bool GetHeliRotorState() const noexcept; bool GetRotorSpeed(float&); bool SetRotorSpeed(float); bool SetWheelsRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept; - void SetHeliRotorState(bool state); + void SetHeliRotorState(bool state, bool stopRotor) noexcept; void SetHeliRotorSpeed(float fSpeed); void SetPlaneRotorSpeed(float fSpeed); bool IsHeliSearchLightVisible(); @@ -673,7 +673,7 @@ class CClientVehicle : public CClientStreamElement uchar m_ucTrackID; bool m_bJustStreamedIn; bool m_bWheelScaleChanged; - bool m_heliRotorState; + bool m_heliRotorState{true}; // Time dependent error compensation interpolation struct diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 28299348b1..9f200bd5d8 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -4279,12 +4279,12 @@ std::variant> CLuaVehicleDefs::OOP_GetVehicleEntryP return entryPoints; } -bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state) +bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state, std::optional stopRotor) { if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI) return false; - vehicle->SetHeliRotorState(state); + vehicle->SetHeliRotorState(state, stopRotor.value_or(true)); return true; } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 05670cf026..1a8d24ec86 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -166,7 +166,7 @@ class CLuaVehicleDefs : public CLuaDefs static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize); static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel); - static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state); + static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state, std::optional stopRotor); static bool GetHeliRotorState(CClientVehicle* const vehicle); // Components diff --git a/Client/sdk/game/CHeli.h b/Client/sdk/game/CHeli.h index 8a3a539a9d..a7783a89ca 100644 --- a/Client/sdk/game/CHeli.h +++ b/Client/sdk/game/CHeli.h @@ -16,7 +16,4 @@ class CHeli : public virtual CAutomobile { public: virtual ~CHeli(){}; - - virtual void SetHeliRotorState(bool state) = 0; - virtual bool GetHeliRotorState() = 0; }; diff --git a/Client/sdk/game/CVehicle.h b/Client/sdk/game/CVehicle.h index 356fe40470..dcea716e51 100644 --- a/Client/sdk/game/CVehicle.h +++ b/Client/sdk/game/CVehicle.h @@ -199,6 +199,7 @@ class CVehicle : public virtual CPhysical virtual bool GetTyresDontBurst() = 0; virtual unsigned short GetAdjustablePropertyValue() = 0; virtual float GetHeliRotorSpeed() = 0; + virtual bool GetHeliRotorState() const noexcept = 0; virtual float GetPlaneRotorSpeed() = 0; virtual unsigned long GetExplodeTime() = 0; @@ -220,6 +221,7 @@ class CVehicle : public virtual CPhysical virtual void SetTyresDontBurst(bool bTyresDontBurst) = 0; virtual void SetAdjustablePropertyValue(unsigned short usAdjustableProperty) = 0; virtual void SetHeliRotorSpeed(float fSpeed) = 0; + virtual void SetHeliRotorState(bool state, bool stopRotor) noexcept = 0; virtual void SetPlaneRotorSpeed(float fSpeed) = 0; virtual bool SetVehicleWheelRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept = 0; virtual void SetTaxiLightOn(bool bLightState) = 0; From baf7367ce32ec6042164fdbb380de2e0bdb73411 Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 31 Jul 2024 23:47:30 +0200 Subject: [PATCH 3/7] Comment --- Client/game_sa/CVehicleSA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index a397d66b4f..1351b2eceb 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -1830,7 +1830,7 @@ void CVehicleSA::StaticSetHooks() // Setup vehicle sun glare hook HookInstall(FUNC_CAutomobile_OnVehiclePreRender, (DWORD)HOOK_Vehicle_PreRender, 5); - // + // Setup hook to handle setHelicopterRotorState function HookInstall(FUNC_CHeli_ProcessFlyingCarStuff, (DWORD)HOOK_CHeli_ProcessFlyingCarStuff, 5); } From 3fbdb2a5dff730155198316b239313b39a6d027e Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 31 Jul 2024 23:56:26 +0200 Subject: [PATCH 4/7] Remove unused include --- Client/mods/deathmatch/logic/CClientVehicle.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 69f80df88e..d259b73b16 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -19,7 +19,6 @@ #include #include #include -#include using std::list; From 7ad9e2060fcf5221e29579537b300edb5c7dbd0d Mon Sep 17 00:00:00 2001 From: FileEX Date: Thu, 1 Aug 2024 00:24:42 +0200 Subject: [PATCH 5/7] Review --- Client/game_sa/CVehicleSA.cpp | 8 +++----- Client/game_sa/CVehicleSA.h | 2 +- Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp | 4 ++-- Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h | 4 ++-- Client/sdk/game/CVehicle.h | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 1351b2eceb..27221f0820 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -524,16 +524,14 @@ void CVehicleSA::SetTrainSpeed(float fSpeed) pInterface->m_fTrainSpeed = fSpeed; } -float CVehicleSA::GetHeliRotorSpeed() +float CVehicleSA::GetHeliRotorSpeed() const { - auto* heliInterface = static_cast(GetInterface()); - return heliInterface->m_wheelSpeed[1]; + return static_cast(m_pInterface)->m_wheelSpeed[1]; } void CVehicleSA::SetHeliRotorSpeed(float speed) { - auto* heliInterface = static_cast(GetInterface()); - heliInterface->m_wheelSpeed[1] = speed; + static_cast(GetInterface())->m_wheelSpeed[1] = speed; } void CVehicleSA::SetHeliRotorState(bool state, bool stopRotor) noexcept diff --git a/Client/game_sa/CVehicleSA.h b/Client/game_sa/CVehicleSA.h index fba10c9b8a..9884f4c3cc 100644 --- a/Client/game_sa/CVehicleSA.h +++ b/Client/game_sa/CVehicleSA.h @@ -546,7 +546,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA bool GetTakeLessDamage() { return GetVehicleInterface()->m_nVehicleFlags.bTakeLessDamage; }; bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; }; unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156); }; - float GetHeliRotorSpeed(); + float GetHeliRotorSpeed() const; bool GetHeliRotorState() const noexcept override { return m_heliRotorState; } float GetPlaneRotorSpeed(); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 9f200bd5d8..431d24e9f5 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -4279,7 +4279,7 @@ std::variant> CLuaVehicleDefs::OOP_GetVehicleEntryP return entryPoints; } -bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state, std::optional stopRotor) +bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state, std::optional stopRotor) noexcept { if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI) return false; @@ -4288,7 +4288,7 @@ bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state, std return true; } -bool CLuaVehicleDefs::GetHeliRotorState(CClientVehicle* vehicle) +bool CLuaVehicleDefs::GetHeliRotorState(CClientVehicle* vehicle) noexcept { return vehicle->GetHeliRotorState(); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 1a8d24ec86..e6c79a0da1 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -166,8 +166,8 @@ class CLuaVehicleDefs : public CLuaDefs static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize); static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel); - static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state, std::optional stopRotor); - static bool GetHeliRotorState(CClientVehicle* const vehicle); + static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state, std::optional stopRotor) noexcept; + static bool GetHeliRotorState(CClientVehicle* const vehicle) noexcept; // Components LUA_DECLARE(SetVehicleComponentPosition); diff --git a/Client/sdk/game/CVehicle.h b/Client/sdk/game/CVehicle.h index dcea716e51..38a3112cda 100644 --- a/Client/sdk/game/CVehicle.h +++ b/Client/sdk/game/CVehicle.h @@ -198,7 +198,7 @@ class CVehicle : public virtual CPhysical virtual bool GetTakeLessDamage() = 0; virtual bool GetTyresDontBurst() = 0; virtual unsigned short GetAdjustablePropertyValue() = 0; - virtual float GetHeliRotorSpeed() = 0; + virtual float GetHeliRotorSpeed() const = 0; virtual bool GetHeliRotorState() const noexcept = 0; virtual float GetPlaneRotorSpeed() = 0; virtual unsigned long GetExplodeTime() = 0; From 71d335f731280a86961b9845916ef2f310fee3a5 Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 9 Aug 2024 23:16:39 +0200 Subject: [PATCH 6/7] Changes & review --- Client/game_sa/CVehicleSA.cpp | 54 ++++++++++++++----- Client/game_sa/CVehicleSA.h | 10 ++-- .../mods/deathmatch/logic/CClientVehicle.cpp | 10 ++-- Client/mods/deathmatch/logic/CClientVehicle.h | 4 +- .../logic/luadefs/CLuaVehicleDefs.cpp | 20 +++---- .../logic/luadefs/CLuaVehicleDefs.h | 4 +- Client/sdk/game/CVehicle.h | 4 +- 7 files changed, 66 insertions(+), 40 deletions(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 27221f0820..a6d28cb642 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -52,16 +52,18 @@ void _declspec(naked) HOOK_Vehicle_PreRender(void) } } -bool CanProcessFlyingCarStuff(CHeliSAInterface* heliInterface) +static bool __fastcall CanProcessFlyingCarStuff(CAutomobileSAInterface* vehicleInterface) { - SClientEntity* vehicle = pGame->GetPools()->GetVehicle((DWORD*)heliInterface); + SClientEntity* vehicle = pGame->GetPools()->GetVehicle((DWORD*)vehicleInterface); if (!vehicle || !vehicle->pEntity) return true; - return vehicle->pEntity->GetHeliRotorState(); + return vehicle->pEntity->GetVehicleRotorState(); } -void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff() +static constexpr DWORD CONTINUE_CHeli_ProcessFlyingCarStuff = 0x6C4E82; +static constexpr DWORD RETURN_CHeli_ProcessFlyingCarStuff = 0x6C5404; +static void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff() { _asm { @@ -69,12 +71,8 @@ void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff() mov al, [esi+36h] pushad - push ecx call CanProcessFlyingCarStuff - add esp, 4 - - movzx eax, al - test eax, eax + test al, al jz skip popad @@ -86,6 +84,30 @@ void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff() } } +static constexpr DWORD CONTINUE_CPlane_ProcessFlyingCarStuff = 0x6CB7D7; +static constexpr DWORD RETURN_CPlane_ProcessFlyingCarStuff = 0x6CC482; +static void _declspec(naked) HOOK_CPlane_ProcessFlyingCarStuff() +{ + _asm + { + push esi + mov esi, ecx + fnstsw ax + + pushad + call CanProcessFlyingCarStuff + test al, al + jz skip + + popad + jmp CONTINUE_CPlane_ProcessFlyingCarStuff + + skip: + popad + jmp RETURN_CPlane_ProcessFlyingCarStuff + } +} + namespace { bool ClumpDumpCB(RpAtomic* pAtomic, void* data) @@ -534,12 +556,17 @@ void CVehicleSA::SetHeliRotorSpeed(float speed) static_cast(GetInterface())->m_wheelSpeed[1] = speed; } -void CVehicleSA::SetHeliRotorState(bool state, bool stopRotor) noexcept +void CVehicleSA::SetVehicleRotorState(bool state, bool stopRotor, bool isHeli) noexcept { - m_heliRotorState = state; + m_rotorState = state; - if (!state && stopRotor) + if (state || !stopRotor) + return; + + if (isHeli) SetHeliRotorSpeed(0.0f); + else + SetPlaneRotorSpeed(0.0f); } void CVehicleSA::SetPlaneRotorSpeed(float fSpeed) @@ -1828,8 +1855,9 @@ void CVehicleSA::StaticSetHooks() // Setup vehicle sun glare hook HookInstall(FUNC_CAutomobile_OnVehiclePreRender, (DWORD)HOOK_Vehicle_PreRender, 5); - // Setup hook to handle setHelicopterRotorState function + // Setup hooks to handle setVehicleRotorState function HookInstall(FUNC_CHeli_ProcessFlyingCarStuff, (DWORD)HOOK_CHeli_ProcessFlyingCarStuff, 5); + HookInstall(FUNC_CPlane_ProcessFlyingCarStuff, (DWORD)HOOK_CPlane_ProcessFlyingCarStuff, 5); } void CVehicleSA::SetVehiclesSunGlareEnabled(bool bEnabled) diff --git a/Client/game_sa/CVehicleSA.h b/Client/game_sa/CVehicleSA.h index 9884f4c3cc..67c38131b1 100644 --- a/Client/game_sa/CVehicleSA.h +++ b/Client/game_sa/CVehicleSA.h @@ -95,9 +95,7 @@ struct RwTexture; #define FUNC_CVehicle_DoSunGlare 0x6DD6F0 #define FUNC_CHeli_ProcessFlyingCarStuff 0x6C4E7D - -static constexpr DWORD CONTINUE_CHeli_ProcessFlyingCarStuff = 0x6C4E82; -static constexpr DWORD RETURN_CHeli_ProcessFlyingCarStuff = 0x6C5404; +#define FUNC_CPlane_ProcessFlyingCarStuff 0x6CB7D2 struct SRailNodeSA { @@ -415,7 +413,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA unsigned char m_ucVariant2; unsigned char m_ucVariantCount{0}; bool m_doorsUndamageable{false}; - bool m_heliRotorState{true}; + bool m_rotorState{true}; std::array m_dummyPositions; @@ -547,7 +545,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; }; unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156); }; float GetHeliRotorSpeed() const; - bool GetHeliRotorState() const noexcept override { return m_heliRotorState; } + bool GetVehicleRotorState() const noexcept override { return m_rotorState; } float GetPlaneRotorSpeed(); unsigned long GetExplodeTime() { return *reinterpret_cast(reinterpret_cast(m_pInterface) + 1240); }; @@ -574,7 +572,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA *reinterpret_cast(reinterpret_cast(m_pInterface) + 2156) = usAdjustableProperty; }; void SetHeliRotorSpeed(float speed); - void SetHeliRotorState(bool state, bool stopRotor) noexcept override; + void SetVehicleRotorState(bool state, bool stopRotor, bool isHeli) noexcept override; void SetPlaneRotorSpeed(float fSpeed); bool SetVehicleWheelRotation(float fWheelRot1, float fWheelRot2, float fWheelRot3, float fWheelRot4) noexcept; void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast(reinterpret_cast(m_pInterface) + 1240) = ulTime; }; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index d259b73b16..29c0afc609 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -1576,15 +1576,15 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed) m_fHeliRotorSpeed = fSpeed; } -bool CClientVehicle::GetHeliRotorState() const noexcept +bool CClientVehicle::GetVehicleRotorState() const noexcept { - return m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI ? m_pVehicle->GetHeliRotorState() : m_heliRotorState; + return m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE) ? m_pVehicle->GetVehicleRotorState() : m_heliRotorState; } -void CClientVehicle::SetHeliRotorState(bool state, bool stopRotor) noexcept +void CClientVehicle::SetVehicleRotorState(bool state, bool stopRotor) noexcept { - if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI) - m_pVehicle->SetHeliRotorState(state, stopRotor); + if (m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE)) + m_pVehicle->SetVehicleRotorState(state, stopRotor, GetVehicleType() == CLIENTVEHICLE_HELI); m_heliRotorState = state; } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index 731b99c2d6..e7e20337e4 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -299,12 +299,12 @@ class CClientVehicle : public CClientStreamElement // TODO: Make the class remember on virtualization float GetHeliRotorSpeed(); float GetPlaneRotorSpeed(); - bool GetHeliRotorState() const noexcept; + bool GetVehicleRotorState() const noexcept; bool GetRotorSpeed(float&); bool SetRotorSpeed(float); bool SetWheelsRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept; - void SetHeliRotorState(bool state, bool stopRotor) noexcept; + void SetVehicleRotorState(bool state, bool stopRotor) noexcept; void SetHeliRotorSpeed(float fSpeed); void SetPlaneRotorSpeed(float fSpeed); bool IsHeliSearchLightVisible(); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 431d24e9f5..b71ff2440b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -92,7 +92,7 @@ void CLuaVehicleDefs::LoadFunctions() {"getVehicleModelWheelSize", ArgumentParser}, {"getVehicleWheelFrictionState", ArgumentParser}, {"getVehicleEntryPoints", ArgumentParser}, - {"getHelicopterRotorState", ArgumentParser}, + {"getVehicleRotorState", ArgumentParser}, // Vehicle set funcs {"createVehicle", CreateVehicle}, @@ -156,7 +156,7 @@ void CLuaVehicleDefs::LoadFunctions() {"setVehicleVariant", ArgumentParser}, {"setVehicleWheelScale", ArgumentParser}, {"setVehicleModelWheelSize", ArgumentParser}, - {"setHelicopterRotorState", ArgumentParser}, + {"setVehicleRotorState", ArgumentParser}, }; // Add functions @@ -245,7 +245,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getModelWheelSize", "getVehicleModelWheelSize"); lua_classfunction(luaVM, "getWheelFrictionState", "getVehicleWheelFrictionState"); lua_classfunction(luaVM, "getEntryPoints", ArgumentParser); - lua_classfunction(luaVM, "getRotorState", "getHelicopterRotorState"); + lua_classfunction(luaVM, "getRotorState", "getVehicleRotorState"); lua_classfunction(luaVM, "setComponentVisible", "setVehicleComponentVisible"); lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn"); @@ -294,7 +294,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setVariant", "setVehicleVariant"); lua_classfunction(luaVM, "setWheelScale", "setVehicleWheelScale"); lua_classfunction(luaVM, "setModelWheelSize", "setVehicleModelWheelSize"); - lua_classfunction(luaVM, "setRotorState", "setHelicopterRotorState"); + lua_classfunction(luaVM, "setRotorState", "setVehicleRotorState"); lua_classfunction(luaVM, "resetComponentPosition", "resetVehicleComponentPosition"); lua_classfunction(luaVM, "resetComponentRotation", "resetVehicleComponentRotation"); @@ -351,7 +351,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "gravity", SetVehicleGravity, OOP_GetVehicleGravity); lua_classvariable(luaVM, "turnVelocity", SetVehicleTurnVelocity, OOP_GetVehicleTurnVelocity); lua_classvariable(luaVM, "wheelScale", "setVehicleWheelScale", "getVehicleWheelScale"); - lua_classvariable(luaVM, "rotorState", "setHelicopterRotorState", "getHelicopterRotorState"); + lua_classvariable(luaVM, "rotorState", "setVehicleRotorState", "getVehicleRotorState"); lua_registerclass(luaVM, "Vehicle", "Element"); } @@ -4279,16 +4279,16 @@ std::variant> CLuaVehicleDefs::OOP_GetVehicleEntryP return entryPoints; } -bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state, std::optional stopRotor) noexcept +bool CLuaVehicleDefs::SetVehicleRotorState(CClientVehicle* vehicle, bool state, std::optional stopRotor) noexcept { - if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI) + if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI && vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_PLANE) return false; - vehicle->SetHeliRotorState(state, stopRotor.value_or(true)); + vehicle->SetVehicleRotorState(state, stopRotor.value_or(true)); return true; } -bool CLuaVehicleDefs::GetHeliRotorState(CClientVehicle* vehicle) noexcept +bool CLuaVehicleDefs::GetVehicleRotorState(CClientVehicle* vehicle) noexcept { - return vehicle->GetHeliRotorState(); + return vehicle->GetVehicleRotorState(); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index e6c79a0da1..fa02a342bb 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -166,8 +166,8 @@ class CLuaVehicleDefs : public CLuaDefs static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize); static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel); - static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state, std::optional stopRotor) noexcept; - static bool GetHeliRotorState(CClientVehicle* const vehicle) noexcept; + static bool SetVehicleRotorState(CClientVehicle* const vehicle, bool state, std::optional stopRotor) noexcept; + static bool GetVehicleRotorState(CClientVehicle* const vehicle) noexcept; // Components LUA_DECLARE(SetVehicleComponentPosition); diff --git a/Client/sdk/game/CVehicle.h b/Client/sdk/game/CVehicle.h index 38a3112cda..2e531e0a44 100644 --- a/Client/sdk/game/CVehicle.h +++ b/Client/sdk/game/CVehicle.h @@ -199,7 +199,7 @@ class CVehicle : public virtual CPhysical virtual bool GetTyresDontBurst() = 0; virtual unsigned short GetAdjustablePropertyValue() = 0; virtual float GetHeliRotorSpeed() const = 0; - virtual bool GetHeliRotorState() const noexcept = 0; + virtual bool GetVehicleRotorState() const noexcept = 0; virtual float GetPlaneRotorSpeed() = 0; virtual unsigned long GetExplodeTime() = 0; @@ -221,7 +221,7 @@ class CVehicle : public virtual CPhysical virtual void SetTyresDontBurst(bool bTyresDontBurst) = 0; virtual void SetAdjustablePropertyValue(unsigned short usAdjustableProperty) = 0; virtual void SetHeliRotorSpeed(float fSpeed) = 0; - virtual void SetHeliRotorState(bool state, bool stopRotor) noexcept = 0; + virtual void SetVehicleRotorState(bool state, bool stopRotor, bool isHeli) noexcept = 0; virtual void SetPlaneRotorSpeed(float fSpeed) = 0; virtual bool SetVehicleWheelRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept = 0; virtual void SetTaxiLightOn(bool bLightState) = 0; From e4c4c18da60976859091380667efc644c478f053 Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 9 Aug 2024 23:21:24 +0200 Subject: [PATCH 7/7] Rename variable --- Client/mods/deathmatch/logic/CClientVehicle.cpp | 4 ++-- Client/mods/deathmatch/logic/CClientVehicle.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 29c0afc609..689e3f1778 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -1578,7 +1578,7 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed) bool CClientVehicle::GetVehicleRotorState() const noexcept { - return m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE) ? m_pVehicle->GetVehicleRotorState() : m_heliRotorState; + return m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE) ? m_pVehicle->GetVehicleRotorState() : m_rotorState; } void CClientVehicle::SetVehicleRotorState(bool state, bool stopRotor) noexcept @@ -1586,7 +1586,7 @@ void CClientVehicle::SetVehicleRotorState(bool state, bool stopRotor) noexcept if (m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE)) m_pVehicle->SetVehicleRotorState(state, stopRotor, GetVehicleType() == CLIENTVEHICLE_HELI); - m_heliRotorState = state; + m_rotorState = state; } void CClientVehicle::SetPlaneRotorSpeed(float fSpeed) diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index e7e20337e4..33dc6f578e 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -673,7 +673,7 @@ class CClientVehicle : public CClientStreamElement uchar m_ucTrackID; bool m_bJustStreamedIn; bool m_bWheelScaleChanged; - bool m_heliRotorState{true}; + bool m_rotorState{true}; // Time dependent error compensation interpolation struct