Decompiled source of Random game closer v0.1.0

mods/Random game closing.dll

Decompiled 5 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 BoneLib;
using BoneLib.BoneMenu;
using LabFusion.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Random_game_closing;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Class1), "Random game closer!", "1.0.0", "CooladTheGreat", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyDescription("Randomly closes your game!")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Random game closing")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Random game closing")]
[assembly: AssemblyTitle("Random game closing")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace Random_game_closing
{
	public class Class1 : MelonMod
	{
		[CompilerGenerated]
		private sealed class <GameCloseTimer>d__37 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Class1 <>4__this;

			private int <roll>5__1;

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

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

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

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

			private bool MoveNext()
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e8: Expected O, but got Unknown
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Expected O, but got Unknown
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					if (IsEnabled && isloaded)
					{
						<roll>5__1 = <>4__this.random.Next(1, 20);
						if (<roll>5__1 == 5)
						{
							FusionNotifier.Send(new FusionNotification
							{
								Title = NotificationText.op_Implicit("BONELAB"),
								Message = NotificationText.op_Implicit($"You got unlucky! Number picked: {<roll>5__1}"),
								ShowPopup = true,
								Type = (NotificationType)2,
								PopupLength = 4f
							});
							<>2__current = (object)new WaitForSecondsRealtime(5f);
							<>1__state = 2;
							return true;
						}
						FusionNotifier.Send(new FusionNotification
						{
							Title = NotificationText.op_Implicit("BONELAB"),
							Message = NotificationText.op_Implicit($"Too close! The number picked was: {<roll>5__1}"),
							ShowPopup = true,
							Type = (NotificationType)3,
							PopupLength = 4f
						});
					}
					break;
				case 2:
					<>1__state = -1;
					MelonLogger.Msg($"Closing game! (Rolled: {<roll>5__1})");
					Application.Quit();
					Process.GetCurrentProcess().Kill();
					break;
				}
				<>2__current = (object)new WaitForSecondsRealtime(30f);
				<>1__state = 1;
				return true;
			}

			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 const string Version = "1.2.1";

		private static bool _preferencesSetup;

		private Random random = new Random();

		public static MelonPreferences_Category MelonPrefCategory { get; private set; }

		public static MelonPreferences_Entry<bool> MelonPrefEnabled { get; private set; }

		public static bool IsEnabled { get; private set; }

		public static bool isloaded { get; private set; }

		public static bool joinedserver { get; private set; }

		public static Page MainPage { get; private set; }

		public static BoolElement EnabledElement { get; private set; }

		public override void OnInitializeMelon()
		{
			SetupMelonPrefs();
			SetupBoneMenu();
			MelonLogger.Msg("Random Game Closer loaded! The game may close at any time...");
			StartCoroutine(GameCloseTimer());
			Hooking.OnLevelUnloaded += Hooking_OnLevelUnloaded;
			Hooking.OnLevelLoaded += Hooking_OnLevelLoaded;
		}

		private static void SetupMelonPrefs()
		{
			MelonPrefCategory = MelonPreferences.CreateCategory("Game closer");
			MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			IsEnabled = MelonPrefEnabled.Value;
			_preferencesSetup = true;
		}

		private static void SetupBoneMenu()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			MainPage = Page.Root.CreatePage("Random game closer!", Color.cyan, 0, true);
			EnabledElement = MainPage.CreateBool("Toggle Game closer!", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
		}

		private static void OnSetEnabled(bool value)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			IsEnabled = value;
			MelonPrefEnabled.Value = value;
			MelonPrefCategory.SaveToFile(false);
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("Game closer!"),
				Message = NotificationText.op_Implicit(IsEnabled ? "Game closer enabled!" : "Game closer disabled!"),
				ShowPopup = true,
				Type = (NotificationType)3,
				PopupLength = 4f
			});
		}

		private void Hooking_OnLevelLoaded(LevelInfo obj)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			isloaded = true;
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("BONELAB"),
				Message = NotificationText.op_Implicit(IsEnabled ? "Game closer is enabled!" : "Game closer is disabled!"),
				ShowPopup = true,
				Type = (NotificationType)(IsEnabled ? 1 : 3),
				PopupLength = 4f
			});
		}

		private void Hooking_OnLevelUnloaded()
		{
			isloaded = false;
		}

		[IteratorStateMachine(typeof(<GameCloseTimer>d__37))]
		private IEnumerator GameCloseTimer()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GameCloseTimer>d__37(0)
			{
				<>4__this = this
			};
		}

		private void StartCoroutine(IEnumerator routine)
		{
			MelonCoroutines.Start(routine);
		}
	}
}