diff --git a/resources/Older Unity bundle/THIS BUNDLE IS FOR UNITY 5.6.1 AND OLDER.txt b/resources/Older Unity bundle/THIS BUNDLE IS FOR UNITY 5.6.1 AND OLDER.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/Config/ModConfig.cs b/src/Config/ModConfig.cs index d475844..05ce207 100644 --- a/src/Config/ModConfig.cs +++ b/src/Config/ModConfig.cs @@ -11,7 +11,7 @@ namespace UnityExplorer.Config public static ModConfig Instance; internal static readonly IniDataParser _parser = new IniDataParser(); - internal const string INI_PATH = ExplorerCore.EXPLORER_FOLDER + @"\config.ini"; + internal static readonly string INI_PATH = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "config.ini"); static ModConfig() { diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index fa9efe5..b0f6176 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using BepInEx; using UnityEngine; using UnityEngine.SceneManagement; using UnityExplorer.Config; @@ -19,7 +20,12 @@ namespace UnityExplorer public const string VERSION = "3.1.4"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.unityexplorer"; + +#if ML public const string EXPLORER_FOLDER = @"Mods\UnityExplorer"; +#elif BIE + public static string EXPLORER_FOLDER = Path.Combine(Paths.ConfigPath, "UnityExplorer"); +#endif public static ExplorerCore Instance { get; private set; } diff --git a/src/Helpers/Texture2DHelpers.cs b/src/Helpers/Texture2DHelpers.cs index 645ef47..dc81f51 100644 --- a/src/Helpers/Texture2DHelpers.cs +++ b/src/Helpers/Texture2DHelpers.cs @@ -70,7 +70,8 @@ namespace UnityExplorer.Helpers pixels = orig.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); - var _newTex = new Texture2D((int)rect.width, (int)rect.height); + // use full constructor for better compatibility + var _newTex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGBA32, Texture.GenerateAllMips, false, IntPtr.Zero); _newTex.SetPixels(pixels); return _newTex; diff --git a/resources/Older Unity bundle/explorerui.bundle b/src/Resources/explorerui.legacy.bundle similarity index 100% rename from resources/Older Unity bundle/explorerui.bundle rename to src/Resources/explorerui.legacy.bundle diff --git a/resources/explorerui.bundle b/src/Resources/explorerui.modern.bundle similarity index 100% rename from resources/explorerui.bundle rename to src/Resources/explorerui.modern.bundle diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index cf4a826..90e195e 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -88,33 +88,62 @@ namespace UnityExplorer.UI } } + private static byte[] ReadFully(this Stream input) + { + using (var ms = new MemoryStream()) + { + input.CopyTo(ms); + return ms.ToArray(); + } + } + + private static AssetBundle LoadExplorerUi(string id) + { + return AssetBundle.LoadFromMemory(ReadFully(typeof(ExplorerCore).Assembly.GetManifestResourceStream($"UnityExplorer.Resources.explorerui.{id}.bundle"))); + } + private static void LoadBundle() { - var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\explorerui.bundle"; - if (File.Exists(bundlePath)) + AssetBundle bundle = null; + + try { - var bundle = AssetBundle.LoadFromFile(bundlePath); - - BackupShader = bundle.LoadAsset("DefaultUI"); - - // Fix for games which don't ship with 'UI/Default' shader. - if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default") - { - ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader..."); - Graphic.defaultGraphicMaterial.shader = BackupShader; - } - - ResizeCursor = bundle.LoadAsset("cursor"); - - ConsoleFont = bundle.LoadAsset("CONSOLA"); - - ExplorerCore.Log("Loaded UI bundle"); + bundle = LoadExplorerUi("modern"); } - else + catch { - ExplorerCore.LogWarning("Could not find the ExplorerUI Bundle! It should exist at '" + bundlePath + "'"); + ExplorerCore.Log("Failed to load modern ExplorerUI Bundle, falling back to legacy"); + + try + { + bundle = LoadExplorerUi("legacy"); + } + catch + { + // ignored + } + } + + if (bundle == null) + { + ExplorerCore.LogWarning("Could not load the ExplorerUI Bundle!"); return; } + + BackupShader = bundle.LoadAsset("DefaultUI"); + + // Fix for games which don't ship with 'UI/Default' shader. + if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default") + { + ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader..."); + Graphic.defaultGraphicMaterial.shader = BackupShader; + } + + ResizeCursor = bundle.LoadAsset("cursor"); + + ConsoleFont = bundle.LoadAsset("CONSOLA"); + + ExplorerCore.Log("Loaded UI bundle"); } private static GameObject CreateRootCanvas() diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index 22569e6..de2597d 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -293,6 +293,7 @@ + diff --git a/src/Unstrip/AssetBundleUnstrip.cs b/src/Unstrip/AssetBundleUnstrip.cs index e412725..c212789 100644 --- a/src/Unstrip/AssetBundleUnstrip.cs +++ b/src/Unstrip/AssetBundleUnstrip.cs @@ -24,6 +24,17 @@ namespace UnityExplorer.Unstrip return new AssetBundle(ptr); } + + private delegate IntPtr d_LoadFromMemory(IntPtr binary, uint crc); + + public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0) + { + var iCall = ICallHelper.GetICall("UnityEngine.AssetBundle::LoadFromMemory_Internal"); + + var ptr = iCall(((Il2CppStructArray) binary).Pointer, crc); + + return new AssetBundle(ptr); + } // ~~~~~~~~~~~~ Instance ~~~~~~~~~~~~