Skip to content

Commit 5b69d70

Browse files
authored
Add spawnFlyingComponent & breakGlass arguments for setVehiclePanelState (PR #3572)
1 parent 21593b9 commit 5b69d70

File tree

14 files changed

+71
-31
lines changed

14 files changed

+71
-31
lines changed

Client/game_sa/CDamageManagerSA.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void CDamageManagerSA::SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus)
9898
}
9999
}
100100

101-
void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus)
101+
void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent, bool breakGlass)
102102
{
103103
// Valid index?
104104
if (bPanel < MAX_PANELS && bPanelStatus <= 3)
@@ -140,28 +140,19 @@ void CDamageManagerSA::SetPanelStatus(BYTE bPanel, BYTE bPanelStatus)
140140
else
141141
{
142142
// Call CAutomobile::SetPanelDamage to update the vehicle
143-
dwFunction = 0x6B1480;
144-
dwThis = (DWORD)internalEntityInterface;
145-
bool bUnknown = false;
146-
_asm
147-
{
148-
mov ecx, dwThis
149-
push bUnknown
150-
push dwPanel
151-
call dwFunction
152-
}
143+
((void(__thiscall*)(CEntitySAInterface*, int, bool, bool))0x6B1480)(internalEntityInterface, dwPanel, bPanel == ePanels::WINDSCREEN_PANEL && breakGlass, !spawnFlyingComponent);
153144
}
154145
}
155146
}
156147
}
157148

158-
void CDamageManagerSA::SetPanelStatus(unsigned long ulStatus)
149+
void CDamageManagerSA::SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent, bool breakGlass)
159150
{
160151
unsigned int uiIndex;
161152

162153
for (uiIndex = 0; uiIndex < MAX_PANELS; uiIndex++)
163154
{
164-
SetPanelStatus(static_cast<eDoors>(uiIndex), static_cast<unsigned char>(ulStatus));
155+
SetPanelStatus(static_cast<eDoors>(uiIndex), static_cast<unsigned char>(ulStatus), spawnFlyingComponent, breakGlass);
165156
ulStatus >>= 4;
166157
}
167158
}

Client/game_sa/CDamageManagerSA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class CDamageManagerSA : public CDamageManager
5151
void SetWheelStatus(eWheelPosition bWheel, BYTE bTireStatus);
5252
BYTE GetPanelStatus(BYTE bPanel);
5353
unsigned long GetPanelStatus();
54-
void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus);
55-
void SetPanelStatus(unsigned long ulStatus);
54+
void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent = true, bool breakGlass = false);
55+
void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent = true, bool breakGlass = false);
5656
BYTE GetLightStatus(BYTE bLight);
5757
unsigned char GetLightStatus();
5858
void SetLightStatus(BYTE bLight, BYTE bLightStatus);

Client/mods/deathmatch/logic/CClientVehicle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,12 +1521,12 @@ bool CClientVehicle::GetWheelMissing(unsigned char ucWheel, const SString& strWh
15211521
return false;
15221522
}
15231523

1524-
void CClientVehicle::SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus)
1524+
void CClientVehicle::SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent, bool breakGlass)
15251525
{
15261526
if (ucPanel < MAX_PANELS)
15271527
{
15281528
if (m_pVehicle && HasDamageModel())
1529-
m_pVehicle->GetDamageManager()->SetPanelStatus(static_cast<ePanels>(ucPanel), ucStatus);
1529+
m_pVehicle->GetDamageManager()->SetPanelStatus(static_cast<ePanels>(ucPanel), ucStatus, spawnFlyingComponent, breakGlass);
15301530

15311531
m_ucPanelStates[ucPanel] = ucStatus;
15321532
}

Client/mods/deathmatch/logic/CClientVehicle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class CClientVehicle : public CClientStreamElement
292292

293293
void SetDoorStatus(unsigned char ucDoor, unsigned char ucStatus, bool spawnFlyingComponent);
294294
void SetWheelStatus(unsigned char ucWheel, unsigned char ucStatus, bool bSilent = true);
295-
void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus);
295+
void SetPanelStatus(unsigned char ucPanel, unsigned char ucStatus, bool spawnFlyingComponent = true, bool breakGlass = false);
296296
void SetLightStatus(unsigned char ucLight, unsigned char ucStatus);
297297
bool GetWheelMissing(unsigned char ucWheel, const SString& strWheelName = "");
298298

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,17 +3197,17 @@ bool CStaticFunctionDefinitions::SetVehicleLightState(CClientEntity& Entity, uns
31973197
return false;
31983198
}
31993199

