VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PluginRegistry.hpp
Go to the documentation of this file.
1#pragma once
2
4
7#include <cstdint>
8#include <memory>
9#include <string>
10#include <string_view>
11#include <vector>
12
13namespace VoltMod
14{
15
16/**
17 * @brief The loaded plugins and the engine events raised on them, one per process.
18 *
19 * Owns the @ref SharedState. Game thread only; nothing locks. SDK-free so it is unit-tested without the engine.
20 */
22{
23public:
25 IPluginAddons* addons = nullptr);
27
30
31 /** Give @p name its own view, at the end of the dispatch order. Nullptr when it already has one.
32 * @p logTag prefixes every line the plugin writes; empty means its name. */
33 PluginContext* AddPlugin(std::string_view name, std::string_view logTag = {}, std::string_view version = {});
34
35 /** Drop every subscription, publication and command name @p name still holds, and report them. */
36 LeakReport RemovePlugin(std::string_view name);
37
38 PluginContext* FindPlugin(std::string_view name);
39
40 /** Between ClientConnected and ClientDisconnected on @p slot. */
41 bool IsConnected(int slot) const { return IsValidSlot(slot) && _state.Clients[slot].has_value(); }
42
43 /** The one gamedata resolution every plugin binds from, null when the host has none. */
44 IPluginGameData* GameData() const { return _state.GameData; }
45
46 /** Record what the host's own schema check found. @p stamp identifies the layout it checked,
47 * so a plugin can tell whether the answer covers the offsets it was built with. */
48 void SetSchemaLayout(uint64_t stamp, bool verified);
49
50 void RaiseFrame();
51 void RaiseServerStartup(std::string_view mapName);
52 /** Ask each plugin whether @p slot may join. The first refusal's reason, or empty to admit. */
53 std::string RaiseClientConnecting(int slot, int64_t steamId, std::string_view name);
54 void RaiseClientConnected(int slot, int64_t steamId, std::string_view name, std::string_view address);
58 /** True when a plugin answered it: later plugins never see it and the engine call is blocked. */
59 bool RaiseConsoleCommand(std::string_view name, std::string_view arguments, int slot);
62 /** Whether any plugin subscribed to player commands; the host decodes none otherwise. */
63 bool HasCommandListeners() const;
64 void RaisePlayerCommand(int slot, const PlayerInput& input);
66 void RaiseButtonPress(int slot, std::string_view buttonId);
67
68 /** Keep @p name for the host's own console commands, so no plugin can take it. */
69 void RegisterHostCommand(std::string_view name);
70
71private:
72 SharedState _state;
73 std::vector<std::unique_ptr<PluginContext>> _plugins; ///< in load order
74};
75
76} // namespace VoltMod
The loaded plugins and the engine events raised on them, one per process.
std::string RaiseClientConnecting(int slot, int64_t steamId, std::string_view name)
void RaiseButtonPress(int slot, std::string_view buttonId)
void RaiseClientSettingsChanged(int slot)
void RegisterHostCommand(std::string_view name)
void RaiseCheckTransmit(CCheckTransmitInfo **infoList, int infoCount)
void SetSchemaLayout(uint64_t stamp, bool verified)
PluginContext * FindPlugin(std::string_view name)
void RaiseClientConnected(int slot, int64_t steamId, std::string_view name, std::string_view address)
void RaiseServerStartup(std::string_view mapName)
void RaiseBuildGameSessionManifest(IEntityResourceManifest *manifest)
bool RaiseConsoleCommand(std::string_view name, std::string_view arguments, int slot)
IPluginGameData * GameData() const
PluginRegistry & operator=(const PluginRegistry &)=delete
LeakReport RemovePlugin(std::string_view name)
PluginRegistry(const PluginRegistry &)=delete
void RaiseClientFullyConnected(int slot)
PluginContext * AddPlugin(std::string_view name, std::string_view logTag={}, std::string_view version={})
void RaiseClientDisconnected(int slot)
bool IsConnected(int slot) const
void RaisePlayerCommand(int slot, const PlayerInput &input)
void RaisePlayerCommandDone(int slot, const PlayerInput &input)
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
Protobuf-free snapshot of the CUserCmd handed to CPlayer_MovementServices::RunCommand,...
IPluginGameData * GameData
PerSlot< std::optional< ConnectedClient > > Clients