VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
WeaponDrop.cpp
Go to the documentation of this file.
7
8namespace VoltMod
9{
10
12 : _hook("WeaponDrop", [this] { return Install(); }),
13 Before(_hook.ForEvent()),
14 _entities(entities),
15 _bindings(bindings)
16{}
17
18Result<Subscription> WeaponDrop::Install()
19{
20 const auto onDrop = [this](EngineWeaponServices& services, CEntityInstance*, bool swapping) {
21 return OnDrop(services, swapping);
22 };
23 return HookFunction("WeaponDrop", _bindings.DropWeapon, onDrop);
24}
25
26HookResult<bool> WeaponDrop::OnDrop(EngineWeaponServices& services, bool swapping)
27{
28 CEntityInstance* pawn = Schema::CPlayer_WeaponServices{&services}.OwnerEntity();
29 WeaponDropRequest drop{.Slot = pawn ? Pawn{_entities, pawn}.Slot() : -1, .Swapping = swapping};
30 if (!IsValidSlot(drop.Slot))
31 {
32 return {};
33 }
34
35 Before.Raise(drop);
36 return drop.Blocked ? HookResult<bool>::Block(false) : HookResult<bool>{};
37}
38
39Status WeaponDrop::Available() const
40{
41 if (!_bindings.DropWeapon)
42 {
43 return std::unexpected(Error::Unsupported("the CCSPlayer_WeaponServices::DropWeapon signature did not bind"));
44 }
45 return {};
46}
47
48} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
static HookResult Block(Ret value)
WeaponDrop(EntitySystem &entities, const Bindings &bindings)
Event< WeaponDropRequest & > Before
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.
Definition Hook.hpp:200
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
std::expected< void, Error > Status
Definition Result.hpp:67
Fn< bool(EngineWeaponServices *, CEntityInstance *, bool)> DropWeapon
Definition Bindings.hpp:53