Skip to main content

Method

Struct Method 

Source
pub struct Method { /* private fields */ }
Expand description

A managed method (MethodInfo*).

Implementations§

Source§

impl Method

Source

pub fn is_instance(&self) -> bool

Source

pub fn parameter_count(&self) -> u32

Source

pub fn return_type_name(&self) -> String

The managed name of the return type, e.g. System.Int32.

Source

pub fn parameter_type_name(&self, index: u32) -> String

The managed type name of parameter index, e.g. System.Single.

Source

pub fn parameter_name(&self, index: u32) -> String

The declared name of parameter index, e.g. amount. Release builds often strip these to arg0, arg1, …

Source

pub fn parameters(&self) -> impl Iterator<Item = Parameter> + '_

The parameters, each with its name and type name.

Source

pub fn signature(&self) -> String

The managed signature, e.g. System.Int32 Heal(System.Single, System.Boolean), built from Method::return_type_name, Method::name and Method::parameters.

Source

pub fn check_types<Args: MethodArgs, R: Il2CppValue>(&self) -> Result<()>

Checks argument types Args (a tuple, with the instance first for instance methods) and return type R against the method’s signature, as Method::hook and Method::call do.

Source

pub fn hook<Args, R, F: HookCallback<Args, R>>( &self, callback: F, ) -> Result<MethodHook>

Redirects calls of this method to callback, after checking its types against the method’s signature. The callback gets the arguments (the instance first for instance methods) and an Original to call the original code with.

let heal = il2cpp.class("Assembly-CSharp", "Game", "PlayerHealth")?.method("Heal", 2)?;
heal.hook(|this: Object, amount: f32, overheal: bool, original: Original<_, i32>| {
    original.call((this, amount * 2.0, overheal))
})?;
Source

pub fn call<Args: MethodArgs, R: Il2CppValue>(&self, args: Args) -> Result<R>

Calls the method’s compiled code after checking the argument and return types. args is a tuple, with the instance first for instance methods.

Managed exceptions thrown by the method unwind through the caller.

Source

pub unsafe fn call_unchecked<Args: MethodArgs, R: Il2CppValue>( &self, args: Args, ) -> R

Method::call without the type check, for calls made often after Method::check_types has passed once.

§Safety

Args and R must pass Method::check_types for this method.

Source§

impl Method

Source

pub fn as_ptr(&self) -> MethodInfo

The MethodInfo*, passed as the last argument when calling the method.

Source

pub fn name(&self) -> &'static str

Source

pub fn code(&self) -> *mut c_void

The method’s compiled code. Call it with the instance first (for instance methods), then the arguments, then Method::as_ptr.

Source

pub unsafe fn hook_raw(&self, detour: *mut u8) -> Result<MethodHook>

Redirects every call of the method to detour, which has the method’s signature as described on Method::code. Inside the detour, original! gets a function that calls the original code. Method::hook is the safe, typed version of this.

The hook stays in place when the returned value is dropped.

§Safety

detour must be an extern "C" function with exactly the method’s signature.

Trait Implementations§

Source§

impl Clone for Method

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Method

Source§

impl Send for Method

Source§

impl Sync for Method

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more