Skip to content

Commit 25dd5a5

Browse files
Synchronize changes from 1.6 master branch [ci skip]
fcb5b03 Make onVehicleExplode event cancellable (#4295)
2 parents f36b764 + fcb5b03 commit 25dd5a5

File tree

6 files changed

+49
-22
lines changed

6 files changed

+49
-22
lines changed

Client/mods/deathmatch/logic/CClientExplosionManager.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEnti
129129
{
130130
auto vehicle = reinterpret_cast<CClientVehicle*>(pResponsible);
131131
pOriginSource = vehicle;
132-
133-
// Create an explosion, if the vehicle was not blown by us directly (CClientVehicle::Blow)
134-
if (vehicle->GetBlowState() == VehicleBlowState::INTACT)
135-
{
136-
vehicle->SetBlowState(VehicleBlowState::AWAITING_EXPLOSION_SYNC);
137-
}
138132
}
139133
// If theres other players, sync it relative to the closest (lag compensation)
140134
else if (m_pManager->GetPlayerManager()->Count() > 1)
@@ -157,7 +151,7 @@ bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEnti
157151
}
158152

159153
// Request a new explosion
160-
g_pClientGame->SendExplosionSync(vecPosition, explosionType, pOriginSource);
154+
g_pClientGame->SendExplosionSync(vecPosition, explosionType, pOriginSource, VehicleBlowState::AWAITING_EXPLOSION_SYNC);
161155
return false;
162156
}
163157

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,7 +5262,7 @@ bool CClientGame::StaticProcessPacket(unsigned char ucPacketID, NetBitStreamInte
52625262
return false;
52635263
}
52645264

5265-
void CClientGame::SendExplosionSync(const CVector& vecPosition, eExplosionType Type, CClientEntity* pOrigin)
5265+
void CClientGame::SendExplosionSync(const CVector& vecPosition, eExplosionType Type, CClientEntity* pOrigin, std::optional<VehicleBlowState> vehicleBlowState)
52665266
{
52675267
SPositionSync position(false);
52685268
position.data.vecPosition = vecPosition;
@@ -5285,7 +5285,7 @@ void CClientGame::SendExplosionSync(const CVector& vecPosition, eExplosionType T
52855285
{
52865286
auto vehicle = reinterpret_cast<CClientVehicle*>(pOrigin);
52875287
pBitStream->WriteBit(1);
5288-
pBitStream->WriteBit(vehicle->GetBlowState() == VehicleBlowState::BLOWN);
5288+
pBitStream->WriteBit(vehicleBlowState.value_or(vehicle->GetBlowState()) == VehicleBlowState::BLOWN);
52895289
}
52905290
else
52915291
{

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ class CClientGame
627627
bool VerifySADataFiles(int iEnableClientChecks = 0);
628628
void DebugElementRender();
629629

630-
void SendExplosionSync(const CVector& vecPosition, eExplosionType Type, CClientEntity* pOrigin = NULL);
630+
void SendExplosionSync(const CVector& vecPosition, eExplosionType Type, CClientEntity* pOrigin = nullptr, std::optional<VehicleBlowState> vehicleBlowState = std::nullopt);
631631
void SendFireSync(CFire* pFire);
632632
void SendProjectileSync(CClientProjectile* pProjectile);
633633

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,17 +2866,46 @@ bool CStaticFunctionDefinitions::BlowVehicle(CClientEntity& Entity, std::optiona
28662866
{
28672867
RUN_CHILDREN(BlowVehicle(**iter, withExplosion))
28682868

2869-
if (IS_VEHICLE(&Entity))
2870-
{
2871-
CClientVehicle& vehicle = static_cast<CClientVehicle&>(Entity);
2869+
if (!IS_VEHICLE(&Entity))
2870+
return false;
28722871

2873-
VehicleBlowFlags blow;
2874-
blow.withExplosion = withExplosion.value_or(true);
2872+
CClientVehicle& vehicle = static_cast<CClientVehicle&>(Entity);
2873+
VehicleBlowFlags blow;
2874+
2875+
blow.withExplosion = withExplosion.value_or(true);
2876+
2877+
if (vehicle.IsLocalEntity())
2878+
{
28752879
vehicle.Blow(blow);
2876-
return true;
28772880
}
2881+
else
2882+
{
2883+
CVector position;
2884+
vehicle.GetPosition(position);
28782885

2879-
return false;
2886+
const auto type = vehicle.GetType();
2887+
const auto state = (blow.withExplosion ? VehicleBlowState::AWAITING_EXPLOSION_SYNC : VehicleBlowState::BLOWN);
2888+
eExplosionType explosion;
2889+
2890+
switch (type)
2891+
{
2892+
case CLIENTVEHICLE_CAR:
2893+
explosion = EXP_TYPE_CAR;
2894+
break;
2895+
case CLIENTVEHICLE_HELI:
2896+
explosion = EXP_TYPE_HELI;
2897+
break;
2898+
case CLIENTVEHICLE_BOAT:
2899+
explosion = EXP_TYPE_BOAT;
2900+
break;
2901+
default:
2902+
explosion = EXP_TYPE_CAR;
2903+
}
2904+
2905+
g_pClientGame->SendExplosionSync(position, explosion, &Entity, state);
2906+
}
2907+
2908+
return true;
28802909
}
28812910

28822911
bool CStaticFunctionDefinitions::GetVehicleVariant(CClientVehicle* pVehicle, unsigned char& ucVariant, unsigned char& ucVariant2)

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,18 +2833,20 @@ void CGame::Packet_ExplosionSync(CExplosionSyncPacket& Packet)
28332833

28342834
if (previousBlowState != VehicleBlowState::BLOWN)
28352835
{
2836-
vehicle->SetBlowState(VehicleBlowState::BLOWN);
2837-
vehicle->SetEngineOn(false);
2838-
28392836
// NOTE(botder): We only trigger this event if we didn't blow up a vehicle with `blowVehicle`
28402837
if (previousBlowState == VehicleBlowState::INTACT)
28412838
{
28422839
CLuaArguments arguments;
28432840
arguments.PushBoolean(!Packet.m_blowVehicleWithoutExplosion);
28442841
arguments.PushElement(clientSource);
2845-
vehicle->CallEvent("onVehicleExplode", arguments);
2842+
2843+
if (!vehicle->CallEvent("onVehicleExplode", arguments))
2844+
return;
28462845
}
28472846

2847+
vehicle->SetBlowState(VehicleBlowState::BLOWN);
2848+
vehicle->SetEngineOn(false);
2849+
28482850
syncToPlayers = vehicle->GetBlowState() == VehicleBlowState::BLOWN && !vehicle->IsBeingDeleted();
28492851
}
28502852
else

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5485,7 +5485,9 @@ bool CStaticFunctionDefinitions::BlowVehicle(CElement* pElement, std::optional<b
54855485

54865486
CLuaArguments arguments;
54875487
arguments.PushBoolean(createExplosion); // withExplosion
5488-
vehicle->CallEvent("onVehicleExplode", arguments);
5488+
5489+
if (!vehicle->CallEvent("onVehicleExplode", arguments))
5490+
return false;
54895491

54905492
// Abort if vehicle got fixed or destroyed
54915493
if (!vehicle->IsBlown() || vehicle->IsBeingDeleted())

0 commit comments

Comments
 (0)