Decompiled source of QuickQuitToMenu v1.0.1

BepInEx/plugins/Taffyko.LethalCompany.QuickQuitToMenu.dll

Decompiled 11 months 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;

[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("Taffyko.LethalCompany.QuickQuitToMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+0091fb4882ab586e2bb63b15e0253c1e008c5d60")]
[assembly: AssemblyProduct("QuickQuitToMenu")]
[assembly: AssemblyTitle("Taffyko.LethalCompany.QuickQuitToMenu")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 QuickQuitToMenu
{
	[BepInPlugin("Taffyko.LethalCompany.QuickQuitToMenu", "QuickQuitToMenu", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal const string modGUID = "Taffyko.LethalCompany.QuickQuitToMenu";

		internal const string modName = "QuickQuitToMenu";

		internal const string modVersion = "1.0.1";

		internal readonly Harmony harmony = new Harmony("Taffyko.LethalCompany.QuickQuitToMenu");

		internal static ManualLogSource log;

		internal static List<Action> cleanupActions;

		internal static ConfigEntry<Key> QuitKey;

		static Plugin()
		{
			cleanupActions = new List<Action>();
			QuitKey = null;
			log = Logger.CreateLogSource("QuickQuitToMenu");
		}

		private void Awake()
		{
			QuitKey = ((BaseUnityPlugin)this).Config.Bind<Key>("General", "QuitKey", (Key)31, "This key, (when pressed in combination with Ctrl, Shift, and Alt), will return you to the main menu.");
			log.LogInfo((object)"Loading Taffyko.LethalCompany.QuickQuitToMenu");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		private void OnDestroy()
		{
		}
	}
	public class QuickQuitToMenuBehaviour : MonoBehaviour
	{
		internal static QuickQuitToMenuBehaviour? instance;

		private static bool pressedNow;

		internal int tries;

		private void Update()
		{
			HandleHotkey();
		}

		public void HandleHotkey()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			if (InputControlExtensions.IsPressed((InputControl)(object)Keyboard.current.ctrlKey, 0f) && InputControlExtensions.IsPressed((InputControl)(object)Keyboard.current.altKey, 0f) && InputControlExtensions.IsPressed((InputControl)(object)Keyboard.current.shiftKey, 0f))
			{
				KeyControl val = ((IEnumerable<KeyControl>)(object)Keyboard.current.allKeys).FirstOrDefault((Func<KeyControl, bool>)((KeyControl key) => key.keyCode == Plugin.QuitKey.Value));
				if (val != null && InputControlExtensions.IsPressed((InputControl)(object)val, 0f))
				{
					if (!pressedNow)
					{
						Plugin.log.LogInfo((object)"QuickQuitToMenu hotkey pressed");
						if (tries < 5 && NetworkManager.Singleton.IsConnectedClient)
						{
							Scene activeScene = SceneManager.GetActiveScene();
							if (((Scene)(ref activeScene)).name != "MainMenu")
							{
								GameNetworkManager obj = GameNetworkManager.Instance;
								if (obj != null)
								{
									obj.Disconnect();
								}
								tries++;
								Plugin.log.LogInfo((object)$"Attempting disconnect (try {tries}/5)");
								goto IL_017f;
							}
						}
						tries = 0;
						Plugin.log.LogInfo((object)"Returning to title screen");
						if ((Object)(object)GameNetworkManager.Instance != (Object)null)
						{
							try
							{
								NetworkManager.Singleton.Shutdown(false);
							}
							catch
							{
							}
							typeof(GameNetworkManager).GetMethod("ResetGameValuesToDefault", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(GameNetworkManager.Instance, new object[0]);
						}
						SceneManager.LoadScene("MainMenu");
					}
					goto IL_017f;
				}
				pressedNow = false;
				return;
			}
			pressedNow = false;
			return;
			IL_017f:
			pressedNow = true;
		}
	}
	[HarmonyPatch]
	internal class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuManager), "Awake")]
		public static void MenuAwake(MenuManager __instance)
		{
			EnsureInstance();
			QuickQuitToMenuBehaviour.instance.tries = 0;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuManager), "Update")]
		public static void MenuUpdate(MenuManager __instance)
		{
			EnsureInstance();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "LateUpdate")]
		public static void GameUpdate(StartOfRound __instance)
		{
			EnsureInstance();
		}

		public static void EnsureInstance()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if ((Object)(object)QuickQuitToMenuBehaviour.instance == (Object)null)
			{
				GameObject val = new GameObject("QuickQuitToMenuBehaviour");
				QuickQuitToMenuBehaviour.instance = val.AddComponent<QuickQuitToMenuBehaviour>();
				Object.DontDestroyOnLoad((Object)val);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Taffyko.LethalCompany.QuickQuitToMenu";

		public const string PLUGIN_NAME = "QuickQuitToMenu";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}