Fixed issues related to negative weapon ammo

(ref. alexbatalov/fallout2-ce#443)

Fixed freeze when reloading an overloaded weapon via the interface bar.
This commit is contained in:
NovaRain
2025-01-19 15:07:35 +08:00
parent b7f7a0362f
commit b6b7ee04f2
5 changed files with 12 additions and 1 deletions
+1
View File
@@ -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
+1
View File
@@ -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*)
+4 -1
View File
@@ -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;
}
+4
View File
@@ -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
View File
@@ -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;
}