From fc4834ebd67fccf7d5f9f92377b92b7115b90b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=91=E5=A0=B4=20=E6=A6=9E=E5=BD=A6?= <51935482+Eternal973@users.noreply.github.com> Date: Wed, 20 Nov 2024 02:16:22 +0800 Subject: [PATCH] [+] Support More Custom Png Assets (#85) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 素材放置于AssetBundleImages,支持姓名框背景板旅行伙伴,Icon仍在修,navichara和PartnerResult在写 --- AquaMai/UX/LoadAssetsPng.cs | 412 +++++++++++++++++++++++++++++++++++- 1 file changed, 409 insertions(+), 3 deletions(-) diff --git a/AquaMai/UX/LoadAssetsPng.cs b/AquaMai/UX/LoadAssetsPng.cs index e912ee0d..2c78e707 100644 --- a/AquaMai/UX/LoadAssetsPng.cs +++ b/AquaMai/UX/LoadAssetsPng.cs @@ -17,7 +17,15 @@ namespace AquaMai.UX; public class LoadAssetsPng { private static string[] imageExts = [".jpg", ".png", ".jpeg"]; - private static Dictionary jacketPaths = new(); + private static Dictionary jacketPaths = new(); + private static Dictionary framePaths = new(); + private static Dictionary platePaths = new(); + private static Dictionary framemaskPaths = new(); + private static Dictionary framepatternPaths = new(); + private static Dictionary iconPaths = new(); + private static Dictionary charaPaths = new(); + private static Dictionary partnerPaths = new(); + //private static Dictionary navicharaPaths = new(); private static Dictionary tabTitlePaths = new(); private static Dictionary localAssetsContents = new(); @@ -33,8 +41,71 @@ public class LoadAssetsPng if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; var idStr = Path.GetFileName(file).Substring("ui_jacket_".Length, 6); jacketPaths[idStr] = file; + } + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\frame"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\frame"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_frame_".Length, 6); + framePaths[idStr] = file; + } + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\nameplate"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\nameplate"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_plate_".Length, 6); + platePaths[idStr] = file; + } + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\framemask"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\framemask"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_framemask_".Length, 6); + framemaskPaths[idStr] = file; } - + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\framepattern"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\framepattern"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_framepattern_".Length, 6); + framepatternPaths[idStr] = file; + } + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\icon"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\icon"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_icon_".Length, 6); + iconPaths[idStr] = file; + } + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\chara"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\chara"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_chara_".Length, 6); + charaPaths[idStr] = file; + } + + if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\partner"))) + foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\partner"))) + { + if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + var idStr = Path.GetFileName(file).Substring("ui_Partner_".Length, 6); + partnerPaths[idStr] = file; + } + //if (Directory.Exists(Path.Combine(aDir, @"AssetBundleImages\navichara\sprite\parts\ui_navichara_21"))) + // foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"AssetBundleImages\navichara\sprite\parts\ui_navichara_", charaid))) + //{ + // if (!imageExts.Contains(Path.GetExtension(file).ToLowerInvariant())) continue; + //var idStr = Path.GetFileName(file).Substring("ui_navichara_".Length, 6); + // navicharaPaths[idStr] = file; + // } + if (Directory.Exists(Path.Combine(aDir, @"Common\Sprites\Tab\Title"))) foreach (var file in Directory.GetFiles(Path.Combine(aDir, @"Common\Sprites\Tab\Title"))) { @@ -43,7 +114,7 @@ public class LoadAssetsPng } } - MelonLogger.Msg($"[LoadAssetsPng] Loaded {jacketPaths.Count} Jacket, {tabTitlePaths.Count} Tab Titles from AssetBundleImages."); + MelonLogger.Msg($"[LoadAssetsPng] Loaded {jacketPaths.Count} Jacket, {platePaths.Count} NamePlate, {framePaths.Count} Frame, {framemaskPaths.Count} FrameMask, {framepatternPaths.Count} FramePattern, {iconPaths.Count} Icon, {charaPaths.Count} Chara, {partnerPaths.Count} PartnerLogo, {tabTitlePaths.Count} Tab Titles from AssetBundleImages."); if (Directory.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets"))) foreach (var laFile in Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "LocalAssets"))) @@ -76,6 +147,128 @@ public class LoadAssetsPng public static Texture2D GetJacketTexture2D(int id) { return GetJacketTexture2D($"{id:000000}"); + } + + private static string GetFramePath(string id) + { + return framePaths.GetValueOrDefault(id); + } + + public static Texture2D GetFrameTexture2D(string id) + { + var path = GetFramePath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; + } + private static string GetPlatePath(string id) + { + return platePaths.GetValueOrDefault(id); + } + + public static Texture2D GetPlateTexture2D(string id) + { + var path = GetPlatePath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; + } + + private static string GetFrameMaskPath(string id) + { + return framemaskPaths.GetValueOrDefault(id); + } + + public static Texture2D GetFrameMaskTexture2D(string id) + { + var path = GetFrameMaskPath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; + } + + private static string GetFramePatternPath(string id) + { + return framepatternPaths.GetValueOrDefault(id); + } + + public static Texture2D GetFramePatternTexture2D(string id) + { + var path = GetFramePatternPath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; + } + private static string GetIconPath(string id) + { + return iconPaths.GetValueOrDefault(id); + } + + public static Texture2D GetIconTexture2D(string id) + { + var path = GetIconPath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; + } + private static string GetCharaPath(string id) + { + return charaPaths.GetValueOrDefault(id); + } + + public static Texture2D GetCharaTexture2D(string id) + { + var path = GetCharaPath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; + } + private static string GetPartnerPath(string id) + { + return partnerPaths.GetValueOrDefault(id); + } + + public static Texture2D GetPartnerTexture2D(string id) + { + var path = GetPartnerPath(id); + if (path == null) + { + return null; + } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.LoadImage(File.ReadAllBytes(path)); + return texture; } /* @@ -165,7 +358,220 @@ public class LoadAssetsPng var texture = GetJacketTexture2D(id); __result = texture ?? __instance.LoadAsset($"Jacket/UI_Jacket_{id}.png"); + return false; + } + } + + [HarmonyPatch] + public static class FrameLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetFrameThumbTexture2D", [typeof(string)]), AM.GetMethod("GetFrameTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_Frame_(\d+)(_s)?\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetFrameTexture2D(id); + __result = texture ?? __instance.LoadAsset($"Frame/UI_Frame_{id}.png"); + + return false; + } + } + + [HarmonyPatch] + public static class PlateLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetPlateTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_Plate_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetPlateTexture2D(id); + __result = texture ?? __instance.LoadAsset($"NamePlate/UI_Plate_{id}.png"); + + return false; + } + } + + [HarmonyPatch] + public static class FrameMaskLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetFrameMaskTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_FrameMask_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetFrameMaskTexture2D(id); + __result = texture ?? __instance.LoadAsset($"FrameMask/UI_FrameMask_{id}.png"); + + return false; + } + } + + [HarmonyPatch] + public static class FramePatternLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetFramePatternTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_FramePattern_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetFramePatternTexture2D(id); + __result = texture ?? __instance.LoadAsset($"FramePattern/UI_FramePattern_{id}.png"); + + return false; + } + } + + [HarmonyPatch] + public static class IconLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + var method = AM.GetMethod("GetIconTexture2D", new[] { typeof(string) }); + if (method != null) + { + yield return method; + } + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_Icon_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + MelonLogger.Msg(filename); + var id = matches[0].Groups[1].Value; + + var texture = GetIconTexture2D(id); + __result = texture ?? __instance.LoadAsset($"Icon/UI_Icon_{id}.png"); + + return false; + } + } + + [HarmonyPatch] + public static class CharaLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetCharacterTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_Chara_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetCharaTexture2D(id); + __result = texture ?? __instance.LoadAsset($"Chara/UI_Chara_{id}.png"); + + return false; + } + } + + [HarmonyPatch] + public static class PartnerLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetPartnerTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_Partner_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetPartnerTexture2D(id); + __result = texture ?? __instance.LoadAsset($"Partner/UI_Partner_{id}.png"); + + return false; + } + } + /* + [HarmonyPatch] + public static class FrameLoader + { + public static IEnumerable TargetMethods() + { + var AM = typeof(AssetManager); + return [AM.GetMethod("GetFrameThumbTexture2D", [typeof(string)]), AM.GetMethod("GetFrameTexture2D", [typeof(string)])]; + } + + public static bool Prefix(string filename, ref Texture2D __result, AssetManager __instance) + { + var matches = Regex.Matches(filename, @"UI_Frame_(\d+)\.png"); + if (matches.Count < 1) + { + return true; + } + + var id = matches[0].Groups[1].Value; + + var texture = GetFrameTexture2D(id); + __result = texture ?? __instance.LoadAsset($"Frame/UI_Frame_{id}.png"); + return false; } } + */ }