-
Notifications
You must be signed in to change notification settings - Fork 5
/
utility.cpp
307 lines (258 loc) · 10.5 KB
/
utility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include "utility.h"
#include <cmath>
#include <iostream>
#include <regex>
#include <unordered_map>
RE::BIPED_MODEL::BipedObjectSlot getBipedObjectSlot(int slot)
{
switch (slot) {
case 0:
return RE::BIPED_MODEL::BipedObjectSlot::kHead;
case 1:
return RE::BIPED_MODEL::BipedObjectSlot::kHair;
case 2:
return RE::BIPED_MODEL::BipedObjectSlot::kBody;
case 3:
return RE::BIPED_MODEL::BipedObjectSlot::kHands;
case 4:
return RE::BIPED_MODEL::BipedObjectSlot::kForearms;
case 5:
return RE::BIPED_MODEL::BipedObjectSlot::kAmulet;
case 6:
return RE::BIPED_MODEL::BipedObjectSlot::kRing;
case 7:
return RE::BIPED_MODEL::BipedObjectSlot::kFeet;
case 8:
return RE::BIPED_MODEL::BipedObjectSlot::kCalves;
case 9:
return RE::BIPED_MODEL::BipedObjectSlot::kShield;
case 10:
return RE::BIPED_MODEL::BipedObjectSlot::kTail;
case 11:
return RE::BIPED_MODEL::BipedObjectSlot::kLongHair;
case 12:
return RE::BIPED_MODEL::BipedObjectSlot::kCirclet;
case 13:
return RE::BIPED_MODEL::BipedObjectSlot::kEars;
case 14:
return RE::BIPED_MODEL::BipedObjectSlot::kModMouth;
case 15:
return RE::BIPED_MODEL::BipedObjectSlot::kModNeck;
case 16:
return RE::BIPED_MODEL::BipedObjectSlot::kModChestPrimary;
case 17:
return RE::BIPED_MODEL::BipedObjectSlot::kModBack;
case 18:
return RE::BIPED_MODEL::BipedObjectSlot::kModMisc1;
case 19:
return RE::BIPED_MODEL::BipedObjectSlot::kModPelvisPrimary;
case 20:
return RE::BIPED_MODEL::BipedObjectSlot::kDecapitateHead;
case 21:
return RE::BIPED_MODEL::BipedObjectSlot::kDecapitate;
case 22:
return RE::BIPED_MODEL::BipedObjectSlot::kModPelvisSecondary;
case 23:
return RE::BIPED_MODEL::BipedObjectSlot::kModLegRight;
case 24:
return RE::BIPED_MODEL::BipedObjectSlot::kModLegLeft;
case 25:
return RE::BIPED_MODEL::BipedObjectSlot::kModFaceJewelry;
case 26:
return RE::BIPED_MODEL::BipedObjectSlot::kModChestSecondary;
case 27:
return RE::BIPED_MODEL::BipedObjectSlot::kModShoulder;
case 28:
return RE::BIPED_MODEL::BipedObjectSlot::kModArmLeft;
case 29:
return RE::BIPED_MODEL::BipedObjectSlot::kModArmRight;
case 30:
return RE::BIPED_MODEL::BipedObjectSlot::kModMisc2;
case 31:
return RE::BIPED_MODEL::BipedObjectSlot::kFX01;
default:
return RE::BIPED_MODEL::BipedObjectSlot::kNone;
}
}
AttributePoints calculateAttributePoints(int level, const StatWeights& weights, int points)
{
AttributePoints result;
// Calculate the total number of points available
int totalPoints = points * (level - 1);
// Check and replace zero weights with 1
float healthWeight = (weights.healthWeight != 0) ? weights.healthWeight : 1;
float staminaWeight = (weights.staminaWeight != 0) ? weights.staminaWeight : 1;
float magickaWeight = (weights.magickaWeight != 0) ? weights.magickaWeight : 1;
// Calculate Magicka Points
int magickaPoints = totalPoints * magickaWeight / (healthWeight + staminaWeight + magickaWeight);
result.magicka = magickaPoints;
// Calculate Stamina Points
int staminaPoints = (totalPoints - magickaPoints) * staminaWeight / (healthWeight + staminaWeight);
result.stamina = staminaPoints;
// Calculate Health Points
result.health = totalPoints - magickaPoints - staminaPoints;
return result;
}
bool IsPluginInstalled(const char* name)
{
auto dataHandler = RE::TESDataHandler::GetSingleton();
auto* modInfo = dataHandler->LookupLoadedModByName(name);
if (modInfo)
return true;
modInfo = dataHandler->LookupLoadedLightModByName(name);
if (modInfo)
return true;
return false;
}
template <typename T>
T GetOffset(const void* baseObject, int offset)
{
return *reinterpret_cast<T*>((uintptr_t)baseObject + offset);
}
RE::TESForm* GetFormFromIdentifier(const std::string& identifier)
{
auto dataHandler = RE::TESDataHandler::GetSingleton();
auto delimiter = identifier.find('|');
if (delimiter != std::string::npos) {
std::string modName = identifier.substr(0, delimiter);
std::string modForm = identifier.substr(delimiter + 1);
uint32_t formID = std::stoul(modForm, nullptr, 16) & 0xFFFFFF;
auto* mod = dataHandler->LookupModByName(modName.c_str());
if (mod->IsLight())
formID = std::stoul(modForm, nullptr, 16) & 0xFFF;
return dataHandler->LookupForm(formID, modName.c_str());
}
return nullptr;
}
std::string toLowerCase(std::string pString)
{
std::string lowercasepString = pString;
std::transform(lowercasepString.begin(), lowercasepString.end(), lowercasepString.begin(), [](unsigned char c) { return std::tolower(c); });
return lowercasepString;
}
std::string trim(const std::string& str)
{
size_t first = str.find_first_not_of(' ');
if (std::string::npos == first) {
return str;
}
size_t last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
std::vector<std::string> splitRelationNumber(const std::string& input)
{
std::regex re(R"(([<>]=?|[<>])\s*(\d+))");
std::smatch match;
std::vector<std::string> result;
if (std::regex_search(input, match, re)) {
std::string relation_sign = match[1];
std::string number_str = match[2];
result.push_back(number_str);
result.push_back(relation_sign);
} else if (std::regex_search(input, std::regex(R"(\d+)"))) {
result.push_back(input);
} else {
result.push_back("none");
}
return result;
}
//extract functions
// Function to extract data from a line using a regex pattern
void extractData(const std::string& line, const std::string& pattern, std::vector<std::string>& destination)
{
std::regex regex_pattern(pattern, std::regex::icase);
std::smatch match;
std::regex_search(line, match, regex_pattern);
std::shared_ptr<std::vector<std::string>> data = std::make_shared<std::vector<std::string>>();
if (!match.empty() && !match[1].str().empty()) {
std::string data_str = match[1];
std::regex list_regex("[^,]+[ ]*[|][ ]*[a-zA-Z0-9]{1,8}", std::regex::icase);
std::sregex_iterator iterator(data_str.begin(), data_str.end(), list_regex);
std::sregex_iterator end;
while (iterator != end) {
std::string tempVar = (*iterator)[0].str();
tempVar.erase(tempVar.begin(), std::find_if_not(tempVar.begin(), tempVar.end(), ::isspace));
tempVar.erase(std::find_if_not(tempVar.rbegin(), tempVar.rend(), ::isspace).base(), tempVar.end());
if (tempVar != "none") {
(*data).push_back(tempVar);
}
++iterator;
}
}
destination = (*data);
}
void extractMultiDataString(const std::string& line, const std::string& pattern, std::vector<std::string>& pcMultFlag,
std::vector<std::string>& pcMultFlag_min_values, std::vector<std::string>& pcMultFlag_max_values)
{
std::regex pcMultFlag_regex(pattern, std::regex::icase);
std::smatch pcMultFlag_match;
std::regex_search(line, pcMultFlag_match, pcMultFlag_regex);
if (!pcMultFlag_match.empty() && !pcMultFlag_match[1].str().empty()) {
std::string pcMultFlag_str = pcMultFlag_match[1];
std::regex pcMultFlag_list_regex("(\\w+)\\s*=\\s*([\\d.]+)(?:\\s*~\\s*([\\d.]+))?", std::regex::icase);
std::sregex_iterator pcMultFlag_iterator(pcMultFlag_str.begin(), pcMultFlag_str.end(), pcMultFlag_list_regex);
std::sregex_iterator pcMultFlag_end;
while (pcMultFlag_iterator != pcMultFlag_end) {
std::string avif = (*pcMultFlag_iterator)[1].str();
avif.erase(avif.begin(), std::find_if_not(avif.begin(), avif.end(), ::isspace));
avif.erase(std::find_if_not(avif.rbegin(), avif.rend(), ::isspace).base(), avif.end());
if (avif == "none") {
break;
}
pcMultFlag.push_back(avif);
pcMultFlag_min_values.push_back((*pcMultFlag_iterator)[2]);
pcMultFlag_max_values.push_back((*pcMultFlag_iterator)[3] != "" ? (*pcMultFlag_iterator)[3] : (*pcMultFlag_iterator)[2]);
++pcMultFlag_iterator;
}
}
}
void extractMultiDataInt(const std::string& line, const std::string& pattern, std::vector<std::string>& pcMultFlag,
std::vector<int>& pcMultFlag_min_values, std::vector<int>& pcMultFlag_max_values)
{
std::regex pcMultFlag_regex(pattern, std::regex::icase);
std::smatch pcMultFlag_match;
std::regex_search(line, pcMultFlag_match, pcMultFlag_regex);
if (!pcMultFlag_match.empty() && !pcMultFlag_match[1].str().empty()) {
std::string pcMultFlag_str = pcMultFlag_match[1];
std::regex pcMultFlag_list_regex("(\\w+)\\s*=\\s*([\\d.]+)(?:\\s*~\\s*([\\d.]+))?", std::regex::icase);
std::sregex_iterator pcMultFlag_iterator(pcMultFlag_str.begin(), pcMultFlag_str.end(), pcMultFlag_list_regex);
std::sregex_iterator pcMultFlag_end;
while (pcMultFlag_iterator != pcMultFlag_end) {
std::string avif = (*pcMultFlag_iterator)[1].str();
avif.erase(avif.begin(), std::find_if_not(avif.begin(), avif.end(), ::isspace));
avif.erase(std::find_if_not(avif.rbegin(), avif.rend(), ::isspace).base(), avif.end());
if (avif == "none") {
break;
}
pcMultFlag.push_back(avif);
pcMultFlag_min_values.push_back(std::stoi((*pcMultFlag_iterator)[2]));
pcMultFlag_max_values.push_back((*pcMultFlag_iterator)[3] != "" ? std::stoi((*pcMultFlag_iterator)[3]) : std::stoi((*pcMultFlag_iterator)[2]));
++pcMultFlag_iterator;
}
}
}
void extractMultiDataFloat(const std::string& line, const std::string& pattern, std::vector<std::string>& pcMultFlag,
std::vector<float>& pcMultFlag_min_values, std::vector<float>& pcMultFlag_max_values)
{
std::regex pcMultFlag_regex(pattern, std::regex::icase);
std::smatch pcMultFlag_match;
std::regex_search(line, pcMultFlag_match, pcMultFlag_regex);
if (!pcMultFlag_match.empty() && !pcMultFlag_match[1].str().empty()) {
std::string pcMultFlag_str = pcMultFlag_match[1];
std::regex pcMultFlag_list_regex("(\\w+)\\s*=\\s*([\\d.]+)(?:\\s*~\\s*([\\d.]+))?", std::regex::icase);
std::sregex_iterator pcMultFlag_iterator(pcMultFlag_str.begin(), pcMultFlag_str.end(), pcMultFlag_list_regex);
std::sregex_iterator pcMultFlag_end;
while (pcMultFlag_iterator != pcMultFlag_end) {
std::string avif = (*pcMultFlag_iterator)[1].str();
avif.erase(avif.begin(), std::find_if_not(avif.begin(), avif.end(), ::isspace));
avif.erase(std::find_if_not(avif.rbegin(), avif.rend(), ::isspace).base(), avif.end());
if (avif == "none") {
break;
}
pcMultFlag.push_back(avif);
pcMultFlag_min_values.push_back(std::stof((*pcMultFlag_iterator)[2]));
pcMultFlag_max_values.push_back((*pcMultFlag_iterator)[3] != "" ? std::stof((*pcMultFlag_iterator)[3]) : std::stof((*pcMultFlag_iterator)[2]));
++pcMultFlag_iterator;
}
}
}