Skip to content

Commit

Permalink
add weapon hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jugeeya committed Jul 11, 2020
1 parent 4d126a3 commit 3119614
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#![feature(proc_macro_hygiene)]

use smash::lib::L2CValue;
use smash::lua2cpp::L2CFighterCommon;
use smash::lua2cpp::L2CAgentBase;
use smash::lua2cpp::{L2CAgentBase, L2CFighterBase, L2CFighterCommon, L2CWeaponCommon};
use smash::phx::Hash40;
use parking_lot::RwLock;

type Callback = fn(&mut L2CFighterCommon);
type WeaponCallback = fn(&mut L2CFighterBase);
type Predicate = unsafe fn(&mut L2CAgentBase, Hash40) -> bool;

static HOOKS: RwLock<Vec<Callback>> = RwLock::new(Vec::new());
static WEAPON_HOOKS: RwLock<Vec<WeaponCallback>> = RwLock::new(Vec::new());
static PREDS: RwLock<Vec<Predicate>> = RwLock::new(Vec::new());

#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_sys_line_system_control_fighter)]
Expand All @@ -21,6 +22,15 @@ pub unsafe fn sys_line_system_control_fighter_hook(fighter: &mut L2CFighterCommo
original!()(fighter)
}

#[skyline::hook(replace = smash::lua2cpp::L2CFighterBase_sys_line_system_control)]
pub unsafe fn sys_line_system_control_hook(fighter_base: &mut L2CFighterBase) -> L2CValue {
for hook in WEAPON_HOOKS.read().iter() {
hook(fighter_base)
}

original!()(fighter_base)
}

#[skyline::hook(replace = smash::lua2cpp::L2CAgentBase_call_coroutine)]
pub unsafe fn call_coroutine_hook(
agent: &mut smash::lua2cpp::L2CAgentBase,
Expand All @@ -40,8 +50,10 @@ pub unsafe fn call_coroutine_hook(
fn nro_main(nro: &skyline::nro::NroInfo) {
match nro.name {
"common" => {
skyline::install_hook!(sys_line_system_control_fighter_hook);
skyline::install_hook!(call_coroutine_hook);
skyline::install_hooks!(
sys_line_system_control_hook,
sys_line_system_control_fighter_hook,
call_coroutine_hook);
}
_ => (),
}
Expand All @@ -60,3 +72,12 @@ pub extern "Rust" fn add_acmd_load_hook(hook: Callback, predicate: Predicate) {
hooks.push(hook);
preds.push(predicate);
}

#[no_mangle]
pub extern "Rust" fn add_acmd_load_weapon_hook(hook: WeaponCallback, predicate: Predicate) {
let mut weapon_hooks = WEAPON_HOOKS.write();
let mut preds = PREDS.write();

weapon_hooks.push(hook);
preds.push(predicate);
}

0 comments on commit 3119614

Please sign in to comment.