From e7ec867581242872e17b0d0232a7481f019e7908 Mon Sep 17 00:00:00 2001 From: jugeeya Date: Fri, 7 Aug 2020 17:42:14 -0700 Subject: [PATCH] fix frame advantage buffer bug --- Cargo.toml | 4 +++ src/training/combo.rs | 68 ++++++++++++++++++++++++++++++++++--------- src/training/mod.rs | 14 +++++++++ 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa26978..bff1fb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,7 @@ lto = true [package.metadata.skyline] titleid = "01006A800016E000" +plugin-dependencies = [ + { name = "libnro_hook.nro", url = "https://github.com/ultimate-research/nro-hook-plugin/releases/download/v0.1.1/libnro_hook.nro" }, +] + diff --git a/src/training/combo.rs b/src/training/combo.rs index 44ff313..0e6c206 100644 --- a/src/training/combo.rs +++ b/src/training/combo.rs @@ -37,20 +37,62 @@ unsafe fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectMo app::sv_battle_object::module_accessor(current_fighter_id as u32) } +macro_rules! actionable_statuses { + () => { + vec![ + FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ESCAPE_AIR, + FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ATTACK_AIR, + FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_GUARD_ON, + FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ESCAPE + ]; + }; +} + unsafe fn is_actionable(module_accessor: *mut app::BattleObjectModuleAccessor) -> bool { - WorkModule::is_enable_transition_term( - module_accessor, - *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ESCAPE_AIR, - ) || WorkModule::is_enable_transition_term( - module_accessor, - *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ATTACK_AIR, - ) || WorkModule::is_enable_transition_term( - module_accessor, - *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_GUARD_ON, - ) || WorkModule::is_enable_transition_term( - module_accessor, - *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ESCAPE, - ) || CancelModule::is_enable_cancel(module_accessor) + actionable_statuses!().iter().any( + |actionable_transition| + WorkModule::is_enable_transition_term(module_accessor, **actionable_transition)) + || CancelModule::is_enable_cancel(module_accessor) +} + +pub unsafe fn is_enable_transition_term( + module_accessor: *mut app::BattleObjectModuleAccessor, + transition_term: i32, + is: bool +) { + let entry_id_int = + WorkModule::get_int(module_accessor, *FIGHTER_INSTANCE_WORK_ID_INT_ENTRY_ID) as i32; + + if entry_id_int != (FighterId::Player as i32) { + return; + } + + // Extra check later in the frame. + // This is in the case that the transition term becomes enabled after our initial check + // and the user buffers that action on that frame. + + if !PLAYER_ACTIONABLE && + ( + (is && actionable_statuses!().iter().any(|actionable_transition| *actionable_transition == transition_term)) + || + (CancelModule::is_enable_cancel(module_accessor)) + ) { + PLAYER_ACTIVE_FRAME = frame_counter::get_frame_count(FRAME_COUNTER_INDEX); + PLAYER_ACTIONABLE = true; + + // if both are now active + if PLAYER_ACTIONABLE && CPU_ACTIONABLE { + if FRAME_ADVANTAGE_CHECK { + let cpu_module_accessor = get_module_accessor(FighterId::CPU); + if was_in_hitstun(cpu_module_accessor) || was_in_shieldstun(cpu_module_accessor) { + FRAME_ADVANTAGE = (CPU_ACTIVE_FRAME as i64 - PLAYER_ACTIVE_FRAME as i64) as i32; + } + + frame_counter::stop_counting(FRAME_COUNTER_INDEX); + FRAME_ADVANTAGE_CHECK = false; + } + } + } } pub unsafe fn get_command_flag_cat( diff --git a/src/training/mod.rs b/src/training/mod.rs index cd5d454..6109d50 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -196,6 +196,18 @@ pub unsafe fn handle_change_motion( ) } +#[skyline::hook(replace = WorkModule::is_enable_transition_term)] +pub unsafe fn handle_is_enable_transition_term( + module_accessor: *mut app::BattleObjectModuleAccessor, + transition_term: i32 +) -> bool { + let is = original!()(module_accessor, transition_term); + + combo::is_enable_transition_term(module_accessor, transition_term, is); + + is +} + pub fn training_mods() { println!("[Training Modpack] Applying training mods."); unsafe { @@ -230,6 +242,8 @@ pub fn training_mods() { // Directional AirDodge, get_stick_x, get_stick_y, + // Combo + handle_is_enable_transition_term, ); combo::init();