Skip to content

Commit 4cefa4d

Browse files
authored
Fix client-side createExplosion not triggering onClientExplosion event (#4341)
1 parent faf6824 commit 4cefa4d

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

Client/mods/deathmatch/logic/CClientExplosionManager.cpp

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ bool CClientExplosionManager::Hook_StaticExplosionCreation(CEntity* pGameExplodi
3939
return g_pExplosionManager->Hook_ExplosionCreation(pGameExplodingEntity, pGameCreator, vecPosition, explosionType);
4040
}
4141

42+
eWeaponType CClientExplosionManager::GetWeaponTypeFromExplosionType(const eExplosionType explosionType)
43+
{
44+
switch (explosionType) {
45+
case EXP_TYPE_GRENADE:
46+
return WEAPONTYPE_GRENADE;
47+
case EXP_TYPE_MOLOTOV:
48+
return WEAPONTYPE_MOLOTOV;
49+
case EXP_TYPE_ROCKET:
50+
case EXP_TYPE_ROCKET_WEAK:
51+
return WEAPONTYPE_ROCKET;
52+
case EXP_TYPE_TANK_GRENADE:
53+
return WEAPONTYPE_TANK_GRENADE;
54+
default:
55+
return WEAPONTYPE_EXPLOSION;
56+
}
57+
}
58+
4259
bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEntity, CEntity* pGameCreator, const CVector& vecPosition,
4360
eExplosionType explosionType)
4461
{
@@ -53,7 +70,23 @@ bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEnti
5370
CClientEntity* const pResponsible = pPools->GetClientEntity(reinterpret_cast<DWORD*>(pResponsibleGameEntity->GetInterface()));
5471

5572
if (!pResponsible)
56-
return false;
73+
{
74+
if (!pGameCreator)
75+
return false;
76+
77+
CClientPlayer* localPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
78+
if (!localPlayer || localPlayer->GetGameEntity() != pGameCreator)
79+
return false;
80+
81+
eWeaponType explosionWeaponType = GetWeaponTypeFromExplosionType(explosionType);
82+
83+
CLuaArguments arguments;
84+
arguments.PushNumber(vecPosition.fX);
85+
arguments.PushNumber(vecPosition.fY);
86+
arguments.PushNumber(vecPosition.fZ);
87+
arguments.PushNumber(explosionWeaponType);
88+
return localPlayer->CallEvent("onClientExplosion", arguments, true);
89+
}
5790

5891
// Determine the used weapon
5992
eWeaponType explosionWeaponType = WEAPONTYPE_EXPLOSION;
@@ -167,25 +200,22 @@ CExplosion* CClientExplosionManager::Create(eExplosionType explosionType, CVecto
167200
if (responsibleWeapon != WEAPONTYPE_UNARMED)
168201
m_LastWeaponType = responsibleWeapon;
169202
else
203+
m_LastWeaponType = GetWeaponTypeFromExplosionType(explosionType);
204+
205+
if (pCreator && pCreator->IsLocalEntity())
170206
{
171-
switch (explosionType)
207+
bool allowExplosion = Hook_ExplosionCreation(nullptr, pGameCreator, vecPosition, explosionType);
208+
if (!allowExplosion)
209+
return nullptr;
210+
}
211+
else if (!pCreator)
212+
{
213+
CClientPlayer* localPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
214+
if (localPlayer)
172215
{
173-
case EXP_TYPE_GRENADE:
174-
m_LastWeaponType = WEAPONTYPE_GRENADE;
175-
break;
176-
case EXP_TYPE_MOLOTOV:
177-
m_LastWeaponType = WEAPONTYPE_MOLOTOV;
178-
break;
179-
case EXP_TYPE_ROCKET:
180-
case EXP_TYPE_ROCKET_WEAK:
181-
m_LastWeaponType = WEAPONTYPE_ROCKET;
182-
break;
183-
case EXP_TYPE_TANK_GRENADE:
184-
m_LastWeaponType = WEAPONTYPE_TANK_GRENADE;
185-
break;
186-
default:
187-
m_LastWeaponType = WEAPONTYPE_EXPLOSION;
188-
break;
216+
bool allowExplosion = Hook_ExplosionCreation(nullptr, localPlayer->GetGameEntity(), vecPosition, explosionType);
217+
if (!allowExplosion)
218+
return nullptr;
189219
}
190220
}
191221

Client/mods/deathmatch/logic/CClientExplosionManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ class CClientExplosionManager
3434
CClientEntityPtr m_pLastCreator;
3535

3636
private:
37-
CClientManager* m_pManager;
37+
CClientManager* m_pManager;
38+
eWeaponType GetWeaponTypeFromExplosionType(const eExplosionType explosionType);
3839
};

0 commit comments

Comments
 (0)