Fixed duplicate sound in the "Move Items" and "Set Timer" windows

* happens when clicking the "Done" button.

Fixed crash when a critter with a powered melee/unarmed weapon runs out
of ammo and there is ammo nearby.

Minor code optimization to Interface.cpp, use spare ecx register instead
of the stack for eax value.
This commit is contained in:
NovaRain
2025-05-03 21:38:33 +08:00
parent b2ccf26bd5
commit 8622917e12
2 changed files with 39 additions and 7 deletions
+33 -1
View File
@@ -3559,6 +3559,32 @@ static __declspec(naked) void editor_design_hook() {
} }
} }
static __declspec(naked) void do_move_timer_hook() {
__asm {
cmp dword ptr ds:[FO_VAR_mouse_buttons], 0; // mouse clicked?
jne skip;
jmp fo::funcoffs::gsound_play_sfx_file_;
skip:
retn;
}
}
// Add a null pointer check to item_w_can_reload_ engine function
static __declspec(naked) void item_w_can_reload_hack() {
static const DWORD item_w_can_reload_Ret = 0x47890F;
__asm {
test eax, eax; // weapon
jz skip;
// overwritten engine code
mov ecx, edx;
mov edx, [eax + protoId];
retn;
skip:
add esp, 4;
jmp item_w_can_reload_Ret;
}
}
void BugFixes::init() { void BugFixes::init() {
#ifndef NDEBUG #ifndef NDEBUG
LoadGameHook::OnBeforeGameClose() += PrintAddrList; LoadGameHook::OnBeforeGameClose() += PrintAddrList;
@@ -3625,7 +3651,7 @@ void BugFixes::init() {
SafeWrite32(0x497E8E, 0x90909090); SafeWrite32(0x497E8E, 0x90909090);
// Fix for extra hidden buttons below the location list in the Status section // Fix for extra hidden buttons below the location list in the Status section
MakeCall(0x497D52, PipStatus_hack, 5); MakeCall(0x497D52, PipStatus_hack, 5);
// Fix for double click sound when selecting a location in the Status section // Fix for the duplicate click sound when selecting a location in the Status section
BlockCall(0x497F52); // block gsound_play_sfx_file_ (PipStatus_) BlockCall(0x497F52); // block gsound_play_sfx_file_ (PipStatus_)
// Fix for "Too Many Items" bug // Fix for "Too Many Items" bug
@@ -4406,6 +4432,12 @@ void BugFixes::init() {
// Fix to prevent out-of-bounds selection in the file list when loading a character file // Fix to prevent out-of-bounds selection in the file list when loading a character file
SafeWriteBatch<BYTE>(0x7C, {0x41E690, 0x41E69C}); // jle > jl (file_dialog_) SafeWriteBatch<BYTE>(0x7C, {0x41E690, 0x41E69C}); // jle > jl (file_dialog_)
// Fix for the duplicate click sound for the "Done" button in the "Move Items" and "Set Timer" windows
HookCall(0x476914, do_move_timer_hook);
// Fix crash when a critter with a powered melee/unarmed weapon runs out of ammo and there is ammo nearby
MakeCall(0x47887B, item_w_can_reload_hack);
} }
} }
+6 -6
View File
@@ -841,21 +841,21 @@ static __declspec(naked) void wmInterfaceInit_hook() {
__asm { __asm {
pop retAddr; pop retAddr;
call fo::funcoffs::win_register_button_; call fo::funcoffs::win_register_button_;
push eax; mov ecx, eax; // save button ID
mov ebx, fo::funcoffs::gsound_red_butt_release_; mov ebx, fo::funcoffs::gsound_red_butt_release_;
mov edx, fo::funcoffs::gsound_red_butt_press_; mov edx, fo::funcoffs::gsound_red_butt_press_;
call fo::funcoffs::win_register_button_sound_func_; call fo::funcoffs::win_register_button_sound_func_;
pop eax; mov eax, ecx; // restore
jmp retAddr; jmp retAddr;
} }
} }
static __declspec(naked) void wmWorldMap_hook() { static __declspec(naked) void wmWorldMap_hook() {
__asm { __asm {
push eax; mov ecx, eax; // save xpos
mov eax, 0x503E14; // 'ib1p1xx1' mov eax, 0x503E14; // 'ib1p1xx1'
call fo::funcoffs::gsound_play_sfx_file_; call fo::funcoffs::gsound_play_sfx_file_;
pop eax; mov eax, ecx; // restore
jmp fo::funcoffs::wmPartyInitWalking_; jmp fo::funcoffs::wmPartyInitWalking_;
} }
} }
@@ -872,11 +872,11 @@ static __declspec(naked) void wmDrawCursorStopped_hack_hotspot() {
static __declspec(naked) void wmTownMapInit_hack() { static __declspec(naked) void wmTownMapInit_hack() {
__asm { __asm {
mov dword ptr ds:[edi + 0x672DD8], eax; // _wmTownMapButtonId mov dword ptr ds:[edi + 0x672DD8], eax; // _wmTownMapButtonId
push eax; mov ecx, eax; // save button ID
mov edx, fo::funcoffs::gsound_med_butt_press_; mov edx, fo::funcoffs::gsound_med_butt_press_;
xor ebx, ebx; // no button release sfx xor ebx, ebx; // no button release sfx
call fo::funcoffs::win_register_button_sound_func_; call fo::funcoffs::win_register_button_sound_func_;
pop eax; mov eax, ecx; // restore
retn; retn;
} }
} }