#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs)]
mod binding;
mod bindings;
pub mod dispatch;
#[cfg(feature = "egui")]
pub mod egui {
pub use crate::egui_backend::{
on_egui, register_user_texture, set_ui_scale, unregister_user_texture,
};
pub use ::egui::*;
}
#[cfg(feature = "egui")]
mod egui_backend;
pub mod gl;
mod lifecycle;
mod objects;
mod overlay;
#[cfg(feature = "reflect")]
pub mod reflect;
mod scene;
mod values;
pub use hao_il2cpp_runtime as runtime;
#[cfg(unix)]
pub use hao_il2cpp_runtime::on_init;
use hao_il2cpp_runtime::{Error, Il2Cpp, Result};
pub use lifecycle::{is_shutting_down, on_render, on_update, shutdown};
pub use objects::{
find_object_of_type, find_objects_of_type, Camera, Canvas, Component, ComponentType,
GameObject, Material, RawImage, RectTransform, RenderTexture, Shader, TextMeshPro, Texture2D,
Transform, UnityObject,
};
pub use overlay::{OverlayCanvas, OverlaySurface, TextOverlay};
pub use scene::{on_scene_loaded, Scene};
pub use values::{
Color, FilterMode, HideFlags, KeyCode, LoadSceneMode, Quaternion, RenderMode, TextureFormat,
Vector2, Vector3,
};
impl Quaternion {
pub fn euler(x: f32, y: f32, z: f32) -> Result<Self> {
bindings::QUATERNION_EULER.call((x, y, z))
}
}
use bindings::*;
fn il2cpp() -> Result<&'static Il2Cpp> {
Il2Cpp::get().ok_or_else(|| Error::NotFound("the Il2Cpp runtime".into()))
}
pub fn log(message: &str) -> Result<()> {
DEBUG_LOG.call((il2cpp()?.string(message)?.0,))
}
pub fn log_warning(message: &str) -> Result<()> {
DEBUG_LOG_WARNING.call((il2cpp()?.string(message)?.0,))
}
pub fn log_error(message: &str) -> Result<()> {
DEBUG_LOG_ERROR.call((il2cpp()?.string(message)?.0,))
}
pub mod time {
use super::*;
pub fn delta() -> Result<f32> {
TIME_DELTA.call(())
}
pub fn frame_count() -> Result<i32> {
TIME_FRAME_COUNT.call(())
}
pub fn scale() -> Result<f32> {
TIME_GET_SCALE.call(())
}
pub fn set_scale(scale: f32) -> Result<()> {
TIME_SET_SCALE.call((scale,))
}
pub fn time() -> Result<f32> {
TIME_GET_TIME.call(())
}
pub fn realtime_since_startup() -> Result<f32> {
TIME_REALTIME.call(())
}
}
pub mod screen {
use super::*;
pub fn width() -> Result<i32> {
SCREEN_WIDTH.call(())
}
pub fn height() -> Result<i32> {
SCREEN_HEIGHT.call(())
}
pub fn size() -> Result<(i32, i32)> {
Ok((width()?, height()?))
}
}
pub mod input {
use super::*;
pub fn key(key: KeyCode) -> Result<bool> {
INPUT_GET_KEY.call((key,))
}
pub fn key_down(key: KeyCode) -> Result<bool> {
INPUT_GET_KEY_DOWN.call((key,))
}
pub fn key_up(key: KeyCode) -> Result<bool> {
INPUT_GET_KEY_UP.call((key,))
}
pub fn mouse_button(button: i32) -> Result<bool> {
INPUT_GET_MOUSE_BUTTON.call((button,))
}
pub fn mouse_position() -> Result<Vector3> {
INPUT_MOUSE_POSITION.call(())
}
pub fn scroll_delta() -> Result<Vector2> {
INPUT_SCROLL_DELTA.call(())
}
pub fn input_string() -> Result<String> {
Ok(INPUT_STRING.call(())?.to_rust().unwrap_or_default())
}
}
pub mod application {
use super::*;
pub fn is_playing() -> Result<bool> {
APPLICATION_IS_PLAYING.call(())
}
pub fn quit(exit_code: i32) -> Result<()> {
APPLICATION_QUIT.call((exit_code,))
}
}
pub fn check_bindings() -> Vec<(String, Error)> {
bindings::all()
.into_iter()
.filter_map(|b| b.check().err().map(|e| (b.describe(), e)))
.collect()
}