Skip to content

Commit

Permalink
[F] IconLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Nov 21, 2024
1 parent 9143b92 commit 0e02dd6
Showing 1 changed file with 74 additions and 78 deletions.
152 changes: 74 additions & 78 deletions AquaMai/UX/LoadAssetsPng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ namespace AquaMai.UX;
public class LoadAssetsPng
{
private static string[] imageExts = [".jpg", ".png", ".jpeg"];
private static Dictionary<string, string> jacketPaths = new();
private static Dictionary<string, string> framePaths = new();
private static Dictionary<string, string> platePaths = new();
private static Dictionary<string, string> framemaskPaths = new();
private static Dictionary<string, string> framepatternPaths = new();
private static Dictionary<string, string> iconPaths = new();
private static Dictionary<string, string> charaPaths = new();
private static Dictionary<string, string> partnerPaths = new();
private static Dictionary<string, string> jacketPaths = new();
private static Dictionary<string, string> framePaths = new();
private static Dictionary<string, string> platePaths = new();
private static Dictionary<string, string> framemaskPaths = new();
private static Dictionary<string, string> framepatternPaths = new();
private static Dictionary<string, string> iconPaths = new();
private static Dictionary<string, string> charaPaths = new();

private static Dictionary<string, string> partnerPaths = new();

//private static Dictionary<string, string> navicharaPaths = new();
private static Dictionary<string, string> tabTitlePaths = new();
private static Dictionary<string, string> localAssetsContents = new();
Expand All @@ -41,71 +43,71 @@ public static void LoadMusicPostfix(List<string> ____targetDirs)
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, @"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")))
{
Expand Down Expand Up @@ -147,8 +149,8 @@ public static Texture2D GetJacketTexture2D(string id)
public static Texture2D GetJacketTexture2D(int id)
{
return GetJacketTexture2D($"{id:000000}");
}

}

private static string GetFramePath(string id)
{
return framePaths.GetValueOrDefault(id);
Expand All @@ -165,7 +167,8 @@ public static Texture2D GetFrameTexture2D(string id)
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);
Expand All @@ -182,8 +185,8 @@ public static Texture2D GetPlateTexture2D(string id)
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);
Expand All @@ -200,8 +203,8 @@ public static Texture2D GetFrameMaskTexture2D(string id)
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);
Expand All @@ -218,7 +221,8 @@ public static Texture2D GetFramePatternTexture2D(string id)
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);
Expand All @@ -235,7 +239,8 @@ public static Texture2D GetIconTexture2D(string id)
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);
Expand All @@ -252,12 +257,13 @@ public static Texture2D GetCharaTexture2D(string id)
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);
Expand Down Expand Up @@ -360,8 +366,8 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}

}

[HarmonyPatch]
public static class FrameLoader
{
Expand All @@ -386,8 +392,8 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}

}

[HarmonyPatch]
public static class PlateLoader
{
Expand All @@ -412,8 +418,8 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}

}

[HarmonyPatch]
public static class FrameMaskLoader
{
Expand All @@ -438,8 +444,8 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}

}

[HarmonyPatch]
public static class FramePatternLoader
{
Expand All @@ -464,38 +470,28 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}

[HarmonyPatch]
public static class IconLoader
}

// Private | Instance
[HarmonyPrefix]
[HarmonyPatch(typeof(AssetManager), "GetIconTexture2D", typeof(string))]
public static bool IconLoader(string filename, ref Texture2D __result, AssetManager __instance)
{
public static IEnumerable<MethodBase> TargetMethods()
var matches = Regex.Matches(filename, @"UI_Icon_(\d+)\.png");
if (matches.Count < 1)
{
var AM = typeof(AssetManager);
var method = AM.GetMethod("GetIconTexture2D", new[] { typeof(string) });
if (method != null)
{
yield return method;
}
return true;
}

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;
MelonLogger.Msg(filename);
var id = matches[0].Groups[1].Value;

var texture = GetIconTexture2D(id);
__result = texture ?? __instance.LoadAsset<Texture2D>($"Icon/UI_Icon_{id}.png");
var texture = GetIconTexture2D(id);
__result = texture ?? __instance.LoadAsset<Texture2D>($"Icon/UI_Icon_{id}.png");

return false;
}

return false;
}
}

[HarmonyPatch]
public static class CharaLoader
{
Expand All @@ -520,8 +516,8 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}
}

[HarmonyPatch]
public static class PartnerLoader
{
Expand All @@ -546,8 +542,8 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager

return false;
}
}
/*
}
/*
[HarmonyPatch]
public static class FrameLoader
{
Expand All @@ -574,4 +570,4 @@ public static bool Prefix(string filename, ref Texture2D __result, AssetManager
}
}
*/
}
}

0 comments on commit 0e02dd6

Please sign in to comment.