-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHook_Skill.cpp
More file actions
245 lines (220 loc) · 7.02 KB
/
Hook_Skill.cpp
File metadata and controls
245 lines (220 loc) · 7.02 KB
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
/**
* @file Hook_SKill.cpp
* @author Kassent
* @author Vadfromnu
* @author Andrew Spaulding (Kasplat)
* @brief C++ implementation of game patches.
*
* Note that several of these functions first go through wrappers in
* HookWrappers.S. See the documentation in RelocPatch.cpp and HookWrappers.S
* for more information on how these patches are modifying the game.
*/
#include "Hook_Skill.h"
#include "GameReferences.h"
#include "GameSettings.h"
#include "HookWrappers.h"
#include "Settings.h"
#include "RelocFn.h"
#include "Compare.h"
#include "ActorAttribute.h"
/**
* @brief Determines the real skill cap of the given skill.
*/
extern "C" float
GetSkillCap_Hook(
ActorAttribute::t skill
) {
ASSERT(settings.IsSkillCapEnabled());
return settings.GetSkillCap(skill);
}
/**
* @brief Reimplements the enchantment charge point equation.
*
* The original equation would fall apart for levels above 199, so this
* implementation caps the level in the calculation to 199.
*
* @param player_av The actor value owner from the player class.
* @param base_points The base point value for the enchantment.
* @param max_charge The maximum charge level of the item.
* @return The charge points per use on the item.
*/
extern "C" float
CalculateChargePointsPerUse_Hook(
void *player_av,
float base_points,
float max_charge
) {
ASSERT(settings.IsEnchantPatchEnabled());
float cost_exponent = *GetFloatGameSetting("fEnchantingCostExponent");
float cost_base = *GetFloatGameSetting("fEnchantingSkillCostBase");
float cost_scale = *GetFloatGameSetting("fEnchantingSkillCostScale");
float cost_mult = *GetFloatGameSetting("fEnchantingSkillCostMult");
float cap = settings.GetEnchantChargeCap();
float enchanting_level = MIN(
PlayerAVOGetCurrent_Original(player_av, ActorAttribute::Enchanting),
cap
);
float base = cost_mult * pow(base_points, cost_exponent);
if (settings.IsEnchantChargeLinear()) {
// Linearly scale between the normal min/max of charge points.
float max_level_scale = pow(cap * cost_base, cost_scale);
float slope = (max_charge * max_level_scale) / (base * (1.0f - max_level_scale) * cap);
float intercept = max_charge / base;
float linear_charge = slope * enchanting_level + intercept;
return max_charge / linear_charge;
} else {
// Original game equation.
return base * (1.0f - pow(enchanting_level * cost_base, cost_scale));
}
}
/**
* @brief Caps the formulas for the given skill_id to the value specified in
* the INI file.
*/
float
PlayerAVOGetCurrent_Hook(
void *av,
ActorAttribute::t attr
) {
ASSERT(settings.IsSkillFormulaCapEnabled());
// FIXME: Need to find where this is called in the text color code and
// replace it so the skills menu is actually correct.
float val = PlayerAVOGetCurrent_Original(av, attr);
if (ActorAttribute::IsSkill(attr)) {
val = MAX(0, MIN(val, settings.GetSkillFormulaCap(attr)));
// If this is a call for enchanting, we enforce the magnitude
// cap here. Note that this hook is never called for charge
// calculation; we overwrite the code which would have.
if (attr == ActorAttribute::Enchanting) {
val = MIN(val, settings.GetSkillFormulaCap(ActorAttribute::Enchanting));
}
}
return val;
}
/**
* @brief Applies a multiplier to the exp gain for the given skill.
*/
void
ImprovePlayerSkillPoints_Hook(
PlayerSkills *skill_data,
ActorAttribute::t attr,
float exp,
UInt64 unk1,
UInt32 unk2,
UInt8 unk3,
bool unk4
) {
ASSERT(settings.IsSkillExpEnabled());
if (ActorAttribute::IsSkill(attr)) {
exp *= settings.GetSkillExpGainMult(
attr,
PlayerAVOGetBase(attr),
GetPlayerLevel()
);
}
ImprovePlayerSkillPoints_Original(skill_data, attr, exp, unk1, unk2, unk3, unk4);
}
/**
* @brief Adjusts the number of perks the player receives at a level-up.
* @param points The number of perk points the player has.
* @param count The original number of points the perk pool was being
* adjusted by.
* @return The new number of perk points the player has.
*/
extern "C" UInt8
ModifyPerkPool_Hook(
UInt8 points,
SInt8 count
) {
ASSERT(settings.IsPerkPointsEnabled());
int delta = MIN(0xFF, settings.GetPerkDelta(GetPlayerLevel()));
int res = points + ((count > 0) ? delta : count);
return static_cast<UInt8>(MAX(0, MIN(0xFF, res)));
}
/**
* @brief Multiplies the EXP gain of a level-up by our configured multiplier.
* @param exp The original exp gain.
* @param skill_id The skill which this exp is being gained from.
* @return The new exp multiplier.
*/
extern "C" float
ImproveLevelExpBySkillLevel_Hook(
float exp,
ActorAttribute::t attr
) {
ASSERT(settings.IsLevelExpEnabled());
if (ActorAttribute::IsSkill(attr)) {
exp *= settings.GetLevelSkillExpMult(
attr,
PlayerAVOGetBase(attr),
GetPlayerLevel()
);
}
return exp;
}
/**
* @brief Adjusts the attribute gain at each level up based on the settings in
* the INI file.
*
* This function overwrites a call to player_avo->ModBase. Since we're
* overwriting a call, we don't need to reg save and, thus, don't need a
* wrapper. We also overwrite the carry weight level up.
*/
void
ImproveAttributeWhenLevelUp_Hook(
void *player_avo,
ActorAttribute::t choice
) {
(void)player_avo;
ASSERT(settings.IsAttributePointsEnabled());
ActorAttributeLevelUp level_up;
settings.GetAttributeLevelUp(
GetPlayerLevel(),
choice,
level_up
);
PlayerAVOModBase(ActorAttribute::Health, level_up.health);
PlayerAVOModBase(ActorAttribute::Magicka, level_up.magicka);
PlayerAVOModBase(ActorAttribute::Stamina, level_up.stamina);
PlayerAVOModCurrent(
0, // Same as OG call.
ActorAttribute::CarryWeight,
level_up.carry_weight
);
}
/**
* @brief Determines what level a skill should take on after being legendaried.
*/
extern "C" void
LegendaryResetSkillLevel_Hook(
float base_level
) {
ASSERT(settings.IsLegendaryEnabled());
float *reset_val = GetFloatGameSetting("fLegendarySkillResetValue");
*reset_val = settings.GetPostLegendarySkillLevel(*reset_val, base_level);
}
/**
* @brief Overwrites the check which determines when a skill can be legendaried.
*/
extern "C" bool
CheckConditionForLegendarySkill_Hook(
void *player_actor,
ActorAttribute::t skill
) {
ASSERT(settings.IsLegendaryEnabled());
float skill_level = PlayerAVOGetBase(skill);
return settings.IsLegendaryAvailable(skill);
}
/**
* @brief Determines if the legendary button should be displayed for the given
* skill based on the users settings.
*/
extern "C" bool
HideLegendaryButton_Hook(
void *player_actor,
ActorAttribute::t skill
) {
ASSERT(settings.IsLegendaryEnabled());
float skill_level = PlayerAVOGetBase(skill);
return settings.IsLegendaryButtonVisible(skill_level);
}