mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-06 01:23:31 +08:00
Load assetbundle from EmbeddedResource
This commit is contained in:
parent
190467fa5c
commit
4a1c54fac1
@ -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()
|
||||
{
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Shader>("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<Sprite>("cursor");
|
||||
|
||||
ConsoleFont = bundle.LoadAsset<Font>("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<Shader>("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<Sprite>("cursor");
|
||||
|
||||
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
|
||||
|
||||
ExplorerCore.Log("Loaded UI bundle");
|
||||
}
|
||||
|
||||
private static GameObject CreateRootCanvas()
|
||||
|
@ -293,6 +293,7 @@
|
||||
<Compile Include="Unstrip\SceneUnstrip.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UI\UIFactory.cs" />
|
||||
<EmbeddedResource Include="Resources\*" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ILRepack.targets" />
|
||||
|
@ -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<d_LoadFromMemory>("UnityEngine.AssetBundle::LoadFromMemory_Internal");
|
||||
|
||||
var ptr = iCall(((Il2CppStructArray<byte>) binary).Pointer, crc);
|
||||
|
||||
return new AssetBundle(ptr);
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~ Instance ~~~~~~~~~~~~
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user