3200-
bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState)
3200+
bool CStaticFunctionDefinitions::SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent, bool breakGlass)
32013201
{
3202-
RUN_CHILDREN(SetVehiclePanelState(**iter, ucPanel, ucState))
3202+
RUN_CHILDREN(SetVehiclePanelState(**iter, ucPanel, ucState, spawnFlyingComponent, breakGlass))
32033203

32043204
if (IS_VEHICLE(&Entity))
32053205
{
32063206
CClientVehicle& Vehicle = static_cast<CClientVehicle&>(Entity);
32073207

32083208
if (ucPanel < 7)
32093209
{
3210-
Vehicle.SetPanelStatus(ucPanel, ucState);
3210+
Vehicle.SetPanelStatus(ucPanel, ucState, spawnFlyingComponent, breakGlass);
32113211
return true;
32123212
}
32133213
}

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class CStaticFunctionDefinitions
243243
static bool SetVehicleDoorState(CClientEntity& Entity, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent);
244244
static bool SetVehicleWheelStates(CClientEntity& Entity, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1);
245245
static bool SetVehicleLightState(CClientEntity& Entity, unsigned char ucLight, unsigned char ucState);
246-
static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState);
246+
static bool SetVehiclePanelState(CClientEntity& Entity, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent = true, bool breakGlass = false);
247247
static bool SetVehicleOverrideLights(CClientEntity& Entity, unsigned char ucLights);
248248
static bool AttachTrailerToVehicle(CClientVehicle& Vehicle, CClientVehicle& Trailer, const CVector& vecRotationOffsetDegrees);
249249
static bool DetachTrailerFromVehicle(CClientVehicle& Vehicle, CClientVehicle* pTrailer = NULL);

Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,14 +1956,17 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM)
19561956
{
19571957
CClientEntity* pEntity = NULL;
19581958
unsigned char ucPanel = 0, ucState = 0;
1959+
bool spawnFlyingComponent, breakGlass;
19591960
CScriptArgReader argStream(luaVM);
19601961
argStream.ReadUserData(pEntity);
19611962
argStream.ReadNumber(ucPanel);
19621963
argStream.ReadNumber(ucState);
1964+
argStream.ReadBool(spawnFlyingComponent, true);
1965+
argStream.ReadBool(breakGlass, false);
19631966

19641967
if (!argStream.HasErrors())
19651968
{
1966-
if (CStaticFunctionDefinitions::SetVehiclePanelState(*pEntity, ucPanel, ucState))
1969+
if (CStaticFunctionDefinitions::SetVehiclePanelState(*pEntity, ucPanel, ucState, spawnFlyingComponent, breakGlass))
19671970
{
19681971
lua_pushboolean(luaVM, true);
19691972
return 1;

Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,15 @@ void CVehicleRPCs::SetVehicleDamageState(CClientEntity* pSource, NetBitStreamInt
352352
unsigned char ucPanel, ucState;
353353
if (bitStream.Read(ucPanel) && bitStream.Read(ucState))
354354
{
355-
pVehicle->SetPanelStatus(ucPanel, ucState);
355+
bool spawnFlyingComponent = true;
356+
bool breakGlass = false;
357+
if (bitStream.Can(eBitStreamVersion::SetVehiclePanelState_SpawnFlyingComponent))
358+
{
359+
bitStream.ReadBit(spawnFlyingComponent);
360+
bitStream.ReadBit(breakGlass);
361+
}
362+
363+
pVehicle->SetPanelStatus(ucPanel, ucState, spawnFlyingComponent, breakGlass);
356364
}
357365
}
358366
default:

Client/multiplayer_sa/CMultiplayerSA_Vehicles.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,33 @@ static void _declspec(naked) HOOK_CAEVehicleAudioEntity__Initialise()
107107
}
108108
}
109109

110+
//////////////////////////////////////////////////////////////////////////////////////////
111+
// CAutomobile::SetPanelDamage
112+
//
113+
// This hook allows determining whether flying components should be spawned
114+
//////////////////////////////////////////////////////////////////////////////////////////
115+
#define HOOKPOS_CAutomobile_SetPanelDamage 0x6B15BE
116+
#define HOOKSIZE_CAutomobile_SetPanelDamage 5
117+
static DWORD SPAWN_FLYING_COMPONENTS = 0x6B15C3;
118+
static DWORD SKIP_FLYING_COMPONENTS = 0x6B15DA;
119+
static void _declspec(naked) HOOK_CAutomobile_SetPanelDamage()
120+
{
121+
_asm
122+
{
123+
mov al, byte ptr [esp+1Ch]
124+
test al, al
125+
jnz skipFlyingComponents
126+
127+
push 5
128+
push ebp
129+
mov ecx, esi
130+
jmp SPAWN_FLYING_COMPONENTS
131+
132+
skipFlyingComponents:
133+
jmp SKIP_FLYING_COMPONENTS
134+
}
135+
}
136+
110137
//////////////////////////////////////////////////////////////////////////////////////////
111138
//
112139
// CMultiplayerSA::InitHooks_Vehicles
@@ -118,4 +145,5 @@ void CMultiplayerSA::InitHooks_Vehicles()
118145
{
119146
EZHookInstall(CDamageManager__ProgressDoorDamage);
120147
EZHookInstall(CAEVehicleAudioEntity__Initialise);
148+
EZHookInstall(CAutomobile_SetPanelDamage);
121149
}

Client/sdk/game/CDamageManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ class CDamageManager
175175
virtual void SetWheelStatus(eWheelPosition bTire, BYTE bTireStatus) = 0;
176176
virtual BYTE GetPanelStatus(BYTE bPanel) = 0;
177177
virtual unsigned long GetPanelStatus() = 0;
178-
virtual void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus) = 0;
179-
virtual void SetPanelStatus(unsigned long ulStatus) = 0;
178+
virtual void SetPanelStatus(BYTE bPanel, BYTE bPanelStatus, bool spawnFlyingComponent = true, bool breakGlass = false) = 0;
179+
virtual void SetPanelStatus(unsigned long ulStatus, bool spawnFlyingComponent = true, bool breakGlass = false) = 0;
180180
virtual BYTE GetLightStatus(BYTE bLight) = 0;
181181
virtual unsigned char GetLightStatus() = 0;
182182
virtual void SetLightStatus(BYTE bLight, BYTE bLightStatus) = 0;

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6719,10 +6719,10 @@ bool CStaticFunctionDefinitions::SetVehicleLightState(CElement* pElement, unsign
67196719
return false;
67206720
}
67216721

