VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
EngineHooks.hpp
Go to the documentation of this file.
1#pragma once
2
5
8#include <cstdint>
9#include <functional>
10#include <string_view>
11
12namespace VoltMod
13{
14
15/**
16 * @brief The engine hooks, installed once for the whole process.
17 *
18 * Each one raises the matching event on @ref PluginRegistry, which calls every loaded plugin in load
19 * order. Game thread only, like everything downstream of it.
20 */
22{
23public:
24 /**
25 * @param beforeFrame Runs at the start of every frame, before the frame reaches the plugins.
26 * @param beforeServerStartup Runs on every map change, before the plugins hear about it.
27 * @param beforeClientConnected Runs with each connecting client's SteamID, before the plugins hear about it.
28 * @param afterClientDisconnected Runs with the SteamID of each client that left, not one moved by a map change.
29 */
31 std::function<void()> beforeServerStartup, std::function<void(int64_t)> beforeClientConnected,
32 std::function<void(int64_t)> afterClientDisconnected);
33
34 EngineHooks(const EngineHooks&) = delete;
36
37private:
38 void ConnectClient(int slot, uint64_t xuid, std::string_view name, std::string_view address);
39
40 /** A map change moves clients to new slots; ClientPutInServer reconnects them there. */
41 void DisconnectEveryone();
42
43 PluginRegistry& _registry;
44 std::function<void()> _beforeFrame;
45 std::function<void()> _beforeServerStartup;
46 std::function<void(int64_t)> _beforeClientConnected;
47 std::function<void(int64_t)> _afterClientDisconnected;
48 Subscriptions _hooks;
49};
50
51} // namespace VoltMod
The engine hooks, installed once for the whole process.
EngineHooks & operator=(const EngineHooks &)=delete
EngineHooks(const EngineHooks &)=delete
The loaded plugins and the engine events raised on them, one per process.
Holds the subscriptions an object makes and releases them together, newest first.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56