Skip to content

Instantly share code, notes, and snippets.

@jugeeya
Last active May 7, 2020 01:28
Show Gist options
  • Save jugeeya/53c211c854f1acbffddc2fcd9aa87d3a to your computer and use it in GitHub Desktop.
Save jugeeya/53c211c854f1acbffddc2fcd9aa87d3a to your computer and use it in GitHub Desktop.
status_Catch_Main replacement
#![feature(proc_macro_hygiene)]
use smash::hash40;
use smash::lib::lua_const::{*};
use smash::lib::{self, L2CAgent, L2CValue};
use smash::app;
use smash::app::{lua_bind::*, sv_animcmd, sv_system};
use skyline::libc::{size_t, c_int, c_void, strlen};
use smash::Result;
use skyline::nro::{self, NroInfo};
use skyline::logging::HexDump;
extern "C" {
#[link_name = "\u{1}_ZN7lua2cpp16L2CFighterCommon17status_Catch_MainEv"]
pub fn status_Catch_Main(
arg1: *mut L2CAgent
) -> u64;
#[link_name = "\u{1}_ZN7lua2cpp16L2CFighterCommon28sub_wait_ground_check_commonEN3lib8L2CValueE"]
pub fn sub_wait_ground_check_common(
arg1: *mut L2CAgent,
arg2: L2CValue
) -> L2CValue;
#[link_name = "\u{1}_ZN7lua2cpp16L2CFighterCommon25sub_air_check_fall_commonEv"]
pub fn sub_air_check_fall_common(
arg1: *mut L2CAgent
) -> L2CValue;
#[link_name = "\u{1}_ZN7lua2cpp14L2CFighterBase13change_statusEN3lib8L2CValueES2_"]
pub fn change_status(
arg1: *mut L2CAgent,
arg2: L2CValue,
arg3: L2CValue
) -> u64;
}
#[allow(unused_unsafe)]
#[skyline::hook(replace = status_Catch_Main)]
pub unsafe fn handle_status_Catch_Main(fighter: *mut L2CAgent) {
let module_accessor = sv_system::battle_object_module_accessor((*fighter).lua_state_agent);
// if CancelModule::is_enable_cancel(module_accessor) {
// let ret = sub_wait_ground_check_common(fighter, L2CValue::new_bool(false));
// println!("{}", HexDump(&ret));
// // sub_air_check_fall_common(fighter);
// }
let situation_kind = StatusModule::situation_kind(module_accessor) as i32;
if situation_kind == SITUATION_KIND_AIR {
// change_status(fighter,L2CValue::new_int(*FIGHTER_STATUS_KIND_FALL as u64), L2CValue::new_bool(false));
StatusModule::change_status_request(module_accessor, *FIGHTER_STATUS_KIND_FALL, false);
return;
}
if WorkModule::is_enable_transition_term(module_accessor,*FIGHTER_STATUS_TRANSITION_TERM_ID_WAIT) {
if MotionModule::is_end(module_accessor) {
if situation_kind != SITUATION_KIND_GROUND {
return;
}
// change_status(fighter,L2CValue::new_int(*FIGHTER_STATUS_KIND_WAIT as u64), L2CValue::new_bool(false));
StatusModule::change_status_request(module_accessor, *FIGHTER_STATUS_KIND_WAIT, false);
return;
}
}
// original!()(fighter); // to call original
}
fn nro_main(nro: &NroInfo) {
match nro.name {
"common" =>
{
println!("Loaded common NRO!");
skyline::install_hook!(handle_status_Catch_Main);
},
_ => ()
}
}
#[skyline::main(name = "test")]
pub fn main() {
println!("Hello from Skyline plugin!");
nro::add_hook(nro_main).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment