diff --git a/MelonLoader/AssetStore/TextureStore.cs b/MelonLoader/AssetStore/TextureStore.cs index 9947d33..9bf4ca4 100644 --- a/MelonLoader/AssetStore/TextureStore.cs +++ b/MelonLoader/AssetStore/TextureStore.cs @@ -7,8 +7,9 @@ namespace PvZ_Fusion_Translator.AssetStore public static class TextureStore { internal static Dictionary textureDict = []; + internal static Dictionary spriteDict = []; - internal static void Init() => FileLoader.LoadTextures(); + internal static void Init() => FileLoader.LoadTextures(); internal static void Reload() { diff --git a/MelonLoader/FileLoader.cs b/MelonLoader/FileLoader.cs index 0bc86f9..f151d5c 100644 --- a/MelonLoader/FileLoader.cs +++ b/MelonLoader/FileLoader.cs @@ -17,6 +17,7 @@ namespace PvZ_Fusion_Translator Strings, Dumps, Almanac, + Sprites } public static string GetAssetDir(AssetType assetType, Utils.LanguageEnum? language = null) @@ -115,11 +116,12 @@ namespace PvZ_Fusion_Translator LoadLocalizedTextures(Utils.LanguageEnum.English); } LoadLocalizedTextures(Utils.Language); - #else + LoadLocalizedSprites(Utils.Language); + #else LoadLocalizedTextures(); - #endif +#endif - Log.LogInfo("Textures loaded successfully."); + Log.LogInfo("Textures loaded successfully."); } internal static void LoadLocalizedTextures(Utils.LanguageEnum? language = null) @@ -163,7 +165,48 @@ namespace PvZ_Fusion_Translator } } - internal static void LoadDefaultTextures() + internal static void LoadLocalizedSprites(Utils.LanguageEnum? language = null) + { + string textureDir = GetAssetDir(AssetType.Sprites, language); + + if (!Directory.Exists(textureDir)) + { + Directory.CreateDirectory(textureDir); + } + try + { + foreach (string filepath in Directory.EnumerateFiles(textureDir, "*.png", SearchOption.AllDirectories)) + { + if (filepath.Contains("[Custom Textures]", StringComparison.OrdinalIgnoreCase) && loadDefaultTextures) + { + continue; + } + + #if OBFUSCATE + if (CheckSumStore.IsModified(filepath)) + { + Log.LogError("File {0} was modified!" , filepath); + continue; + } + #endif + + #if DEBUG + Log.LogDebug("Loading File (Sprite): " + filepath); + #endif + + Texture2D texture2D = Utils.LoadImage(filepath); + TextureStore.spriteDict[Path.GetFileNameWithoutExtension(filepath)] = filepath; + } + } + + catch (Exception e) + { + Log.LogError("Error loading Texture."); + Log.LogError(e.GetType() + " " + e.Message); + } + } + + internal static void LoadDefaultTextures() { if(Utils.customTextures == false) { diff --git a/MelonLoader/Patches/GameObjects/Board_Patch.cs b/MelonLoader/Patches/GameObjects/Board_Patch.cs new file mode 100644 index 0000000..328e768 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/Board_Patch.cs @@ -0,0 +1,28 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(Board))] + public static class Board_Patch + { + [HarmonyPatch(nameof(Board.Update))] + [HarmonyPostfix] + private static void Update(Board __instance) + { + foreach (SpriteRenderer spriteRenderer in __instance.GetComponentsInChildren()) + { + if (spriteRenderer.sprite != null) + { + if (TextureStore.spriteDict.ContainsKey(spriteRenderer.sprite.name) && spriteRenderer.drawMode != SpriteDrawMode.Sliced) + { + spriteRenderer.drawMode = SpriteDrawMode.Sliced; + } + } + } + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 0c67690..fa1cbfe 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -400,6 +400,7 @@ +