mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-24 10:54:16 +00:00
use nn_hid hook for compatibility with results screen skip
This commit is contained in:
parent
7a3df98df7
commit
345fd619a1
4 changed files with 28 additions and 60 deletions
|
@ -1,2 +0,0 @@
|
|||
[build]
|
||||
target = "aarch64-skyline-switch"
|
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue