VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
GameDataScanner.hpp
Go to the documentation of this file.
1#pragma once
2
7
11#include <functional>
12#include <map>
13#include <string>
14#include <string_view>
15#include <vector>
16
17namespace VoltMod
18{
19
20/** A vtable slot and its class table. Index is -1 when unbound. */
22{
23 int Index = -1;
24 void* Table = nullptr;
25};
26
27/** What one gamedata key resolved to. @ref Reason is empty exactly when it bound. */
29{
30 /** Every section holding the key; more than one is a file error. */
31 std::vector<std::string_view> Sections;
32 /** No kind when the key is in more than one section. */
34 void* Address = nullptr;
35 int Value = -1;
36 std::string Reason;
37};
38
39/** Resolves every gamedata key against the loaded modules, once for the process. */
41{
42public:
43 /** @p file, @p originalOf and @p scriptOf must outlive the scanner. */
46
47 void ResolveAll();
48
49 /** Nullptr when the file does not have @p key. */
50 const GameDataEntry* Find(std::string_view key) const;
51
52 /** `key: reason` for each entry that did not bind. */
53 const std::vector<std::string>& Failures() const { return _failures; }
54
55 const GameDataRecord& Record() const { return _record; }
56
57 /** Log the entry counts, and warn when the file was checked on another game build. */
58 void LogSummary(std::string_view path) const;
59
60private:
61 /** An address, a slot or offset value, or both for a vtable slot. */
62 struct Bound
63 {
64 void* Address = nullptr;
65 int Value = -1;
66 };
67
68 Result<Bound> Locate(GameDataSection kind, const std::string& key);
69 void Fail(std::string_view key, GameDataEntry& entry, const Error& error);
70
71 Result<void*> FindFunction(const std::string& key);
72 Result<void*> FindScriptFunction(const std::string& key, const GameDataDocument::Function& entry);
73 Result<void*> FindGlobal(const std::string& key);
74 Result<VirtualSlot> FindSlot(const std::string& key);
75 Result<int> FindOffset(const std::string& key);
76 Result<int> FindBaseOffset(const GameDataDocument::Offset& entry);
77
78 Result<ScriptTarget> FindScript(void* table, const std::string& name) const;
79 /** The slot a virtual VScript binding dispatches through. */
80 Result<int> ScriptSlot(void* table, const std::string& name) const;
81
82 const GameDataDocument& _file;
83 const OriginalSlotLookup& _originalOf;
84 const ScriptBindingLookup& _scriptOf;
85 std::map<std::string, GameDataEntry, std::less<>> _entries;
86 ModuleSymbols _symbols;
87 std::vector<std::string> _failures;
88 GameDataRecord _record;
89};
90
91} // namespace VoltMod
void LogSummary(std::string_view path) const
const std::vector< std::string > & Failures() const
const GameDataRecord & Record() const
const GameDataEntry * Find(std::string_view key) const
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
std::vector< std::string_view > Sections