Skip to content

Commit

Permalink
Merge pull request HDR-Development#2054 from HDR-Development/ptrainer…
Browse files Browse the repository at this point in the history
…-backwards-switch

PTrainer - Hold to Backwards Switch
  • Loading branch information
blu-dev authored Nov 2, 2023
2 parents 1387ee0 + 973be5e commit 6a32272
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ scripts/change_summary.txt
scripts/log.txt
scripts/tmp
rust-toolchain
plugin/hdr_version.txt
**/hdr_version.txt
**/*.zip
**/*package/
**/zips/
Expand Down
6 changes: 6 additions & 0 deletions dynamic/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,12 @@ pub mod vars {
}
}

pub mod ptrainer {
pub mod instance {
pub const IS_SWITCH_BACKWARDS: i32 = 0x0100;
}
}

pub mod plizardon {
pub mod instance {
pub const DISABLE_SPECIAL_S: i32 = 0x0100;
Expand Down
20 changes: 20 additions & 0 deletions fighters/common/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub fn install() {
set_team_second_hook,
set_team_hook,
set_team_owner_id_hook,
ptrainer_swap_backwards_hook,
ptrainer_stub_death_switch
// shield_damage_analog,
// shield_pushback_analog
);
Expand Down Expand Up @@ -209,3 +211,21 @@ pub unsafe fn psych_up_hit() {
pub unsafe fn krool_belly_damage_hook(damage: f32, fighter: *mut Fighter, unk: bool) {
krool_belly_damage_hook_impl(damage, fighter, unk);
}

#[skyline::hook(offset = 0x34cdc64, inline)]
unsafe fn ptrainer_swap_backwards_hook(ctx: &mut skyline::hooks::InlineCtx) {
let object = *ctx.registers[20].x.as_ref() as *mut BattleObject;
if VarModule::is_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS) {
let new = match *ctx.registers[8].x.as_ref() {
0 => 1,
1 => 2,
2 => 0,
_ => unreachable!()
};

*ctx.registers[8].x.as_mut() = new;
}
}

#[skyline::hook(offset = 0xf96310)]
unsafe fn ptrainer_stub_death_switch() {}
9 changes: 9 additions & 0 deletions fighters/pfushigisou/src/opff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ unsafe fn fastfall_specials(fighter: &mut L2CFighterCommon) {
}
}

unsafe fn special_lw_track(boma: &mut BattleObjectModuleAccessor) {
if boma.is_status(*FIGHTER_STATUS_KIND_SPECIAL_LW) && !boma.is_button_on(Buttons::SpecialAll) {
let parent_id = LinkModule::get_parent_id(boma, *FIGHTER_POKEMON_LINK_NO_PTRAINER, true) as u32;
let object = utils::util::get_battle_object_from_id(parent_id);
VarModule::off_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS);
}
}

pub unsafe fn moveset(fighter: &mut L2CFighterCommon, boma: &mut BattleObjectModuleAccessor, id: usize, cat: [i32 ; 4], status_kind: i32, situation_kind: i32, motion_kind: u64, stick_x: f32, stick_y: f32, facing: f32, frame: f32) {
razorleaf_adc(boma, status_kind, situation_kind, cat[0], frame);
fastfall_specials(fighter);
special_lw_track(boma);
}

#[utils::macros::opff(FIGHTER_KIND_PFUSHIGISOU )]
Expand Down
13 changes: 8 additions & 5 deletions fighters/pfushigisou/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ unsafe fn request_change_pokemon() -> bool {
return false;
}

#[skyline::hook(offset = 0xf96310)]
unsafe fn stub_death_switch() {}
#[status_script(agent = "pzenigame", status = FIGHTER_STATUS_KIND_SPECIAL_LW, condition = LUA_SCRIPT_STATUS_FUNC_STATUS_MAIN)]
unsafe fn special_lw_main(fighter: &mut L2CFighterCommon) -> L2CValue {
let parent_id = LinkModule::get_parent_id(fighter.module_accessor, *FIGHTER_POKEMON_LINK_NO_PTRAINER, true) as u32;
let object = utils::util::get_battle_object_from_id(parent_id);
VarModule::on_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS); // we will turn this off in opff
original!(fighter)
}

pub fn install() {
install_status_scripts!(
);
skyline::install_hooks!(
stub_death_switch,
special_lw_main
);
}
9 changes: 9 additions & 0 deletions fighters/plizardon/src/opff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ unsafe fn fastfall_specials(fighter: &mut L2CFighterCommon) {
}
}

