1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-10-03 09:44:26 +00:00

Fix DI in/away errors

This commit is contained in:
jugeeya 2020-08-10 20:21:45 -07:00
parent a892cf8326
commit 716300b01c
5 changed files with 35 additions and 25 deletions

View file

@ -54,8 +54,6 @@ impl From<i32> for Direction {
} }
} }
//pub static FIGHTER_FACING_LEFT: f32 = 1.0;
pub static FIGHTER_FACING_RIGHT: f32 = -1.0;
pub static ANGLE_NONE: f64 = -69.0; pub static ANGLE_NONE: f64 = -69.0;
pub fn direction_to_angle(direction: Direction) -> f64 { pub fn direction_to_angle(direction: Direction) -> f64 {
match direction { match direction {

View file

@ -41,6 +41,15 @@ pub fn get_category(module_accessor: &mut app::BattleObjectModuleAccessor) -> i3
return (module_accessor.info >> 28) as u8 as i32; return (module_accessor.info >> 28) as u8 as i32;
} }
pub unsafe fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModuleAccessor {
let entry_id_int = fighter_id as i32;
let entry_id = app::FighterEntryID(entry_id_int);
let mgr = *(FIGHTER_MANAGER_ADDR as *mut *mut app::FighterManager);
let fighter_entry = FighterManager::get_fighter_entry(mgr, entry_id) as *mut app::FighterEntry;
let current_fighter_id = FighterEntry::current_fighter_id(fighter_entry);
app::sv_battle_object::module_accessor(current_fighter_id as u32)
}
pub unsafe fn is_fighter(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool { pub unsafe fn is_fighter(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
get_category(module_accessor) == BATTLE_OBJECT_CATEGORY_FIGHTER get_category(module_accessor) == BATTLE_OBJECT_CATEGORY_FIGHTER
} }

View file

@ -1,5 +1,4 @@
use crate::common::consts::FighterId; use crate::common::consts::FighterId;
use crate::common::FIGHTER_MANAGER_ADDR;
use crate::common::*; use crate::common::*;
use crate::training::*; use crate::training::*;
@ -28,15 +27,6 @@ unsafe fn was_in_shieldstun(module_accessor: *mut app::BattleObjectModuleAccesso
prev_status == FIGHTER_STATUS_KIND_GUARD_DAMAGE prev_status == FIGHTER_STATUS_KIND_GUARD_DAMAGE
} }
unsafe fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModuleAccessor {
let entry_id_int = fighter_id as i32;
let entry_id = app::FighterEntryID(entry_id_int);
let mgr = *(FIGHTER_MANAGER_ADDR as *mut *mut app::FighterManager);
let fighter_entry = FighterManager::get_fighter_entry(mgr, entry_id) as *mut app::FighterEntry;
let current_fighter_id = FighterEntry::current_fighter_id(fighter_entry);
app::sv_battle_object::module_accessor(current_fighter_id as u32)
}
macro_rules! actionable_statuses { macro_rules! actionable_statuses {
() => { () => {
vec![ vec![

View file

@ -7,8 +7,6 @@ use smash::lib::lua_const::*;
use smash::lib::L2CValue; use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon; use smash::lua2cpp::L2CFighterCommon;
pub static mut DI_ANGLE: f64 = 0.0;
#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_FighterStatusDamage__correctDamageVectorCommon)] #[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_FighterStatusDamage__correctDamageVectorCommon)]
pub unsafe fn handle_correct_damage_vector_common( pub unsafe fn handle_correct_damage_vector_common(
fighter: &mut L2CFighterCommon, fighter: &mut L2CFighterCommon,
@ -33,25 +31,31 @@ unsafe fn mod_handle_di(fighter: &mut L2CFighterCommon, _arg1: L2CValue) {
} }
// Either left, right, or none // Either left, right, or none
DI_ANGLE = get_angle(MENU.di_state); let mut angle = get_angle(MENU.di_state);
// Nothig to do on no DI // Nothing to do on no DI
if DI_ANGLE == ANGLE_NONE { if angle == ANGLE_NONE {
return; return;
} }
// If facing left, reverse angle let launch_speed_x = KineticEnergy::get_speed_x(
if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT { KineticModule::get_energy(
DI_ANGLE -= PI; 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 {
angle = PI - angle;
} }
WorkModule::set_float( WorkModule::set_float(
module_accessor, module_accessor,
DI_ANGLE.cos() as f32, angle.cos() as f32,
*FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X, *FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X,
); );
WorkModule::set_float( WorkModule::set_float(
module_accessor, module_accessor,
DI_ANGLE.sin() as f32, angle.sin() as f32,
*FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y, *FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y,
); );
} }

View file

@ -2,6 +2,7 @@ use crate::common::consts::*;
use crate::common::*; use crate::common::*;
use core::f64::consts::PI; use core::f64::consts::PI;
use smash::app::{self, lua_bind::*}; use smash::app::{self, lua_bind::*};
use smash::lib::lua_const::*;
use smash::hash40; use smash::hash40;
static mut STICK_DIRECTION: Direction = Direction::None; static mut STICK_DIRECTION: Direction = Direction::None;
@ -51,9 +52,17 @@ unsafe fn get_angle(module_accessor: &mut app::BattleObjectModuleAccessor) -> f6
return ANGLE_NONE; return ANGLE_NONE;
} }
// If facing left, reverse angle // TODO: if left_stick is used for something other than
if PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT { // directional airdodge, this may not make sense.
angle -= PI; 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 {
angle = PI - angle;
} }
angle angle