Skip to content

Fix client-side createExplosion not triggering onClientExplosion event #4341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions Client/mods/deathmatch/logic/CClientExplosionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ bool CClientExplosionManager::Hook_StaticExplosionCreation(CEntity* pGameExplodi
return g_pExplosionManager->Hook_ExplosionCreation(pGameExplodingEntity, pGameCreator, vecPosition, explosionType);
}

eWeaponType CClientExplosionManager::GetWeaponTypeFromExplosionType(eExplosionType explosionType)
{
switch (explosionType) {
case EXP_TYPE_GRENADE:
return WEAPONTYPE_GRENADE;
case EXP_TYPE_MOLOTOV:
return WEAPONTYPE_MOLOTOV;
case EXP_TYPE_ROCKET:
case EXP_TYPE_ROCKET_WEAK:
return WEAPONTYPE_ROCKET;
case EXP_TYPE_TANK_GRENADE:
return WEAPONTYPE_TANK_GRENADE;
default:
return WEAPONTYPE_EXPLOSION;
}
}

bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEntity, CEntity* pGameCreator, const CVector& vecPosition,
eExplosionType explosionType)
{
Expand All @@ -53,7 +70,23 @@ bool CClientExplosionManager::Hook_ExplosionCreation(CEntity* pGameExplodingEnti
CClientEntity* const pResponsible = pPools->GetClientEntity(reinterpret_cast<DWORD*>(pResponsibleGameEntity->GetInterface()));

if (!pResponsible)
return false;
{
if (!pGameCreator)
return false;

CClientPlayer* pLocalPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
if (!pLocalPlayer || pLocalPlayer->GetGameEntity() != pGameCreator)
return false;

eWeaponType explosionWeaponType = GetWeaponTypeFromExplosionType(explosionType);

CLuaArguments arguments;
arguments.PushNumber(vecPosition.fX);
arguments.PushNumber(vecPosition.fY);
arguments.PushNumber(vecPosition.fZ);
arguments.PushNumber(explosionWeaponType);
return pLocalPlayer->CallEvent("onClientExplosion", arguments, true);
}

// Determine the used weapon
eWeaponType explosionWeaponType = WEAPONTYPE_EXPLOSION;
Expand Down Expand Up @@ -167,25 +200,22 @@ CExplosion* CClientExplosionManager::Create(eExplosionType explosionType, CVecto
if (responsibleWeapon != WEAPONTYPE_UNARMED)
m_LastWeaponType = responsibleWeapon;
else
m_LastWeaponType = GetWeaponTypeFromExplosionType(explosionType);

if (pCreator && pCreator->IsLocalEntity())
{
switch (explosionType)
bool bAllowExplosion = Hook_ExplosionCreation(nullptr, pGameCreator, vecPosition, explosionType);
if (!bAllowExplosion)
return nullptr;
}
else if (!pCreator)
{
CClientPlayer* pLocalPlayer = m_pManager->GetPlayerManager()->GetLocalPlayer();
if (pLocalPlayer)
{
case EXP_TYPE_GRENADE:
m_LastWeaponType = WEAPONTYPE_GRENADE;
break;
case EXP_TYPE_MOLOTOV:
m_LastWeaponType = WEAPONTYPE_MOLOTOV;
break;
case EXP_TYPE_ROCKET:
case EXP_TYPE_ROCKET_WEAK:
m_LastWeaponType = WEAPONTYPE_ROCKET;
break;
case EXP_TYPE_TANK_GRENADE:
m_LastWeaponType = WEAPONTYPE_TANK_GRENADE;
break;
default:
m_LastWeaponType = WEAPONTYPE_EXPLOSION;
break;
bool bAllowExplosion = Hook_ExplosionCreation(nullptr, pLocalPlayer->GetGameEntity(), vecPosition, explosionType);
if (!bAllowExplosion)
return nullptr;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CClientExplosionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ class CClientExplosionManager
CClientEntityPtr m_pLastCreator;

private:
CClientManager* m_pManager;
CClientManager* m_pManager;
eWeaponType GetWeaponTypeFromExplosionType(eExplosionType explosionType);
};
Loading