1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-24 10:54:16 +00:00

Merge pull request #57 from jam1garner/master

Refactor to Make Codebase More Idiomatic
This commit is contained in:
jugeeya 2020-05-16 11:02:08 -07:00 committed by GitHub
commit af54cd90bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 413 additions and 374 deletions

View file

@ -1,4 +1,4 @@
pub const NONE: i32 = 0;
use smash::lib::lua_const::*;
// Side Taunt
@ -8,69 +8,209 @@ pub const NONE: i32 = 0;
0, pi/4, pi/2, 3pi/4, pi, 5pi/4, 3pi/2, 7pi/4
*/
/* DI */
pub static mut DI_STATE: i32 = NONE;
pub const DI_RANDOM_IN_AWAY: i32 = 9;
// const std::vector<std::string> di_items{"None", "Out", "Up Out", "Up", "Up In", "In", "Down In", "Down", "Down Out", "Random"};
/// DI
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DirectionalInfluence {
None = 0,
// lol what goes here jug smh my head
RandomInAway = 9,
}
// Attack Option
pub const MASH_NAIR: i32 = 0;
pub const MASH_FAIR: i32 = 1;
pub const MASH_BAIR: i32 = 2;
pub const MASH_UPAIR: i32 = 3;
pub const MASH_DAIR: i32 = 4;
pub const MASH_NEUTRAL_B: i32 = 5;
pub const MASH_SIDE_B: i32 = 6;
pub const MASH_UP_B: i32 = 7;
pub const MASH_DOWN_B: i32 = 8;
pub const MASH_UP_SMASH: i32 = 9;
pub const MASH_GRAB: i32 = 10;
// pub const std::vector<std::string> attack_items{"Neutral Air", "Forward Air", "Back Air", "Up Air", "Down Air", "Neutral B", "Side B", "Up B", "Down B", "Up Smash", "Grab"};
/// Mash Attack States
#[repr(i32)]
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum Attack {
Nair = 0,
Fair = 1,
Bair = 2,
UpAir = 3,
Dair = 4,
NeutralB = 5,
SideB = 6,
UpB = 7,
DownB = 8,
UpSmash = 9,
Grab = 10
}
impl From<i32> for Attack {
fn from(x: i32) -> Self {
use Attack::*;
match x {
0 => Nair,
1 => Fair,
2 => Bair,
3 => UpAir,
4 => Dair,
5 => NeutralB,
6 => SideB,
7 => UpB,
8 => DownB,
9 => UpSmash,
10 => Grab,
_ => panic!("Invalid mash attack state {}", x)
}
}
}
impl Attack {
pub fn into_attack_air_kind(&self) -> Option<i32> {
use Attack::*;
Some(
match self {
Nair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_N,
Fair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_F,
Bair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_B,
Dair => *FIGHTER_COMMAND_ATTACK_AIR_KIND_LW,
UpAir => *FIGHTER_COMMAND_ATTACK_AIR_KIND_HI,
_ => return None,
}
)
}
}
// Ledge Option
pub const RANDOM_LEDGE: i32 = 1;
pub const NEUTRAL_LEDGE: i32 = 2;
pub const ROLL_LEDGE: i32 = 3;
pub const JUMP_LEDGE: i32 = 4;
pub const ATTACK_LEDGE: i32 = 5;
// pub const std::vector<std::string> ledge_items{"None", "Random", "Ntrl. Getup", "Roll", "Jump", "Attack"};
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum LedgeOption {
None = 0,
Random = 1,
Neutral = 2,
Roll = 3,
Jump = 4,
Attack = 5,
}
impl From<i32> for LedgeOption {
fn from(x: i32) -> Self {
use LedgeOption::*;
match x {
0 => None,
1 => Random,
2 => Neutral,
3 => Roll,
4 => Jump,
5 => Attack,
_ => panic!("Invalid ledge option {}", x)
}
}
}
impl LedgeOption {
pub fn into_status(&self) -> Option<i32> {
Some(
match self {
LedgeOption::Neutral => *FIGHTER_STATUS_KIND_CLIFF_CLIMB,
LedgeOption::Roll => *FIGHTER_STATUS_KIND_CLIFF_ESCAPE,
LedgeOption::Jump => *FIGHTER_STATUS_KIND_CLIFF_JUMP1,
LedgeOption::Attack => *FIGHTER_STATUS_KIND_CLIFF_ATTACK,
_ => return None,
}
)
}
}
// Tech Option
pub const RANDOM_TECH: i32 = 1;
pub const TECH_IN_PLACE: i32 = 2;
pub const TECH_ROLL: i32 = 3;
pub const TECH_MISS: i32 = 4;
// pub const std::vector<std::string> tech_items{"None", "Random", "In-Place", "Roll", "Miss Tech"};
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TechOption {
None = 0,
Random = 1,
InPlace = 2,
Roll = 3,
Miss = 4
}
// Mash States
pub const MASH_AIRDODGE: i32 = 1;
pub const MASH_JUMP: i32 = 2;
pub const MASH_ATTACK: i32 = 3;
pub const MASH_SPOTDODGE: i32 = 4;
pub const MASH_RANDOM: i32 = 5;
// pub const std::vector<std::string> mash_items{"None", "Airdodge", "Jump", "Attack", "Spotdodge", "Random"};
impl From<i32> for TechOption {
fn from(x: i32) -> Self {
use TechOption::*;
// Shield States
pub const SHIELD_INFINITE: i32 = 1;
pub const SHIELD_HOLD: i32 = 2;
// pub const std::vector<std::string> shield_items{"None", "Infinite", "Hold"};
match x {
0 => None,
1 => Random,
2 => InPlace,
3 => Roll,
4 => Miss,
_ => panic!("Invalid tech option {}", x)
}
}
}
/// Mash States
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Mash {
None = 0,
Airdodge = 1,
Jump = 2,
Attack = 3,
Spotdodge = 4,
Random = 5
}
impl From<i32> for Mash {
fn from(x: i32) -> Self {
match x {
0 => Mash::None,
1 => Mash::Airdodge,
2 => Mash::Jump,
3 => Mash::Attack,
4 => Mash::Spotdodge,
5 => Mash::Random,
_ => panic!("Invalid mash state {}", x)
}
}
}
/// Shield States
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Shield {
None = 0,
Infinite = 1,
Hold = 2,
}
// Defensive States
pub const RANDOM_DEFENSIVE: i32 = 1;
pub const DEFENSIVE_SPOTDODGE: i32 = 2;
pub const DEFENSIVE_ROLL: i32 = 3;
pub const DEFENSIVE_JAB: i32 = 4;
pub const DEFENSIVE_SHIELD: i32 = 5;
// pub const std::vector<std::string> defensive_items{"None", "Random", "Spotdodge", "Roll", "Jab", "Flash Shield"};
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Defensive {
None = 0,
Random = 1,
Spotdodge = 2,
Roll = 3,
Jab = 4,
Shield = 5,
}
impl From<i32> for Defensive {
fn from(x: i32) -> Self {
use Defensive::*;
match x {
0 => None,
1 => Random,
2 => Spotdodge,
3 => Roll,
4 => Jab,
5 => Shield,
_ => panic!("Invalid mash state {}", x)
}
}
}
#[repr(C)]
pub struct TrainingModpackMenu {
pub HITBOX_VIS: bool,
pub DI_STATE: i32,
pub ATTACK_STATE: i32,
pub LEDGE_STATE: i32,
pub TECH_STATE: i32,
pub MASH_STATE: i32,
pub SHIELD_STATE: i32,
pub DEFENSIVE_STATE: i32,
pub hitbox_vis: bool,
pub di_state: DirectionalInfluence,
pub mash_attack_state: Attack,
pub ledge_state: LedgeOption,
pub tech_state: TechOption,
pub mash_state: Mash,
pub shield_state: Shield,
pub defensive_state: Defensive,
}

