Decompiled source of Simple Regeneration v1.0.0

plugins/SimpleRegeneration.dll

Decompiled 3 months ago
using System.Collections;
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 SimpleRegeneration.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("SimpleRegeneration")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleRegeneration")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("37800e6f-5e5b-43b7-93b9-f70e147015e9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SimpleRegeneration
{
	[BepInPlugin("minecart.SimpleRegeneration", "Simple Regeneration", "1.0.0")]
	public class SimpleRegenerationModBase : BaseUnityPlugin
	{
		private const string modGUID = "minecart.SimpleRegeneration";

		private const string modName = "Simple Regeneration";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("minecart.SimpleRegeneration");

		private static SimpleRegenerationModBase Instance;

		internal ManualLogSource mls;

		private static ConfigEntry<int> healthRegenRate;

		private static ConfigEntry<bool> needFullStamina;

		private static ConfigEntry<float> timeBetweenRegen;

		public static int GetHRR => healthRegenRate.Value;

		public static bool GetNFS => needFullStamina.Value;

		public static float GetTBR => timeBetweenRegen.Value;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			healthRegenRate = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Health Regen Rate", 1, "The amount of health regenerated per the time set.");
			needFullStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Need Full Stamina To Regen", false, "Determines if you need full stamina in order to regenerate health.");
			timeBetweenRegen = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Time Between Regen", 3f, "The time it takes to regenerate health. This is in seconds.");
			mls = Logger.CreateLogSource("minecart.SimpleRegeneration");
			mls.LogInfo((object)"healing is funn!!!");
			harmony.PatchAll(typeof(SimpleRegenerationModBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace SimpleRegeneration.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static bool isRegenerating;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void RegenPatch(PlayerControllerB __instance)
		{
			if (!isRegenerating && __instance.health < 100)
			{
				((MonoBehaviour)RegenerationHelper.Instance).StartCoroutine(RegenerateHealth(__instance));
			}
		}

		private static IEnumerator RegenerateHealth(PlayerControllerB player)
		{
			isRegenerating = true;
			while (player.health < 100)
			{
				if (!SimpleRegenerationModBase.GetNFS)
				{
					player.health += SimpleRegenerationModBase.GetHRR;
				}
				else if (player.sprintMeter == 1f)
				{
					player.health += SimpleRegenerationModBase.GetHRR;
				}
				yield return (object)new WaitForSeconds(SimpleRegenerationModBase.GetTBR);
			}
			isRegenerating = false;
		}
	}
	public class RegenerationHelper : MonoBehaviour
	{
		private static RegenerationHelper _instance;

		public static RegenerationHelper Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null)
				{
					GameObject val = new GameObject("RegenerationHelper");
					_instance = val.AddComponent<RegenerationHelper>();
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				return _instance;
			}
		}
	}
}