mirror of https://github.com/hykilpikonna/AquaDX
[+] Load Jacket from A???\AssetBundleImages\jacket\*.png
parent
d58fe84439
commit
489c00ebb0
|
@ -1,56 +1,77 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Manager;
|
||||||
|
using MelonLoader;
|
||||||
|
|
||||||
namespace AquaMai.UX
|
namespace AquaMai.UX
|
||||||
{
|
{
|
||||||
[HarmonyPatch]
|
|
||||||
public class LoadJacketPng
|
public class LoadJacketPng
|
||||||
{
|
{
|
||||||
public static IEnumerable<MethodBase> TargetMethods()
|
[HarmonyPatch]
|
||||||
|
public static class Loader
|
||||||
{
|
{
|
||||||
var AM = typeof(AssetManager);
|
public static IEnumerable<MethodBase> TargetMethods()
|
||||||
return new[] { AM.GetMethod("GetJacketThumbTexture2D", new[] { typeof(string) }), AM.GetMethod("GetJacketTexture2D", new[] { typeof(string) }) };
|
{
|
||||||
|
var AM = typeof(AssetManager);
|
||||||
|
return new[] { AM.GetMethod("GetJacketThumbTexture2D", new[] { typeof(string) }), AM.GetMethod("GetJacketTexture2D", new[] { typeof(string) }) };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance)
|
||||||
|
{
|
||||||
|
var matches = Regex.Matches(filename, @"UI_Jacket_(\d+)(_s)?\.png");
|
||||||
|
if (matches.Count < 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var id = matches[0].Groups[1].Value;
|
||||||
|
|
||||||
|
var texture = GetJacketTexture2D(id);
|
||||||
|
__result = texture ?? __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance)
|
private static string[] imageExts = [".jpg", ".png", ".jpeg"];
|
||||||
|
private static Regex localAssetsJacketExt = new(@"(\d{6})\.(png|jpg|jpeg)");
|
||||||
|
private static Dictionary<string, string> jacketPaths = new();
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(DataManager), "LoadMusicBase")]
|
||||||
|
public static void LoadMusicPostfix(List<string> ____targetDirs)
|
||||||
{
|
{
|
||||||
var matches = Regex.Matches(filename, @"UI_Jacket_(\d+)(_s)?\.png");
|
foreach (var aDir in ____targetDirs)
|
||||||
if (matches.Count < 1)
|
|
||||||
{
|
{
|
||||||
return true;
|
if (!Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\jacket"))) continue;
|
||||||
|
foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\jacket")))
|
||||||
|
{
|
||||||
|
if (!imageExts.Contains(Path.GetExtension(file))) continue;
|
||||||
|
var idStr = Path.GetFileName(file).Substring("ui_jacket_".Length, 6);
|
||||||
|
jacketPaths[idStr] = file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var id = matches[0].Groups[1].Value;
|
foreach (var laFile in Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "LocalAssets")))
|
||||||
|
|
||||||
var texture = GetJacketTexture2D(id);
|
|
||||||
if (texture is null)
|
|
||||||
{
|
{
|
||||||
__result = __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
|
var match = localAssetsJacketExt.Match(Path.GetFileName(laFile));
|
||||||
}
|
if (!match.Success) continue;
|
||||||
else
|
jacketPaths[match.Groups[1].Value] = laFile;
|
||||||
{
|
|
||||||
__result = texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
MelonLogger.Msg($"Loaded {jacketPaths.Count} custom jacket images.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetJacketPath(string id)
|
private static string GetJacketPath(string id)
|
||||||
{
|
{
|
||||||
foreach (var ext in new[] { ".jpg", ".png", ".webp", ".bmp", ".gif" })
|
return jacketPaths.GetValueOrDefault(id);
|
||||||
{
|
|
||||||
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)
|
public static Texture2D GetJacketTexture2D(string id)
|
||||||
|
|
Loading…
Reference in New Issue