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:10:55 +08:00
parent 6f9d1fc1f8
commit d654233614
5 changed files with 12 additions and 1 deletions
+1
View File
@@ -121,6 +121,7 @@ PTR_(main_ctd, fo::ComputeAttackResult)
PTR_(main_death_voiceover_done, DWORD)
PTR_(main_window, DWORD)
PTR_(map_elevation, DWORD)
PTR_(map_flags, DWORD)
PTR_(map_global_vars, long*) // array
PTR_(map_number, DWORD)
PTR_(master_db_handle, fo::PathNode*)
+1
View File
@@ -183,6 +183,7 @@
#define FO_VAR_main_death_voiceover_done 0x614838
#define FO_VAR_main_window 0x5194F0
#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
+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
@@ -4332,6 +4332,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
@@ -944,6 +944,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;
}