Decompiled source of Game Close On Death v0.1.0

mods/DeathEqualsShutdown.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using DeathEqualsShutdown;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using LabFusion.Network;
using LabFusion.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
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), "DeathEqualsShutdown", "1.0.0", "CooladTheGreat", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DeathEqualsShutdown")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DeathEqualsShutdown")]
[assembly: AssemblyTitle("DeathEqualsShutdown")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DeathEqualsShutdown;

public class Class1 : MelonMod
{
	[HarmonyPatch(typeof(Player_Health), "Dying")]
	private static class DyingPatch
	{
		[HarmonyPrefix]
		private static void Postfix(Player_Health __instance)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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)
			//IL_0060: Expected O, but got Unknown
			if (IsEnabled && !NetworkInfo.HasServer)
			{
				FusionNotifier.Send(new FusionNotification
				{
					Title = NotificationText.op_Implicit("Death Warning"),
					Message = NotificationText.op_Implicit("Kill something quick, your game will close on death!"),
					ShowPopup = true,
					Type = (NotificationType)1,
					PopupLength = 4f
				});
			}
		}
	}

	[HarmonyPatch(typeof(Player_Health), "Death")]
	private static class DeathPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Player_Health __instance)
		{
			if (IsEnabled && !NetworkInfo.HasServer)
			{
				Application.Quit();
				Process.GetCurrentProcess().Kill();
			}
		}
	}

	private static bool _preferencesSetup;

	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 Page MainPage { get; private set; }

	public static BoolElement EnabledElement { get; private set; }

	public bool HasServer()
	{
		return NetworkInfo.HasServer;
	}

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

	private static void OnSetEnabled(bool value)
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Expected O, but got Unknown
		IsEnabled = value;
		MelonPrefEnabled.Value = value;
		MelonPrefCategory.SaveToFile(false);
		if (NetworkInfo.HasServer)
		{
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("Game close on death!"),
				Message = NotificationText.op_Implicit("Why would you want to enable the mod when your in a server? This is so you don't crash all the time."),
				ShowPopup = true,
				Type = (NotificationType)2,
				PopupLength = 4f
			});
		}
		else
		{
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("Game close on death!"),
				Message = NotificationText.op_Implicit(IsEnabled ? "Game close on death Enabled!" : "Game close on death disabled!"),
				ShowPopup = true,
				Type = (NotificationType)(IsEnabled ? 1 : 3),
				PopupLength = 4f
			});
		}
	}

	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("Game close on death!", Color.cyan, 0, true);
		EnabledElement = MainPage.CreateBool("Toggle Death detector!", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
	}

	public override void OnInitializeMelon()
	{
		SetupMelonPrefs();
		SetupBoneMenu();
		Hooking.OnLevelLoaded += Hooking_OnLevelLoaded;
	}

	private void Hooking_OnLevelLoaded(LevelInfo obj)
	{
		//IL_0058: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		if (NetworkInfo.HasServer)
		{
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("Game close on death!"),
				Message = NotificationText.op_Implicit("You are in a server. The mod is disabled to keep your game running."),
				ShowPopup = true,
				Type = (NotificationType)1,
				PopupLength = 4f
			});
		}
		else
		{
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("Game close on death!"),
				Message = NotificationText.op_Implicit(IsEnabled ? "Game close on death Enabled!" : "Game close on death disabled!"),
				ShowPopup = true,
				Type = (NotificationType)(IsEnabled ? 1 : 3),
				PopupLength = 4f
			});
		}
	}
}