[F] IconLoader

pull/88/head
Clansty 2024-11-22 00:59:25 +08:00
parent 9143b92932
commit 0e02dd660c
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
1 changed files with 74 additions and 78 deletions

View File

@ -24,7 +24,9 @@ public class LoadAssetsPng
private static Dictionary<string, string> framepatternPaths = new(); private static Dictionary<string, string> framepatternPaths = new();
private static Dictionary<string, string> iconPaths = new(); private static Dictionary<string, string> iconPaths = new();
private static Dictionary<string, string> charaPaths = new(); private static Dictionary<string, string> charaPaths = new();
private static Dictionary<string, string> partnerPaths = new(); private static Dictionary<string, string> partnerPaths = new();
//private static Dictionary<string, string> navicharaPaths = new(); //private static Dictionary<string, string> navicharaPaths = new();
private static Dictionary<string, string> tabTitlePaths = new(); private static Dictionary<string, string> tabTitlePaths = new();
private static Dictionary<string, string> localAssetsContents = new(); private static Dictionary<string, string> localAssetsContents = new();
@ -166,6 +168,7 @@ public class LoadAssetsPng
texture.LoadImage(File.ReadAllBytes(path)); texture.LoadImage(File.ReadAllBytes(path));
return texture; return texture;
} }
private static string GetPlatePath(string id) private static string GetPlatePath(string id)
{ {
return platePaths.GetValueOrDefault(id); return platePaths.GetValueOrDefault(id);
@ -219,6 +222,7 @@ public class LoadAssetsPng
texture.LoadImage(File.ReadAllBytes(path)); texture.LoadImage(File.ReadAllBytes(path));
return texture; return texture;
} }
private static string GetIconPath(string id) private static string GetIconPath(string id)
{ {
return iconPaths.GetValueOrDefault(id); return iconPaths.GetValueOrDefault(id);
@ -236,6 +240,7 @@ public class LoadAssetsPng
texture.LoadImage(File.ReadAllBytes(path)); texture.LoadImage(File.ReadAllBytes(path));
return texture; return texture;
} }
private static string GetCharaPath(string id) private static string GetCharaPath(string id)
{ {
return charaPaths.GetValueOrDefault(id); return charaPaths.GetValueOrDefault(id);
@ -253,6 +258,7 @@ public class LoadAssetsPng
texture.LoadImage(File.ReadAllBytes(path)); texture.LoadImage(File.ReadAllBytes(path));
return texture; return texture;
} }
private static string GetPartnerPath(string id) private static string GetPartnerPath(string id)
{ {
return partnerPaths.GetValueOrDefault(id); return partnerPaths.GetValueOrDefault(id);
@ -466,34 +472,24 @@ public class LoadAssetsPng
} }
} }
[HarmonyPatch] // Private | Instance
public static class IconLoader [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); return true;
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) MelonLogger.Msg(filename);
{ var id = matches[0].Groups[1].Value;
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); var texture = GetIconTexture2D(id);
__result = texture ?? __instance.LoadAsset<Texture2D>($"Icon/UI_Icon_{id}.png"); __result = texture ?? __instance.LoadAsset<Texture2D>($"Icon/UI_Icon_{id}.png");
return false; return false;
}
} }
[HarmonyPatch] [HarmonyPatch]