Decompiled source of HealthRegen v2.4.0

HealthRegen.dll

Decompiled 8 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using OPJosMod.HealthRegen.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OPJosMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OPJosMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70095872-b952-4e27-bbc4-3d70d0238f39")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OPJosMod
{
	public static class ConfigVariables
	{
		public static float healFrequency;

		public static int healAmount;
	}
}
namespace OPJosMod.HealthRegen
{
	[BepInPlugin("OpJosMod.HealthRegen", "Health Regen", "2.4.0")]
	public class OpJosMod : BaseUnityPlugin
	{
		private const string modGUID = "OpJosMod.HealthRegen";

		private const string modName = "Health Regen";

		private const string modVersion = "2.4.0";

		private readonly Harmony harmony = new Harmony("OpJosMod.HealthRegen");

		private static OpJosMod Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("OpJosMod.HealthRegen");
			mls.LogInfo((object)"mod has started");
			setupConfig();
			harmony.PatchAll(typeof(OpJosMod));
			PlayerControllerBPatch.SetLogSource(mls);
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}

		private void setupConfig()
		{
			ConfigEntry<float> val = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Frequency", "HealFrequency", 10f, "How many seconds between each time you heal");
			ConfigEntry<int> val2 = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Amount", "HealAmount", 4, "How much you heal");
			ConfigVariables.healFrequency = val.Value;
			ConfigVariables.healAmount = val2.Value;
		}
	}
}
namespace OPJosMod.HealthRegen.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static ManualLogSource mls;

		private static float lastHealedAt = Time.time;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void patchUpdate(PlayerControllerB __instance)
		{
			if (__instance.health < 100 && Time.time - lastHealedAt > ConfigVariables.healFrequency)
			{
				HealPlayer(__instance);
			}
		}

		private static void HealPlayer(PlayerControllerB player)
		{
			if (player.isPlayerDead)
			{
				return;
			}
			lastHealedAt = Time.time;
			int num = 1;
			int healAmount = ConfigVariables.healAmount;
			if (player.criticallyInjured || player.health <= 10)
			{
				player.health += num;
			}
			else
			{
				if (player.health + healAmount >= 100)
				{
					int num2 = 100 - player.health;
					player.health = 100;
					player.DamagePlayerServerRpc(-num2, player.health);
					mls.LogMessage((object)$"first if, healthHealed:{num2}, player helath:{player.health}");
				}
				else
				{
					player.health += healAmount;
					player.DamagePlayerServerRpc(-healAmount, player.health);
					mls.LogMessage((object)$"second if, healthToAdd:{healAmount}, player helath:{player.health}");
				}
				HUDManager.Instance.UpdateHealthUI(player.health, false);
			}
			mls.LogMessage((object)$"updated health to:{player.health} at: {Time.time}");
		}
	}
}