diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index 1d7cd3e..bf50b3a 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -330,6 +330,6 @@ pub unsafe fn handle_set_rebound( } pub fn hitbox_visualization() { - println!("Applying hitbox visualization mods."); + println!("[Training Modpack] Applying hitbox visualization mods."); skyline::install_hooks!(handle_attack, handle_catch, handle_set_rebound); } diff --git a/src/lib.rs b/src/lib.rs index 140310b..6021ffc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ fn nro_main(nro: &NroInfo<'_>) { skyline::install_hooks!( training::shield::handle_sub_guard_cont, training::directional_influence::handle_correct_damage_vector_common, + training::tech::handle_change_status ); } _ => (), diff --git a/src/training/mod.rs b/src/training/mod.rs index baf3979..c33457a 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -4,11 +4,12 @@ use skyline::nn::ro::LookupSymbol; use smash::app::{self, lua_bind::*}; pub mod directional_influence; +pub mod shield; +pub mod tech; + mod ledge; mod mash; mod save_states; -pub mod shield; -mod tech; #[skyline::hook(replace = WorkModule::get_param_float)] pub unsafe fn handle_get_param_float( @@ -112,36 +113,6 @@ pub unsafe fn handle_check_button_off( .unwrap_or_else(|| original!()(module_accessor, button)) } -#[skyline::hook(replace = StatusModule::init_settings)] -pub unsafe fn handle_init_settings( - module_accessor: &mut app::BattleObjectModuleAccessor, - situation_kind: i32, - unk1: i32, - unk2: u32, - ground_cliff_check_kind: i32, - unk3: bool, - unk4: i32, - unk5: i32, - unk6: i32, - unk7: i32, -) { - let status_kind = StatusModule::status_kind(module_accessor); - tech::init_settings(module_accessor, status_kind).unwrap_or_else(|| { - original!()( - module_accessor, - situation_kind, - unk1, - unk2, - ground_cliff_check_kind, - unk3, - unk4, - unk5, - unk6, - unk7, - ) - }) -} - #[skyline::hook(replace = MotionModule::change_motion)] pub unsafe fn handle_change_motion( module_accessor: &mut app::BattleObjectModuleAccessor, @@ -153,18 +124,18 @@ pub unsafe fn handle_change_motion( unk5: bool, unk6: bool, ) -> u64 { - tech::change_motion(module_accessor, motion_kind).unwrap_or_else(|| { - original!()( - module_accessor, - motion_kind, - unk1, - unk2, - unk3, - unk4, - unk5, - unk6, - ) - }) + let motion_kind = tech::change_motion(module_accessor, motion_kind).unwrap_or(motion_kind); + + original!()( + module_accessor, + motion_kind, + unk1, + unk2, + unk3, + unk4, + unk5, + unk6, + ) } pub fn training_mods() { @@ -190,7 +161,6 @@ pub fn training_mods() { handle_get_attack_air_kind, // Tech options - handle_init_settings, handle_change_motion, ); diff --git a/src/training/save_states.rs b/src/training/save_states.rs index 4f43f66..e576174 100644 --- a/src/training/save_states.rs +++ b/src/training/save_states.rs @@ -69,8 +69,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) *save_state = PosMove; let left_right = - (*save_state_x > 0.0) as i32 as f32 - (*save_state_x < 0.0) as i32 as f32; - let y_pos = 0.0; + (PostureModule::pos_x(module_accessor) > 0.0) as i32 as f32 - (PostureModule::pos_x(module_accessor) < 0.0) as i32 as f32; + let y_pos = 20.0; let pos = Vector3f { x: left_right * 50.0, diff --git a/src/training/tech.rs b/src/training/tech.rs index dbcd753..eef440a 100644 --- a/src/training/tech.rs +++ b/src/training/tech.rs @@ -3,13 +3,18 @@ use crate::common::*; use smash::app::{self, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; +use smash::app::sv_system; +use smash::lib::L2CValue; +use smash::lua2cpp::L2CFighterBase; -pub unsafe fn init_settings( - module_accessor: &mut app::BattleObjectModuleAccessor, - status_kind: i32, -) -> Option<()> { +#[skyline::hook(replace = smash::lua2cpp::L2CFighterBase_change_status)] +pub unsafe fn handle_change_status(fighter: &mut L2CFighterBase, status_kind: L2CValue, unk: L2CValue) -> L2CValue { + let mut status_kind = status_kind; + let mut unk = unk; + let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); if is_training_mode() && is_operation_cpu(module_accessor) { - if status_kind == FIGHTER_STATUS_KIND_DOWN { + let status_kind_int = status_kind.try_get_int().unwrap_or(*FIGHTER_STATUS_KIND_WAIT as u64) as i32; + if status_kind_int == FIGHTER_STATUS_KIND_DOWN { match MENU.tech_state { TechOption::Random => { let random_statuses = vec![ @@ -22,36 +27,24 @@ pub unsafe fn init_settings( app::sv_math::rand(hash40("fighter"), random_statuses.len() as i32) as usize; if random_statuses[random_status_index] != FIGHTER_STATUS_KIND_DOWN { - StatusModule::change_status_request_from_script( - module_accessor, - random_statuses[random_status_index], - true, - ); - return Some(()); + status_kind = L2CValue::new_int(random_statuses[random_status_index] as u64); + unk = L2CValue::new_bool(true); } } TechOption::InPlace => { - StatusModule::change_status_request_from_script( - module_accessor, - *FIGHTER_STATUS_KIND_PASSIVE, - true, - ); - return Some(()); + status_kind = L2CValue::new_int(*FIGHTER_STATUS_KIND_PASSIVE as u64); + unk = L2CValue::new_bool(true); } TechOption::Roll => { - StatusModule::change_status_request_from_script( - module_accessor, - *FIGHTER_STATUS_KIND_PASSIVE_FB, - true, - ); - return Some(()); + status_kind = L2CValue::new_int(*FIGHTER_STATUS_KIND_PASSIVE_FB as u64); + unk = L2CValue::new_bool(true); } _ => (), } } } - None + original!()(fighter, status_kind, unk) } pub unsafe fn should_perform_defensive_option( @@ -109,7 +102,7 @@ pub unsafe fn get_command_flag_cat( StatusModule::change_status_request_from_script( module_accessor, random_statuses[random_status_index], - true, + false, ); } else if should_perform_defensive_option(module_accessor, prev_status, status) { perform_defensive_option(module_accessor, flag);