From 1e6852943020d753a3aa9a65c7dc9f7cdbca0675 Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Fri, 22 Oct 2021 15:54:14 +1100 Subject: [PATCH] Don't patch stripped UnloadAllAssetBundles --- src/UI/UIManager.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 6930bc3..e0d04e7 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -446,16 +446,17 @@ namespace UnityExplorer.UI AssetBundle LoadBundle(string id) { - ExplorerCore.Log($"Loading {id} bundle for Unity {Application.unityVersion}"); - - return AssetBundle.LoadFromMemory(ReadFully(typeof(ExplorerCore) + var bundle = AssetBundle.LoadFromMemory(ReadFully(typeof(ExplorerCore) .Assembly .GetManifestResourceStream($"UnityExplorer.Resources.{id}.bundle"))); + if (bundle) + ExplorerCore.Log($"Loaded {id} bundle for Unity {Application.unityVersion}"); + return bundle; } if (ExplorerBundle == null) { - ExplorerCore.LogWarning("Could not load the ExplorerUI Bundle!"); + ExplorerCore.LogWarning("Could not load the UnityExplorer UI Bundle!"); DefaultFont = ConsoleFont = Resources.GetBuiltinResource("Arial.ttf"); return; } @@ -505,6 +506,11 @@ namespace UnityExplorer.UI { if (TypeofAssetBundle.GetMethod("UnloadAllAssetBundles", AccessTools.all) is MethodInfo unloadAllBundles) { +#if CPP + // if IL2CPP, ensure method wasn't stripped + if (UnhollowerBaseLib.UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(unloadAllBundles) == null) + return; +#endif var processor = ExplorerCore.Harmony.CreateProcessor(unloadAllBundles); var prefix = new HarmonyMethod(typeof(UIManager).GetMethod(nameof(Prefix_UnloadAllAssetBundles), AccessTools.all)); processor.AddPrefix(prefix);