Decompiled source of ESCapism v1.5.4

ESCapism/ESCapism.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
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 IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ESCapism")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4ec895757ebae4a5d8b715b5f73abc369809c2b1")]
[assembly: AssemblyProduct("ESCapism")]
[assembly: AssemblyTitle("ESCapism")]
[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 ESCapism
{
	[BepInPlugin("Hibiscus.ESCapism", "ESCapism", "1.5.4")]
	public class ESCapismPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Hibiscus.ESCapism";

		public const string PluginAuthor = "Hibiscus";

		public const string PluginName = "ESCapism";

		public const string PluginVersion = "1.5.4";

		private static List<HGButton> CancelButtons = new List<HGButton>();

		private string[] _menuButtonNames = new string[4] { "NakedButton", "NakedButton (Back)", "Button, Return", "BackButton" };

		public static ConfigEntry<bool> EnabledInGame { get; set; }

		public static ConfigEntry<bool> EnabledInMenu { get; set; }

		public void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			CreateConfig();
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				SetupRiskOfOptions();
			}
			MPEventSystem.Update += new Manipulator(HandleEventSystemUpdate);
		}

		private void CreateConfig()
		{
			EnabledInGame = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled in game", true, "If enabled, you will be able to close windows by pressing ESCAPE in game");
			EnabledInMenu = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled in menu", true, "If enabled, you will be able to close windows by pressing ESCAPE in menu");
		}

		private void SetupRiskOfOptions()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnabledInGame));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnabledInMenu));
		}

		private void HandleEventSystemUpdate(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<Console>(x, "get_instance")
			});
			ILLabel val2 = val.DefineLabel();
			val.MarkLabel(val2);
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<MPEventSystem>>((Action<MPEventSystem>)delegate
			{
				PickupPickerPanel[] array = (PickupPickerPanel[])(object)Object.FindObjectsOfType(typeof(PickupPickerPanel));
				HGPopoutPanel[] array2 = (HGPopoutPanel[])(object)Object.FindObjectsOfType(typeof(HGPopoutPanel));
				if (array.Length != 0 && EnabledInGame.Value)
				{
					FindButtonsOnPanels(array);
				}
				else if (array2.Length != 0 && EnabledInMenu.Value)
				{
					FindButtonsOnPanels(array2);
				}
				else
				{
					HGButton[] array3 = Object.FindObjectsOfType<HGButton>();
					foreach (HGButton button in array3)
					{
						if (_menuButtonNames.Any((string name) => ((Object)button).name.Equals(name)) && EnabledInMenu.Value)
						{
							CancelButtons.Add(button);
						}
					}
				}
				if (CancelButtons.Count > 0)
				{
					CloseMenu();
				}
				else
				{
					Console.instance.SubmitCmd((NetworkUser)null, "pause", false);
				}
			});
			val.Emit(OpCodes.Ret);
			ILLabel val3 = default(ILLabel);
			val.GotoPrev(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref val3)
			});
			val.Next.Operand = val2;
			val.Next.OpCode = OpCodes.Brfalse;
		}

		private void FindButtonsOnPanels<T>(T[] panels)
		{
			for (int i = 0; i < panels.Length; i++)
			{
				_ = ref panels[i];
				HGButton[] array = Object.FindObjectsOfType<HGButton>();
				foreach (HGButton val in array)
				{
					if (((Object)val).name.Equals("CancelButton"))
					{
						CancelButtons.Add(val);
					}
				}
			}
		}

		private void CloseMenu()
		{
			while (CancelButtons.Count != 0)
			{
				if (CancelButtons[0] != null)
				{
					((MPButton)CancelButtons[0]).InvokeClick();
				}
				CancelButtons.RemoveAt(0);
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}