1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-03-20 05:16:11 +00:00
UltimateTrainingModpack/src/training/sdi.rs
Chris McDonald 5b2e4c7319
Add rustfmt CI checker and format (#518)
* Add rustfmt CI checker

Minimal checker that just runs `cargo fmt --check` on all targets.

* rustfmt
2023-04-11 14:56:14 -07:00

55 lines
1.5 KiB
Rust

use core::f64::consts::PI;
use smash::app::{self, lua_bind::*};
use smash::Vector2f;
use crate::common::consts::*;
use crate::common::*;
use crate::training::directional_influence;
static mut COUNTER: u32 = 0;
static mut DIRECTION: Direction = Direction::NEUTRAL;
pub fn roll_direction() {
unsafe {
COUNTER = 0;
DIRECTION = MENU.sdi_state.get_random();
}
}
unsafe fn get_sdi_direction() -> Option<f64> {
DIRECTION.into_angle().map(|angle| {
if directional_influence::should_reverse_angle(&DIRECTION) {
PI - angle
} else {
angle
}
})
}
#[skyline::hook(replace = FighterControlModuleImpl::check_hit_stop_delay_command)]
pub unsafe fn check_hit_stop_delay_command(
module_accessor: &mut app::BattleObjectModuleAccessor,
sdi_direction: *mut Vector2f,
) -> u64 {
// Function returns 1 if there is an SDI input, 0 is there is not
if !is_training_mode() || !is_operation_cpu(module_accessor) {
return original!()(module_accessor, sdi_direction);
}
let repeat = MENU.sdi_strength.into_u32();
COUNTER = (COUNTER + 1) % repeat;
if COUNTER == repeat - 1 {
if let Some(angle) = get_sdi_direction() {
// If there is a non-neutral direction picked,
// modify the SDI angle Vector2f as a side-effect
// and return 1 so the CPU knows that an SDI input occurred
(*sdi_direction).x = angle.cos() as f32;
(*sdi_direction).y = angle.sin() as f32;
return 1;
}
}
0
}