diff --git a/src/common/consts.rs b/src/common/consts.rs index 854f9e1..805f43a 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -54,8 +54,6 @@ impl From for Direction { } } -//pub static FIGHTER_FACING_LEFT: f32 = 1.0; -pub static FIGHTER_FACING_RIGHT: f32 = -1.0; pub static ANGLE_NONE: f64 = -69.0; pub fn direction_to_angle(direction: Direction) -> f64 { match direction { diff --git a/src/common/mod.rs b/src/common/mod.rs index 88fce7b..0f021c6 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -41,6 +41,15 @@ pub fn get_category(module_accessor: &mut app::BattleObjectModuleAccessor) -> i3 return (module_accessor.info >> 28) as u8 as i32; } +pub unsafe fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModuleAccessor { + let entry_id_int = fighter_id as i32; + let entry_id = app::FighterEntryID(entry_id_int); + let mgr = *(FIGHTER_MANAGER_ADDR as *mut *mut app::FighterManager); + let fighter_entry = FighterManager::get_fighter_entry(mgr, entry_id) as *mut app::FighterEntry; + let current_fighter_id = FighterEntry::current_fighter_id(fighter_entry); + app::sv_battle_object::module_accessor(current_fighter_id as u32) +} + pub unsafe fn is_fighter(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool { get_category(module_accessor) == BATTLE_OBJECT_CATEGORY_FIGHTER } diff --git a/src/training/combo.rs b/src/training/combo.rs index 0e6c206..164ff4b 100644 --- a/src/training/combo.rs +++ b/src/training/combo.rs @@ -1,5 +1,4 @@ use crate::common::consts::FighterId; -use crate::common::FIGHTER_MANAGER_ADDR; use crate::common::*; use crate::training::*; @@ -28,15 +27,6 @@ unsafe fn was_in_shieldstun(module_accessor: *mut app::BattleObjectModuleAccesso prev_status == FIGHTER_STATUS_KIND_GUARD_DAMAGE } -unsafe fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModuleAccessor { - let entry_id_int = fighter_id as i32; - let entry_id = app::FighterEntryID(entry_id_int); - let mgr = *(FIGHTER_MANAGER_ADDR as *mut *mut app::FighterManager); - let fighter_entry = FighterManager::get_fighter_entry(mgr, entry_id) as *mut app::FighterEntry; - let current_fighter_id = FighterEntry::current_fighter_id(fighter_entry); - app::sv_battle_object::module_accessor(current_fighter_id as u32) -} - macro_rules! actionable_statuses { () => { vec![ diff --git a/src/training/directional_influence.rs b/src/training/directional_influence.rs index 7d41f6d..8308c51 100644 --- a/src/training/directional_influence.rs +++ b/src/training/directional_influence.rs @@ -7,8 +7,6 @@ use smash::lib::lua_const::*; use smash::lib::L2CValue; use smash::lua2cpp::L2CFighterCommon; -pub static mut DI_ANGLE: f64 = 0.0; - #[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_FighterStatusDamage__correctDamageVectorCommon)] pub unsafe fn handle_correct_damage_vector_common( fighter: &mut L2CFighterCommon, @@ -33,25 +31,31 @@ unsafe fn mod_handle_di(fighter: &mut L2CFighterCommon, _arg1: L2CValue) { } // Either left, right, or none - DI_ANGLE = get_angle(MENU.di_state); - // Nothig to do on no DI - if DI_ANGLE == ANGLE_NONE { + let mut angle = get_angle(MENU.di_state); + // Nothing to do on no DI + if angle == ANGLE_NONE { return; } - // If facing left, reverse angle - if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT { - DI_ANGLE -= PI; + let launch_speed_x = KineticEnergy::get_speed_x( + KineticModule::get_energy( + module_accessor, + *FIGHTER_KINETIC_ENERGY_ID_DAMAGE + ) as *mut smash::app::KineticEnergy); + + // If we're launched left, reverse stick X + if launch_speed_x < 0.0 { + angle = PI - angle; } WorkModule::set_float( module_accessor, - DI_ANGLE.cos() as f32, + angle.cos() as f32, *FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X, ); WorkModule::set_float( module_accessor, - DI_ANGLE.sin() as f32, + angle.sin() as f32, *FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y, ); } diff --git a/src/training/left_stick.rs b/src/training/left_stick.rs index 13360ae..5c6c5a7 100644 --- a/src/training/left_stick.rs +++ b/src/training/left_stick.rs @@ -2,6 +2,7 @@ use crate::common::consts::*; use crate::common::*; use core::f64::consts::PI; use smash::app::{self, lua_bind::*}; +use smash::lib::lua_const::*; use smash::hash40; static mut STICK_DIRECTION: Direction = Direction::None; @@ -51,9 +52,17 @@ unsafe fn get_angle(module_accessor: &mut app::BattleObjectModuleAccessor) -> f6 return ANGLE_NONE; } - // If facing left, reverse angle - if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT { - angle -= PI; + // TODO: if left_stick is used for something other than + // directional airdodge, this may not make sense. + let launch_speed_x = KineticEnergy::get_speed_x( + KineticModule::get_energy( + module_accessor, + *FIGHTER_KINETIC_ENERGY_ID_DAMAGE + ) as *mut smash::app::KineticEnergy); + + // If we're launched left, reverse stick X + if launch_speed_x < 0.0 { + angle = PI - angle; } angle