10#include <igameevents.h>
11#include <mathlib/vector.h>
12#include <shareddefs.h>
33 event.SetString(
"weapon", std::string(
weapon).
c_str());
37 : _hook(
"Damage", [
this] {
return Install(); }),
38 Before(_hook.ForEvent()),
53 auto*
info =
static_cast<EngineDamageInfo*
>(
rawInfo);
54 DamageHit
hit{.Victim = Entity{_entities, &
victim},
55 .Attacker = {
static_cast<uint32_t>(
info->Attacker.ToInt())},
56 .Inflictor = {
static_cast<uint32_t>(
info->Inflictor.ToInt())},
57 .Amount =
info->Damage,
68 if (
info->Damage != 0.0f)
82 return std::unexpected(
Error::Unsupported(
"the CBaseEntity::TakeDamageOld signature did not bind"));
86 return std::unexpected(
Error::Unsupported(
"the CTakeDamageInfo constructor signature did not bind"));
109 push.NormalizeInPlace();
114 static_cast<int>(
info.Type), 0,
nullptr);
124 if (!
info.Weapon.empty())
134void Damage::HookDeathEvents()
149 if (!_hit || _hit->
Weapon.empty())
162 SendDeath(*
event, *_hit);
169 const int victim =
death.GetPlayerSlot(
"userid").Get();
Event< DamageHit & > Before
void Apply(const Entity &victim, const DamageInfo &info)
Damage(EntitySystem &entities, const Bindings &bindings, Interfaces &interfaces, GameEvents &events)
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
Entity Get(EntityRef ref)
A live entity, valid for this frame only.
CEntityInstance * Raw() const noexcept
Creates, fires and listens to game events.
IGameEventListener2 * GetClientLegacyListener(int slot) const
static HookResult Block(Ret value)
constexpr uint32_t DamageCrush
constexpr uint32_t DamageBullet
constexpr uint32_t DamageFall
constexpr uint32_t DamageHeadshot
constexpr uint32_t DamageBurn
constexpr uint32_t DamageShock
constexpr uint32_t DamageSlash
constexpr uint32_t DamageClub
constexpr uint32_t DamageGeneric
constexpr uint32_t DamageBlast
Ret CallOriginal(Ret(Iface::*method)(Args...), Iface *instance, Passed &&... args)
Result< Subscription > HookFunction(std::string_view name, const Fn< Ret(Object *, Args...)> &function, Before &&before, After &&after=nullptr)
Hook a signature-bound function at its entry.
static std::string ReadFile(const std::filesystem::path &path)
static void SetWeapon(IGameEvent &event, std::string_view weapon)
std::expected< void, Error > Status
Subscription HookInterface(Ret(Iface::*method)(Args...), Iface *instance, Before &&before, After &&after=nullptr)
Hook one virtual method of an engine interface for a subscription's lifetime.
Fn< void(void *, CEntityInstance *, CEntityInstance *, CEntityInstance *, const Vector *, const Vector *, float, int, int, void *)> BuildDamageInfo
Fn< int64_t(CEntityInstance *, void *, void *)> TakeDamage
std::string_view VictimWeapon
EngineDamageInfo * OriginatingInfo
static Error Unsupported(std::string detail)
Centralized holder for all HL2SDK interface pointers.
IGameEventManager2 * GameEventManager
static constexpr std::string_view EventName