Decompiled source of SimpleMessage v1.0.0

plugins/SimpleMessage.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("SimpleMessage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SimpleMessage")]
[assembly: AssemblyTitle("SimpleMessage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace SimpleMessage
{
	[BepInPlugin("TheCosmicJesterOfTheVoid.SimpleMessage", "SimpleMessage", "1.0.0.0")]
	public class SimpleMessageBase : BaseUnityPlugin
	{
		private const string modGUID = "TheCosmicJesterOfTheVoid.SimpleMessage";

		private const string modName = "SimpleMessage";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("TheCosmicJesterOfTheVoid.SimpleMessage");

		public static SimpleMessageBase Instance;

		internal ManualLogSource mls;

		public static ConfigEntry<string> color;

		public static GameObject simpleMessagePrefab;

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("TheCosmicJesterOfTheVoid.SimpleMessage");
			mls.LogInfo((object)"SimpleMessage awakened.");
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "simplemessage"));
			simpleMessagePrefab = val.LoadAsset<GameObject>("Assets/Items/SimpleMessage/SimpleCanvas.prefab");
			color = ((BaseUnityPlugin)this).Config.Bind<string>("SimpleMessage", "Color", "purple", "the color of the text can be its name (e.g: purple) or html format (e.g: #ff0000ff)");
			mls.LogInfo((object)"SimpleMessage loaded.");
			harmony.PatchAll(typeof(SimpleMessagePatch));
		}
	}
	public class SimpleMessageGO : NetworkBehaviour
	{
		private bool isOpen = false;

		public GameObject InputBox;

		private static SimpleMessageGO instance;

		private TMP_InputField inputField;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void Start()
		{
			if (!((Object)(object)this != (Object)(object)instance))
			{
				InputActionAsset actions = IngamePlayerSettings.Instance.playerInput.actions;
				SimpleMessageInputClass.Instance.SimmpleMessageKey.performed += SimpleMessage;
				InputBox = ((Component)((Component)this).transform.GetChild(0)).gameObject;
				inputField = InputBox.GetComponent<TMP_InputField>();
				((UnityEvent<string>)(object)inputField.onSubmit).AddListener((UnityAction<string>)SendGlobalMessage);
				InputBox.SetActive(false);
				Debug.Log((object)"This spawned");
			}
		}

		private void SimpleMessage(CallbackContext context)
		{
			Debug.Log((object)"Pressed X");
			if ((Object)(object)HUDManager.Instance != (Object)null && ((NetworkBehaviour)HUDManager.Instance).IsHost)
			{
				if (isOpen)
				{
					isOpen = false;
					InputBox.SetActive(false);
				}
				else
				{
					isOpen = true;
					InputBox.SetActive(true);
					((Selectable)inputField).Select();
				}
			}
		}

		private void SendGlobalMessage(string message)
		{
			inputField.text = "";
			Debug.Log((object)("SimpleMessage: " + message));
			isOpen = false;
			InputBox.SetActive(false);
			if (Object.op_Implicit((Object)(object)HUDManager.Instance))
			{
				HUDManager.Instance.AddTextMessageClientRpc("<color=" + SimpleMessageBase.color.Value + ">" + message + "</color>\n");
			}
		}

		public override void OnDestroy()
		{
			((NetworkBehaviour)this).OnDestroy();
			SimpleMessageInputClass.Instance.SimmpleMessageKey.performed -= SimpleMessage;
			((UnityEvent<string>)(object)inputField.onSubmit).RemoveListener((UnityAction<string>)SendGlobalMessage);
			instance = null;
		}
	}
	public class SimpleMessageInputClass : LcInputActions
	{
		public static readonly SimpleMessageInputClass Instance = new SimpleMessageInputClass();

		public InputAction SimmpleMessageKey => ((LcInputActions)this).Asset["simplemessagekey"];

		public override void CreateInputActions(in InputActionMapBuilder builder)
		{
			builder.NewActionBinding().WithActionId("simplemessagekey").WithActionType((InputActionType)1)
				.WithKbmPath("<Keyboard>/x")
				.WithBindingName("Simple message")
				.Finish();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class SimpleMessagePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void createSimpleMessage()
		{
			Debug.Log((object)"0");
			GameObject val = Object.Instantiate<GameObject>(SimpleMessageBase.simpleMessagePrefab);
			Debug.Log((object)"1");
			val.AddComponent<SimpleMessageGO>();
			Object.DontDestroyOnLoad((Object)(object)val);
			Debug.Log((object)"2");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}