Cyrus Mod Loader
Loading...
Searching...
No Matches
ClassDump.h
1#pragma once
2#include <Cyrus/shared.h>
3#include <Windows.h>
4#include <cstdint>
5#include <fstream>
6#include <iostream>
7#include <nlohmann/json.hpp>
8#include <ostream>
9#include <string>
10
11using namespace nlohmann;
12
14public:
15 uint8_t pad[0x30]; // 0x8
16 std::string typeName; // 0x38
17 uint8_t pad1[0x30]; // 0x58
18 bool isPointer; // 0x88
19
20 virtual ~ClassTypeStorage() = default;
21};
22
24public:
25 virtual void *constructor(); // 0x0
26 virtual char *getStorage(); // 0x8
27 virtual int getElements(bool a); // 0x10
28 virtual void unk1(); // 0x18
29 virtual bool isDynamic(); // 0x20
30};
31
32class ClassDescriptor;
33
35public:
36 std::string value;
37 void *pad;
38 std::string name;
39};
40
42public:
43 uint8_t pad[0x30]; // 0x8
46 uint8_t paddd[0x2]; // 0x48
47 uintptr_t propertyID; // 0x50
48 char *name; // 0x58
49 void *pad3; // 0x60
50 uint32_t offset; // 0x68
51 uint32_t pad2; // 0x6C
53 void *pad4; // 0x78
54 uintptr_t flags; // 0x80
55 char *note; // 0x88
56 void *pad22; // 0x90
57 uintptr_t enumStart; // 0x98
58 uintptr_t enumEnd; // 0xA0
59
60 char *getName() { return name; }
61
62 uint32_t getPropertyID() { return propertyID; }
63
64 std::string getType() { return storage->typeName; }
65
66 bool isPointer() { return storage->isPointer; }
67
68 virtual ~ClassProperty() = default;
69
70 json serialize() {
71 json j;
72 std::string note = std::string(this->note);
73 auto name = getName();
74 if (note != name) {
75 j["note"] = note;
76 }
77 j["name"] = name;
78 j["type"] = getType();
79 j["container"] = containerStorage->getStorage();
80 j["offset"] = offset;
81 auto dynamic = containerStorage->isDynamic();
82 j["dynamic"] = dynamic;
83 j["pointer"] = isPointer();
84 if (!dynamic) {
85 j["elements"] = containerStorage->getElements(false);
86 }
87
88 auto enumItemCount = (enumEnd - enumStart) / 0x48;
89 j["enumValueCount"] = enumItemCount;
90 for (auto i = enumStart; i < enumEnd; i += 0x48) {
91 auto enumVal = reinterpret_cast<ClassEnumVal *>(i);
92 j["enumValues"].push_back(
93 json({{"name", enumVal->name}, {"value", enumVal->value}}));
94 }
95 return j;
96 }
97};
98
99DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, pad, 0x8);
100DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, descriptor, 0x38);
101DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, containerStorage, 0x40);
102DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, propertyID, 0x50);
103DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, name, 0x58);
104DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, pad3, 0x60);
105DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, offset, 0x68);
106DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, pad2, 0x6C);
107DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, storage, 0x70);
108DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, pad4, 0x78);
109DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, flags, 0x80);
110DEFINE_OFFSET_AND_STATIC_ASSERT(ClassProperty, note, 0x88);
111
112struct ArgStuff {
113 uintptr_t start;
114 uintptr_t end;
115 uintptr_t WTF;
116};
117
119public:
120 uint8_t pad[0x28]; // 0x8
121 uintptr_t fnAdress; // 0x30
122
124 virtual bool getArgsData(ArgStuff *out) = 0;
125};
126
128 uint8_t pad[0x30]; // 0x8
129 std::string name; // 0x38
130 ClassFunctionTypeStorage *functionData; // 0x58
131public:
132 virtual ~ClassFunction() = default;
133
134 json serialize(std::string parentType) {
135 json j;
136 j["name"] = name;
137
138 if (!functionData) {
139 return j;
140 }
141
142 auto ret = functionData->getReturnType();
143 if (ret) {
144 j["returnType"] = ret->typeName;
145 } else {
146 j["returnType"] = "void";
147 }
148
149 ArgStuff *args = new ArgStuff;
150 args->start = 0;
151 args->end = 0;
152 args->WTF = 0;
153 if (functionData->getArgsData(args)) {
154 j["argCount"] = (args->end - args->start) / 0x8;
155 }
156
157 j["args"].push_back(parentType + " *self");
158 for (auto i = args->start; i < args->end; i += 0x8) {
159 auto arg = *reinterpret_cast<ClassTypeStorage **>(i);
160 j["args"].push_back(arg->typeName + " a" +
161 std::to_string((i - args->start) / 0x8));
162 }
163
164 j["rva"] = functionData->fnAdress -
165 reinterpret_cast<uintptr_t>(GetModuleHandleA(0));
166 return j;
167 }
168};
169
171public:
172 uintptr_t unk1; // 0x8
173 uint32_t m_offset; // 0x10
174 uint32_t unk2; // 0x14
175 ClassDescriptor *super; // 0x18; super class descriptor
177 uint8_t padd[0x30]; // 0x28
178 std::vector<ClassProperty *> properties; // 0x58
179 std::vector<ClassFunction *> functions; // 0x70
180
181public:
182 virtual ~ClassDescriptor() = default;
183
184 json serialize() {
185 json j;
186 j["offset"] = m_offset;
187 if (!classTypeStorage) {
188 return j;
189 }
190 j["name"] = classTypeStorage->typeName;
191
192 if (!super) {
193 return j;
194 }
195
196 auto cSupper = super;
197 j["super"] = super->classTypeStorage->typeName;
198 while (cSupper) {
199 j["allSuperClasses"].push_back(cSupper->classTypeStorage->typeName);
200 cSupper = cSupper->super;
201 }
202
203 for (auto i = 0; i < properties.size(); i += 2) {
204 auto prop = properties[i];
205 j["properties"].push_back(prop->serialize());
206 }
207
208 for (auto i = 0; i < functions.size(); i += 2) {
209 auto f = functions[i];
210 j["functions"].push_back(f->serialize(classTypeStorage->typeName));
211 }
212 return j;
213 }
214};
215
216DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, unk1, 0x8);
217DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, m_offset, 0x10);
218DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, unk2, 0x14);
219DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, super, 0x18);
220DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, classTypeStorage, 0x20);
221DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, padd, 0x28);
222DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, properties, 0x58);
223DEFINE_OFFSET_AND_STATIC_ASSERT(ClassDescriptor, functions, 0x70);
224
225void dumpClasses() {
226 std::vector<ClassDescriptor *> wizClasses;
227 uintptr_t base = reinterpret_cast<uintptr_t>(GetModuleHandleA(nullptr));
228 uintptr_t superClassDescriptor =
229 *reinterpret_cast<uintptr_t *>(base + 0x347F018);
230
231 const auto wizClassDescriptorEnd =
232 *reinterpret_cast<uintptr_t *>(superClassDescriptor);
233 auto currentClassDescriptor =
234 *reinterpret_cast<uintptr_t *>(wizClassDescriptorEnd);
235
236 auto count = 0;
237 while (currentClassDescriptor != wizClassDescriptorEnd) {
238 auto classDataPointer =
239 *reinterpret_cast<uintptr_t *>(currentClassDescriptor + 0x28);
240 auto classAttributePointer =
241 *reinterpret_cast<uintptr_t *>(currentClassDescriptor + 0x10);
242 if (*reinterpret_cast<uint8_t *>(classAttributePointer + 0x19)) {
243 auto linkedDescriptor =
244 *reinterpret_cast<uintptr_t *>(currentClassDescriptor + 0x8);
245 for (; !*reinterpret_cast<uint8_t *>(linkedDescriptor + 0x19);
246 linkedDescriptor =
247 *reinterpret_cast<uintptr_t *>(linkedDescriptor + 0x8)) {
248 if (currentClassDescriptor !=
249 *reinterpret_cast<uintptr_t *>(linkedDescriptor + 0x10)) {
250 break;
251 }
252 currentClassDescriptor = linkedDescriptor;
253 }
254 currentClassDescriptor = linkedDescriptor;
255 } else {
256 currentClassDescriptor =
257 *reinterpret_cast<uintptr_t *>(currentClassDescriptor + 0x10);
258 for (auto linkedDescriptor =
259 *reinterpret_cast<uintptr_t *>(classAttributePointer);
260 !*reinterpret_cast<uint8_t *>(linkedDescriptor + 0x19);
261 linkedDescriptor =
262 *reinterpret_cast<uintptr_t *>(linkedDescriptor)) {
263 currentClassDescriptor = linkedDescriptor;
264 }
265 }
266 auto currentClass = *reinterpret_cast<uintptr_t *>(classDataPointer + 0x90);
267 if (currentClass &&
268 !*reinterpret_cast<uint8_t *>(classDataPointer + 0x88)) {
269 wizClasses.push_back(reinterpret_cast<ClassDescriptor *>(currentClass));
270 count++;
271 }
272 }
273
274 json classes;
275 for (auto wizClass : wizClasses) {
276 if (wizClass == nullptr) {
277 continue;
278 }
279 classes.push_back(wizClass->serialize());
280 }
281 std::ofstream file("classes.json");
282 if (file.is_open()) {
283 auto classesJson = classes.dump(4);
284 file << classesJson;
285 file.close();
286 } else {
287 std::cout << "Unable to open classes file for writing" << std::endl;
288 }
289}
Definition ClassDump.h:23
virtual bool isDynamic()
virtual char * getStorage()
virtual void unk1()
virtual int getElements(bool a)
virtual void * constructor()
Definition ClassDump.h:170
json serialize()
Definition ClassDump.h:184
std::vector< ClassProperty * > properties
Definition ClassDump.h:178
uint32_t m_offset
Definition ClassDump.h:173
virtual ~ClassDescriptor()=default
uintptr_t unk1
Definition ClassDump.h:172
uint8_t padd[0x30]
Definition ClassDump.h:177
ClassDescriptor * super
Definition ClassDump.h:175
std::vector< ClassFunction * > functions
Definition ClassDump.h:179
ClassTypeStorage * classTypeStorage
Definition ClassDump.h:176
uint32_t unk2
Definition ClassDump.h:174
Definition ClassDump.h:34
std::string name
Definition ClassDump.h:38
std::string value
Definition ClassDump.h:36
void * pad
Definition ClassDump.h:37
Definition ClassDump.h:127
virtual ~ClassFunction()=default
json serialize(std::string parentType)
Definition ClassDump.h:134
Definition ClassDump.h:118
uintptr_t fnAdress
Definition ClassDump.h:121
virtual ClassTypeStorage * getReturnType()=0
virtual bool getArgsData(ArgStuff *out)=0
uint8_t pad[0x28]
Definition ClassDump.h:120
Definition ClassDump.h:41
uint32_t offset
Definition ClassDump.h:50
ClassContainerStorage * containerStorage
Definition ClassDump.h:45
ClassTypeStorage * storage
Definition ClassDump.h:52
ClassDescriptor * descriptor
Definition ClassDump.h:44
uintptr_t propertyID
Definition ClassDump.h:47
uintptr_t enumEnd
Definition ClassDump.h:58
json serialize()
Definition ClassDump.h:70
virtual ~ClassProperty()=default
uint8_t pad[0x30]
Definition ClassDump.h:43
uint32_t pad2
Definition ClassDump.h:51
uintptr_t enumStart
Definition ClassDump.h:57
char * name
Definition ClassDump.h:48
std::string getType()
Definition ClassDump.h:64
void * pad4
Definition ClassDump.h:53
uint32_t getPropertyID()
Definition ClassDump.h:62
char * getName()
Definition ClassDump.h:60
bool isPointer()
Definition ClassDump.h:66
void * pad22
Definition ClassDump.h:56
uint8_t paddd[0x2]
Definition ClassDump.h:46
uintptr_t flags
Definition ClassDump.h:54
char * note
Definition ClassDump.h:55
void * pad3
Definition ClassDump.h:49
Definition ClassDump.h:13
std::string typeName
Definition ClassDump.h:16
virtual ~ClassTypeStorage()=default
uint8_t pad[0x30]
Definition ClassDump.h:15
uint8_t pad1[0x30]
Definition ClassDump.h:17
bool isPointer
Definition ClassDump.h:18
PropClassStorage classes
An external declaration of the PropClassStorage object.
Definition storage.cpp:84
Definition ClassDump.h:112
uintptr_t start
Definition ClassDump.h:113
uintptr_t WTF
Definition ClassDump.h:115
uintptr_t end
Definition ClassDump.h:114