Skip to content

Commit

Permalink
Minor edits to ItemCounterAutoCaps
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaRain committed May 23, 2024
1 parent 08a5f86 commit 4891613
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
3 changes: 2 additions & 1 deletion artifacts/ddraw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ ReloadReserve=-1
;Set to 1 to change the counter in the 'Move Items' window to start with maximum number, except in the barter screen
ItemCounterDefaultMax=0

;Set to 1 to enable caps auto-balancing: when dragging caps between tables in the barter screen, 'Move Items' window will be shown with correct number pre-filled that balances the tables
;Set to 1 to enable money/caps auto-balancing in the barter screen
;When moving money/caps to or from the table, the 'Move Items' window will be pre-filled with the correct balancing amount
ItemCounterAutoCaps=0

;Set to 1 to leave the music playing in dialogue with talking heads
Expand Down
1 change: 0 additions & 1 deletion sfall/FalloutEngine/Fallout2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

#include "Enums.h"
#include "GamePids.h"
#include "FunctionOffsets.h"
#include "Structs.h"
#include "EngineUtils.h"
Expand Down
9 changes: 3 additions & 6 deletions sfall/Modules/HookScripts/MiscHs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace sfall
{

static DWORD lastTableCostPC; // keep last cost for pc
static DWORD lastTableCostNPC;

Expand Down Expand Up @@ -55,11 +55,6 @@ static DWORD __fastcall BarterPriceHook_Script(fo::GameObject* source, fo::GameO
cost = rets[0]; // new cost for npc
}
}
if (isPCHook) {
lastTableCostPC = cost;
} else {
lastTableCostNPC = cost;
}
EndHook();
return cost;
}
Expand All @@ -74,6 +69,7 @@ static void __declspec(naked) BarterPriceHook() {
call BarterPriceHook_Script; // edx - target
pop ecx;
pop edx;
mov lastTableCostNPC, eax;
retn;
}
}
Expand All @@ -89,6 +85,7 @@ static void __declspec(naked) PC_BarterPriceHook() {
call BarterPriceHook_Script;
pop ecx;
pop edx;
mov lastTableCostPC, eax;
retn;
}
}
Expand Down
29 changes: 14 additions & 15 deletions sfall/Modules/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,17 +621,16 @@ static void __declspec(naked) do_move_timer_hook() {

static long CalculateSuggestedMoveCount(fo::GameObject* item, long maxQuantity, bool fromPlayer, bool fromInventory) {
// This is an exact copy of logic from https://github.com/alexbatalov/fallout2-ce/pull/311
if (item->protoId == fo::PID_BOTTLE_CAPS && !fo::var::dialog_target_is_party) {
// Calculate change money automatically
long totalCostPlayer;
long totalCostNpc;
if (item->protoId == fo::PID_BOTTLE_CAPS && !fo::var::dialog_target_is_party) {
// Calculate change money automatically
long totalCostPlayer, totalCostNpc;
BarterPriceHook_GetLastCosts(totalCostPlayer, totalCostNpc);
// Actor's balance: negative - the actor must add money to balance the tables and vice versa
long balance = fromPlayer ? totalCostPlayer - totalCostNpc : totalCostNpc - totalCostPlayer;
if ((balance < 0 && fromInventory) || (balance > 0 && !fromInventory)) {
return min(std::abs(balance), maxQuantity);
}
}
// Actor's balance: negative - the actor must add money to balance the tables and vice versa
long balance = fromPlayer ? totalCostPlayer - totalCostNpc : totalCostNpc - totalCostPlayer;
if ((balance < 0 && fromInventory) || (balance > 0 && !fromInventory)) {
return min(std::abs(balance), maxQuantity);
}
}
return 1;
}

Expand Down Expand Up @@ -675,11 +674,11 @@ static void __declspec(naked) do_move_timer_hack() {
__asm {
push ecx;
push ebp; // max
mov edx, dword ptr[esp + 32]; // return address
mov ecx, dword ptr[esp + 20]; // item, potentially
mov edx, dword ptr [esp + 32]; // return address
mov ecx, dword ptr [esp + 20]; // item, potentially
call CalculateDefaultMoveCount;
mov ebx, eax;
pop ecx;
pop ecx;
retn;
}
}
Expand Down Expand Up @@ -811,8 +810,8 @@ void Inventory::init() {
skipFromContainer = IniReader::GetConfigInt("Input", "FastMoveFromContainer", 0);
}

itemCounterDefaultMax = IniReader::GetConfigInt("Misc", "ItemCounterDefaultMax", 0);
itemCounterAutoCaps = IniReader::GetConfigInt("Misc", "ItemCounterAutoCaps", 0);
itemCounterDefaultMax = (IniReader::GetConfigInt("Misc", "ItemCounterDefaultMax", 0) != 0);
itemCounterAutoCaps = (IniReader::GetConfigInt("Misc", "ItemCounterAutoCaps", 0) != 0);
if (itemCounterDefaultMax || itemCounterAutoCaps) {
MakeCall(0x4768A3, do_move_timer_hack);
}
Expand Down

0 comments on commit 4891613

Please sign in to comment.