Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TrainingModpackOverlay/include/taunt_toggles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ option after getting up.
// clang-format off
#define ENUM_CLASS_TechFlag(type,x) \
x(type,Miss,"Miss Tech") \
x(type,Roll,"Roll") \
x(type,RollF,"RollF") \
x(type,RollB,"RollB") \
x(type,InPlace,"In Place")

// clang-format on
Expand Down
22 changes: 10 additions & 12 deletions src/common/consts.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

use crate::common::get_random_int;
use core::f64::consts::PI;
use smash::lib::lua_const::*;
use smash::hash40;
use smash::app;


/// Hitbox Visualization
#[repr(i32)]
Expand Down Expand Up @@ -134,7 +131,7 @@ macro_rules! to_vec_impl {

// Ledge Option
bitflags! {
pub struct LedgeOption : u32
pub struct LedgeOption : u32
{
const NEUTRAL = 0b1;
const ROLL = 0b10;
Expand All @@ -143,8 +140,8 @@ bitflags! {
}
}

pub unsafe fn random_option<T>(arg : &Vec<T>) -> &T {
return &arg[app::sv_math::rand(hash40("fighter"), arg.len() as i32) as usize];
pub unsafe fn random_option<T>(arg: &Vec<T>) -> &T {
return &arg[get_random_int(arg.len() as i32) as usize];
}

impl LedgeOption {
Expand All @@ -157,20 +154,21 @@ impl LedgeOption {
_ => return None,
})
}
to_vec_impl!{LedgeOption}
to_vec_impl! {LedgeOption}
}

// Tech options
bitflags! {
pub struct TechFlags : u32 {
const NO_TECH = 0b1;
const ROLL = 0b10;
const IN_PLACE = 0b100;
const NO_TECH = 0x1;
const ROLL_F = 0x2;
const ROLL_B = 0x4;
const IN_PLACE = 0x8;
}
}

impl TechFlags {
to_vec_impl!{TechFlags}
to_vec_impl! {TechFlags}
}

/// Mash States
Expand Down
5 changes: 5 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod consts;

use crate::common::consts::*;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;

pub static mut MENU_STRUCT: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
Expand Down Expand Up @@ -117,3 +118,7 @@ pub unsafe fn is_in_shieldstun(module_accessor: &mut app::BattleObjectModuleAcce
|| (prev_status == FIGHTER_STATUS_KIND_GUARD_DAMAGE
&& status_kind == FIGHTER_STATUS_KIND_GUARD_OFF)
}

pub fn get_random_int(max: i32) -> i32 {
unsafe { app::sv_math::rand(hash40("fighter"), max) }
}
5 changes: 2 additions & 3 deletions src/training/directional_influence.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::common::consts::*;
use crate::common::*;
use core::f64::consts::PI;
use smash::app::{self, lua_bind::*, sv_system};
use smash::hash40;
use smash::app::{lua_bind::*, sv_system};
use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
Expand Down Expand Up @@ -71,7 +70,7 @@ unsafe fn get_angle(direction: Direction) -> f64 {

unsafe fn get_random_direction() -> Direction {
// Choose Left/Right/None
let rand = app::sv_math::rand(hash40("fighter"), 3);
let rand = get_random_int(3);
if rand == 0 {
Direction::Left
} else if rand == 1 {
Expand Down
18 changes: 10 additions & 8 deletions src/training/ledge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::common::consts::*;
use crate::common::*;
use crate::training::mash;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;

pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor) {
Expand All @@ -17,10 +16,7 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
return;
}

let random_frame = app::sv_math::rand(
hash40("fighter"),
MotionModule::end_frame(module_accessor) as i32,
) as f32;
let random_frame = get_random_int(MotionModule::end_frame(module_accessor) as i32) as f32;

let frame = MotionModule::frame(module_accessor) as f32;
if !(frame == random_frame || frame > 30.0) {
Expand All @@ -32,9 +28,15 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor

let ledge_options = MENU.ledge_state.to_vec();
match ledge_options.len() {
0 => { ledge_case = LedgeOption::empty(); },
1 => { ledge_case = ledge_options[0]; },
_ => { ledge_case = *random_option(&ledge_options); }
0 => {
ledge_case = LedgeOption::empty();
}
1 => {
ledge_case = ledge_options[0];
}
_ => {
ledge_case = *random_option(&ledge_options);
}
}

if let Some(new_status) = ledge_case.into_status() {
Expand Down
12 changes: 5 additions & 7 deletions src/training/left_stick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::common::*;
use core::f64::consts::PI;
use smash::app::{self, lua_bind::*};
use smash::lib::lua_const::*;
use smash::hash40;

static mut STICK_DIRECTION: Direction = Direction::None;

Expand Down Expand Up @@ -54,11 +53,10 @@ unsafe fn get_angle(module_accessor: &mut app::BattleObjectModuleAccessor) -> f6

// TODO: if left_stick is used for something other than
// directional airdodge, this may not make sense.
let launch_speed_x = KineticEnergy::get_speed_x(
KineticModule::get_energy(
module_accessor,
*FIGHTER_KINETIC_ENERGY_ID_DAMAGE
) as *mut smash::app::KineticEnergy);
let launch_speed_x = KineticEnergy::get_speed_x(KineticModule::get_energy(
module_accessor,
*FIGHTER_KINETIC_ENERGY_ID_DAMAGE,
) as *mut smash::app::KineticEnergy);

// If we're launched left, reverse stick X
if launch_speed_x < 0.0 {
Expand Down Expand Up @@ -90,6 +88,6 @@ unsafe fn pick_angle(direction: Direction) -> f64 {
}

unsafe fn get_random_direction() -> Direction {
let rand = app::sv_math::rand(hash40("fighter"), 8);
let rand = get_random_int(8);
Direction::from(rand)
}
11 changes: 4 additions & 7 deletions src/training/mash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::training::character_specific;
use crate::training::fast_fall;
use crate::training::shield;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;

static mut CURRENT_AERIAL: Action = Action::Nair;
Expand Down Expand Up @@ -158,7 +157,7 @@ fn should_reset(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
}

fn should_buffer(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
unsafe{
unsafe {
if MENU.mash_in_neutral == OnOff::On {
return true;
}
Expand Down Expand Up @@ -217,8 +216,7 @@ fn get_random_action(module_accessor: &mut app::BattleObjectModuleAccessor) -> A
random_cmds.push(Mash::Spotdodge);
}

let random_cmd_index =
app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize;
let random_cmd_index = get_random_int(random_cmds.len() as i32) as usize;

mash_to_action(random_cmds[random_cmd_index])
}
Expand Down Expand Up @@ -530,13 +528,12 @@ pub unsafe fn perform_defensive_option() {
Mash::Attack,
];

let random_cmd_index =
app::sv_math::rand(hash40("fighter"), random_cmds.len() as i32) as usize;
let random_cmd_index = get_random_int(random_cmds.len() as i32) as usize;

action = mash_to_action(random_cmds[random_cmd_index]);
}
Defensive::Roll => {
if app::sv_math::rand(hash40("fighter"), 2) == 0 {
if get_random_int(2) == 0 {
action = Action::RollForward;
} else {
action = Action::RollBack;
Expand Down
27 changes: 19 additions & 8 deletions src/training/tech.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterBase;

static mut ROLL_DIRECTION: Direction = Direction::None;

#[skyline::hook(replace = smash::lua2cpp::L2CFighterBase_change_status)]
pub unsafe fn handle_change_status(
fighter: &mut L2CFighterBase,
Expand Down Expand Up @@ -44,10 +46,14 @@ unsafe fn mod_handle_change_status(
|| status_kind_int == FIGHTER_STATUS_KIND_DAMAGE_FLY_REFLECT_D
{
let states = MENU.tech_state.to_vec();
let mut state = if states.is_empty() { TechFlags::empty() } else { states[0] };
let mut state = if states.is_empty() {
TechFlags::empty()
} else {
states[0]
};

if states.len() > 1 {
let idx = app::sv_math::rand(hash40("fighter"), states.len() as i32) as usize;
let idx = get_random_int(states.len() as i32) as usize;
state = states[idx];
}

Expand All @@ -56,9 +62,15 @@ unsafe fn mod_handle_change_status(
*status_kind = FIGHTER_STATUS_KIND_PASSIVE.as_lua_int();
*unk = LUA_TRUE;
}
TechFlags::ROLL => {
TechFlags::ROLL_F => {
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
*unk = LUA_TRUE;
ROLL_DIRECTION = Direction::Left; // = In
}
TechFlags::ROLL_B => {
*status_kind = FIGHTER_STATUS_KIND_PASSIVE_FB.as_lua_int();
*unk = LUA_TRUE;
ROLL_DIRECTION = Direction::Right; // = Away
}
_ => (),
}
Expand Down Expand Up @@ -117,8 +129,7 @@ pub unsafe fn get_command_flag_cat(
*FIGHTER_STATUS_KIND_DOWN_STAND_ATTACK, // Getup Attack
];

let random_status_index =
app::sv_math::rand(hash40("fighter"), random_statuses.len() as i32) as usize;
let random_status_index = get_random_int(random_statuses.len() as i32) as usize;
StatusModule::change_status_request_from_script(
module_accessor,
random_statuses[random_status_index],
Expand All @@ -140,14 +151,14 @@ pub unsafe fn change_motion(
return None;
}

if MENU.tech_state == TechFlags::empty() || MENU.tech_state == TechFlags::NO_TECH {
if MENU.tech_state == TechFlags::empty() {
return None;
}

let random_roll = app::sv_math::rand(hash40("fighter"), 2);
let random_roll = get_random_int(2);

if [hash40("passive_stand_f"), hash40("passive_stand_b")].contains(&motion_kind) {
if random_roll != 0 {
if ROLL_DIRECTION == Direction::Left {
return Some(hash40("passive_stand_f"));
} else {
return Some(hash40("passive_stand_b"));
Expand Down