From ee711d8f81c0b89f41e83adc5ac86681adeeb19f Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 2 Nov 2019 09:07:34 +0800 Subject: [PATCH] Added "get_inven_ap_cost" script function --- artifacts/scripting/headers/sfall.h | 1 + artifacts/scripting/sfall function notes.txt | 3 +++ sfall/Interface.cpp | 4 ++-- sfall/Inventory.cpp | 11 +++++------ sfall/Inventory.h | 4 +++- sfall/ScriptOps/MetaruleOp.hpp | 1 + sfall/ScriptOps/MiscOps.hpp | 6 +++++- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index de207351..0973d755 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -238,6 +238,7 @@ #define get_current_inven_size(obj) sfall_func1("get_current_inven_size", obj) #define get_cursor_mode sfall_func0("get_cursor_mode") #define get_flags(obj) sfall_func1("get_flags", obj) +#define get_inven_ap_cost sfall_func0("get_inven_ap_cost") #define get_map_enter_position sfall_func0("get_map_enter_position") #define get_metarule_table sfall_func0("get_metarule_table") #define get_object_data(obj, offset) sfall_func2("get_object_data", obj, offset) diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index 9d5889ea..481b8462 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -525,6 +525,9 @@ Some utility/math functions are available: > void sfall_func1("add_trait", int traitId) - adds the specified trait to the player +> int sfall_func0("get_inven_ap_cost") +- returns the current AP cost to access the inventory in combat + ------------------------ ------ MORE INFO ------- ------------------------ diff --git a/sfall/Interface.cpp b/sfall/Interface.cpp index ca0a9a54..0cabfcae 100644 --- a/sfall/Interface.cpp +++ b/sfall/Interface.cpp @@ -32,11 +32,11 @@ static void __declspec(naked) intface_redraw_items_hack0() { newArt: mov costAP, edx; cmp edx, 10; - jae skip; + je noShift; + ja skip; mov edx, 10; // width retn; skip: - je noShift; // ap == 10 sub edx, 10; imul edx, 5; // shift add ebx, edx; // add width shift to 'from' diff --git a/sfall/Inventory.cpp b/sfall/Inventory.cpp index 5ace1b9b..a31754b9 100644 --- a/sfall/Inventory.cpp +++ b/sfall/Inventory.cpp @@ -653,16 +653,15 @@ inline static void ApplyInvenApCostPatch() { onlyOnceAP = true; } -void _stdcall SetInvenApCost(int cost) { +void __fastcall SetInvenApCost(int cost) { invenApCost = cost; if (!onlyOnceAP) ApplyInvenApCostPatch(); } -// TODO: Make GetInvenApCost() function -/*long GetInvenApCost() { - long plevel = PerkLevel(*ptr_obj_dude, PERK_quick_pockets); - return invenApCost - (invenApQPReduction * plevel); -}*/ +long __stdcall GetInvenApCost() { + long perkLevel = PerkLevel(*ptr_obj_dude, PERK_quick_pockets); + return invenApCost - (invenApQPReduction * perkLevel); +} void InventoryReset() { invenApCost = invenApCostDef; diff --git a/sfall/Inventory.h b/sfall/Inventory.h index 425e4420..2add45ba 100644 --- a/sfall/Inventory.h +++ b/sfall/Inventory.h @@ -18,8 +18,10 @@ #pragma once -void _stdcall SetInvenApCost(int cost); +long __stdcall GetInvenApCost() ; +void __fastcall SetInvenApCost(int cost); DWORD __stdcall sf_item_total_size(TGameObj* critter); + void InventoryInit(); void InventoryReset(); void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey); diff --git a/sfall/ScriptOps/MetaruleOp.hpp b/sfall/ScriptOps/MetaruleOp.hpp index f7605295..09b48c4e 100644 --- a/sfall/ScriptOps/MetaruleOp.hpp +++ b/sfall/ScriptOps/MetaruleOp.hpp @@ -131,6 +131,7 @@ static const SfallMetarule metaruleArray[] = { {"get_current_inven_size", sf_get_current_inven_size, 1, 1}, {"get_cursor_mode", sf_get_cursor_mode, 0, 0}, {"get_flags", sf_get_flags, 1, 1}, + {"get_inven_ap_cost", sf_get_inven_ap_cost, 0, 0}, {"get_map_enter_position", sf_get_map_enter_position, 0, 0}, {"get_metarule_table", sf_get_metarule_table, 0, 0}, {"get_object_data", sf_get_object_data, 2, 2}, diff --git a/sfall/ScriptOps/MiscOps.hpp b/sfall/ScriptOps/MiscOps.hpp index 78eecd38..f352f515 100644 --- a/sfall/ScriptOps/MiscOps.hpp +++ b/sfall/ScriptOps/MiscOps.hpp @@ -1294,7 +1294,7 @@ static void __declspec(naked) set_inven_ap_cost() { __asm { push ecx; _GET_ARG_INT(end); - push eax; + mov ecx, eax; call SetInvenApCost; end: pop ecx; @@ -1302,6 +1302,10 @@ end: } } +static void sf_get_inven_ap_cost() { + opHandler.setReturn(GetInvenApCost()); +} + static void __declspec(naked) op_sneak_success() { _OP_BEGIN(ebp) __asm {