diff --git a/Cargo.toml b/Cargo.toml index 130faf8..76573fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ nnsdk = { git = "https://github.com/ultimate-research/nnsdk-rs" } [profile.dev] panic = "abort" +lto = "off" [profile.release] panic = "abort" diff --git a/src/training/mod.rs b/src/training/mod.rs index 8bc1a36..2cd3fc6 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -759,7 +759,7 @@ pub unsafe fn handle_reused_ui( mut param_2: u32, // In Little Mac's case, the meter value as an integer ) { if !is_training_mode() { - original!()(fighter_data, param_2); + return original!()(fighter_data, param_2); } if save_states::is_loading() { diff --git a/src/training/save_states.rs b/src/training/save_states.rs index b2359aa..263fbb2 100644 --- a/src/training/save_states.rs +++ b/src/training/save_states.rs @@ -9,7 +9,7 @@ use smash::hash40; use smash::lib::lua_const::*; use smash::phx::{Hash40, Vector3f}; use std::ptr; -use training_mod_consts::{CharacterItem, SaveDamage}; +use training_mod_consts::{CharacterItem, SaveDamage, SaveStateSlot}; use SaveState::*; @@ -229,7 +229,8 @@ static mut MIRROR_STATE: f32 = 1.0; static mut RANDOM_SLOT: usize = 0; unsafe fn get_slot() -> usize { - if MENU.randomize_slots == OnOff::On { + let random_slot = MENU.randomize_slots.get_random(); + if random_slot != SaveStateSlot::empty() { RANDOM_SLOT } else { MENU.save_state_slot.as_idx() as usize @@ -449,8 +450,9 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) } if (autoload_reset || triggered_reset) && !fighter_is_nana { if save_state.state == NoAction { - let slot = if MENU.randomize_slots == OnOff::On { - RANDOM_SLOT = get_random_int(NUM_SAVE_STATE_SLOTS as i32) as usize; + let random_slot = MENU.randomize_slots.get_random(); + let slot = if random_slot != SaveStateSlot::empty() { + RANDOM_SLOT = random_slot.as_idx(); RANDOM_SLOT } else { selected_slot diff --git a/training_mod_consts/src/lib.rs b/training_mod_consts/src/lib.rs index f1b2e16..e86ffb7 100644 --- a/training_mod_consts/src/lib.rs +++ b/training_mod_consts/src/lib.rs @@ -54,7 +54,7 @@ pub struct TrainingModpackMenu { pub save_state_autoload: OnOff, pub save_state_enable: OnOff, pub save_state_slot: SaveStateSlot, - pub randomize_slots: OnOff, + pub randomize_slots: SaveStateSlot, pub save_state_mirroring: SaveStateMirroring, pub save_state_playback: PlaybackSlot, pub sdi_state: Direction, @@ -162,8 +162,8 @@ pub static DEFAULTS_MENU: TrainingModpackMenu = TrainingModpackMenu { save_damage_limits_player: DamagePercent::default(), save_state_autoload: OnOff::Off, save_state_enable: OnOff::On, - save_state_slot: SaveStateSlot::One, - randomize_slots: OnOff::Off, + save_state_slot: SaveStateSlot::S1, + randomize_slots: SaveStateSlot::empty(), save_state_mirroring: SaveStateMirroring::None, save_state_playback: PlaybackSlot::empty(), sdi_state: Direction::empty(), @@ -770,14 +770,14 @@ pub unsafe fn ui_menu(menu: TrainingModpackMenu) -> UiMenu { "save_state_slot".to_string(), "Save State Slot: Save and load states from different slots.".to_string(), true, - &(menu.save_state_slot as u32), + &(menu.save_state_slot.bits() as u32), ); - save_state_tab.add_submenu_with_toggles::( + save_state_tab.add_submenu_with_toggles::( "Randomize Slots".to_string(), "randomize_slots".to_string(), - "Randomize Slots: Randomize slot when loading save state.".to_string(), - true, - &(menu.randomize_slots as u32), + "Randomize Slots: Slots to randomize when loading save state.".to_string(), + false, + &(menu.randomize_slots.bits() as u32), ); save_state_tab.add_submenu_with_toggles::( "Character Item".to_string(), diff --git a/training_mod_consts/src/options.rs b/training_mod_consts/src/options.rs index f7ff546..cfaf8e3 100644 --- a/training_mod_consts/src/options.rs +++ b/training_mod_consts/src/options.rs @@ -1359,50 +1359,62 @@ impl fmt::Display for SaveDamage { extra_bitflag_impls! {SaveDamage} impl_serde_for_bitflags!(SaveDamage); -/// Save State Slots -#[repr(i32)] -#[derive( - Debug, Clone, Copy, PartialEq, FromPrimitive, EnumIter, Serialize_repr, Deserialize_repr, -)] -pub enum SaveStateSlot { - One = 0x0, - Two = 0x1, - Three = 0x2, - Four = 0x4, - Five = 0x8, +// Save State Slots +bitflags! { + pub struct SaveStateSlot : u32 + { + const S1 = 0x1; + const S2 = 0x2; + const S3 = 0x4; + const S4 = 0x8; + const S5 = 0x10; + } } impl SaveStateSlot { - pub fn as_idx(self) -> u32 { - log_2(self as i32 as u32) + pub fn into_idx(self) -> Option { + Some(match self { + SaveStateSlot::S1 => 0, + SaveStateSlot::S2 => 1, + SaveStateSlot::S3 => 2, + SaveStateSlot::S4 => 3, + SaveStateSlot::S5 => 4, + _ => return None, + }) + } + + pub fn as_idx(self) -> usize { + match self { + SaveStateSlot::S1 => 0, + SaveStateSlot::S2 => 1, + SaveStateSlot::S3 => 2, + SaveStateSlot::S4 => 3, + SaveStateSlot::S5 => 4, + _ => 0, + } } } impl fmt::Display for SaveStateSlot { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let combination_string = self.combination_string(); write!( f, "{}", match *self { - SaveStateSlot::One => "1", - SaveStateSlot::Two => "2", - SaveStateSlot::Three => "3", - SaveStateSlot::Four => "4", - SaveStateSlot::Five => "5", + SaveStateSlot::S1 => "1", + SaveStateSlot::S2 => "2", + SaveStateSlot::S3 => "3", + SaveStateSlot::S4 => "4", + SaveStateSlot::S5 => "5", + _ => combination_string.as_str(), } ) } } -impl ToggleTrait for SaveStateSlot { - fn to_toggle_vals() -> Vec { - SaveStateSlot::iter().map(|i| i as u32).collect() - } - - fn to_toggle_strings() -> Vec { - SaveStateSlot::iter().map(|i| i.to_string()).collect() - } -} +extra_bitflag_impls! {SaveStateSlot} +impl_serde_for_bitflags!(SaveStateSlot); // Input Recording Slot #[repr(u32)]