Decompiled source of ChatMacros v1.2.1

plugins/Marioalexsan.ChatMacros.dll

Decompiled a week 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 Marioalexsan.ChatMacros.SoftDependencies;
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.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1+1f5d96a509a6f85bf9e53ac7e9dab34ff6e00095")]
[assembly: AssemblyProduct("ChatMacros")]
[assembly: AssemblyTitle("Marioalexsan.ChatMacros")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.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.1")]
	[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_0;

			internal void <Awake>b__41_0()
			{
				EasySettings.AddHeader("ChatMacros");
				EasySettings.AddToggle("Enabled", Enabled);
				EasySettings.AddToggle("Enable Alt Macros", EnableAltMacros);
				EasySettings.AddToggle("Enable Ctrl Macros", EnableCtrlMacros);
				for (int i = 0; i < MacroButtons.Count; i++)
				{
					EasySettings.AddTextField($"Macro {i + 1}", MacroTexts[i]);
					_altTextOptions.Add(EasySettings.AddTextField($"Macro {i + 1} + Alt", MacroAltTexts[i]));
					_ctrlTextOptions.Add(EasySettings.AddTextField($"Macro {i + 1} + Ctrl", MacroCtrlTexts[i]));
					EasySettings.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()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (!EasySettings.IsAvailable)
			{
				return;
			}
			UnityEvent onInitialized = EasySettings.OnInitialized;
			object obj = <>c.<>9__41_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					EasySettings.AddHeader("ChatMacros");
					EasySettings.AddToggle("Enabled", Enabled);
					EasySettings.AddToggle("Enable Alt Macros", EnableAltMacros);
					EasySettings.AddToggle("Enable Ctrl Macros", EnableCtrlMacros);
					for (int i = 0; i < MacroButtons.Count; i++)
					{
						EasySettings.AddTextField($"Macro {i + 1}", MacroTexts[i]);
						_altTextOptions.Add(EasySettings.AddTextField($"Macro {i + 1} + Alt", MacroAltTexts[i]));
						_ctrlTextOptions.Add(EasySettings.AddTextField($"Macro {i + 1} + Ctrl", MacroCtrlTexts[i]));
						EasySettings.AddKeyButton($"Macro {i + 1} Button", MacroButtons[i]);
					}
				};
				<>c.<>9__41_0 = val;
				obj = (object)val;
			}
			onInitialized.AddListener((UnityAction)obj);
			EasySettings.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.1";
	}
}
namespace Marioalexsan.ChatMacros.SoftDependencies
{
	public static class EasySettings
	{
		private const MethodImplOptions SoftDepend = MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization;

		public const string ModID = "EasySettings";

		public static readonly Version ExpectedVersion = new Version("1.2.0");

		private static BaseUnityPlugin? _plugin;

		private static bool _initialized;

		private static bool _warnedAboutTextFields = false;

		public static Version CurrentVersion { get; private set; } = new Version("1.2.0");


		public static bool IsAvailable
		{
			get
			{
				if (!_initialized)
				{
					_plugin = (Chainloader.PluginInfos.TryGetValue("EasySettings", out var value) ? value.Instance : null);
					_initialized = true;
					if ((Object)(object)_plugin == (Object)null)
					{
						Logging.LogWarning("Soft dependency EasySettings was not found.");
					}
					else if (_plugin.Info.Metadata.Version != ExpectedVersion)
					{
						CurrentVersion = _plugin.Info.Metadata.Version;
						Logging.LogWarning(string.Format("Soft dependency {0} has a different version than expected (have: {1}, expect: {2}).", "EasySettings", _plugin.Info.Metadata.Version, ExpectedVersion));
					}
				}
				return (Object)(object)_plugin != (Object)null;
			}
		}

		public static UnityEvent OnInitialized
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnInitialized;
			}
		}

		public static UnityEvent OnCancelSettings
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnCancelSettings;
			}
		}

		public static UnityEvent OnApplySettings
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnApplySettings;
			}
		}

		public static UnityEvent OnCloseSettings
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnCloseSettings;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddSpace()
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddSpace()).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddHeader(string label)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddHeader(label)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddButton(string buttonLabel, UnityAction onClick)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddButton(buttonLabel, onClick)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddToggle(string label, ConfigEntry<bool> config)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddToggle(label, config)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddSlider(string label, ConfigEntry<float> config, bool wholeNumbers = false)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddSlider(label, config, wholeNumbers)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddAdvancedSlider(string label, ConfigEntry<float> config, bool wholeNumbers = false)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddAdvancedSlider(label, config, wholeNumbers)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddDropdown<T>(string label, ConfigEntry<T> config) where T : Enum
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddDropdown<T>(label, config)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddKeyButton(string label, ConfigEntry<KeyCode> config)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddKeyButton(label, config)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddTextField(string label, ConfigEntry<string> config, string preset = "Text...")
		{
			if (CurrentVersion < new Version(1, 2, 0))
			{
				if (!_warnedAboutTextFields)
				{
					_warnedAboutTextFields = true;
					Logging.LogWarning($"EasySettings text fields are not supported in version {CurrentVersion} (need {new Version(1, 2, 0)})");
					Logging.LogWarning("This means that this mod won't be able to initialize text field settings, so you may have some missing stuff.");
					Logging.LogWarning("Please update EasySettings or edit the configuration manually instead.");
				}
				return null;
			}
			return AddTextFieldInternal(label, config, preset);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static GameObject AddTextFieldInternal(string label, ConfigEntry<string> config, string preset = "Text...")
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			string value = config.Value;
			AtlyssTextField val = Settings.ModTab.AddTextField(label, config, preset);
			val.InputField.characterLimit = 0;
			val.InputField.SetTextWithoutNotify(value);
			val.Apply();
			RectTransform component = ((Component)val.InputField).GetComponent<RectTransform>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.SetInsetAndSizeFromParentEdge((Edge)1, 10f, component.sizeDelta.x * 1.5f);
			}
			return ((Component)((BaseAtlyssElement)val).Root).gameObject;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}