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