unsafe fn special_lw_track(boma: &mut BattleObjectModuleAccessor) {
if boma.is_status(*FIGHTER_STATUS_KIND_SPECIAL_LW) && !boma.is_button_on(Buttons::SpecialAll) {
let parent_id = LinkModule::get_parent_id(boma, *FIGHTER_POKEMON_LINK_NO_PTRAINER, true) as u32;
let object = utils::util::get_battle_object_from_id(parent_id);
VarModule::off_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS);
}
}

pub unsafe fn moveset(fighter: &mut L2CFighterCommon, boma: &mut BattleObjectModuleAccessor, id: usize, cat: [i32 ; 4], status_kind: i32, situation_kind: i32, motion_kind: u64, stick_x: f32, stick_y: f32, facing: f32, frame: f32) {
flame_cancel(boma, status_kind, situation_kind, frame);
flare_blitz_edge_cancel(fighter);
fastfall_specials(fighter);
special_lw_track(boma);

// Frame Data
//frame_data(boma, status_kind, motion_kind, frame);
Expand Down
11 changes: 11 additions & 0 deletions fighters/plizardon/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@ fn plizardon_init(fighter: &mut L2CFighterCommon) {
}
}

#[status_script(agent = "plizardon", status = FIGHTER_STATUS_KIND_SPECIAL_LW, condition = LUA_SCRIPT_STATUS_FUNC_STATUS_MAIN)]
unsafe fn special_lw_main(fighter: &mut L2CFighterCommon) -> L2CValue {
let parent_id = LinkModule::get_parent_id(fighter.module_accessor, *FIGHTER_POKEMON_LINK_NO_PTRAINER, true) as u32;
let object = utils::util::get_battle_object_from_id(parent_id);
VarModule::on_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS); // we will turn this off in opff
original!(fighter)
}

pub fn install() {
smashline::install_agent_init_callbacks!(plizardon_init);
special_s::install();
install_status_scripts!(
special_lw_main
);

}
9 changes: 9 additions & 0 deletions fighters/pzenigame/src/opff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,19 @@ unsafe fn fastfall_specials(fighter: &mut L2CFighterCommon) {
}
}

unsafe fn special_lw_track(boma: &mut BattleObjectModuleAccessor) {
if boma.is_status(*FIGHTER_STATUS_KIND_SPECIAL_LW) && !boma.is_button_on(Buttons::SpecialAll) {
let parent_id = LinkModule::get_parent_id(boma, *FIGHTER_POKEMON_LINK_NO_PTRAINER, true) as u32;
let object = utils::util::get_battle_object_from_id(parent_id);
VarModule::off_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS);
}
}

pub unsafe fn moveset(fighter: &mut L2CFighterCommon, boma: &mut BattleObjectModuleAccessor, id: usize, cat: [i32 ; 4], status_kind: i32, situation_kind: i32, motion_kind: u64, stick_x: f32, stick_y: f32, facing: f32, frame: f32) {
withdraw_jc(boma, id, status_kind, situation_kind, cat[0], stick_x, facing, frame);
nspecial_cancels(boma, status_kind, situation_kind, cat[0]);
fastfall_specials(fighter);
special_lw_track(boma);
}
#[utils::macros::opff(FIGHTER_KIND_PZENIGAME )]
pub fn pzenigame_frame_wrapper(fighter: &mut smash::lua2cpp::L2CFighterCommon) {
Expand Down
13 changes: 11 additions & 2 deletions fighters/pzenigame/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use globals::*;
// status script import

#[status_script(agent = "pzenigame", status = FIGHTER_STATUS_KIND_RUN, condition = LUA_SCRIPT_STATUS_FUNC_STATUS_END)]
pub unsafe fn end_run(fighter: &mut L2CFighterCommon) -> L2CValue {
fighter.status_end_Run();
Expand All @@ -16,9 +16,18 @@ unsafe fn pzenigame_special_s_loop_main(fighter: &mut L2CFighterCommon) -> L2CVa
ret
}

#[status_script(agent = "pzenigame", status = FIGHTER_STATUS_KIND_SPECIAL_LW, condition = LUA_SCRIPT_STATUS_FUNC_STATUS_MAIN)]
unsafe fn special_lw_main(fighter: &mut L2CFighterCommon) -> L2CValue {
let parent_id = LinkModule::get_parent_id(fighter.module_accessor, *FIGHTER_POKEMON_LINK_NO_PTRAINER, true) as u32;
let object = utils::util::get_battle_object_from_id(parent_id);
VarModule::on_flag(object, vars::ptrainer::instance::IS_SWITCH_BACKWARDS); // we will turn this off in opff
original!(fighter)
}

pub fn install() {
install_status_scripts!(
end_run,
pzenigame_special_s_loop_main
pzenigame_special_s_loop_main,
special_lw_main
);
}

0 comments on commit 6a32272

Please sign in to comment.