2024-04-22 20:58:01 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using HarmonyLib;
|
|
|
|
using UnityEngine;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using MelonLoader;
|
|
|
|
|
|
|
|
namespace AquaMai.UX
|
|
|
|
{
|
|
|
|
[HarmonyPatch]
|
|
|
|
public class LoadJacketPng
|
|
|
|
{
|
|
|
|
public static IEnumerable<MethodBase> TargetMethods()
|
|
|
|
{
|
|
|
|
var AM = typeof(AssetManager);
|
2024-06-19 21:12:29 +08:00
|
|
|
return new[] { AM.GetMethod("GetJacketThumbTexture2D", new[] { typeof(string) }), AM.GetMethod("GetJacketTexture2D", new[] { typeof(string) }) };
|
2024-04-22 20:58:01 +08:00
|
|
|
}
|
2024-06-19 21:12:29 +08:00
|
|
|
|
|
|
|
public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance)
|
2024-04-22 20:58:01 +08:00
|
|
|
{
|
|
|
|
var matches = Regex.Matches(filename, @"UI_Jacket_(\d+)(_s)?\.png");
|
|
|
|
if (matches.Count < 1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var id = matches[0].Groups[1].Value;
|
2024-06-19 21:12:29 +08:00
|
|
|
foreach (var ext in new[] { ".jpg", ".png", ".webp", ".bmp", ".gif" })
|
2024-04-22 20:58:01 +08:00
|
|
|
{
|
|
|
|
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext)))
|
|
|
|
{
|
|
|
|
filename = id + ext;
|
|
|
|
}
|
|
|
|
}
|
2024-06-19 21:12:29 +08:00
|
|
|
|
2024-04-22 20:58:01 +08:00
|
|
|
var localPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", filename);
|
2024-06-19 21:12:29 +08:00
|
|
|
if (File.Exists(localPath))
|
|
|
|
{
|
|
|
|
__result = new Texture2D(1, 1);
|
|
|
|
ImageConversion.LoadImage(__result, File.ReadAllBytes(localPath));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__result = __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
|
|
|
|
}
|
|
|
|
|
2024-04-22 20:58:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|