### Assembly typical entry point example Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, gets the C# assembly, finds a class by name, and prints its name and assembly name. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let asm = api::cache::csharp(); let player = asm.class("PlayerController").expect("class"); println!("{} in {}", player.name, asm.name); }); ``` -------------------------------- ### Example — world to screen Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge and gets the main camera, then converts a world position to screen coordinates using CameraEye::Mono. Prints the screen position and on-screen flag. ```rust use il2cpp_bridge_rs::init; use il2cpp_bridge_rs::structs::components::rendering::{Camera, CameraEye}; use il2cpp_bridge_rs::structs::Vector3; init("GameAssembly", || { let cam = Camera::get_main().ok().flatten().expect("no main camera"); let (screen, on_screen) = cam .world_to_screen(Vector3::new(0.0, 1.0, 0.0), CameraEye::Mono) .unwrap_or((Vector3::ZERO.truncate(), false)); println!("screen {:?} on_screen={}", screen, on_screen); }); ``` -------------------------------- ### Image usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, gets the core module image, prints image info and class count, and finds a class by name. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let asm = api::cache::coremodule(); // ensures cache ready let img = &asm.image; println!("image {} ({})", img.name, img.filename); println!("{} classes", img.get_classes().len()); let camera = img.class("UnityEngine.Camera").expect("camera"); println!("found {}", camera.name); }); ``` -------------------------------- ### Example — tint a renderer's material Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, gets a renderer's material, sets its color to red and float property _Glossiness to 0.5. Prints an error if no material is available. ```rust use il2cpp_bridge_rs::init; use il2cpp_bridge_rs::structs::Color; init("GameAssembly", || { // renderer from GameObject::get_component::(...) let renderer: Renderer = /* ... */; match renderer.get_material() { Ok(mat) => { let _ = mat.set_color(Color::RED); let _ = mat.set_float("_Glossiness", 0.5); } Err(e) => eprintln!("no material: {}", e), } }); ``` -------------------------------- ### Type usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to retrieve a class, get a method, and print its return type and argument type information. Uses matches_name to assert the argument type is System.Single. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let cls = api::cache::csharp().class("PlayerController").expect("class"); let m = cls.method(("TakeDamage", ["System.Single"])).expect("method"); println!("return {} ({})", m.return_type.cpp_name(), m.return_type.size); for arg in &m.args { println!(" {}: {}", arg.name, arg.type_info.cpp_name()); assert!(arg.type_info.matches_name("System.Single")); } }); ``` -------------------------------- ### Assembly chainable dump example Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, gets the C# assembly, dumps it to Assembly-CSharp.cs, and prints class count and assembly name. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let asm = api::cache::csharp(); asm.dump(); // writes Assembly-CSharp.cs under the dump directory println!("{} classes in {}", asm.classes.len(), asm.name); }); ``` -------------------------------- ### Application usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to call unity_version and identifier, printing the version or an error and the identifier. ```rust use il2cpp_bridge_rs::api::Application; match Application::unity_version() { Ok(v) => println!("Unity {}", v), Err(e) => eprintln!("{}", e), } println!("id={}", Application::identifier().unwrap_or_default()); ``` -------------------------------- ### Application::version Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the application version. ```rust pub fn version() -> Result ``` -------------------------------- ### Example — resolve a class and iterate methods Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to use api::cache::csharp() to get an assembly, find a class, and access a method by name and signature. Prints the class name, method name, and RVA. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let asm = api::cache::csharp(); let player = asm.class("PlayerController").expect("class exists"); let take_damage = player .method(("TakeDamage", ["System.Single"])) .expect("method exists"); println!("{}::{} @ 0x{:X}", player.name, take_damage.name, take_damage.rva); }); ``` -------------------------------- ### Basic init example Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the runtime with the target image 'GameAssembly' and runs a callback that accesses the C# cache. The rest of the injected library continues; callbacks run asynchronously. ```rust use il2cpp_bridge_rs::{api, init}; fn main() { init("GameAssembly", || { let asm = api::cache::csharp(); println!("Ready: {}", asm.name); }); // The rest of your injected library continues; callbacks run async. } ``` -------------------------------- ### Example — read keys and values Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to read keys and values from an Il2cppDictionary. StringKey is illustrative; key/value types must be Copy and match the managed layout. ```rust use il2cpp_bridge_rs::structs::collections::Il2cppDictionary; let dict = dict_ptr as *const Il2cppDictionary; let dict = unsafe { &*dict }; for (k, v) in dict.get_keys().iter().zip(dict.get_values().iter()) { println!("{:?} = {}", k, v); } ``` -------------------------------- ### Install il2cpp-bridge-rs with Cargo Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/README.md Adds the il2cpp-bridge-rs crate as a dependency to a Rust project. Run this in the project root before using the library. ```bash cargo add il2cpp-bridge-rs ``` -------------------------------- ### api::load usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Example of calling `api::load` with a custom loader that uses `resolve_symbol`. Handles both success and error cases, printing the count or missing required symbols. ```rust use il2cpp_bridge_rs::{api, memory::symbol::resolve_symbol}; use std::ffi::c_void; let resolved = api::load(|symbol| match resolve_symbol(symbol) { Ok(addr) => addr as *mut c_void, Err(e) => { eprintln!("missing {}", e); std::ptr::null_mut() } }); match resolved { Ok(count) => println!("loaded {} symbols", count), Err(missing) => eprintln!("missing required: {:?}", missing), } ``` -------------------------------- ### Screen methods Source: https://github.com/batchhh/il2cpp-bridge-rs Lists static methods for Screen to get width and height. ```rust pub fn get_width() -> Result pub fn get_height() -> Result ``` -------------------------------- ### Example — iterate a list Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to iterate an Il2cppList after initializing with init(). Assumes list_ptr points at a managed List. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { // Assume `list_ptr` points at a managed `List`. let list = list_ptr as *const il2cpp_bridge_rs::structs::collections::Il2cppList; let list = unsafe { &*list }; for v in list.iter() { println!("item {}", v); } }); ``` -------------------------------- ### Example — write a property with error handling Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, finds a GameSettings instance, checks for a setter, and writes volume with error handling. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let cls = api::cache::csharp().class("GameSettings").expect("class"); let obj = cls.find_objects_of_type(false).into_iter().next().expect("no obj"); let prop = obj.property("volume").expect("property"); if !prop.has_setter() { eprintln!("read-only property"); return; } match unsafe { prop.set_value(0.5f32) } { Ok(()) => println!("volume set"), Err(e) => eprintln!("failed: {}", e), } }); ``` -------------------------------- ### One-shot dump example Source: https://github.com/batchhh/il2cpp-bridge-rs Calls `api::dump_all()` inside `init` and prints the output path or an error message. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { match api::dump_all() { Some(path) => println!("wrote {}", path), None => eprintln!("dump failed"), } }); ``` -------------------------------- ### Example — fill a managed array Source: https://github.com/batchhh/il2cpp-bridge-rs Creates a managed System.Int32 array of size 5, fills it with 7, and prints length, first element, and the vector. Uses init with GameAssembly and expects the int class to exist. ```rust use il2cpp_bridge_rs::{api, init, structs::collections::Il2cppArray}; init("GameAssembly", || { let i32_cls = api::cache::mscorlib().class("System.Int32").expect("int"); let arr = Il2cppArray::::new(&i32_cls, 5); assert!(!arr.is_null()); let a = unsafe { &mut *arr }; a.fill(7); println!("len={} first={}", a.len(), a.at(0)); let vec = a.to_vector(); // [7,7,7,7,7] println!("vec={:?}", vec); }); ``` -------------------------------- ### Application::version Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the application version. ```APIDOC ## Application::version ### Description Gets the application version. ### Method `pub fn version() -> Result` ### Returns - `Result` - The application version, or an error string. ``` -------------------------------- ### Example — read a property Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, finds a PlayerController instance, and reads the moveSpeed property via get_value, printing the value. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let cls = api::cache::csharp().class("PlayerController").expect("class"); let player = cls.find_objects_of_type(false).into_iter().next() .expect("no player"); // instance-bound property lookup let speed: f32 = unsafe { player.property("moveSpeed").expect("property").get_value() }.unwrap_or(0.0); println!("moveSpeed = {}", speed); }); ``` -------------------------------- ### profiler_install Source: https://github.com/batchhh/il2cpp-bridge-rs Installs a profiler. This is a direct FFI call into the IL2CPP runtime. ```APIDOC ## profiler_install ### Description Installs a profiler. This is a direct FFI call into the IL2CPP runtime. ### Method FFI function ### Signature ```rust pub unsafe fn profiler_install(prof: *mut c_void, shutdown_callback: *mut c_void) -> (); ``` ### Parameters - `prof` (*mut c_void) - Required - Pointer to the profiler. - `shutdown_callback` (*mut c_void) - Required - Pointer to the shutdown callback. ``` -------------------------------- ### Time::get_class Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the `UnityEngine.Time` class. ```APIDOC ## Time::get_class ### Description Gets the `UnityEngine.Time` class. ### Method `pub fn get_class() -> Option` ### Returns - `Option` - The `UnityEngine.Time` class, or `None`. ``` -------------------------------- ### Time::get_class Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the UnityEngine.Time class. ```rust pub fn get_class() -> Option ``` -------------------------------- ### Time slow motion example Source: https://github.com/batchhh/il2cpp-bridge-rs Demonstrates reading delta time, setting time scale to 0.5, and printing both values. ```rust use il2cpp_bridge_rs::api::Time; let dt = Time::get_delta_time(); Time::set_time_scale(0.5); println!("dt={} scale={}", dt, Time::get_time_scale()); ``` -------------------------------- ### Color usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Shows creating a Color, comparing to a constant, and converting to Vector4. Outputs the vector via println. ```rust use il2cpp_bridge_rs::structs::{Color, Vector4}; let c = Color::new(1.0, 0.0, 0.0, 1.0); assert_eq!(c, Color::RED); let v: Vector4 = c.into(); println!("{:?}", v); ``` -------------------------------- ### Application::unity_version Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the Unity engine version; returns "unknown" when the string is empty. ```rust pub fn unity_version() -> Result ``` -------------------------------- ### profiler_install_enter_leave Source: https://github.com/batchhh/il2cpp-bridge-rs Installs enter/leave profiler callbacks. This is a direct FFI call into the IL2CPP runtime. ```APIDOC ## profiler_install_enter_leave ### Description Installs enter/leave profiler callbacks. This is a direct FFI call into the IL2CPP runtime. ### Method FFI function ### Signature ```rust pub unsafe fn profiler_install_enter_leave(enter: *mut c_void, leave: *mut c_void) -> (); ``` ### Parameters - `enter` (*mut c_void) - Required - Pointer to the enter callback. - `leave` (*mut c_void) - Required - Pointer to the leave callback. ``` -------------------------------- ### Application::unity_version Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the Unity engine version. Returns "unknown" when the string is empty. ```APIDOC ## Application::unity_version ### Description Gets the Unity engine version; returns `"unknown"` when the string is empty. ### Method `pub fn unity_version() -> Result` ### Returns - `Result` - The Unity engine version, or an error string. ``` -------------------------------- ### Application::data_path Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the persistent data path. ```rust pub fn data_path() -> Result ``` -------------------------------- ### profiler_install_allocation Source: https://github.com/batchhh/il2cpp-bridge-rs Installs an allocation profiler callback. This is a direct FFI call into the IL2CPP runtime. ```APIDOC ## profiler_install_allocation ### Description Installs an allocation profiler callback. This is a direct FFI call into the IL2CPP runtime. ### Method FFI function ### Signature ```rust pub unsafe fn profiler_install_allocation(callback: *mut c_void) -> (); ``` ### Parameters - `callback` (*mut c_void) - Required - Pointer to the allocation callback. ``` -------------------------------- ### unity_install_unitytls_interface Source: https://github.com/batchhh/il2cpp-bridge-rs Installs the UnityTLS interface. This is a direct FFI call into the IL2CPP runtime. ```APIDOC ## unity_install_unitytls_interface ### Description Installs the UnityTLS interface. This is a direct FFI call into the IL2CPP runtime. ### Method FFI function ### Signature ```rust pub unsafe fn unity_install_unitytls_interface(unitytls_interface_struct: *const c_void) -> (); ``` ### Parameters - `unitytls_interface_struct` (*const c_void) - Required - Pointer to the UnityTLS interface struct. ``` -------------------------------- ### Direct FFI call example Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to call the API directly using unsafe Rust. Retrieves the domain and its assemblies. Requires importing `il2cpp_bridge_rs::api`. ```rust use il2cpp_bridge_rs::api; unsafe { let domain = api::domain_get(); let mut size = 0usize; let assemblies = api::domain_get_assemblies(domain, &mut size); } ``` -------------------------------- ### profiler_install_gc Source: https://github.com/batchhh/il2cpp-bridge-rs Installs garbage collection profiler callbacks. This is a direct FFI call into the IL2CPP runtime. ```APIDOC ## profiler_install_gc ### Description Installs garbage collection profiler callbacks. This is a direct FFI call into the IL2CPP runtime. ### Method FFI function ### Signature ```rust pub unsafe fn profiler_install_gc(callback: *mut c_void, heap_resize_callback: *mut c_void) -> (); ``` ### Parameters - `callback` (*mut c_void) - Required - Pointer to the GC callback. - `heap_resize_callback` (*mut c_void) - Required - Pointer to the heap resize callback. ``` -------------------------------- ### Import path for init Source: https://github.com/batchhh/il2cpp-bridge-rs Import the init function from the crate. ```rust use il2cpp_bridge_rs::init; ``` -------------------------------- ### Example — write a field with error handling Source: https://github.com/batchhh/il2cpp-bridge-rs Finds a `PlayerController` object, gets the `health` field, and writes `999i32` using `set_value`. Handles the `Result` by printing success or error. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let cls = api::cache::csharp().class("PlayerController").expect("class"); let player = cls.find_objects_of_type(false).into_iter().next() .expect("no player"); let field = player.field("health").expect("field"); // set_value is unsafe and returns a Result match unsafe { field.set_value(999i32) } { Ok(()) => println!("health set"), Err(e) => eprintln!("failed: {}", e), } }); ``` -------------------------------- ### RaycastHit usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Shows using RaycastHit as output for Physics::raycast_ray. Creates a Ray and prints the hit distance if the raycast succeeds. ```rust use il2cpp_bridge_rs::structs::{math::{Physics, RaycastHit, Ray}, Vector3}; let mut hit = RaycastHit::default(); let ray = Ray { origin: Vector3::ZERO, direction: Vector3::new(0.0, 0.0, 1.0) }; if Physics::raycast_ray(ray, &mut hit, 100.0, 0.into()) { println!("hit at {}", hit.distance); } ``` -------------------------------- ### Example — enumerate assemblies by token order Source: https://github.com/batchhh/il2cpp-bridge-rs Collects all assemblies from the global cache, sorts them by the minimum class token, and prints their names. ```rust use il2cpp_bridge_rs::api::cache; let mut assemblies: Vec<_> = cache::CACHE .assemblies .iter() .map(|e| std::sync::Arc::clone(e.value())) .collect(); assemblies.sort_by_key(|a| { a.classes.iter().map(|c| c.token & 0x00FF_FFFF).min().unwrap_or(u32::MAX) }); for a in &assemblies { println!("{}", a.name); } ``` -------------------------------- ### Build documentation with make doc Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/CONTRIBUTING.md Run this command when you modify rustdoc or public-facing markdown to ensure documentation builds correctly. ```bash make doc ``` -------------------------------- ### rw read/write example Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to read an i32 from a memory address and write an incremented value back. Uses unwrap_or(0) to handle read errors and the ? operator for write errors. ```rust use il2cpp_bridge_rs::memory::rw; let value: i32 = unsafe { rw::read(0x1234_5678) }.unwrap_or(0); unsafe { rw::write(0x1234_5678, value + 1) }?; ``` -------------------------------- ### Manual dlopen workaround for Linux Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/docs/platform-support.md Manual workaround for Linux when automatic symbol promotion fails. Call this before init() to load GameAssembly.so with global visibility, or use promote_library_to_global("GameAssembly") as an alternative. ```rust unsafe { libc::dlopen(b"GameAssembly.so\0".as_ptr().cast(), libc::RTLD_NOW | libc::RTLD_GLOBAL); } ``` -------------------------------- ### Catch errors by matching message in consumer code Source: https://github.com/batchhh/il2cpp-bridge-rs Error values are `String`, so catch them by matching the message or handling all errors uniformly. This example checks if the error starts with "IL2CPP exception during invocation" to detect a managed exception leaked as a string message. ```rust let result: Result<(), String> = unsafe { method.call::<()>(&[]) }; if let Err(e) = result { if e.starts_with("IL2CPP exception during invocation") { // a managed exception leaked as a string message } } ``` -------------------------------- ### Animator get_bone_transform usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Example usage of get_bone_transform to retrieve the head bone transform. Requires prior initialization and obtaining an Animator instance via get_component. ```rust use il2cpp_bridge_rs::init; use il2cpp_bridge_rs::structs::components::{Animator, HumanBodyBones}; init("GameAssembly", || { let animator: Animator = /* from get_component */; match animator.get_bone_transform(HumanBodyBones::Head) { Ok(head) => println!("head {:p}", head.as_ptr()), Err(e) => eprintln!("{}", e), } }); ``` -------------------------------- ### image lookup example Source: https://github.com/batchhh/il2cpp-bridge-rs Demonstrates retrieving the base address of the 'GameAssembly' image and printing it in hexadecimal. Uses if let to handle the Option result. ```rust use il2cpp_bridge_rs::memory::image; if let Some(base) = image::get_image_base("GameAssembly") { println!("base = 0x{:X}", base); } ``` -------------------------------- ### Internals resolve/add usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Example of resolving an icall and registering a new one. The unsafe extern "C" function is cast to a c_void pointer for add. ```rust use il2cpp_bridge_rs::api::Internals; unsafe extern "C" fn my_icall(value: i32) -> i32 { value * 2 } let func = Internals::resolve("UnityEngine.Application::get_unityVersion"); if func.is_null() { eprintln!("icall not exposed"); } Internals::add("MyPlugin::Double", my_icall as *mut _ as *mut std::ffi::c_void); ``` -------------------------------- ### Build commands from Makefile Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/docs/platform-support.md Common build commands from the Makefile. Use these to compile, check, lint, and generate documentation for the crate. ```bash make build make build-release make check make clippy make doc ``` -------------------------------- ### Example — stringify and virtual method resolution Source: https://github.com/batchhh/il2cpp-bridge-rs Demonstrates il2cpp_to_string, get_class, and get_virtual_method on a found object. Prints the managed ToString result, class name, and virtual method pointer. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let cls = api::cache::csharp().class("PlayerController").expect("class"); let player = cls.find_objects_of_type(false).into_iter().next().expect("no player"); // managed ToString() println!("{} ", player.il2cpp_to_string()); let class = player.get_class().expect("get class"); println!("object kind: {}", class.name); // resolve the virtual implementation pointer for an instance method if let Some(m) = player.method("ToString") { let va = player.get_virtual_method(&m); println!("virtual ToString @ {:p}", va); } }); ``` -------------------------------- ### invoke_method usage example Source: https://github.com/batchhh/il2cpp-bridge-rs Example of calling invoke_method with a method obtained from class_get_method_from_name, passing null for static calls. The match handles the Ok raw pointer or Err managed exception message. ```rust use il2cpp_bridge_rs::api::{self, invoke_method}; use std::ffi::c_void; unsafe { let method = api::class_get_method_from_name(some_class, c"Run".as_ptr(), 0); let result = invoke_method(method, std::ptr::null_mut(), std::ptr::null()); match result { Ok(ptr) => println!("returned {:p}", ptr), Err(e) => eprintln!("managed exception: {}", e), } } ``` -------------------------------- ### Load scene by name with error handling example Source: https://github.com/batchhh/il2cpp-bridge-rs Example usage of SceneManager::load_scene_name to load a scene by name, with error handling. Prints loading message with scene count on success, or error on failure. ```rust use il2cpp_bridge_rs::init; use il2cpp_bridge_rs::structs::components::SceneManager; init("GameAssembly", || { match SceneManager::load_scene_name("BossRoom") { Ok(()) => println!("loading BossRoom ({} scenes)", SceneManager::scene_count()), Err(e) => eprintln!("load failed: {}", e), } }); ``` -------------------------------- ### Example — resolve an object and invoke a method Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to find an object of a class and call an instance method with a float argument. Uses init, api::cache::csharp, find_objects_of_type, method with a tuple selector, and unsafe call. ```rust use il2cpp_bridge_rs::{api, init}; use std::ffi::c_void; init("GameAssembly", || { let player = api::cache::csharp().class("PlayerController") .expect("class") .find_objects_of_type(false) .into_iter() .next() .expect("no player"); let bound = player.method(("TakeDamage", ["System.Single"])).expect("method"); let amount: f32 = 25.0; let _: Result<(), _> = unsafe { bound.call(&[&amount as *const f32 as *mut c_void]) }; }); ``` -------------------------------- ### Generic method inflation Source: https://github.com/batchhh/il2cpp-bridge-rs Gets a generic method definition 'Convert' from the 'Utility' class and inflates it with 'System.Int32', printing the concrete method name or an error. Uses 'api::cache::mscorlib()' to get the type. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let cls = api::cache::csharp().class("Utility").expect("class"); let method = cls.method("Convert").expect("generic method def"); let int_t = api::cache::mscorlib().class("System.Int32").expect("int"); match method.inflate(&[&int_t]) { Ok(concrete) => println!("inflated to {:?}", concrete.name), Err(e) => eprintln!("inflate failed: {}", e), } }); ``` -------------------------------- ### Clone and validate with make build, check, clippy Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/CONTRIBUTING.md Clone the repository and run the standard validation commands before opening a pull request. The sequence builds the crate, runs checks, and executes Clippy lints. ```bash git clone https://github.com/Batchhh/il2cpp-bridge-rs.git cd il2cpp-bridge-rs make build make check make clippy ``` -------------------------------- ### Enumerate active scene's root objects example Source: https://github.com/batchhh/il2cpp-bridge-rs Example usage of SceneManager::get_active_scene and Scene::root_game_objects to enumerate root objects. Prints scene name and loaded status, then each root object pointer. ```rust use il2cpp_bridge_rs::init; use il2cpp_bridge_rs::structs::components::SceneManager; init("GameAssembly", || { let scene = SceneManager::get_active_scene().expect("no active scene"); println!("scene '{}' loaded={}"), scene.name(), scene.is_loaded()); for go in scene.root_game_objects() { println!("root: {:p}", go.as_ptr()); } }); ``` -------------------------------- ### Convert a managed string example Source: https://github.com/batchhh/il2cpp-bridge-rs Initializes the bridge, finds a `PlayerController` object, calls `get_name` to obtain an `Il2cppString` pointer, and prints the converted string. Also shows creating a managed string for a parameter with `Il2cppString::new`. ```rust use il2cpp_bridge_rs::{api, api::cache, init}; use std::ffi::c_void; init("GameAssembly", || { let cls = api::cache::csharp().class("PlayerController").expect("class"); let player = cls.find_objects_of_type(false).into_iter().next().expect("no player"); // instance-bound get_name returns *mut Il2cppString let name_ptr: *mut il2cpp_bridge_rs::structs::Il2cppString = unsafe { player.method("get_name").expect("get_name").call(&[]) }.unwrap_or(std::ptr::null_mut()); if !name_ptr.is_null() { println!("name = {}", unsafe { (&*name_ptr).to_string().unwrap_or_default() }); } }); // Also: create a managed string for a parameter fn managed_param() { let s = il2cpp_bridge_rs::structs::Il2cppString::new("Player"); // pass s as *mut c_void where a System.String is expected let _: *mut c_void = s as *mut _; } ``` -------------------------------- ### MonoBehaviour::start_coroutine Source: https://github.com/batchhh/il2cpp-bridge-rs Starts a coroutine with the given enumerator. Errors on null enumerator or missing method / null result. ```APIDOC ## MonoBehaviour::start_coroutine ### Description Starts a coroutine with the given enumerator. Errors on null enumerator or missing method / null result. ### Method start_coroutine ### Parameters - **enumerator** (*mut c_void) - Required - The enumerator to start. ### Returns - **Result** - The Coroutine or an error message. ``` -------------------------------- ### GameObject::get_layer Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the layer of the GameObject. ```APIDOC ## [Rust] GameObject::get_layer ### Description Gets the layer of the GameObject. ### Method get_layer ### Signature pub fn get_layer(&self) -> Result ### Returns - **Result** - Ok(layer) on success, or an error message on failure. ``` -------------------------------- ### MonoBehaviour::start_coroutine_by_name Source: https://github.com/batchhh/il2cpp-bridge-rs Starts a coroutine by method name. Errors on null enumerator or missing method / null result. ```APIDOC ## MonoBehaviour::start_coroutine_by_name ### Description Starts a coroutine by method name. Errors on null enumerator or missing method / null result. ### Method start_coroutine_by_name ### Parameters - **method_name** (&str) - Required - The name of the coroutine method. ### Returns - **Result** - The Coroutine or an error message. ``` -------------------------------- ### Application::identifier Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the application identifier (bundle ID). Tries get_identifier, then get_bundleIdentifier, else returns "unknown.application". ```rust pub fn identifier() -> Result ``` -------------------------------- ### Transform::get_local_scale Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the local scale of the Transform. ```APIDOC ## [Rust] Transform::get_local_scale ### Description Gets the local scale of the Transform. ### Method get_local_scale ### Signature pub fn get_local_scale(&self) -> Result ### Returns - **Result** - Ok(Vector3) on success, or an error message on failure. ``` -------------------------------- ### dump_all Source: https://github.com/batchhh/il2cpp-bridge-rs Dumps all loaded assemblies into a single dump.cs file in the default directory. Returns the output file path on success. ```APIDOC ## dump_all ### Description Dumps all loaded assemblies into a single dump.cs file in the default directory. Returns the output file path on success. ### Method Function ### Signature ```rust pub fn dump_all() -> Option ``` ### Parameters None ### Response #### Success Response - **output** (Option) - The output file path on success. ``` -------------------------------- ### Example — class_from_ptr re-entry from a raw pointer Source: https://github.com/batchhh/il2cpp-bridge-rs Shows how to obtain a raw class pointer via api::class_from_name and then hydrate a Class from it using cache::class_from_ptr. Prints the class name and namespace. ```rust use il2cpp_bridge_rs::{api, api::cache}; let klass_ptr = api::class_from_name(some_image, c"UnityEngine".as_ptr(), c"Transform".as_ptr()); if let Some(class) = cache::class_from_ptr(klass_ptr) { println!("name={} namespace={}", class.name, class.namespace); } ``` -------------------------------- ### Transform::get_position Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the world position of the Transform. ```APIDOC ## [Rust] Transform::get_position ### Description Gets the world position of the Transform. ### Method get_position ### Signature pub fn get_position(&self) -> Result ### Returns - **Result** - Ok(Vector3) on success, or an error message on failure. ``` -------------------------------- ### Initialize IL2CPP bridge with init Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/docs/getting-started.md Initializes the IL2CPP bridge with the target image "GameAssembly" and prints the loaded assembly name. This is runtime-dependent and must run inside a live Unity IL2CPP process. ```rust use il2cpp_bridge_rs::{api, init}; init("GameAssembly", || { let asm = api::cache::csharp(); println!("Assembly loaded: {}", asm.name); }); ``` -------------------------------- ### Transform::get_game_object Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the GameObject that this Transform is attached to. ```APIDOC ## [Rust] Transform::get_game_object ### Description Gets the GameObject that this Transform is attached to. ### Method get_game_object ### Signature pub fn get_game_object(&self) -> Result ### Returns - **Result** - Ok(GameObject) on success, or an error message on failure. ``` -------------------------------- ### Import paths for api helpers Source: https://github.com/batchhh/il2cpp-bridge-rs Import the metadata dump functions and the Unity static wrappers from `il2cpp_bridge_rs::api`. ```rust use il2cpp_bridge_rs::api::{dump, dump_all, dump_all_to, dump_assembly, dump_to}; ``` ```rust use il2cpp_bridge_rs::api::Application; ``` ```rust use il2cpp_bridge_rs::api::Time; ``` -------------------------------- ### GameObject::get_scene Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the Scene that contains the GameObject. ```APIDOC ## [Rust] GameObject::get_scene ### Description Gets the Scene that contains the GameObject. ### Method get_scene ### Signature pub fn get_scene(&self) -> Result ### Returns - **Result** - Ok(Scene) on success, or an error message on failure. ``` -------------------------------- ### Local development commands Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/docs/getting-started.md Common development commands for this repository. Use these for local development and maintenance. ```bash make build ``` ```bash make check ``` ```bash make clippy ``` ```bash make doc ``` -------------------------------- ### Transform::get_child Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the child Transform at the specified index. ```APIDOC ## [Rust] Transform::get_child ### Description Gets the child Transform at the specified index. ### Method get_child ### Signature pub fn get_child(&self, index: i32) -> Result ### Parameters - **index** (i32) - Required - The index of the child. ### Returns - **Result** - Ok(Transform) on success, or an error message on failure. ``` -------------------------------- ### Transform::get_rotation Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the world rotation of the Transform as a Quaternion. ```APIDOC ## [Rust] Transform::get_rotation ### Description Gets the world rotation of the Transform as a Quaternion. ### Method get_rotation ### Signature pub fn get_rotation(&self) -> Result ### Returns - **Result** - Ok(Quaternion) on success, or an error message on failure. ``` -------------------------------- ### GameObject::get_is_static Source: https://github.com/batchhh/il2cpp-bridge-rs Gets whether the GameObject is marked as static. ```APIDOC ## [Rust] GameObject::get_is_static ### Description Gets whether the GameObject is marked as static. ### Method get_is_static ### Signature pub fn get_is_static(&self) -> Result ### Returns - **Result** - Ok(true) if static, Ok(false) if not, or an error message on failure. ``` -------------------------------- ### Transform::local_rotation Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the local rotation of the Transform relative to its parent. ```APIDOC ## [Rust] Transform::local_rotation ### Description Gets the local rotation of the Transform relative to its parent. ### Method local_rotation ### Signature pub fn local_rotation(&self) -> Result ### Returns - **Result** - Ok(Quaternion) on success, or an error message on failure. ``` -------------------------------- ### dump Source: https://github.com/batchhh/il2cpp-bridge-rs Dumps all loaded assemblies into separate .cs files in the default directory. Returns the output directory path on success, None on failure. ```APIDOC ## dump ### Description Dumps all loaded assemblies into separate .cs files in the default directory. Returns the output directory path on success, None on failure. ### Method Function ### Signature ```rust pub fn dump() -> Option ``` ### Parameters None ### Response #### Success Response - **output** (Option) - The output directory path on success, None on failure. ``` -------------------------------- ### Transform::local_position Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the local position of the Transform relative to its parent. ```APIDOC ## [Rust] Transform::local_position ### Description Gets the local position of the Transform relative to its parent. ### Method local_position ### Signature pub fn local_position(&self) -> Result ### Returns - **Result** - Ok(Vector3) on success, or an error message on failure. ``` -------------------------------- ### GameObject::get_active_in_hierarchy Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the active state of the GameObject considering the parent hierarchy. ```APIDOC ## [Rust] GameObject::get_active_in_hierarchy ### Description Gets the active state of the GameObject considering the parent hierarchy. ### Method get_active_in_hierarchy ### Signature pub fn get_active_in_hierarchy(&self) -> Result ### Returns - **Result** - Ok(true) if active in hierarchy, Ok(false) if inactive, or an error message on failure. ``` -------------------------------- ### Platform-specific build commands Source: https://github.com/batchhh/il2cpp-bridge-rs/blob/main/docs/platform-support.md Platform-specific build commands from the Makefile. Use the command matching your target platform to build the crate for that platform. ```bash make build-ios make build-macos make build-linux make build-android make build-windows ``` -------------------------------- ### GameObject::get_active_self Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the active state of the GameObject itself (not considering parent hierarchy). ```APIDOC ## [Rust] GameObject::get_active_self ### Description Gets the active state of the GameObject itself (not considering parent hierarchy). ### Method get_active_self ### Signature pub fn get_active_self(&self) -> Result ### Returns - **Result** - Ok(true) if active, Ok(false) if inactive, or an error message on failure. ``` -------------------------------- ### init function signature Source: https://github.com/batchhh/il2cpp-bridge-rs The init function takes a target image name and a callback. It resolves IL2CPP exports, loads the function table, attaches the worker thread, initializes the metadata cache, hydrates metadata, and runs queued callbacks. The callback is executed asynchronously on a freshly spawned thread. ```rust pub fn init(target_image: &str, on_complete: F) where F: FnOnce() + Send + 'static, ``` -------------------------------- ### GameObject::get_transform Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the Transform component of the GameObject. Returns an error if the Transform is null. ```APIDOC ## [Rust] GameObject::get_transform ### Description Gets the Transform component of the GameObject. Returns an error if the Transform is null. ### Method get_transform ### Signature pub fn get_transform(&self) -> Result ### Returns - **Result** - Ok(Transform) on success, or an error message if the Transform is null. ``` -------------------------------- ### create_instance method signature Source: https://github.com/batchhh/il2cpp-bridge-rs Creates a managed instance via System.Activator.CreateInstance (constructor semantics). Errors on missing Type object, missing System.Activator / CreateInstance(Type) resolution, null result, or invocation failure. ```rust pub fn create_instance(&self) -> Result ``` -------------------------------- ### dump_all function signature Source: https://github.com/batchhh/il2cpp-bridge-rs Dumps all loaded assemblies into a single `dump.cs` file in the default directory. Returns the output file path on success. ```rust pub fn dump_all() -> Option ``` -------------------------------- ### dump_to Source: https://github.com/batchhh/il2cpp-bridge-rs Dumps all loaded assemblies into separate .cs files under the specified base_path. Returns the output directory path on success. ```APIDOC ## dump_to ### Description Dumps all loaded assemblies into separate .cs files under the specified base_path. Returns the output directory path on success. ### Method Function ### Signature ```rust pub fn dump_to(base_path: &str) -> Option ``` ### Parameters #### Parameters - **base_path** (&str) - Required - Root directory; output goes to `/dump/`. ### Response #### Success Response - **output** (Option) - The output directory path on success. ``` -------------------------------- ### dump function signature Source: https://github.com/batchhh/il2cpp-bridge-rs Dumps all loaded assemblies into separate `.cs` files in the default directory. Returns the output directory path on success, `None` on failure. ```rust pub fn dump() -> Option ``` -------------------------------- ### Transform::get_child_count Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the number of child transforms. Swallows errors and returns 0 on failure. ```APIDOC ## [Rust] Transform::get_child_count ### Description Gets the number of child transforms. Swallows errors and returns 0 on failure. ### Method get_child_count ### Signature pub fn get_child_count(&self) -> i32 ### Returns - **i32** - The number of children, or 0 on failure. ``` -------------------------------- ### Transform::get_lossy_scale Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the lossy scale of the Transform (world scale considering parent scaling). ```APIDOC ## [Rust] Transform::get_lossy_scale ### Description Gets the lossy scale of the Transform (world scale considering parent scaling). ### Method get_lossy_scale ### Signature pub fn get_lossy_scale(&self) -> Result ### Returns - **Result** - Ok(Vector3) on success, or an error message on failure. ``` -------------------------------- ### create_instance Source: https://github.com/batchhh/il2cpp-bridge-rs Creates a managed instance via System.Activator.CreateInstance (constructor semantics). Errors: missing Type object, missing System.Activator / CreateInstance(Type) resolution, null result, or invocation failure. ```APIDOC ## create_instance ### Description Creates a managed instance via System.Activator.CreateInstance (constructor semantics). Errors: missing Type object, missing System.Activator / CreateInstance(Type) resolution, null result, or invocation failure. ### Method Signature ```rust pub fn create_instance(&self) -> Result ``` ``` -------------------------------- ### GameObject::get_component Source: https://github.com/batchhh/il2cpp-bridge-rs Gets a component of type T from the GameObject. The component type must implement ComponentTrait. ```APIDOC ## [Rust] GameObject::get_component ### Description Gets a component of type T from the GameObject. The component type must implement ComponentTrait. ### Method get_component ### Signature pub fn get_component(&self, class: &Class) -> Result ### Parameters - **class** (&Class) - Required - The Unity class of the component to retrieve. ### Returns - **Result** - Ok(T) on success, or an error message on failure. ``` -------------------------------- ### UnityObject::instantiate_at Source: https://github.com/batchhh/il2cpp-bridge-rs Instantiates a copy of the original Unity object at a given position and rotation. Calls `Object.Instantiate` overload with 3 arguments. Errors on missing method or null result. ```APIDOC ## UnityObject::instantiate_at ### Description Instantiates a copy of the original Unity object at a given position and rotation. Calls `Object.Instantiate` overload with 3 arguments. Errors on missing method or null result. ### Method `instantiate_at` ### Signature ```rust pub fn instantiate_at(original: &UnityObject, position: Vector3, rotation: Quaternion) -> Result ``` ### Parameters - `original` (&UnityObject) - Required - The original object to instantiate. - `position` (Vector3) - Required - The position for the new instance. - `rotation` (Quaternion) - Required - The rotation for the new instance. ### Return Value - `Result` - The new instance, or an error message. ``` -------------------------------- ### UnityObject::get_class Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the Unity class of the object (UnityEngine.Object). ```APIDOC ## UnityObject::get_class ### Description Gets the Unity class of the object (UnityEngine.Object). ### Method `get_class` ### Signature ```rust pub fn get_class() -> Option ``` ### Return Value - `Option` - The class, or `None` if not available. ``` -------------------------------- ### Application::data_path Source: https://github.com/batchhh/il2cpp-bridge-rs Gets the persistent data path. ```APIDOC ## Application::data_path ### Description Gets the persistent data path. ### Method `pub fn data_path() -> Result` ### Returns - `Result` - The persistent data path, or an error string. ```