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