From 345fd619a16c98f266aa01e74526aa7b0946c651 Mon Sep 17 00:00:00 2001 From: jugeeya Date: Fri, 20 Aug 2021 18:48:40 +0000 Subject: [PATCH] use nn_hid hook for compatibility with results screen skip --- .cargo/config | 2 -- Cargo.toml | 2 ++ src/training/input_delay.rs | 36 +++++++++++++++------------- src/training/mod.rs | 48 +++++-------------------------------- 4 files changed, 28 insertions(+), 60 deletions(-) delete mode 100644 .cargo/config diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index 49f3dc5..0000000 --- a/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "aarch64-skyline-switch" diff --git a/Cargo.toml b/Cargo.toml index 7d3a081..ec4d3c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ num-traits = "0.2" wsl = "0.1.0" strum = "0.21.0" strum_macros = "0.21.0" +rand = { git = "https://github.com/skyline-rs/rand" } [profile.dev] panic = "abort" @@ -38,6 +39,7 @@ 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" }, { name = "libparam_hook.nro", url = "https://github.com/ultimate-research/params-hook-plugin/releases/download/v0.1.1/libparam_hook.nro" }, + { name = "libnn_hid_hook.nro", url = "https://github.com/jugeeya/nn-hid-hook/releases/download/beta/libnn_hid_hook.nro" } ] [features] diff --git a/src/training/input_delay.rs b/src/training/input_delay.rs index 32d6764..0e44927 100644 --- a/src/training/input_delay.rs +++ b/src/training/input_delay.rs @@ -23,25 +23,29 @@ pub unsafe fn p1_controller_id() -> u32 { } } -pub unsafe fn handle_get_npad_state( +pub fn handle_get_npad_state( state: *mut NpadHandheldState, controller_id: *const u32, ) { - if *controller_id == p1_controller_id() { - let mut delayed_states = P1_DELAYED_NPAD_STATES.lock(); - let actual_state = *state; + unsafe { + if crate::common::is_training_mode() { + if *controller_id == p1_controller_id() { + let mut delayed_states = P1_DELAYED_NPAD_STATES.lock(); + let actual_state = *state; - if delayed_states.len() < MENU.input_delay as usize { - let update_count = (*state).updateCount; - *state = NpadHandheldState::default(); - (*state).updateCount = update_count; - } else if let Some(delayed_state) = delayed_states.back() { - let update_count = (*state).updateCount; - *state = *delayed_state; - (*state).updateCount = update_count; + if delayed_states.len() < MENU.input_delay as usize { + let update_count = (*state).updateCount; + *state = NpadHandheldState::default(); + (*state).updateCount = update_count; + } else if let Some(delayed_state) = delayed_states.back() { + let update_count = (*state).updateCount; + *state = *delayed_state; + (*state).updateCount = update_count; + } + + delayed_states.push_front(actual_state); + delayed_states.truncate(MENU.input_delay as usize); + } } - - delayed_states.push_front(actual_state); - delayed_states.truncate(MENU.input_delay as usize); } -} +} \ No newline at end of file diff --git a/src/training/mod.rs b/src/training/mod.rs index 9dab3dd..3182112 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -289,52 +289,16 @@ fn params_main(params_info: &ParamsInfo<'_>) { } } -macro_rules! create_nn_hid_hooks { - ( - $( - ($func:ident, $hook:ident) - ),* - ) => { - $( - #[allow(non_snake_case)] - #[skyline::hook(replace = $func)] - pub unsafe fn $hook( - state: *mut skyline::nn::hid::NpadHandheldState, - controller_id: *const u32, - ) { - original!()(state, controller_id); - if is_training_mode() { - input_delay::handle_get_npad_state(state, controller_id); - /* TODO: - 1) make number of frames configurable - 2) make possible without a second controller plugged in - **/ - // input_record::handle_get_npad_state(state, controller_id); - } - } - )* - }; -} - -create_nn_hid_hooks!( - (GetNpadHandheldState, handle_get_npad_handheld_state), - (GetNpadFullKeyState, handle_get_npad_full_key_state), - (GetNpadGcState, handle_get_npad_gc_state), - (GetNpadJoyDualState, handle_get_joy_dual_state), - (GetNpadJoyLeftState, handle_get_joy_left_state), - (GetNpadJoyRightState, handle_get_joy_right_state)); - pub fn training_mods() { println!("[Training Modpack] Applying training mods."); // Input Recording/Delay - skyline::install_hooks!( - handle_get_npad_handheld_state, - handle_get_npad_full_key_state, - handle_get_npad_gc_state, - handle_get_joy_dual_state, - handle_get_joy_left_state, - handle_get_joy_right_state); + unsafe { + if (add_nn_hid_hook as *const ()).is_null() { + panic!("The NN-HID hook plugin could not be found and is required to add NRO hooks. Make sure libnn_hid_hook.nro is installed."); + } + add_nn_hid_hook(input_delay::handle_get_npad_state); + } unsafe { LookupSymbol(