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:
24 explicit PluginRegistry(LoaderHandoff start = {}, IPluginGameData* gameData = nullptr,
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 /** Where plugins find live schema fields to fill their offsets from. */
48
49 void RaiseFrame();
50 void RaiseServerStartup(std::string_view mapName);
51 /** Ask each plugin whether @p slot may join. The first refusal's reason, or empty to admit. */
52 std::string RaiseClientConnecting(int slot, int64_t steamId, std::string_view name);
53 void RaiseClientConnected(int slot, int64_t steamId, std::string_view name, std::string_view address);
54 void RaiseClientDisconnected(int slot);
55 void RaiseClientFullyConnected(int slot);
56 void RaiseClientSettingsChanged(int slot);
57 /** True when a plugin answered it: later plugins never see it and the engine call is blocked. */
58 bool RaiseConsoleCommand(std::string_view name, std::string_view arguments, int slot);
59 void RaiseCheckTransmit(CCheckTransmitInfo** infoList, int infoCount);
60 void RaiseBuildGameSessionManifest(IEntityResourceManifest* manifest);
61 /** Whether any plugin subscribed to player commands; the host decodes none otherwise. */
62 bool HasCommandListeners() const;
63 void RaisePlayerCommand(int slot, const PlayerInput& input);
64 void RaisePlayerCommandDone(int slot, const PlayerInput& input);
65 void RaiseButtonPress(int slot, std::string_view buttonId);
66
67 /** Keep @p name for the host's own console commands, so no plugin can take it. */
68 void RegisterHostCommand(std::string_view name);
69
70private:
71 SharedState _state;
72 std::vector<std::unique_ptr<PluginContext>> _plugins; ///< in load order
73};
74
75} // namespace VoltMod
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 SetSchemaFields(Schema::LiveFieldLookup lookup)
void RaiseCheckTransmit(CCheckTransmitInfo **infoList, int infoCount)
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)
PluginRegistry(LoaderHandoff start={}, IPluginGameData *gameData=nullptr, IPluginAddons *addons=nullptr)
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)
std::function< LiveField(std::string_view className, std::string_view field)> LiveFieldLookup
Definition Layout.hpp:14
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
Protobuf-free snapshot of the CUserCmd handed to CPlayer_MovementServices::RunCommand,...