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;
43mod values;
44
45pub use hao_il2cpp_runtime as runtime;
46#[cfg(unix)]
47pub use hao_il2cpp_runtime::on_init;
48use hao_il2cpp_runtime::{Error, Il2Cpp, Result};
49pub use lifecycle::{on_render, on_update};
50pub use objects::{
51 find_object_of_type, find_objects_of_type, Camera, Canvas, Component, ComponentType,
52 GameObject, Material, RawImage, RectTransform, RenderTexture, Shader, TextMeshPro, Texture2D,
53 Transform, UnityObject,
54};
55pub use overlay::{OverlayCanvas, OverlaySurface, TextOverlay};
56pub use scene::{on_scene_loaded, Scene};
57pub use values::{
58 Color, FilterMode, HideFlags, KeyCode, LoadSceneMode, Quaternion, RenderMode, TextureFormat,
59 Vector2, Vector3,
60};
61
62impl Quaternion {
63 pub fn euler(x: f32, y: f32, z: f32) -> Result<Self> {
65 bindings::QUATERNION_EULER.call((x, y, z))
66 }
67}
68
69use bindings::*;
70
71fn il2cpp() -> Result<&'static Il2Cpp> {
72 Il2Cpp::get().ok_or_else(|| Error::NotFound("the Il2Cpp runtime".into()))
73}
74
75pub fn log(message: &str) -> Result<()> {
77 DEBUG_LOG.call((il2cpp()?.string(message)?.0,))
78}
79
80pub fn log_warning(message: &str) -> Result<()> {
82 DEBUG_LOG_WARNING.call((il2cpp()?.string(message)?.0,))
83}
84
85pub fn log_error(message: &str) -> Result<()> {
87 DEBUG_LOG_ERROR.call((il2cpp()?.string(message)?.0,))
88}
89
90pub mod time {
92 use super::*;
93
94 pub fn delta() -> Result<f32> {
96 TIME_DELTA.call(())
97 }
98
99 pub fn frame_count() -> Result<i32> {
101 TIME_FRAME_COUNT.call(())
102 }
103
104 pub fn scale() -> Result<f32> {
106 TIME_GET_SCALE.call(())
107 }
108
109 pub fn set_scale(scale: f32) -> Result<()> {
110 TIME_SET_SCALE.call((scale,))
111 }
112
113 pub fn time() -> Result<f32> {
115 TIME_GET_TIME.call(())
116 }
117
118 pub fn realtime_since_startup() -> Result<f32> {
120 TIME_REALTIME.call(())
121 }
122}
123
124pub mod screen {
126 use super::*;
127
128 pub fn width() -> Result<i32> {
129 SCREEN_WIDTH.call(())
130 }
131
132 pub fn height() -> Result<i32> {
133 SCREEN_HEIGHT.call(())
134 }
135
136 pub fn size() -> Result<(i32, i32)> {
138 Ok((width()?, height()?))
139 }
140}
141
142pub mod input {
144 use super::*;
145
146 pub fn key(key: KeyCode) -> Result<bool> {
148 INPUT_GET_KEY.call((key,))
149 }
150
151 pub fn key_down(key: KeyCode) -> Result<bool> {
153 INPUT_GET_KEY_DOWN.call((key,))
154 }
155
156 pub fn key_up(key: KeyCode) -> Result<bool> {
158 INPUT_GET_KEY_UP.call((key,))
159 }
160
161 pub fn mouse_button(button: i32) -> Result<bool> {
163 INPUT_GET_MOUSE_BUTTON.call((button,))
164 }
165
166 pub fn mouse_position() -> Result<Vector3> {
168 INPUT_MOUSE_POSITION.call(())
169 }
170
171 pub fn scroll_delta() -> Result<Vector2> {
173 INPUT_SCROLL_DELTA.call(())
174 }
175
176 pub fn input_string() -> Result<String> {
179 Ok(INPUT_STRING.call(())?.to_rust().unwrap_or_default())
180 }
181}
182
183pub mod application {
185 use super::*;
186
187 pub fn is_playing() -> Result<bool> {
188 APPLICATION_IS_PLAYING.call(())
189 }
190
191 pub fn quit(exit_code: i32) -> Result<()> {
193 APPLICATION_QUIT.call((exit_code,))
194 }
195}
196
197pub fn check_bindings() -> Vec<(String, Error)> {
200 bindings::all()
201 .into_iter()
202 .filter_map(|b| b.check().err().map(|e| (b.describe(), e)))
203 .collect()
204}