From e3af4f5754db822e33c10b2f1b04856bf1849112 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 18 Apr 2020 10:37:56 +0800 Subject: [PATCH] Fixed ReloadWeaponKey for using any non-weapon item (#84) --- artifacts/ddraw.ini | 4 +-- sfall/FalloutEngine.cpp | 56 ++++++++++++++++++++++++++--------------- sfall/FalloutEngine.h | 18 +++++++------ sfall/HookScripts.cpp | 2 +- sfall/Inventory.cpp | 53 ++++++++++++++++---------------------- sfall/Inventory.h | 2 +- 6 files changed, 72 insertions(+), 63 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 58480c31..d4933d27 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,5 +1,5 @@ ;sfall configuration settings -;v3.8.24 +;v3.8.25 [Main] ;Change to 1 if you want to use command line args to tell sfall to use another ini file. @@ -185,7 +185,7 @@ HighlightCorpses=1 ;64 - purple OutlineColor=16 -;A key to press to reload your currently equipped weapon +;A key to press to reload your currently equipped weapon or use the active item ;Set to 0 if you don't want a reload key, or a DX scancode otherwise ReloadWeaponKey=0 diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index ed96fd2c..ad708741 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -851,14 +851,6 @@ long __stdcall ItemGetType(TGameObj* item) { WRAP_WATCOM_CALL1(item_get_type_, item) } -long __stdcall ItemSize(TGameObj* item) { - WRAP_WATCOM_CALL1(item_size_, item) -} - -long __stdcall ItemWeight(TGameObj* item) { - WRAP_WATCOM_CALL1(item_weight_, item) -} - long __stdcall IsPartyMember(TGameObj* obj) { WRAP_WATCOM_CALL1(isPartyMember_, obj) } @@ -1484,6 +1476,26 @@ long __stdcall TileDir(long scrTile, long dstTile) { WRAP_WATCOM_CALL2(tile_dir_, scrTile, dstTile) } +long __stdcall ItemCCurrSize(TGameObj* critter) { + WRAP_WATCOM_CALL1(item_c_curr_size_, critter) +} + +long __stdcall ItemCapsTotal(TGameObj* object) { + WRAP_WATCOM_CALL1(item_caps_total_, object) +} + +long __stdcall ItemSize(TGameObj* item) { + WRAP_WATCOM_CALL1(item_size_, item) +} + +long __stdcall ItemTotalCost(TGameObj* object) { + WRAP_WATCOM_CALL1(item_total_cost_, object) +} + +long __stdcall ItemTotalWeight(TGameObj* object) { + WRAP_WATCOM_CALL1(item_total_weight_, object) +} + long __stdcall ItemWAnimWeap(TGameObj* item, DWORD hitMode) { WRAP_WATCOM_CALL2(item_w_anim_weap_, item, hitMode) } @@ -1496,6 +1508,10 @@ long __stdcall ItemWCurrAmmo(TGameObj* item) { WRAP_WATCOM_CALL1(item_w_curr_ammo_, item) } +long __stdcall ItemWMaxAmmo(TGameObj* item) { + WRAP_WATCOM_CALL1(item_w_max_ammo_, item) +} + long __stdcall ItemWReload(TGameObj* weapon, TGameObj* ammo) { WRAP_WATCOM_CALL2(item_w_reload_, weapon, ammo) } @@ -1504,26 +1520,22 @@ long __stdcall ItemWRounds(TGameObj* item) { WRAP_WATCOM_CALL1(item_w_rounds_, item) } +long __stdcall ItemWeight(TGameObj* item) { + WRAP_WATCOM_CALL1(item_weight_, item) +} + long __stdcall BarterComputeValue(TGameObj* source, TGameObj* target) { WRAP_WATCOM_CALL2(barter_compute_value_, source, target) } -long __stdcall ItemCapsTotal(TGameObj* object) { - WRAP_WATCOM_CALL1(item_caps_total_, object) -} - -long __stdcall ItemTotalCost(TGameObj* object) { - WRAP_WATCOM_CALL1(item_total_cost_, object) -} - -long __stdcall ItemTotalWeight(TGameObj* object) { - WRAP_WATCOM_CALL1(item_total_weight_, object) -} - void __fastcall CorrectFidForRemovedItemFunc(TGameObj* critter, TGameObj* item, long slotFlag) { WRAP_WATCOM_FCALL3(correctFidForRemovedItem_, critter, item, slotFlag) } +void __stdcall IntfaceToggleItemState() { + WRAP_WATCOM_CALL0(intface_toggle_item_state_) +} + void __stdcall IntfaceUpdateAc(long animate) { WRAP_WATCOM_CALL1(intface_update_ac_, animate) } @@ -1532,6 +1544,10 @@ void __stdcall IntfaceUpdateMovePoints(long ap, long freeAP) { WRAP_WATCOM_CALL2(intface_update_move_points_, ap, freeAP) } +void __stdcall IntfaceUseItem() { + WRAP_WATCOM_CALL0(intface_use_item_) +} + void __fastcall IntfaceUpdateItems(long animate, long modeLeft, long modeRight) { WRAP_WATCOM_FCALL3(intface_update_items_, animate, modeLeft, modeRight) } diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index ab5a6940..94893f50 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -1061,8 +1061,6 @@ void DevPrintf(...); #endif long __stdcall ItemGetType(TGameObj* item); -long __stdcall ItemSize(TGameObj* item); -long __stdcall ItemWeight(TGameObj* item); long __stdcall IsPartyMember(TGameObj* obj); long __stdcall PartyMemberGetCurrentLevel(TGameObj* obj); @@ -1318,25 +1316,31 @@ long __stdcall TileDist(long scrTile, long dstTile); long __stdcall TileDir(long scrTile, long dstTile); -// for the backported AmmoCostHook from 4.x +long __stdcall ItemCCurrSize(TGameObj* critter); +long __stdcall ItemCapsTotal(TGameObj* object); +long __stdcall ItemSize(TGameObj* item); +long __stdcall ItemTotalCost(TGameObj* object); +long __stdcall ItemTotalWeight(TGameObj* object); long __stdcall ItemWAnimWeap(TGameObj* item, DWORD hitMode); long __stdcall ItemWComputeAmmoCost(TGameObj* item, DWORD* rounds); long __stdcall ItemWCurrAmmo(TGameObj* item); +long __stdcall ItemWMaxAmmo(TGameObj* item); long __stdcall ItemWReload(TGameObj* weapon, TGameObj* ammo); long __stdcall ItemWRounds(TGameObj* item); +long __stdcall ItemWeight(TGameObj* item); -// for the backported BarterPriceHook from 4.x long __stdcall BarterComputeValue(TGameObj* source, TGameObj* target); -long __stdcall ItemCapsTotal(TGameObj* object); -long __stdcall ItemTotalCost(TGameObj* object); -long __stdcall ItemTotalWeight(TGameObj* object); void __fastcall CorrectFidForRemovedItemFunc(TGameObj* critter, TGameObj* item, long slotFlag); +void __stdcall IntfaceToggleItemState(); + void __stdcall IntfaceUpdateAc(long animate); void __stdcall IntfaceUpdateMovePoints(long ap, long freeAP); +void __stdcall IntfaceUseItem(); + void __fastcall IntfaceUpdateItems(long animate, long modeLeft, long modeRight); TGameObj* __fastcall InvenFindType(TGameObj* critter, long itemType, DWORD* buf); diff --git a/sfall/HookScripts.cpp b/sfall/HookScripts.cpp index f856b72f..8393fe3b 100644 --- a/sfall/HookScripts.cpp +++ b/sfall/HookScripts.cpp @@ -867,7 +867,7 @@ DWORD _stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey) { args[2] = vKey; RunHookScript(HOOK_KEYPRESS); if (cRet != 0) dxKey = result = rets[0]; - InventoryKeyPressedHook(dxKey, pressed, vKey); + InventoryKeyPressedHook(dxKey, pressed); EndHook(); return result; } diff --git a/sfall/Inventory.cpp b/sfall/Inventory.cpp index fb3b0082..6af3781f 100644 --- a/sfall/Inventory.cpp +++ b/sfall/Inventory.cpp @@ -31,42 +31,36 @@ static DWORD reloadWeaponKey = 0; static DWORD itemFastMoveKey = 0; static DWORD skipFromContainer = 0; -DWORD& GetActiveItemMode() { - return ptr_itemButtonItems[(*ptr_itemCurrentItem * 6) + 4]; +long& GetActiveItemMode() { + return (long&)ptr_itemButtonItems[(*ptr_itemCurrentItem * 6) + 4]; } TGameObj* GetActiveItem() { return (TGameObj*)ptr_itemButtonItems[*ptr_itemCurrentItem * 6]; } -void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey) { +void InventoryKeyPressedHook(DWORD dxKey, bool pressed) { if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsGameLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) { - DWORD maxAmmo, curAmmo; TGameObj* item = GetActiveItem(); - __asm { - mov eax, item; - call item_w_max_ammo_; - mov maxAmmo, eax; - mov eax, item; - call item_w_curr_ammo_; - mov curAmmo, eax; - } - if (maxAmmo != curAmmo) { - DWORD ¤tMode = GetActiveItemMode(); - DWORD previusMode = currentMode; - currentMode = 5; // reload mode - __asm { - call intface_use_item_; - } - if (previusMode != 5) { - // return to previous active item mode (if it wasn't "reload") - currentMode = previusMode - 1; - if (currentMode < 0) - currentMode = 4; - __asm { - call intface_toggle_item_state_; + if (!item) return; + + if (ItemGetType(item) == item_type_weapon) { + long maxAmmo = ItemWMaxAmmo(item); + long curAmmo = ItemWCurrAmmo(item); + if (maxAmmo != curAmmo) { + long ¤tMode = GetActiveItemMode(); + long previusMode = currentMode; + currentMode = 5; // reload mode + IntfaceUseItem(); + if (previusMode != 5) { + // return to previous active item mode (if it wasn't "reload") + currentMode = previusMode - 1; + if (currentMode < 0) currentMode = 4; + IntfaceToggleItemState(); } } + } else { + IntfaceUseItem(); } } } @@ -74,12 +68,7 @@ void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey) { ///////////////////////////////////////////////////////////////// DWORD __stdcall sf_item_total_size(TGameObj* critter) { - int totalSize; - __asm { - mov eax, critter; - call item_c_curr_size_; - mov totalSize, eax; - } + int totalSize = ItemCCurrSize(critter); if (((critter->artFid >> 24) & 0x0F) == OBJ_TYPE_CRITTER) { TGameObj* item = InvenRightHand(critter); diff --git a/sfall/Inventory.h b/sfall/Inventory.h index d51efee4..09ee6441 100644 --- a/sfall/Inventory.h +++ b/sfall/Inventory.h @@ -24,4 +24,4 @@ DWORD __stdcall sf_item_total_size(TGameObj* critter); void InventoryInit(); void InventoryReset(); -void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey); +void InventoryKeyPressedHook(DWORD dxKey, bool pressed);