Decompiled source of EggChat v0.2.0

EggChat.dll

Decompiled 11 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameNetcodeStuff;
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("EggChat")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("(WIP) Quality-of-life additions to text chat.")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("EggChat")]
[assembly: AssemblyTitle("EggChat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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 EggChat
{
	[BepInPlugin("EggChat", "EggChat", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		public static int maxCharLimit = 127;

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Initializing EggChat");
			Instance = this;
			Harmony val = new Harmony("EggChat");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Initialized EggChat");
		}

		public static bool isLocalPlayerDead()
		{
			return GameNetworkManager.Instance.localPlayerController.isPlayerDead;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "EggChat";

		public const string PLUGIN_NAME = "EggChat";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace EggChat.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void HUDManager_awake(HUDManager __instance)
		{
			__instance.chatTextField.characterLimit = Plugin.maxCharLimit - 1;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void HUDManager_update(HUDManager __instance)
		{
			if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
			{
				__instance.Inventory.canvasGroup.alpha = 0f;
				__instance.PlayerInfo.canvasGroup.alpha = 0f;
				__instance.Clock.canvasGroup.alpha = 0f;
			}
		}

		[HarmonyPatch("EnableChat_performed")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> EnableChat_performed_transpiler(IEnumerable<CodeInstruction> instructions)
		{
			FieldInfo isPlayerDead = typeof(PlayerControllerB).GetField("isPlayerDead");
			bool referenceToIsPlayerDead = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.LoadsField(instruction, isPlayerDead, false))
				{
					referenceToIsPlayerDead = true;
				}
				if (referenceToIsPlayerDead && instruction.opcode == OpCodes.Ret)
				{
					referenceToIsPlayerDead = false;
					yield return new CodeInstruction(OpCodes.Nop, (object)null);
				}
				else
				{
					yield return instruction;
				}
			}
		}

		[HarmonyPatch("SubmitChat_performed")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> SubmitChat_performed_transpiler(IEnumerable<CodeInstruction> instructions)
		{
			FieldInfo isPlayerDead = typeof(PlayerControllerB).GetField("isPlayerDead");
			bool referenceToIsPlayerDead = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.LoadsField(instruction, isPlayerDead, false))
				{
					referenceToIsPlayerDead = true;
				}
				if (referenceToIsPlayerDead && instruction.opcode == OpCodes.Ret)
				{
					referenceToIsPlayerDead = false;
					yield return new CodeInstruction(OpCodes.Nop, (object)null);
				}
				else if (instruction.opcode == OpCodes.Ldc_I4_S && (sbyte)instruction.operand == 50)
				{
					yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)Plugin.maxCharLimit);
				}
				else
				{
					yield return instruction;
				}
			}
		}

		[HarmonyPatch("AddPlayerChatMessageServerRpc")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddPlayerChatMessageServerRpc_transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldc_I4_S && (sbyte)instruction.operand == 50)
				{
					yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)Plugin.maxCharLimit);
				}
				else
				{
					yield return instruction;
				}
			}
		}

		[HarmonyPatch("AddPlayerChatMessageClientRpc")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddPlayerChatMessageClientRpc_transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator iL)
		{
			FieldInfo isPlayerDead = typeof(PlayerControllerB).GetField("isPlayerDead");
			bool referenceToIsPlayerDead = false;
			Label addChatMessageLabel = default(Label);
			foreach (CodeInstruction instruction2 in instructions)
			{
				if (instruction2.opcode == OpCodes.Brtrue)
				{
					addChatMessageLabel = (Label)instruction2.operand;
				}
			}
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.LoadsField(instruction, isPlayerDead, false))
				{
					referenceToIsPlayerDead = true;
				}
				if (referenceToIsPlayerDead && instruction.opcode == OpCodes.Ret)
				{
					referenceToIsPlayerDead = false;
					yield return new CodeInstruction(OpCodes.Call, (object)typeof(Plugin).GetMethod("isLocalPlayerDead"));
					yield return new CodeInstruction(OpCodes.Brtrue, (object)addChatMessageLabel);
					yield return instruction;
				}
				else
				{
					yield return instruction;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("KillPlayer")]
		[HarmonyPostfix]
		private static void KillPlayer_postfix()
		{
			HUDManager.Instance.HideHUD(false);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> EndOfGame_transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo hideHUD = typeof(HUDManager).GetMethod("HideHUD");
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, hideHUD))
				{
					yield return new CodeInstruction(OpCodes.Pop, (object)null);
					yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
					yield return instruction;
				}
				else
				{
					yield return instruction;
				}
			}
		}
	}
}