Decompiled source of SingleplayerPause v1.1.1

BepInEx/plugins/SingleplayerPause.dll

Decompiled 2 months 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.Logging;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SingleplayerPause")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0")]
[assembly: AssemblyProduct("SingleplayerPause")]
[assembly: AssemblyTitle("SingleplayerPause")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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;
		}
	}
}
[BepInPlugin("com.yourname.pausemenu.mod", "SingleplayerPauseMod", "1.1.0")]
public class SingleplayerPauseMod : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <DelayedPause>d__6 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public float delay;

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

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

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

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

		private bool MoveNext()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSecondsRealtime(delay);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)Menu.Instance != (Object)null && Menu.Instance.IsOpen && IsSingleplayer())
				{
					Time.timeScale = 0f;
					AudioListener.pause = true;
					Cursor.lockState = (CursorLockMode)0;
					wasPaused = true;
				}
				pauseCoroutine = null;
				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();
		}
	}

	[CompilerGenerated]
	private sealed class <ResumeAfterInput>d__7 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public float delay;

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

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

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

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

		private bool MoveNext()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSecondsRealtime(delay);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)Menu.Instance != (Object)null && Menu.Instance.IsOpen && IsSingleplayer())
				{
					Time.timeScale = 0f;
					AudioListener.pause = true;
					Cursor.lockState = (CursorLockMode)0;
				}
				else
				{
					wasPaused = false;
				}
				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();
		}
	}

	public static ManualLogSource LoggerInstance;

	private static bool menuWasOpen;

	private static bool wasPaused;

	private static Coroutine pauseCoroutine;

	private void Awake()
	{
		LoggerInstance = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"SingleplayerPauseMod loaded!");
	}

	private void Update()
	{
		if ((Object)(object)Menu.Instance == (Object)null)
		{
			return;
		}
		bool isOpen = Menu.Instance.IsOpen;
		bool isHub = LevelData.IsHub;
		bool flag = IsSingleplayer();
		if (wasPaused && flag && !isHub && Keyboard.current != null && (((ButtonControl)Keyboard.current.escapeKey).wasPressedThisFrame || ((ButtonControl)Keyboard.current.tabKey).wasPressedThisFrame))
		{
			Time.timeScale = 1f;
			AudioListener.pause = false;
			((MonoBehaviour)this).StartCoroutine(ResumeAfterInput(0.5f));
		}
		if (wasPaused && !flag)
		{
			Time.timeScale = 1f;
			AudioListener.pause = false;
			wasPaused = false;
			if (pauseCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(pauseCoroutine);
				pauseCoroutine = null;
			}
		}
		if (!isHub)
		{
			if (isOpen && !menuWasOpen && flag && !wasPaused)
			{
				if (pauseCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(pauseCoroutine);
				}
				pauseCoroutine = ((MonoBehaviour)this).StartCoroutine(DelayedPause(1f));
			}
			else if (!isOpen && menuWasOpen && flag && wasPaused)
			{
				Time.timeScale = 1f;
				AudioListener.pause = false;
				Cursor.lockState = (CursorLockMode)1;
				wasPaused = false;
				if (pauseCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(pauseCoroutine);
					pauseCoroutine = null;
				}
			}
		}
		menuWasOpen = isOpen;
	}

	[IteratorStateMachine(typeof(<DelayedPause>d__6))]
	private IEnumerator DelayedPause(float delay)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DelayedPause>d__6(0)
		{
			delay = delay
		};
	}

	[IteratorStateMachine(typeof(<ResumeAfterInput>d__7))]
	private IEnumerator ResumeAfterInput(float delay)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ResumeAfterInput>d__7(0)
		{
			delay = delay
		};
	}

	private static bool IsSingleplayer()
	{
		if ((Object)(object)NetworkManager.Singleton != (Object)null)
		{
			return NetworkManager.Singleton.ConnectedClients.Count <= 1;
		}
		if ((Object)(object)GameManager.Instance != (Object)null)
		{
			return GameManager.players.Count <= 1;
		}
		return true;
	}
}
namespace SingleplayerPause
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SingleplayerPause";

		public const string PLUGIN_NAME = "SingleplayerPause";

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