Decompiled source of LobbyChat v1.0.0

WormtownTestMod.dll

Decompiled 6 months 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;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[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("WormtownTestMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WormtownTestMod")]
[assembly: AssemblyTitle("WormtownTestMod")]
[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 WormtownTestMod
{
	[BepInPlugin("WormtownTestMod", "WormtownTestMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_ShowQuickChatMenu_InGamePardner <>9__3_1;

			public static hook_ShowQuickChatMenu_Lobby <>9__3_2;

			public static hook_Update <>9__3_3;

			internal void <Awake>b__3_1(orig_ShowQuickChatMenu_InGamePardner orig, QuickChatManager self)
			{
				_ = ChatController.IsChatOpen;
				if (!ChatController.IsChatOpen)
				{
					orig.Invoke(self);
				}
			}

			internal void <Awake>b__3_2(orig_ShowQuickChatMenu_Lobby orig, QuickChatManager self)
			{
				_ = ChatController.IsChatOpen;
				if (!ChatController.IsChatOpen)
				{
					orig.Invoke(self);
				}
			}

			internal void <Awake>b__3_3(orig_Update orig, WormAbilityManager self)
			{
				_ = ChatController.IsChatOpen;
				if (!((NetworkBehaviour)self).IsOwner || !ChatController.IsChatOpen)
				{
					orig.Invoke(self);
				}
			}
		}

		public static GameObject WormChatInstance;

		public static AssetBundle wormbundle;

		public static ManualLogSource logger;

		private void Awake()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			wormbundle = AssetBundle.LoadFromFile(Assembly.GetExecutingAssembly().Location.Replace("WormtownTestMod.dll", "wormbundle"));
			GameManager.Update += (hook_Update)delegate(orig_Update orig, GameManager self)
			{
				orig.Invoke(self);
				if ((Object)(object)WormChatInstance == (Object)null)
				{
					SpawnChatBox();
				}
			};
			object obj = <>c.<>9__3_1;
			if (obj == null)
			{
				hook_ShowQuickChatMenu_InGamePardner val = delegate(orig_ShowQuickChatMenu_InGamePardner orig, QuickChatManager self)
				{
					_ = ChatController.IsChatOpen;
					if (!ChatController.IsChatOpen)
					{
						orig.Invoke(self);
					}
				};
				<>c.<>9__3_1 = val;
				obj = (object)val;
			}
			QuickChatManager.ShowQuickChatMenu_InGamePardner += (hook_ShowQuickChatMenu_InGamePardner)obj;
			object obj2 = <>c.<>9__3_2;
			if (obj2 == null)
			{
				hook_ShowQuickChatMenu_Lobby val2 = delegate(orig_ShowQuickChatMenu_Lobby orig, QuickChatManager self)
				{
					_ = ChatController.IsChatOpen;
					if (!ChatController.IsChatOpen)
					{
						orig.Invoke(self);
					}
				};
				<>c.<>9__3_2 = val2;
				obj2 = (object)val2;
			}
			QuickChatManager.ShowQuickChatMenu_Lobby += (hook_ShowQuickChatMenu_Lobby)obj2;
			object obj3 = <>c.<>9__3_3;
			if (obj3 == null)
			{
				hook_Update val3 = delegate(orig_Update orig, WormAbilityManager self)
				{
					_ = ChatController.IsChatOpen;
					if (!((NetworkBehaviour)self).IsOwner || !ChatController.IsChatOpen)
					{
						orig.Invoke(self);
					}
				};
				<>c.<>9__3_3 = val3;
				obj3 = (object)val3;
			}
			WormAbilityManager.Update += (hook_Update)obj3;
		}

		private void SpawnChatBox()
		{
			WormChatInstance = Object.Instantiate<GameObject>(wormbundle.LoadAsset<GameObject>("ChatEntryBox.prefab"));
			((BaseUnityPlugin)this).Logger.LogInfo((object)WormChatInstance);
			((Component)WormChatInstance.transform.Find("Canvas")).gameObject.SetActive(false);
			WormChatInstance.AddComponent<ChatController>();
			Object.DontDestroyOnLoad((Object)(object)WormChatInstance);
		}
	}
	public class ChatController : MonoBehaviour
	{
		private GameObject canvas;

		public TMP_InputField input;

		public static bool IsChatOpen;

		public void Start()
		{
			canvas = ((Component)((Component)this).transform.Find("Canvas")).gameObject;
			input = canvas.GetComponentInChildren<TMP_InputField>();
			((UnityEvent<string>)(object)input.onSubmit).AddListener((UnityAction<string>)OnSubmit);
			Plugin.logger.LogError((object)"initialized chat ui");
		}

		public void Update()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if ((Object.op_Implicit((Object)(object)GameManager.Singleton) && (int)GameManager.Singleton.gameState == 1) || (int)GameManager.Singleton.gameState == 0)
			{
				if (Input.GetKeyDown((KeyCode)303))
				{
					if (canvas.activeInHierarchy)
					{
						canvas.SetActive(false);
						IsChatOpen = false;
						return;
					}
					canvas.SetActive(true);
					((Selectable)input).Select();
					((Selectable)input).OnSelect((BaseEventData)null);
					input.ActivateInputField();
					EventSystem.current.SetSelectedGameObject(((Component)input).gameObject, (BaseEventData)null);
					IsChatOpen = true;
				}
			}
			else
			{
				canvas.SetActive(false);
				IsChatOpen = false;
			}
		}

		public void OnSubmit(string text)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			if ((int)GameManager.Singleton.gameState == 1 || (int)GameManager.Singleton.gameState <= 0)
			{
				string steamDisplayNameText = MainMenuManager.Singleton.GetSteamDisplayNameText();
				if (text == "")
				{
					canvas.SetActive(false);
					IsChatOpen = false;
					return;
				}
				text = "<color=#56DEFF>" + steamDisplayNameText + "</color>: " + text;
				EventFeedManager.Singleton.AddANewEventFeedPopUp_ServerRPC(Encoding.UTF8.GetBytes(text), (byte)0);
				input.text = "";
				canvas.SetActive(false);
				IsChatOpen = false;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "WormtownTestMod";

		public const string PLUGIN_NAME = "WormtownTestMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}