1mod binding;
29mod bindings;
30pub mod dispatch;
31#[cfg(feature = "egui")]
32pub mod egui {
33 pub use crate::egui_backend::{on_egui, register_user_texture, set_ui_scale, unregister_user_texture};
35 pub use ::egui::*;
36}
37#[cfg(feature = "egui")]
38mod egui_backend;
39pub mod gl;
40mod lifecycle;
41mod objects;
42mod overlay;
43mod scene;
44#[cfg(feature = "reflect")]
45pub mod reflect;
46mod values;
47
48pub use hao_il2cpp_runtime as runtime;
49#[cfg(unix)]
50pub use hao_il2cpp_runtime::on_init;
51use hao_il2cpp_runtime::{Error, Il2Cpp, Result};
52pub use lifecycle::{is_shutting_down, on_render, on_update, shutdown};
53pub use objects::{
54 find_object_of_type, find_objects_of_type, Camera, Canvas, Component, ComponentType,
55 GameObject, Material, RawImage, RectTransform, RenderTexture, Shader, TextMeshPro, Texture2D,
56 Transform, UnityObject,
57};
58pub use overlay::{OverlayCanvas, OverlaySurface, TextOverlay};
59pub use scene::{on_scene_loaded, Scene};
60pub use values::{
61 Color, FilterMode, HideFlags, KeyCode, LoadSceneMode, Quaternion, RenderMode, TextureFormat,
62 Vector2, Vector3,
63};
64
65impl Quaternion {
66 pub fn euler(x: f32, y: f32, z: f32) -> Result<Self> {
68 bindings::QUATERNION_EULER.call((x, y, z))
69 }
70}
71
72use bindings::*;
73
74fn il2cpp() -> Result<&'static Il2Cpp> {
75 Il2Cpp::get().ok_or_else(|| Error::NotFound("the Il2Cpp runtime".into()))
76}
77
78pub fn log(message: &str) -> Result<()> {
80 DEBUG_LOG.call((il2cpp()?.string(message)?.0,))
81}
82
83pub fn log_warning(message: &str) -> Result<()> {
85 DEBUG_LOG_WARNING.call((il2cpp()?.string(message)?.0,))
86}
87
88pub fn log_error(message: &str) -> Result<()> {
90 DEBUG_LOG_ERROR.call((il2cpp()?.string(message)?.0,))
91}
92
93pub mod time {
95 use super::*;
96
97 pub fn delta() -> Result<f32> {
99 TIME_DELTA.call(())
100 }
101
102 pub fn frame_count() -> Result<i32> {
104 TIME_FRAME_COUNT.call(())
105 }
106
107 pub fn scale() -> Result<f32> {
109 TIME_GET_SCALE.call(())
110 }
111
112 pub fn set_scale(scale: f32) -> Result<()> {
113 TIME_SET_SCALE.call((scale,))
114 }
115
116 pub fn time() -> Result<f32> {
118 TIME_GET_TIME.call(())
119 }
120
121 pub fn realtime_since_startup() -> Result<f32> {
123 TIME_REALTIME.call(())
124 }
125}
126
127pub mod screen {
129 use super::*;
130
131 pub fn width() -> Result<i32> {
132 SCREEN_WIDTH.call(())
133 }
134
135 pub fn height() -> Result<i32> {
136 SCREEN_HEIGHT.call(())
137 }
138
139 pub fn size() -> Result<(i32, i32)> {
141 Ok((width()?, height()?))
142 }
143}
144
145pub mod input {
147 use super::*;
148
149 pub fn key(key: KeyCode) -> Result<bool> {
151 INPUT_GET_KEY.call((key,))
152 }
153
154 pub fn key_down(key: KeyCode) -> Result<bool> {
156 INPUT_GET_KEY_DOWN.call((key,))
157 }
158
159 pub fn key_up(key: KeyCode) -> Result<bool> {
161 INPUT_GET_KEY_UP.call((key,))
162 }
163
164 pub fn mouse_button(button: i32) -> Result<bool> {
166 INPUT_GET_MOUSE_BUTTON.call((button,))
167 }
168
169 pub fn mouse_position() -> Result<Vector3> {
171 INPUT_MOUSE_POSITION.call(())
172 }
173
174 pub fn scroll_delta() -> Result<Vector2> {
176 INPUT_SCROLL_DELTA.call(())
177 }
178
179 pub fn input_string() -> Result<String> {
182 Ok(INPUT_STRING.call(())?.to_rust().unwrap_or_default())
183 }
184}
185
186pub mod application {
188 use super::*;
189
190 pub fn is_playing() -> Result<bool> {
191 APPLICATION_IS_PLAYING.call(())
192 }
193
194 pub fn quit(exit_code: i32) -> Result<()> {
196 APPLICATION_QUIT.call((exit_code,))
197 }
198}
199
200pub fn check_bindings() -> Vec<(String, Error)> {
203 bindings::all()
204 .into_iter()
205 .filter_map(|b| b.check().err().map(|e| (b.describe(), e)))
206 .collect()
207}