Decompiled source of Inf Health v1.0.0

Mods/InfHealth.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using InfHealth;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Inf Health", "1.0.0", "imebruhh", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("InfHealth")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InfHealth")]
[assembly: AssemblyTitle("InfHealth")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 InfHealth
{
	public class Core : MelonMod
	{
		public static volatile bool Enabled;

		private static MelonPreferences_Category _prefs;

		private static MelonPreferences_Entry<bool> _enabledPref;

		public override void OnInitializeMelon()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			_prefs = MelonPreferences.CreateCategory("InfHealth");
			_enabledPref = _prefs.CreateEntry<bool>("Enabled", false, "Inf Health enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			Enabled = _enabledPref.Value;
			Page.Root.CreatePage("Inf Health", Color.red, 0, true).CreateBool("Inf Health", Color.green, Enabled, (Action<bool>)OnToggle);
			((MelonBase)this).LoggerInstance.Msg("Inf Health loaded. Currently " + (Enabled ? "ON" : "OFF") + ".");
		}

		private static void OnToggle(bool value)
		{
			Enabled = value;
			_enabledPref.Value = value;
			MelonPreferences.Save();
			Health playerHealth = GetPlayerHealth();
			if (!((Object)(object)playerHealth == (Object)null))
			{
				if (value)
				{
					playerHealth.SetHealthMode(0);
					playerHealth.SetFullHealth();
				}
				else
				{
					playerHealth.SetHealthMode(1);
				}
			}
		}

		internal static Health GetPlayerHealth()
		{
			try
			{
				RigManager rigManager = Player.RigManager;
				if ((Object)(object)rigManager == (Object)null)
				{
					return null;
				}
				return rigManager.health;
			}
			catch
			{
				return null;
			}
		}

		public override void OnUpdate()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled)
			{
				return;
			}
			try
			{
				Health playerHealth = GetPlayerHealth();
				if (!((Object)(object)playerHealth == (Object)null))
				{
					if ((int)playerHealth.healthMode != 0)
					{
						playerHealth.healthMode = (HealthMode)0;
					}
					playerHealth.curr_Health = playerHealth.max_Health;
					if (!playerHealth.alive)
					{
						playerHealth.alive = true;
					}
					if (playerHealth.deathIsImminent)
					{
						playerHealth.deathIsImminent = false;
					}
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Player_Health), "TAKEDAMAGE")]
	internal static class Patch_TakeDamage
	{
		private static bool Prefix()
		{
			return !Core.Enabled;
		}
	}
	[HarmonyPatch(typeof(Player_Health), "Dying")]
	internal static class Patch_Dying
	{
		private static bool Prefix()
		{
			return !Core.Enabled;
		}
	}
	[HarmonyPatch(typeof(Player_Health), "Death")]
	internal static class Patch_Death
	{
		private static bool Prefix()
		{
			return !Core.Enabled;
		}
	}
}