Skip to content

Commit

Permalink
Tweaked how XPTable data was loaded
Browse files Browse the repository at this point in the history
* to align hook functions with the engine functions they replaced.
  • Loading branch information
NovaRain committed Nov 19, 2024
1 parent a585d93 commit d193568
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions sfall/FalloutEngine/FunctionOffsets_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sfall/Modules/BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions sfall/Modules/Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ static __declspec(naked) void stat_set_base_hack_check() {
}
}

// 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;
Expand All @@ -123,9 +124,11 @@ static __declspec(naked) void GetLevelXPHook() {
}
}

// Returns experience to reach the next level
static __declspec(naked) void GetNextLevelXPHook() {
__asm {
mov eax, ds:[FO_VAR_Level_pc];
inc eax;
jmp GetLevelXPHook;
}
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit d193568

Please sign in to comment.