Decompiled source of God Mode FIXED v0.2.0

Mods/Godmodebonelab.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 Godmodebonelab;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using LabFusion.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
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(GodModeMod), "Godmode", "1.0.0", "CooladTheGreat", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyDescription("Makes your player unkillable")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Godmodebonelab")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Godmodebonelab")]
[assembly: AssemblyTitle("Godmodebonelab")]
[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 Godmodebonelab
{
	public class GodModeMod : MelonMod
	{
		[HarmonyPatch(typeof(Player_Health), "TAKEDAMAGE")]
		private static class TakeDamagePatch
		{
			private static bool Prefix(ref float damage)
			{
				if (IsEnabled && !joinedserver)
				{
					damage = 0f;
					return false;
				}
				return true;
			}
		}

		public const string Version = "1.2.1";

		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 bool joinedserver { get; private set; }

		public static Page MainPage { get; private set; }

		public static BoolElement EnabledElement { get; private set; }

		public override void OnInitializeMelon()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			SetupMelonPrefs();
			SetupBoneMenu();
			try
			{
				((MelonBase)this).HarmonyInstance.PatchAll();
				MelonLogger.Msg("Harmony patches applied successfully.");
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Failed to apply Harmony patches: {value}");
			}
			joinedserver = false;
			Hooking.OnLevelLoaded += OnLevelLoaded;
			MultiplayerHooking.OnJoinServer += new ServerEvent(MultiplayerHooking_OnJoinServer);
			MultiplayerHooking.OnDisconnect += new ServerEvent(MultiplayerHooking_OnDisconnect);
		}

		private void MultiplayerHooking_OnDisconnect()
		{
			joinedserver = false;
		}

		private void MultiplayerHooking_OnJoinServer()
		{
			joinedserver = true;
		}

		private static void SetupMelonPrefs()
		{
			MelonPrefCategory = MelonPreferences.CreateCategory("GodMode");
			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("God Mode", Color.cyan, 0, true);
			EnabledElement = MainPage.CreateBool("Toggle God Mode", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
		}

		private static void OnSetEnabled(bool value)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0066: Expected O, but got Unknown
			//IL_0095: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			IsEnabled = value;
			MelonPrefEnabled.Value = value;
			MelonPrefCategory.SaveToFile(false);
			if (joinedserver)
			{
				FusionNotifier.Send(new FusionNotification
				{
					Title = NotificationText.op_Implicit("God Mode"),
					Message = NotificationText.op_Implicit("You have joined a server! Godmode is OFF!"),
					ShowPopup = true,
					Type = (NotificationType)3
				});
			}
			else
			{
				FusionNotifier.Send(new FusionNotification
				{
					Title = NotificationText.op_Implicit("God Mode"),
					Message = NotificationText.op_Implicit(IsEnabled ? "God mode enabled!" : "God mode disabled!"),
					ShowPopup = true,
					Type = (NotificationType)3
				});
			}
		}

		private void OnLevelLoaded(LevelInfo levelInfo)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//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_0054: Expected O, but got Unknown
			if (IsEnabled)
			{
				if (joinedserver)
				{
					FusionNotifier.Send(new FusionNotification
					{
						Title = NotificationText.op_Implicit("God Mode"),
						Message = NotificationText.op_Implicit("You have joined a server! Godmode is OFF!"),
						ShowPopup = true,
						Type = (NotificationType)3
					});
				}
				else
				{
					FusionNotifier.Send(new FusionNotification
					{
						Title = NotificationText.op_Implicit("God Mode Active"),
						Message = NotificationText.op_Implicit("You are invincible! Made by CooladTheGreat!"),
						ShowPopup = true,
						Type = (NotificationType)3
					});
				}
			}
		}
	}
}