Skip to content

Commit

Permalink
Fixed issues related to negative weapon ammo
Browse files Browse the repository at this point in the history
(ref. alexbatalov/fallout2-ce#443)

Fixed freeze when reloading an overloaded weapon via the interface bar.
  • Loading branch information
NovaRain committed Jan 19, 2025
1 parent b7f7a03 commit b6b7ee0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions sfall/FalloutEngine/VariableOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
#define FO_VAR_main_window 0x5194F0
#define FO_VAR_main_window_buf 0x5194F4
#define FO_VAR_map_elevation 0x519578
#define FO_VAR_map_flags 0x631D7C
#define FO_VAR_map_global_vars 0x51956C
#define FO_VAR_map_name 0x631D58
#define FO_VAR_map_number 0x631D88
Expand Down
1 change: 1 addition & 0 deletions sfall/FalloutEngine/Variables_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ VAR_(main_ctd, fo::ComputeAttackResult)
VAR_(main_death_voiceover_done, DWORD)
VAR_(main_window, DWORD)
VAR_(map_elevation, DWORD)
VAR_(map_flags, DWORD)
VAR_(map_global_vars, long*) // array
VAR_(map_number, DWORD)
VAR_(master_db_handle, fo::PathNode*)
Expand Down
5 changes: 4 additions & 1 deletion sfall/Game/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ static __declspec(naked) void item_w_mp_cost_replacement() {

// Simplified implementation of item_w_curr_ammo_ engine function
long __fastcall Items::item_w_curr_ammo(fo::GameObject* item) {
if (item) return item->item.charges;
if (item) {
if (item->item.charges < 0) item->item.charges = 0; // fix negative ammo
return item->item.charges;
}
return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions sfall/Modules/BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4329,6 +4329,10 @@ void BugFixes::init() {
HookCall(0x43C9A0, perks_dialog_hook_tag);
HookCall(0x43C9E2, perks_dialog_hook_mutate);
HookCall(0x4329D1, editor_design_hook); // reset flags on exiting the character screen

// Fix to prevent the game from hanging when reloading a weapon overloaded with ammo via the interface bar
SafeWrite8(0x4787A2, 0x8D); // jz > jge (item_w_try_reload_)
SafeWrite8(0x45F5BD, 0x7E); // jz > jle (intface_toggle_item_state_)
}

}
2 changes: 2 additions & 0 deletions sfall/Modules/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,8 @@ static __declspec(naked) void intface_update_ammo_lights_hack() {
mov eax, 70; // 70 - full ammo bar
cmp edx, eax;
cmovg edx, eax;
cmp edx, ebx; // ebx = 0 (empty ammo bar)
cmovl edx, ebx;
mov eax, ammoBarXPos; // overwritten engine code
retn;
}
Expand Down

0 comments on commit b6b7ee0

Please sign in to comment.