Decompiled source of MinecraftFormatting v1.0.0

MinecraftFormatting.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MinecraftFormatting")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MinecraftFormatting")]
[assembly: AssemblyTitle("MinecraftFormatting")]
[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 MinecraftFormatting
{
	[BepInPlugin("MinecraftFormatting", "MinecraftFormatting", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmony = new Harmony("MinecraftFormatting");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MinecraftFormatting loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MinecraftFormatting";

		public const string PLUGIN_NAME = "MinecraftFormatting";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MinecraftFormatting.Patches
{
	[HarmonyPatch(typeof(HUDManager), "AddTextToChatOnServer")]
	public class SendChat
	{
		private static readonly Dictionary<char, string> colors = new Dictionary<char, string>
		{
			{ '0', "<color=#000000>" },
			{ '1', "<color=#0000AA>" },
			{ '2', "<color=#00AA00>" },
			{ '3', "<color=#00AAAA>" },
			{ '4', "<color=#AA0000>" },
			{ '5', "<color=#AA00AA>" },
			{ '6', "<color=#FFAA00>" },
			{ '7', "<color=#AAAAAA>" },
			{ '8', "<color=#555555>" },
			{ '9', "<color=#5555FF>" },
			{ 'a', "<color=#55FF55>" },
			{ 'b', "<color=#55FFFF>" },
			{ 'c', "<color=#FF5555>" },
			{ 'd', "<color=#FF55FF>" },
			{ 'e', "<color=#FFFF55>" },
			{ 'f', "<color=#FFFFFF>" }
		};

		private static readonly Dictionary<char, string> formats = new Dictionary<char, string>
		{
			{ 'l', "<b>" },
			{ 'm', "<s>" },
			{ 'n', "<u>" },
			{ 'o', "<i>" },
			{ 'r', "<color=#FFFF00>" }
		};

		private static void Prefix(ref string chatMessage, int playerId)
		{
			if (playerId != -1)
			{
				chatMessage = FormatText(chatMessage, playerId);
			}
		}

		private static string FormatText(string chatMessage, int playerId)
		{
			List<char> list = new List<char>();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append((playerId == -1) ? "<color=#7069ff>" : "<color=#FFFF00>");
			for (int i = 0; i < chatMessage.Length; i++)
			{
				bool flag = false;
				if (chatMessage[i] == '&')
				{
					if (i + 1 == chatMessage.Length)
					{
						break;
					}
					if (chatMessage[i + 1] == 'r')
					{
						stringBuilder.Append("</color>");
						stringBuilder.Append(formats['r']);
						foreach (char item in list)
						{
							stringBuilder.Append("</");
							stringBuilder.Append(item);
							stringBuilder.Append('>');
						}
						list.Clear();
						i += 2;
						flag = true;
					}
					else if (formats.ContainsKey(chatMessage[i + 1]))
					{
						list.Add(formats[chatMessage[i + 1]][1]);
						stringBuilder.Append(formats[chatMessage[i + 1]]);
						i += 2;
						flag = true;
					}
					else if (colors.ContainsKey(chatMessage[i + 1]))
					{
						stringBuilder.Append("</color>");
						stringBuilder.Append(colors[chatMessage[i + 1]]);
						i += 2;
						flag = true;
					}
				}
				if (i >= chatMessage.Length)
				{
					break;
				}
				if (chatMessage[i] == '&' && flag)
				{
					i--;
				}
				else
				{
					stringBuilder.Append(chatMessage[i]);
				}
			}
			foreach (char item2 in list)
			{
				stringBuilder.Append("</");
				stringBuilder.Append(item2);
				stringBuilder.Append('>');
			}
			stringBuilder.Append("</color>");
			return stringBuilder.ToString();
		}
	}
}