Decompiled source of RamuneCommandPauseRemade v1.0.1

Ramune.CommandPauseRemade.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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("Ramune.CommandPauseRemade")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+939d27cbfbb74394f698fca5d2ffa477c0c1689e")]
[assembly: AssemblyProduct("Ramune.CommandPauseRemade")]
[assembly: AssemblyTitle("Ramune.CommandPauseRemade")]
[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 Ramune.CommandPauseRemade
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("RamuneNeptune.Ramune.CommandPauseRemade", "Ramune.CommandPauseRemade", "1.0.1")]
	public class CommandPauseRemade : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Action<Stage> <>9__4_0;

			public static hook_OnDisplayBegin <>9__4_1;

			public static hook_OnDisplayEnd <>9__4_2;

			public static hook_Awake <>9__4_3;

			internal void <Awake>b__4_0(Stage self)
			{
				CommandPauseController.TrackedMasterInstances.Clear();
			}

			internal void <Awake>b__4_1(orig_OnDisplayBegin orig, PickupPickerController self, NetworkUIPromptController promptController, LocalUser localUser, CameraRigController cameraRigController)
			{
				orig.Invoke(self, promptController, localUser, cameraRigController);
				if (RoR2Application.isInSinglePlayer && ModConfig.EnableSingleplayer.Value)
				{
					Time.timeScale = 0f;
				}
			}

			internal void <Awake>b__4_2(orig_OnDisplayEnd orig, PickupPickerController self, NetworkUIPromptController promptController, LocalUser localUser, CameraRigController cameraRigController)
			{
				orig.Invoke(self, promptController, localUser, cameraRigController);
				if (RoR2Application.isInSinglePlayer && ModConfig.EnableSingleplayer.Value)
				{
					Time.timeScale = 1f;
				}
			}

			internal void <Awake>b__4_3(orig_Awake orig, PickupPickerController self)
			{
				orig.Invoke(self);
				if (!RoR2Application.isInSinglePlayer && NetworkServer.active && ModConfig.EnableMultiplayer.Value)
				{
					((Component)self).gameObject.AddComponent<CommandPauseController>().networkUIPromptController = self.networkUIPromptController;
				}
			}
		}

		public const string PluginGUID = "RamuneNeptune.Ramune.CommandPauseRemade";

		public const string PluginAuthor = "RamuneNeptune";

		public const string PluginName = "Ramune.CommandPauseRemade";

		public const string PluginVersion = "1.0.1";

		public void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			Stage.onStageStartGlobal += delegate
			{
				CommandPauseController.TrackedMasterInstances.Clear();
			};
			object obj = <>c.<>9__4_1;
			if (obj == null)
			{
				hook_OnDisplayBegin val = delegate(orig_OnDisplayBegin orig, PickupPickerController self, NetworkUIPromptController promptController, LocalUser localUser, CameraRigController cameraRigController)
				{
					orig.Invoke(self, promptController, localUser, cameraRigController);
					if (RoR2Application.isInSinglePlayer && ModConfig.EnableSingleplayer.Value)
					{
						Time.timeScale = 0f;
					}
				};
				<>c.<>9__4_1 = val;
				obj = (object)val;
			}
			PickupPickerController.OnDisplayBegin += (hook_OnDisplayBegin)obj;
			object obj2 = <>c.<>9__4_2;
			if (obj2 == null)
			{
				hook_OnDisplayEnd val2 = delegate(orig_OnDisplayEnd orig, PickupPickerController self, NetworkUIPromptController promptController, LocalUser localUser, CameraRigController cameraRigController)
				{
					orig.Invoke(self, promptController, localUser, cameraRigController);
					if (RoR2Application.isInSinglePlayer && ModConfig.EnableSingleplayer.Value)
					{
						Time.timeScale = 1f;
					}
				};
				<>c.<>9__4_2 = val2;
				obj2 = (object)val2;
			}
			PickupPickerController.OnDisplayEnd += (hook_OnDisplayEnd)obj2;
			object obj3 = <>c.<>9__4_3;
			if (obj3 == null)
			{
				hook_Awake val3 = delegate(orig_Awake orig, PickupPickerController self)
				{
					orig.Invoke(self);
					if (!RoR2Application.isInSinglePlayer && NetworkServer.active && ModConfig.EnableMultiplayer.Value)
					{
						((Component)self).gameObject.AddComponent<CommandPauseController>().networkUIPromptController = self.networkUIPromptController;
					}
				};
				<>c.<>9__4_3 = val3;
				obj3 = (object)val3;
			}
			PickupPickerController.Awake += (hook_Awake)obj3;
		}
	}
	public class CommandPauseController : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <StartDelay>d__8 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public CharacterMaster master;

			public int currentInstanceForMaster;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(ModConfig.ProtectionDelay.Value);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					DisableProtection(master, currentInstanceForMaster);
					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 readonly BuffDef[] PauseBuffDefs = (BuffDef[])(object)new BuffDef[4]
		{
			Buffs.HealingDisabled,
			Buffs.Immune,
			Buffs.Untargetable,
			Buffs.Entangle
		};

		public static readonly Dictionary<CharacterMaster, int> TrackedMasterInstances = new Dictionary<CharacterMaster, int>();

		public NetworkUIPromptController networkUIPromptController;

		public CharacterMaster trackedMaster;

		public void Update()
		{
			CharacterMaster val = (Object.op_Implicit((Object)(object)networkUIPromptController) ? networkUIPromptController.currentParticipantMaster : null);
			if ((Object)(object)val == (Object)(object)trackedMaster)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)trackedMaster))
			{
				CharacterBody body = trackedMaster.GetBody();
				if (body != null)
				{
					body.RemoveBuff(Buffs.Entangle);
				}
				int valueOrDefault = TrackedMasterInstances.GetValueOrDefault(trackedMaster);
				if (ModConfig.ProtectionDelay.Value > 0f)
				{
					((MonoBehaviour)RoR2Application.instance).StartCoroutine(StartDelay(trackedMaster, valueOrDefault));
				}
				else
				{
					DisableProtection(trackedMaster, valueOrDefault);
				}
			}
			trackedMaster = val;
			if (Object.op_Implicit((Object)(object)trackedMaster))
			{
				TrackedMasterInstances[trackedMaster] = TrackedMasterInstances.GetValueOrDefault(trackedMaster) + 1;
				ToggleProtection(trackedMaster, enabled: true);
			}
		}

		public void OnDestroy()
		{
			Update();
		}

		public static void ToggleProtection(CharacterMaster master, bool enabled)
		{
			if (Object.op_Implicit((Object)(object)master))
			{
				master.godMode = enabled;
				master.GetBody()?.ToggleBuffBulk(enabled, PauseBuffDefs);
			}
		}

		public static void DisableProtection(CharacterMaster master, int currentInstanceForMaster)
		{
			if (Object.op_Implicit((Object)(object)master) && TrackedMasterInstances.GetValueOrDefault(master) == currentInstanceForMaster)
			{
				ToggleProtection(master, enabled: false);
			}
		}

		[IteratorStateMachine(typeof(<StartDelay>d__8))]
		public static IEnumerator StartDelay(CharacterMaster master, int currentInstanceForMaster)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <StartDelay>d__8(0)
			{
				master = master,
				currentInstanceForMaster = currentInstanceForMaster
			};
		}
	}
	public static class ModConfig
	{
		public static ConfigEntry<bool> EnableSingleplayer { get; private set; }

		public static ConfigEntry<bool> EnableMultiplayer { get; private set; }

		public static ConfigEntry<float> ProtectionDelay { get; private set; }

		public static void Init(ConfigFile config)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			EnableSingleplayer = config.Bind<bool>("Singleplayer", "Enable Singleplayer Pausing", true, "If true, time will freeze while opening the Artifact of Command menu in singleplayer. (default: true)");
			EnableMultiplayer = config.Bind<bool>("Multiplayer", "Enable Multiplayer Protection", true, "If true, players receive protection while in the Artifact of Command menu in multiplayer. (default: true)");
			ProtectionDelay = config.Bind<float>("Multiplayer", "Protection Removal Delay", 0.85f, "The delay (in seconds) before protections are removed after closing the Command menu. (default: 0.85)");
			string path = Path.Combine(Path.GetDirectoryName(typeof(ModConfig).Assembly.Location), "icon.png");
			if (File.Exists(path))
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
				{
					((Texture)val).filterMode = (FilterMode)0;
					val.Apply();
					ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)));
				}
			}
			ModSettingsManager.SetModDescription("While opening an Artifact of Command menu, pauses the game in Singeplayer, and provides protection to players in Multiplayer (Required host-only for MP)");
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnableSingleplayer, true));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnableMultiplayer, true));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(ProtectionDelay, new StepSliderConfig
			{
				min = 0f,
				max = 10f,
				increment = 0.01f
			}));
		}
	}
	public static class Extensions
	{
		public static void ToggleBuffBulk(this CharacterBody body, bool add, params BuffDef[] buffDefs)
		{
			if (!Object.op_Implicit((Object)(object)body) || !NetworkServer.active)
			{
				return;
			}
			foreach (BuffDef val in buffDefs)
			{
				if (add)
				{
					body.AddBuff(val);
					continue;
				}
				while (body.HasBuff(val))
				{
					body.RemoveBuff(val);
				}
			}
		}
	}
	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);
		}
	}
}