Decompiled source of ColorEnabler v1.0.1

Antro.ColorEnabler.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Antro.ColorEnabler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Antro.ColorEnabler")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("Antro.ColorEnabler")]
[assembly: AssemblyTitle("Antro.ColorEnabler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Antro.ColorEnabler
{
	[BepInPlugin("Antro.ColorEnabler", "Color Enabler", "1.0.0.0")]
	public class Plugin : BasePlugin
	{
		public override void Load()
		{
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
			((BasePlugin)this).Log.LogInfo((object)"Color Enabler Loaded! (>color=RED>Word wraps only the word). Size tags are disabled for security.");
		}
	}
	public static class Patches
	{
		[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
		[HarmonyPostfix]
		public static void ForceRichTextUI(TextMeshProUGUI __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				((TMP_Text)__instance).richText = true;
			}
		}

		[HarmonyPatch(typeof(TextMeshPro), "Awake")]
		[HarmonyPostfix]
		public static void ForceRichText3D(TextMeshPro __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				((TMP_Text)__instance).richText = true;
			}
		}

		[HarmonyPatch(typeof(TMP_Text), "set_text")]
		[HarmonyPrefix]
		public static void ReplaceTags(ref string value)
		{
			if (!string.IsNullOrEmpty(value))
			{
				if (value.IndexOf("size", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					value = Regex.Replace(value, "(?i)<size=[^>]*>", string.Empty);
					value = Regex.Replace(value, "(?i)</size>", string.Empty);
				}
				if (value.Contains(">color="))
				{
					string pattern = ">color=([^>]+)>(\\S+)";
					string replacement = "<color=$1>$2</color>";
					value = Regex.Replace(value, pattern, replacement);
				}
				if (value.Contains(">b>"))
				{
					value = Regex.Replace(value, ">b>(\\S+)", "<b>$1</b>");
				}
			}
		}
	}
}