From d1935686786da4439b4bfde2f6e1c4019b1f9372 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 19 Nov 2024 21:54:26 +0800 Subject: [PATCH] Tweaked how XPTable data was loaded * to align hook functions with the engine functions they replaced. --- sfall/FalloutEngine/FunctionOffsets_def.h | 1 + sfall/Modules/BugFixes.cpp | 2 +- sfall/Modules/Stats.cpp | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sfall/FalloutEngine/FunctionOffsets_def.h b/sfall/FalloutEngine/FunctionOffsets_def.h index ad814611..1f392d38 100644 --- a/sfall/FalloutEngine/FunctionOffsets_def.h +++ b/sfall/FalloutEngine/FunctionOffsets_def.h @@ -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) diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 843da102..38d77b3f 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -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 diff --git a/sfall/Modules/Stats.cpp b/sfall/Modules/Stats.cpp index b21f09e1..936ca083 100644 --- a/sfall/Modules/Stats.cpp +++ b/sfall/Modules/Stats.cpp @@ -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(numLevels + 1)); }