Decompiled source of BaseHealth v1.0.0

BaseHealth.dll

Decompiled 21 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.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 BaseHealth
{
	[BepInPlugin("com.vette.basehealth", "BaseHealth", "1.0.0")]
	public class BaseHealthPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.vette.basehealth";

		public const string PluginName = "BaseHealth";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<int> BaseHealthValue;

		public static ConfigEntry<float> RegenPercentPerTick;

		public static ConfigEntry<float> RegenIntervalSeconds;

		internal static ManualLogSource Logger;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			BaseHealthValue = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BaseHealth", 100, new ConfigDescription("Defines the character's base health. Value between 25 and 1000.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(25, 1000), Array.Empty<object>()));
			RegenIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Regeneration", "RegenIntervalSeconds", 1f, new ConfigDescription("Interval in seconds between each health regeneration tick. Value between 1 and 30.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			RegenPercentPerTick = ((BaseUnityPlugin)this).Config.Bind<float>("Regeneration", "RegenPercentPerTick", 0.02f, new ConfigDescription("Percentage of base health healed per regeneration tick. 0.02 equals 2 percent. Value between 0.001 and 1.0.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.001f, 1f), Array.Empty<object>()));
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.vette.basehealth");
			_harmony.PatchAll();
			Logger.LogInfo((object)string.Format("[{0}] Loaded successfully. BaseHealth set to: {1}", "BaseHealth", BaseHealthValue.Value));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Character), "SetMaxHealth", new Type[] { typeof(float) })]
	public static class HealthPatch_Character
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance, ref float health)
		{
			if (!((Object)(object)__instance == (Object)null) && __instance is Player)
			{
				health = BaseHealthPlugin.BaseHealthValue.Value;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetMaxHealth", new Type[]
	{
		typeof(float),
		typeof(bool)
	})]
	public static class HealthPatch_Player
	{
		[HarmonyPrefix]
		public static void Prefix(Player __instance, ref float health, ref bool flashBar)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				health = BaseHealthPlugin.BaseHealthValue.Value;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnRespawn")]
	public static class HealthPatch_PlayerRespawn
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				float num = BaseHealthPlugin.BaseHealthValue.Value;
				((Character)__instance).SetHealth(num);
				BaseHealthPlugin.Logger.LogInfo((object)$"[BaseHealth] Character respawned with base health set to: {num}");
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Awake")]
	public static class HealthRegen_Attach
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && (Object)(object)((Component)__instance).GetComponent<HealthRegenBehaviour>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<HealthRegenBehaviour>();
			}
		}
	}
	public class HealthRegenBehaviour : MonoBehaviour
	{
		private const float IntervaloEmSegundos = 1f;

		private const float PercentualCuraPorTick = 0.001f;

		private Player _jogador;

		private ZNetView _netView;

		private void Awake()
		{
			_jogador = ((Component)this).GetComponent<Player>();
			_netView = ((Component)this).GetComponent<ZNetView>();
			((MonoBehaviour)this).InvokeRepeating("RegenerarVida", 1f, 1f);
		}

		private void OnDestroy()
		{
			((MonoBehaviour)this).CancelInvoke("RegenerarVida");
		}

		private void RegenerarVida()
		{
			if ((Object)(object)_jogador == (Object)null || (Object)(object)_netView == (Object)null || !_netView.IsValid() || !_netView.IsOwner())
			{
				return;
			}
			float health = ((Character)_jogador).GetHealth();
			float num = BaseHealthPlugin.BaseHealthValue.Value;
			if (!(health <= 0f) && !(health >= num))
			{
				float num2 = num * 0.001f;
				float num3 = health + num2;
				if (num3 > num)
				{
					num3 = num;
				}
				((Character)_jogador).Heal(num3 - health, false);
			}
		}
	}
}