diff --git a/src/common/mod.rs b/src/common/mod.rs index 41174db..f22b8a4 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -9,6 +9,7 @@ use crate::common::consts::*; use smash::app::{self, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; +use smash::lua2cpp::L2CFighterCommon; pub use crate::common::consts::MENU; pub static mut DEFAULTS_MENU: TrainingModpackMenu = crate::common::consts::DEFAULTS_MENU; @@ -242,3 +243,9 @@ pub unsafe fn get_fighter_distance() -> f32 { cpu_pos.z, ) } + +// From https://github.com/chrispo-git/ult-s/blob/cc1c3060ed83f6d33f39964e84f9c32c07a17bae/src/controls/util.rs#L106 +pub unsafe fn get_fighter_common_from_accessor(module_accessor: &mut app::BattleObjectModuleAccessor) -> &mut L2CFighterCommon { + let lua_module = *(module_accessor as *mut app::BattleObjectModuleAccessor as *mut u64).add(0x190 / 8); + &mut *(*((lua_module + 0x1D8) as *mut *mut L2CFighterCommon)) +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2741442..c6d03c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,6 @@ fn nro_main(nro: &NroInfo<'_>) { training::shield::handle_sub_guard_cont, training::directional_influence::handle_correct_damage_vector_common, training::tech::handle_change_status, - training::tech::mod_is_enable_passive, ); } } diff --git a/src/training/tech.rs b/src/training/tech.rs index 73c3441..6679a60 100644 --- a/src/training/tech.rs +++ b/src/training/tech.rs @@ -1,17 +1,15 @@ use crate::common::consts::*; use crate::common::*; use crate::training::{frame_counter, mash}; -use smash::app::sv_system; -use smash::app::{self, lua_bind::*}; +use smash::app::{self, BattleObjectModuleAccessor, sv_system, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; use smash::lib::L2CValue; -use smash::lua2cpp::{L2CFighterBase, L2CFighterCommon}; +use smash::lua2cpp::{L2CFighterBase}; static mut TECH_ROLL_DIRECTION: Direction = Direction::empty(); static mut MISS_TECH_ROLL_DIRECTION: Direction = Direction::empty(); static mut FRAME_COUNTER: usize = 0; -static mut CAN_TECH: bool = false; pub fn init() { unsafe { @@ -19,14 +17,9 @@ pub fn init() { } } -#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_is_enable_passive)] -pub unsafe fn mod_is_enable_passive(fighter: &mut L2CFighterCommon) -> L2CValue { - let ori = original!()(fighter); - let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); - if is_training_mode() && is_operation_cpu(module_accessor) { - CAN_TECH = ori.get_bool(); - } - ori +unsafe fn is_enable_passive(module_accessor: &mut BattleObjectModuleAccessor) -> bool { + let fighter = get_fighter_common_from_accessor(module_accessor); + fighter.is_enable_passive().get_bool() } #[skyline::hook(replace = smash::lua2cpp::L2CFighterBase_change_status)] @@ -95,7 +88,7 @@ unsafe fn handle_grnd_tech( module_accessor, *FIGHTER_STATUS_TRANSITION_TERM_ID_PASSIVE, ) && (second_prev_status != FIGHTER_STATUS_KIND_CATCHED_AIR_FALL_GANON) - && CAN_TECH; + && is_enable_passive(module_accessor); if !can_tech { return false; @@ -138,7 +131,7 @@ unsafe fn handle_wall_tech( let can_tech = WorkModule::is_enable_transition_term( module_accessor, *FIGHTER_STATUS_TRANSITION_TERM_ID_PASSIVE_WALL, - ) && CAN_TECH; + ) && is_enable_passive(module_accessor); if ![ *FIGHTER_STATUS_KIND_STOP_WALL, @@ -180,7 +173,7 @@ unsafe fn handle_ceil_tech( let can_tech = WorkModule::is_enable_transition_term( module_accessor, *FIGHTER_STATUS_TRANSITION_TERM_ID_PASSIVE_CEIL, - ) && CAN_TECH; + ) && is_enable_passive(module_accessor); if ![ *FIGHTER_STATUS_KIND_STOP_CEIL,