mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-03-14 02:16:10 +00:00
Change menu from pointer to reference
This commit is contained in:
parent
12ecda2dce
commit
f75ff6468a
8 changed files with 36 additions and 37 deletions
|
@ -1,8 +1,7 @@
|
|||
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;
|
||||
|
@ -18,7 +17,7 @@ pub static mut menu_struct: consts::TrainingModpackMenu = consts::TrainingModpac
|
|||
DEFENSIVE_STATE: RANDOM_DEFENSIVE,
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -233,11 +233,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)
|
||||
|
@ -312,7 +312,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 +328,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(),
|
||||
|
@ -362,7 +362,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(),
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -4,6 +4,7 @@
|
|||
#![allow(non_snake_case)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![feature(with_options)]
|
||||
#![feature(const_mut_refs)]
|
||||
|
||||
mod common;
|
||||
mod hitbox_visualizer;
|
||||
|
@ -26,7 +27,7 @@ use smash::lua2cpp::L2CFighterCommon;
|
|||
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.ATTACK_STATE == MASH_GRAB {
|
||||
if StatusModule::prev_status_kind(module_accessor, 0) == FIGHTER_STATUS_KIND_GUARD_DAMAGE {
|
||||
if WorkModule::get_int(
|
||||
module_accessor,
|
||||
|
@ -45,7 +46,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,7 +59,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue
|
|||
}
|
||||
}
|
||||
}
|
||||
if (*menu).MASH_STATE == MASH_UP_B {
|
||||
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,
|
||||
|
@ -71,7 +72,7 @@ pub unsafe fn handle_sub_guard_cont(fighter: &mut L2CFighterCommon) -> L2CValue
|
|||
// }
|
||||
}
|
||||
}
|
||||
if (*menu).MASH_STATE == MASH_UP_SMASH {
|
||||
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,
|
||||
|
@ -106,8 +107,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}", common::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(
|
||||
|
|
|
@ -15,11 +15,11 @@ 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 != NONE {
|
||||
let mut angle = (menu.DI_STATE - 1) as f64 * PI / 4.0;
|
||||
|
||||
// Either 0 (right) or PI (left)
|
||||
if (*menu).DI_STATE == DI_RANDOM_IN_AWAY {
|
||||
if menu.DI_STATE == DI_RANDOM_IN_AWAY {
|
||||
angle = app::sv_math::rand(hash40("fighter"), 2) as f64 * PI;
|
||||
}
|
||||
// If facing left, reverse angle
|
||||
|
|
|
@ -21,10 +21,10 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
|
|||
let mut status = 0;
|
||||
let ledge_case: i32;
|
||||
|
||||
if (*menu).LEDGE_STATE == RANDOM_LEDGE {
|
||||
if menu.LEDGE_STATE == RANDOM_LEDGE {
|
||||
ledge_case = app::sv_math::rand(hash40("fighter"), 4) + 2;
|
||||
} else {
|
||||
ledge_case = (*menu).LEDGE_STATE;
|
||||
ledge_case = menu.LEDGE_STATE;
|
||||
}
|
||||
|
||||
match ledge_case {
|
||||
|
@ -89,7 +89,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 +105,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 != NONE && is_training_mode() && is_operation_cpu(module_accessor) {
|
||||
force_option(module_accessor);
|
||||
defensive_option(module_accessor, category, flag);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ 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 {
|
||||
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),
|
||||
|
@ -20,7 +20,7 @@ pub unsafe fn get_attack_air_kind(
|
|||
}
|
||||
}
|
||||
|
||||
if (*menu).MASH_STATE == MASH_RANDOM {
|
||||
if menu.MASH_STATE == MASH_RANDOM {
|
||||
return Some(app::sv_math::rand(hash40("fighter"), 5) + 1);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ pub unsafe fn get_command_flag_cat(
|
|||
|| is_in_landing(module_accessor)
|
||||
|| is_in_shieldstun(module_accessor)
|
||||
{
|
||||
match (*menu).MASH_STATE {
|
||||
match menu.MASH_STATE {
|
||||
MASH_AIRDODGE => {
|
||||
if category == FIGHTER_PAD_COMMAND_CATEGORY1 {
|
||||
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_AIR_ESCAPE;
|
||||
|
@ -57,7 +57,7 @@ pub unsafe fn get_command_flag_cat(
|
|||
}
|
||||
MASH_ATTACK => {
|
||||
if category == FIGHTER_PAD_COMMAND_CATEGORY1 {
|
||||
match (*menu).ATTACK_STATE {
|
||||
match menu.ATTACK_STATE {
|
||||
MASH_NAIR | MASH_FAIR | MASH_BAIR | MASH_UPAIR | MASH_DAIR => {
|
||||
*flag |= *FIGHTER_PAD_CMD_CAT1_FLAG_ATTACK_N;
|
||||
// If we are performing the attack OOS we also need to jump
|
||||
|
@ -140,7 +140,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);
|
||||
|
|
|
@ -10,7 +10,7 @@ pub unsafe fn get_param_float(
|
|||
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 == NONE {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,12 @@ 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 [MASH_NEUTRAL_B, MASH_SIDE_B, MASH_DOWN_B].contains(&menu.ATTACK_STATE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if [MASH_SPOTDODGE, MASH_GRAB].contains(&(*menu).ATTACK_STATE) {
|
||||
if [MASH_SPOTDODGE, MASH_GRAB].contains(&menu.ATTACK_STATE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ 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 {
|
||||
match menu.TECH_STATE {
|
||||
RANDOM_TECH => {
|
||||
let random_statuses = vec![
|
||||
*FIGHTER_STATUS_KIND_DOWN,
|
||||
|
@ -90,7 +90,7 @@ pub unsafe fn get_command_flag_cat(
|
|||
category: i32,
|
||||
flag: &mut i32,
|
||||
) {
|
||||
if (*menu).TECH_STATE != NONE && is_training_mode() && is_operation_cpu(module_accessor) {
|
||||
if menu.TECH_STATE != 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 +126,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 +141,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 != 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"));
|
||||
|
|
Loading…
Add table
Reference in a new issue