1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-28 04:44:06 +00:00
This commit is contained in:
jugeeya 2020-05-16 12:31:42 -07:00
parent af54cd90bb
commit c43da06180
5 changed files with 125 additions and 129 deletions

10
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,10 @@
{
"rust-analyzer.checkOnSave.overrideCommand": [
"xargo",
"check",
"--workspace",
"--message-format=json",
"--all-features"
],
"rust-analyzer.updates.channel": "nightly",
}

View file

@ -6,93 +6,19 @@ mod common;
mod hitbox_visualizer; mod hitbox_visualizer;
mod training; mod training;
use crate::common::consts::*;
use crate::common::*; use crate::common::*;
use skyline::c_str; use skyline::c_str;
use skyline::libc::{c_void, mkdir, fclose, fopen, fwrite}; use skyline::libc::{c_void, mkdir, fclose, fopen, fwrite};
use skyline::nro::{self, NroInfo}; use skyline::nro::{self, NroInfo};
use smash::app::lua_bind::*;
use smash::app::sv_system;
use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_sub_guard_cont)]
pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue {
let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent);
if is_training_mode() && is_operation_cpu(module_accessor) {
if MENU.mash_state == Mash::Attack && MENU.mash_attack_state == Attack::Grab {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
if WorkModule::get_int(
module_accessor,
*FIGHTER_INSTANCE_WORK_ID_INT_INVALID_CATCH_FRAME,
) == 0
{
if WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_CATCH,
) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_CATCH as u64),
L2CValue::new_bool(true),
);
}
}
}
}
if MENU.mash_state == Mash::Spotdodge {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
if WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ESCAPE,
) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_ESCAPE as u64),
L2CValue::new_bool(true),
);
}
}
}
if MENU.mash_state == Mash::Attack {
if MENU.mash_attack_state == Attack::UpB {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
// if WorkModule::is_enable_transition_term(
// module_accessor,
// *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON,
// ) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_SPECIAL_HI as u64),
L2CValue::new_bool(false),
);
// }
}
}
if MENU.mash_attack_state == Attack::UpSmash {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
// if WorkModule::is_enable_transition_term(
// module_accessor,
// *FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON,
// ) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_ATTACK_HI4_START as u64),
L2CValue::new_bool(false),
);
// }
}
}
}
}
original!()(fighter)
}
fn nro_main(nro: &NroInfo<'_>) { fn nro_main(nro: &NroInfo<'_>) {
match nro.name { match nro.name {
"common" => { "common" => {
println!("Loaded common NRO!"); skyline::install_hooks!(
skyline::install_hook!(handle_sub_guard_cont); training::shield::handle_sub_guard_cont,
training::directional_influence::handle_correct_damage_vector_common,
);
} }
_ => (), _ => (),
} }
@ -100,14 +26,14 @@ fn nro_main(nro: &NroInfo<'_>) {
#[skyline::main(name = "training_modpack")] #[skyline::main(name = "training_modpack")]
pub fn main() { pub fn main() {
println!("Training modpack initialized."); println!("[Training Modpack] Initialized.");
hitbox_visualizer::hitbox_visualization(); hitbox_visualizer::hitbox_visualization();
training::training_mods(); training::training_mods();
nro::add_hook(nro_main).unwrap(); nro::add_hook(nro_main).unwrap();
unsafe { unsafe {
let buffer = format!("{:x}", MENU as *const _ as u64); let buffer = format!("{:x}", MENU as *const _ as u64);
println!("Writing training_modpack.log with {}...\n", buffer); println!("[Training Modpack] Writing training_modpack.log with {}...", buffer);
mkdir("sd:/TrainingModpack/\u{0}".as_bytes().as_ptr(), 0777); mkdir("sd:/TrainingModpack/\u{0}".as_bytes().as_ptr(), 0777);
let f = fopen( let f = fopen(
"sd:/TrainingModpack/training_modpack.log\u{0}".as_bytes().as_ptr(), "sd:/TrainingModpack/training_modpack.log\u{0}".as_bytes().as_ptr(),

View file

@ -1,42 +1,43 @@
use crate::common::consts::*;
use crate::common::*; use crate::common::*;
use crate::common::consts::*;
use core::f64::consts::PI; use core::f64::consts::PI;
use smash::app::{self, lua_bind::*}; use smash::app::{self, sv_system, lua_bind::*};
use smash::hash40; use smash::hash40;
use smash::lib::lua_const::*; use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
pub unsafe fn get_float( pub static mut DI_ANGLE : f64 = 0.0;
module_accessor: &mut app::BattleObjectModuleAccessor, pub static NO_DI : f64 = -69.0;
var: i32,
) -> Option<f32> {
if var == FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X
|| var == FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y
{
if is_training_mode() && is_operation_cpu(module_accessor) && is_in_hitstun(module_accessor)
{
if MENU.di_state != DirectionalInfluence::None {
let mut angle = (MENU.di_state as i32 - 1) as f64 * PI / 4.0;
#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_FighterStatusDamage__correctDamageVectorCommon)]
pub unsafe fn handle_correct_damage_vector_common(fighter: &mut L2CFighterCommon, arg1: L2CValue) -> L2CValue {
let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent);
if is_training_mode() && is_operation_cpu(module_accessor) {
if MENU.di_state != DirectionalInfluence::None {
DI_ANGLE = (MENU.di_state as i32 - 1) as f64 * PI / 4.0;
// Either left, right, or none
if MENU.di_state == DirectionalInfluence::RandomInAway {
let rand = app::sv_math::rand(hash40("fighter"), 3) ;
// Either 0 (right) or PI (left) // Either 0 (right) or PI (left)
if MENU.di_state == DirectionalInfluence::RandomInAway { if [0, 1].contains(&rand) {
angle = app::sv_math::rand(hash40("fighter"), 2) as f64 * PI; DI_ANGLE = rand as f64 * PI;
} else {
DI_ANGLE = NO_DI;
} }
}
// If facing left, reverse angle
if DI_ANGLE != NO_DI && PostureModule::lr(module_accessor) != -1.0 {
DI_ANGLE -= PI;
}
// If facing left, reverse angle if DI_ANGLE != NO_DI {
if PostureModule::lr(module_accessor) != -1.0 { WorkModule::set_float(module_accessor, DI_ANGLE.cos() as f32, *FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X);
angle -= PI; WorkModule::set_float(module_accessor, DI_ANGLE.sin() as f32, *FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y);
}
if var == FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X {
return Some(angle.cos() as f32);
}
if var == FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y {
return Some(angle.sin() as f32);
}
} }
} }
} }
None original!()(fighter, arg1)
} }

View file

@ -3,22 +3,13 @@ use crate::hitbox_visualizer;
use skyline::{c_str, nn::ro::LookupSymbol}; use skyline::{c_str, nn::ro::LookupSymbol};
use smash::app::{self, lua_bind::*}; use smash::app::{self, lua_bind::*};
mod directional_influence; pub mod directional_influence;
mod ledge; mod ledge;
mod mash; mod mash;
mod save_states; mod save_states;
mod shield; pub mod shield;
mod tech; mod tech;
#[skyline::hook(replace = WorkModule::get_float)]
pub unsafe fn handle_get_float(
module_accessor: &mut app::BattleObjectModuleAccessor,
var: i32,
) -> f32 {
directional_influence::get_float(module_accessor, var)
.unwrap_or_else(|| original!()(module_accessor, var))
}
#[skyline::hook(replace = WorkModule::get_param_float)] #[skyline::hook(replace = WorkModule::get_param_float)]
pub unsafe fn handle_get_param_float( pub unsafe fn handle_get_param_float(
module_accessor: &mut app::BattleObjectModuleAccessor, module_accessor: &mut app::BattleObjectModuleAccessor,
@ -191,7 +182,7 @@ pub fn training_mods() {
handle_get_command_flag_cat, handle_get_command_flag_cat,
// Set DI // Set DI
handle_get_float, // handle_get_float,
// Hold/Infinite shield // Hold/Infinite shield
handle_check_button_on, handle_check_button_on,

View file

@ -3,6 +3,10 @@ use crate::common::*;
use smash::app; use smash::app;
use smash::hash40; use smash::hash40;
use smash::lib::lua_const::*; use smash::lib::lua_const::*;
use smash::app::lua_bind::*;
use smash::app::sv_system;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
pub unsafe fn get_param_float( pub unsafe fn get_param_float(
_module_accessor: &mut app::BattleObjectModuleAccessor, _module_accessor: &mut app::BattleObjectModuleAccessor,
@ -32,8 +36,8 @@ pub unsafe fn get_param_float(
pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool { pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
// We should hold shield if the state requires it // We should hold shield if the state requires it
if [Shield::Hold, Shield::Infinite].contains(&MENU.shield_state) { if [Shield::Hold, Shield::Infinite].contains(&MENU.shield_state) {
// If we are not mashing then we will always hold shield // If we are not mashing attack then we will always hold shield
if MENU.mash_state == Mash::None { if MENU.mash_state != Mash::Attack {
return true; return true;
} }
@ -45,21 +49,85 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc
if MENU.mash_state == Mash::Attack { if MENU.mash_state == Mash::Attack {
if [Attack::NeutralB, Attack::SideB, Attack::DownB].contains(&MENU.mash_attack_state) { if [Attack::NeutralB, Attack::SideB, Attack::DownB].contains(&MENU.mash_attack_state) {
return false; return false;
} } else {
if MENU.mash_attack_state == Attack::Grab {
return true; return true;
} }
} }
if MENU.mash_state == Mash::Spotdodge {
return true;
}
} }
false false
} }
#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_sub_guard_cont)]
pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue {
let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent);
if is_training_mode() && is_operation_cpu(module_accessor) {
if MENU.mash_state == Mash::Attack && MENU.mash_attack_state == Attack::Grab {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
if WorkModule::get_int(
module_accessor,
*FIGHTER_INSTANCE_WORK_ID_INT_INVALID_CATCH_FRAME,
) == 0
{
if WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_CATCH,
) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_CATCH as u64),
L2CValue::new_bool(true),
);
}
}
}
}
if MENU.mash_state == Mash::Spotdodge {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
if WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_ESCAPE,
) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_ESCAPE as u64),
L2CValue::new_bool(true),
);
}
}
}
if MENU.mash_state == Mash::Attack {
if MENU.mash_attack_state == Attack::UpB {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
if WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON,
) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_SPECIAL_HI as u64),
L2CValue::new_bool(false),
);
}
}
}
if MENU.mash_attack_state == Attack::UpSmash {
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
if WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_CONT_JUMP_SQUAT_BUTTON,
) {
fighter.fighter_base.change_status(
L2CValue::new_int(*FIGHTER_STATUS_KIND_ATTACK_HI4_START as u64),
L2CValue::new_bool(false),
);
}
}
}
}
}
original!()(fighter)
}
pub unsafe fn check_button_on( pub unsafe fn check_button_on(
module_accessor: &mut app::BattleObjectModuleAccessor, module_accessor: &mut app::BattleObjectModuleAccessor,
button: i32, button: i32,