Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FixCharWarn v1.0.2
FixCharWarn.dll
Decompiled 6 months agousing System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("FixCharWarn")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("FixCharWarn")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("6964290d-06d4-4810-84f0-aaf3de08e041")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace FixCharWarn; [BepInPlugin("FixCharWarn", "chuxia.FixCharWarn", "1.0.2")] public class FixCharWarnPlugin : BaseUnityPlugin { public static ManualLogSource ManualLog; public void Awake() { ManualLog = ((BaseUnityPlugin)this).Logger; Harmony.CreateAndPatchAll(typeof(Patches), (string)null); } } public static class Patches { private const bool ENABLE_DEBUG_LOG = false; [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] [HarmonyPriority(0)] [HarmonyWrapSafe] public static void TMP_Text_textSetter(TMP_Text __instance, ref string value) { if (!((Object)(object)__instance.font == (Object)null) && !string.IsNullOrEmpty(value)) { string text = ReplaceInvalidCharactersTMP(__instance, value); if ((object)text != value) { bool flag = false; value = text; } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] [HarmonyPriority(0)] [HarmonyWrapSafe] public static void Text_textSetter(Text __instance, ref string value) { if (!((Object)(object)__instance.font == (Object)null) && !string.IsNullOrEmpty(value)) { string text = ReplaceInvalidCharactersUI(__instance, value); if ((object)text != value) { bool flag = false; value = text; } } } private static string ReplaceInvalidCharactersUI(Text uiText, string input) { Font font = uiText.font; if ((Object)(object)font == (Object)null || string.IsNullOrEmpty(input)) { return input; } StringBuilder stringBuilder = new StringBuilder(input.Length); foreach (char c in input) { if (char.IsControl(c)) { stringBuilder.Append(c); } else if (font.HasCharacter(c)) { stringBuilder.Append(c); } else { stringBuilder.Append('□'); } } return stringBuilder.ToString(); } private static string ReplaceInvalidCharactersTMP(TMP_Text textComponent, string input) { TMP_FontAsset font = textComponent.font; if ((Object)(object)font == (Object)null || string.IsNullOrEmpty(input)) { return input; } StringBuilder stringBuilder = new StringBuilder(input.Length); foreach (char c in input) { if (char.IsControl(c)) { stringBuilder.Append(c); } else if (font.HasCharacter(c, true, true)) { stringBuilder.Append(c); } else { stringBuilder.Append('□'); } } return stringBuilder.ToString(); } }