Decompiled source of ChatMacros v1.2.2

plugins/Marioalexsan.ChatMacros.dll

Decompiled a month 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 BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Nessie.ATLYSS.EasySettings;
using Nessie.ATLYSS.EasySettings.UIElements;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Marioalexsan.ChatMacros")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2+73366e2c1bfde8bd85bf4353f5c35f19aefa83ac")]
[assembly: AssemblyProduct("ChatMacros")]
[assembly: AssemblyTitle("Marioalexsan.ChatMacros")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.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.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;
		}
	}
	[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 Marioalexsan.ChatMacros
{
	[HarmonyPatch(typeof(ChatBehaviour), "Send_ChatMessage")]
	internal static class DisableReturnRequirement
	{
		internal static bool SkipReturnCheck { get; set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction x) => CodeInstructionExtensions.Calls(x, AccessTools.Method(typeof(Input), "GetKeyDown", new Type[1] { typeof(KeyCode) }, (Type[])null))), (string)null)
			});
			if (!val.IsValid)
			{
				throw new InvalidOperationException("Couldn't patch Send_ChatMessage! Please notify the mod developer about this!");
			}
			val.Set(OpCodes.Call, (object)AccessTools.Method(typeof(DisableReturnRequirement), "GetKeyDownMixin", (Type[])null, (Type[])null));
			return val.InstructionEnumeration();
		}

		private static bool GetKeyDownMixin(KeyCode code)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (SkipReturnCheck && (int)code == 13)
			{
				return true;
			}
			return Input.GetKeyDown(code);
		}
	}
	[BepInPlugin("Marioalexsan.ChatMacros", "ChatMacros", "1.2.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ChatMacros : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__41_1;

			internal void <Awake>b__41_1()
			{
				SettingsTab orAddCustomTab = Settings.GetOrAddCustomTab("ChatMacros");
				orAddCustomTab.AddToggle("Enabled", Enabled);
				orAddCustomTab.AddToggle("Enable Alt Macros", EnableAltMacros);
				orAddCustomTab.AddToggle("Enable Ctrl Macros", EnableCtrlMacros);
				for (int i = 0; i < MacroButtons.Count; i++)
				{
					orAddCustomTab.AddTextField($"Macro {i + 1}", MacroTexts[i], "Text...");
					_altTextOptions.Add(((Component)((BaseAtlyssElement)orAddCustomTab.AddTextField($"Macro {i + 1} + Alt", MacroAltTexts[i], "Text...")).Root).gameObject);
					_ctrlTextOptions.Add(((Component)((BaseAtlyssElement)orAddCustomTab.AddTextField($"Macro {i + 1} + Ctrl", MacroCtrlTexts[i], "Text...")).Root).gameObject);
					orAddCustomTab.AddKeyButton($"Macro {i + 1} Button", MacroButtons[i]);
				}
			}
		}

		private static ChatMacros? _plugin;

		private readonly Harmony _harmony = new Harmony("Marioalexsan.ChatMacros");

		private static readonly List<GameObject> _altTextOptions = new List<GameObject>();

		private static readonly List<GameObject> _ctrlTextOptions = new List<GameObject>();

		private static readonly Queue<string> _queuedCommands = new Queue<string>();

		private static DateTime _lastCommandAt = DateTime.Now;

		public static ChatMacros Plugin => _plugin ?? throw new InvalidOperationException("ChatMacros hasn't been initialized yet. Either wait until initialization, or check via ChainLoader instead.");

		internal ManualLogSource Logger { get; private set; }

		public static ConfigEntry<bool> Enabled { get; private set; } = null;


		public static ConfigEntry<bool> EnableAltMacros { get; private set; } = null;


		public static ConfigEntry<bool> EnableCtrlMacros { get; private set; } = null;


		public static List<ConfigEntry<string>> MacroTexts { get; private set; } = new List<ConfigEntry<string>>();


		public static List<ConfigEntry<string>> MacroAltTexts { get; private set; } = new List<ConfigEntry<string>>();


		public static List<ConfigEntry<string>> MacroCtrlTexts { get; private set; } = new List<ConfigEntry<string>>();


		public static List<ConfigEntry<KeyCode>> MacroButtons { get; private set; } = new List<ConfigEntry<KeyCode>>();


		public ChatMacros()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected I4, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			_plugin = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll();
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable all keybindings for this mod");
			EnableAltMacros = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableAltMacros", false, "Enables usage of Alt + Macro combinations");
			EnableCtrlMacros = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableCtrlMacros", false, "Enables usage of Ctrl + Macro combinations");
			for (KeyCode val = (KeyCode)257; (int)val <= 265; val = (KeyCode)(val + 1))
			{
				int num = val - 257 + 1;
				MacroTexts.Add(((BaseUnityPlugin)this).Config.Bind<string>("MacroTexts", $"Macro{num}", "", $"Chat message or command to send when Macro {num} is triggered"));
				MacroAltTexts.Add(((BaseUnityPlugin)this).Config.Bind<string>("MacroTexts", $"Macro{num}Alt", "", $"Chat message or command to send when Macro {num} is triggered in combination with Alt"));
				MacroCtrlTexts.Add(((BaseUnityPlugin)this).Config.Bind<string>("MacroTexts", $"Macro{num}Ctrl", "", $"Chat message or command to send when Macro {num} is triggered in combination with Ctrl"));
				MacroButtons.Add(((BaseUnityPlugin)this).Config.Bind<KeyCode>("MacroBindings", $"Macro{num}Button", val, $"Button to press to trigger Macro {num}"));
			}
		}

		public void Awake()
		{
			if (Chainloader.PluginInfos.ContainsKey("EasySettings"))
			{
				SetupEasySettings();
			}
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			void SetupEasySettings()
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Expected O, but got Unknown
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Expected O, but got Unknown
				UnityEvent onInitialized = Settings.OnInitialized;
				object obj = <>c.<>9__41_1;
				if (obj == null)
				{
					UnityAction val = delegate
					{
						SettingsTab orAddCustomTab = Settings.GetOrAddCustomTab("ChatMacros");
						orAddCustomTab.AddToggle("Enabled", Enabled);
						orAddCustomTab.AddToggle("Enable Alt Macros", EnableAltMacros);
						orAddCustomTab.AddToggle("Enable Ctrl Macros", EnableCtrlMacros);
						for (int i = 0; i < MacroButtons.Count; i++)
						{
							orAddCustomTab.AddTextField($"Macro {i + 1}", MacroTexts[i], "Text...");
							_altTextOptions.Add(((Component)((BaseAtlyssElement)orAddCustomTab.AddTextField($"Macro {i + 1} + Alt", MacroAltTexts[i], "Text...")).Root).gameObject);
							_ctrlTextOptions.Add(((Component)((BaseAtlyssElement)orAddCustomTab.AddTextField($"Macro {i + 1} + Ctrl", MacroCtrlTexts[i], "Text...")).Root).gameObject);
							orAddCustomTab.AddKeyButton($"Macro {i + 1} Button", MacroButtons[i]);
						}
					};
					<>c.<>9__41_1 = val;
					obj = (object)val;
				}
				onInitialized.AddListener((UnityAction)obj);
				Settings.OnApplySettings.AddListener((UnityAction)delegate
				{
					((BaseUnityPlugin)this).Config.Save();
				});
			}
		}

		public void Update()
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _altTextOptions.Count; i++)
			{
				_altTextOptions[i].SetActive(EnableAltMacros.Value);
			}
			for (int j = 0; j < _ctrlTextOptions.Count; j++)
			{
				_ctrlTextOptions[j].SetActive(EnableCtrlMacros.Value);
			}
			bool flag = Enabled.Value && Object.op_Implicit((Object)(object)ChatBehaviour._current) && !ChatBehaviour._current._focusedInChat && (!Object.op_Implicit((Object)(object)SettingsManager._current) || !SettingsManager._current._isOpen) && (Object)(object)EventSystem.current.currentSelectedGameObject == (Object)null;
			if (_lastCommandAt + TimeSpan.FromMilliseconds(100.0) <= DateTime.Now && _queuedCommands.Count > 0)
			{
				_lastCommandAt = DateTime.Now;
				SendMacro(_queuedCommands.Dequeue());
			}
			if (!flag)
			{
				return;
			}
			int num = -1;
			for (int k = 0; k < MacroButtons.Count; k++)
			{
				if (Input.GetKeyDown(MacroButtons[k].Value))
				{
					num = k;
					break;
				}
			}
			if (num == -1)
			{
				return;
			}
			string text = ((EnableAltMacros.Value && (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307))) ? MacroAltTexts[num].Value : ((!EnableCtrlMacros.Value || (!Input.GetKey((KeyCode)306) && !Input.GetKey((KeyCode)305))) ? MacroTexts[num].Value : MacroCtrlTexts[num].Value));
			if (!string.IsNullOrWhiteSpace(text))
			{
				string[] array = text.Split("&&", StringSplitOptions.RemoveEmptyEntries);
				for (int l = 0; l < array.Length; l++)
				{
					_queuedCommands.Enqueue(array[l].Trim().Replace("&amp;", "&"));
				}
			}
		}

		private static void SendMacro(string targetText)
		{
			if (!Object.op_Implicit((Object)(object)ChatBehaviour._current))
			{
				return;
			}
			try
			{
				DisableReturnRequirement.SkipReturnCheck = true;
				ChatBehaviour._current.Send_ChatMessage(targetText);
			}
			finally
			{
				DisableReturnRequirement.SkipReturnCheck = false;
			}
		}
	}
	internal static class Logging
	{
		private static ManualLogSource InternalLogger => ChatMacros.Plugin.Logger;

		public static void LogFatal(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)1, toggle);
		}

		public static void LogError(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)2, toggle);
		}

		public static void LogWarning(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)4, toggle);
		}

		public static void LogMessage(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)8, toggle);
		}

		public static void LogInfo(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)16, toggle);
		}

		public static void LogDebug(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)32, toggle);
		}

		private static void Log(object data, LogLevel level = 16, ConfigEntry<bool>? toggle = null)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (toggle == null || toggle.Value)
			{
				ManualLogSource internalLogger = InternalLogger;
				if (internalLogger != null)
				{
					internalLogger.Log(level, data);
				}
			}
		}
	}
	internal static class ModInfo
	{
		public const string GUID = "Marioalexsan.ChatMacros";

		public const string NAME = "ChatMacros";

		public const string VERSION = "1.2.2";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}