il2cpp_bridge_rs/api/core/internals.rs
1//! Helpers for resolving and registering IL2CPP internal calls.
2//!
3//! These functions are lower-level than the usual cache/object workflow and are
4//! mainly useful when Unity exposes the functionality you need as an icall.
5use super::api;
6use std::ffi::{c_void, CString};
7
8/// Resolver and registration helper for IL2CPP internal calls.
9pub struct Internals;
10
11impl Internals {
12 /// Resolves an internal call by its fully qualified name.
13 ///
14 /// Returns a raw function pointer or null if the icall is unavailable in
15 /// the current runtime.
16 pub fn resolve(name: &str) -> *mut c_void {
17 let name_c = CString::new(name).unwrap();
18 unsafe { api::resolve_icall(name_c.as_ptr()) }
19 }
20
21 /// Registers a new internal call implementation.
22 ///
23 /// This is mainly relevant when embedding or extending a runtime that
24 /// expects a native implementation to be available through the icall table.
25 pub fn add(name: &str, method: *mut c_void) {
26 let name_c = CString::new(name).unwrap();
27 unsafe { api::add_internal_call(name_c.as_ptr(), method) }
28 }
29}