diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index 23262aeb..45093e77 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -292,7 +292,7 @@ Some utility/math functions are available: > float sqrt(float x) - square root of x -> float abs(float x) +> int/float abs(int/float x) - absolute (positive) value of x > float sin(float x) diff --git a/sfall/Modules/Scripting/Handlers/Utils.cpp b/sfall/Modules/Scripting/Handlers/Utils.cpp index cab9307c..d30e08b1 100644 --- a/sfall/Modules/Scripting/Handlers/Utils.cpp +++ b/sfall/Modules/Scripting/Handlers/Utils.cpp @@ -38,7 +38,11 @@ void sf_sqrt(OpcodeContext& ctx) { } void sf_abs(OpcodeContext& ctx) { - ctx.setReturn(abs(ctx.arg(0).asFloat())); + if (ctx.arg(0).isInt()) { + ctx.setReturn(abs(ctx.arg(0).asInt())); + } else { + ctx.setReturn(abs(ctx.arg(0).asFloat())); + } } void sf_sin(OpcodeContext& ctx) { diff --git a/sfall/Modules/Skills.cpp b/sfall/Modules/Skills.cpp index 8c9e8754..54f3e9f1 100644 --- a/sfall/Modules/Skills.cpp +++ b/sfall/Modules/Skills.cpp @@ -56,7 +56,7 @@ static SkillModifier baseSkillMax; static BYTE skillCosts[512 * fo::SKILL_count]; static DWORD basedOnPoints; -static double* multipliers; +static double* multipliers = nullptr; static std::vector pickpocketMods; static ChanceModifier basePickpocket; @@ -136,7 +136,7 @@ static int __fastcall GetStatBonus(fo::GameObject* critter, const fo::SkillInfo* } result += points * info->skillPointMulti; result += info->base; - return (int)result; + return static_cast(result); } //On input, ebx/edx contains the skill id, ecx contains the critter, edi contains a SkillInfo*, ebp contains the number of skill points @@ -145,9 +145,9 @@ static const DWORD StatBonusHookRet = 0x4AA5D6; static void __declspec(naked) skill_level_hack_bonus() { __asm { push ecx; - push ebp; - push ebx; - mov edx, edi; + push ebp; // points + push ebx; // skill + mov edx, edi; // info call GetStatBonus; // ecx - critter mov esi, eax; pop ecx; @@ -253,13 +253,14 @@ void Skills::init() { SafeWrite8(0x4ABC67, 0x89); // mov [esp + 0x54], eax SafeWrite32(0x4ABC6B, 0x90909090); - char buf[512], key[16], file[64]; + char buf[512], key[16]; auto skillsFile = GetConfigString("Misc", "SkillsFile", ""); - if (skillsFile.size() > 0) { + if (!skillsFile.empty()) { fo::SkillInfo *skills = fo::var::skill_data; - sprintf(file, ".\\%s", skillsFile.c_str()); - multipliers = new double[7 * fo::SKILL_count]; - memset(multipliers, 0, 7 * fo::SKILL_count * sizeof(double)); + + skillsFile = ".\\" + skillsFile; + const char* file = skillsFile.c_str(); + multipliers = new double[7 * fo::SKILL_count](); for (int i = 0; i < fo::SKILL_count; i++) { sprintf(key, "Skill%d", i); @@ -276,7 +277,8 @@ void Skills::init() { case 'i': multipliers[i * 7 + 4] = m; break; case 'a': multipliers[i * 7 + 5] = m; break; case 'l': multipliers[i * 7 + 6] = m; break; - default: continue; + default: + dlogr("Warning : Invalid character for SPECIAL stats in the skills file.", DL_INIT); } } tok = strtok(0, "|");