diff --git a/src/common/button_config.rs b/src/common/button_config.rs index b4f6675..7a42ef1 100644 --- a/src/common/button_config.rs +++ b/src/common/button_config.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use crate::common::*; use crate::input::{ControllerStyle::*, *}; +use crate::training::frame_counter; use crate::training::ui::menu::VANILLA_MENU_ACTIVE; use lazy_static::lazy_static; @@ -136,7 +137,7 @@ pub fn handle_final_input_mapping(player_idx: i32, controller_struct: &mut SomeC let p1_controller = &mut *controller_struct.controller; let mut start_menu_request = false; - let menu_close_wait_frame = unsafe { *menu::VISUAL_FRAME_COUNTER.data_ptr() }; + let menu_close_wait_frame = frame_counter::get_frame_count(*menu::MENU_CLOSE_FRAME_COUNTER); if unsafe { MENU.menu_open_start_press == OnOff::On } { let start_hold_frames = &mut *START_HOLD_FRAMES.lock(); if p1_controller.current_buttons.plus() { diff --git a/src/common/menu.rs b/src/common/menu.rs index 56ba6e6..4e327ec 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -1,6 +1,6 @@ +use once_cell::sync::Lazy; use std::collections::HashMap; use std::fs; -use std::sync::Lazy; use lazy_static::lazy_static; use parking_lot::Mutex; @@ -14,6 +14,7 @@ use crate::consts::MENU_OPTIONS_PATH; use crate::events::{Event, EVENT_QUEUE}; use crate::input::*; use crate::logging::*; +use crate::training::frame_counter; pub const MENU_CLOSE_WAIT_FRAMES: u32 = 15; pub static mut QUICK_MENU_ACTIVE: bool = false; @@ -112,9 +113,8 @@ lazy_static! { }; } -static MENU_CLOSE_FRAME_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::Real) -}); +pub static MENU_CLOSE_FRAME_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::Real)); pub fn handle_final_input_mapping( player_idx: i32, diff --git a/src/training/buff.rs b/src/training/buff.rs index 7ea9109..afd8634 100644 --- a/src/training/buff.rs +++ b/src/training/buff.rs @@ -6,7 +6,7 @@ use crate::is_operation_cpu; use crate::training::frame_counter; use crate::training::handle_add_limit; -use std::sync::Lazy; +use once_cell::sync::Lazy; static mut BUFF_REMAINING_PLAYER: i32 = 0; static mut BUFF_REMAINING_CPU: i32 = 0; @@ -14,9 +14,8 @@ static mut BUFF_REMAINING_CPU: i32 = 0; static mut IS_BUFFING_PLAYER: bool = false; static mut IS_BUFFING_CPU: bool = false; -static BUFF_DELAY_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static BUFF_DELAY_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); pub unsafe fn restart_buff(module_accessor: &mut app::BattleObjectModuleAccessor) { if is_operation_cpu(module_accessor) { diff --git a/src/training/combo.rs b/src/training/combo.rs index 5c50ecd..f440a90 100644 --- a/src/training/combo.rs +++ b/src/training/combo.rs @@ -5,7 +5,7 @@ use crate::common::consts::FighterId; use crate::common::*; use crate::training::*; -use std::sync::Lazy; +use once_cell::sync::Lazy; pub static mut FRAME_ADVANTAGE: i32 = 0; static mut PLAYER_ACTIONABLE: bool = false; @@ -14,9 +14,8 @@ static mut PLAYER_ACTIVE_FRAME: u32 = 0; static mut CPU_ACTIVE_FRAME: u32 = 0; static mut FRAME_ADVANTAGE_CHECK: bool = false; -static FRAME_COUNTER_INDEX: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static FRAME_COUNTER_INDEX: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); unsafe fn _was_in_hitstun(module_accessor: *mut app::BattleObjectModuleAccessor) -> bool { let prev_status = StatusModule::prev_status_kind(module_accessor, 0); diff --git a/src/training/fast_fall.rs b/src/training/fast_fall.rs index 6caecf6..fd90437 100644 --- a/src/training/fast_fall.rs +++ b/src/training/fast_fall.rs @@ -5,7 +5,7 @@ use smash::phx::{Hash40, Vector3f}; use crate::common::*; use crate::training::{frame_counter, input_record}; -use std::sync::Lazy; +use once_cell::sync::Lazy; // The current fastfall delay static mut DELAY: u32 = 0; @@ -22,9 +22,8 @@ pub fn roll_fast_fall() { } } -static FRAME_COUNTER_INDEX: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static FRAME_COUNTER_INDEX: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); pub fn get_command_flag_cat(module_accessor: &mut app::BattleObjectModuleAccessor) { if !should_fast_fall() { diff --git a/src/training/frame_counter.rs b/src/training/frame_counter.rs index 2be5cb2..a34ba6d 100644 --- a/src/training/frame_counter.rs +++ b/src/training/frame_counter.rs @@ -1,9 +1,10 @@ +#[derive(PartialEq, Eq)] pub enum FrameCounterType { InGame, // "Reset" occurs when we enter training mode and when we run L+R+A or save state load // Some frame counters need in-game frames that do not reset when this occurs InGameNoReset, - Real + Real, } pub struct FrameCounter { @@ -18,11 +19,11 @@ pub fn register_counter(counter_type: FrameCounterType) -> usize { unsafe { let index = COUNTERS.len(); - COUNTERS.push(FrameCounter{ + COUNTERS.push(FrameCounter { count: 0, should_count: false, - counter_type: counter_type - }) + counter_type, + }); index } @@ -97,7 +98,10 @@ pub fn tick_ingame() { pub fn tick_real() { unsafe { for (index, counter) in COUNTERS.iter().enumerate() { - if !counter.should_count || (counter.counter_type == FrameCounterType::InGame || counter.counter_type == FrameCounterType::InGameNoReset) { + if !counter.should_count + || (counter.counter_type == FrameCounterType::InGame + || counter.counter_type == FrameCounterType::InGameNoReset) + { continue; } tick_idx(index); diff --git a/src/training/ledge.rs b/src/training/ledge.rs index bd1f53a..af61b7c 100644 --- a/src/training/ledge.rs +++ b/src/training/ledge.rs @@ -5,17 +5,14 @@ use crate::common::consts::*; use crate::common::*; use crate::training::{frame_counter, input_record, mash}; -use std::sync::Lazy; +use once_cell::sync::Lazy; const NOT_SET: u32 = 9001; static mut LEDGE_DELAY: u32 = NOT_SET; -static mut LEDGE_DELAY_COUNTER: usize = 0; static mut LEDGE_CASE: LedgeOption = LedgeOption::empty(); -static LEDGE_DELAY_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); - +static LEDGE_DELAY_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); pub fn reset_ledge_delay() { unsafe { diff --git a/src/training/mash.rs b/src/training/mash.rs index cf8c18b..d1d63b0 100644 --- a/src/training/mash.rs +++ b/src/training/mash.rs @@ -11,6 +11,8 @@ use crate::training::input_record; use crate::training::shield; use crate::training::{attack_angle, save_states}; +use once_cell::sync::Lazy; + const DISTANCE_CLOSE_THRESHOLD: f32 = 16.0; const DISTANCE_MID_THRESHOLD: f32 = 37.0; const DISTANCE_FAR_THRESHOLD: f32 = 64.0; @@ -22,9 +24,8 @@ static mut FALLING_AERIAL: bool = false; static mut AERIAL_DELAY: u32 = 0; -static AERIAL_DELAY_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static AERIAL_DELAY_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); // Track if we're about to do another command flag cat run in the same frame for a dash or dash attack static mut IS_TRANSITIONING_DASH: bool = false; diff --git a/src/training/mod.rs b/src/training/mod.rs index 783f1d7..955e6da 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -676,7 +676,7 @@ static OPCF_OFFSET: usize = 0x06b7fdc; // One instruction after the CPU Control function completes #[skyline::hook(offset = OPCF_OFFSET, inline)] unsafe fn handle_once_per_cpu_frame(_ctx: &mut InlineCtx) { - frame_counter::tick(); + frame_counter::tick_ingame(); // Tick notifications let queue = &mut ui::notifications::QUEUE; let notification = queue.first(); @@ -806,15 +806,7 @@ pub fn training_mods() { handle_final_input_mapping ); - combo::init(); - shield::init(); - fast_fall::init(); - mash::init(); - ledge::init(); - throw::init(); - buff::init(); items::init(); - tech::init(); input_record::init(); ui::init(); } diff --git a/src/training/shield.rs b/src/training/shield.rs index fd7b48b..5aec36a 100644 --- a/src/training/shield.rs +++ b/src/training/shield.rs @@ -10,7 +10,7 @@ use crate::common::consts::*; use crate::common::*; use crate::training::{frame_counter, input_record, mash, save_states}; -use std::sync::Lazy; +use once_cell::sync::Lazy; // How many hits to hold shield until picking an Out Of Shield option static mut MULTI_HIT_OFFSET: u32 = 0; @@ -24,9 +24,8 @@ static mut WAS_IN_SHIELDSTUN: bool = false; // For how many frames should the shield hold be overwritten static mut SUSPEND_SHIELD: bool = false; -static REACTION_COUNTER_INDEX: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static REACTION_COUNTER_INDEX: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); // Toggle for shield decay static mut SHIELD_DECAY: bool = false; diff --git a/src/training/tech.rs b/src/training/tech.rs index 26d7bd4..0185181 100644 --- a/src/training/tech.rs +++ b/src/training/tech.rs @@ -8,14 +8,13 @@ use crate::common::consts::*; use crate::common::*; use crate::training::{frame_counter, mash}; -use std::sync::Lazy; +use once_cell::sync::Lazy; static mut TECH_ROLL_DIRECTION: Direction = Direction::empty(); static mut MISS_TECH_ROLL_DIRECTION: Direction = Direction::empty(); -static FRAME_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static FRAME_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); unsafe fn is_enable_passive(module_accessor: &mut BattleObjectModuleAccessor) -> bool { let fighter = get_fighter_common_from_accessor(module_accessor); diff --git a/src/training/throw.rs b/src/training/throw.rs index 2fb9e32..159fb5c 100644 --- a/src/training/throw.rs +++ b/src/training/throw.rs @@ -6,17 +6,17 @@ use crate::common::*; use crate::training::frame_counter; use crate::training::mash; +use once_cell::sync::Lazy; + const NOT_SET: u32 = 9001; static mut THROW_DELAY: u32 = NOT_SET; -static mut THROW_DELAY_COUNTER: usize = 0; +static mut PUMMEL_DELAY: u32 = NOT_SET; static mut THROW_CASE: ThrowOption = ThrowOption::empty(); -static THROW_DELAY_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); -static PUMMEL_DELAY_COUNTER: Lazy = Lazy::new(|| { - frame_counter::register_counter(frame_counter::FrameCounterType::InGame) -}); +static THROW_DELAY_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); +static PUMMEL_DELAY_COUNTER: Lazy = + Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGame)); // Rolling Throw Delays and Pummel Delays separately diff --git a/src/training/ui/menu.rs b/src/training/ui/menu.rs index 2ed356a..22a2d69 100644 --- a/src/training/ui/menu.rs +++ b/src/training/ui/menu.rs @@ -6,9 +6,8 @@ use smash::ui2d::{SmashPane, SmashTextBox}; use training_mod_tui::gauge::GaugeState; use training_mod_tui::{App, AppPage, NUM_LISTS}; -use crate::common::menu::{ - MENU_CLOSE_WAIT_FRAMES, MENU_CLOSE_FRAME_COUNTER, -}; +use crate::common::menu::{MENU_CLOSE_FRAME_COUNTER, MENU_CLOSE_WAIT_FRAMES}; +use crate::training::frame_counter; use crate::{common, common::menu::QUICK_MENU_ACTIVE, input::*}; use super::fade_out; diff --git a/src/training/ui/mod.rs b/src/training/ui/mod.rs index 2b0d7c8..b00e413 100644 --- a/src/training/ui/mod.rs +++ b/src/training/ui/mod.rs @@ -4,9 +4,12 @@ use sarc::SarcFile; use skyline::nn::ui2d::*; use training_mod_consts::{OnOff, MENU}; -use crate::common::{is_ready_go, is_training_mode, menu::QUICK_MENU_ACTIVE}; #[cfg(feature = "layout_arc_from_file")] use crate::consts::LAYOUT_ARC_PATH; +use crate::{ + common::{is_ready_go, is_training_mode, menu::QUICK_MENU_ACTIVE}, + training::frame_counter, +}; mod damage; mod display;