Decompiled source of ReturnToLobby v1.0.4

ReturnToLobby.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 MenuLib;
using MenuLib.MonoBehaviors;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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: AssemblyCompany("OrigamiCoder")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+597759883b39a5e5144c9fe87b2468af90b067c0")]
[assembly: AssemblyProduct("ReturnToLobby")]
[assembly: AssemblyTitle("ReturnToLobby")]
[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.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 ReturnToLobby
{
	[BepInPlugin("OrigamiCoder.ReturnToLobby", "ReturnToLobby", "1.0.4")]
	[BepInDependency("nickklmao.menulib", "2.5.3")]
	public class ReturnToLobby : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <ReturnLobbyPopupDelayed>d__26 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public ReturnToLobby <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ReturnLobbyPopupDelayed>d__26(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (!Object.op_Implicit((Object)(object)MenuManager.instance.currentMenuPage))
					{
						MenuManager.instance.PageOpen((MenuPageIndex)1, false);
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					break;
				case 2:
					<>1__state = -1;
					break;
				}
				if (!MenuManager.instance.currentMenuPage.pageActive)
				{
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				<>4__this.ReturnLobbyPopup();
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private bool IsPopupActive = false;

		internal static ReturnToLobby Instance { get; private set; }

		internal static ReturnToLobbyConfig? _config { get; set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		internal static bool IsReturningToLobby { get; set; }

		private void Awake()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			MenuAPI.AddElementToEscapeMenu((BuilderDelegate)delegate(Transform parent)
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				if (SemiFunc.IsMasterClient())
				{
					Transform val = parent.Find("Menu Button - Main Menu");
					float num = (((Object)(object)val != (Object)null) ? val.localPosition.y : 155f);
					REPOButton val2 = MenuAPI.CreateREPOButton("Lobby", (Action)ReturnLobbyPopup, parent, new Vector2(245f, num));
				}
			});
			_config = new ReturnToLobbyConfig(this);
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void ReturnLobbyPopup()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			IsPopupActive = true;
			MenuAPI.OpenPopup("Lobby", new Color(1f, 0.553f, 0f), "Return to lobby?", (Action)ReturnLobbyClick, (Action)ReturnLobbyCancel);
		}

		private void ReturnLobbyClick()
		{
			RunManager instance = RunManager.instance;
			int num = (SemiFunc.IsLevelShop(instance.levelCurrent) ? 1 : (SemiFunc.RunIsLobby() ? 2 : 0));
			instance.ChangeLevel(true, SemiFunc.RunIsArena(), (ChangeLevelType)3);
			SemiFunc.StatSetSaveLevel(num);
			instance.loadLevel = num;
			StatsManager.instance.SaveFileSave();
			IsPopupActive = false;
		}

		private void ReturnLobbyCancel()
		{
			IsPopupActive = false;
		}

		private void Update()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMasterClient() && ReturnToLobbyConfig.IsInitialized && !IsPopupActive)
			{
				KeyboardShortcut value = ReturnToLobbyConfig.KeyboardShortcut.Value;
				if (((KeyboardShortcut)(ref value)).IsDown() && !SemiFunc.MenuLevel())
				{
					((MonoBehaviour)this).StartCoroutine(ReturnLobbyPopupDelayed());
				}
			}
		}

		[IteratorStateMachine(typeof(<ReturnLobbyPopupDelayed>d__26))]
		private IEnumerator ReturnLobbyPopupDelayed()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReturnLobbyPopupDelayed>d__26(0)
			{
				<>4__this = this
			};
		}
	}
	internal class ReturnToLobbyConfig
	{
		internal static bool IsInitialized;

		internal static ConfigEntry<KeyboardShortcut> KeyboardShortcut;

		internal static ConfigEntry<KeyCode> MainKey;

		internal static ConfigEntry<KeyCode> Modifier;

		public ReturnToLobbyConfig(ReturnToLobby plugin)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut = ((BaseUnityPlugin)plugin).Config.Bind<KeyboardShortcut>("Settings", "Keyboard Shortcut", new KeyboardShortcut((KeyCode)108, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
			MainKey = ((BaseUnityPlugin)plugin).Config.Bind<KeyCode>("Settings", "MainKey", (KeyCode)108, "Keybind");
			Modifier = ((BaseUnityPlugin)plugin).Config.Bind<KeyCode>("Settings", "ModifierKey", (KeyCode)305, "Optional Modifier");
			MainKey.SettingChanged += OnSettingChanged;
			Modifier.SettingChanged += OnSettingChanged;
			IsInitialized = true;
			static void OnSettingChanged(object sender, EventArgs e)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Invalid comparison between Unknown and I4
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: 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)
				List<KeyCode> list = new List<KeyCode>();
				if ((int)Modifier.Value > 0)
				{
					list.Add(Modifier.Value);
				}
				KeyboardShortcut.Value = new KeyboardShortcut(MainKey.Value, list.ToArray());
			}
		}
	}
}