Tweaked how XPTable data was loaded

* to align hook functions with the engine functions they replaced.
This commit is contained in:
NovaRain
2024-11-19 21:54:26 +08:00
parent a585d936ce
commit d193568678
3 changed files with 12 additions and 8 deletions
@@ -3489,6 +3489,7 @@ FUNC(srcCopy_, 0x4E0DB0)
FUNC(sscanf_, 0x4F0EF5)
FUNC(stackavail_, 0x4EE308)
FUNC(statPCAddExperienceCheckPMs_, 0x4AFAB8)
FUNC(statPcMinExpForLevel_, 0x4AF9A8)
FUNC(statPcResetExperience_, 0x4AFC38)
FUNC(stat_description_, 0x4AF898)
FUNC(stat_exit_, 0x4AEEE4)
+1 -1
View File
@@ -4285,7 +4285,7 @@ void BugFixes::init() {
SafeWrite8(0x440C8E, 7); // jnz 0x440C96
// Fix for gaining two levels at once when leveling up from level 97
SafeWrite8(0x4AF9AF, 0x7F); // jge > jg (stat_pc_min_exp_)
SafeWrite8(0x4AF9AF, 0x7F); // jge > jg (statPcMinExpForLevel_)
// Fix to prevent integer overflow for the number of items in a stack in the inventory
// If the number of items in a stack is less than 1, it is considered an integer overflow
+10 -7
View File
@@ -110,10 +110,11 @@ failMax:
}
}
// Returns experience to reach a given level
static __declspec(naked) void GetLevelXPHook() {
__asm {
cmp eax, PC_LEVEL_MAX;
jge lvlMax;
jg lvlMax;
dec eax;
mov eax, [xpTable + eax * 4];
retn;
@@ -123,9 +124,11 @@ lvlMax:
}
}
// Returns experience to reach the next level
static __declspec(naked) void GetNextLevelXPHook() {
__asm {
mov eax, ds:[FO_VAR_Level_pc];
inc eax;
jmp GetLevelXPHook;
}
}
@@ -299,13 +302,13 @@ void Stats::init() {
size_t numLevels = xpTableList.size();
if (numLevels > 0) {
if (numLevels >= PC_LEVEL_MAX) numLevels = PC_LEVEL_MAX - 1;
HookCalls(GetNextLevelXPHook, {0x434AA7, 0x439642, 0x4AFB22});
HookCalls(GetLevelXPHook, {0x496C8D, 0x4AFC53});
HookCalls(GetNextLevelXPHook, {0x434AA7, 0x439642, 0x4AFB22}); // replace stat_pc_min_exp_
HookCalls(GetLevelXPHook, {0x496C8D, 0x4AFC53}); // replace statPcMinExpForLevel_
for (size_t i = 0; i < PC_LEVEL_MAX; i++) {
xpTable[i] = (i < numLevels)
? atoi(xpTableList[i].c_str())
: -1;
for (size_t i = 0; i < PC_LEVEL_MAX - 1; i++) {
xpTable[i + 1] = (i < numLevels)
? atoi(xpTableList[i].c_str())
: -1;
}
SafeWrite8(0x4AFB1B, static_cast<BYTE>(numLevels + 1));
}