VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
GameDataTable.cpp
Go to the documentation of this file.
2
4
8#include <cstdint>
9#include <format>
10#include <utility>
11
12namespace VoltMod
13{
14
17{
19 if (!file)
20 {
21 Log::Error("GameData: {} was not read: {}", path, file.error().Detail);
22 return;
23 }
24
25 _file = std::make_unique<GameDataDocument>(std::move(*file));
26 _originalOf = originalOf;
27 _scriptOf = scriptOf;
28 _scanner = std::make_unique<GameDataScanner>(*_file, _originalOf, _scriptOf);
29 _scanner->ResolveAll();
30 _scanner->LogSummary(path);
31
32 const std::vector<std::string>& failures = _scanner->Failures();
33 if (!failures.empty())
34 {
35 Log::Error("GameData: {} entries did not bind: {}", failures.size(), Strings::Join(failures, "; "));
36 return;
37 }
38
39 WriteGameDataRecord(_scanner->Record());
40}
41
43{
44 const GameDataEntry* entry = _scanner ? _scanner->Find(key) : nullptr;
45 if (!entry)
46 {
47 return NotBound("not in gamedata");
48 }
49 if (!entry->Reason.empty())
50 {
51 return NotBound(entry->Reason);
52 }
53 if ((static_cast<uint32_t>(sections) & static_cast<uint32_t>(entry->Kind)) == 0)
54 {
55 return NotBound(std::format("in '{}', which this member does not bind from", entry->Sections[0]));
56 }
57
58 return {.Found = true, .Address = entry->Address, .Value = entry->Value};
59}
60
61GameDataLocation GameDataTable::NotBound(std::string reason)
62{
63 _reason = std::move(reason);
64 return {.Reason = _reason};
65}
66
67} // namespace VoltMod
GameDataLocation Lookup(GameDataSection sections, std::string_view key) override
GameDataTable(std::string_view path, const OriginalSlotLookup &originalOf={}, const ScriptBindingLookup &scriptOf={})
static Result< T > ReadFile(std::string_view path)
Parse path (resolved via ResolvePath) into T.
Definition Json.hpp:46
static std::string Join(const std::vector< std::string > &parts, std::string_view delimiter)
Definition Strings.cpp:114
void Error(std::format_string< Args... > fmt, Args &&... args)
Definition Log.hpp:97
void WriteGameDataRecord(const GameDataRecord &resolved)
std::function< Result< ScriptTarget >(void *classTable, std::string_view name)> ScriptBindingLookup
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::function< const void *(void **vtable, int index)> OriginalSlotLookup