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

Refactor untechables (#446)

* Fix rust-analyzer config

* Refactor tech.rs to no longer depend on a static mut
This commit is contained in:
asimon-1 2022-12-15 22:56:36 -05:00 committed by GitHub
parent 0f510a7df5
commit 74e374db6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 16 deletions

View file

@ -9,6 +9,7 @@ use crate::common::consts::*;
use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
use smash::lua2cpp::L2CFighterCommon;
pub use crate::common::consts::MENU;
pub static mut DEFAULTS_MENU: TrainingModpackMenu = crate::common::consts::DEFAULTS_MENU;
@ -242,3 +243,9 @@ pub unsafe fn get_fighter_distance() -> f32 {
cpu_pos.z,
)
}
// From https://github.com/chrispo-git/ult-s/blob/cc1c3060ed83f6d33f39964e84f9c32c07a17bae/src/controls/util.rs#L106
pub unsafe fn get_fighter_common_from_accessor(module_accessor: &mut app::BattleObjectModuleAccessor) -> &mut L2CFighterCommon {
let lua_module = *(module_accessor as *mut app::BattleObjectModuleAccessor as *mut u64).add(0x190 / 8);
&mut *(*((lua_module + 0x1D8) as *mut *mut L2CFighterCommon))
}

View file

@ -42,7 +42,6 @@ fn nro_main(nro: &NroInfo<'_>) {
training::shield::handle_sub_guard_cont,
training::directional_influence::handle_correct_damage_vector_common,
training::tech::handle_change_status,
training::tech::mod_is_enable_passive,
);
}
}

View file

@ -1,17 +1,15 @@
use crate::common::consts::*;
use crate::common::*;
use crate::training::{frame_counter, mash};
use smash::app::sv_system;
use smash::app::{self, lua_bind::*};
use smash::app::{self, BattleObjectModuleAccessor, sv_system, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
use smash::lib::L2CValue;
use smash::lua2cpp::{L2CFighterBase, L2CFighterCommon};
use smash::lua2cpp::{L2CFighterBase};
static mut TECH_ROLL_DIRECTION: Direction = Direction::empty();
static mut MISS_TECH_ROLL_DIRECTION: Direction = Direction::empty();
static mut FRAME_COUNTER: usize = 0;
static mut CAN_TECH: bool = false;
pub fn init() {
unsafe {
@ -19,14 +17,9 @@ pub fn init() {
}
}
#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_is_enable_passive)]
pub unsafe fn mod_is_enable_passive(fighter: &mut L2CFighterCommon) -> L2CValue {
let ori = original!()(fighter);
let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent);
if is_training_mode() && is_operation_cpu(module_accessor) {
CAN_TECH = ori.get_bool();
}
ori
unsafe fn is_enable_passive(module_accessor: &mut BattleObjectModuleAccessor) -> bool {
let fighter = get_fighter_common_from_accessor(module_accessor);
fighter.is_enable_passive().get_bool()
}
#[skyline::hook(replace = smash::lua2cpp::L2CFighterBase_change_status)]
@ -95,7 +88,7 @@ unsafe fn handle_grnd_tech(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_PASSIVE,
) && (second_prev_status != FIGHTER_STATUS_KIND_CATCHED_AIR_FALL_GANON)
&& CAN_TECH;
&& is_enable_passive(module_accessor);
if !can_tech {
return false;
@ -138,7 +131,7 @@ unsafe fn handle_wall_tech(
let can_tech = WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_PASSIVE_WALL,
) && CAN_TECH;
) && is_enable_passive(module_accessor);
if ![
*FIGHTER_STATUS_KIND_STOP_WALL,
@ -180,7 +173,7 @@ unsafe fn handle_ceil_tech(
let can_tech = WorkModule::is_enable_transition_term(
module_accessor,
*FIGHTER_STATUS_TRANSITION_TERM_ID_PASSIVE_CEIL,
) && CAN_TECH;
) && is_enable_passive(module_accessor);
if ![
*FIGHTER_STATUS_KIND_STOP_CEIL,