Dota2Patcher
 
Загрузка...
Поиск...
Не найдено
CGameEntitySystem.h
См. документацию.
1#pragma once
2#include "../Utils/Memory.h"
3#include "CEntityIdentity.h"
4
5// Forward declaration
6class CHandle;
8//
9
11public:
12 optional<string> name() const {
13 const auto name_ptr = Memory::read_memory<uintptr_t>(this + 0x8);
14 return !name_ptr ? nullopt : Memory::read_string(name_ptr.value());
15 }
16};
17
19public:
20 optional<string> binary_name() const { // C_DOTA_Unit_Hero_AntiMage
21 optional base = Memory::read_memory<SchemaName*>(this + 0x30);
22 return !base ? nullopt : base.value()->name();
23 }
24
25 optional<string> class_name() const { // C_DOTA_BaseNPC_Hero
26 optional base = Memory::read_memory<SchemaName*>(this + 0x38);
27 return !base ? nullopt : base.value()->name();
28 }
29};
30
32public:
33 void dump_entities() const { // for testing purposes
34 std::ofstream dump_file;
35 dump_file.open("C:\\entity_dump.txt");
36 int ents_count = 0;
37
38 auto ident = this->first_identity();
39 if (!ident)
40 return;
41
42 while (true) {
43 ents_count++;
44
45 const auto schema = ident->schema_class_binding();
46 const auto internal_name = ident->internal_name();
47 const auto entity_name = ident->entity_name();
48 const auto binary_name = schema->binary_name();
49 const auto class_name = schema->class_name();
50
51 dump_file
52 << "internal_name: " << internal_name.value_or("empty")
53 << " | entity_name: " << entity_name.value_or("empty")
54 << " | binary_name: " << binary_name.value_or("empty")
55 << " | class_name: " << class_name.value_or("empty");
56
57 if (ident->handle())
58 dump_file << " | handle: " << std::hex << ident->handle().value().get() << " | index: " << ident->handle().value().to_index();
59
60 dump_file << " -> [" << (void*)ident->base_entity() << "]\n";
61
62 const auto next_ent = ident->m_pNext();
63 if (!next_ent)
64 break;
65
66 ident = next_ent.value();
67 }
68
69 dump_file.close();
70 printf("\n");
71 LOG::INFO("dump_entities: done. Total: {}", ents_count);
72 }
73
74 optional<CBaseEntity*> find_by_name(const ENTITY_NAME_TYPE& name_type, const string& name_to_find) const {
75 auto ident = this->first_identity();
76 if (!ident)
77 return nullopt;
78
79 while (true) {
80 switch (name_type) {
82 const auto internal_name = ident->internal_name().value_or("");
83 if (internal_name == name_to_find)
84 return ident->base_entity();
85 break;
86 }
88 const auto entity_name = ident->entity_name().value_or("");
89 if (entity_name == name_to_find)
90 return ident->base_entity();
91 break;
92 }
94 const auto schema = ident->schema_class_binding();
95 const auto binary_name = schema->binary_name().value_or("");
96 if (binary_name == name_to_find)
97 return ident->base_entity();
98 break;
99 }
101 const auto schema = ident->schema_class_binding();
102 const auto class_name = schema->class_name().value_or("");
103 if (class_name == name_to_find)
104 return ident->base_entity();
105 break;
106 }
107 }
108
109 const auto next_ent = ident->m_pNext();
110 if (!next_ent)
111 break;
112
113 ident = next_ent.value();
114 }
115
116 return nullopt;
117 }
118
119 template <typename T>
120 std::vector<T*> find_vector_by_name(const ENTITY_NAME_TYPE& name_type, const string& name_to_find) const {
121 std::vector<T*> found;
122
123 auto ident = this->first_identity();
124
125 while (ident) {
126 switch (name_type) {
128 const auto internal_name = ident->internal_name().value_or("");
129 if (internal_name == name_to_find)
130 found.push_back(reinterpret_cast<T*>(ident->base_entity()));
131 break;
132 }
134 const auto entity_name = ident->entity_name().value_or("");
135 if (entity_name == name_to_find)
136 found.push_back(reinterpret_cast<T*>(ident->base_entity()));
137 break;
138 }
140 const auto schema = ident->schema_class_binding();
141 const auto binary_name = schema->binary_name().value_or("");
142 if (binary_name == name_to_find)
143 found.push_back(reinterpret_cast<T*>(ident->base_entity()));
144 break;
145 }
147 const auto schema = ident->schema_class_binding();
148 const auto class_name = schema->class_name().value_or("");
149 if (class_name == name_to_find)
150 found.push_back(reinterpret_cast<T*>(ident->base_entity()));
151 break;
152 }
153 }
154
155 ident = ident->m_pNext().value_or(nullptr);
156 }
157
158 return found;
159 }
160
161 optional<CBaseEntity*> find_by_index(uint32_t index, bool hero_only = false) const {
162 for (auto ident = this->first_identity(); ident; ident = ident->m_pNext().value_or(nullptr)) {
163 if (hero_only) {
164 const auto schema = ident->schema_class_binding();
165 if (!schema || schema->class_name().value_or("") != "C_DOTA_BaseNPC_Hero")
166 continue;
167 }
168
169 if (ident->handle() && ident->handle().value().to_index() == index)
170 return ident->base_entity();
171 }
172
173 return nullopt;
174 }
175
176
177 optional <CBaseEntity*> find_by_handle(const CHandle handle, bool hero_only = false) const {
178 return find_by_index(handle.to_index(), hero_only);
179 }
180
182 return Memory::read_memory<CEntityIdentity*>(this + 0x210).value_or(nullptr);
183 }
184};
ENTITY_NAME_TYPE
Definition Enums.h:21
Definition CEntityIdentity.h:11
optional< CEntityIdentity * > m_pNext() const
Definition CEntityIdentity.h:44
Definition CGameEntitySystem.h:31
std::vector< T * > find_vector_by_name(const ENTITY_NAME_TYPE &name_type, const string &name_to_find) const
Definition CGameEntitySystem.h:120
optional< CBaseEntity * > find_by_index(uint32_t index, bool hero_only=false) const
Definition CGameEntitySystem.h:161
optional< CBaseEntity * > find_by_handle(const CHandle handle, bool hero_only=false) const
Definition CGameEntitySystem.h:177
CEntityIdentity * first_identity() const
Definition CGameEntitySystem.h:181
void dump_entities() const
Definition CGameEntitySystem.h:33
optional< CBaseEntity * > find_by_name(const ENTITY_NAME_TYPE &name_type, const string &name_to_find) const
Definition CGameEntitySystem.h:74
Definition CHandle.h:6
uint32_t to_index() const
Definition CHandle.h:10
Definition CGameEntitySystem.h:18
optional< string > binary_name() const
Definition CGameEntitySystem.h:20
optional< string > class_name() const
Definition CGameEntitySystem.h:25
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
Definition CGameEntitySystem.h:10
optional< string > name() const
Definition CGameEntitySystem.h:12