diff --git a/src/training/save_states.rs b/src/training/save_states.rs index 18d1a74..c41f838 100644 --- a/src/training/save_states.rs +++ b/src/training/save_states.rs @@ -17,6 +17,12 @@ use smash::hash40; use smash::lib::lua_const::*; use smash::phx::{Hash40, Vector3f}; use training_mod_consts::{CharacterItem, SaveDamage}; +use std::collections::HashMap; + +extern "C" { + #[link_name = "\u{1}_ZN3app14sv_information8stage_idEv"] + pub fn stage_id() -> i32; +} #[derive(PartialEq)] enum SaveState { @@ -150,6 +156,16 @@ pub unsafe fn get_param_int( None } +fn get_stage_offset(stage_id: i32) -> f32 { + let offsets: HashMap = HashMap::from([ + (*StageID::Animal_Village, 1.195), + (*StageID::Animal_City, 1.448), + (*StageID::Yoshi_Island, -1.053), + ]); + + *offsets.get(&stage_id).unwrap_or(&0.0) +} + fn set_damage(module_accessor: &mut app::BattleObjectModuleAccessor, damage: f32) { unsafe { DamageModule::heal( @@ -327,11 +343,20 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) ControlModule::stop_rumble(module_accessor, false); KineticModule::clear_speed_all(module_accessor); - let pos = Vector3f { - x: MIRROR_STATE * save_state.x, - y: save_state.y, - z: 0.0, + let pos = if MIRROR_STATE == -1.0 { + Vector3f { + x: MIRROR_STATE * (save_state.x - get_stage_offset(stage_id())), + y: save_state.y, + z: 0.0, + } + } else { + Vector3f { + x: save_state.x, + y: save_state.y, + z: 0.0, + } }; + let lr = MIRROR_STATE * save_state.lr; PostureModule::set_pos(module_accessor, &pos); PostureModule::set_lr(module_accessor, lr); @@ -483,7 +508,12 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) save_state.y = PostureModule::pos_y(module_accessor); save_state.lr = PostureModule::lr(module_accessor); save_state.percent = DamageModule::damage(module_accessor, 0); - save_state.situation_kind = StatusModule::situation_kind(module_accessor); + save_state.situation_kind = + if StatusModule::situation_kind(module_accessor) == *SITUATION_KIND_CLIFF { + *SITUATION_KIND_AIR + } else { + StatusModule::situation_kind(module_accessor) + }; // Always store fighter kind so that charges are handled properly save_state.fighter_kind = app::utility::get_kind(module_accessor); save_state.charge = charge::get_charge(module_accessor, fighter_kind);