From 047ea001f0cef7206b0d713539169439134530ac Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Sun, 20 Apr 2025 12:20:55 -0400 Subject: [PATCH] abyss menu patch finished --- .../Patches/GameObjects/AbyssMenu_Patch.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs index c771e11..f3160c2 100644 --- a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs @@ -5,7 +5,7 @@ using MelonLoader; using PvZ_Fusion_Translator.AssetStore; using Unity.VisualScripting; using UnityEngine; -using static MelonLoader.MelonLogger; +using System.Text.RegularExpressions; namespace PvZ_Fusion_Translator.Patches.GameObjects { @@ -34,7 +34,27 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.levelInfo) { + string regexStr = "第(\\d+)关\n场景:([^\\s]+)\n总波数:(\\d+)波\n特殊环境:([^\\s:]+)\n减伤强度:(\\d+)"; + Regex regex = new Regex(regexStr); + + if(regex.IsMatch(txt.text)) + { + Match match = regex.Match(txt.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); + } + + txt.text = string.Format(StringStore.translationStringRegex[regexStr], [.. dynamicParts]); + txt.font = fontAsset; + } } } }