Cyrus Mod Loader
Loading...
Searching...
No Matches
DML.h
1#pragma once
2#include "shared.h"
3#include <cstdint>
4#include <iostream>
5#include <stdexcept>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10enum DMLFieldType : int8_t {
11 UNKNOWN,
12 GID,
13 I16,
14 U8,
15 DFLOAT,
16 I32,
17 U16,
18 U32,
19 DDOUBLE,
20 STR,
21 WSTR,
22};
23
24class DMLField {
25public:
26 void *vftable;
27 double doubleValue; // 0x0008
28 float floatValue; // 0x0010
29 int32_t intValue; // 0x0014
30 char *strValue; // 0x0018
31 wchar_t *wstrValue; // 0x0020
32 uint64_t gidValue; // 0x0028
33 DMLFieldType type; // 0x0030
34 char pad[3]; // 0x0031
35 char pad_0034[4]; // 0x0034
36 void *N000000D3; // 0x0038
37 int32_t N000000D4; // 0x0040
38 int32_t flags; // 0x0044
39 char pad_0048[8]; // 0x0048
40 char fieldName[32]; // 0x0050
41 char pad_0070[8]; // 0x0070
42
43 std::string toString() const {
44 switch (type) {
45 case DMLFieldType::GID:
46 return std::to_string(gidValue);
47 case DMLFieldType::I16:
48 case DMLFieldType::I32:
49 return std::to_string(intValue);
50 case DMLFieldType::U8:
51 case DMLFieldType::U16:
52 case DMLFieldType::U32:
53 return std::to_string(static_cast<uint32_t>(intValue));
54 case DMLFieldType::DFLOAT:
55 return std::to_string(floatValue);
56 case DMLFieldType::DDOUBLE:
57 return std::to_string(doubleValue);
58 case DMLFieldType::STR: {
59 auto is_ptr = reinterpret_cast<uintptr_t>((void *)wstrValue) == 0;
60 if (is_ptr) {
61 auto str_adr = *reinterpret_cast<std::string *>(strValue);
62 return str_adr;
63 }
64 return std::string(strValue);
65 }
66 case DMLFieldType::WSTR:
67 return "WSTRING";
68 default:
69 return "UNKNOWN";
70 }
71 }
72
73 template <typename T> void setValue(T value) {
74 try {
75 switch (type) {
76 case DMLFieldType::GID:
77 gidValue = static_cast<uint64_t>(value);
78 break;
79 case DMLFieldType::I16:
80 intValue = static_cast<int16_t>(value);
81 break;
82 case DMLFieldType::U8:
83 intValue = static_cast<uint8_t>(value);
84 break;
85 case DMLFieldType::DFLOAT:
86 floatValue = static_cast<float>(value);
87 break;
88 case DMLFieldType::I32:
89 intValue = static_cast<int32_t>(value);
90 break;
91 case DMLFieldType::U16:
92 intValue = static_cast<uint16_t>(value);
93 break;
94 case DMLFieldType::U32:
95 intValue = static_cast<uint32_t>(value);
96 break;
97 case DMLFieldType::DDOUBLE:
98 doubleValue = static_cast<double>(value);
99 break;
100 case DMLFieldType::STR:
101 if constexpr (std::is_same<T, std::string>::value) {
102 delete[] strValue;
103 strValue = new char[value.length() + 1];
104 strcpy(strValue, value.c_str());
105 } else {
106 throw std::invalid_argument(
107 "Type mismatch: expected std::string for STR");
108 }
109 break;
110 case DMLFieldType::WSTR:
111 if constexpr (std::is_same<T, std::wstring>::value) {
112 delete[] wstrValue;
113 wstrValue = new wchar_t[value.length() + 1];
114 std::wcscpy(wstrValue, value.c_str());
115 } else {
116 throw std::invalid_argument(
117 "Type mismatch: expected std::wstring for WSTR");
118 }
119 break;
120 default:
121 throw std::invalid_argument("Unknown DMLFieldType");
122 }
123 } catch (const std::exception &e) {
124 std::cerr << "Error setting value: " << e.what() << std::endl;
125 }
126 }
127}; // Size: 0x0080
128
130public:
131 void *vftable;
132 int16_t pad[2]; // 0x0008
133 bool isInitialized; // 0x000C
134 uint8_t serviceID; // 0x000D
135 uint8_t messageID; // 0x000E
136 uint8_t unk; // 0x000F
137 char pad_0010[16]; // 0x0010
139 DMLField *endField; // 0x0028
140 DMLField *maxField; // 0x0030
141 char pad_0038[72]; // 0x0038
142
144 DMLField *currentField = this->startField;
145 DMLField *endField = this->endField;
146
147 while (currentField < endField) {
148 std::cout << currentField->fieldName << ": " << currentField->toString()
149 << std::endl;
150 currentField = reinterpret_cast<DMLField *>(
151 reinterpret_cast<char *>(currentField) + sizeof(DMLField));
152 }
153 }
154
155 DMLField *getField(const std::string &fieldName) {
156 DMLField *currentField = this->startField;
157 while (currentField < this->endField) {
158 if (fieldName == currentField->fieldName) {
159 return currentField;
160 }
161 currentField = reinterpret_cast<DMLField *>(
162 reinterpret_cast<char *>(currentField) + sizeof(DMLField));
163 }
164 return nullptr;
165 }
166
167 std::unordered_map<std::string, DMLField *> GetRecords() {
168 std::unordered_map<std::string, DMLField *> records{};
169
170 DMLField *currentField = this->startField;
171 while (currentField < this->endField) {
172 records[currentField->fieldName] = currentField;
173 currentField = reinterpret_cast<DMLField *>(
174 reinterpret_cast<char *>(currentField) + sizeof(DMLField));
175 }
176 return records;
177 }
178}; // Size: 0x0080
Definition DML.h:24
int32_t N000000D4
Definition DML.h:37
char pad_0034[4]
Definition DML.h:35
uint64_t gidValue
Definition DML.h:32
char fieldName[32]
Definition DML.h:40
float floatValue
Definition DML.h:28
void * vftable
Definition DML.h:26
char * strValue
Definition DML.h:30
double doubleValue
Definition DML.h:27
std::string toString() const
Definition DML.h:43
int32_t intValue
Definition DML.h:29
int32_t flags
Definition DML.h:38
void * N000000D3
Definition DML.h:36
DMLFieldType type
Definition DML.h:33
char pad[3]
Definition DML.h:34
wchar_t * wstrValue
Definition DML.h:31
char pad_0070[8]
Definition DML.h:41
void setValue(T value)
Definition DML.h:73
char pad_0048[8]
Definition DML.h:39
Definition DML.h:129
char pad_0038[72]
Definition DML.h:141
int16_t pad[2]
Definition DML.h:132
uint8_t unk
Definition DML.h:136
uint8_t messageID
Definition DML.h:135
DMLField * startField
Definition DML.h:138
std::unordered_map< std::string, DMLField * > GetRecords()
Definition DML.h:167
void PrintDMLFieldNames()
Definition DML.h:143
char pad_0010[16]
Definition DML.h:137
uint8_t serviceID
Definition DML.h:134
DMLField * getField(const std::string &fieldName)
Definition DML.h:155
DMLField * endField
Definition DML.h:139
bool isInitialized
Definition DML.h:133
DMLField * maxField
Definition DML.h:140
void * vftable
Definition DML.h:131