6722-
bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState)
6722+
bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent, bool breakGlass)
67236723
{
67246724
assert(pElement);
6725-
RUN_CHILDREN(SetVehiclePanelState(*iter, ucPanel, ucState))
6725+
RUN_CHILDREN(SetVehiclePanelState(*iter, ucPanel, ucState, spawnFlyingComponent, breakGlass))
67266726

67276727
if (IS_VEHICLE(pElement))
67286728
{
@@ -6739,6 +6739,8 @@ bool CStaticFunctionDefinitions::SetVehiclePanelState(CElement* pElement, unsign
67396739
BitStream.pBitStream->Write(ucObject);
67406740
BitStream.pBitStream->Write(ucPanel);
67416741
BitStream.pBitStream->Write(ucState);
6742+
BitStream.pBitStream->WriteBit(spawnFlyingComponent);
6743+
BitStream.pBitStream->WriteBit(breakGlass);
67426744
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_DAMAGE_STATE, *BitStream.pBitStream));
67436745
return true;
67446746
}

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class CStaticFunctionDefinitions
314314
static bool SetVehicleDoorState(CElement* pElement, unsigned char ucDoor, unsigned char ucState, bool spawnFlyingComponent);
315315
static bool SetVehicleWheelStates(CElement* pElement, int iFrontLeft, int iRearLeft = -1, int iFrontRight = -1, int iRearRight = -1);
316316
static bool SetVehicleLightState(CElement* pElement, unsigned char ucLight, unsigned char ucState);
317-
static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState);
317+
static bool SetVehiclePanelState(CElement* pElement, unsigned char ucPanel, unsigned char ucState, bool spawnFlyingComponent = true, bool breakGlass = false);
318318
static bool SetVehicleIdleRespawnDelay(CElement* pElement, unsigned long ulTime);
319319
static bool SetVehicleRespawnDelay(CElement* pElement, unsigned long ulTime);
320320
static bool GetVehicleRespawnPosition(CElement* pElement, CVector& vecPosition);

Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,15 +2125,19 @@ int CLuaVehicleDefs::SetVehiclePanelState(lua_State* luaVM)
21252125
CElement* pElement;
21262126
unsigned char ucPanel;
21272127
unsigned char ucState;
2128+
bool spawnFlyingComponent;
2129+
bool breakGlass;
21282130

21292131
CScriptArgReader argStream(luaVM);
21302132
argStream.ReadUserData(pElement);
21312133
argStream.ReadNumber(ucPanel);
21322134
argStream.ReadNumber(ucState);
2135+
argStream.ReadBool(spawnFlyingComponent, true);
2136+
argStream.ReadBool(breakGlass, false);
21332137

21342138
if (!argStream.HasErrors())
21352139
{
2136-
if (CStaticFunctionDefinitions::SetVehiclePanelState(pElement, ucPanel, ucState))
2140+
if (CStaticFunctionDefinitions::SetVehiclePanelState(pElement, ucPanel, ucState, spawnFlyingComponent, breakGlass))
21372141
{
21382142
lua_pushboolean(luaVM, true);
21392143
return 1;

Shared/sdk/net/bitstream.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,13 @@ enum class eBitStreamVersion : unsigned short
589589
WorldSpecialPropertyEvent,
590590

591591
// Add setElementOnFire function
592-
// 2024-30-12
592+
// 2024-12-30
593593
SetElementOnFire,
594594

595+
// Add "spawnFlyingComponent" to setVehiclePanelState
596+
// 2024-12-31
597+
SetVehiclePanelState_SpawnFlyingComponent,
598+
595599
// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
596600
// Make sure you only add things above this comment.
597601
Next,

0 commit comments

Comments
 (0)