Expand description
Typed Unity wrappers for mods of Unity Il2Cpp games, on top of
hao_il2cpp_runtime.
The runtime crate finds and hooks methods by name. This crate wraps common Unity functionality the same way for any Unity game: game objects and components, UI, scenes, logging and time. Each Unity method is looked up the first time it’s used and checked against the game’s real signature, so a game whose Unity version differs gives an error rather than a crash.
use std::sync::OnceLock;
use hao_il2cpp_unity::{on_scene_loaded, TextOverlay};
static OVERLAY: OnceLock<TextOverlay> = OnceLock::new();
hao_il2cpp_unity::on_init(|_| {
on_scene_loaded(|scene, _| {
let overlay = OVERLAY.get_or_init(|| TextOverlay::new("my mod").unwrap());
overlay.set_text(&format!("scene: {}", scene.name().unwrap())).unwrap();
})
});Unity’s API may only be used from its main thread: inside hooks of methods
the game calls on it, such as on_scene_loaded’s callbacks.
Re-exports§
pub use hao_il2cpp_runtime as runtime;
Modules§
- application
UnityEngine.Application.- egui
- egui integration (requires the
eguifeature). Seeon_egui. - gl
- Immediate-mode drawing with
UnityEngine.GL, for use inside anon_rendercallback (it’s only valid during rendering). - input
UnityEngine.Input(the legacy input manager).- reflect
- Reflection roots for the
reflectfeature. Seehao::reflectfor the pattern. The overlay and binding handles hold engine pointers and are not reflected; the plain-data types are. - screen
UnityEngine.Screen.- time
Time.
Structs§
- Camera
UnityEngine.Camera, passed toon_rendercallbacks.- Canvas
UnityEngine.Canvas, the root of a UI.- Color
UnityEngine.Color, with components from 0 to 1.- Component
UnityEngine.Component.- Filter
Mode UnityEngine.FilterMode, how a texture is sampled.POINTsamples the nearest texel exactly (no blending with neighbours).- Game
Object UnityEngine.GameObject.- Hide
Flags UnityEngine.HideFlags.HIDE_AND_DONT_SAVEkeeps a runtime-created object (e.g. aMaterial) from being destroyed on scene load.- KeyCode
UnityEngine.KeyCode, forinput. A few common keys are named; any other can be made withKeyCode(value).- Load
Scene Mode UnityEngine.SceneManagement.LoadSceneMode.- Material
UnityEngine.Material, e.g. for agldrawing pass.- Overlay
Canvas - A screen-space-overlay
Canvasdrawn on top of the game’s own UI (the maximum sorting order) and kept across scene loads. Parent UI elements, or aRawImage, undergame_object. - Overlay
Surface - A full-screen off-screen target shown on top of the game’s UI, for drawing an
overlay with the
glmodule. - Quaternion
UnityEngine.Quaternion, a rotation. UseQuaternion::eulerto build one.- RawImage
UnityEngine.UI.RawImage, a UI element that draws a rawTexture2DorRenderTexture.- Rect
Transform UnityEngine.RectTransform, the transform of UI elements.- Render
Mode UnityEngine.RenderMode, how aCanvasis drawn.- Render
Texture UnityEngine.RenderTexture, an off-screen render target.- Scene
UnityEngine.SceneManagement.Scene.- Shader
UnityEngine.Shader.- Text
Mesh Pro TMPro.TextMeshProUGUI, TextMeshPro text in a UI.- Text
Overlay - A line of TextMeshPro text on its own
OverlayCanvas, drawn over the game’s UI and kept across scene loads. Positioned from the top left of the screen. - Texture2D
UnityEngine.Texture2D.- Texture
Format UnityEngine.TextureFormat.- Transform
UnityEngine.Transform: position in the scene and the parent/child hierarchy.- Unity
Object UnityEngine.Object, the base of everything Unity manages.- Vector2
UnityEngine.Vector2.- Vector3
UnityEngine.Vector3.
Traits§
- Component
Type - A component type, for
GameObject::add_component.
Functions§
- check_
bindings - Resolves every wrapped Unity method against the running game, returning the ones that are missing or have a different signature.
- find_
object_ of_ type - The first active object of type
T, orNone(Object.FindObjectOfType). - find_
objects_ of_ type - Every active object of type
Tin the loaded scenes (Object.FindObjectsOfType). - log
Debug.Log: writes to the game’s log (Player.log).- log_
error Debug.LogError.- log_
warning Debug.LogWarning.- on_init
- Runs
callbackonceil2cpp_inithas finished, or straight away if it already has. - on_
render - Runs
callbackon the render thread after each camera finishes rendering, passing theCamera. This is where to draw an overlay on top of the game withgl, or to drive an immediate-mode UI such as egui. - on_
scene_ loaded - Runs
callbackon Unity’s main thread after each scene loads, which is a good time to add objects to the game. Panics are caught and printed. - on_
update - Runs
callbackonce per frame on Unity’s main thread, a good place to update an overlay. Panics are caught and printed.