Decompiled source of Simple Chat v1.1.0

SimpleChat/SimpleChat.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SimpleChat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleChat")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("265ac6eb-eb88-42ec-8525-f9bd3df38204")]
[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 SimpleChat;

[BepInPlugin("nb.wackjob.SimpleChat", "Simple Chat", "1.1.0")]
public class SimpleChat : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Terminal))]
	public static class Chat_MixedCase_Terminal_Patch
	{
		[HarmonyPatch("AddString", new Type[]
		{
			typeof(string),
			typeof(string),
			typeof(Type),
			typeof(bool)
		})]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddString_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return StripForcedCase(instructions);
		}
	}

	[HarmonyPatch(typeof(Chat))]
	public static class Chat_MixedCase_Chat_Patch
	{
		[HarmonyPatch("AddInworldText")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddInworldText_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return StripForcedCase(instructions);
		}
	}

	[HarmonyPatch(typeof(Chat))]
	public static class Chat_Shout_Patch
	{
		[HarmonyPatch("InputText")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> InputText_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldstr && instruction.operand.Equals("say "))
				{
					instruction.operand = "s ";
				}
				yield return instruction;
			}
		}
	}

	[HarmonyPatch(typeof(Minimap))]
	public static class Minimap_Patches
	{
		[HarmonyPatch("UpdateDynamicPins")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i + 1].opcode == OpCodes.Call)
				{
					MethodBase methodBase = (MethodBase)list[i + 1].operand;
					if (methodBase.Name == "UpdateShoutPins")
					{
						list.RemoveRange(i, 2);
						break;
					}
				}
			}
			return list;
		}
	}

	public static Harmony harmony = new Harmony("nb.wackjob.SimpleChat");

	private void Awake()
	{
		harmony.PatchAll();
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	public static IEnumerable<CodeInstruction> StripForcedCase(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].opcode == OpCodes.Callvirt)
			{
				MethodBase methodBase = list[i].operand as MethodBase;
				if (methodBase != null && (methodBase.Name == "ToLowerInvariant" || methodBase.Name == "ToUpper"))
				{
					list.RemoveRange(i - 1, 3);
					i -= 2;
				}
			}
		}
		return list;
	}
}