use hao_il2cpp_unity::runtime::{Object, Original};
#[used]
#[link_section = ".init_array"]
static LOAD: extern "C" fn() = load;
fn init_logging() {
let filter =
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into());
let _ = tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(std::io::stderr)
.try_init();
}
extern "C" fn load() {
init_logging();
hao_il2cpp_unity::on_init(|il2cpp| {
let health = il2cpp.class(
"Assembly-CSharp",
"Assets.Scripts.Inventory__Items__Pickups",
"PlayerHealth",
)?;
let hp = health.field("hp")?;
health.method("Heal", 2)?.hook(
move |this: Object, amount: f32, overheal: bool, original: Original<_, i32>| {
let healed = original.call((this, amount * 2.0, overheal));
let hp: i32 = unsafe { hp.read(this) };
let _ = hao_il2cpp_unity::log(&format!(
"[heal_mod] healed {} instead of {}, hp is now {}",
healed, amount, hp
));
healed
},
)?;
tracing::info!("hooked PlayerHealth.Heal");
Ok(())
});
}