VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Teleport.cpp
Go to the documentation of this file.
7#include <mathlib/vector.h>
8
9namespace VoltMod
10{
11
13{
14 const auto onTeleport = [&entities, &before](CEntityInstance& pawn, const Vector*, const QAngle*, const Vector*) {
15 // Through the controller, so a recycled pawn address cannot mislead.
16 if (const int slot = Pawn{entities, &pawn}.Slot(); IsValidSlot(slot))
17 {
18 before.Raise(slot);
19 }
20 };
21 return HookVirtual("Teleport", bindings.Teleport, onTeleport);
22}
23
25 : _hook("Teleport", [this] { return HookTeleport(_bindings, _entities, Before); }),
26 Before(_hook.ForEvent()),
27 _entities(entities),
28 _bindings(bindings)
29{}
30
32{
33 if (!_bindings.Teleport)
34 {
35 return std::unexpected(Error::Unsupported("the CBaseEntity::Teleport vtable slot did not bind"));
36 }
37 return {};
38}
39
40} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
A multicast signal with a fixed handler signature: the one way to subscribe in VoltMod.
Definition Event.hpp:54
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:19
int Slot() const
Definition Pawn.cpp:218
Event< int > Before
Definition Teleport.hpp:42
Teleport(EntitySystem &entities, const Bindings &bindings)
Definition Teleport.cpp:24
Status Available() const
Definition Teleport.cpp:31
Result< Subscription > HookVirtual(std::string_view name, const VirtualFn< Ret(Object *, Args...)> &function, Before &&before, After &&after=nullptr)
Hook a gamedata-bound virtual function on objects sharing its class vtable.
Definition Hook.hpp:168
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
::QAngle QAngle
Definition Math.hpp:14
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
static Result< Subscription > HookTeleport(const Bindings &bindings, EntitySystem &entities, Event< int > &before)
Definition Teleport.cpp:12
std::expected< void, Error > Status
Definition Result.hpp:67
::Vector Vector
Definition Math.hpp:11
std::expected< T, Error > Result
Definition Result.hpp:64
VirtualFn< void(CEntityInstance *, const Vector *, const QAngle *, const Vector *)> Teleport
Definition Bindings.hpp:77
static Error Unsupported(std::string detail)
Definition Result.hpp:57