1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-24 02:44:17 +00:00

Save Sora Spell (#623)

* Initial implementation, getting the wrong pointer somewhere

* Working build w/ Kirby

* Sound Fix

* appease clippy
This commit is contained in:
GradualSyrup 2023-09-04 23:24:37 -05:00 committed by GitHub
parent 872911dbb8
commit 9ffe3c7ceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 1 deletions

View file

@ -34,6 +34,9 @@ pub fn is_training_mode() -> bool {
true
}
#[skyline::from_offset(0x3ac540)]
pub fn get_battle_object_from_id(battle_object_id: u32) -> *mut app::BattleObject;
pub fn get_category(module_accessor: &app::BattleObjectModuleAccessor) -> i32 {
(module_accessor.battle_object_id >> 28) as u8 as i32
}
@ -42,6 +45,11 @@ pub fn is_emulator() -> bool {
unsafe { skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as u64 == 0x8004000 }
}
pub unsafe fn try_get_battle_object(battle_object_id: u32) -> Option<&'static app::BattleObject> {
let battle_object_ptr = get_battle_object_from_id(battle_object_id);
battle_object_ptr.as_ref()
}
pub fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModuleAccessor {
try_get_module_accessor(fighter_id).unwrap()
}

View file

@ -1,3 +1,4 @@
use crate::common::try_get_battle_object;
use crate::training::charge::ChargeState;
use crate::training::save_states;
use smash::app::{self, lua_bind::*, smashball::is_training_mode};
@ -197,6 +198,14 @@ pub unsafe fn get_kirby_hat_charge(
);
charge_state.int_x(my_charge)
}
// Sora Spell
else if opponent_fighter_kind == FIGHTER_KIND_TRAIL {
let my_charge = WorkModule::get_int(
module_accessor,
*FIGHTER_TRAIL_INSTANCE_WORK_ID_INT_SPECIAL_N_MAGIC_KIND,
);
charge_state.int_x(my_charge)
}
// No charge for this character's copy ability
else {
charge_state
@ -572,6 +581,26 @@ pub unsafe fn handle_kirby_hat_charge(
);
});
}
// Sora Spell - 0 to 2
else if opponent_fighter_kind == FIGHTER_KIND_TRAIL {
charge.int_x.map(|spell_kind| {
let prev_spell_kind = (spell_kind + 1) % 3;
WorkModule::set_int(
module_accessor,
prev_spell_kind,
*FIGHTER_TRAIL_INSTANCE_WORK_ID_INT_SPECIAL_N_MAGIC_KIND,
);
// app::FighterSpecializer_Trail::change_magic() doesn't actually run if the below flag isn't set
WorkModule::on_flag(
module_accessor,
*FIGHTER_TRAIL_STATUS_SPECIAL_N1_FLAG_CHANGE_MAGIC,
);
if let Some(battle_object) = try_get_battle_object(module_accessor.battle_object_id) {
let fighter = battle_object as *const app::BattleObject as *mut app::Fighter;
app::FighterSpecializer_Trail::change_magic(fighter);
}
});
}
}
pub fn init() {

View file

@ -1,5 +1,5 @@
use crate::common::consts::FighterId;
use crate::common::get_module_accessor;
use crate::common::{get_module_accessor, try_get_battle_object};
use crate::training::character_specific::{kirby, pikmin};
use serde::{Deserialize, Serialize};
use smash::app::{self, lua_bind::*, ArticleOperationTarget, FighterFacial, FighterUtil};
@ -274,6 +274,14 @@ pub unsafe fn get_charge(
*FIGHTER_MIIGUNNER_INSTANCE_WORK_ID_INT_GUNNER_CHARGE_COUNT,
);
charge_state.int_x(my_charge)
}
// Sora Spell
else if fighter_kind == FIGHTER_KIND_TRAIL {
let my_charge = WorkModule::get_int(
module_accessor,
*FIGHTER_TRAIL_INSTANCE_WORK_ID_INT_SPECIAL_N_MAGIC_KIND,
);
charge_state.int_x(my_charge)
} else {
charge_state
}
@ -933,4 +941,24 @@ pub unsafe fn handle_charge(
);
});
}
// Sora Spell - 0 to 2
else if fighter_kind == FIGHTER_KIND_TRAIL {
charge.int_x.map(|spell_kind| {
let prev_spell_kind = (spell_kind + 1) % 3; // Should have used this for pikmin idk what I was on
WorkModule::set_int(
module_accessor,
prev_spell_kind,
*FIGHTER_TRAIL_INSTANCE_WORK_ID_INT_SPECIAL_N_MAGIC_KIND,
);
// app::FighterSpecializer_Trail::change_magic() doesn't actually run if the below flag isn't set
WorkModule::on_flag(
module_accessor,
*FIGHTER_TRAIL_STATUS_SPECIAL_N1_FLAG_CHANGE_MAGIC,
);
if let Some(battle_object) = try_get_battle_object(module_accessor.battle_object_id) {
let fighter = battle_object as *const app::BattleObject as *mut app::Fighter;
app::FighterSpecializer_Trail::change_magic(fighter);
}
});
}
}

View file

@ -523,6 +523,14 @@ pub unsafe fn handle_fighter_play_se(
my_hash = Hash40::new("se_silent");
}
}
// Supress Sora Magic Switch SFX when loading Save State
if my_hash.hash == 0x156fdf29ba {
let module_accessor = (*sound_module).owner;
// Kirby and Sora's Special N statuses are all here or higher
if StatusModule::status_kind(module_accessor) < *FIGHTER_TRAIL_STATUS_KIND_SPECIAL_N1 {
my_hash = Hash40::new("se_silent");
}
}
my_hash = ptrainer::handle_pokemon_sound_effect(my_hash);
original!()(sound_module, my_hash, bool1, bool2, bool3, bool4, se_type)
}