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
3
#include "
Engine/Memory/ScriptBindings.hpp
"
4
#include "
Host/GameData/GameDataDocument.hpp
"
5
#include "
Host/GameData/GameDataRecord.hpp
"
6
#include "
Host/GameData/ModuleSymbols.hpp
"
7
8
#include <
VoltMod/Core/Result.hpp
>
9
#include <
VoltMod/Engine/Memory/OriginalSlotLookup.hpp
>
10
#include <
VoltMod/Host/IPluginGameData.hpp
>
11
#include <functional>
12
#include <map>
13
#include <string>
14
#include <string_view>
15
#include <vector>
16
17
namespace
VoltMod
18
{
19
20
/** A vtable slot and its class table. Index is -1 when unbound. */
21
struct
VirtualSlot
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. */
28
struct
GameDataEntry
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. */
33
GameDataSection
Kind
{};
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. */
40
class
GameDataScanner
41
{
42
public
:
43
/** @p file, @p originalOf and @p scriptOf must outlive the scanner. */
44
GameDataScanner
(
const
GameDataDocument
&
file
,
const
OriginalSlotLookup
&
originalOf
,
45
const
ScriptBindingLookup
&
scriptOf
);
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
60
private
:
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
GameDataDocument.hpp
GameDataRecord.hpp
IPluginGameData.hpp
ModuleSymbols.hpp
OriginalSlotLookup.hpp
Result.hpp
ScriptBindings.hpp
VoltMod::Address
Definition
BindingTypes.hpp:13
VoltMod::GameDataScanner
Definition
GameDataScanner.hpp:41
VoltMod::GameDataScanner::LogSummary
void LogSummary(std::string_view path) const
Definition
GameDataScanner.cpp:125
VoltMod::GameDataScanner::Failures
const std::vector< std::string > & Failures() const
Definition
GameDataScanner.hpp:53
VoltMod::GameDataScanner::Record
const GameDataRecord & Record() const
Definition
GameDataScanner.hpp:55
VoltMod::GameDataScanner::Find
const GameDataEntry * Find(std::string_view key) const
Definition
GameDataScanner.cpp:119
VoltMod::GameDataScanner::ResolveAll
void ResolveAll()
Definition
GameDataScanner.cpp:99
VoltMod
Definition
Options.hpp:13
VoltMod::ScriptBindingLookup
std::function< Result< ScriptTarget >(void *classTable, std::string_view name)> ScriptBindingLookup
Definition
ScriptBindings.hpp:19
VoltMod::ReadFile
static std::string ReadFile(const std::filesystem::path &path)
Definition
Loader.cpp:56
VoltMod::OriginalSlotLookup
std::function< const void *(void **vtable, int index)> OriginalSlotLookup
Definition
OriginalSlotLookup.hpp:13
VoltMod::GameDataSection
GameDataSection
Definition
GameDataLocation.hpp:11
VoltMod::GameDataDocument
Definition
GameDataDocument.hpp:14
VoltMod::GameDataEntry
Definition
GameDataScanner.hpp:29
VoltMod::GameDataEntry::Kind
GameDataSection Kind
Definition
GameDataScanner.hpp:33
VoltMod::GameDataEntry::Reason
std::string Reason
Definition
GameDataScanner.hpp:36
VoltMod::GameDataEntry::Sections
std::vector< std::string_view > Sections
Definition
GameDataScanner.hpp:31
VoltMod::GameDataEntry::Value
int Value
Definition
GameDataScanner.hpp:35
VoltMod::GameDataRecord
Definition
GameDataRecord.hpp:12
VoltMod::VirtualSlot
Definition
GameDataScanner.hpp:22
VoltMod::VirtualSlot::Table
void * Table
Definition
GameDataScanner.hpp:24
VoltMod::VirtualSlot::Index
int Index
Definition
GameDataScanner.hpp:23
src
Host
GameData
GameDataScanner.hpp
Generated by
1.9.8