VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Layout.cpp
Go to the documentation of this file.
1#include "Schema/Layout.hpp"
2
3#include <format>
4#include <string>
5#include <vector>
6
7namespace VoltMod::Schema
8{
9
10Status ResolveLayout(std::span<FieldLayout> fields, const LiveFieldLookup& lookup)
11{
12 // Report all mismatches so one changed class does not hide the rest.
13 std::vector<std::string> broken;
14 for (FieldLayout& field : fields)
15 {
16 const LiveField live = lookup(field.Class, field.Field);
17 field.Offset = live.Offset;
18 if (live.Offset < 0)
19 {
20 broken.push_back(std::format("{}::{}: gone", field.Class, field.Field));
21 continue;
22 }
23
24 if (field.Size != 0 && live.Size != 0 && live.Size != field.Size)
25 {
26 broken.push_back(std::format("{}::{}: size {} -> {}", field.Class, field.Field, field.Size, live.Size));
27 }
28 }
29
30 if (broken.empty())
31 {
32 return {};
33 }
34
35 std::string message =
36 "the server schema no longer matches these fields; regenerate with voltmod framework schemagen:";
37 for (const std::string& line : broken)
38 {
39 message += std::format("\n {}", line);
40 }
41 return std::unexpected(Error::Invalid(message));
42}
43
44} // namespace VoltMod::Schema
std::function< LiveField(std::string_view className, std::string_view field)> LiveFieldLookup
Definition Layout.hpp:14
Status ResolveLayout(std::span< FieldLayout > fields, const LiveFieldLookup &lookup)
Definition Layout.cpp:10
std::expected< void, Error > Status
Definition Result.hpp:67
static Error Invalid(std::string detail)
Definition Result.hpp:51