VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Movement.hpp
Go to the documentation of this file.
1#pragma once
2
9#include <functional>
10#include <optional>
11
12namespace VoltMod
13{
14
15/**
16 * @brief Each player's command from CCSPlayer_MovementServices::RunCommand.
17 *
18 * The host hooks RunCommand once for every plugin and decodes each command once; this service
19 * listens to it while one of its events has a handler. @ref PlayerInput::Valid is false when the
20 * usercmd payload was missing.
21 */
23{
24public:
25 /** Subscribes a Movement to the host's commands; dropping the result unsubscribes. */
26 using Connector = std::function<Subscription(Movement&)>;
27
28 /** @p bindings must outlive this; @p connect runs when the first handler arrives. */
30 Movement(const Movement&) = delete;
31 Movement& operator=(const Movement&) = delete;
32
33private:
34 LazyHook _hook;
35
36public:
37 /** Edit this plugin's copy of the command before @ref Before sees it. The engine's usercmd is
38 * unchanged. */
42
43 /** Why movement events cannot fire: the RunCommand slot or the usercmd offset did not bind. */
44 Status Available() const;
45
46 /** @internal The host's command, before and after the engine runs it. */
47 void BeforeCommand(int slot, const PlayerInput& input);
48 void AfterCommand(int slot, const PlayerInput& input);
49
50private:
51 Result<Subscription> Install();
52
53 const Bindings& _bindings;
54 Connector _connect;
55 std::optional<PlayerInput> _rewritten; ///< this plugin's copy while Rewrite has handlers
56};
57
58} // namespace VoltMod
A multicast signal with a fixed handler signature: the one way to subscribe in VoltMod.
Definition Event.hpp:54
An engine hook that exists only while one of its events has handlers.
Definition LazyHook.hpp:30
Each player's command from CCSPlayer_MovementServices::RunCommand.
Definition Movement.hpp:23
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
Movement(const Movement &)=delete
std::function< Subscription(Movement &)> Connector
Definition Movement.hpp:26
void AfterCommand(int slot, const PlayerInput &input)
Definition Movement.cpp:52
Movement & operator=(const Movement &)=delete
Status Available() const
Definition Movement.cpp:25
Owns one registration and releases it on destruction.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
std::expected< T, Error > Result
Definition Result.hpp:64
Protobuf-free snapshot of the CUserCmd handed to CPlayer_MovementServices::RunCommand,...