This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathil2cpp.cpp
106 lines (89 loc) · 3.31 KB
/
il2cpp.cpp
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
#include "il2cpp.h"
namespace il2cpp
{
// variables
pointer moduleBase;
pointer assemblyBase;
// api
il2cpp_string_new unity_string_new;
il2cpp_resolve_icall unity_resolve_icall;
t_unity_find_objects unity_find_objects;
t_unity_get_transform unity_get_transform;
t_unity_transform_get_vector unity_transform_get_vector;
t_unity_get_main_camera unity_get_main_camera;
t_unity_get_gameobject unity_get_gameobject;
t_unity_create_gui_text unity_create_text;
t_unity_label unity_draw_text;
t_unity_no_style unity_none_style;
t_unity_get_screen_data unity_get_screen_width;
t_unity_get_screen_data unity_get_screen_height;
pointer GetModuleBase()
{
if (assemblyBase == 0)
{
assemblyBase = (pointer)GetModuleHandleA(assemblyName);
}
return assemblyBase;
}
void Init() {
// grab data
unity_string_new = (il2cpp_string_new)GetProcAddress((HMODULE)assemblyBase, "il2cpp_string_new");
unity_resolve_icall = (il2cpp_resolve_icall)GetProcAddress((HMODULE)assemblyBase, "il2cpp_resolve_icall");
unity_find_objects = (t_unity_find_objects)unity_resolve_icall(fname_find_gameobjects);
unity_get_transform = (t_unity_get_transform)unity_resolve_icall(fname_get_transform);
unity_transform_get_vector = (t_unity_transform_get_vector)unity_resolve_icall(fname_get_transform_vector);
unity_get_main_camera = (t_unity_get_main_camera)unity_resolve_icall(fname_get_current_camera);
unity_get_gameobject = (t_unity_get_gameobject)unity_resolve_icall(fname_get_gameobject);
unity_get_screen_width = (t_unity_get_screen_data)unity_resolve_icall(fname_screen_width);
unity_get_screen_height = (t_unity_get_screen_data)unity_resolve_icall(fname_screen_height);
// unity3D rendering
unity_create_text = (t_unity_create_gui_text)(assemblyBase + offset::create_text);
unity_draw_text = (t_unity_label)(assemblyBase + offset::draw_text);
unity_none_style = (t_unity_no_style)(assemblyBase + offset::none_style);
}
int get_screen_width() {
return unity_get_screen_width();
}
int get_screen_height() {
return unity_get_screen_height();
}
void draw_text(Rect position, const char* text) {
auto il2cpp_string = unity_string_new(text);
auto content = unity_create_text(il2cpp_string);
auto style = unity_none_style();
unity_draw_text(position, content, style);
}
pointer get_current_camera() {
return unity_get_main_camera();
}
pointer* find_entities(const char* tag) {
auto il2cpp_string = unity_string_new(tag);
return unity_find_objects(il2cpp_string);
}
void get_transform(pointer entity, vec3* pos) {
auto transform = (pointer*)unity_get_transform(entity);
unity_transform_get_vector(transform, pos);
}
pointer get_gameobject(pointer component) {
auto go = unity_get_gameobject(component);
return go;
}
vec3 get_camera_position(pointer camera) {
if (camera != NULL) {
camera = Read<pointer>((pointer)camera + offset::camera);
return Read<vec3>(camera + offset::camera_position);
}
return vec3{};
}
Matrix get_viewmatrix() {
auto camera = get_current_camera();
return get_viewmatrix(camera);
}
Matrix get_viewmatrix(pointer camera) {
if (camera != NULL) {
camera = Read<pointer>((pointer)camera + offset::camera);
return Read<Matrix>(camera + offset::matrix);
}
return Matrix{};
}
}