View file

@ -1,32 +1,31 @@
pub mod consts;
use crate::common::consts::*;
use smash::app::lua_bind::*;
use smash::app::{self};
use smash::app::{self, lua_bind::*};
use smash::lib::lua_const::*;
// use smash::app::{FighterManager, FighterInformation};
use smash::hash40;
pub static mut menu_struct: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
HITBOX_VIS: true,
DI_STATE: NONE,
ATTACK_STATE: MASH_NAIR,
LEDGE_STATE: RANDOM_LEDGE,
TECH_STATE: RANDOM_TECH,
MASH_STATE: NONE,
SHIELD_STATE: NONE,
DEFENSIVE_STATE: RANDOM_DEFENSIVE,
pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
hitbox_vis: true,
di_state: DirectionalInfluence::None,
mash_attack_state: Attack::Nair,
ledge_state: LedgeOption::Random,
tech_state: TechOption::Random,
mash_state: Mash::None,
shield_state: Shield::None,
defensive_state: Defensive::Random,
};
pub static mut menu: *mut consts::TrainingModpackMenu = 0 as *mut consts::TrainingModpackMenu;
pub static MENU: &'static mut consts::TrainingModpackMenu = unsafe { &mut MENU_STRUCT };
pub static mut fighter_manager_addr: usize = 0;
pub static mut FIGHTER_MANAGER_ADDR: usize = 0;
extern "C" {
#[link_name = "\u{1}_ZN3app9smashball16is_training_modeEv"]
pub fn is_training_mode() -> bool;
#[link_name = "\u{1}_ZN3app7utility8get_kindEPKNS_26BattleObjectModuleAccessorE"]
pub fn get_kind(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32;
//#[link_name = "\u{1}_ZN3app7utility8get_kindEPKNS_26BattleObjectModuleAccessorE"]
//pub fn get_kind(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32;
}
pub fn get_category(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32 {
@ -40,7 +39,7 @@ pub unsafe fn is_operation_cpu(module_accessor: &mut app::BattleObjectModuleAcce
let entry_id_int =
WorkModule::get_int(module_accessor, *FIGHTER_INSTANCE_WORK_ID_INT_ENTRY_ID) as i32;
let entry_id = app::FighterEntryID(entry_id_int);
let _entry_id = app::FighterEntryID(entry_id_int);
// let mut mgr = FighterManager{_address : fighter_manager_addr as u64};
// let fighter_information = lua_bind::FighterManager::get_fighter_information(&mut mgr, entry_id) as *mut FighterInformation;
// println!("FighterInformation: {:#?}", fighter_information);
@ -74,11 +73,11 @@ pub unsafe fn is_in_landing(module_accessor: &mut app::BattleObjectModuleAccesso
}
pub unsafe fn perform_defensive_option(
module_accessor: &mut app::BattleObjectModuleAccessor,
_module_accessor: &mut app::BattleObjectModuleAccessor,
flag: &mut i32,
) {
match (*menu).DEFENSIVE_STATE {
RANDOM_DEFENSIVE => {
match MENU.defensive_state {
Defensive::Random => {
let random_cmds = vec![
*FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE,
*FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F,
@ -90,15 +89,15 @@ pub unsafe fn perform_defensive_option(
app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize;
*flag |= random_cmds[random_cmd_index];
}
DEFENSIVE_ROLL => {
Defensive::Roll => {
if app::sv_math::rand(hash40("fighter"), 2) == 0 {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_F;
} else {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE_B;
}
}
DEFENSIVE_SPOTDODGE => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE,
DEFENSIVE_JAB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N,
Defensive::Spotdodge => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE,
Defensive::Jab => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N,
_ => (),
}
}

View file

@ -1,88 +1,9 @@
use crate::common::*;
use crate::common::consts::*;
use smash::app::lua_bind::*;
use smash::app::sv_animcmd::{self};
use smash::app::sv_system::{self};
use smash::app::{self};
use crate::common::{*, consts::*};
use smash::app::{self, lua_bind::*, sv_animcmd, sv_system};
use smash::hash40;
use smash::lib::lua_const::*;
use smash::lib::{L2CAgent, L2CValue};
use smash::lib::{lua_const::*, L2CAgent, L2CValue};
use smash::phx::{Hash40, Vector3f};
/**
* Rounds a number to the nearest multiple of another number.
*/
pub fn round_to(val: f32, align: f32) -> f32 {
(val / align).round() * align
}
/**
* Linearly interpolates between two numbers, without bounds checking.
*/
pub fn lerp(min: f32, max: f32, t: f32) -> f32 {
min + (max - min) * t
}
pub fn unlerp(min: f32, max: f32, val: f32) -> f32 {
(val - min) / (max - min)
}
/**
* Linearly interpolates between two numbers, with bounds checking.
*/
pub fn lerp_bounded(min: f32, max: f32, t: f32) -> f32 {
if t <= 0.0 {
min
} else {
if t >= 1.0 {
max
} else {
lerp(min, max, t)
}
}
}
pub fn unlerp_bounded(min: f32, max: f32, val: f32) -> f32 {
if val <= min {
0.0
} else {
if val >= max {
1.0
} else {
unlerp(min, max, val)
}
}
}
/**
* Linearly interpolates between two colors, with bounds checking, accounting for
* gamma. arguments:
* - min_color (Vector3f) -- xyz maps to rgb, components are usually in the
* range [0.0f, 1.0f] but can go beyond to account for super-bright or
* super-dark colors
* - max_Color (Vector3f) -- same as minColor
* - t (float) -- how far to interpolate between the colors
* - gamma (float = 2.0f) -- used for color correction, helps avoid ugly dark
* colors when interpolating b/t bright colors
*/
pub fn color_lerp(min_color: Vector3f, max_color: Vector3f, t: f32, gamma: f32) -> Vector3f {
let gamma_inv = 1.0 / gamma;
let align = 1.0 / 255.0; // color components must be a multiple of 1/255
Vector3f {
x: round_to(
lerp_bounded(min_color.x.powf(gamma), max_color.x.powf(gamma), t).powf(gamma_inv),
align,
),
y: round_to(
lerp_bounded(min_color.y.powf(gamma), max_color.y.powf(gamma), t).powf(gamma_inv),
align,
),
z: round_to(
lerp_bounded(min_color.z.powf(gamma), max_color.z.powf(gamma), t).powf(gamma_inv),
align,
),
}
}
pub const ID_COLORS: &[Vector3f] = &[
// used to tint the hitbox effects -- make sure that at least one component
// is equal to 1.0
@ -141,18 +62,18 @@ pub unsafe fn generate_hitbox_effects(
z2: Option<f32>,
color: Vector3f,
) {
let red = L2CValue::new_num(color.x);
let green = L2CValue::new_num(color.y);
let blue = L2CValue::new_num(color.z);
let _red = L2CValue::new_num(color.x);
let _green = L2CValue::new_num(color.y);
let _blue = L2CValue::new_num(color.z);
let size_mult = 19.0 / 200.0;
let shield_effect = L2CValue::new_int(hash40("sys_shield"));
let zero_rot = L2CValue::new_num(0.0);
let terminate = L2CValue::new_bool(true);
let effect_size = L2CValue::new_num(size * size_mult);
let _shield_effect = L2CValue::new_int(hash40("sys_shield"));
let _zero_rot = L2CValue::new_num(0.0);
let _terminate = L2CValue::new_bool(true);
let _effect_size = L2CValue::new_num(size * size_mult);
let rate = L2CValue::new_num(8.0);
let _rate = L2CValue::new_num(8.0);
let x_dist: f32;
let y_dist: f32;
@ -233,11 +154,11 @@ pub unsafe fn get_command_flag_cat(
// Pause Effect AnimCMD if hitbox visualization is active
MotionAnimcmdModule::set_sleep_effect(
module_accessor,
(*menu).HITBOX_VIS,
MENU.hitbox_vis,
);
// apply only once per frame
if category == 0 && is_training_mode() && (*menu).HITBOX_VIS {
if category == 0 && is_training_mode() && MENU.hitbox_vis {
let status_kind = StatusModule::status_kind(module_accessor) as i32;
if !(*FIGHTER_STATUS_KIND_CATCH..=*FIGHTER_STATUS_KIND_CATCH_TURN).contains(&status_kind)
@ -290,7 +211,6 @@ pub unsafe fn get_command_flag_cat(
}
// Necessary to ensure we visualize on the first frame of the hitbox
#[allow(unused_unsafe)]
#[skyline::hook(replace = sv_animcmd::ATTACK)]
unsafe fn handle_attack(lua_state: u64) {
let mut l2c_agent = L2CAgent::new(lua_state);
@ -298,11 +218,11 @@ unsafe fn handle_attack(lua_state: u64) {
// get all necessary grabbox params
let id = l2c_agent.pop_lua_stack(1); // int
let joint = l2c_agent.pop_lua_stack(3); // hash40
let damage = l2c_agent.pop_lua_stack(4); // float
let _damage = l2c_agent.pop_lua_stack(4); // float
let _angle = l2c_agent.pop_lua_stack(5); // int
let kbg = l2c_agent.pop_lua_stack(6); // int
let fkb = l2c_agent.pop_lua_stack(7); // int
let bkb = l2c_agent.pop_lua_stack(8); // int
let _kbg = l2c_agent.pop_lua_stack(6); // int
let _fkb = l2c_agent.pop_lua_stack(7); // int
let _bkb = l2c_agent.pop_lua_stack(8); // int
let size = l2c_agent.pop_lua_stack(9); // float
let x = l2c_agent.pop_lua_stack(10); // float
let y = l2c_agent.pop_lua_stack(11); // float
@ -312,7 +232,7 @@ unsafe fn handle_attack(lua_state: u64) {
let z2 = l2c_agent.pop_lua_stack(15); // float or void
// hacky way of forcing no shield damage on all hitboxes
if is_training_mode() && (*menu).SHIELD_STATE == SHIELD_INFINITE {
if is_training_mode() && MENU.shield_state == Shield::Infinite {
let hitbox_params: Vec<L2CValue> =
(0..36).map(|i| l2c_agent.pop_lua_stack(i + 1)).collect();
l2c_agent.clear_lua_stack();
@ -328,7 +248,7 @@ unsafe fn handle_attack(lua_state: u64) {
original!()(lua_state);
if (*menu).HITBOX_VIS && is_training_mode() {
if MENU.hitbox_vis && is_training_mode() {
generate_hitbox_effects(
sv_system::battle_object_module_accessor(lua_state),
joint.get_int(),
@ -344,7 +264,6 @@ unsafe fn handle_attack(lua_state: u64) {
}
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = sv_animcmd::CATCH)]
unsafe fn handle_catch(lua_state: u64) {
let mut l2c_agent = L2CAgent::new(lua_state);
@ -362,7 +281,7 @@ unsafe fn handle_catch(lua_state: u64) {
original!()(lua_state);
if (*menu).HITBOX_VIS && is_training_mode() {
if MENU.hitbox_vis && is_training_mode() {
generate_hitbox_effects(
sv_system::battle_object_module_accessor(lua_state),
joint.get_int(),
@ -383,7 +302,6 @@ pub unsafe fn is_shielding(module_accessor: *mut app::BattleObjectModuleAccessor
(*FIGHTER_STATUS_KIND_GUARD_ON..=*FIGHTER_STATUS_KIND_GUARD_DAMAGE).contains(&status_kind)
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = GrabModule::set_rebound)]
pub unsafe fn handle_set_rebound(
module_accessor: *mut app::BattleObjectModuleAccessor,
@ -415,7 +333,9 @@ pub unsafe fn handle_set_rebound(
pub fn hitbox_visualization() {
println!("Applying hitbox visualization mods.");
skyline::install_hook!(handle_attack);
skyline::install_hook!(handle_catch);
skyline::install_hook!(handle_set_rebound);
skyline::install_hooks!(
handle_attack,
handle_catch,
handle_set_rebound
);
}

View file

@ -1,9 +1,6 @@
#![feature(proc_macro_hygiene)]
#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![feature(with_options)]
#![feature(const_mut_refs)]
mod common;
mod hitbox_visualizer;
@ -16,17 +13,16 @@ use skyline::c_str;
use skyline::libc::{c_void, mkdir, fclose, fopen, fwrite};
use skyline::nro::{self, NroInfo};
use smash::app::lua_bind::*;
use smash::app::sv_system::{self};
use smash::app::sv_system;
use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
#[allow(unused_unsafe)]
#[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).ATTACK_STATE == MASH_GRAB {
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,
@ -45,7 +41,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue
}
}
}
if (*menu).MASH_STATE == MASH_SPOTDODGE {
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,
@ -58,37 +54,41 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue
}
}
}
if (*menu).MASH_STATE == MASH_UP_B {
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_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_STATE == MASH_UP_SMASH {
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),
);
// }
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 {
"common" => {
println!("Loaded common NRO!");
@ -106,8 +106,7 @@ pub fn main() {
nro::add_hook(nro_main).unwrap();
unsafe {
common::menu = &mut common::menu_struct;
let buffer = format!("{:x}", common::menu as u64);
let buffer = format!("{:x}", MENU as *const _ as u64);
println!("Writing training_modpack.log with {}...\n", buffer);
mkdir("sd:/TrainingModpack/\u{0}".as_bytes().as_ptr(), 0777);
let f = fopen(

View file

@ -1,8 +1,7 @@
use crate::common::consts::*;
use crate::common::*;
use core::f64::consts::PI;
use smash::app::lua_bind::*;
use smash::app::{self};
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
@ -15,13 +14,14 @@ pub unsafe fn get_float(
{
if is_training_mode() && is_operation_cpu(module_accessor) && is_in_hitstun(module_accessor)
{
if (*menu).DI_STATE != NONE {
let mut angle = ((*menu).DI_STATE - 1) as f64 * PI / 4.0;
if MENU.di_state != DirectionalInfluence::None {
let mut angle = (MENU.di_state as i32 - 1) as f64 * PI / 4.0;
// Either 0 (right) or PI (left)
if (*menu).DI_STATE == DI_RANDOM_IN_AWAY {
if MENU.di_state == DirectionalInfluence::RandomInAway {
angle = app::sv_math::rand(hash40("fighter"), 2) as f64 * PI;
}
// If facing left, reverse angle
if PostureModule::lr(module_accessor) != -1.0 {
angle -= PI;

View file

@ -1,7 +1,6 @@
use crate::common::consts::*;
use crate::common::*;
use smash::app::lua_bind::*;
use smash::app::{self};
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
@ -19,20 +18,16 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
let frame = MotionModule::frame(module_accessor) as f32;
if frame == random_frame || frame > 30.0 {
let mut status = 0;
let ledge_case: i32;
let ledge_case: LedgeOption;
if (*menu).LEDGE_STATE == RANDOM_LEDGE {
ledge_case = app::sv_math::rand(hash40("fighter"), 4) + 2;
if MENU.ledge_state == LedgeOption::Random {
ledge_case = (app::sv_math::rand(hash40("fighter"), 4) + 2).into();
} else {
ledge_case = (*menu).LEDGE_STATE;
ledge_case = MENU.ledge_state;
}
match ledge_case {
NEUTRAL_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_CLIMB,
ROLL_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_ESCAPE,
JUMP_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_JUMP1,
ATTACK_LEDGE => status = *FIGHTER_STATUS_KIND_CLIFF_ATTACK,
_ => (),
if let Some(new_status) = ledge_case.into_status() {
status = new_status;
}
StatusModule::change_status_request_from_script(module_accessor, status, true);
@ -61,7 +56,7 @@ pub unsafe fn should_perform_defensive_option(
pub unsafe fn defensive_option(
module_accessor: &mut app::BattleObjectModuleAccessor,
category: i32,
_category: i32,
flag: &mut i32,
) {
let status = StatusModule::status_kind(module_accessor) as i32;
@ -89,7 +84,7 @@ pub unsafe fn check_button_on(
if is_training_mode() && is_operation_cpu(module_accessor) {
let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32;
let status = StatusModule::status_kind(module_accessor) as i32;
if (*menu).DEFENSIVE_STATE == DEFENSIVE_SHIELD
if MENU.defensive_state == Defensive::Shield
&& should_perform_defensive_option(module_accessor, prev_status, status)
{
return Some(true);
@ -105,7 +100,7 @@ pub unsafe fn get_command_flag_cat(
category: i32,
flag: &mut i32,
) {
if (*menu).LEDGE_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) {
if MENU.ledge_state != LedgeOption::None && is_training_mode() && is_operation_cpu(module_accessor) {
force_option(module_accessor);
defensive_option(module_accessor, category, flag);
}

View file

@ -1,7 +1,6 @@
use crate::common::consts::*;
use crate::common::*;
use smash::app::lua_bind::*;
use smash::app::{self};
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
@ -9,23 +8,16 @@ pub unsafe fn get_attack_air_kind(
module_accessor: &mut app::BattleObjectModuleAccessor,
) -> Option<i32> {
if is_training_mode() && is_operation_cpu(module_accessor) {
if (*menu).MASH_STATE == MASH_ATTACK {
match (*menu).ATTACK_STATE {
MASH_NAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_N),
MASH_FAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_F),
MASH_BAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_B),
MASH_UPAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_HI),
MASH_DAIR => return Some(*FIGHTER_COMMAND_ATTACK_AIR_KIND_LW),
_ => (),
}
}
if (*menu).MASH_STATE == MASH_RANDOM {
return Some(app::sv_math::rand(hash40("fighter"), 5) + 1);
if MENU.mash_state == Mash::Attack {
MENU.mash_attack_state.into_attack_air_kind()
} else if MENU.mash_state == Mash::Random {
Some(app::sv_math::rand(hash40("fighter"), 5) + 1)
} else {
None
}
} else {
None
}
None
}
pub unsafe fn get_command_flag_cat(
@ -38,44 +30,45 @@ pub unsafe fn get_command_flag_cat(
|| is_in_landing(module_accessor)
|| is_in_shieldstun(module_accessor)
{
match (*menu).MASH_STATE {
MASH_AIRDODGE => {
match MENU.mash_state {
Mash::Airdodge => {
if category == FIGHTER_PAD_COMMAND_CATEGORY1 {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_AIR_ESCAPE;
}
}
MASH_JUMP => {
Mash::Jump => {
if !is_in_landing(module_accessor) && category == FIGHTER_PAD_COMMAND_CATEGORY1
{
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_JUMP_BUTTON;
}
}
MASH_SPOTDODGE => {
Mash::Spotdodge => {
if category == FIGHTER_PAD_COMMAND_CATEGORY1 {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ESCAPE;
}
}
MASH_ATTACK => {
Mash::Attack => {
if category == FIGHTER_PAD_COMMAND_CATEGORY1 {
match (*menu).ATTACK_STATE {
MASH_NAIR | MASH_FAIR | MASH_BAIR | MASH_UPAIR | MASH_DAIR => {
use Attack::*;
match MENU.mash_attack_state {
Nair | Fair | Bair | UpAir | Dair => {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N;
// If we are performing the attack OOS we also need to jump
if is_in_shieldstun(module_accessor) {
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_JUMP_BUTTON;
}
}
MASH_NEUTRAL_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_N,
MASH_SIDE_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_S,
MASH_UP_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_HI,
MASH_DOWN_B => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_LW,
MASH_UP_SMASH => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_HI4,
MASH_GRAB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_CATCH,
_ => (),
NeutralB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_N,
SideB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_S,
UpB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_HI,
DownB => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_SPECIAL_LW,
UpSmash => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_HI4,
Grab => *flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_CATCH,
}
}
}
MASH_RANDOM => {
Mash::Random => {
if category == FIGHTER_PAD_COMMAND_CATEGORY1 {
let situation_kind = StatusModule::situation_kind(module_accessor) as i32;
@ -140,7 +133,7 @@ pub unsafe fn check_button_on(
) -> Option<bool> {
if [*CONTROL_PAD_BUTTON_GUARD_HOLD, *CONTROL_PAD_BUTTON_GUARD].contains(&button) {
if is_training_mode() && is_operation_cpu(module_accessor) {
if (*menu).MASH_STATE == MASH_AIRDODGE
if MENU.mash_state == Mash::Airdodge
&& (is_in_hitstun(module_accessor) || is_in_landing(module_accessor))
{
return Some(true);

View file

@ -1,37 +1,34 @@
use crate::common::fighter_manager_addr;
use crate::common::FIGHTER_MANAGER_ADDR;
use crate::hitbox_visualizer;
use skyline::{c_str, nn::ro::LookupSymbol};
use smash::app::{self, lua_bind::*};
mod DirectionalInfluence;
mod Ledge;
mod Mash;
mod SaveStates;
mod Shield;
mod Tech;
mod directional_influence;
mod ledge;
mod mash;
mod save_states;
mod shield;
mod tech;
#[allow(unused_unsafe)]
#[skyline::hook(replace = WorkModule::get_float)]
pub unsafe fn handle_get_float(
module_accessor: &mut app::BattleObjectModuleAccessor,
var: i32,
) -> f32 {
DirectionalInfluence::get_float(module_accessor, var)
directional_influence::get_float(module_accessor, var)
.unwrap_or_else(|| original!()(module_accessor, var))
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = WorkModule::get_param_float)]
pub unsafe fn handle_get_param_float(
module_accessor: &mut app::BattleObjectModuleAccessor,
param_type: u64,
param_hash: u64,
) -> f32 {
Shield::get_param_float(module_accessor, param_type, param_hash)
shield::get_param_float(module_accessor, param_type, param_hash)
.unwrap_or_else(|| original!()(module_accessor, param_type, param_hash))
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = ControlModule::get_attack_air_kind)]
pub unsafe fn handle_get_attack_air_kind(
module_accessor: &mut app::BattleObjectModuleAccessor,
@ -40,16 +37,15 @@ pub unsafe fn handle_get_attack_air_kind(
// int kind = InputRecorder::get_attack_air_kind(module_accessor, replace);
// if (replace) return kind;
Mash::get_attack_air_kind(module_accessor).unwrap_or_else(|| original!()(module_accessor))
mash::get_attack_air_kind(module_accessor).unwrap_or_else(|| original!()(module_accessor))
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = ControlModule::get_command_flag_cat)]
pub unsafe fn handle_get_command_flag_cat(
module_accessor: &mut app::BattleObjectModuleAccessor,
category: i32,
) -> i32 {
SaveStates::save_states(module_accessor);
save_states::save_states(module_accessor);
let mut flag = original!()(module_accessor, category);
@ -57,9 +53,9 @@ pub unsafe fn handle_get_command_flag_cat(
// int ret = InputRecorder::get_command_flag_cat(module_accessor, category, flag, replace);
// if (replace) return ret;
Mash::get_command_flag_cat(module_accessor, category, &mut flag);
Ledge::get_command_flag_cat(module_accessor, category, &mut flag);
Tech::get_command_flag_cat(module_accessor, category, &mut flag);
mash::get_command_flag_cat(module_accessor, category, &mut flag);
ledge::get_command_flag_cat(module_accessor, category, &mut flag);
tech::get_command_flag_cat(module_accessor, category, &mut flag);
hitbox_visualizer::get_command_flag_cat(module_accessor, category);
flag
@ -101,40 +97,37 @@ pub unsafe fn handle_get_command_flag_cat(
// return stick_y;
// }
#[allow(unused_unsafe)]
#[skyline::hook(replace = ControlModule::check_button_on)]
pub unsafe fn handle_check_button_on(
module_accessor: &mut app::BattleObjectModuleAccessor,
button: i32,
) -> bool {
Shield::check_button_on(module_accessor, button).unwrap_or_else(|| {
Mash::check_button_on(module_accessor, button).unwrap_or_else(|| {
Tech::check_button_on(module_accessor, button).unwrap_or_else(|| {
Ledge::check_button_on(module_accessor, button)
shield::check_button_on(module_accessor, button).unwrap_or_else(|| {
mash::check_button_on(module_accessor, button).unwrap_or_else(|| {
tech::check_button_on(module_accessor, button).unwrap_or_else(|| {
ledge::check_button_on(module_accessor, button)
.unwrap_or_else(|| original!()(module_accessor, button))
})
})
})
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = ControlModule::check_button_off)]
pub unsafe fn handle_check_button_off(
module_accessor: &mut app::BattleObjectModuleAccessor,
button: i32,
) -> bool {
Shield::check_button_off(module_accessor, button)
shield::check_button_off(module_accessor, button)
.unwrap_or_else(|| original!()(module_accessor, button))
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = StatusModule::init_settings)]
pub unsafe fn handle_init_settings(
module_accessor: &mut app::BattleObjectModuleAccessor,
situationKind: i32,
situation_kind: i32,
unk1: i32,
unk2: u32,
groundCliffCheckKind: i32,
ground_cliff_check_kind: i32,
unk3: bool,
unk4: i32,
unk5: i32,
@ -142,13 +135,13 @@ pub unsafe fn handle_init_settings(
unk7: i32,
) {
let status_kind = StatusModule::status_kind(module_accessor) as i32;
Tech::init_settings(module_accessor, status_kind).unwrap_or_else(|| {
tech::init_settings(module_accessor, status_kind).unwrap_or_else(|| {
original!()(
module_accessor,
situationKind,
situation_kind,
unk1,
unk2,
groundCliffCheckKind,
ground_cliff_check_kind,
unk3,
unk4,
unk5,
@ -158,7 +151,6 @@ pub unsafe fn handle_init_settings(
})
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = MotionModule::change_motion)]
pub unsafe fn handle_change_motion(
module_accessor: &mut app::BattleObjectModuleAccessor,
@ -170,7 +162,7 @@ pub unsafe fn handle_change_motion(
unk5: bool,
unk6: bool,
) -> u64 {
Tech::change_motion(module_accessor, motion_kind).unwrap_or_else(|| {
tech::change_motion(module_accessor, motion_kind).unwrap_or_else(|| {
original!()(
module_accessor,
motion_kind,
@ -188,26 +180,32 @@ pub fn training_mods() {
println!("Applying training mods.");
unsafe {
LookupSymbol(
&mut fighter_manager_addr,
&mut FIGHTER_MANAGER_ADDR,
c_str("_ZN3lib9SingletonIN3app14FighterManagerEE9instance_E"),
);
println!("Lookup symbol output: {:#?}", fighter_manager_addr);
println!("Lookup symbol output: {:#?}", FIGHTER_MANAGER_ADDR);
}
// Mash airdodge/jump
skyline::install_hook!(handle_get_command_flag_cat);
skyline::install_hooks!(
// Mash airdodge/jump
handle_get_command_flag_cat,
// Set DI
skyline::install_hook!(handle_get_float);
// Set DI
handle_get_float,
// Hold/Infinite shield
skyline::install_hook!(handle_check_button_on);
skyline::install_hook!(handle_check_button_off);
skyline::install_hook!(handle_get_param_float);
// Mash attack
skyline::install_hook!(handle_get_attack_air_kind);
// Hold/Infinite shield
handle_check_button_on,
handle_check_button_off,
handle_get_param_float,
// Mash attack
handle_get_attack_air_kind,
// Tech options
handle_init_settings,
handle_change_motion,
);
// // Input recorder
// SaltySD_function_replace_sym(
@ -216,8 +214,4 @@ pub fn training_mods() {
// SaltySD_function_replace_sym(
// "_ZN3app8lua_bind31ControlModule__get_stick_y_implEPNS_26BattleObjectModuleAccessorE",
// (u64)&ControlModule::get_stick_y_replace);
// Tech options
skyline::install_hook!(handle_init_settings);
skyline::install_hook!(handle_change_motion);
}

View file

@ -1,6 +1,5 @@
use crate::common::*;
use smash::app::lua_bind::*;
use smash::app::{self};
use smash::app::{self, lua_bind::*};
use smash::lib::lua_const::*;
use smash::phx::Vector3f;
@ -12,23 +11,22 @@ enum SaveState {
PosMove,
}
use crate::training::SaveStates::SaveState::*;
use SaveState::*;
static mut save_state_player_state: SaveState = NoAction;
static mut save_state_cpu_state: SaveState = NoAction;
static mut save_state_move_alert: bool = false;
static mut SAVE_STATE_PLAYER_STATE: SaveState = NoAction;
static mut SAVE_STATE_CPU_STATE: SaveState = NoAction;
static mut save_state_x_player: f32 = 0.0;
static mut save_state_y_player: f32 = 0.0;
static mut save_state_percent_player: f32 = 0.0;
static mut save_state_lr_player: f32 = 1.0;
static mut save_state_situation_kind_player: i32 = 0 as i32;
static mut SAVE_STATE_X_PLAYER: f32 = 0.0;
static mut SAVE_STATE_Y_PLAYER: f32 = 0.0;
static mut SAVE_STATE_PERCENT_PLAYER: f32 = 0.0;
static mut SAVE_STATE_LR_PLAYER: f32 = 1.0;
static mut SAVE_STATE_SITUATION_KIND_PLAYER: i32 = 0 as i32;
static mut save_state_x_cpu: f32 = 0.0;
static mut save_state_y_cpu: f32 = 0.0;
static mut save_state_percent_cpu: f32 = 0.0;
static mut save_state_lr_cpu: f32 = 1.0;
static mut save_state_situation_kind_cpu: i32 = 0 as i32;
static mut SAVE_STATE_X_CPU: f32 = 0.0;
static mut SAVE_STATE_Y_CPU: f32 = 0.0;
static mut SAVE_STATE_PERCENT_CPU: f32 = 0.0;
static mut SAVE_STATE_LR_CPU: f32 = 1.0;
static mut SAVE_STATE_SITUATION_KIND_CPU: i32 = 0 as i32;
pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) {
let status = StatusModule::status_kind(module_accessor) as i32;
@ -40,29 +38,28 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
let save_state_situation_kind: *mut i32;
let save_state: *mut SaveState;
if is_operation_cpu(module_accessor) {
save_state_x = &mut save_state_x_cpu;
save_state_y = &mut save_state_y_cpu;
save_state_percent = &mut save_state_percent_cpu;
save_state_lr = &mut save_state_lr_cpu;
save_state_situation_kind = &mut save_state_situation_kind_cpu;
save_state = &mut save_state_cpu_state;
save_state_x = &mut SAVE_STATE_X_CPU;
save_state_y = &mut SAVE_STATE_Y_CPU;
save_state_percent = &mut SAVE_STATE_PERCENT_CPU;
save_state_lr = &mut SAVE_STATE_LR_CPU;
save_state_situation_kind = &mut SAVE_STATE_SITUATION_KIND_CPU;
save_state = &mut SAVE_STATE_CPU_STATE;
} else {
save_state_x = &mut save_state_x_player;
save_state_y = &mut save_state_y_player;
save_state_percent = &mut save_state_percent_player;
save_state_lr = &mut save_state_lr_player;
save_state_situation_kind = &mut save_state_situation_kind_player;
save_state = &mut save_state_player_state;
save_state_x = &mut SAVE_STATE_X_PLAYER;
save_state_y = &mut SAVE_STATE_Y_PLAYER;
save_state_percent = &mut SAVE_STATE_PERCENT_PLAYER;
save_state_lr = &mut SAVE_STATE_LR_PLAYER;
save_state_situation_kind = &mut SAVE_STATE_SITUATION_KIND_PLAYER;
save_state = &mut SAVE_STATE_PLAYER_STATE;
}
// Grab + Dpad up: reset state
if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH) != 0
if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH)
&& ControlModule::check_button_trigger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_HI)
!= 0
{
if *save_state == NoAction {
save_state_player_state = CameraMove;
save_state_cpu_state = CameraMove;
SAVE_STATE_PLAYER_STATE = CameraMove;
SAVE_STATE_CPU_STATE = CameraMove;
}
return;
}
@ -152,12 +149,11 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
}
// Grab + Dpad down: Save state
if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH) != 0
if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH)
&& ControlModule::check_button_trigger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_LW)
!= 0
{
save_state_player_state = Save;
save_state_cpu_state = Save;
SAVE_STATE_PLAYER_STATE = Save;
SAVE_STATE_CPU_STATE = Save;
}
if *save_state == Save {

View file

@ -1,16 +1,16 @@
use crate::common::consts::*;
use crate::common::*;
use smash::app::{self};
use smash::app;
use smash::hash40;
use smash::lib::lua_const::*;
pub unsafe fn get_param_float(
module_accessor: &mut app::BattleObjectModuleAccessor,
_module_accessor: &mut app::BattleObjectModuleAccessor,
param_type: u64,
param_hash: u64,
) -> Option<f32> {
if is_training_mode() {
if (*menu).SHIELD_STATE == SHIELD_INFINITE {
if MENU.shield_state == Shield::Infinite {
if param_type == hash40("common") {
if param_hash == hash40("shield_dec1") {
return Some(0.0);
@ -31,9 +31,9 @@ pub unsafe fn get_param_float(
pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
// 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 (*menu).MASH_STATE == NONE {
if MENU.mash_state == Mash::None {
return true;
}
@ -42,15 +42,19 @@ pub unsafe fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAc
}
// We will only drop shield if we are in shieldstun and our attack can be performed OOS
if (*menu).MASH_STATE == MASH_ATTACK {
if [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&(*menu).ATTACK_STATE) {
if MENU.mash_state == Mash::Attack {
if [Attack::NeutralB, Attack::SideB, Attack::DownB].contains(&MENU.mash_attack_state) {
return false;
}
if [MASH_SPOTDODGE, MASH_GRAB].contains(&(*menu).ATTACK_STATE) {
if MENU.mash_attack_state == Attack::Grab {
return true;
}
}
if MENU.mash_state == Mash::Spotdodge {
return true;
}
}
false

View file

@ -1,7 +1,6 @@
use crate::common::consts::*;
use crate::common::*;
use smash::app::lua_bind::*;
use smash::app::{self};
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
@ -11,8 +10,8 @@ pub unsafe fn init_settings(
) -> Option<()> {
if is_training_mode() && is_operation_cpu(module_accessor) {
if status_kind == FIGHTER_STATUS_KIND_DOWN {
match (*menu).TECH_STATE {
RANDOM_TECH => {
match MENU.tech_state {
TechOption::Random => {
let random_statuses = vec![
*FIGHTER_STATUS_KIND_DOWN,
*FIGHTER_STATUS_KIND_PASSIVE,
@ -31,7 +30,7 @@ pub unsafe fn init_settings(
return Some(());
}
}
TECH_IN_PLACE => {
TechOption::InPlace => {
StatusModule::change_status_request_from_script(
module_accessor,
*FIGHTER_STATUS_KIND_PASSIVE,
@ -39,7 +38,7 @@ pub unsafe fn init_settings(
);
return Some(());
}
TECH_ROLL => {
TechOption::Roll => {
StatusModule::change_status_request_from_script(
module_accessor,
*FIGHTER_STATUS_KIND_PASSIVE_FB,
@ -87,10 +86,10 @@ pub unsafe fn should_perform_defensive_option(
pub unsafe fn get_command_flag_cat(
module_accessor: &mut app::BattleObjectModuleAccessor,
category: i32,
_category: i32,
flag: &mut i32,
) {
if (*menu).TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) {
if MENU.tech_state != TechOption::None && is_training_mode() && is_operation_cpu(module_accessor) {
let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32;
let status = StatusModule::status_kind(module_accessor) as i32;
if [
@ -126,7 +125,7 @@ pub unsafe fn check_button_on(
if is_training_mode() && is_operation_cpu(module_accessor) {
let prev_status = StatusModule::prev_status_kind(module_accessor, 0) as i32;
let status = StatusModule::status_kind(module_accessor) as i32;
if (*menu).DEFENSIVE_STATE == DEFENSIVE_SHIELD
if MENU.defensive_state == Defensive::Shield
&& should_perform_defensive_option(module_accessor, prev_status, status)
{
return Some(true);
@ -141,7 +140,7 @@ pub unsafe fn change_motion(
module_accessor: &mut app::BattleObjectModuleAccessor,
motion_kind: u64,
) -> Option<u64> {
if (*menu).TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) {
if MENU.tech_state != TechOption::None && is_training_mode() && is_operation_cpu(module_accessor) {
if [hash40("passive_stand_f"), hash40("passive_stand_b")].contains(&motion_kind) {
if app::sv_math::rand(hash40("fighter"), 2) != 0 {
return Some(hash40("passive_stand_f"));