VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ButtonPresses.hpp
Go to the documentation of this file.
1#pragma once
2
6
11#include <string>
12#include <vector>
13
14namespace VoltMod
15{
16
17/**
18 * @brief The FilterMessage hook for every plugin: custom HUD button presses, raised on the frame
19 * after they arrive. Game thread only.
20 */
22{
23public:
24 /** A missing message registry hooks nothing. @p bindings and @p registry must outlive this. */
26
27 ButtonPresses(const ButtonPresses&) = delete;
29
30 /** Raise the presses that arrived since the last frame. */
31 void OnFrame();
32
33private:
34 struct Press
35 {
36 int Slot = -1;
37 std::string ButtonId;
38 };
39
40 /** The user message fields a press is read from, resolved on the first message. */
41 struct MessageFields
42 {
43 const ProtoFieldDescriptor* Type = nullptr;
44 const ProtoFieldDescriptor* Data = nullptr;
45
46 explicit operator bool() const { return Type && Data; }
47 };
48
49 static const MessageFields& FieldsOf(const ProtoMessage& proto);
50
51 Status Install(const EngineInterfaces& engine);
52
54 void WarnMalformed(int slot, std::string_view detail);
55
56 PluginRegistry& _registry;
57 const Bindings& _bindings;
58 int _messageId = -1;
59 std::vector<Press> _queued;
60 Cooldown<int> _warnings; ///< a client can send malformed presses at will
61 Subscription _hook;
62};
63
64} // namespace VoltMod
Access CS user-message fields through protobuf reflection.
The FilterMessage hook for every plugin: custom HUD button presses, raised on the frame after they ar...
ButtonPresses(const ButtonPresses &)=delete
ButtonPresses & operator=(const ButtonPresses &)=delete
The loaded plugins and the engine events raised on them, one per process.
google::protobuf::Message ProtoMessage
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
google::protobuf::FieldDescriptor ProtoFieldDescriptor