Dota2Patcher
 
Loading...
Searching...
No Matches
CCvar.h
Go to the documentation of this file.
1#pragma once
2#include "../Utils/Memory.h"
3
4class CCvarNode {
5public:
6 optional <string> name() const {
7 const auto name_ptr = Memory::read_memory<uintptr_t>(this);
8 return !name_ptr ? nullopt : Memory::read_string(name_ptr.value());
9 }
10
11 template <typename T>
12 T get() const {
13 return Memory::read_memory<T>(this + 0x40);
14 }
15
16 template <typename T>
17 void set(const T value) {
18 Memory::write_memory<T>(this + 0x40, value);
19 }
20};
21
23public:
24 CCvarNode* node_by_index(const size_t index) const {
25 return Memory::read_memory<CCvarNode*>(this + index * 8).value_or(nullptr);
26 }
27};
28
29class CCvar {
30public:
31 CCvarNodes* node() const {
32 return Memory::read_memory<CCvarNodes*>(this + 0x40).value_or(nullptr);
33 }
34
35 optional<CCvarNode*> find_by_name(const string& name_to_find) const {
36 for (size_t index = 0; auto current_node = this->node()->node_by_index(index); ++index) {
37 if (const auto current_name = current_node->name(); current_name && current_name.value() == name_to_find)
38 return current_node;
39 }
40
41 return nullopt;
42 }
43
44 size_t load_convars() const {
45 size_t count = 0;
46 for (size_t index = 0; auto current_node = this->node()->node_by_index(index); ++index) {
47 if (const auto current_name = current_node->name(); current_name) {
48 g_convars[current_name.value()] = current_node;
49 count++;
50 }
51 }
52
53 return count;
54 }
55
57 static inline std::unordered_map<string, CCvarNode*> g_convars;
58};
Definition CCvar.h:4
optional< string > name() const
Definition CCvar.h:6
void set(const T value)
Definition CCvar.h:17
T get() const
Definition CCvar.h:12
Definition CCvar.h:22
CCvarNode * node_by_index(const size_t index) const
Definition CCvar.h:24
Definition CCvar.h:29
static std::unordered_map< string, CCvarNode * > g_convars
Global variable to store dumped ConVars.
Definition CCvar.h:57
optional< CCvarNode * > find_by_name(const string &name_to_find) const
Definition CCvar.h:35
size_t load_convars() const
Definition CCvar.h:44
CCvarNodes * node() const
Definition CCvar.h:31
static optional< T > read_memory(const N &address)
Definition Memory.h:78
static optional< string > read_string(const T &address, const size_t max_length=64)
Definition Memory.h:125