VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
GameDataDocument.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <map>
5#include <optional>
6#include <string>
7#include <string_view>
8
9namespace VoltMod
10{
11
12/** gamedata.jsonc. Strict reading rejects unknown keys; capitalized platform columns dodge GCC's `linux` macro. */
14{
15 struct Build
16 {
17 std::string server; ///< steam.inf ServerVersion the entries were verified on.
18 std::string verified; ///< YYYY-MM-DD of the last full review.
19 };
20
21 /** A byte pattern per platform, or the VScript binding `script` of `class`. */
22 struct Function
23 {
24 std::string Module = "server";
25 std::optional<std::string> Windows;
26 std::optional<std::string> Linux;
27 std::string Class;
28 std::string Script;
29 };
30
31 /** A pattern and the offset of its rel32 displacement. */
33 {
34 std::string pattern;
35 int rel32At = 0;
36 };
37
38 struct Global
39 {
40 std::string Module = "server";
41 std::optional<GlobalColumn> Windows;
42 std::optional<GlobalColumn> Linux;
43 };
44
45 /** A vtable slot, counted in `class` or its named `base`, or read from the VScript binding `script`. */
46 struct VTable
47 {
48 std::string Class;
49 std::string Base;
50 std::string Module = "server";
51 std::optional<int> Windows;
52 std::optional<int> Linux;
53 std::string Script;
54 };
55
56 /** A platform offset, or the RTTI-derived location of `base` within `class`. */
57 struct Offset
58 {
59 std::optional<int> Windows;
60 std::optional<int> Linux;
61 std::string Class;
62 std::string Base;
63 std::string Module = "server";
64 };
65
67 std::map<std::string, Function> functions;
68 std::map<std::string, Global> globals;
69 std::map<std::string, VTable> vtables;
70 std::map<std::string, Offset> offsets;
71};
72
73#ifdef _WIN32
74inline constexpr std::string_view PlatformName = "windows";
75#else
76inline constexpr std::string_view PlatformName = "linux";
77#endif
78
79template <class TEntry>
80const auto& PlatformColumn(const TEntry& entry)
81{
82#ifdef _WIN32
83 return entry.Windows;
84#else
85 return entry.Linux;
86#endif
87}
88
89} // namespace VoltMod
90
91// The JSON keys differ from the member names.
92
93template <>
94struct glz::meta<VoltMod::GameDataDocument>
95{
96 static constexpr auto modify = glz::object("$schema", glz::skip{});
97};
98
99template <>
100struct glz::meta<VoltMod::GameDataDocument::Function>
101{
103 static constexpr auto value = glz::object("module", &T::Module, "windows", &T::Windows, "linux", &T::Linux, "class",
104 &T::Class, "script", &T::Script);
105};
106
107template <>
108struct glz::meta<VoltMod::GameDataDocument::Global>
109{
111 static constexpr auto value = glz::object("module", &T::Module, "windows", &T::Windows, "linux", &T::Linux);
112};
113
114template <>
115struct glz::meta<VoltMod::GameDataDocument::VTable>
116{
118 static constexpr auto value = glz::object("class", &T::Class, "base", &T::Base, "module", &T::Module, "windows",
119 &T::Windows, "linux", &T::Linux, "script", &T::Script);
120};
121
122template <>
123struct glz::meta<VoltMod::GameDataDocument::Offset>
124{
126 static constexpr auto value = glz::object("windows", &T::Windows, "linux", &T::Linux, "class", &T::Class, "base",
127 &T::Base, "module", &T::Module);
128};
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
const auto & PlatformColumn(const TEntry &entry)
constexpr std::string_view PlatformName
std::string server
steam.inf ServerVersion the entries were verified on.
std::string verified
YYYY-MM-DD of the last full review.
std::optional< std::string > Linux
std::optional< std::string > Windows
std::optional< GlobalColumn > Windows
std::optional< GlobalColumn > Linux
std::map< std::string, Function > functions
std::map< std::string, Global > globals
std::map< std::string, VTable > vtables
std::map< std::string, Offset > offsets