From e6a75282e13bc9b85ce3b1b090d2f3041860c920 Mon Sep 17 00:00:00 2001 From: FileEX Date: Mon, 15 Jul 2024 20:11:15 +0200 Subject: [PATCH 1/3] spawnFlyingComponent --- Client/game_sa/CDamageManagerSA.cpp | 12 ++++---- Client/game_sa/CDamageManagerSA.h | 4 +-- .../mods/deathmatch/logic/CClientVehicle.cpp | 6 ++-- Client/mods/deathmatch/logic/CClientVehicle.h | 2 +- Client/mods/deathmatch/logic/CNetAPI.cpp | 2 +- .../mods/deathmatch/logic/CPacketHandler.cpp | 4 +-- .../logic/CStaticFunctionDefinitions.cpp | 6 ++-- .../logic/CStaticFunctionDefinitions.h | 2 +- .../logic/luadefs/CLuaVehicleDefs.cpp | 4 ++- .../deathmatch/logic/rpc/CVehicleRPCs.cpp | 6 +++- .../CMultiplayerSA_Vehicles.cpp | 28 +++++++++++++++++++ Client/sdk/game/CDamageManager.h | 4 +-- .../logic/CStaticFunctionDefinitions.cpp | 5 ++-- .../logic/CStaticFunctionDefinitions.h | 2 +- .../logic/luadefs/CLuaVehicleDefs.cpp | 4 ++- Shared/sdk/net/bitstream.h | 3 ++ 16 files changed, 68 insertions(+), 26 deletions(-) diff --git a/Client/game_sa/CDamageManagerSA.cpp b/Client/game_sa/CDamageManagerSA.cpp index 372dcaeaa5..b6ffca6574 100644 --- a/Client/game_sa/CDamageManagerSA.cpp +++ b/Client/game_sa/CDamageManagerSA.cpp @@ -98,7 +98,7 @@ void CDamageManagerSA::SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus) } } -void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus) +void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent) { // Valid index? if (bPanel < MAX_PANELS && bPanelStatus <= 3) @@ -142,11 +142,13 @@ void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus) // Call CAutomobile::SetPanelDamage to update the vehicle dwFunction = 0x6B1480; dwThis = (DWORD)internalEntityInterface; - bool bUnknown = false; + bool windscreenShatter = bPanel == ePanels::WINDSCREEN_PANEL && spawnFlyingComponent; + bool quiet = !spawnFlyingComponent; _asm { mov ecx, dwThis - push bUnknown + push quiet + push windscreenShatter push dwPanel call dwFunction } @@ -155,13 +157,13 @@ void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus) } } -void CDamageManagerSA::SetPanelStatus(unsigned long ulStatus) +void CDamageManagerSA::SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent) { unsigned int uiIndex; for (uiIndex = 0; uiIndex < MAX_PANELS; uiIndex++) { - SetPanelStatus(static_cast(uiIndex), static_cast(ulStatus)); + SetPanelStatus(static_cast(uiIndex), static_cast(ulStatus), spawnFlyingComponent); ulStatus >>= 4; } } diff --git a/Client/game_sa/CDamageManagerSA.h b/Client/game_sa/CDamageManagerSA.h index 33f72aeccc..44e30d6966 100644 --- a/Client/game_sa/CDamageManagerSA.h +++ b/Client/game_sa/CDamageManagerSA.h @@ -51,8 +51,8 @@ class CDamageManagerSA : public CDamageManager void SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus); BYTE GetPanelStatus(BYTE bPanel); unsigned long GetPanelStatus(); - void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus); - void SetPanelStatus(unsigned long ulStatus); + void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent); + void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent); BYTE GetLightStatus(BYTE bLight); unsigned char GetLightStatus(); void SetLightStatus(BYTE bLight, BYTE bLightStatus); diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 42b2215adc..88f1158f0f 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -814,7 +814,7 @@ void CClientVehicle::Fix() for (int i = 0; i < MAX_DOORS; i++) SetDoorStatus(i, ucDoorStates[i], true); for (int i = 0; i < MAX_PANELS; i++) - SetPanelStatus(i, 0); + SetPanelStatus(i, 0, true); for (int i = 0; i < MAX_LIGHTS; i++) SetLightStatus(i, 0); for (int i = 0; i < MAX_WHEELS; i++) @@ -1524,12 +1524,12 @@ bool CClientVehicle::GetWheelMissing(unsigned char ucWheel, const SString& strWh return false; } -void CClientVehicle::SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus) +void CClientVehicle::SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent) { if (ucPanel < MAX_PANELS) { if (m_pVehicle && HasDamageModel()) - m_pVehicle->GetDamageManager()->SetPanelStatus(static_cast(ucPanel), ucStatus); + m_pVehicle->GetDamageManager()->SetPanelStatus(static_cast(ucPanel), ucStatus, spawnFlyingComponent); m_ucPanelStates[ucPanel] = ucStatus; } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index ff87ef00dc..6bdadbd1f4 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -292,7 +292,7 @@ class CClientVehicle : public CClientStreamElement void SetDoorStatus(unsigned char ucDoor, unsigned char ucStatus, bool spawnFlyingComponent); void SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent = true); - void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus); + void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent); void SetLightStatus(unsigned char ucLight, unsigned char ucStatus); bool GetWheelMissing(unsigned char ucWheel, const SString& strWheelName = ""); diff --git a/Client/mods/deathmatch/logic/CNetAPI.cpp b/Client/mods/deathmatch/logic/CNetAPI.cpp index a6238512c7..1f8b6783e2 100644 --- a/Client/mods/deathmatch/logic/CNetAPI.cpp +++ b/Client/mods/deathmatch/logic/CNetAPI.cpp @@ -2245,7 +2245,7 @@ void CNetAPI::ReadVehiclePartsState(CClientVehicle* pVehicle, NetBitStreamInterf if (damage.data.bSyncPanels) for (unsigned int i = 0; i < MAX_PANELS; ++i) - pVehicle->SetPanelStatus(i, damage.data.panels.data.ucStates[i]); + pVehicle->SetPanelStatus(i, damage.data.panels.data.ucStates[i], true); if (damage.data.bSyncLights) for (unsigned int i = 0; i < MAX_LIGHTS; ++i) diff --git a/Client/mods/deathmatch/logic/CPacketHandler.cpp b/Client/mods/deathmatch/logic/CPacketHandler.cpp index 5b640aa655..ad4d3f2808 100644 --- a/Client/mods/deathmatch/logic/CPacketHandler.cpp +++ b/Client/mods/deathmatch/logic/CPacketHandler.cpp @@ -1635,7 +1635,7 @@ void CPacketHandler::Packet_VehicleDamageSync(NetBitStreamInterface& bitStream) for (unsigned int i = 0; i < MAX_PANELS; ++i) { if (damage.data.bPanelStatesChanged[i]) - pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]); + pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i], true); } for (unsigned int i = 0; i < MAX_LIGHTS; ++i) { @@ -3386,7 +3386,7 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream) for (int i = 0; i < MAX_WHEELS; i++) pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i]); for (int i = 0; i < MAX_PANELS; i++) - pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]); + pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i], true); for (int i = 0; i < MAX_LIGHTS; i++) pVehicle->SetLightStatus(i, damage.data.ucLightStates[i]); pVehicle->ResetDamageModelSync(); diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 87e99ac4ca..b078f3a8cf 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3201,9 +3201,9 @@ bool CStaticFunctionDefinitions::SetVehicleLightState(CClientEntity& Entity, uns return false; } -bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState) +bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent) { - RUN_CHILDREN(SetVehiclePanelState(**iter, ucPanel, ucState)) + RUN_CHILDREN(SetVehiclePanelState(**iter, ucPanel, ucState, spawnFlyingComponent)) if (IS_VEHICLE(&Entity)) { @@ -3211,7 +3211,7 @@ bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, uns if (ucPanel < 7) { - Vehicle.SetPanelStatus(ucPanel, ucState); + Vehicle.SetPanelStatus(ucPanel, ucState, spawnFlyingComponent); return true; } } diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 2ffe1ff0a5..fa798ffd25 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -241,7 +241,7 @@ class CStaticFunctionDefinitions static bool SetVehicleDoorState(CClientEntity& Entity, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent); static bool SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1); static bool SetVehicleLightState(CClientEntity& Entity, unsigned char ucLight, unsigned char ucState); - static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState); + static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent); static bool SetVehicleOverrideLights(CClientEntity& Entity, unsigned char ucLights); static bool AttachTrailerToVehicle(CClientVehicle& Vehicle, CClientVehicle& Trailer, const CVector& vecRotationOffsetDegrees); static bool DetachTrailerFromVehicle(CClientVehicle& Vehicle, CClientVehicle* pTrailer = NULL); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index b26b2163e4..9f889e720d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -1939,14 +1939,16 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM) { CClientEntity* pEntity = NULL; unsigned char ucPanel = 0, ucState = 0; + bool spawnFlyingComponent; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pEntity); argStream.ReadNumber(ucPanel); argStream.ReadNumber(ucState); + argStream.ReadBool(spawnFlyingComponent, true); if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::SetVehiclePanelState(*pEntity, ucPanel, ucState)) + if (CStaticFunctionDefinitions::SetVehiclePanelState(*pEntity, ucPanel, ucState, spawnFlyingComponent)) { lua_pushboolean(luaVM, true); return 1; diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index be586965db..9de51e0589 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -350,7 +350,11 @@ void CVehicleRPCs::SetVehicleDamageState(CClientEntity* pSource, NetBitStreamInt unsigned char ucPanel, ucState; if (bitStream.Read(ucPanel) && bitStream.Read(ucState)) { - pVehicle->SetPanelStatus(ucPanel, ucState); + bool spawnFlyingComponent = true; + if (bitStream.Can(eBitStreamVersion::SetVehiclePanelState_SpawnFlyingComponent)) + bitStream.ReadBit(spawnFlyingComponent); + + pVehicle->SetPanelStatus(ucPanel, ucState, spawnFlyingComponent); } } default: diff --git a/Client/multiplayer_sa/CMultiplayerSA_Vehicles.cpp b/Client/multiplayer_sa/CMultiplayerSA_Vehicles.cpp index 88b0b11eb8..9884e8e658 100644 --- a/Client/multiplayer_sa/CMultiplayerSA_Vehicles.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA_Vehicles.cpp @@ -107,6 +107,33 @@ static void _declspec(naked) HOOK_CAEVehicleAudioEntity__Initialise() } } +////////////////////////////////////////////////////////////////////////////////////////// +// CAutomobile::SetPanelDamage +// +// This hook allows determining whether flying components should be spawned +////////////////////////////////////////////////////////////////////////////////////////// +#define HOOKPOS_CAutomobile_SetPanelDamage 0x6B15BE +#define HOOKSIZE_CAutomobile_SetPanelDamage 5 +static DWORD SPAWN_FLYING_COMPONENTS = 0x6B15C3; +static DWORD SKIP_FLYING_COMPONENTS = 0x6B15DA; +static void _declspec(naked) HOOK_CAutomobile_SetPanelDamage() +{ + _asm + { + mov al, byte ptr [esp+1Ch] + test al, al + jnz skipFlyingComponents + + push 5 + push ebp + mov ecx, esi + jmp SPAWN_FLYING_COMPONENTS + + skipFlyingComponents: + jmp SKIP_FLYING_COMPONENTS + } +} + ////////////////////////////////////////////////////////////////////////////////////////// // // CMultiplayerSA::InitHooks_Vehicles @@ -118,4 +145,5 @@ void CMultiplayerSA::InitHooks_Vehicles() { EZHookInstall(CDamageManager__ProgressDoorDamage); EZHookInstall(CAEVehicleAudioEntity__Initialise); + EZHookInstall(CAutomobile_SetPanelDamage); } diff --git a/Client/sdk/game/CDamageManager.h b/Client/sdk/game/CDamageManager.h index 81fda71267..d3eec78db0 100644 --- a/Client/sdk/game/CDamageManager.h +++ b/Client/sdk/game/CDamageManager.h @@ -132,8 +132,8 @@ class CDamageManager virtual void SetWheelStatus(eWheelPosition bTire, BYTE bTireStatus) = 0; virtual BYTE GetPanelStatus(BYTE bPanel) = 0; virtual unsigned long GetPanelStatus() = 0; - virtual void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus) = 0; - virtual void SetPanelStatus(unsigned long ulStatus) = 0; + virtual void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent) = 0; + virtual void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent) = 0; virtual BYTE GetLightStatus(BYTE bLight) = 0; virtual unsigned char GetLightStatus() = 0; virtual void SetLightStatus(BYTE bLight, BYTE bLightStatus) = 0; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index cbfb4809b5..15d1d5aea1 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -6732,10 +6732,10 @@ bool CStaticFunctionDefinitions::SetVehicleLightState(CElement* pElement, unsign return false; } -bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState) +bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent) { assert(pElement); - RUN_CHILDREN(SetVehiclePanelState(*iter, ucPanel, ucState)) + RUN_CHILDREN(SetVehiclePanelState(*iter, ucPanel, ucState, spawnFlyingComponent)) if (IS_VEHICLE(pElement)) { @@ -6752,6 +6752,7 @@ bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsign BitStream.pBitStream->Write(ucObject); BitStream.pBitStream->Write(ucPanel); BitStream.pBitStream->Write(ucState); + BitStream.pBitStream->WriteBit(spawnFlyingComponent); m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_DAMAGE_STATE, *BitStream.pBitStream)); return true; } diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index db6fb1874e..41262ee0e0 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -311,7 +311,7 @@ class CStaticFunctionDefinitions static bool SetVehicleDoorState(CElement* pElement, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent); static bool SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1); static bool SetVehicleLightState(CElement* pElement, unsigned char ucLight, unsigned char ucState); - static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState); + static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent); static bool SetVehicleIdleRespawnDelay(CElement* pElement, unsigned long ulTime); static bool SetVehicleRespawnDelay(CElement* pElement, unsigned long ulTime); static bool GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 294ea7310c..c88731522d 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -2122,15 +2122,17 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM) CElement* pElement; unsigned char ucPanel; unsigned char ucState; + bool spawnFlyingComponent; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pElement); argStream.ReadNumber(ucPanel); argStream.ReadNumber(ucState); + argStream.ReadBool(spawnFlyingComponent, true); if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::SetVehiclePanelState(pElement, ucPanel, ucState)) + if (CStaticFunctionDefinitions::SetVehiclePanelState(pElement, ucPanel, ucState, spawnFlyingComponent)) { lua_pushboolean(luaVM, true); return 1; diff --git a/Shared/sdk/net/bitstream.h b/Shared/sdk/net/bitstream.h index e0de0f9172..38e653ec5b 100644 --- a/Shared/sdk/net/bitstream.h +++ b/Shared/sdk/net/bitstream.h @@ -560,6 +560,9 @@ enum class eBitStreamVersion : unsigned short // 2024-06-30 WorldSpecialProperty_TunnelWeatherBlend, + // Add "spawnFlyingComponent" to setVehiclePanelState + // 2024-07-15 + SetVehiclePanelState_SpawnFlyingComponent, // This allows us to automatically increment the BitStreamVersion when things are added to this enum. // Make sure you only add things above this comment. From dda9018a6fef4f6873b8b947dfa5f93de7eca697 Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 17 Jul 2024 16:16:39 +0200 Subject: [PATCH 2/3] Add breakGlass argument --- Client/game_sa/CDamageManagerSA.cpp | 8 ++++---- Client/game_sa/CDamageManagerSA.h | 4 ++-- Client/mods/deathmatch/logic/CClientVehicle.cpp | 6 +++--- Client/mods/deathmatch/logic/CClientVehicle.h | 2 +- Client/mods/deathmatch/logic/CNetAPI.cpp | 2 +- Client/mods/deathmatch/logic/CPacketHandler.cpp | 4 ++-- .../mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 6 +++--- Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h | 2 +- Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp | 5 +++-- Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp | 6 +++++- Client/sdk/game/CDamageManager.h | 4 ++-- .../mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 5 +++-- Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h | 2 +- Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp | 4 +++- 14 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Client/game_sa/CDamageManagerSA.cpp b/Client/game_sa/CDamageManagerSA.cpp index b6ffca6574..e98ad93393 100644 --- a/Client/game_sa/CDamageManagerSA.cpp +++ b/Client/game_sa/CDamageManagerSA.cpp @@ -98,7 +98,7 @@ void CDamageManagerSA::SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus) } } -void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent) +void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent, bool breakGlass) { // Valid index? if (bPanel < MAX_PANELS && bPanelStatus <= 3) @@ -142,7 +142,7 @@ void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawn // Call CAutomobile::SetPanelDamage to update the vehicle dwFunction = 0x6B1480; dwThis = (DWORD)internalEntityInterface; - bool windscreenShatter = bPanel == ePanels::WINDSCREEN_PANEL && spawnFlyingComponent; + bool windscreenShatter = bPanel == ePanels::WINDSCREEN_PANEL && breakGlass; bool quiet = !spawnFlyingComponent; _asm { @@ -157,13 +157,13 @@ void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawn } } -void CDamageManagerSA::SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent) +void CDamageManagerSA::SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent, bool breakGlass) { unsigned int uiIndex; for (uiIndex = 0; uiIndex < MAX_PANELS; uiIndex++) { - SetPanelStatus(static_cast(uiIndex), static_cast(ulStatus), spawnFlyingComponent); + SetPanelStatus(static_cast(uiIndex), static_cast(ulStatus), spawnFlyingComponent, breakGlass); ulStatus >>= 4; } } diff --git a/Client/game_sa/CDamageManagerSA.h b/Client/game_sa/CDamageManagerSA.h index 44e30d6966..00651f68b5 100644 --- a/Client/game_sa/CDamageManagerSA.h +++ b/Client/game_sa/CDamageManagerSA.h @@ -51,8 +51,8 @@ class CDamageManagerSA : public CDamageManager void SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus); BYTE GetPanelStatus(BYTE bPanel); unsigned long GetPanelStatus(); - void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent); - void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent); + void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent = true, bool breakGlass = false); + void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent = true, bool breakGlass = false); BYTE GetLightStatus(BYTE bLight); unsigned char GetLightStatus(); void SetLightStatus(BYTE bLight, BYTE bLightStatus); diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 88f1158f0f..1564204e0d 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -814,7 +814,7 @@ void CClientVehicle::Fix() for (int i = 0; i < MAX_DOORS; i++) SetDoorStatus(i, ucDoorStates[i], true); for (int i = 0; i < MAX_PANELS; i++) - SetPanelStatus(i, 0, true); + SetPanelStatus(i, 0); for (int i = 0; i < MAX_LIGHTS; i++) SetLightStatus(i, 0); for (int i = 0; i < MAX_WHEELS; i++) @@ -1524,12 +1524,12 @@ bool CClientVehicle::GetWheelMissing(unsigned char ucWheel, const SString& strWh return false; } -void CClientVehicle::SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent) +void CClientVehicle::SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent, bool breakGlass) { if (ucPanel < MAX_PANELS) { if (m_pVehicle && HasDamageModel()) - m_pVehicle->GetDamageManager()->SetPanelStatus(static_cast(ucPanel), ucStatus, spawnFlyingComponent); + m_pVehicle->GetDamageManager()->SetPanelStatus(static_cast(ucPanel), ucStatus, spawnFlyingComponent, breakGlass); m_ucPanelStates[ucPanel] = ucStatus; } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index 6bdadbd1f4..f5bc422e87 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -292,7 +292,7 @@ class CClientVehicle : public CClientStreamElement void SetDoorStatus(unsigned char ucDoor, unsigned char ucStatus, bool spawnFlyingComponent); void SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent = true); - void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent); + void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent = true, bool breakGlass = false); void SetLightStatus(unsigned char ucLight, unsigned char ucStatus); bool GetWheelMissing(unsigned char ucWheel, const SString& strWheelName = ""); diff --git a/Client/mods/deathmatch/logic/CNetAPI.cpp b/Client/mods/deathmatch/logic/CNetAPI.cpp index 1f8b6783e2..a6238512c7 100644 --- a/Client/mods/deathmatch/logic/CNetAPI.cpp +++ b/Client/mods/deathmatch/logic/CNetAPI.cpp @@ -2245,7 +2245,7 @@ void CNetAPI::ReadVehiclePartsState(CClientVehicle* pVehicle, NetBitStreamInterf if (damage.data.bSyncPanels) for (unsigned int i = 0; i < MAX_PANELS; ++i) - pVehicle->SetPanelStatus(i, damage.data.panels.data.ucStates[i], true); + pVehicle->SetPanelStatus(i, damage.data.panels.data.ucStates[i]); if (damage.data.bSyncLights) for (unsigned int i = 0; i < MAX_LIGHTS; ++i) diff --git a/Client/mods/deathmatch/logic/CPacketHandler.cpp b/Client/mods/deathmatch/logic/CPacketHandler.cpp index 9fe0d17caa..ed8ba623c1 100644 --- a/Client/mods/deathmatch/logic/CPacketHandler.cpp +++ b/Client/mods/deathmatch/logic/CPacketHandler.cpp @@ -1637,7 +1637,7 @@ void CPacketHandler::Packet_VehicleDamageSync(NetBitStreamInterface& bitStream) for (unsigned int i = 0; i < MAX_PANELS; ++i) { if (damage.data.bPanelStatesChanged[i]) - pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i], true); + pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]); } for (unsigned int i = 0; i < MAX_LIGHTS; ++i) { @@ -3388,7 +3388,7 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream) for (int i = 0; i < MAX_WHEELS; i++) pVehicle->SetWheelStatus(i, damage.data.ucWheelStates[i]); for (int i = 0; i < MAX_PANELS; i++) - pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i], true); + pVehicle->SetPanelStatus(i, damage.data.ucPanelStates[i]); for (int i = 0; i < MAX_LIGHTS; i++) pVehicle->SetLightStatus(i, damage.data.ucLightStates[i]); pVehicle->ResetDamageModelSync(); diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 8dc1eb0e09..e54c38be65 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3202,9 +3202,9 @@ bool CStaticFunctionDefinitions::SetVehicleLightState(CClientEntity& Entity, uns return false; } -bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent) +bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent, bool breakGlass) { - RUN_CHILDREN(SetVehiclePanelState(**iter, ucPanel, ucState, spawnFlyingComponent)) + RUN_CHILDREN(SetVehiclePanelState(**iter, ucPanel, ucState, spawnFlyingComponent, breakGlass)) if (IS_VEHICLE(&Entity)) { @@ -3212,7 +3212,7 @@ bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, uns if (ucPanel < 7) { - Vehicle.SetPanelStatus(ucPanel, ucState, spawnFlyingComponent); + Vehicle.SetPanelStatus(ucPanel, ucState, spawnFlyingComponent, breakGlass); return true; } } diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 420bc34634..7bcc2152e8 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -241,7 +241,7 @@ class CStaticFunctionDefinitions static bool SetVehicleDoorState(CClientEntity& Entity, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent); static bool SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1); static bool SetVehicleLightState(CClientEntity& Entity, unsigned char ucLight, unsigned char ucState); - static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent); + static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent = true, bool breakGlass = false); static bool SetVehicleOverrideLights(CClientEntity& Entity, unsigned char ucLights); static bool AttachTrailerToVehicle(CClientVehicle& Vehicle, CClientVehicle& Trailer, const CVector& vecRotationOffsetDegrees); static bool DetachTrailerFromVehicle(CClientVehicle& Vehicle, CClientVehicle* pTrailer = NULL); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 9f889e720d..30a05856cd 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -1939,16 +1939,17 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM) { CClientEntity* pEntity = NULL; unsigned char ucPanel = 0, ucState = 0; - bool spawnFlyingComponent; + bool spawnFlyingComponent, breakGlass; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pEntity); argStream.ReadNumber(ucPanel); argStream.ReadNumber(ucState); argStream.ReadBool(spawnFlyingComponent, true); + argStream.ReadBool(breakGlass, false); if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::SetVehiclePanelState(*pEntity, ucPanel, ucState, spawnFlyingComponent)) + if (CStaticFunctionDefinitions::SetVehiclePanelState(*pEntity, ucPanel, ucState, spawnFlyingComponent, breakGlass)) { lua_pushboolean(luaVM, true); return 1; diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index 9de51e0589..c470bbbbaf 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -351,10 +351,14 @@ void CVehicleRPCs::SetVehicleDamageState(CClientEntity* pSource, NetBitStreamInt if (bitStream.Read(ucPanel) && bitStream.Read(ucState)) { bool spawnFlyingComponent = true; + bool breakGlass = false; if (bitStream.Can(eBitStreamVersion::SetVehiclePanelState_SpawnFlyingComponent)) + { bitStream.ReadBit(spawnFlyingComponent); + bitStream.ReadBit(breakGlass); + } - pVehicle->SetPanelStatus(ucPanel, ucState, spawnFlyingComponent); + pVehicle->SetPanelStatus(ucPanel, ucState, spawnFlyingComponent, breakGlass); } } default: diff --git a/Client/sdk/game/CDamageManager.h b/Client/sdk/game/CDamageManager.h index d3eec78db0..df6511b052 100644 --- a/Client/sdk/game/CDamageManager.h +++ b/Client/sdk/game/CDamageManager.h @@ -132,8 +132,8 @@ class CDamageManager virtual void SetWheelStatus(eWheelPosition bTire, BYTE bTireStatus) = 0; virtual BYTE GetPanelStatus(BYTE bPanel) = 0; virtual unsigned long GetPanelStatus() = 0; - virtual void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent) = 0; - virtual void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent) = 0; + virtual void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent = true, bool breakGlass = false) = 0; + virtual void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent = true, bool breakGlass = false) = 0; virtual BYTE GetLightStatus(BYTE bLight) = 0; virtual unsigned char GetLightStatus() = 0; virtual void SetLightStatus(BYTE bLight, BYTE bLightStatus) = 0; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 4ff7f74d70..366be40f0c 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -6734,10 +6734,10 @@ bool CStaticFunctionDefinitions::SetVehicleLightState(CElement* pElement, unsign return false; } -bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent) +bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent, bool breakGlass) { assert(pElement); - RUN_CHILDREN(SetVehiclePanelState(*iter, ucPanel, ucState, spawnFlyingComponent)) + RUN_CHILDREN(SetVehiclePanelState(*iter, ucPanel, ucState, spawnFlyingComponent, breakGlass)) if (IS_VEHICLE(pElement)) { @@ -6755,6 +6755,7 @@ bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsign BitStream.pBitStream->Write(ucPanel); BitStream.pBitStream->Write(ucState); BitStream.pBitStream->WriteBit(spawnFlyingComponent); + BitStream.pBitStream->WriteBit(breakGlass); m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_DAMAGE_STATE, *BitStream.pBitStream)); return true; } diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 3f1cadaee4..2ed33b93b2 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -311,7 +311,7 @@ class CStaticFunctionDefinitions static bool SetVehicleDoorState(CElement* pElement, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent); static bool SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1); static bool SetVehicleLightState(CElement* pElement, unsigned char ucLight, unsigned char ucState); - static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent); + static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent = true, bool breakGlass = false); static bool SetVehicleIdleRespawnDelay(CElement* pElement, unsigned long ulTime); static bool SetVehicleRespawnDelay(CElement* pElement, unsigned long ulTime); static bool GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index c88731522d..529c7e7e43 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -2123,16 +2123,18 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM) unsigned char ucPanel; unsigned char ucState; bool spawnFlyingComponent; + bool breakGlass; CScriptArgReader argStream(luaVM); argStream.ReadUserData(pElement); argStream.ReadNumber(ucPanel); argStream.ReadNumber(ucState); argStream.ReadBool(spawnFlyingComponent, true); + argStream.ReadBool(breakGlass, false); if (!argStream.HasErrors()) { - if (CStaticFunctionDefinitions::SetVehiclePanelState(pElement, ucPanel, ucState, spawnFlyingComponent)) + if (CStaticFunctionDefinitions::SetVehiclePanelState(pElement, ucPanel, ucState, spawnFlyingComponent, breakGlass)) { lua_pushboolean(luaVM, true); return 1; From 17d68d0400b67cfbe78c58bf1beec11565dcf881 Mon Sep 17 00:00:00 2001 From: FileEX Date: Sat, 5 Oct 2024 18:05:46 +0200 Subject: [PATCH 3/3] Review --- Client/game_sa/CDamageManagerSA.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Client/game_sa/CDamageManagerSA.cpp b/Client/game_sa/CDamageManagerSA.cpp index e98ad93393..6f5ae8f81e 100644 --- a/Client/game_sa/CDamageManagerSA.cpp +++ b/Client/game_sa/CDamageManagerSA.cpp @@ -140,18 +140,7 @@ void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawn else { // Call CAutomobile::SetPanelDamage to update the vehicle - dwFunction = 0x6B1480; - dwThis = (DWORD)internalEntityInterface; - bool windscreenShatter = bPanel == ePanels::WINDSCREEN_PANEL && breakGlass; - bool quiet = !spawnFlyingComponent; - _asm - { - mov ecx, dwThis - push quiet - push windscreenShatter - push dwPanel - call dwFunction - } + ((void(__thiscall*)(CEntitySAInterface*, int, bool, bool))0x6B1480)(internalEntityInterface, dwPanel, bPanel == ePanels::WINDSCREEN_PANEL && breakGlass, !spawnFlyingComponent); } } }