Decompiled source of PolariteTMP v0.1.3

Polarite TMP.dll

Decompiled 2 months ago
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;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Polarite.Multiplayer;
using Polarite.Networking.Extensions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UKMod template")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UKMod template")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3d018c2f-f5bc-47be-a844-3e9888579d1f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PolariteTMP;

[BepInPlugin("com.nico.polaritetmp", "Polarite TMP", "0.3.0")]
public class Plugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.nico.polaritetmp";

	public const string PluginName = "Polarite TMP";

	public const string PluginVersion = "0.3.0";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"Polarite TMP loaded!");
		Harmony val = new Harmony("com.nico.polaritetmp");
		val.PatchAll();
	}
}
[HarmonyPatch(typeof(ChatUI), "<CreateUI>b__20_0")]
internal static class ChatUI_MessageBuild_Patch
{
	private static readonly Regex TagRegex = new Regex("<(/?)(\\w+)[^>]*>", RegexOptions.Compiled);

	private static readonly HashSet<string> VoidTags = new HashSet<string> { "br" };

	private static string CloseUnclosedTags(string input)
	{
		if (string.IsNullOrEmpty(input))
		{
			return input;
		}
		List<string> list = new List<string>();
		foreach (Match item2 in TagRegex.Matches(input))
		{
			bool flag = item2.Groups[1].Value == "/";
			string item = item2.Groups[2].Value.ToLowerInvariant();
			if (VoidTags.Contains(item))
			{
				continue;
			}
			if (flag)
			{
				int num = list.LastIndexOf(item);
				if (num >= 0)
				{
					list.RemoveRange(num, list.Count - num);
				}
			}
			else
			{
				list.Add(item);
			}
		}
		if (list.Count == 0)
		{
			return input;
		}
		StringBuilder stringBuilder = new StringBuilder(input);
		for (int num2 = list.Count - 1; num2 >= 0; num2--)
		{
			stringBuilder.Append("</").Append(list[num2]).Append('>');
		}
		return stringBuilder.ToString();
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(StringExtensions), "WithoutTMP", (Type[])null, (Type[])null);
		MethodInfo operand = AccessTools.Method(typeof(ChatUI_MessageBuild_Patch), "CloseUnclosedTags", (Type[])null, (Type[])null);
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		int num = 0;
		for (int i = 0; i < list.Count; i++)
		{
			if (CodeInstructionExtensions.Calls(list[i], methodInfo))
			{
				list[i].operand = operand;
				num++;
			}
		}
		if (num == 0)
		{
			Plugin.Log.LogWarning((object)"PolariteTMP: no WithoutTMP calls found to patch - game may have updated.");
		}
		else
		{
			Plugin.Log.LogInfo((object)$"PolariteTMP: Successfully redirected {num} instance(s) of WithoutTMP.");
		}
		return list;
	}
}