mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-07 09:43:37 +08:00
Null ptr check on AssetBundle loading
This commit is contained in:
parent
8123ec2412
commit
077a2b434a
@ -20,36 +20,43 @@ namespace UnityExplorer
|
||||
|
||||
// ~~~~~~~~~~~~ Static ~~~~~~~~~~~~
|
||||
|
||||
// AssetBundle.LoadFromFile(string path)
|
||||
|
||||
internal delegate IntPtr d_LoadFromFile(IntPtr path, uint crc, ulong offset);
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public static AssetBundle LoadFromFile(string path)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadFromFile>("UnityEngine.AssetBundle::LoadFromFile_Internal");
|
||||
var ptr = iCall(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0UL);
|
||||
return new AssetBundle(ptr);
|
||||
IntPtr ptr = ICallManager.GetICall<d_LoadFromFile>("UnityEngine.AssetBundle::LoadFromFile_Internal")
|
||||
.Invoke(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0UL);
|
||||
|
||||
return ptr != IntPtr.Zero ? new AssetBundle(ptr) : null;
|
||||
}
|
||||
|
||||
// AssetBundle.LoadFromMemory(byte[] binary)
|
||||
|
||||
private delegate IntPtr d_LoadFromMemory(IntPtr binary, uint crc);
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadFromMemory>("UnityEngine.AssetBundle::LoadFromMemory_Internal");
|
||||
var ptr = iCall(((Il2CppStructArray<byte>)binary).Pointer, crc);
|
||||
return new AssetBundle(ptr);
|
||||
IntPtr ptr = ICallManager.GetICall<d_LoadFromMemory>("UnityEngine.AssetBundle::LoadFromMemory_Internal")
|
||||
.Invoke(((Il2CppStructArray<byte>)binary).Pointer, crc);
|
||||
|
||||
return ptr != IntPtr.Zero ? new AssetBundle(ptr) : null;
|
||||
}
|
||||
|
||||
// AssetBundle.GetAllLoadedAssetBundles()
|
||||
|
||||
public delegate IntPtr d_GetAllLoadedAssetBundles_Native();
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public static AssetBundle[] GetAllLoadedAssetBundles()
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_GetAllLoadedAssetBundles_Native>("UnityEngine.AssetBundle::GetAllLoadedAssetBundles_Native");
|
||||
var ptr = iCall();
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
return (AssetBundle[])new Il2CppReferenceArray<AssetBundle>(ptr);
|
||||
IntPtr ptr = ICallManager.GetICall<d_GetAllLoadedAssetBundles_Native>("UnityEngine.AssetBundle::GetAllLoadedAssetBundles_Native")
|
||||
.Invoke();
|
||||
|
||||
return ptr != IntPtr.Zero ? (AssetBundle[])new Il2CppReferenceArray<AssetBundle>(ptr) : null;
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~ Instance ~~~~~~~~~~~~
|
||||
@ -65,13 +72,10 @@ namespace UnityExplorer
|
||||
[HideFromIl2Cpp]
|
||||
public UnityEngine.Object[] LoadAllAssets()
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal");
|
||||
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), UnhollowerRuntimeLib.Il2CppType.Of<UnityEngine.Object>().Pointer);
|
||||
IntPtr ptr = ICallManager.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal")
|
||||
.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), UnhollowerRuntimeLib.Il2CppType.Of<UnityEngine.Object>().Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return new UnityEngine.Object[0];
|
||||
|
||||
return new Il2CppReferenceArray<UnityEngine.Object>(ptr);
|
||||
return ptr != IntPtr.Zero ? (UnityEngine.Object[])new Il2CppReferenceArray<UnityEngine.Object>(ptr) : new UnityEngine.Object[0];
|
||||
}
|
||||
|
||||
// LoadAsset<T>(string name, Type type)
|
||||
@ -81,13 +85,10 @@ namespace UnityExplorer
|
||||
[HideFromIl2Cpp]
|
||||
public T LoadAsset<T>(string name) where T : UnityEngine.Object
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal");
|
||||
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), UnhollowerRuntimeLib.Il2CppType.Of<T>().Pointer);
|
||||
IntPtr ptr = ICallManager.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal")
|
||||
.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), UnhollowerRuntimeLib.Il2CppType.Of<T>().Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new UnityEngine.Object(ptr).TryCast<T>();
|
||||
return ptr != IntPtr.Zero ? new UnityEngine.Object(ptr).TryCast<T>() : null;
|
||||
}
|
||||
|
||||
// Unload(bool unloadAllLoadedObjects);
|
||||
@ -97,8 +98,8 @@ namespace UnityExplorer
|
||||
[HideFromIl2Cpp]
|
||||
public void Unload(bool unloadAllLoadedObjects)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_Unload>("UnityEngine.AssetBundle::Unload");
|
||||
iCall.Invoke(this.m_bundlePtr, unloadAllLoadedObjects);
|
||||
ICallManager.GetICall<d_Unload>("UnityEngine.AssetBundle::Unload")
|
||||
.Invoke(this.m_bundlePtr, unloadAllLoadedObjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user