[+] Use the png jacket as bga

This commit is contained in:
Clansty
2024-06-26 03:11:56 +08:00
parent 8b72214780
commit 2946c51774
5 changed files with 86 additions and 15 deletions

View File

@@ -5,7 +5,6 @@ using System.Reflection;
using HarmonyLib;
using UnityEngine;
using System.Text.RegularExpressions;
using MelonLoader;
namespace AquaMai.UX
{
@@ -27,26 +26,49 @@ namespace AquaMai.UX
}
var id = matches[0].Groups[1].Value;
foreach (var ext in new[] { ".jpg", ".png", ".webp", ".bmp", ".gif" })
{
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext)))
{
filename = id + ext;
}
}
var localPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", filename);
if (File.Exists(localPath))
var texture = GetJacketTexture2D(id);
if (texture is null)
{
__result = new Texture2D(1, 1);
ImageConversion.LoadImage(__result, File.ReadAllBytes(localPath));
__result = __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
}
else
{
__result = __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
__result = texture;
}
return false;
}
private static string GetJacketPath(string id)
{
foreach (var ext in new[] { ".jpg", ".png", ".webp", ".bmp", ".gif" })
{
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext)))
{
return Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext);
}
}
return null;
}
public static Texture2D GetJacketTexture2D(string id)
{
var path = GetJacketPath(id);
if (path == null)
{
return null;
}
var texture = new Texture2D(1, 1);
texture.LoadImage(File.ReadAllBytes(path));
return texture;
}
public static Texture2D GetJacketTexture2D(int id)
{
return GetJacketTexture2D($"{id:000000}");
}
}
}
}