-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIl2CppAssetBundle.cs
285 lines (246 loc) · 15.6 KB
/
Il2CppAssetBundle.cs
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using System;
using MelonLoader;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using System.Xml.Linq;
namespace UnityEngine
{
public class Il2CppAssetBundle
{
private IntPtr bundleptr = IntPtr.Zero;
public Il2CppAssetBundle(IntPtr ptr) { bundleptr = ptr; }
static Il2CppAssetBundle()
{
get_isStreamedSceneAssetBundleDelegateField = IL2CPP.ResolveICall<get_isStreamedSceneAssetBundleDelegate>("UnityEngine.AssetBundle::get_isStreamedSceneAssetBundle");
returnMainAssetDelegateField = IL2CPP.ResolveICall<returnMainAssetDelegate>("UnityEngine.AssetBundle::returnMainAsset");
ContainsDelegateField = IL2CPP.ResolveICall<ContainsDelegate>("UnityEngine.AssetBundle::Contains");
GetAllAssetNamesDelegateField = IL2CPP.ResolveICall<GetAllAssetNamesDelegate>("UnityEngine.AssetBundle::GetAllAssetNames");
GetAllScenePathsDelegateField = IL2CPP.ResolveICall<GetAllScenePathsDelegate>("UnityEngine.AssetBundle::GetAllScenePaths");
LoadAsset_InternalDelegateField = IL2CPP.ResolveICall<LoadAsset_InternalDelegate>("UnityEngine.AssetBundle::LoadAsset_Internal(System.String,System.Type)");
LoadAssetAsync_InternalDelegateField = IL2CPP.ResolveICall<LoadAssetAsync_InternalDelegate>("UnityEngine.AssetBundle::LoadAssetAsync_Internal");
LoadAssetWithSubAssets_InternalDelegateField = IL2CPP.ResolveICall<LoadAssetWithSubAssets_InternalDelegate>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal");
LoadAssetWithSubAssetsAsync_InternalDelegateField = IL2CPP.ResolveICall<LoadAssetWithSubAssetsAsync_InternalDelegate>("UnityEngine.AssetBundle::LoadAssetWithSubAssetsAsync_Internal");
UnloadDelegateField = IL2CPP.ResolveICall<UnloadDelegate>("UnityEngine.AssetBundle::Unload");
}
public bool isStreamedSceneAssetBundle
{
get
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (get_isStreamedSceneAssetBundleDelegateField == null)
throw new NullReferenceException("The get_isStreamedSceneAssetBundleDelegateField cannot be null.");
return get_isStreamedSceneAssetBundleDelegateField(bundleptr);
}
}
public Object mainAsset
{
get
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (returnMainAssetDelegateField == null)
throw new NullReferenceException("The returnMainAssetDelegateField cannot be null.");
IntPtr intPtr = returnMainAssetDelegateField(bundleptr);
return ((intPtr != IntPtr.Zero) ? new Object(intPtr) : null);
}
}
public bool Contains(string name)
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (string.IsNullOrEmpty(name))
throw new ArgumentException("The input asset name cannot be null or empty.");
if (ContainsDelegateField == null)
throw new NullReferenceException("The ContainsDelegateField cannot be null.");
return ContainsDelegateField(bundleptr, IL2CPP.ManagedStringToIl2Cpp(name));
}
public Il2CppStringArray AllAssetNames() => GetAllAssetNames();
public Il2CppStringArray GetAllAssetNames()
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (GetAllAssetNamesDelegateField == null)
throw new NullReferenceException("The GetAllAssetNamesDelegateField cannot be null.");
IntPtr intPtr = GetAllAssetNamesDelegateField(bundleptr);
return ((intPtr != IntPtr.Zero) ? new Il2CppStringArray(intPtr) : null);
}
public Il2CppStringArray AllScenePaths() => GetAllScenePaths();
public Il2CppStringArray GetAllScenePaths()
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (GetAllScenePathsDelegateField == null)
throw new NullReferenceException("The GetAllScenePathsDelegateField cannot be null.");
IntPtr intPtr = GetAllScenePathsDelegateField(bundleptr);
return ((intPtr != IntPtr.Zero) ? new Il2CppStringArray(intPtr) : null);
}
public Object Load(string name) => LoadAsset(name);
public Object LoadAsset(string name) => LoadAsset<Object>(name);
public T Load<T>(string name) where T : Object => LoadAsset<T>(name);
public T LoadAsset<T>(string name) where T : Object
{
if (!InteropSupport.IsGeneratedAssemblyType(typeof(T)))
throw new NullReferenceException("The type must be a Generated Assembly Type.");
IntPtr intptr = LoadAsset(name, Il2CppType.Of<T>().Pointer);
return ((intptr != IntPtr.Zero) ? InteropSupport.Il2CppObjectPtrToIl2CppObject<T>(intptr) : null);
}
public Object Load(string name, Il2CppSystem.Type type) => LoadAsset(name, type);
public Object LoadAsset(string name, Il2CppSystem.Type type)
{
if (type == null)
throw new NullReferenceException("The input type cannot be null.");
IntPtr intptr = LoadAsset(name, type.Pointer);
return ((intptr != IntPtr.Zero) ? new Object(intptr) : null);
}
public IntPtr Load(string name, IntPtr typeptr) => LoadAsset(name, typeptr);
public IntPtr LoadAsset(string name, IntPtr typeptr)
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (string.IsNullOrEmpty(name))
throw new ArgumentException("The input asset name cannot be null or empty.");
if (typeptr == IntPtr.Zero)
throw new NullReferenceException("The input type cannot be IntPtr.Zero");
if (LoadAsset_InternalDelegateField == null)
throw new NullReferenceException("The LoadAsset_InternalDelegateField cannot be null.");
return LoadAsset_InternalDelegateField(bundleptr, IL2CPP.ManagedStringToIl2Cpp(name), typeptr);
}
public Il2CppAssetBundleRequest LoadAssetAsync(string name) => LoadAssetAsync<Object>(name);
public Il2CppAssetBundleRequest LoadAssetAsync<T>(string name) where T : Object
{
if (!InteropSupport.IsGeneratedAssemblyType(typeof(T)))
throw new NullReferenceException("The type must be a Generated Assembly Type.");
IntPtr intptr = LoadAssetAsync(name, Il2CppType.Of<T>().Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppAssetBundleRequest(intptr) : null);
}
public Il2CppAssetBundleRequest LoadAssetAsync(string name, Il2CppSystem.Type type)
{
if (type == null)
throw new NullReferenceException("The input type cannot be null.");
IntPtr intptr = LoadAssetAsync(name, type.Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppAssetBundleRequest(intptr) : null);
}
public IntPtr LoadAssetAsync(string name, IntPtr typeptr)
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (string.IsNullOrEmpty(name))
throw new ArgumentException("The input asset name cannot be null or empty.");
if (typeptr == IntPtr.Zero)
throw new NullReferenceException("The input type cannot be IntPtr.Zero");
if (LoadAssetAsync_InternalDelegateField == null)
throw new NullReferenceException("The LoadAssetAsync_InternalDelegateField cannot be null.");
return LoadAssetAsync_InternalDelegateField(bundleptr, IL2CPP.ManagedStringToIl2Cpp(name), typeptr);
}
public Il2CppReferenceArray<Object> LoadAll() => LoadAllAssets();
public Il2CppReferenceArray<Object> LoadAllAssets() => LoadAllAssets<Object>();
public Il2CppReferenceArray<T> LoadAll<T>() where T : Object => LoadAllAssets<T>();
public Il2CppReferenceArray<T> LoadAllAssets<T>() where T : Object
{
if (!InteropSupport.IsGeneratedAssemblyType(typeof(T)))
throw new NullReferenceException("The type must be a Generated Assembly Type.");
IntPtr intptr = LoadAllAssets(Il2CppType.Of<T>().Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppReferenceArray<T>(intptr) : null);
}
public Il2CppReferenceArray<Object> LoadAll(Il2CppSystem.Type type) => LoadAllAssets(type);
public Il2CppReferenceArray<Object> LoadAllAssets(Il2CppSystem.Type type)
{
if (type == null)
throw new NullReferenceException("The input type cannot be null.");
IntPtr intptr = LoadAllAssets(type.Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppReferenceArray<Object>(intptr) : null);
}
public IntPtr LoadAll(IntPtr typeptr) => LoadAllAssets(typeptr);
public IntPtr LoadAllAssets(IntPtr typeptr)
{
if (typeptr == IntPtr.Zero)
throw new NullReferenceException("The input type cannot be IntPtr.Zero");
if (LoadAssetWithSubAssets_InternalDelegateField == null)
throw new NullReferenceException("The LoadAssetWithSubAssets_InternalDelegateField cannot be null.");
return LoadAssetWithSubAssets_InternalDelegateField(bundleptr, IL2CPP.ManagedStringToIl2Cpp(string.Empty), typeptr);
}
public Il2CppReferenceArray<Object> LoadAssetWithSubAssets(string name) => LoadAssetWithSubAssets<Object>(name);
public Il2CppReferenceArray<T> LoadAssetWithSubAssets<T>(string name) where T : Object
{
if (!InteropSupport.IsGeneratedAssemblyType(typeof(T)))
throw new NullReferenceException("The type must be a Generated Assembly Type.");
IntPtr intptr = LoadAssetWithSubAssets(name, Il2CppType.Of<T>().Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppReferenceArray<T>(intptr) : null);
}
public Il2CppReferenceArray<Object> LoadAssetWithSubAssets(string name, Il2CppSystem.Type type)
{
if (type == null)
throw new NullReferenceException("The input type cannot be null.");
IntPtr intptr = LoadAssetWithSubAssets(name, type.Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppReferenceArray<Object>(intptr) : null);
}
public IntPtr LoadAssetWithSubAssets(string name, IntPtr typeptr)
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (string.IsNullOrEmpty(name))
throw new ArgumentException("The input asset name cannot be null or empty.");
if (typeptr == IntPtr.Zero)
throw new NullReferenceException("The input type cannot be IntPtr.Zero");
if (LoadAssetWithSubAssets_InternalDelegateField == null)
throw new NullReferenceException("The LoadAssetWithSubAssets_InternalDelegateField cannot be null.");
return LoadAssetWithSubAssets_InternalDelegateField(bundleptr, IL2CPP.ManagedStringToIl2Cpp(name), typeptr);
}
public Il2CppAssetBundleRequest LoadAssetWithSubAssetsAsync(string name) => LoadAssetWithSubAssetsAsync<Object>(name);
public Il2CppAssetBundleRequest LoadAssetWithSubAssetsAsync<T>(string name) where T : Object
{
if (!InteropSupport.IsGeneratedAssemblyType(typeof(T)))
throw new NullReferenceException("The type must be a Generated Assembly Type.");
IntPtr intptr = LoadAssetWithSubAssetsAsync(name, Il2CppType.Of<T>().Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppAssetBundleRequest(intptr) : null);
}
public Il2CppAssetBundleRequest LoadAssetWithSubAssetsAsync(string name, Il2CppSystem.Type type)
{
if (type == null)
throw new NullReferenceException("The input type cannot be null.");
IntPtr intptr = LoadAssetWithSubAssetsAsync(name, type.Pointer);
return ((intptr != IntPtr.Zero) ? new Il2CppAssetBundleRequest(intptr) : null);
}
public IntPtr LoadAssetWithSubAssetsAsync(string name, IntPtr typeptr)
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (string.IsNullOrEmpty(name))
throw new ArgumentException("The input asset name cannot be null or empty.");
if (typeptr == IntPtr.Zero)
throw new NullReferenceException("The input type cannot be IntPtr.Zero");
if (LoadAssetWithSubAssetsAsync_InternalDelegateField == null)
throw new NullReferenceException("The LoadAssetWithSubAssetsAsync_InternalDelegateField cannot be null.");
return LoadAssetWithSubAssetsAsync_InternalDelegateField(bundleptr, IL2CPP.ManagedStringToIl2Cpp(name), typeptr);
}
public void Unload(bool unloadAllLoadedObjects)
{
if (bundleptr == IntPtr.Zero)
throw new NullReferenceException("The bundleptr cannot be IntPtr.Zero");
if (UnloadDelegateField == null)
throw new NullReferenceException("The UnloadDelegateField cannot be null.");
UnloadDelegateField(bundleptr, unloadAllLoadedObjects);
}
private delegate bool get_isStreamedSceneAssetBundleDelegate(IntPtr _this);
private static readonly returnMainAssetDelegate returnMainAssetDelegateField;
private delegate IntPtr returnMainAssetDelegate(IntPtr _this);
private static readonly get_isStreamedSceneAssetBundleDelegate get_isStreamedSceneAssetBundleDelegateField;
private delegate bool ContainsDelegate(IntPtr _this, IntPtr name);
private static readonly ContainsDelegate ContainsDelegateField;
private delegate IntPtr GetAllAssetNamesDelegate(IntPtr _this);
private static readonly GetAllAssetNamesDelegate GetAllAssetNamesDelegateField;
private delegate IntPtr GetAllScenePathsDelegate(IntPtr _this);
private static readonly GetAllScenePathsDelegate GetAllScenePathsDelegateField;
private delegate IntPtr LoadAsset_InternalDelegate(IntPtr _this, IntPtr name, IntPtr type);
private static readonly LoadAsset_InternalDelegate LoadAsset_InternalDelegateField;
private delegate IntPtr LoadAssetAsync_InternalDelegate(IntPtr _this, IntPtr name, IntPtr type);
private static readonly LoadAssetAsync_InternalDelegate LoadAssetAsync_InternalDelegateField;
private delegate IntPtr LoadAssetWithSubAssets_InternalDelegate(IntPtr _this, IntPtr name, IntPtr type);
private static readonly LoadAssetWithSubAssets_InternalDelegate LoadAssetWithSubAssets_InternalDelegateField;
private delegate IntPtr LoadAssetWithSubAssetsAsync_InternalDelegate(IntPtr _this, IntPtr name, IntPtr type);
private static readonly LoadAssetWithSubAssetsAsync_InternalDelegate LoadAssetWithSubAssetsAsync_InternalDelegateField;
private delegate void UnloadDelegate(IntPtr _this, bool unloadAllObjects);
private static readonly UnloadDelegate UnloadDelegateField;
}
}