Decompiled source of PauseButton v1.0.0

NGA.PauseButton.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Sodalite;
using Sodalite.Api;
using Sodalite.ModPanel;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("NGA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Persistent player progression! Raid, stash loot, and deploy with seemless scene/loadout saving.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("NGA.PauseButton")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace NGA
{
	[BepInPlugin("NGA.PauseButton", "PauseButton", "0.0.1")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInProcess("h3vr.exe")]
	public class PauseButton : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FVRWristMenu2))]
		[HarmonyPatch("Awake")]
		private class WristMenuAwakeHook
		{
			private static void Postfix(FVRWristMenu2 __instance)
			{
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Expected O, but got Unknown
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Expected O, but got Unknown
				if ((Object)(object)__instance == (Object)null)
				{
					Logger.LogMessage((object)"FVRWristMenu2 is null!?");
				}
				bool flag = false;
				string text = "Pause/Play";
				foreach (WristMenuButton button in WristMenuAPI.Buttons)
				{
					if (button.Text == text)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					WristMenuAPI.Buttons.Add(new WristMenuButton(text, int.MaxValue, new ButtonClickEvent(TogglePause)));
				}
			}
		}

		[HarmonyPatch(typeof(FVRViveHand))]
		[HarmonyPatch("EnableWristMenu")]
		private class FVRViveHandEnableWristMenuHook
		{
			private static void Postfix(FVRViveHand __instance)
			{
				if (!game_paused_now)
				{
					SlowDownTime(WristSlow.Value);
				}
			}
		}

		[HarmonyPatch(typeof(FVRViveHand))]
		[HarmonyPatch("DisableWristMenu")]
		private class FVRViveHandDisableWristMenuHook
		{
			private static void Postfix(FVRViveHand __instance)
			{
				if (!game_paused_now)
				{
					SpeedUpTime();
				}
			}
		}

		private static ConfigEntry<bool> GameEnabled;

		private static ConfigEntry<float> WristSlow;

		private static bool game_paused_now = false;

		public static float technically_not_zero = 1E-10f;

		private static readonly float s_fixedDeltaTime = Time.fixedDeltaTime;

		private FVRSceneSettings _currentSceneSettingsPtr = null;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("NGA.PauseButton");
			Logger.LogMessage((object)"New harmony");
			SetUpConfigFields();
			Logger.LogMessage((object)"Setted the fields");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from NGA.PauseButton 0.0.1");
		}

		public void Update()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			if ((Object)(object)GM.CurrentSceneSettings != (Object)null && (Object)(object)GM.CurrentSceneSettings != (Object)(object)_currentSceneSettingsPtr)
			{
				_currentSceneSettingsPtr = GM.CurrentSceneSettings;
				GM.CurrentSceneSettings.PlayerDeathEvent -= new PlayerDeath(DisablePauseOnDeath);
				GM.CurrentSceneSettings.PlayerDeathEvent += new PlayerDeath(DisablePauseOnDeath);
			}
		}

		private void SetUpConfigFields()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			GameEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Overall", "ON/OFF", true, "Disables all code execution by this mod.");
			WristSlow = ((BaseUnityPlugin)this).Config.Bind<float>("Overall", "Slow-down Percent in Menu", 1f, new ConfigDescription("How much time slows down when wrist menu is active. Set 1 for off.", (AcceptableValueBase)new AcceptableValueFloatRangeStep(0.05f, 1f, 0.05f), new object[0]));
		}

		private static bool CheckSkip()
		{
			return !GameEnabled.Value;
		}

		public static void TogglePause(object sender, ButtonClickEventArgs args)
		{
			if (game_paused_now)
			{
				SpeedUpTime();
				game_paused_now = false;
			}
			else
			{
				SlowDownTime();
				game_paused_now = true;
			}
		}

		private void DisablePauseOnDeath(bool killedSelf = false)
		{
			SpeedUpTime();
		}

		public static void SpeedUpTime()
		{
			ChangeTimeScale(1f);
		}

		public static void SlowDownTime(float f = 0f)
		{
			ChangeTimeScale(f);
		}

		public static void ChangeTimeScale(float scale)
		{
			Time.timeScale = Mathf.Clamp(scale, technically_not_zero, 1f);
			Time.fixedDeltaTime = Time.timeScale * s_fixedDeltaTime;
		}
	}
}