using HarmonyLib; using System; using System.Collections.Generic; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using Unity.VisualScripting; using UnityEngine; using System.Text.RegularExpressions; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { [HarmonyPatch(typeof(AbyssSettlementMenu))] public static class AbyssSettlementMenu_Patch { [HarmonyPatch(nameof(AbyssSettlementMenu.InitSettle))] [HarmonyPostfix] private static void InitSettle(AbyssSettlementMenu __instance) { TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); string[] regexStrList = [ "?(\\d+)?\n????:(\\d+)?(\\d+)?\n????:(\\d+)\n???????:(\\d+)\n??????:(\\d+)\n????????\n???????:(\\d+)", "?(\\d+)?\n????:(\\d+)?(\\d+)?\n????:(\\d+)\n???????:(\\d+)\n??????:(\\d+)\n????:(\\d+)\n???????:(\\d+),?????:(\\d+)\n???????:(\\d+)", "?(\\d+)?\n????:(\\d+)?(\\d+)?\n????:(\\d+)\n???????:(\\d+)\n????:(\\d+)\n???????:(\\d+),?????:(\\d+)\n???????:(\\d+)", "?(\\d+)?\n????:(\\d+)?(\\d+)?\n????:(\\d+)\n???????:(\\d+)\n??????:(\\d+)\n????:(\\d+)\n???????:(\\d+),?????:(\\d+)\n???????:(\\d+)", "?(\\d+)?\n????:(\\d+)?(\\d+)?\n????:(\\d+)\n???????:(\\d+)\n????????\n???????:(\\d+)", "?(\\d+)?\n????:(\\d+)?(\\d+)?\n????:(\\d+)\n???????:(\\d+)\n??????:(\\d+)\n????????\n???????:(\\d+)" ]; foreach(string regexStr in regexStrList) { Regex regex = new Regex(regexStr); if (regex.IsMatch(__instance.settleInfo.text)) { Match match = regex.Match(__instance.settleInfo.text); int groupCount = match.Groups.Count; List dynamicParts = []; for (int i = 1; i < groupCount; i++) { string groupValue = match.Groups[i].Value; string translatedValue = StringStore.translationString.ContainsKey(groupValue) ? StringStore.translationString[groupValue] : groupValue; dynamicParts.Add(translatedValue); } __instance.settleInfo.text = string.Format(StringStore.translationStringRegex[regexStr], [.. dynamicParts]); __instance.settleInfo.font = fontAsset; } } } } }