unity/
engine.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use crate::prelude::*;

pub mod ui;
pub mod rendering;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Color {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Vector2<T> {
    pub x: T,
    pub y: T,
}

impl<T> Vector2<T> {
    pub fn new(x: T, y: T) -> Self {
        Self { x, y }
    }
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Vector3<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}

impl<T> Vector3<T> {
    pub fn new(x: T, y: T, z: T) -> Self {
        Self { x, y, z }
    }
}

#[crate::class("UnityEngine", "Material")]
pub struct Material { }

#[crate::from_offset("UnityEngine", "Material", "get_shader")]
fn material_get_shader(this: &Material, method_info: OptionalMethod) -> Option<&'static Shader>;

#[crate::from_offset("UnityEngine", "Material", "set_shader")]
fn material_set_shader(this: &mut Material, value: &Shader, method_info: OptionalMethod);

impl Material {
    pub fn get_shader(&self) -> Option<&'static Shader> {
        unsafe { material_get_shader(self, None) }
    }

    pub fn set_shader(&mut self, value: &'static Shader) {
        unsafe { material_set_shader(self, value, None) }
    }
}

#[crate::class("UnityEngine", "Shader")]
pub struct Shader { }

#[repr(i32)]
pub enum FilterMode {
    Point,
    Bilinear,
    Trilinear,
}

#[crate::class("UnityEngine", "Texture2D")]
pub struct Texture2D { }

impl Texture2D {
    pub fn new(width: i32, height: i32) -> &'static mut Self {
        let new_texture = Texture2D::instantiate().unwrap();
        unsafe { texture2d_ctor(new_texture, width, height, None) };
        new_texture
    }

    pub fn set_filter_mode(&mut self, mode: FilterMode) {
        unsafe { texture2d_set_filter_mode(&self, mode, None) }
    }
}

#[crate::from_offset("UnityEngine", "Texture2D", ".ctor")]
fn texture2d_ctor(this: &Texture2D, width: i32, height: i32, method_info: OptionalMethod);


#[crate::from_offset("UnityEngine", "Texture", "set_filterMode")]
fn texture2d_set_filter_mode(this: &Texture2D, filter_mode: FilterMode, method_info: OptionalMethod);

#[crate::class("UnityEngine", "Sprite")]
pub struct Sprite { }

#[repr(i32)]
pub enum SpriteMeshType {
    FullRect,
    Tight
}

impl Sprite {
    pub fn create2(texture: &Texture2D, rect: Rect, pivot: Vector2<f32>, pixels_to_unit: f32, extrude: u32, mesh_type: SpriteMeshType) -> &'static mut Self {
        unsafe { sprite_create2(texture, rect, pivot, pixels_to_unit, extrude, mesh_type, None) }
    }
}

#[skyline::from_offset(0x2f989c0)]
fn sprite_create2(texture: &Texture2D, rect: Rect, pivot: Vector2<f32>, pixels_to_unit: f32, extrude: u32, mesh_type: SpriteMeshType, method_info: OptionalMethod) -> &'static mut Sprite;


#[crate::class("UnityEngine", "ImageConversion")]
pub struct ImageConversion { }

impl ImageConversion {
    pub fn load_image(texture: &mut Texture2D, data: &Il2CppArray<u8>) -> bool {
		unsafe { imageconversion_load_image(texture, data, None) }
    }
}

#[crate::from_offset("UnityEngine", "ImageConversion", "LoadImage")]
fn imageconversion_load_image(tex: &Texture2D, data: &Il2CppArray<u8>, method_info: OptionalMethod) -> bool;

#[repr(C)]
pub struct Rect {
    x: f32,
    y: f32,
    width: f32,
    height: f32,
}

impl Rect {
    pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
        Self { x, y, width, height }
    }
}

#[crate::class("UnityEngine", "AssetBundle")]
pub struct AssetBundle {
    
}

impl AssetBundle {
    /// If you wish to skip the crc check, simply provide 0.
    pub fn load_from_memory_async_internal(array: &mut Il2CppArray<u8>, crc: u32) -> *const u8 {
        let method = unsafe {
            std::mem::transmute::<_, extern "C" fn(&mut Il2CppArray<u8>, u32, OptionalMethod) -> *const u8>(
                crate::il2cpp::method_from_name("UnityEngine.AssetBundle::LoadFromMemoryAsync_Internal(System.Byte[],System.UInt32)"),
            )
        };

        method(array, crc, None)
    }
}