From 13c87133bf8780e6860f417718e7fec3170a94bc Mon Sep 17 00:00:00 2001 From: GradualSyrup <68757075+GradualSyrup@users.noreply.github.com> Date: Sun, 20 Aug 2023 14:56:31 -0500 Subject: [PATCH] Fix PLAY_SE hook crash (#602) --- src/training/buff.rs | 4 ++++ src/training/mod.rs | 26 +++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/training/buff.rs b/src/training/buff.rs index 9ebbc3e..6a81aeb 100644 --- a/src/training/buff.rs +++ b/src/training/buff.rs @@ -43,6 +43,10 @@ pub unsafe fn is_buffing(module_accessor: &mut app::BattleObjectModuleAccessor) IS_BUFFING_PLAYER } +pub unsafe fn is_buffing_any() -> bool { + IS_BUFFING_CPU || IS_BUFFING_PLAYER +} + pub unsafe fn set_buff_rem(module_accessor: &mut app::BattleObjectModuleAccessor, new_value: i32) { if is_operation_cpu(module_accessor) { BUFF_REMAINING_CPU = new_value; diff --git a/src/training/mod.rs b/src/training/mod.rs index 7f9eb24..d6d9900 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -476,7 +476,7 @@ static PLAY_SE_OFFSET: usize = 0x04cf6a0; // fighters don't use the symbol and go straight through their vtable to this function #[skyline::hook(offset = PLAY_SE_OFFSET)] pub unsafe fn handle_fighter_play_se( - module_accessor: &mut app::BattleObjectModuleAccessor, + sound_module: u64, // pointer to fighter's SoundModule my_hash: Hash40, bool1: bool, bool2: bool, @@ -485,22 +485,14 @@ pub unsafe fn handle_fighter_play_se( se_type: enSEType, ) -> u64 { if !is_training_mode() { - return original!()( - module_accessor, - my_hash, - bool1, - bool2, - bool3, - bool4, - se_type, - ); + return original!()(sound_module, my_hash, bool1, bool2, bool3, bool4, se_type); } // Supress Buff Sound Effects while buffing - if buff::is_buffing(module_accessor) { + if buff::is_buffing_any() { let silent_hash = Hash40::new("se_silent"); return original!()( - module_accessor, + sound_module, silent_hash, bool1, bool2, @@ -509,15 +501,7 @@ pub unsafe fn handle_fighter_play_se( se_type, ); } - original!()( - module_accessor, - my_hash, - bool1, - bool2, - bool3, - bool4, - se_type, - ) + original!()(sound_module, my_hash, bool1, bool2, bool3, bool4, se_type) } static FOLLOW_REQ_OFFSET: usize = 0x044f860;