using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using HarmonyLib; using TMPro; using TurronishMod.Logger; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: Guid("426c6978-4a61-7600-9d41-426c69784a61")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.0.0.0")] namespace ControlDoblaje; [BepInPlugin("com.turronish.localizacion", "Turronish Localizacion", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class TurronishLocalizacionPlugin : BaseUnityPlugin { private void Awake() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown TraduccionParcialScannerInstaller.Instalar(); Harmony val = new Harmony("com.turronish.localizacion"); val.PatchAll(); try { Type type = AccessTools.TypeByName("Febucci.UI.TextAnimatorPlayer"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "ShowText", new Type[1] { typeof(string) }, (Type[])null) : null); if (methodInfo != null) { val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(FebucciShowTextPatch).GetMethod("Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Fade] Febucci ShowText parcheado (traducción en entrada)."); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[Fade] Febucci TextAnimatorPlayer.ShowText no encontrado — fade-in del español quedará sin re-cálculo."); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[Fade] patch Febucci falló (omitido): " + ex.Message)); } TurronishDiagLogger.Info("[Localizacion]", "TurronishLocalizacion cargado OK."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Localizacion] TurronishLocalizacion cargado."); } } public static class FebucciShowTextPatch { public static void Prefix(ref string text) { if (string.IsNullOrEmpty(text)) { return; } try { text = Traducciones.Aplicar(text); } catch { } } } public class TraduccionParcialScanner : MonoBehaviour { private float _timer = 0f; private const float INTERVAL = 0.8f; private static readonly char[] _accentadas = "áéíóúñ¡¿ÁÉÍÓÚÑ".ToCharArray(); private void Update() { if (!Traducciones.TextoEspanolActivo) { return; } _timer -= Time.unscaledDeltaTime; if (_timer > 0f) { return; } _timer = 0.8f; try { EscanearTextosParcia(); } catch { } } private static void EscanearTextosParcia() { TextMeshProUGUI[] array = Object.FindObjectsOfType(); foreach (TextMeshProUGUI val in array) { if ((Object)(object)val == (Object)null || Traducciones.EsDeNuestraUI((Component)(object)val)) { continue; } string text = ((TMP_Text)val).text; if (string.IsNullOrEmpty(text) || !text.Contains("\n") || (Object)(object)((Component)val).GetComponentInParent() != (Object)null) { continue; } bool flag = false; bool flag2 = false; string[] array2 = text.Split(new char[1] { '\n' }); foreach (string text2 in array2) { if (!string.IsNullOrWhiteSpace(text2)) { if (text2.IndexOfAny(_accentadas) >= 0) { flag = true; } else if (text2.Trim().Length >= 8) { flag2 = true; } if (flag && flag2) { break; } } } if (flag && flag2) { Traducciones.InvalidarCache(text); string text3 = Traducciones.Aplicar(text); if (text3 != text) { ((TMP_Text)val).SetText(text3); } } } } } public static class TraduccionParcialScannerInstaller { private static GameObject _go; public static void Instalar() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if (!((Object)(object)_go != (Object)null)) { _go = new GameObject("_TraduccionParcialScanner"); Object.DontDestroyOnLoad((Object)(object)_go); _go.AddComponent(); _go.AddComponent(); } } } internal static class PromptFix { private static readonly HashSet _ensanchadas = new HashSet(); public static void AjustarLargo(TMP_Text tmp, string textoFinal) { //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)tmp == (Object)null || textoFinal == null) { return; } string text = Regex.Replace(textoFinal, "<[^>]+>", string.Empty).Trim(); if (text != "Reanudar") { return; } try { bool flag = false; PropertyInfo property = ((object)tmp).GetType().GetProperty("textWrappingMode"); if (property != null) { try { object value = Enum.Parse(property.PropertyType, "NoWrap"); property.SetValue(tmp, value, null); flag = true; } catch { } } if (!flag && tmp.enableWordWrapping) { tmp.enableWordWrapping = false; } tmp.overflowMode = (TextOverflowModes)0; int instanceID = ((Object)tmp).GetInstanceID(); if (!_ensanchadas.Add(instanceID)) { return; } RectTransform rectTransform = tmp.rectTransform; if ((Object)(object)rectTransform != (Object)null) { float num = tmp.GetPreferredValues(textoFinal).x + 8f; float num2 = num - rectTransform.sizeDelta.x; if (num2 > 0f) { rectTransform.sizeDelta = new Vector2(num, rectTransform.sizeDelta.y); rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x + num2 * rectTransform.pivot.x, rectTransform.anchoredPosition.y); } } } catch { } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] public class UITraduccionesSetterPatch { private static readonly HashSet _ajustadas = new HashSet(); private static bool _reparsando = false; private static void Prefix(TMP_Text __instance, ref string value) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).GetComponentInParent() != (Object)null) && !Traducciones.EsDeNuestraUI((Component)(object)__instance)) { string text = value; value = Traducciones.Aplicar(value); PromptFix.AjustarLargo(__instance, value); if (value != text && (float)value.Length > (float)text.Length * 1.15f) { _ajustadas.Remove(((Object)__instance).GetInstanceID()); } } } private static void Postfix(TMP_Text __instance) { if (_reparsando || (Object)(object)__instance == (Object)null) { return; } int instanceID = ((Object)__instance).GetInstanceID(); if (_ajustadas.Contains(instanceID)) { return; } string text = __instance.text; if (text == null || text.IndexOf("{fade", StringComparison.OrdinalIgnoreCase) < 0) { return; } _ajustadas.Add(instanceID); if (text.Contains("Recuerda,")) { float num = ((__instance.enableAutoSizing && __instance.fontSizeMax > 0f) ? __instance.fontSizeMax : __instance.fontSize); if (num > 0f) { __instance.enableAutoSizing = false; __instance.fontSize = num * 0.75f; ControlDoblajePlugin.Log.LogInfo((object)$"[TMP-Resize] 'Recuerda ENA' → autoSize off, fontSize {num:F1} → {__instance.fontSize:F1}"); } } ReParsearFebucci(__instance, text); } private static void ReParsearFebucci(TMP_Text tmp, string texto) { try { Component[] components = ((Component)tmp).GetComponents(); Component[] array = components; foreach (Component val in array) { if ((Object)(object)val == (Object)null) { continue; } Type type = ((object)val).GetType(); string name = type.Name; if (name.IndexOf("TextAnimator", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Typewriter", StringComparison.OrdinalIgnoreCase) < 0) { continue; } _reparsando = true; try { if (TryInvocar(val, type, "SetText", new object[2] { texto, false }) || TryInvocar(val, type, "ShowText", new object[1] { texto }) || TryInvocar(val, type, "SetText", new object[1] { texto })) { break; } } finally { _reparsando = false; } } } catch { } } private static bool TryInvocar(object comp, Type tp, string metodo, object[] args) { try { Type[] array = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { array[i] = args[i].GetType(); } MethodInfo method = tp.GetMethod(metodo, BindingFlags.Instance | BindingFlags.Public, null, array, null); if (method == null) { return false; } method.Invoke(comp, args); ControlDoblajePlugin.Log.LogInfo((object)$"[Fade] Febucci re-parse via {tp.Name}.{metodo}({array.Length} args)"); return true; } catch { return false; } } } [HarmonyPatch(typeof(TMP_Text), "SetText", new Type[] { typeof(string) })] public class UITraduccionesSetTextPatch { private static void Prefix(TMP_Text __instance, ref string sourceText) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).GetComponentInParent() != (Object)null) && !Traducciones.EsDeNuestraUI((Component)(object)__instance)) { sourceText = Traducciones.Aplicar(sourceText); PromptFix.AjustarLargo(__instance, sourceText); } } } [HarmonyPatch(typeof(TMP_Text), "SetText", new Type[] { typeof(string), typeof(bool) })] public class UITraduccionesSetTextBoolPatch { private static void Prefix(TMP_Text __instance, ref string sourceText) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).GetComponentInParent() != (Object)null) && !Traducciones.EsDeNuestraUI((Component)(object)__instance)) { sourceText = Traducciones.Aplicar(sourceText); PromptFix.AjustarLargo(__instance, sourceText); } } } [HarmonyPatch(typeof(TextMeshProUGUI), "OnEnable")] public class UITraduccionesOnEnablePatch { private static void Postfix(TextMeshProUGUI __instance) { if (!((Object)(object)((Component)__instance).GetComponentInParent() != (Object)null) && !Traducciones.EsDeNuestraUI((Component)(object)__instance)) { string text = Traducciones.Aplicar(((TMP_Text)__instance).text); if (text != ((TMP_Text)__instance).text) { ((TMP_Text)__instance).SetText(text); } } } } [HarmonyPatch(typeof(TextMeshProUGUI), "Awake")] public class UITraduccionesAwakePatch { private static void Postfix(TextMeshProUGUI __instance) { if (Traducciones.TextoEspanolActivo && !((Object)(object)((Component)__instance).GetComponentInParent() != (Object)null) && !Traducciones.EsDeNuestraUI((Component)(object)__instance)) { string text = Traducciones.Aplicar(((TMP_Text)__instance).text); if (text != ((TMP_Text)__instance).text) { ((TMP_Text)__instance).SetText(text); } } } }