From f75ff6468a772bb1f81d7452e8f1861ac6040ccb Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Fri, 15 May 2020 19:43:37 -0400 Subject: [PATCH 01/14] Change menu from pointer to reference --- src/common/mod.rs | 5 ++--- src/hitbox_visualizer/mod.rs | 10 +++++----- src/lib.rs | 12 ++++++------ src/training/DirectionalInfluence.rs | 6 +++--- src/training/Ledge.rs | 8 ++++---- src/training/Mash.rs | 12 ++++++------ src/training/Shield.rs | 12 ++++++------ src/training/Tech.rs | 8 ++++---- 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index 89076a1..a9443d2 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,8 +1,7 @@ pub mod consts; use crate::common::consts::*; -use smash::app::lua_bind::*; -use smash::app::{self}; +use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; // use smash::app::{FighterManager, FighterInformation}; use smash::hash40; @@ -18,7 +17,7 @@ pub static mut menu_struct: consts::TrainingModpackMenu = consts::TrainingModpac DEFENSIVE_STATE: RANDOM_DEFENSIVE, }; -pub static mut menu: *mut consts::TrainingModpackMenu = 0 as *mut consts::TrainingModpackMenu; +pub static menu: &'static mut consts::TrainingModpackMenu = unsafe { &mut menu_struct}; pub static mut fighter_manager_addr: usize = 0; diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index 46df4b1..bdc9d80 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -233,11 +233,11 @@ pub unsafe fn get_command_flag_cat( // Pause Effect AnimCMD if hitbox visualization is active MotionAnimcmdModule::set_sleep_effect( module_accessor, - (*menu).HITBOX_VIS, + menu.HITBOX_VIS, ); // apply only once per frame - if category == 0 && is_training_mode() && (*menu).HITBOX_VIS { + if category == 0 && is_training_mode() && menu.HITBOX_VIS { let status_kind = StatusModule::status_kind(module_accessor) as i32; if !(*FIGHTER_STATUS_KIND_CATCH..=*FIGHTER_STATUS_KIND_CATCH_TURN).contains(&status_kind) @@ -312,7 +312,7 @@ unsafe fn handle_attack(lua_state: u64) { let z2 = l2c_agent.pop_lua_stack(15); // float or void // hacky way of forcing no shield damage on all hitboxes - if is_training_mode() && (*menu).SHIELD_STATE == SHIELD_INFINITE { + if is_training_mode() && menu.SHIELD_STATE == SHIELD_INFINITE { let hitbox_params: Vec = (0..36).map(|i| l2c_agent.pop_lua_stack(i + 1)).collect(); l2c_agent.clear_lua_stack(); @@ -328,7 +328,7 @@ unsafe fn handle_attack(lua_state: u64) { original!()(lua_state); - if (*menu).HITBOX_VIS && is_training_mode() { + if menu.HITBOX_VIS && is_training_mode() { generate_hitbox_effects( sv_system::battle_object_module_accessor(lua_state), joint.get_int(), @@ -362,7 +362,7 @@ unsafe fn handle_catch(lua_state: u64) { original!()(lua_state); - if (*menu).HITBOX_VIS && is_training_mode() { + if menu.HITBOX_VIS && is_training_mode() { generate_hitbox_effects( sv_system::battle_object_module_accessor(lua_state), joint.get_int(), diff --git a/src/lib.rs b/src/lib.rs index 931794a..1c88f58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] #![allow(non_upper_case_globals)] #![feature(with_options)] +#![feature(const_mut_refs)] mod common; mod hitbox_visualizer; @@ -26,7 +27,7 @@ use smash::lua2cpp::L2CFighterCommon; pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue { let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); if is_training_mode() && is_operation_cpu(module_accessor) { - if (*menu).MASH_STATE == MASH_ATTACK && (*menu).ATTACK_STATE == MASH_GRAB { + if menu.MASH_STATE == MASH_ATTACK && menu.ATTACK_STATE == MASH_GRAB { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::get_int( module_accessor, @@ -45,7 +46,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } } - if (*menu).MASH_STATE == MASH_SPOTDODGE { + if menu.MASH_STATE == MASH_SPOTDODGE { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::is_enable_transition_term( module_accessor, @@ -58,7 +59,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } } - if (*menu).MASH_STATE == MASH_UP_B { + if menu.MASH_STATE == MASH_UP_B { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { // if WorkModule::is_enable_transition_term( // module_accessor, @@ -71,7 +72,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue // } } } - if (*menu).MASH_STATE == MASH_UP_SMASH { + if menu.MASH_STATE == MASH_UP_SMASH { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { // if WorkModule::is_enable_transition_term( // module_accessor, @@ -106,8 +107,7 @@ pub fn main() { nro::add_hook(nro_main).unwrap(); unsafe { - common::menu = &mut common::menu_struct; - let buffer = format!("{:x}", common::menu as u64); + let buffer = format!("{:x}", common::menu as *const _ as u64); println!("Writing training_modpack.log with {}...\n", buffer); mkdir("sd:/TrainingModpack/\u{0}".as_bytes().as_ptr(), 0777); let f = fopen( diff --git a/src/training/DirectionalInfluence.rs b/src/training/DirectionalInfluence.rs index 68f3e7c..b04b010 100644 --- a/src/training/DirectionalInfluence.rs +++ b/src/training/DirectionalInfluence.rs @@ -15,11 +15,11 @@ pub unsafe fn get_float( { if is_training_mode() && is_operation_cpu(module_accessor) && is_in_hitstun(module_accessor) { - if (*menu).DI_STATE != NONE { - let mut angle = ((*menu).DI_STATE - 1) as f64 * PI / 4.0; + if menu.DI_STATE != NONE { + let mut angle = (menu.DI_STATE - 1) as f64 * PI / 4.0; // Either 0 (right) or PI (left) - if (*menu).DI_STATE == DI_RANDOM_IN_AWAY { + if menu.DI_STATE == DI_RANDOM_IN_AWAY { angle = app::sv_math::rand(hash40("fighter"), 2) as f64 * PI; } // If facing left, reverse angle diff --git a/src/training/Ledge.rs b/src/training/Ledge.rs index 3cdde90..19f9cfe 100644 --- a/src/training/Ledge.rs +++ b/src/training/Ledge.rs @@ -21,10 +21,10 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor let mut status = 0; let ledge_case: i32; - if (*menu).LEDGE_STATE == RANDOM_LEDGE { + if menu.LEDGE_STATE == RANDOM_LEDGE { ledge_case = app::sv_math::rand(hash40("fighter"), 4) + 2; } else { - ledge_case = (*menu).LEDGE_STATE; + ledge_case = menu.LEDGE_STATE; } match ledge_case { @@ -89,7 +89,7 @@ pub unsafe fn check_button_on( if is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; - if (*menu).DEFENSIVE_STATE == DEFENSIVE_SHIELD + if menu.DEFENSIVE_STATE == DEFENSIVE_SHIELD && should_perform_defensive_option(module_accessor, prev_status, status) { return Some(true); @@ -105,7 +105,7 @@ pub unsafe fn get_command_flag_cat( category: i32, flag: &mut i32, ) { - if (*menu).LEDGE_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if menu.LEDGE_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { force_option(module_accessor); defensive_option(module_accessor, category, flag); } diff --git a/src/training/Mash.rs b/src/training/Mash.rs index 324dc1b..5f68fbd 100644 --- a/src/training/Mash.rs +++ b/src/training/Mash.rs @@ -9,8 +9,8 @@ pub unsafe fn get_attack_air_kind( module_accessor: &mut app::BattleObjectModuleAccessor, ) -> Option { if is_training_mode() && is_operation_cpu(module_accessor) { - if (*menu).MASH_STATE == MASH_ATTACK { - match (*menu).ATTACK_STATE { + if menu.MASH_STATE == MASH_ATTACK { + match menu.ATTACK_STATE { MASH_NAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_N), MASH_FAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_F), MASH_BAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_B), @@ -20,7 +20,7 @@ pub unsafe fn get_attack_air_kind( } } - if (*menu).MASH_STATE == MASH_RANDOM { + if menu.MASH_STATE == MASH_RANDOM { return Some(app::sv_math::rand(hash40("fighter"), 5) + 1); } } @@ -38,7 +38,7 @@ pub unsafe fn get_command_flag_cat( || is_in_landing(module_accessor) || is_in_shieldstun(module_accessor) { - match (*menu).MASH_STATE { + match menu.MASH_STATE { MASH_AIRDODGE => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_AIR_ESCAPE; @@ -57,7 +57,7 @@ pub unsafe fn get_command_flag_cat( } MASH_ATTACK => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { - match (*menu).ATTACK_STATE { + match menu.ATTACK_STATE { MASH_NAIR | MASH_FAIR | MASH_BAIR | MASH_UPAIR | MASH_DAIR => { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N; // If we are performing the attack OOS we also need to jump @@ -140,7 +140,7 @@ pub unsafe fn check_button_on( ) -> Option { if [*CONTROL_PAD_BUTTON_GUARD_HOLD, *CONTROL_PAD_BUTTON_GUARD].contains(&button) { if is_training_mode() && is_operation_cpu(module_accessor) { - if (*menu).MASH_STATE == MASH_AIRDODGE + if menu.MASH_STATE == MASH_AIRDODGE && (is_in_hitstun(module_accessor) || is_in_landing(module_accessor)) { return Some(true); diff --git a/src/training/Shield.rs b/src/training/Shield.rs index 3cffd2c..a2cb9a4 100644 --- a/src/training/Shield.rs +++ b/src/training/Shield.rs @@ -10,7 +10,7 @@ pub unsafe fn get_param_float( param_hash: u64, ) -> Option { if is_training_mode() { - if (*menu).SHIELD_STATE == SHIELD_INFINITE { + if menu.SHIELD_STATE == SHIELD_INFINITE { if param_type == hash40("common") { if param_hash == hash40("shield_dec1") { return Some(0.0); @@ -31,9 +31,9 @@ pub unsafe fn get_param_float( pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool { // We should hold shield if the state requires it - if [SHIELD_HOLD, SHIELD_INFINITE].contains(&(*menu).SHIELD_STATE) { + if [SHIELD_HOLD, SHIELD_INFINITE].contains(&menu.SHIELD_STATE) { // If we are not mashing then we will always hold shield - if (*menu).MASH_STATE == NONE { + if menu.MASH_STATE == NONE { return true; } @@ -42,12 +42,12 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc } // We will only drop shield if we are in shieldstun and our attack can be performed OOS - if (*menu).MASH_STATE == MASH_ATTACK { - if [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&(*menu).ATTACK_STATE) { + if menu.MASH_STATE == MASH_ATTACK { + if [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&menu.ATTACK_STATE) { return false; } - if [MASH_SPOTDODGE, MASH_GRAB].contains(&(*menu).ATTACK_STATE) { + if [MASH_SPOTDODGE, MASH_GRAB].contains(&menu.ATTACK_STATE) { return true; } } diff --git a/src/training/Tech.rs b/src/training/Tech.rs index 559a4f9..8b9d177 100644 --- a/src/training/Tech.rs +++ b/src/training/Tech.rs @@ -11,7 +11,7 @@ pub unsafe fn init_settings( ) -> Option<()> { if is_training_mode() && is_operation_cpu(module_accessor) { if status_kind == FIGHTER_STATUS_KIND_DOWN { - match (*menu).TECH_STATE { + match menu.TECH_STATE { RANDOM_TECH => { let random_statuses = vec![ *FIGHTER_STATUS_KIND_DOWN, @@ -90,7 +90,7 @@ pub unsafe fn get_command_flag_cat( category: i32, flag: &mut i32, ) { - if (*menu).TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if menu.TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; if [ @@ -126,7 +126,7 @@ pub unsafe fn check_button_on( if is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; - if (*menu).DEFENSIVE_STATE == DEFENSIVE_SHIELD + if menu.DEFENSIVE_STATE == DEFENSIVE_SHIELD && should_perform_defensive_option(module_accessor, prev_status, status) { return Some(true); @@ -141,7 +141,7 @@ pub unsafe fn change_motion( module_accessor: &mut app::BattleObjectModuleAccessor, motion_kind: u64, ) -> Option { - if (*menu).TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if menu.TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { if [hash40("passive_stand_f"), hash40("passive_stand_b")].contains(&motion_kind) { if app::sv_math::rand(hash40("fighter"), 2) != 0 { return Some(hash40("passive_stand_f")); From cd3a6d938b001d8720c7fc4b5ef80b395560479f Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Fri, 15 May 2020 19:49:25 -0400 Subject: [PATCH 02/14] Clean up various imports --- src/common/mod.rs | 1 - src/hitbox_visualizer/mod.rs | 11 +++-------- src/lib.rs | 2 +- src/training/DirectionalInfluence.rs | 3 +-- src/training/Ledge.rs | 3 +-- src/training/Mash.rs | 3 +-- src/training/SaveStates.rs | 3 +-- src/training/Shield.rs | 2 +- src/training/Tech.rs | 3 +-- 9 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index a9443d2..c3af5ce 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -3,7 +3,6 @@ pub mod consts; use crate::common::consts::*; use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; -// use smash::app::{FighterManager, FighterInformation}; use smash::hash40; pub static mut menu_struct: consts::TrainingModpackMenu = consts::TrainingModpackMenu { diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index bdc9d80..f80c87b 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -1,12 +1,7 @@ -use crate::common::*; -use crate::common::consts::*; -use smash::app::lua_bind::*; -use smash::app::sv_animcmd::{self}; -use smash::app::sv_system::{self}; -use smash::app::{self}; +use crate::common::{*, consts::*}; +use smash::app::{self, lua_bind::*, sv_animcmd, sv_system}; use smash::hash40; -use smash::lib::lua_const::*; -use smash::lib::{L2CAgent, L2CValue}; +use smash::lib::{lua_const::*, L2CAgent, L2CValue}; use smash::phx::{Hash40, Vector3f}; /** diff --git a/src/lib.rs b/src/lib.rs index 1c88f58..307349c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ use skyline::c_str; use skyline::libc::{c_void, mkdir, fclose, fopen, fwrite}; use skyline::nro::{self, NroInfo}; use smash::app::lua_bind::*; -use smash::app::sv_system::{self}; +use smash::app::sv_system; use smash::lib::lua_const::*; use smash::lib::L2CValue; use smash::lua2cpp::L2CFighterCommon; diff --git a/src/training/DirectionalInfluence.rs b/src/training/DirectionalInfluence.rs index b04b010..267e0be 100644 --- a/src/training/DirectionalInfluence.rs +++ b/src/training/DirectionalInfluence.rs @@ -1,8 +1,7 @@ use crate::common::consts::*; use crate::common::*; use core::f64::consts::PI; -use smash::app::lua_bind::*; -use smash::app::{self}; +use smash::app::{self, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; diff --git a/src/training/Ledge.rs b/src/training/Ledge.rs index 19f9cfe..3e2a92e 100644 --- a/src/training/Ledge.rs +++ b/src/training/Ledge.rs @@ -1,7 +1,6 @@ use crate::common::consts::*; use crate::common::*; -use smash::app::lua_bind::*; -use smash::app::{self}; +use smash::app::{self, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; diff --git a/src/training/Mash.rs b/src/training/Mash.rs index 5f68fbd..3437802 100644 --- a/src/training/Mash.rs +++ b/src/training/Mash.rs @@ -1,7 +1,6 @@ use crate::common::consts::*; use crate::common::*; -use smash::app::lua_bind::*; -use smash::app::{self}; +use smash::app::{self, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; diff --git a/src/training/SaveStates.rs b/src/training/SaveStates.rs index 951e297..cf7a655 100644 --- a/src/training/SaveStates.rs +++ b/src/training/SaveStates.rs @@ -1,6 +1,5 @@ use crate::common::*; -use smash::app::lua_bind::*; -use smash::app::{self}; +use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; use smash::phx::Vector3f; diff --git a/src/training/Shield.rs b/src/training/Shield.rs index a2cb9a4..b387f6a 100644 --- a/src/training/Shield.rs +++ b/src/training/Shield.rs @@ -1,6 +1,6 @@ use crate::common::consts::*; use crate::common::*; -use smash::app::{self}; +use smash::app; use smash::hash40; use smash::lib::lua_const::*; diff --git a/src/training/Tech.rs b/src/training/Tech.rs index 8b9d177..f20dab5 100644 --- a/src/training/Tech.rs +++ b/src/training/Tech.rs @@ -1,7 +1,6 @@ use crate::common::consts::*; use crate::common::*; -use smash::app::lua_bind::*; -use smash::app::{self}; +use smash::app::{self, lua_bind::*}; use smash::hash40; use smash::lib::lua_const::*; From 6eb99546f9cce1f02f3b4d99ef79b47484a4879c Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Fri, 15 May 2020 20:24:35 -0400 Subject: [PATCH 03/14] Clean up hook installations by switching to install_hooks --- src/hitbox_visualizer/mod.rs | 8 +++++--- src/training/mod.rs | 34 ++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index f80c87b..c9530e3 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -410,7 +410,9 @@ pub unsafe fn handle_set_rebound( pub fn hitbox_visualization() { println!("Applying hitbox visualization mods."); - skyline::install_hook!(handle_attack); - skyline::install_hook!(handle_catch); - skyline::install_hook!(handle_set_rebound); + skyline::install_hooks!( + handle_attack, + handle_catch, + handle_set_rebound + ); } diff --git a/src/training/mod.rs b/src/training/mod.rs index 526d9c9..8f08c68 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -194,20 +194,26 @@ pub fn training_mods() { println!("Lookup symbol output: {:#?}", fighter_manager_addr); } - // Mash airdodge/jump - skyline::install_hook!(handle_get_command_flag_cat); + skyline::install_hooks!( + // Mash airdodge/jump + handle_get_command_flag_cat, - // Set DI - skyline::install_hook!(handle_get_float); + // Set DI + handle_get_float, - // Hold/Infinite shield - skyline::install_hook!(handle_check_button_on); - skyline::install_hook!(handle_check_button_off); - - skyline::install_hook!(handle_get_param_float); - - // Mash attack - skyline::install_hook!(handle_get_attack_air_kind); + // Hold/Infinite shield + handle_check_button_on, + handle_check_button_off, + + handle_get_param_float, + + // Mash attack + handle_get_attack_air_kind, + + // Tech options + handle_init_settings, + handle_change_motion, + ); // // Input recorder // SaltySD_function_replace_sym( @@ -216,8 +222,4 @@ pub fn training_mods() { // SaltySD_function_replace_sym( // "_ZN3app8lua_bind31ControlModule__get_stick_y_implEPNS_26BattleObjectModuleAccessorE", // (u64)&ControlModule::get_stick_y_replace); - - // Tech options - skyline::install_hook!(handle_init_settings); - skyline::install_hook!(handle_change_motion); } From 4dfc78c98fe1d95d4553fca05b20bf7097d98442 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Fri, 15 May 2020 21:59:03 -0400 Subject: [PATCH 04/14] Remove style lint allows --- src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 307349c..b60f63f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,4 @@ #![feature(proc_macro_hygiene)] -#![allow(unused_variables)] -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] #![feature(with_options)] #![feature(const_mut_refs)] @@ -22,7 +18,6 @@ use smash::lib::lua_const::*; use smash::lib::L2CValue; use smash::lua2cpp::L2CFighterCommon; -#[allow(unused_unsafe)] #[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_sub_guard_cont)] pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue { let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); From a79bedfa7f47002e027f65f067fcbd27919106e0 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Fri, 15 May 2020 22:02:45 -0400 Subject: [PATCH 05/14] Prefix underscore to unused variables --- src/common/mod.rs | 4 ++-- src/hitbox_visualizer/mod.rs | 24 ++++++++++++------------ src/training/Ledge.rs | 2 +- src/training/Shield.rs | 2 +- src/training/Tech.rs | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index c3af5ce..3c410f0 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -38,7 +38,7 @@ pub unsafe fn is_operation_cpu(module_accessor: &mut app::BattleObjectModuleAcce let entry_id_int = WorkModule::get_int(module_accessor, *FIGHTER_INSTANCE_WORK_ID_INT_ENTRY_ID) as i32; - let entry_id = app::FighterEntryID(entry_id_int); + let _entry_id = app::FighterEntryID(entry_id_int); // let mut mgr = FighterManager{_address : fighter_manager_addr as u64}; // let fighter_information = lua_bind::FighterManager::get_fighter_information(&mut mgr, entry_id) as *mut FighterInformation; // println!("FighterInformation: {:#?}", fighter_information); @@ -72,7 +72,7 @@ pub unsafe fn is_in_landing(module_accessor: &mut app::BattleObjectModuleAccesso } pub unsafe fn perform_defensive_option( - module_accessor: &mut app::BattleObjectModuleAccessor, + _module_accessor: &mut app::BattleObjectModuleAccessor, flag: &mut i32, ) { match (*menu).DEFENSIVE_STATE { diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index c9530e3..c7b9601 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -136,18 +136,18 @@ pub unsafe fn generate_hitbox_effects( z2: Option, color: Vector3f, ) { - let red = L2CValue::new_num(color.x); - let green = L2CValue::new_num(color.y); - let blue = L2CValue::new_num(color.z); + let _red = L2CValue::new_num(color.x); + let _green = L2CValue::new_num(color.y); + let _blue = L2CValue::new_num(color.z); let size_mult = 19.0 / 200.0; - let shield_effect = L2CValue::new_int(hash40("sys_shield")); - let zero_rot = L2CValue::new_num(0.0); - let terminate = L2CValue::new_bool(true); - let effect_size = L2CValue::new_num(size * size_mult); + let _shield_effect = L2CValue::new_int(hash40("sys_shield")); + let _zero_rot = L2CValue::new_num(0.0); + let _terminate = L2CValue::new_bool(true); + let _effect_size = L2CValue::new_num(size * size_mult); - let rate = L2CValue::new_num(8.0); + let _rate = L2CValue::new_num(8.0); let x_dist: f32; let y_dist: f32; @@ -293,11 +293,11 @@ unsafe fn handle_attack(lua_state: u64) { // get all necessary grabbox params let id = l2c_agent.pop_lua_stack(1); // int let joint = l2c_agent.pop_lua_stack(3); // hash40 - let damage = l2c_agent.pop_lua_stack(4); // float + let _damage = l2c_agent.pop_lua_stack(4); // float let _angle = l2c_agent.pop_lua_stack(5); // int - let kbg = l2c_agent.pop_lua_stack(6); // int - let fkb = l2c_agent.pop_lua_stack(7); // int - let bkb = l2c_agent.pop_lua_stack(8); // int + let _kbg = l2c_agent.pop_lua_stack(6); // int + let _fkb = l2c_agent.pop_lua_stack(7); // int + let _bkb = l2c_agent.pop_lua_stack(8); // int let size = l2c_agent.pop_lua_stack(9); // float let x = l2c_agent.pop_lua_stack(10); // float let y = l2c_agent.pop_lua_stack(11); // float diff --git a/src/training/Ledge.rs b/src/training/Ledge.rs index 3e2a92e..0d2e9df 100644 --- a/src/training/Ledge.rs +++ b/src/training/Ledge.rs @@ -60,7 +60,7 @@ pub unsafe fn should_perform_defensive_option( pub unsafe fn defensive_option( module_accessor: &mut app::BattleObjectModuleAccessor, - category: i32, + _category: i32, flag: &mut i32, ) { let status = StatusModule::status_kind(module_accessor) as i32; diff --git a/src/training/Shield.rs b/src/training/Shield.rs index b387f6a..08a1a13 100644 --- a/src/training/Shield.rs +++ b/src/training/Shield.rs @@ -5,7 +5,7 @@ use smash::hash40; use smash::lib::lua_const::*; pub unsafe fn get_param_float( - module_accessor: &mut app::BattleObjectModuleAccessor, + _module_accessor: &mut app::BattleObjectModuleAccessor, param_type: u64, param_hash: u64, ) -> Option { diff --git a/src/training/Tech.rs b/src/training/Tech.rs index f20dab5..7255ecd 100644 --- a/src/training/Tech.rs +++ b/src/training/Tech.rs @@ -86,7 +86,7 @@ pub unsafe fn should_perform_defensive_option( pub unsafe fn get_command_flag_cat( module_accessor: &mut app::BattleObjectModuleAccessor, - category: i32, + _category: i32, flag: &mut i32, ) { if menu.TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { From 798e18a71a0762a3f6531029c97b2b375b37784c Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Fri, 15 May 2020 23:40:27 -0400 Subject: [PATCH 06/14] Fix all style/dead_code lints --- src/common/consts.rs | 18 ++-- src/common/mod.rs | 29 ++++--- src/hitbox_visualizer/mod.rs | 87 ++----------------- src/lib.rs | 12 +-- ...lInfluence.rs => directional_influence.rs} | 6 +- src/training/{Ledge.rs => ledge.rs} | 8 +- src/training/{Mash.rs => mash.rs} | 12 +-- src/training/mod.rs | 62 ++++++------- .../{SaveStates.rs => save_states.rs} | 59 +++++++------ src/training/{Shield.rs => shield.rs} | 12 +-- src/training/{Tech.rs => tech.rs} | 8 +- 11 files changed, 114 insertions(+), 199 deletions(-) rename src/training/{DirectionalInfluence.rs => directional_influence.rs} (88%) rename src/training/{Ledge.rs => ledge.rs} (94%) rename src/training/{Mash.rs => mash.rs} (96%) rename src/training/{SaveStates.rs => save_states.rs} (75%) rename src/training/{Shield.rs => shield.rs} (88%) rename src/training/{Tech.rs => tech.rs} (96%) diff --git a/src/common/consts.rs b/src/common/consts.rs index 0b9fc03..bde958a 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -9,7 +9,6 @@ pub const NONE: i32 = 0; */ /* DI */ -pub static mut DI_STATE: i32 = NONE; pub const DI_RANDOM_IN_AWAY: i32 = 9; // const std::vector di_items{"None", "Out", "Up Out", "Up", "Up In", "In", "Down In", "Down", "Down Out", "Random"}; @@ -39,6 +38,7 @@ pub const ATTACK_LEDGE: i32 = 5; pub const RANDOM_TECH: i32 = 1; pub const TECH_IN_PLACE: i32 = 2; pub const TECH_ROLL: i32 = 3; +#[allow(dead_code)] pub const TECH_MISS: i32 = 4; // pub const std::vector tech_items{"None", "Random", "In-Place", "Roll", "Miss Tech"}; @@ -65,12 +65,12 @@ pub const DEFENSIVE_SHIELD: i32 = 5; #[repr(C)] pub struct TrainingModpackMenu { - pub HITBOX_VIS: bool, - pub DI_STATE: i32, - pub ATTACK_STATE: i32, - pub LEDGE_STATE: i32, - pub TECH_STATE: i32, - pub MASH_STATE: i32, - pub SHIELD_STATE: i32, - pub DEFENSIVE_STATE: i32, + pub hitbox_vis: bool, + pub di_state: i32, + pub attack_state: i32, + pub ledge_state: i32, + pub tech_state: i32, + pub mash_state: i32, + pub shield_state: i32, + pub defensive_state: i32, } diff --git a/src/common/mod.rs b/src/common/mod.rs index 3c410f0..4dd4fa5 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -5,26 +5,27 @@ use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; use smash::hash40; -pub static mut menu_struct: consts::TrainingModpackMenu = consts::TrainingModpackMenu { - HITBOX_VIS: true, - DI_STATE: NONE, - ATTACK_STATE: MASH_NAIR, - LEDGE_STATE: RANDOM_LEDGE, - TECH_STATE: RANDOM_TECH, - MASH_STATE: NONE, - SHIELD_STATE: NONE, - DEFENSIVE_STATE: RANDOM_DEFENSIVE, +pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpackMenu { + hitbox_vis: true, + di_state: NONE, + attack_state: MASH_NAIR, + ledge_state: RANDOM_LEDGE, + tech_state: RANDOM_TECH, + mash_state: NONE, + shield_state: NONE, + defensive_state: RANDOM_DEFENSIVE, }; -pub static menu: &'static mut consts::TrainingModpackMenu = unsafe { &mut menu_struct}; +pub static MENU: &'static mut consts::TrainingModpackMenu = unsafe { &mut MENU_STRUCT }; -pub static mut fighter_manager_addr: usize = 0; +pub static mut FIGHTER_MANAGER_ADDR: usize = 0; extern "C" { #[link_name = "\u{1}_ZN3app9smashball16is_training_modeEv"] pub fn is_training_mode() -> bool; - #[link_name = "\u{1}_ZN3app7utility8get_kindEPKNS_26BattleObjectModuleAccessorE"] - pub fn get_kind(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32; + + //#[link_name = "\u{1}_ZN3app7utility8get_kindEPKNS_26BattleObjectModuleAccessorE"] + //pub fn get_kind(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32; } pub fn get_category(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32 { @@ -75,7 +76,7 @@ pub unsafe fn perform_defensive_option( _module_accessor: &mut app::BattleObjectModuleAccessor, flag: &mut i32, ) { - match (*menu).DEFENSIVE_STATE { + match MENU.defensive_state { RANDOM_DEFENSIVE => { let random_cmds = vec![ *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE, diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index c7b9601..7aa1138 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -4,80 +4,6 @@ use smash::hash40; use smash::lib::{lua_const::*, L2CAgent, L2CValue}; use smash::phx::{Hash40, Vector3f}; -/** - * Rounds a number to the nearest multiple of another number. - */ -pub fn round_to(val: f32, align: f32) -> f32 { - (val / align).round() * align -} - -/** - * Linearly interpolates between two numbers, without bounds checking. - */ -pub fn lerp(min: f32, max: f32, t: f32) -> f32 { - min + (max - min) * t -} - -pub fn unlerp(min: f32, max: f32, val: f32) -> f32 { - (val - min) / (max - min) -} - -/** - * Linearly interpolates between two numbers, with bounds checking. - */ -pub fn lerp_bounded(min: f32, max: f32, t: f32) -> f32 { - if t <= 0.0 { - min - } else { - if t >= 1.0 { - max - } else { - lerp(min, max, t) - } - } -} -pub fn unlerp_bounded(min: f32, max: f32, val: f32) -> f32 { - if val <= min { - 0.0 - } else { - if val >= max { - 1.0 - } else { - unlerp(min, max, val) - } - } -} - -/** - * Linearly interpolates between two colors, with bounds checking, accounting for - * gamma. arguments: - * - min_color (Vector3f) -- xyz maps to rgb, components are usually in the - * range [0.0f, 1.0f] but can go beyond to account for super-bright or - * super-dark colors - * - max_Color (Vector3f) -- same as minColor - * - t (float) -- how far to interpolate between the colors - * - gamma (float = 2.0f) -- used for color correction, helps avoid ugly dark - * colors when interpolating b/t bright colors - */ - -pub fn color_lerp(min_color: Vector3f, max_color: Vector3f, t: f32, gamma: f32) -> Vector3f { - let gamma_inv = 1.0 / gamma; - let align = 1.0 / 255.0; // color components must be a multiple of 1/255 - Vector3f { - x: round_to( - lerp_bounded(min_color.x.powf(gamma), max_color.x.powf(gamma), t).powf(gamma_inv), - align, - ), - y: round_to( - lerp_bounded(min_color.y.powf(gamma), max_color.y.powf(gamma), t).powf(gamma_inv), - align, - ), - z: round_to( - lerp_bounded(min_color.z.powf(gamma), max_color.z.powf(gamma), t).powf(gamma_inv), - align, - ), - } -} pub const ID_COLORS: &[Vector3f] = &[ // used to tint the hitbox effects -- make sure that at least one component // is equal to 1.0 @@ -228,11 +154,11 @@ pub unsafe fn get_command_flag_cat( // Pause Effect AnimCMD if hitbox visualization is active MotionAnimcmdModule::set_sleep_effect( module_accessor, - menu.HITBOX_VIS, + MENU.hitbox_vis, ); // apply only once per frame - if category == 0 && is_training_mode() && menu.HITBOX_VIS { + if category == 0 && is_training_mode() && MENU.hitbox_vis { let status_kind = StatusModule::status_kind(module_accessor) as i32; if !(*FIGHTER_STATUS_KIND_CATCH..=*FIGHTER_STATUS_KIND_CATCH_TURN).contains(&status_kind) @@ -285,7 +211,6 @@ pub unsafe fn get_command_flag_cat( } // Necessary to ensure we visualize on the first frame of the hitbox -#[allow(unused_unsafe)] #[skyline::hook(replace = sv_animcmd::ATTACK)] unsafe fn handle_attack(lua_state: u64) { let mut l2c_agent = L2CAgent::new(lua_state); @@ -307,7 +232,7 @@ unsafe fn handle_attack(lua_state: u64) { let z2 = l2c_agent.pop_lua_stack(15); // float or void // hacky way of forcing no shield damage on all hitboxes - if is_training_mode() && menu.SHIELD_STATE == SHIELD_INFINITE { + if is_training_mode() && MENU.shield_state == SHIELD_INFINITE { let hitbox_params: Vec = (0..36).map(|i| l2c_agent.pop_lua_stack(i + 1)).collect(); l2c_agent.clear_lua_stack(); @@ -323,7 +248,7 @@ unsafe fn handle_attack(lua_state: u64) { original!()(lua_state); - if menu.HITBOX_VIS && is_training_mode() { + if MENU.hitbox_vis && is_training_mode() { generate_hitbox_effects( sv_system::battle_object_module_accessor(lua_state), joint.get_int(), @@ -339,7 +264,6 @@ unsafe fn handle_attack(lua_state: u64) { } } -#[allow(unused_unsafe)] #[skyline::hook(replace = sv_animcmd::CATCH)] unsafe fn handle_catch(lua_state: u64) { let mut l2c_agent = L2CAgent::new(lua_state); @@ -357,7 +281,7 @@ unsafe fn handle_catch(lua_state: u64) { original!()(lua_state); - if menu.HITBOX_VIS && is_training_mode() { + if MENU.hitbox_vis && is_training_mode() { generate_hitbox_effects( sv_system::battle_object_module_accessor(lua_state), joint.get_int(), @@ -378,7 +302,6 @@ pub unsafe fn is_shielding(module_accessor: *mut app::BattleObjectModuleAccessor (*FIGHTER_STATUS_KIND_GUARD_ON..=*FIGHTER_STATUS_KIND_GUARD_DAMAGE).contains(&status_kind) } -#[allow(unused_unsafe)] #[skyline::hook(replace = GrabModule::set_rebound)] pub unsafe fn handle_set_rebound( module_accessor: *mut app::BattleObjectModuleAccessor, diff --git a/src/lib.rs b/src/lib.rs index b60f63f..e6e18a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ use smash::lua2cpp::L2CFighterCommon; pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue { let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); if is_training_mode() && is_operation_cpu(module_accessor) { - if menu.MASH_STATE == MASH_ATTACK && menu.ATTACK_STATE == MASH_GRAB { + if MENU.mash_state == MASH_ATTACK && MENU.attack_state == MASH_GRAB { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::get_int( module_accessor, @@ -41,7 +41,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } } - if menu.MASH_STATE == MASH_SPOTDODGE { + if MENU.mash_state == MASH_SPOTDODGE { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::is_enable_transition_term( module_accessor, @@ -54,7 +54,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } } - if menu.MASH_STATE == MASH_UP_B { + if MENU.mash_state == MASH_UP_B { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { // if WorkModule::is_enable_transition_term( // module_accessor, @@ -67,7 +67,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue // } } } - if menu.MASH_STATE == MASH_UP_SMASH { + if MENU.mash_state == MASH_UP_SMASH { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { // if WorkModule::is_enable_transition_term( // module_accessor, @@ -84,7 +84,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue original!()(fighter) } -fn nro_main(nro: &NroInfo) { +fn nro_main(nro: &NroInfo<'_>) { match nro.name { "common" => { println!("Loaded common NRO!"); @@ -102,7 +102,7 @@ pub fn main() { nro::add_hook(nro_main).unwrap(); unsafe { - let buffer = format!("{:x}", common::menu as *const _ as u64); + let buffer = format!("{:x}", MENU as *const _ as u64); println!("Writing training_modpack.log with {}...\n", buffer); mkdir("sd:/TrainingModpack/\u{0}".as_bytes().as_ptr(), 0777); let f = fopen( diff --git a/src/training/DirectionalInfluence.rs b/src/training/directional_influence.rs similarity index 88% rename from src/training/DirectionalInfluence.rs rename to src/training/directional_influence.rs index 267e0be..7afc7d4 100644 --- a/src/training/DirectionalInfluence.rs +++ b/src/training/directional_influence.rs @@ -14,11 +14,11 @@ pub unsafe fn get_float( { if is_training_mode() && is_operation_cpu(module_accessor) && is_in_hitstun(module_accessor) { - if menu.DI_STATE != NONE { - let mut angle = (menu.DI_STATE - 1) as f64 * PI / 4.0; + if MENU.di_state != NONE { + let mut angle = (MENU.di_state - 1) as f64 * PI / 4.0; // Either 0 (right) or PI (left) - if menu.DI_STATE == DI_RANDOM_IN_AWAY { + if MENU.di_state == DI_RANDOM_IN_AWAY { angle = app::sv_math::rand(hash40("fighter"), 2) as f64 * PI; } // If facing left, reverse angle diff --git a/src/training/Ledge.rs b/src/training/ledge.rs similarity index 94% rename from src/training/Ledge.rs rename to src/training/ledge.rs index 0d2e9df..9e4ec0b 100644 --- a/src/training/Ledge.rs +++ b/src/training/ledge.rs @@ -20,10 +20,10 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor let mut status = 0; let ledge_case: i32; - if menu.LEDGE_STATE == RANDOM_LEDGE { + if MENU.ledge_state == RANDOM_LEDGE { ledge_case = app::sv_math::rand(hash40("fighter"), 4) + 2; } else { - ledge_case = menu.LEDGE_STATE; + ledge_case = MENU.ledge_state; } match ledge_case { @@ -88,7 +88,7 @@ pub unsafe fn check_button_on( if is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; - if menu.DEFENSIVE_STATE == DEFENSIVE_SHIELD + if MENU.defensive_state == DEFENSIVE_SHIELD && should_perform_defensive_option(module_accessor, prev_status, status) { return Some(true); @@ -104,7 +104,7 @@ pub unsafe fn get_command_flag_cat( category: i32, flag: &mut i32, ) { - if menu.LEDGE_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if MENU.ledge_state != NONE && is_training_mode() && is_operation_cpu(module_accessor) { force_option(module_accessor); defensive_option(module_accessor, category, flag); } diff --git a/src/training/Mash.rs b/src/training/mash.rs similarity index 96% rename from src/training/Mash.rs rename to src/training/mash.rs index 3437802..3c6acc3 100644 --- a/src/training/Mash.rs +++ b/src/training/mash.rs @@ -8,8 +8,8 @@ pub unsafe fn get_attack_air_kind( module_accessor: &mut app::BattleObjectModuleAccessor, ) -> Option { if is_training_mode() && is_operation_cpu(module_accessor) { - if menu.MASH_STATE == MASH_ATTACK { - match menu.ATTACK_STATE { + if MENU.mash_state == MASH_ATTACK { + match MENU.attack_state { MASH_NAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_N), MASH_FAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_F), MASH_BAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_B), @@ -19,7 +19,7 @@ pub unsafe fn get_attack_air_kind( } } - if menu.MASH_STATE == MASH_RANDOM { + if MENU.mash_state == MASH_RANDOM { return Some(app::sv_math::rand(hash40("fighter"), 5) + 1); } } @@ -37,7 +37,7 @@ pub unsafe fn get_command_flag_cat( || is_in_landing(module_accessor) || is_in_shieldstun(module_accessor) { - match menu.MASH_STATE { + match MENU.mash_state { MASH_AIRDODGE => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_AIR_ESCAPE; @@ -56,7 +56,7 @@ pub unsafe fn get_command_flag_cat( } MASH_ATTACK => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { - match menu.ATTACK_STATE { + match MENU.attack_state { MASH_NAIR | MASH_FAIR | MASH_BAIR | MASH_UPAIR | MASH_DAIR => { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N; // If we are performing the attack OOS we also need to jump @@ -139,7 +139,7 @@ pub unsafe fn check_button_on( ) -> Option { if [*CONTROL_PAD_BUTTON_GUARD_HOLD, *CONTROL_PAD_BUTTON_GUARD].contains(&button) { if is_training_mode() && is_operation_cpu(module_accessor) { - if menu.MASH_STATE == MASH_AIRDODGE + if MENU.mash_state == MASH_AIRDODGE && (is_in_hitstun(module_accessor) || is_in_landing(module_accessor)) { return Some(true); diff --git a/src/training/mod.rs b/src/training/mod.rs index 8f08c68..9197bf1 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -1,37 +1,34 @@ -use crate::common::fighter_manager_addr; +use crate::common::FIGHTER_MANAGER_ADDR; use crate::hitbox_visualizer; use skyline::{c_str, nn::ro::LookupSymbol}; use smash::app::{self, lua_bind::*}; -mod DirectionalInfluence; -mod Ledge; -mod Mash; -mod SaveStates; -mod Shield; -mod Tech; +mod directional_influence; +mod ledge; +mod mash; +mod save_states; +mod shield; +mod tech; -#[allow(unused_unsafe)] #[skyline::hook(replace = WorkModule::get_float)] pub unsafe fn handle_get_float( module_accessor: &mut app::BattleObjectModuleAccessor, var: i32, ) -> f32 { - DirectionalInfluence::get_float(module_accessor, var) + directional_influence::get_float(module_accessor, var) .unwrap_or_else(|| original!()(module_accessor, var)) } -#[allow(unused_unsafe)] #[skyline::hook(replace = WorkModule::get_param_float)] pub unsafe fn handle_get_param_float( module_accessor: &mut app::BattleObjectModuleAccessor, param_type: u64, param_hash: u64, ) -> f32 { - Shield::get_param_float(module_accessor, param_type, param_hash) + shield::get_param_float(module_accessor, param_type, param_hash) .unwrap_or_else(|| original!()(module_accessor, param_type, param_hash)) } -#[allow(unused_unsafe)] #[skyline::hook(replace = ControlModule::get_attack_air_kind)] pub unsafe fn handle_get_attack_air_kind( module_accessor: &mut app::BattleObjectModuleAccessor, @@ -40,16 +37,15 @@ pub unsafe fn handle_get_attack_air_kind( // int kind = InputRecorder::get_attack_air_kind(module_accessor, replace); // if (replace) return kind; - Mash::get_attack_air_kind(module_accessor).unwrap_or_else(|| original!()(module_accessor)) + mash::get_attack_air_kind(module_accessor).unwrap_or_else(|| original!()(module_accessor)) } -#[allow(unused_unsafe)] #[skyline::hook(replace = ControlModule::get_command_flag_cat)] pub unsafe fn handle_get_command_flag_cat( module_accessor: &mut app::BattleObjectModuleAccessor, category: i32, ) -> i32 { - SaveStates::save_states(module_accessor); + save_states::save_states(module_accessor); let mut flag = original!()(module_accessor, category); @@ -57,9 +53,9 @@ pub unsafe fn handle_get_command_flag_cat( // int ret = InputRecorder::get_command_flag_cat(module_accessor, category, flag, replace); // if (replace) return ret; - Mash::get_command_flag_cat(module_accessor, category, &mut flag); - Ledge::get_command_flag_cat(module_accessor, category, &mut flag); - Tech::get_command_flag_cat(module_accessor, category, &mut flag); + mash::get_command_flag_cat(module_accessor, category, &mut flag); + ledge::get_command_flag_cat(module_accessor, category, &mut flag); + tech::get_command_flag_cat(module_accessor, category, &mut flag); hitbox_visualizer::get_command_flag_cat(module_accessor, category); flag @@ -101,40 +97,37 @@ pub unsafe fn handle_get_command_flag_cat( // return stick_y; // } -#[allow(unused_unsafe)] #[skyline::hook(replace = ControlModule::check_button_on)] 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(|| { - Mash::check_button_on(module_accessor, button).unwrap_or_else(|| { - Tech::check_button_on(module_accessor, button).unwrap_or_else(|| { - Ledge::check_button_on(module_accessor, button) + shield::check_button_on(module_accessor, button).unwrap_or_else(|| { + mash::check_button_on(module_accessor, button).unwrap_or_else(|| { + tech::check_button_on(module_accessor, button).unwrap_or_else(|| { + ledge::check_button_on(module_accessor, button) .unwrap_or_else(|| original!()(module_accessor, button)) }) }) }) } -#[allow(unused_unsafe)] #[skyline::hook(replace = ControlModule::check_button_off)] pub unsafe fn handle_check_button_off( module_accessor: &mut app::BattleObjectModuleAccessor, button: i32, ) -> bool { - Shield::check_button_off(module_accessor, button) + shield::check_button_off(module_accessor, button) .unwrap_or_else(|| original!()(module_accessor, button)) } -#[allow(unused_unsafe)] #[skyline::hook(replace = StatusModule::init_settings)] pub unsafe fn handle_init_settings( module_accessor: &mut app::BattleObjectModuleAccessor, - situationKind: i32, + situation_kind: i32, unk1: i32, unk2: u32, - groundCliffCheckKind: i32, + ground_cliff_check_kind: i32, unk3: bool, unk4: i32, unk5: i32, @@ -142,13 +135,13 @@ pub unsafe fn handle_init_settings( unk7: i32, ) { let status_kind = StatusModule::status_kind(module_accessor) as i32; - Tech::init_settings(module_accessor, status_kind).unwrap_or_else(|| { + tech::init_settings(module_accessor, status_kind).unwrap_or_else(|| { original!()( module_accessor, - situationKind, + situation_kind, unk1, unk2, - groundCliffCheckKind, + ground_cliff_check_kind, unk3, unk4, unk5, @@ -158,7 +151,6 @@ pub unsafe fn handle_init_settings( }) } -#[allow(unused_unsafe)] #[skyline::hook(replace = MotionModule::change_motion)] pub unsafe fn handle_change_motion( module_accessor: &mut app::BattleObjectModuleAccessor, @@ -170,7 +162,7 @@ pub unsafe fn handle_change_motion( unk5: bool, unk6: bool, ) -> u64 { - Tech::change_motion(module_accessor, motion_kind).unwrap_or_else(|| { + tech::change_motion(module_accessor, motion_kind).unwrap_or_else(|| { original!()( module_accessor, motion_kind, @@ -188,10 +180,10 @@ pub fn training_mods() { println!("Applying training mods."); unsafe { LookupSymbol( - &mut fighter_manager_addr, + &mut FIGHTER_MANAGER_ADDR, c_str("_ZN3lib9SingletonIN3app14FighterManagerEE9instance_E"), ); - println!("Lookup symbol output: {:#?}", fighter_manager_addr); + println!("Lookup symbol output: {:#?}", FIGHTER_MANAGER_ADDR); } skyline::install_hooks!( diff --git a/src/training/SaveStates.rs b/src/training/save_states.rs similarity index 75% rename from src/training/SaveStates.rs rename to src/training/save_states.rs index cf7a655..5fc2d50 100644 --- a/src/training/SaveStates.rs +++ b/src/training/save_states.rs @@ -11,23 +11,22 @@ enum SaveState { PosMove, } -use crate::training::SaveStates::SaveState::*; +use SaveState::*; -static mut save_state_player_state: SaveState = NoAction; -static mut save_state_cpu_state: SaveState = NoAction; -static mut save_state_move_alert: bool = false; +static mut SAVE_STATE_PLAYER_STATE: SaveState = NoAction; +static mut SAVE_STATE_CPU_STATE: SaveState = NoAction; -static mut save_state_x_player: f32 = 0.0; -static mut save_state_y_player: f32 = 0.0; -static mut save_state_percent_player: f32 = 0.0; -static mut save_state_lr_player: f32 = 1.0; -static mut save_state_situation_kind_player: i32 = 0 as i32; +static mut SAVE_STATE_X_PLAYER: f32 = 0.0; +static mut SAVE_STATE_Y_PLAYER: f32 = 0.0; +static mut SAVE_STATE_PERCENT_PLAYER: f32 = 0.0; +static mut SAVE_STATE_LR_PLAYER: f32 = 1.0; +static mut SAVE_STATE_SITUATION_KIND_PLAYER: i32 = 0 as i32; -static mut save_state_x_cpu: f32 = 0.0; -static mut save_state_y_cpu: f32 = 0.0; -static mut save_state_percent_cpu: f32 = 0.0; -static mut save_state_lr_cpu: f32 = 1.0; -static mut save_state_situation_kind_cpu: i32 = 0 as i32; +static mut SAVE_STATE_X_CPU: f32 = 0.0; +static mut SAVE_STATE_Y_CPU: f32 = 0.0; +static mut SAVE_STATE_PERCENT_CPU: f32 = 0.0; +static mut SAVE_STATE_LR_CPU: f32 = 1.0; +static mut SAVE_STATE_SITUATION_KIND_CPU: i32 = 0 as i32; pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) { let status = StatusModule::status_kind(module_accessor) as i32; @@ -39,19 +38,19 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) let save_state_situation_kind: *mut i32; let save_state: *mut SaveState; if is_operation_cpu(module_accessor) { - save_state_x = &mut save_state_x_cpu; - save_state_y = &mut save_state_y_cpu; - save_state_percent = &mut save_state_percent_cpu; - save_state_lr = &mut save_state_lr_cpu; - save_state_situation_kind = &mut save_state_situation_kind_cpu; - save_state = &mut save_state_cpu_state; + save_state_x = &mut SAVE_STATE_X_CPU; + save_state_y = &mut SAVE_STATE_Y_CPU; + save_state_percent = &mut SAVE_STATE_PERCENT_CPU; + save_state_lr = &mut SAVE_STATE_LR_CPU; + save_state_situation_kind = &mut SAVE_STATE_SITUATION_KIND_CPU; + save_state = &mut SAVE_STATE_CPU_STATE; } else { - save_state_x = &mut save_state_x_player; - save_state_y = &mut save_state_y_player; - save_state_percent = &mut save_state_percent_player; - save_state_lr = &mut save_state_lr_player; - save_state_situation_kind = &mut save_state_situation_kind_player; - save_state = &mut save_state_player_state; + save_state_x = &mut SAVE_STATE_X_PLAYER; + save_state_y = &mut SAVE_STATE_Y_PLAYER; + save_state_percent = &mut SAVE_STATE_PERCENT_PLAYER; + save_state_lr = &mut SAVE_STATE_LR_PLAYER; + save_state_situation_kind = &mut SAVE_STATE_SITUATION_KIND_PLAYER; + save_state = &mut SAVE_STATE_PLAYER_STATE; } // Grab + Dpad up: reset state @@ -60,8 +59,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) != 0 { if *save_state == NoAction { - save_state_player_state = CameraMove; - save_state_cpu_state = CameraMove; + SAVE_STATE_PLAYER_STATE = CameraMove; + SAVE_STATE_CPU_STATE = CameraMove; } return; } @@ -155,8 +154,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) && ControlModule::check_button_trigger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_LW) != 0 { - save_state_player_state = Save; - save_state_cpu_state = Save; + SAVE_STATE_PLAYER_STATE = Save; + SAVE_STATE_CPU_STATE = Save; } if *save_state == Save { diff --git a/src/training/Shield.rs b/src/training/shield.rs similarity index 88% rename from src/training/Shield.rs rename to src/training/shield.rs index 08a1a13..0a82f62 100644 --- a/src/training/Shield.rs +++ b/src/training/shield.rs @@ -10,7 +10,7 @@ pub unsafe fn get_param_float( param_hash: u64, ) -> Option { if is_training_mode() { - if menu.SHIELD_STATE == SHIELD_INFINITE { + if MENU.shield_state == SHIELD_INFINITE { if param_type == hash40("common") { if param_hash == hash40("shield_dec1") { return Some(0.0); @@ -31,9 +31,9 @@ pub unsafe fn get_param_float( pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool { // We should hold shield if the state requires it - if [SHIELD_HOLD, SHIELD_INFINITE].contains(&menu.SHIELD_STATE) { + if [SHIELD_HOLD, SHIELD_INFINITE].contains(&MENU.shield_state) { // If we are not mashing then we will always hold shield - if menu.MASH_STATE == NONE { + if MENU.mash_state == NONE { return true; } @@ -42,12 +42,12 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc } // We will only drop shield if we are in shieldstun and our attack can be performed OOS - if menu.MASH_STATE == MASH_ATTACK { - if [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&menu.ATTACK_STATE) { + if MENU.mash_state == MASH_ATTACK { + if [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&MENU.attack_state) { return false; } - if [MASH_SPOTDODGE, MASH_GRAB].contains(&menu.ATTACK_STATE) { + if [MASH_SPOTDODGE, MASH_GRAB].contains(&MENU.attack_state) { return true; } } diff --git a/src/training/Tech.rs b/src/training/tech.rs similarity index 96% rename from src/training/Tech.rs rename to src/training/tech.rs index 7255ecd..d972bdd 100644 --- a/src/training/Tech.rs +++ b/src/training/tech.rs @@ -10,7 +10,7 @@ pub unsafe fn init_settings( ) -> Option<()> { if is_training_mode() && is_operation_cpu(module_accessor) { if status_kind == FIGHTER_STATUS_KIND_DOWN { - match menu.TECH_STATE { + match MENU.tech_state { RANDOM_TECH => { let random_statuses = vec![ *FIGHTER_STATUS_KIND_DOWN, @@ -89,7 +89,7 @@ pub unsafe fn get_command_flag_cat( _category: i32, flag: &mut i32, ) { - if menu.TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if MENU.tech_state != NONE && is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; if [ @@ -125,7 +125,7 @@ pub unsafe fn check_button_on( if is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; - if menu.DEFENSIVE_STATE == DEFENSIVE_SHIELD + if MENU.defensive_state == DEFENSIVE_SHIELD && should_perform_defensive_option(module_accessor, prev_status, status) { return Some(true); @@ -140,7 +140,7 @@ pub unsafe fn change_motion( module_accessor: &mut app::BattleObjectModuleAccessor, motion_kind: u64, ) -> Option { - if menu.TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if MENU.tech_state != NONE && is_training_mode() && is_operation_cpu(module_accessor) { if [hash40("passive_stand_f"), hash40("passive_stand_b")].contains(&motion_kind) { if app::sv_math::rand(hash40("fighter"), 2) != 0 { return Some(hash40("passive_stand_f")); From 4342f626f89fc524396b59e4d8539f35cb024c58 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 01:12:06 -0400 Subject: [PATCH 07/14] Move mash_attack_state from constants to an enum --- src/common/consts.rs | 70 ++++++++++++++++++++++++++++++++++-------- src/common/mod.rs | 2 +- src/lib.rs | 52 ++++++++++++++++--------------- src/training/mash.rs | 40 ++++++++++-------------- src/training/shield.rs | 8 +++-- 5 files changed, 109 insertions(+), 63 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index bde958a..683199f 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -1,3 +1,5 @@ +use smash::lib::lua_const::*; + pub const NONE: i32 = 0; // Side Taunt @@ -12,18 +14,60 @@ pub const NONE: i32 = 0; pub const DI_RANDOM_IN_AWAY: i32 = 9; // const std::vector di_items{"None", "Out", "Up Out", "Up", "Up In", "In", "Down In", "Down", "Down Out", "Random"}; -// Attack Option -pub const MASH_NAIR: i32 = 0; -pub const MASH_FAIR: i32 = 1; -pub const MASH_BAIR: i32 = 2; -pub const MASH_UPAIR: i32 = 3; -pub const MASH_DAIR: i32 = 4; -pub const MASH_NEUTRAL_B: i32 = 5; -pub const MASH_SIDE_B: i32 = 6; -pub const MASH_UP_B: i32 = 7; -pub const MASH_DOWN_B: i32 = 8; -pub const MASH_UP_SMASH: i32 = 9; -pub const MASH_GRAB: i32 = 10; +#[repr(i32)] +#[derive(PartialEq, Debug, Copy, Clone)] +pub enum Attack { + Nair = 0, + Fair = 1, + Bair = 2, + UpAir = 3, + Dair = 4, + NeutralB = 5, + SideB = 6, + UpB = 7, + DownB = 8, + UpSmash = 9, + Grab = 10 +} + +impl From for Attack { + fn from(x: i32) -> Self { + use Attack::*; + + match x { + 0 => Nair, + 1 => Fair, + 2 => Bair, + 3 => UpAir, + 4 => Dair, + 5 => NeutralB, + 6 => SideB, + 7 => UpB, + 8 => DownB, + 9 => UpSmash, + 10 => Grab, + _ => panic!("Invalid mash state {}", x) + } + } +} + +impl Attack { + pub fn into_attack_air_kind(&self) -> Option { + use Attack::*; + + Some( + match self { + Nair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_N, + Fair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_F, + Bair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_B, + Dair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_LW, + UpAir => *FIGHTER_COMMAND_ATTACK_AIR_KIND_HI, + _ => return None, + } + ) + } +} + // pub const std::vector attack_items{"Neutral Air", "Forward Air", "Back Air", "Up Air", "Down Air", "Neutral B", "Side B", "Up B", "Down B", "Up Smash", "Grab"}; // Ledge Option @@ -67,7 +111,7 @@ pub const DEFENSIVE_SHIELD: i32 = 5; pub struct TrainingModpackMenu { pub hitbox_vis: bool, pub di_state: i32, - pub attack_state: i32, + pub mash_attack_state: Attack, pub ledge_state: i32, pub tech_state: i32, pub mash_state: i32, diff --git a/src/common/mod.rs b/src/common/mod.rs index 4dd4fa5..5fc62fa 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -8,7 +8,7 @@ use smash::hash40; pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpackMenu { hitbox_vis: true, di_state: NONE, - attack_state: MASH_NAIR, + mash_attack_state: Attack::Nair, ledge_state: RANDOM_LEDGE, tech_state: RANDOM_TECH, mash_state: NONE, diff --git a/src/lib.rs b/src/lib.rs index e6e18a6..360ad1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ use smash::lua2cpp::L2CFighterCommon; pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue { let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); if is_training_mode() && is_operation_cpu(module_accessor) { - if MENU.mash_state == MASH_ATTACK && MENU.attack_state == MASH_GRAB { + if MENU.mash_state == MASH_ATTACK && MENU.mash_attack_state == Attack::Grab { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::get_int( module_accessor, @@ -54,33 +54,37 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } } - if MENU.mash_state == MASH_UP_B { - if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { - // if WorkModule::is_enable_transition_term( - // module_accessor, - // *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON, - // ) { - fighter.fighter_base.change_status( - L2CValue::new_int(*FIGHTER_STATUS_KIND_SPECIAL_HI as u64), - L2CValue::new_bool(false), - ); - // } + + if MENU.mash_state == MASH_ATTACK { + if MENU.mash_attack_state == Attack::UpB { + if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { + // if WorkModule::is_enable_transition_term( + // module_accessor, + // *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON, + // ) { + fighter.fighter_base.change_status( + L2CValue::new_int(*FIGHTER_STATUS_KIND_SPECIAL_HI as u64), + L2CValue::new_bool(false), + ); + // } + } } - } - if MENU.mash_state == MASH_UP_SMASH { - if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { - // if WorkModule::is_enable_transition_term( - // module_accessor, - // *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON, - // ) { - fighter.fighter_base.change_status( - L2CValue::new_int(*FIGHTER_STATUS_KIND_ATTACK_HI4_START as u64), - L2CValue::new_bool(false), - ); - // } + if MENU.mash_attack_state == Attack::UpSmash { + if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { + // if WorkModule::is_enable_transition_term( + // module_accessor, + // *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON, + // ) { + fighter.fighter_base.change_status( + L2CValue::new_int(*FIGHTER_STATUS_KIND_ATTACK_HI4_START as u64), + L2CValue::new_bool(false), + ); + // } + } } } } + original!()(fighter) } diff --git a/src/training/mash.rs b/src/training/mash.rs index 3c6acc3..ce7e924 100644 --- a/src/training/mash.rs +++ b/src/training/mash.rs @@ -9,22 +9,15 @@ pub unsafe fn get_attack_air_kind( ) -> Option { if is_training_mode() && is_operation_cpu(module_accessor) { if MENU.mash_state == MASH_ATTACK { - match MENU.attack_state { - MASH_NAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_N), - MASH_FAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_F), - MASH_BAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_B), - MASH_UPAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_HI), - MASH_DAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_LW), - _ => (), - } - } - - if MENU.mash_state == MASH_RANDOM { - return Some(app::sv_math::rand(hash40("fighter"), 5) + 1); + MENU.mash_attack_state.into_attack_air_kind() + } else if MENU.mash_state == MASH_RANDOM { + Some(app::sv_math::rand(hash40("fighter"), 5) + 1) + } else { + None } + } else { + None } - - None } pub unsafe fn get_command_flag_cat( @@ -56,21 +49,22 @@ pub unsafe fn get_command_flag_cat( } MASH_ATTACK => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { - match MENU.attack_state { - MASH_NAIR | MASH_FAIR | MASH_BAIR | MASH_UPAIR | MASH_DAIR => { + use Attack::*; + + match MENU.mash_attack_state { + Nair | Fair | Bair | UpAir | Dair => { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N; // If we are performing the attack OOS we also need to jump if is_in_shieldstun(module_accessor) { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_JUMP_BUTTON; } } - MASH_NEUTRAL_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_N, - MASH_SIDE_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_S, - MASH_UP_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_HI, - MASH_DOWN_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_LW, - MASH_UP_SMASH => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_HI4, - MASH_GRAB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_CATCH, - _ => (), + NeutralB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_N, + SideB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_S, + UpB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_HI, + DownB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_LW, + UpSmash => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_HI4, + Grab => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_CATCH, } } } diff --git a/src/training/shield.rs b/src/training/shield.rs index 0a82f62..c9fc086 100644 --- a/src/training/shield.rs +++ b/src/training/shield.rs @@ -43,14 +43,18 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc // We will only drop shield if we are in shieldstun and our attack can be performed OOS if MENU.mash_state == MASH_ATTACK { - if [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&MENU.attack_state) { + if [Attack::NeutralB, Attack::SideB, Attack::DownB].contains(&MENU.mash_attack_state) { return false; } - if [MASH_SPOTDODGE, MASH_GRAB].contains(&MENU.attack_state) { + if MENU.mash_attack_state == Attack::Grab { return true; } } + + if MENU.mash_state == MASH_SPOTDODGE { + return true; + } } false From f86415830d2ec705306bba614dca9ddb392f57b6 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 01:26:12 -0400 Subject: [PATCH 08/14] Move mash_state from set of constants to an enum --- src/common/consts.rs | 37 +++++++++++++++++++++++++++++-------- src/common/mod.rs | 2 +- src/lib.rs | 6 +++--- src/training/mash.rs | 16 ++++++++-------- src/training/shield.rs | 6 +++--- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index 683199f..89286c3 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -14,6 +14,7 @@ pub const NONE: i32 = 0; pub const DI_RANDOM_IN_AWAY: i32 = 9; // const std::vector di_items{"None", "Out", "Up Out", "Up", "Up In", "In", "Down In", "Down", "Down Out", "Random"}; +/// Mash Attack States #[repr(i32)] #[derive(PartialEq, Debug, Copy, Clone)] pub enum Attack { @@ -46,7 +47,7 @@ impl From for Attack { 8 => DownB, 9 => UpSmash, 10 => Grab, - _ => panic!("Invalid mash state {}", x) + _ => panic!("Invalid mash attack state {}", x) } } } @@ -86,12 +87,32 @@ pub const TECH_ROLL: i32 = 3; pub const TECH_MISS: i32 = 4; // pub const std::vector tech_items{"None", "Random", "In-Place", "Roll", "Miss Tech"}; -// Mash States -pub const MASH_AIRDODGE: i32 = 1; -pub const MASH_JUMP: i32 = 2; -pub const MASH_ATTACK: i32 = 3; -pub const MASH_SPOTDODGE: i32 = 4; -pub const MASH_RANDOM: i32 = 5; +/// Mash States +#[repr(i32)] +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum Mash { + None = 0, + Airdodge = 1, + Jump = 2, + Attack = 3, + Spotdodge = 4, + Random = 5 +} + +impl From for Mash { + fn from(x: i32) -> Self { + match x { + 0 => Mash::None, + 1 => Mash::Airdodge, + 2 => Mash::Jump, + 3 => Mash::Attack, + 4 => Mash::Spotdodge, + 5 => Mash::Random, + _ => panic!("Invalid mash state {}", x) + } + } +} + // pub const std::vector mash_items{"None", "Airdodge", "Jump", "Attack", "Spotdodge", "Random"}; // Shield States @@ -114,7 +135,7 @@ pub struct TrainingModpackMenu { pub mash_attack_state: Attack, pub ledge_state: i32, pub tech_state: i32, - pub mash_state: i32, + pub mash_state: Mash, pub shield_state: i32, pub defensive_state: i32, } diff --git a/src/common/mod.rs b/src/common/mod.rs index 5fc62fa..aad83d5 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -11,7 +11,7 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac mash_attack_state: Attack::Nair, ledge_state: RANDOM_LEDGE, tech_state: RANDOM_TECH, - mash_state: NONE, + mash_state: Mash::None, shield_state: NONE, defensive_state: RANDOM_DEFENSIVE, }; diff --git a/src/lib.rs b/src/lib.rs index 360ad1a..e52b74a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ use smash::lua2cpp::L2CFighterCommon; pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue { let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); if is_training_mode() && is_operation_cpu(module_accessor) { - if MENU.mash_state == MASH_ATTACK && MENU.mash_attack_state == Attack::Grab { + if MENU.mash_state == Mash::Attack && MENU.mash_attack_state == Attack::Grab { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::get_int( module_accessor, @@ -41,7 +41,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } } - if MENU.mash_state == MASH_SPOTDODGE { + if MENU.mash_state == Mash::Spotdodge { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { if WorkModule::is_enable_transition_term( module_accessor, @@ -55,7 +55,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue } } - if MENU.mash_state == MASH_ATTACK { + if MENU.mash_state == Mash::Attack { if MENU.mash_attack_state == Attack::UpB { if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE { // if WorkModule::is_enable_transition_term( diff --git a/src/training/mash.rs b/src/training/mash.rs index ce7e924..e479721 100644 --- a/src/training/mash.rs +++ b/src/training/mash.rs @@ -8,9 +8,9 @@ pub unsafe fn get_attack_air_kind( module_accessor: &mut app::BattleObjectModuleAccessor, ) -> Option { if is_training_mode() && is_operation_cpu(module_accessor) { - if MENU.mash_state == MASH_ATTACK { + if MENU.mash_state == Mash::Attack { MENU.mash_attack_state.into_attack_air_kind() - } else if MENU.mash_state == MASH_RANDOM { + } else if MENU.mash_state == Mash::Random { Some(app::sv_math::rand(hash40("fighter"), 5) + 1) } else { None @@ -31,23 +31,23 @@ pub unsafe fn get_command_flag_cat( || is_in_shieldstun(module_accessor) { match MENU.mash_state { - MASH_AIRDODGE => { + Mash::Airdodge => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_AIR_ESCAPE; } } - MASH_JUMP => { + Mash::Jump => { if !is_in_landing(module_accessor) && category == FIGHTER_PAD_COMMAND_CATEGORY1 { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_JUMP_BUTTON; } } - MASH_SPOTDODGE => { + Mash::Spotdodge => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE; } } - MASH_ATTACK => { + Mash::Attack => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { use Attack::*; @@ -68,7 +68,7 @@ pub unsafe fn get_command_flag_cat( } } } - MASH_RANDOM => { + Mash::Random => { if category == FIGHTER_PAD_COMMAND_CATEGORY1 { let situation_kind = StatusModule::situation_kind(module_accessor) as i32; @@ -133,7 +133,7 @@ pub unsafe fn check_button_on( ) -> Option { if [*CONTROL_PAD_BUTTON_GUARD_HOLD, *CONTROL_PAD_BUTTON_GUARD].contains(&button) { if is_training_mode() && is_operation_cpu(module_accessor) { - if MENU.mash_state == MASH_AIRDODGE + if MENU.mash_state == Mash::Airdodge && (is_in_hitstun(module_accessor) || is_in_landing(module_accessor)) { return Some(true); diff --git a/src/training/shield.rs b/src/training/shield.rs index c9fc086..49c2be7 100644 --- a/src/training/shield.rs +++ b/src/training/shield.rs @@ -33,7 +33,7 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc // We should hold shield if the state requires it if [SHIELD_HOLD, SHIELD_INFINITE].contains(&MENU.shield_state) { // If we are not mashing then we will always hold shield - if MENU.mash_state == NONE { + if MENU.mash_state == Mash::None { return true; } @@ -42,7 +42,7 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc } // We will only drop shield if we are in shieldstun and our attack can be performed OOS - if MENU.mash_state == MASH_ATTACK { + if MENU.mash_state == Mash::Attack { if [Attack::NeutralB, Attack::SideB, Attack::DownB].contains(&MENU.mash_attack_state) { return false; } @@ -52,7 +52,7 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc } } - if MENU.mash_state == MASH_SPOTDODGE { + if MENU.mash_state == Mash::Spotdodge { return true; } } From 95180e6364141934b0f98e848dcfcfe06565b5ba Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 01:45:35 -0400 Subject: [PATCH 09/14] Move shield_state from a group of consts to an enum --- src/common/consts.rs | 14 ++++++++++---- src/common/mod.rs | 2 +- src/hitbox_visualizer/mod.rs | 2 +- src/training/shield.rs | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index 89286c3..587e255 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -115,9 +115,15 @@ impl From for Mash { // pub const std::vector mash_items{"None", "Airdodge", "Jump", "Attack", "Spotdodge", "Random"}; -// Shield States -pub const SHIELD_INFINITE: i32 = 1; -pub const SHIELD_HOLD: i32 = 2; +/// Shield States +#[repr(i32)] +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum Shield { + None = 0, + Infinite = 1, + Hold = 2, +} + // pub const std::vector shield_items{"None", "Infinite", "Hold"}; // Defensive States @@ -136,6 +142,6 @@ pub struct TrainingModpackMenu { pub ledge_state: i32, pub tech_state: i32, pub mash_state: Mash, - pub shield_state: i32, + pub shield_state: Shield, pub defensive_state: i32, } diff --git a/src/common/mod.rs b/src/common/mod.rs index aad83d5..bff8dff 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -12,7 +12,7 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac ledge_state: RANDOM_LEDGE, tech_state: RANDOM_TECH, mash_state: Mash::None, - shield_state: NONE, + shield_state: Shield::None, defensive_state: RANDOM_DEFENSIVE, }; diff --git a/src/hitbox_visualizer/mod.rs b/src/hitbox_visualizer/mod.rs index 7aa1138..2c56512 100644 --- a/src/hitbox_visualizer/mod.rs +++ b/src/hitbox_visualizer/mod.rs @@ -232,7 +232,7 @@ unsafe fn handle_attack(lua_state: u64) { let z2 = l2c_agent.pop_lua_stack(15); // float or void // hacky way of forcing no shield damage on all hitboxes - if is_training_mode() && MENU.shield_state == SHIELD_INFINITE { + if is_training_mode() && MENU.shield_state == Shield::Infinite { let hitbox_params: Vec = (0..36).map(|i| l2c_agent.pop_lua_stack(i + 1)).collect(); l2c_agent.clear_lua_stack(); diff --git a/src/training/shield.rs b/src/training/shield.rs index 49c2be7..0aa70e9 100644 --- a/src/training/shield.rs +++ b/src/training/shield.rs @@ -10,7 +10,7 @@ pub unsafe fn get_param_float( param_hash: u64, ) -> Option { if is_training_mode() { - if MENU.shield_state == SHIELD_INFINITE { + if MENU.shield_state == Shield::Infinite { if param_type == hash40("common") { if param_hash == hash40("shield_dec1") { return Some(0.0); @@ -31,7 +31,7 @@ pub unsafe fn get_param_float( pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool { // We should hold shield if the state requires it - if [SHIELD_HOLD, SHIELD_INFINITE].contains(&MENU.shield_state) { + if [Shield::Hold, Shield::Infinite].contains(&MENU.shield_state) { // If we are not mashing then we will always hold shield if MENU.mash_state == Mash::None { return true; From eb03831d3c75a60825ab4bf003d0d81ac08bb625 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 01:49:22 -0400 Subject: [PATCH 10/14] Update ControlModule usage to compile with latest skyline_smash --- src/training/save_states.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/training/save_states.rs b/src/training/save_states.rs index 5fc2d50..f922fad 100644 --- a/src/training/save_states.rs +++ b/src/training/save_states.rs @@ -54,9 +54,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) } // Grab + Dpad up: reset state - if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH) != 0 + if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH) && ControlModule::check_button_trigger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_HI) - != 0 { if *save_state == NoAction { SAVE_STATE_PLAYER_STATE = CameraMove; @@ -150,9 +149,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) } // Grab + Dpad down: Save state - if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH) != 0 + if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH) && ControlModule::check_button_trigger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_LW) - != 0 { SAVE_STATE_PLAYER_STATE = Save; SAVE_STATE_CPU_STATE = Save; From cb3d829e03ed6859049614cc8b35fd427527696c Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 01:56:58 -0400 Subject: [PATCH 11/14] Move defensive_state from grouped constants to an enum --- src/common/consts.rs | 34 ++++++++++++++++++++++++++++------ src/common/mod.rs | 10 +++++----- src/training/ledge.rs | 2 +- src/training/tech.rs | 2 +- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index 587e255..369a1ec 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -127,11 +127,33 @@ pub enum Shield { // pub const std::vector shield_items{"None", "Infinite", "Hold"}; // Defensive States -pub const RANDOM_DEFENSIVE: i32 = 1; -pub const DEFENSIVE_SPOTDODGE: i32 = 2; -pub const DEFENSIVE_ROLL: i32 = 3; -pub const DEFENSIVE_JAB: i32 = 4; -pub const DEFENSIVE_SHIELD: i32 = 5; +#[repr(i32)] +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum Defensive { + None = 0, + Random = 1, + Spotdodge = 2, + Roll = 3, + Jab = 4, + Shield = 5, +} + +impl From for Defensive { + fn from(x: i32) -> Self { + use Defensive::*; + + match x { + 0 => None, + 1 => Random, + 2 => Spotdodge, + 3 => Roll, + 4 => Jab, + 5 => Shield, + _ => panic!("Invalid mash state {}", x) + } + } +} + // pub const std::vector defensive_items{"None", "Random", "Spotdodge", "Roll", "Jab", "Flash Shield"}; #[repr(C)] @@ -143,5 +165,5 @@ pub struct TrainingModpackMenu { pub tech_state: i32, pub mash_state: Mash, pub shield_state: Shield, - pub defensive_state: i32, + pub defensive_state: Defensive, } diff --git a/src/common/mod.rs b/src/common/mod.rs index bff8dff..aaecd77 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -13,7 +13,7 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac tech_state: RANDOM_TECH, mash_state: Mash::None, shield_state: Shield::None, - defensive_state: RANDOM_DEFENSIVE, + defensive_state: Defensive::Random, }; pub static MENU: &'static mut consts::TrainingModpackMenu = unsafe { &mut MENU_STRUCT }; @@ -77,7 +77,7 @@ pub unsafe fn perform_defensive_option( flag: &mut i32, ) { match MENU.defensive_state { - RANDOM_DEFENSIVE => { + Defensive::Random => { let random_cmds = vec![ *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE, *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F, @@ -89,15 +89,15 @@ pub unsafe fn perform_defensive_option( app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize; *flag |= random_cmds[random_cmd_index]; } - DEFENSIVE_ROLL => { + Defensive::Roll => { if app::sv_math::rand(hash40("fighter"), 2) == 0 { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F; } else { *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_B; } } - DEFENSIVE_SPOTDODGE => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE, - DEFENSIVE_JAB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N, + Defensive::Spotdodge => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE, + Defensive::Jab => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N, _ => (), } } diff --git a/src/training/ledge.rs b/src/training/ledge.rs index 9e4ec0b..6093067 100644 --- a/src/training/ledge.rs +++ b/src/training/ledge.rs @@ -88,7 +88,7 @@ pub unsafe fn check_button_on( if is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; - if MENU.defensive_state == DEFENSIVE_SHIELD + if MENU.defensive_state == Defensive::Shield && should_perform_defensive_option(module_accessor, prev_status, status) { return Some(true); diff --git a/src/training/tech.rs b/src/training/tech.rs index d972bdd..1bb402e 100644 --- a/src/training/tech.rs +++ b/src/training/tech.rs @@ -125,7 +125,7 @@ pub unsafe fn check_button_on( if is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; - if MENU.defensive_state == DEFENSIVE_SHIELD + if MENU.defensive_state == Defensive::Shield && should_perform_defensive_option(module_accessor, prev_status, status) { return Some(true); From 4d280043673a586f92188e5fb660e1c523a2b2ad Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 02:08:07 -0400 Subject: [PATCH 12/14] Move ledge_state from grouped consts to an enum --- src/common/consts.rs | 34 ++++++++++++++++++++++++++++------ src/common/mod.rs | 2 +- src/training/ledge.rs | 16 ++++++++-------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index 369a1ec..fd2c762 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -72,11 +72,33 @@ impl Attack { // pub const std::vector attack_items{"Neutral Air", "Forward Air", "Back Air", "Up Air", "Down Air", "Neutral B", "Side B", "Up B", "Down B", "Up Smash", "Grab"}; // Ledge Option -pub const RANDOM_LEDGE: i32 = 1; -pub const NEUTRAL_LEDGE: i32 = 2; -pub const ROLL_LEDGE: i32 = 3; -pub const JUMP_LEDGE: i32 = 4; -pub const ATTACK_LEDGE: i32 = 5; +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum LedgeOption { + None = 0, + Random = 1, + Neutral = 2, + Roll = 3, + Jump = 4, + Attack = 5, +} + +impl From for LedgeOption { + fn from(x: i32) -> Self { + use LedgeOption::*; + + match x { + 0 => None, + 1 => Random, + 2 => Neutral, + 3 => Roll, + 4 => Jump, + 5 => Attack, + _ => panic!("Invalid ledge option {}", x) + } + } +} + // pub const std::vector ledge_items{"None", "Random", "Ntrl. Getup", "Roll", "Jump", "Attack"}; // Tech Option @@ -161,7 +183,7 @@ pub struct TrainingModpackMenu { pub hitbox_vis: bool, pub di_state: i32, pub mash_attack_state: Attack, - pub ledge_state: i32, + pub ledge_state: LedgeOption, pub tech_state: i32, pub mash_state: Mash, pub shield_state: Shield, diff --git a/src/common/mod.rs b/src/common/mod.rs index aaecd77..a6d1ea9 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -9,7 +9,7 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac hitbox_vis: true, di_state: NONE, mash_attack_state: Attack::Nair, - ledge_state: RANDOM_LEDGE, + ledge_state: LedgeOption::Random, tech_state: RANDOM_TECH, mash_state: Mash::None, shield_state: Shield::None, diff --git a/src/training/ledge.rs b/src/training/ledge.rs index 6093067..50f5d64 100644 --- a/src/training/ledge.rs +++ b/src/training/ledge.rs @@ -18,19 +18,19 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor let frame = MotionModule::frame(module_accessor) as f32; if frame == random_frame || frame > 30.0 { let mut status = 0; - let ledge_case: i32; + let ledge_case: LedgeOption; - if MENU.ledge_state == RANDOM_LEDGE { - ledge_case = app::sv_math::rand(hash40("fighter"), 4) + 2; + if MENU.ledge_state == LedgeOption::Random { + ledge_case = (app::sv_math::rand(hash40("fighter"), 4) + 2).into(); } else { ledge_case = MENU.ledge_state; } match ledge_case { - NEUTRAL_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_CLIMB, - ROLL_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_ESCAPE, - JUMP_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_JUMP1, - ATTACK_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_ATTACK, + LedgeOption::Neutral => status = *FIGHTER_STATUS_KIND_CLIFF_CLIMB, + LedgeOption::Roll => status = *FIGHTER_STATUS_KIND_CLIFF_ESCAPE, + LedgeOption::Jump => status = *FIGHTER_STATUS_KIND_CLIFF_JUMP1, + LedgeOption::Attack => status = *FIGHTER_STATUS_KIND_CLIFF_ATTACK, _ => (), } @@ -104,7 +104,7 @@ pub unsafe fn get_command_flag_cat( category: i32, flag: &mut i32, ) { - if MENU.ledge_state != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if MENU.ledge_state != LedgeOption::None && is_training_mode() && is_operation_cpu(module_accessor) { force_option(module_accessor); defensive_option(module_accessor, category, flag); } From 78e53c29bd8350acaa064e3ef0e57a8ad61298c8 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 02:18:58 -0400 Subject: [PATCH 13/14] Move tech_state from grouped consts to an enum --- src/common/consts.rs | 55 ++++++++++++++++++++++++++++++------------- src/common/mod.rs | 2 +- src/training/ledge.rs | 8 ++----- src/training/tech.rs | 10 ++++---- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index fd2c762..6e71661 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -12,7 +12,6 @@ pub const NONE: i32 = 0; /* DI */ pub const DI_RANDOM_IN_AWAY: i32 = 9; -// const std::vector di_items{"None", "Out", "Up Out", "Up", "Up In", "In", "Down In", "Down", "Down Out", "Random"}; /// Mash Attack States #[repr(i32)] @@ -69,8 +68,6 @@ impl Attack { } } -// pub const std::vector attack_items{"Neutral Air", "Forward Air", "Back Air", "Up Air", "Down Air", "Neutral B", "Side B", "Up B", "Down B", "Up Smash", "Grab"}; - // Ledge Option #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq)] @@ -99,15 +96,45 @@ impl From for LedgeOption { } } -// pub const std::vector ledge_items{"None", "Random", "Ntrl. Getup", "Roll", "Jump", "Attack"}; +impl LedgeOption { + pub fn into_status(&self) -> Option { + Some( + match self { + LedgeOption::Neutral => status = *FIGHTER_STATUS_KIND_CLIFF_CLIMB, + LedgeOption::Roll => status = *FIGHTER_STATUS_KIND_CLIFF_ESCAPE, + LedgeOption::Jump => status = *FIGHTER_STATUS_KIND_CLIFF_JUMP1, + LedgeOption::Attack => status = *FIGHTER_STATUS_KIND_CLIFF_ATTACK, + _ => return None, + } + ) + } +} // Tech Option -pub const RANDOM_TECH: i32 = 1; -pub const TECH_IN_PLACE: i32 = 2; -pub const TECH_ROLL: i32 = 3; -#[allow(dead_code)] -pub const TECH_MISS: i32 = 4; -// pub const std::vector tech_items{"None", "Random", "In-Place", "Roll", "Miss Tech"}; +#[repr(i32)] +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum TechOption { + None = 0, + Random = 1, + InPlace = 2, + Roll = 3, + Miss = 4 +} + +impl From for TechOption { + fn from(x: i32) -> Self { + use TechOption::*; + + match x { + 0 => None, + 1 => Random, + 2 => InPlace, + 3 => Roll, + 4 => Miss, + _ => panic!("Invalid tech option {}", x) + } + } +} /// Mash States #[repr(i32)] @@ -135,8 +162,6 @@ impl From for Mash { } } -// pub const std::vector mash_items{"None", "Airdodge", "Jump", "Attack", "Spotdodge", "Random"}; - /// Shield States #[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq)] @@ -146,8 +171,6 @@ pub enum Shield { Hold = 2, } -// pub const std::vector shield_items{"None", "Infinite", "Hold"}; - // Defensive States #[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq)] @@ -176,15 +199,13 @@ impl From for Defensive { } } -// pub const std::vector defensive_items{"None", "Random", "Spotdodge", "Roll", "Jab", "Flash Shield"}; - #[repr(C)] pub struct TrainingModpackMenu { pub hitbox_vis: bool, pub di_state: i32, pub mash_attack_state: Attack, pub ledge_state: LedgeOption, - pub tech_state: i32, + pub tech_state: TechOption, pub mash_state: Mash, pub shield_state: Shield, pub defensive_state: Defensive, diff --git a/src/common/mod.rs b/src/common/mod.rs index a6d1ea9..fab2a5a 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -10,7 +10,7 @@ pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpac di_state: NONE, mash_attack_state: Attack::Nair, ledge_state: LedgeOption::Random, - tech_state: RANDOM_TECH, + tech_state: TechOption::Random, mash_state: Mash::None, shield_state: Shield::None, defensive_state: Defensive::Random, diff --git a/src/training/ledge.rs b/src/training/ledge.rs index 50f5d64..d60e1ac 100644 --- a/src/training/ledge.rs +++ b/src/training/ledge.rs @@ -26,12 +26,8 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor ledge_case = MENU.ledge_state; } - match ledge_case { - LedgeOption::Neutral => status = *FIGHTER_STATUS_KIND_CLIFF_CLIMB, - LedgeOption::Roll => status = *FIGHTER_STATUS_KIND_CLIFF_ESCAPE, - LedgeOption::Jump => status = *FIGHTER_STATUS_KIND_CLIFF_JUMP1, - LedgeOption::Attack => status = *FIGHTER_STATUS_KIND_CLIFF_ATTACK, - _ => (), + if let Some(new_status) = ledge_case.into_status() { + status = new_status; } StatusModule::change_status_request_from_script(module_accessor, status, true); diff --git a/src/training/tech.rs b/src/training/tech.rs index 1bb402e..dbcd753 100644 --- a/src/training/tech.rs +++ b/src/training/tech.rs @@ -11,7 +11,7 @@ pub unsafe fn init_settings( if is_training_mode() && is_operation_cpu(module_accessor) { if status_kind == FIGHTER_STATUS_KIND_DOWN { match MENU.tech_state { - RANDOM_TECH => { + TechOption::Random => { let random_statuses = vec![ *FIGHTER_STATUS_KIND_DOWN, *FIGHTER_STATUS_KIND_PASSIVE, @@ -30,7 +30,7 @@ pub unsafe fn init_settings( return Some(()); } } - TECH_IN_PLACE => { + TechOption::InPlace => { StatusModule::change_status_request_from_script( module_accessor, *FIGHTER_STATUS_KIND_PASSIVE, @@ -38,7 +38,7 @@ pub unsafe fn init_settings( ); return Some(()); } - TECH_ROLL => { + TechOption::Roll => { StatusModule::change_status_request_from_script( module_accessor, *FIGHTER_STATUS_KIND_PASSIVE_FB, @@ -89,7 +89,7 @@ pub unsafe fn get_command_flag_cat( _category: i32, flag: &mut i32, ) { - if MENU.tech_state != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if MENU.tech_state != TechOption::None && is_training_mode() && is_operation_cpu(module_accessor) { let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32; let status = StatusModule::status_kind(module_accessor) as i32; if [ @@ -140,7 +140,7 @@ pub unsafe fn change_motion( module_accessor: &mut app::BattleObjectModuleAccessor, motion_kind: u64, ) -> Option { - if MENU.tech_state != NONE && is_training_mode() && is_operation_cpu(module_accessor) { + if MENU.tech_state != TechOption::None && is_training_mode() && is_operation_cpu(module_accessor) { if [hash40("passive_stand_f"), hash40("passive_stand_b")].contains(&motion_kind) { if app::sv_math::rand(hash40("fighter"), 2) != 0 { return Some(hash40("passive_stand_f")); From a1a761889cf2a050164960d86aa01f1bc4c149fa Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 16 May 2020 02:27:14 -0400 Subject: [PATCH 14/14] Move DI selection from const to an enum --- src/common/consts.rs | 22 +++++++++++++--------- src/common/mod.rs | 2 +- src/training/directional_influence.rs | 7 ++++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/common/consts.rs b/src/common/consts.rs index 6e71661..b7dd199 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -1,7 +1,5 @@ use smash::lib::lua_const::*; -pub const NONE: i32 = 0; - // Side Taunt // DI @@ -10,8 +8,14 @@ pub const NONE: i32 = 0; 0, pi/4, pi/2, 3pi/4, pi, 5pi/4, 3pi/2, 7pi/4 */ -/* DI */ -pub const DI_RANDOM_IN_AWAY: i32 = 9; +/// DI +#[repr(i32)] +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum DirectionalInfluence { + None = 0, + // lol what goes here jug smh my head + RandomInAway = 9, +} /// Mash Attack States #[repr(i32)] @@ -100,10 +104,10 @@ impl LedgeOption { pub fn into_status(&self) -> Option { Some( match self { - LedgeOption::Neutral => status = *FIGHTER_STATUS_KIND_CLIFF_CLIMB, - LedgeOption::Roll => status = *FIGHTER_STATUS_KIND_CLIFF_ESCAPE, - LedgeOption::Jump => status = *FIGHTER_STATUS_KIND_CLIFF_JUMP1, - LedgeOption::Attack => status = *FIGHTER_STATUS_KIND_CLIFF_ATTACK, + LedgeOption::Neutral => *FIGHTER_STATUS_KIND_CLIFF_CLIMB, + LedgeOption::Roll => *FIGHTER_STATUS_KIND_CLIFF_ESCAPE, + LedgeOption::Jump => *FIGHTER_STATUS_KIND_CLIFF_JUMP1, + LedgeOption::Attack => *FIGHTER_STATUS_KIND_CLIFF_ATTACK, _ => return None, } ) @@ -202,7 +206,7 @@ impl From for Defensive { #[repr(C)] pub struct TrainingModpackMenu { pub hitbox_vis: bool, - pub di_state: i32, + pub di_state: DirectionalInfluence, pub mash_attack_state: Attack, pub ledge_state: LedgeOption, pub tech_state: TechOption, diff --git a/src/common/mod.rs b/src/common/mod.rs index fab2a5a..189a4b2 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -7,7 +7,7 @@ use smash::hash40; pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpackMenu { hitbox_vis: true, - di_state: NONE, + di_state: DirectionalInfluence::None, mash_attack_state: Attack::Nair, ledge_state: LedgeOption::Random, tech_state: TechOption::Random, diff --git a/src/training/directional_influence.rs b/src/training/directional_influence.rs index 7afc7d4..624270e 100644 --- a/src/training/directional_influence.rs +++ b/src/training/directional_influence.rs @@ -14,13 +14,14 @@ pub unsafe fn get_float( { if is_training_mode() && is_operation_cpu(module_accessor) && is_in_hitstun(module_accessor) { - if MENU.di_state != NONE { - let mut angle = (MENU.di_state - 1) as f64 * PI / 4.0; + if MENU.di_state != DirectionalInfluence::None { + let mut angle = (MENU.di_state as i32 - 1) as f64 * PI / 4.0; // Either 0 (right) or PI (left) - if MENU.di_state == DI_RANDOM_IN_AWAY { + if MENU.di_state == DirectionalInfluence::RandomInAway { angle = app::sv_math::rand(hash40("fighter"), 2) as f64 * PI; } + // If facing left, reverse angle if PostureModule::lr(module_accessor) != -1.0 { angle -= PI;