Skip to content

Commit

Permalink
New effect: Deadly Bullets (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
gromchek authored Jan 26, 2024
1 parent 20e5fc3 commit b94debd
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions src/gtasa/effects/custom/unsorted/DeadlyBulletsEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "util/CPedDamageResponseCalculator.h"
#include "util/EffectBase.h"
#include "util/hooks/HookMacros.h"

template <float dmgMult> class DeadlyBulletsEffect : public EffectBase
{
bool isPlayerOnly = false;

public:
DeadlyBulletsEffect (bool playerOnly) : isPlayerOnly (playerOnly) {}

void
OnStart (EffectInstance *inst) override
{
if (!isPlayerOnly)
{
HOOK_METHOD_ARGS (inst, Hooked_ComputeWillKillPed_everyone,
void (CPedDamageResponseCalculator *, CPed *,
uint8_t *, char),
0x4B5B27);

HOOK_METHOD_ARGS (inst, Hooked_VehicleInflictDamage_everyone,
void (CVehicle *, CEntity *, eWeaponType, float,
CVector),
0x6D7C90);
}
else
{
HOOK_METHOD_ARGS (inst, Hooked_ComputeWillKillPed_player,
void (CPedDamageResponseCalculator *, CPed *,
uint8_t *, char),
0x4B5B27);

HOOK_METHOD_ARGS (inst, Hooked_VehicleInflictDamage_player,
void (CVehicle *, CEntity *, eWeaponType, float,
CVector),
0x6D7C90);
}
}

static void
Hooked_VehicleInflictDamage_player (auto &&cb, CVehicle *self,
CEntity *damager, eWeaponType type,
float intensity, CVector coords)
{
cb ();

if (damager != FindPlayerPed ()) return;

if (!self || self->m_nPhysicalFlags.bBulletProof) return;

if (type >= WEAPON_PISTOL && type <= WEAPON_SNIPERRIFLE)
{
float mult = std::abs (dmgMult - 1.0f);
self->m_fHealth -= (intensity * mult);
}
}

static void
Hooked_VehicleInflictDamage_everyone (auto &&cb, CVehicle *self,
CEntity *damager, eWeaponType type,
float intensity, CVector coords)
{
cb ();

if (!self || self->m_nPhysicalFlags.bBulletProof) return;

if (type >= WEAPON_PISTOL && type <= WEAPON_SNIPERRIFLE)
{
float mult = std::abs (dmgMult - 1.0f);
self->m_fHealth -= (intensity * mult);
}
}

static void
Hooked_ComputeWillKillPed_player (auto &&cb,
CPedDamageResponseCalculator *thisCalc,
CPed *ped, uint8_t *cDamageResponseInfo,
char a4)
{
if (thisCalc->m_pDamager != FindPlayerPed ()) return;

if (thisCalc->m_weaponType >= WEAPON_PISTOL
&& thisCalc->m_weaponType <= WEAPON_SNIPERRIFLE)
{
thisCalc->m_fDamageFactor *= dmgMult;
}

cb ();
}

static void
Hooked_ComputeWillKillPed_everyone (auto &&cb,
CPedDamageResponseCalculator *thisCalc,
CPed *ped, uint8_t *cDamageResponseInfo,
char a4)
{
if (thisCalc->m_weaponType >= WEAPON_PISTOL
&& thisCalc->m_weaponType <= WEAPON_SNIPERRIFLE)
{
thisCalc->m_fDamageFactor *= dmgMult;
}

cb ();
}
};

using DeadlyBulletsEffectQuad = DeadlyBulletsEffect<4.0f>;

/* clang-format off */
DEFINE_EFFECT (DeadlyBulletsEffectQuad, "effect_deadly_bullets_quad_dmg_everyone",
GROUP_WEAPONS, false);
DEFINE_EFFECT (DeadlyBulletsEffectQuad, "effect_deadly_bullets_quad_dmg_player",
GROUP_WEAPONS, true);
/* clang-format on */

0 comments on commit b94debd

Please sign in to comment.