Skip to main content

Crate hao_il2cpp_runtime

Crate hao_il2cpp_runtime 

Source
Expand description

Hook and call into a Unity Il2Cpp game from inside its process, the way MelonLoader mods do.

A mod is a cdylib loaded into the game (on Linux with LD_PRELOAD). on_init runs once the game’s Il2Cpp runtime has started, and from there methods are found by name and hooked with ordinary closures. The closure’s types are checked against the method’s real signature when the hook is installed:

use hao_il2cpp_runtime::{Il2Cpp, Object, Original};

hao_il2cpp_runtime::on_init(|il2cpp: &'static Il2Cpp| {
    let health = il2cpp.class("Assembly-CSharp", "Assets.Scripts.Inventory__Items__Pickups", "PlayerHealth")?;
    // `int Heal(float amount, bool allowOverheal)`: the instance comes first.
    health.method("Heal", 2)?.hook(|this: Object, amount: f32, overheal: bool, original: Original<_, i32>| {
        original.call((this, amount * 2.0, overheal))
    })?;
    Ok(())
});

Modules§

element
Managed element types (Il2CppTypeEnum).
reflect
Reflection roots for the reflect feature. See hao::reflect for the pattern. Only the plain-data types reflect; the runtime handles (raw pointers, GC handles, hooks) do not.

Macros§

original
Inside a detour from Method::hook_raw, gets the function that calls the original method. Must be the first thing the detour does.

Structs§

Api
Function pointers into the game’s Il2Cpp runtime.
Class
A managed class (Il2CppClass*).
Field
A managed field (FieldInfo*).
GcHandle
Keeps an object alive and findable after the garbage collector moves or would free it. The collector doesn’t scan Rust memory, so objects kept between calls (in statics or closures) need one. Freed on drop.
Il2Cpp
The game’s Il2Cpp runtime.
Il2CppString
A managed string (Il2CppString*), possibly null.
Method
A managed method (MethodInfo*).
MethodHook
An applied method hook. Dropping it leaves the hook in place.
Object
A managed object reference (Il2CppObject*), possibly null.
Original
Calls the original code of a hooked method.
Parameter
A method parameter’s name and managed type name, from Method::parameters.
Signature
The Rust types of a hook or call, checked against the method before use.
TypeInfo
The managed type of a parameter or return value.
ValueCheck
How a Rust type is checked against a managed parameter or return type.

Enums§

Error

Traits§

HookCallback
A closure usable as a hook for a method with parameters Args returning R. Implemented for Fn(args..., Original<(args...), R>) -> R.
Il2CppValue
A Rust type that has the same representation as some managed types when passed to and from compiled Il2Cpp code.
MethodArgs
Argument tuples for Method::call.

Functions§

find_game_assembly
The game binary in a game folder, whichever platform the game was built for.
is_game_assembly
Whether path is a game binary: GameAssembly.so, GameAssembly.dll or any other GameAssembly.*. Both / and \\ separate directories, as Windows paths can show up on Linux under Wine.
loaded_game_assembly
The game binary mapped into this process, if any.
on_init
Runs callback once il2cpp_init has finished, or straight away if it already has.
read_field⚠
Reads a managed object’s field at offset (from Class::field_offset).
write_field⚠
Writes a managed object’s field at offset. Only for fields that don’t hold references.

Type Aliases§

MethodInfo
The hidden last argument of every Il2Cpp method (const MethodInfo*).
Ptr
Result