VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Movement.cpp
Go to the documentation of this file.
2#include <utility>
3
4namespace VoltMod
5{
6
8 : _hook("Movement", [this] { return Install(); }),
9 Rewrite(_hook.ForEvent()),
10 Before(_hook.ForEvent()),
11 After(_hook.ForEvent()),
12 _bindings(bindings),
13 _connect(std::move(connect))
14{}
15
16Result<Subscription> Movement::Install()
17{
19 {
20 return std::unexpected(available.error());
21 }
22 return _connect(*this);
23}
24
26{
27 if (!_bindings.RunCommand)
28 {
29 return std::unexpected(Error::Unsupported("the CPlayer_MovementServices::RunCommand vtable slot did not bind"));
30 }
31 if (!_bindings.UserCmdProto)
32 {
33 return std::unexpected(Error::Unsupported("the CUserCmd::CSGOUserCmdPB offset did not bind"));
34 }
35 return {};
36}
37
39{
40 // Every plugin sees the host's decode; only a rewrite needs a copy of its own.
41 if (Rewrite.Empty())
42 {
43 _rewritten.reset();
44 Before.Raise(slot, input);
45 return;
46 }
47 _rewritten = input;
48 Rewrite.Raise(slot, *_rewritten);
49 Before.Raise(slot, *_rewritten);
50}
51
53{
54 After.Raise(slot, _rewritten ? *_rewritten : input);
55}
56
57} // namespace VoltMod
Movement(const Bindings &bindings, Connector connect)
Definition Movement.cpp:7
Event< int, const PlayerInput & > Before
Definition Movement.hpp:40
Event< int, PlayerInput & > Rewrite
Definition Movement.hpp:39
void BeforeCommand(int slot, const PlayerInput &input)
Definition Movement.cpp:38
Event< int, const PlayerInput & > After
Definition Movement.hpp:41
std::function< Subscription(Movement &)> Connector
Definition Movement.hpp:26
void AfterCommand(int slot, const PlayerInput &input)
Definition Movement.cpp:52
Status Available() const
Definition Movement.cpp:25
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
Offset< void > UserCmdProto
Definition Bindings.hpp:105
VirtualFn< void *(EngineMovementServices *, void *)> RunCommand
Definition Bindings.hpp:84
static Error Unsupported(std::string detail)
Definition Result.hpp:57
Protobuf-free snapshot of the CUserCmd handed to CPlayer_MovementServices::RunCommand,...