VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PluginModule.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <concepts>
9#include <cstddef>
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <string_view>
14
15namespace VoltMod::Internal
16{
17
18template <class T>
19concept PluginType = std::derived_from<T, Plugin> && std::constructible_from<T, Runtime&>;
20
21using PluginFactory = std::unique_ptr<Plugin> (*)(Runtime&);
22
23/** Owns the host connection, runtime, and one user plugin for each load cycle. */
25{
26public:
27 explicit PluginModule(PluginFactory factory) : _factory(factory) {}
29
30 PluginModule(const PluginModule&) = delete;
32
33 bool Attach(IPluginContext& host, char* error, size_t errorSize) noexcept;
34 void Detach() noexcept;
36
38 bool AttachImpl(IPluginContext& host, char* error, size_t errorSize);
39 /** Log the load steps, hand the host @p reason, and tear down what was built. */
40 bool Refuse(std::string_view reason, char* error, size_t errorSize);
41
42 void OnServerStartup(std::string_view mapName);
43 bool OnConsoleCommand(std::string_view name, std::string_view arguments, int slot);
44 void SubscribeHostEvents();
45 void Shutdown() noexcept;
46
47 void OnFrame();
48 bool OnClientConnecting(int slot, int64_t steamId, std::string_view name, char* reason, size_t reasonSize);
49 void OnClientConnected(int slot, int64_t steamId, std::string_view name, std::string_view address);
50 void OnClientDisconnected(int slot);
51 void OnClientFullyConnected(int slot);
52 void OnClientSettingsChanged(int slot);
53 void OnCheckTransmit(CCheckTransmitInfo** infoList, int infoCount);
54 void OnBuildGameSessionManifest(IEntityResourceManifest* manifest);
55
56 PluginFactory _factory;
57 IPluginContext* _host = nullptr;
58 /** Declared above the runtime, whose services keep references into it. */
59 std::unique_ptr<UnsafeServices> _unsafe;
60 std::unique_ptr<HostPlayerLanguages> _languages;
61 std::unique_ptr<Runtime> _runtime;
62 Subscriptions _hostEvents;
63 std::unique_ptr<Plugin> _plugin;
64 std::string _status;
65};
66
69{
70 return PluginModule([](Runtime& runtime) -> std::unique_ptr<Plugin> { return std::make_unique<T>(runtime); });
71}
72
73} // namespace VoltMod::Internal
PluginModule(const PluginModule &)=delete
const char * StatusJson() noexcept
Definition Plugin.cpp:211
PluginModule & operator=(const PluginModule &)=delete
bool Attach(IPluginContext &host, char *error, size_t errorSize) noexcept
Definition Plugin.cpp:33
PluginModule(PluginFactory factory)
Everything a plugin owns for one load cycle.
Definition Plugin.hpp:15
Framework services for one load and unload cycle.
Definition Runtime.hpp:57
Holds the subscriptions an object makes and releases them together, newest first.
std::unique_ptr< Plugin >(*)(Runtime &) PluginFactory
PluginModule MakePluginModule()
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
Opt-in access to raw engine interfaces and typed gamedata bindings.