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);