From 5cb981c268ac15501736af47173a2043a15acf87 Mon Sep 17 00:00:00 2001 From: sidschingis Date: Sun, 28 Jun 2020 22:41:51 +0200 Subject: [PATCH] Jump Toggles (#103) * Code Formatting * Cleanup * Implement Tilts * Update TrainingModpackOverlay * Move is_shielding to Commong * Fix Flash Shield Fixed not dropping shield again * Formatting * Remove ToDos * Use Generic OnOff Enum * Add Falling Aerial Toggle * Implement Full Hop Toggle * Add Comments --- TrainingModpackOverlay | 2 +- src/common/consts.rs | 16 +++------- src/common/mod.rs | 6 ++-- src/training/fast_fall.rs | 18 +++++++---- src/training/full_hop.rs | 64 +++++++++++++++++++++++++++++++++++++++ src/training/mash.rs | 9 +++++- src/training/mod.rs | 13 +++++--- 7 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 src/training/full_hop.rs diff --git a/TrainingModpackOverlay b/TrainingModpackOverlay index ff24883..60ae2fb 160000 --- a/TrainingModpackOverlay +++ b/TrainingModpackOverlay @@ -1 +1 @@ -Subproject commit ff248838a589e1d3316d1493e1cd16f89e1e1373 +Subproject commit 60ae2fbb5260f074c4c1763d2b4cc0b6d1070744 diff --git a/src/common/consts.rs b/src/common/consts.rs index 1ba7989..96b3459 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -257,17 +257,9 @@ impl From for Defensive { } } -/// Mash in neutral #[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq)] -pub enum MashInNeutral { - Off = 0, - On = 1, -} - -#[repr(i32)] -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum FastFall { +pub enum OnOff { Off = 0, On = 1, } @@ -284,8 +276,10 @@ pub struct TrainingModpackMenu { pub shield_state: Shield, pub defensive_state: Defensive, pub oos_offset: i32, - pub mash_in_neutral: MashInNeutral, - pub fast_fall: FastFall, + pub mash_in_neutral: OnOff, + pub fast_fall: OnOff, + pub falling_aerials: OnOff, + pub full_hop: OnOff, } // Fighter Ids diff --git a/src/common/mod.rs b/src/common/mod.rs index 877eb29..5729773 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -15,8 +15,10 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac shield_state: Shield::None, defensive_state: Defensive::Random, oos_offset: 0, - mash_in_neutral: MashInNeutral::Off, - fast_fall: FastFall::Off, + mash_in_neutral: OnOff::Off, + fast_fall: OnOff::Off, + falling_aerials: OnOff::Off, + full_hop: OnOff::Off, }; pub static mut MENU: &'static mut consts::TrainingModpackMenu = unsafe { &mut MENU_STRUCT }; diff --git a/src/training/fast_fall.rs b/src/training/fast_fall.rs index f688a68..7dc0c31 100644 --- a/src/training/fast_fall.rs +++ b/src/training/fast_fall.rs @@ -1,4 +1,4 @@ -use crate::common::consts::FastFall; +use crate::common::consts::OnOff; use crate::common::*; use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; @@ -17,7 +17,7 @@ pub unsafe fn get_command_flag_cat( return; } - if MENU.fast_fall != FastFall::On { + if MENU.fast_fall != OnOff::On { return; } @@ -29,14 +29,12 @@ pub unsafe fn get_command_flag_cat( return; } - let y_speed = - KineticModule::get_sum_speed_y(module_accessor, *FIGHTER_KINETIC_ENERGY_ID_GRAVITY); // Need to be falling - if y_speed >= 0.0 { + if !is_falling(module_accessor) { return; } - // Can't fastfall in hitstun + // Can't fastfall in hitstun // tumble // meteor if is_in_hitstun(module_accessor) { return; } @@ -56,6 +54,14 @@ pub unsafe fn get_command_flag_cat( add_spark_effect(module_accessor); } +pub fn is_falling(module_accessor: &mut app::BattleObjectModuleAccessor)->bool { + unsafe { + let y_speed = + KineticModule::get_sum_speed_y(module_accessor, *FIGHTER_KINETIC_ENERGY_ID_GRAVITY); + y_speed < 0.0 + } +} + unsafe fn add_spark_effect(module_accessor: &mut app::BattleObjectModuleAccessor) { // Mock Spark effect let pos = Vector3f { diff --git a/src/training/full_hop.rs b/src/training/full_hop.rs new file mode 100644 index 0000000..df508aa --- /dev/null +++ b/src/training/full_hop.rs @@ -0,0 +1,64 @@ +use crate::common::consts::*; +use crate::common::*; +use smash::app::{self, lua_bind::*}; +use smash::lib::lua_const::*; + +/** + * This is needed to have the CPU put up shield + */ +pub unsafe fn check_button_on( + module_accessor: &mut app::BattleObjectModuleAccessor, + button: i32, +) -> Option { + if should_return_none_in_check_button(module_accessor, button) { + return None; + } + Some(true) +} + +/** + * This is needed to prevent dropping shield immediately + */ +pub unsafe fn check_button_off( + module_accessor: &mut app::BattleObjectModuleAccessor, + button: i32, +) -> Option { + if should_return_none_in_check_button(module_accessor, button) { + return None; + } + Some(false) +} + +/** + * AKA should the cpu hold the jump button + */ +unsafe fn should_return_none_in_check_button( + module_accessor: &mut app::BattleObjectModuleAccessor, + button: i32, +) -> bool { + if !is_training_mode() { + return true; + } + + if !is_operation_cpu(module_accessor) { + return true; + } + + // We only care about the jump button + if ![*CONTROL_PAD_BUTTON_JUMP, *CONTROL_PAD_BUTTON_FLICK_JUMP].contains(&button) { + return true; + } + + // Nothing to do if not toggled + if MENU.full_hop != OnOff::On{ + return true; + } + + // Only need to hold during jump squat + let status_kind = StatusModule::status_kind(module_accessor) as i32; + if status_kind != FIGHTER_STATUS_KIND_JUMP_SQUAT { + return true; + } + + false +} diff --git a/src/training/mash.rs b/src/training/mash.rs index ba10e13..1655556 100644 --- a/src/training/mash.rs +++ b/src/training/mash.rs @@ -1,5 +1,6 @@ use crate::common::consts::*; use crate::common::*; +use crate::training::fast_fall; use crate::training::shield; use smash::app::{self, lua_bind::*}; use smash::hash40; @@ -86,7 +87,7 @@ unsafe fn check_buffer(module_accessor: &mut app::BattleObjectModuleAccessor) { return; } - if !is_in_hitstun(module_accessor) && MENU.mash_in_neutral != MashInNeutral::On { + if !is_in_hitstun(module_accessor) && MENU.mash_in_neutral != OnOff::On { return; } @@ -268,6 +269,12 @@ unsafe fn get_aerial_flag( transition_flag = *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ATTACK_AIR; } + if MENU.falling_aerials == OnOff::On && !fast_fall::is_falling(module_accessor) { + // Keep Buffering until we are falling + buffer_action(Mash::Attack); + return flag; + } + let action_flag: i32; match attack { diff --git a/src/training/mod.rs b/src/training/mod.rs index 18bb18e..7a99733 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -11,6 +11,7 @@ pub mod tech; pub mod combo; mod fast_fall; mod frame_counter; +mod full_hop; mod ledge; mod left_stick; mod mash; @@ -151,8 +152,10 @@ pub unsafe fn handle_check_button_on( module_accessor: &mut app::BattleObjectModuleAccessor, button: i32, ) -> bool { - shield::check_button_on(module_accessor, button) - .unwrap_or_else(|| original!()(module_accessor, button)) + shield::check_button_on(module_accessor, button).unwrap_or_else(|| { + full_hop::check_button_on(module_accessor, button) + .unwrap_or_else(|| original!()(module_accessor, button)) + }) } #[skyline::hook(replace = ControlModule::check_button_off)] @@ -160,8 +163,10 @@ pub unsafe fn handle_check_button_off( module_accessor: &mut app::BattleObjectModuleAccessor, button: i32, ) -> bool { - shield::check_button_off(module_accessor, button) - .unwrap_or_else(|| original!()(module_accessor, button)) + shield::check_button_off(module_accessor, button).unwrap_or_else(|| { + full_hop::check_button_off(module_accessor, button) + .unwrap_or_else(|| original!()(module_accessor, button)) + }) } #[skyline::hook(replace = MotionModule::change_motion)]