-
Notifications
You must be signed in to change notification settings - Fork 2
/
Settings.h
630 lines (562 loc) · 20.5 KB
/
Settings.h
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/**
* @file Settings.h
* @brief Defines the class which is used to load and interact with the settings
* specified by the player in the INI file.
* @author Kassent.
* @author Andrew Spaulding (Kasplat)
*
* Rampaged through by Kasplat to change the interface/encapsulation to be
* more clear.
*/
#ifndef __SKYRIM_UNCAPPER_AE_SETTINGS_H__
#define __SKYRIM_UNCAPPER_AE_SETTINGS_H__
#include <string>
#include <vector>
#include "Compare.h"
#include "SkillSlot.h"
#include "Ini.h"
#include "ActorAttribute.h"
#define CONFIG_VERSION 6
template<typename T>
class LeveledSetting {
private:
struct LevelItem {
unsigned int level;
T item;
};
/// @brief The buffer size used to concat the section and subsection.
static const size_t kBufSize = 256;
std::vector<LevelItem> list;
const char *section;
T defaultVal;
/**
* @brief Adds an item to the leveled setting list.
*
* If the given item is already in the setting list, it will not be added
* again.
*
* @param level The level for the item.
* @param item The item to be added.
*/
void
Add(
unsigned int level,
T item
) {
// Store the items in sorted order, so we can binary search for the
// nearest later.
size_t lo = 0, hi = list.size();
size_t mid = lo + ((hi - lo) >> 1);
while (lo < hi) {
ASSERT(mid < list.size());
if (level < list[mid].level) {
hi = mid;
} else if (level > list[mid].level) {
lo = mid + 1;
} else {
return;
}
mid = lo + ((hi - lo) >> 1);
}
// Insert before the final hi element.
ASSERT(hi <= list.size());
list.insert(list.begin() + hi, { level, item });
}
/**
* @brief Reads in the configuration from the given INI file.
* @param ini The INI to read the config from.
* @param sec The section to read in the INI.
* @param val The default value if none is found.
*/
void
InternalReadConfig(
CSimpleIniA &ini,
const char *sec,
T val
) {
CSimpleIniA::TNamesDepend keys;
list.clear();
if (ini.GetAllKeys(sec, keys)) {
for (auto& element : keys) {\
Add(
atoi(element.pItem),
ReadIniValue(ini, sec, element.pItem, val)
);
}
}
Add(0, val);
list.shrink_to_fit();
}
/**
* @brief Saves the content of the list to the given INI file.
* @param ini The INI file to write to.
* @param sec The section to write to.
* @param comment The comment to write to the first element.
*/
void
InternalSaveConfig(
CSimpleIniA &ini,
const char *sec,
const char *comment
) {
char key[16];
for (size_t i = 0; i < list.size(); i++) {
ASSERT(sprintf_s(key, "%d", list[i].level) > 0);\
SaveIniValue(
ini,
sec,
key,
list[i].item,
(!i) ? (comment) : NULL
);
}
}
public:
/// @brief Default constructor. Must give args to ReadConfig()/SaveConfig().
LeveledSetting(
) : list(0),
section(nullptr),
defaultVal(0)
{}
/**
* @brief Constructs a leveled setting with the given section and default.
*
* If this initializer is used, then it is illegal to call ReadConfig()
* and SaveConfig() with more than the ini argument.
*
* @param section The section to read/write the setting to.
* @param default The default value for the setting.
*/
LeveledSetting(
const char *section,
T default_val
) : list(0),
section(section),
defaultVal(default_val)
{}
/**
* @brief Reads in the configuration from the given INI file.
*
* It is illegal to call this function if the list was initialized with
* the non-default constructor.
*
* @param ini The ini file to read the configuration from.
* @param sec The section to read the configuration from.
* @param subsec The subsection to read the config from.
* @param val A default value if no config is found.
*/
void
ReadConfig(
CSimpleIniA &ini,
const char *sec,
const char *subsec,
T val
) {
ASSERT(section == nullptr);
char buf[kBufSize];
auto res = sprintf_s(buf, "%s%s", sec, subsec);
ASSERT((0 < res) && (res < kBufSize));
InternalReadConfig(ini, buf, val);
}
/**
* @brief Reads in the configuration from the given INI file.
*
* It is illegal to call this function if the list was initialized with
* the default constuctor.
*
* @param ini The ini file to read the configuration from.
*/
void
ReadConfig(
CSimpleIniA &ini
) {
ASSERT(section);
InternalReadConfig(ini, section, defaultVal);
}
/**
* @brief Saves the content of the list to the given INI file.
*
* It is illegal to call this function if the list was initialized with
* the non-default constructor.
*
* @param ini The INI file to save the content to.
* @param sec The section to save the configuration to.
* @param subsec The subsection to save the configuration to.
* @param comment The comment to add to the top of the section.
*/
void
SaveConfig(
CSimpleIniA &ini,
const char *sec,
const char *subsec,
const char *comment
) {
ASSERT(section == nullptr);
char buf[kBufSize];
auto res = sprintf_s(buf, "%s%s", sec, subsec);
ASSERT((0 < res) && (res < kBufSize));
InternalSaveConfig(ini, buf, comment);
}
/**
* @brief Saves the content of the list to the given INI file.
*
* It is illegal to call this function if the list was initialized with
* the default constructor.
*
* @param ini The INI file to save the content to.
* @param comment The comment to add to the top of the section.
*/
void
SaveConfig(
CSimpleIniA &ini,
const char *comment
) {
ASSERT(section);
InternalSaveConfig(ini, section, comment);
}
/**
* @brief Finds the value closest to the given level in the list.
*
* Note that only values whose level is less than or equal to the given
* level will be considered.
*
* @param level The level to search for an item for.
* @return The associated value.
*/
T
GetNearest(
unsigned int level
) {
ASSERT(list.size() > 0);
size_t lo = 0, hi = list.size();
size_t mid = lo + ((hi - lo) >> 1);
while (lo < hi) {
ASSERT(mid < list.size());
if ((list[mid].level <= level)
&& ((mid + 1 == list.size()) || (level < list[mid + 1].level))) {
return list[mid].item;
} else if (level < list[mid].level) {
hi = mid;
} else {
ASSERT((level > list[mid].level) || (level >= list[mid + 1].level));
lo = mid + 1;
}
mid = lo + ((hi - lo) >> 1);
}
// If no direct match was found, return the closest lo item.
return list[lo].item;
}
/**
* @brief Accumulates the values across all previous levels, and determines
* what the increment from the last level was.
*
* This function is intended to be used for the calculation of partial
* perk point awards.
*
* @param level The new level of the player.
* @return The increment from the previous level.
*/
unsigned int
GetCumulativeDelta(
unsigned int level
) {
ASSERT(list.size() > 0);
T pacc = 0, acc = 0;
for (size_t i = 0; (i < list.size()) && (list[i].level <= level); i++) {
// Update the accumulation. Note the exclusive upper bound on level.
unsigned int bound = ((i + 1) < list.size()) ? list[i + 1].level : level + 1;
unsigned int this_level = MIN(level + 1, bound);
acc += (this_level - list[i].level) * list[i].item;
// If this is the last iteration, get the previous accumulation.
if (((i + 1) >= list.size()) || (list[i + 1].level > level)) {
pacc = acc - list[i].item;
}
}
return static_cast<unsigned int>(acc) - static_cast<unsigned int>(pacc);
}
};
template <typename T>
class SkillSetting {
private:
/// @brief Size of the prefixed skill field buffer.
static const size_t kBufSize = 32;
T val;
public:
SkillSetting() {}
/**
* @brief Gets the value contained by this skill setting.
*/
inline T
Get() {
return val;
}
/**
* @brief Reads in the config from the given ini file.
* @param ini The INI to read from.
* @param section The section to read from.
* @param field The field to read from.
* @param default_val The value to assume if the data is not available.
*/
void
ReadConfig(
CSimpleIniA &ini,
const char *section,
const char *field,
T default_val
) {
char buf[kBufSize];
auto res = sprintf_s(buf, "%c%s", GetPrefix<T>(), field);
ASSERT((0 < res) && (res < kBufSize));
val = ReadIniValue(ini, section, buf, default_val);
}
/**
* @brief Saves the current value to the given INI file.
* @param ini The INI to save to.
* @param section The section to save to.
* @param field The field to write to.
* @param comment The comment to add to the field.
*/
void
SaveConfig(
CSimpleIniA &ini,
const char *section,
const char *field,
const char *comment
) {
char buf[kBufSize];
auto res = sprintf_s(buf, "%c%s", GetPrefix<T>(), field);
ASSERT((0 < res) && (res < kBufSize));
SaveIniValue(ini, section, buf, val, comment);
}
};
template <template<typename> class T, typename U>
class SkillSettingManager {
private:
const char *section;
T<U> data[SkillSlot::kCount];
U defaultVal;
public:
SkillSettingManager(
const char *section,
U default_val
) : section(section),
defaultVal(default_val)
{}
/**
* @brief Gets the setting for the given skill.
* @param The skill to get the setting for.
*/
T<U>&
Get(
SkillSlot::t skill
) {
return data[skill];
}
/**
* @brief Reads in the given configuration file.
* @param ini The ini file to read.
*/
void
ReadConfig(
CSimpleIniA &ini
) {
for (int i = 0; i < SkillSlot::kCount; i++) {
SkillSlot::t slot = static_cast<SkillSlot::t>(i);
data[i].ReadConfig(ini, section, SkillSlot::Str(slot), defaultVal);
}
}
/**
* @brief Writes out the configuration to the given INI file.
* @param ini The ini file to write the configuration to.
* @param comment The comment to write to the first element.
*/
void
SaveConfig(
CSimpleIniA &ini,
const char *comment
) {
for (int i = 0; i < SkillSlot::kCount; i++) {
SkillSlot::t slot = static_cast<SkillSlot::t>(i);
data[i].SaveConfig(ini, section, SkillSlot::Str(slot), (!i) ? comment : NULL);
}
}
};
class Settings {
private:
class GeneralSettings {
private:
static const char *const kSection;
static const char *const kVersionDesc;
static const char *const kEnableSkillCapsDesc;
static const char *const kEnableSkillFormulaCapsDesc;
static const char *const kEnableEnchantingPatchDesc;
static const char *const kEnableSkillExpMultsDesc;
static const char *const kEnableLevelExpMultsDesc;
static const char *const kEnablePerkPointsDesc;
static const char *const kEnableAttributePointsDesc;
static const char *const kEnableLegendaryDesc;
public:
SectionField<unsigned int> version;
SectionField<std::string> author;
SectionField<bool> enableSkillCaps;
SectionField<bool> enableSkillFormulaCaps;
SectionField<bool> enableEnchantingPatch;
SectionField<bool> enableSkillExpMults;
SectionField<bool> enableLevelExpMults;
SectionField<bool> enablePerkPoints;
SectionField<bool> enableAttributePoints;
SectionField<bool> enableLegendary;
GeneralSettings(
) : version("Version", 0),
author("Author", "Kassent"),
enableSkillCaps("bUseSkillCaps", true),
enableSkillFormulaCaps("bUseSkillFormulaCaps", true),
enableEnchantingPatch("bUseEnchanterCaps", true),
enableSkillExpMults("bUseSkillExpGainMults", true),
enableLevelExpMults("bUsePCLevelSkillExpMults", true),
enablePerkPoints("bUsePerksAtLevelUp", true),
enableAttributePoints("bUseAttributesAtLevelUp", true),
enableLegendary("bUseLegendarySettings", true)
{}
void ReadConfig(CSimpleIniA &ini);
void SaveConfig(CSimpleIniA &ini);
};
class EnchantSettings {
private:
static const char *const kSection;
static const char *const kMagnitudeLevelCapDesc;
static const char *const kChargeLevelCapDesc;
static const char *const kUseLinearChargeFormulaDesc;
public:
SectionField<unsigned int> magnitudeLevelCap;
SectionField<unsigned int> chargeLevelCap;
SectionField<bool> useLinearChargeFormula;
EnchantSettings(
) : magnitudeLevelCap("iMagnitudeLevelCap", 100),
chargeLevelCap("iChargeLevelCap", 199),
useLinearChargeFormula("bUseLinearChargeFormula", false)
{}
void ReadConfig(CSimpleIniA &ini);
void SaveConfig(CSimpleIniA &ini);
};
class LegendarySettings {
private:
static const char *const kSection;
static const char *const kKeepSkillLevelDesc;
static const char *const kHideButtonDesc;
static const char *const kSkillLevelEnableDesc;
static const char *const kSkillLevelAfterDesc;
public:
SectionField<bool> keepSkillLevel;
SectionField<bool> hideButton;
SectionField<unsigned int> skillLevelEnable;
SectionField<unsigned int> skillLevelAfter;
LegendarySettings(
) : keepSkillLevel("bLegendaryKeepSkillLevel", false),
hideButton("bHideLegendaryButton", true),
skillLevelEnable("iSkillLevelEnableLegendary", 100),
skillLevelAfter("iSkillLevelAfterLegendary", 0)
{}
void ReadConfig(CSimpleIniA &ini);
void SaveConfig(CSimpleIniA &ini);
};
static const char *const kSkillCapsDesc;
static const char *const kSkillFormulaCapsDesc;
static const char *const kSkillExpGainMultsDesc;
static const char *const kSkillExpGainMultsWithPCLevelDesc;
static const char *const kSkillExpGainMultsWithSkillsDesc;
static const char *const kLevelSkillExpMultsDesc;
static const char *const kLevelSkillExpMultsWithPCLevelDesc;
static const char *const kLevelSkillExpMultsWithSkillsDesc;
static const char *const kPerksAtLevelUpDesc;
static const char *const kHealthAtLevelUpDesc;
static const char *const kHealthAtMagickaLevelUpDesc;
static const char *const kHealthAtStaminaLevelUpDesc;
static const char *const kMagickaAtLevelUpDesc;
static const char *const kMagickaAtHealthLevelUpDesc;
static const char *const kMagickaAtStaminaLevelUpDesc;
static const char *const kStaminaAtLevelUpDesc;
static const char *const kStaminaAtHealthLevelUpDesc;
static const char *const kStaminaAtMagickaLevelUpDesc;
static const char *const kCarryWeightAtHealthLevelUpDesc;
static const char *const kCarryWeightAtMagickaLevelUpDesc;
static const char *const kCarryWeightAtStaminaLevelUpDesc;
bool SaveConfig(CSimpleIniA &ini, const std::string &path);
GeneralSettings general;
SkillSettingManager<SkillSetting, unsigned int> skillCaps;
SkillSettingManager<SkillSetting, unsigned int> skillFormulaCaps;
EnchantSettings enchant;
SkillSettingManager<SkillSetting, float> skillExpGainMults;
SkillSettingManager<LeveledSetting, float> skillExpGainMultsWithSkills;
SkillSettingManager<LeveledSetting, float> skillExpGainMultsWithPCLevel;
SkillSettingManager<SkillSetting, float> levelSkillExpMults;
SkillSettingManager<LeveledSetting, float> levelSkillExpMultsWithSkills;
SkillSettingManager<LeveledSetting, float> levelSkillExpMultsWithPCLevel;
LeveledSetting<float> perksAtLevelUp;
LeveledSetting<unsigned int> healthAtLevelUp;
LeveledSetting<unsigned int> healthAtMagickaLevelUp;
LeveledSetting<unsigned int> healthAtStaminaLevelUp;
LeveledSetting<unsigned int> magickaAtLevelUp;
LeveledSetting<unsigned int> magickaAtHealthLevelUp;
LeveledSetting<unsigned int> magickaAtStaminaLevelUp;
LeveledSetting<unsigned int> staminaAtLevelUp;
LeveledSetting<unsigned int> staminaAtHealthLevelUp;
LeveledSetting<unsigned int> staminaAtMagickaLevelUp;
LeveledSetting<unsigned int> carryWeightAtHealthLevelUp;
LeveledSetting<unsigned int> carryWeightAtMagickaLevelUp;
LeveledSetting<unsigned int> carryWeightAtStaminaLevelUp;
LegendarySettings legendary;
public:
Settings(
) : general(),
skillCaps("SkillCaps", 100),
skillFormulaCaps("SkillFormulaCaps", 100),
enchant(),
skillExpGainMults("SkillExpGainMults", 1.00),
skillExpGainMultsWithPCLevel("SkillExpGainMults\\CharacterLevel\\", 1.00),
skillExpGainMultsWithSkills("SkillExpGainMults\\BaseSkillLevel\\", 1.00),
levelSkillExpMults("LevelSkillExpMults", 1.00),
levelSkillExpMultsWithPCLevel("LevelSkillExpMults\\CharacterLevel\\", 1.00),
levelSkillExpMultsWithSkills("LevelSkillExpMults\\BaseSkillLevel\\", 1.00),
perksAtLevelUp("PerksAtLevelUp", 1.00),
healthAtLevelUp("HealthAtLevelUp", 10),
healthAtMagickaLevelUp("HealthAtMagickaLevelUp", 0),
healthAtStaminaLevelUp("HealthAtStaminaLevelUp", 0),
magickaAtLevelUp("MagickaAtLevelUp", 10),
magickaAtHealthLevelUp("MagickaAtHealthLevelUp", 0),
magickaAtStaminaLevelUp("MagickaAtStaminaLevelUp", 0),
staminaAtLevelUp("StaminaAtLevelUp", 10),
staminaAtHealthLevelUp("StaminaAtHealthLevelUp", 0),
staminaAtMagickaLevelUp("StaminaAtMagickaLevelUp", 0),
carryWeightAtHealthLevelUp("CarryWeightAtHealthLevelUp", 0),
carryWeightAtMagickaLevelUp("CarryWeightAtMagickaLevelUp", 0),
carryWeightAtStaminaLevelUp("CarryWeightAtStaminaLevelUp", 5),
legendary()
{}
bool ReadConfig(const std::string& path);
inline bool IsSkillCapEnabled(void) { return general.enableSkillCaps.Get(); }
inline bool IsSkillFormulaCapEnabled(void) { return general.enableSkillFormulaCaps.Get(); }
inline bool IsEnchantPatchEnabled(void) { return general.enableEnchantingPatch.Get(); }
inline bool IsSkillExpEnabled(void) { return general.enableSkillExpMults.Get(); }
inline bool IsLevelExpEnabled(void) { return general.enableLevelExpMults.Get(); }
inline bool IsPerkPointsEnabled(void) { return general.enablePerkPoints.Get(); }
inline bool IsAttributePointsEnabled(void) { return general.enableAttributePoints.Get(); }
inline bool IsLegendaryEnabled(void) { return general.enableLegendary.Get(); }
float GetSkillCap(ActorAttribute::t skill);
float GetSkillFormulaCap(ActorAttribute::t skill);
float GetEnchantMagnitudeCap(void);
float GetEnchantChargeCap(void);
inline bool IsEnchantChargeLinear(void) { return enchant.useLinearChargeFormula.Get(); }
float GetSkillExpGainMult(ActorAttribute::t skill, unsigned int skill_level,
unsigned int player_level);
float GetLevelSkillExpMult(ActorAttribute::t skill, unsigned int skill_level,
unsigned int player_level);
unsigned int GetPerkDelta(unsigned int player_level);
void GetAttributeLevelUp(unsigned int player_level, ActorAttribute::t attr,
ActorAttributeLevelUp &level_up);
bool IsLegendaryButtonVisible(unsigned int skill_level);
bool IsLegendaryAvailable(unsigned int skill_level);
float GetPostLegendarySkillLevel(float default_reset, float base_level);
};
extern Settings settings;
#endif /* __SKYRIM_UNCAPPER_AE_SETTINGS_H__ */