Decompiled source of TZPHealingCustom v1.0.0

TZPReworked.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TzpLeth.Patches;
using Unity.Netcode;
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("TZPHealCustom")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TZPHealCustom")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2ba0eb43-680c-46bc-9c38-f755dcb4f038")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TzpLeth
{
	[BepInPlugin("riverbible.TZPHealCustom", "TZP Healing Custom", "1.0.0")]
	public class TZPHEAL : BaseUnityPlugin
	{
		private const string modGUID = "riverbible.TZPHealCustom";

		private const string modName = "TZP Healing Custom";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("riverbible.TZPHealCustom");

		private ConfigEntry<bool> configInfiniteFuel;

		public static bool InfiniteFuel;

		private ConfigEntry<bool> configShowBatteryIcon;

		public static bool ShowBatteryIcon;

		private static TZPHEAL Instance;

		internal ManualLogSource mls;

		private ConfigEntry<int> configHealingPercent;

		public static int HealingPercent;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("riverbible.TZPHealCustom");
			mls.LogInfo((object)"TZP HEAL loaded");
			harmony.PatchAll(typeof(TZPHEAL));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			configInfiniteFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Infinite TZP", false, "Prevent TZP from ever running out.");
			InfiniteFuel = configInfiniteFuel.Value;
			configShowBatteryIcon = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Battery Icon", true, "Show a battery icon with the current TZP Fuel");
			ShowBatteryIcon = configShowBatteryIcon.Value;
			configHealingPercent = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Healing Percent", 2, "Determines how much TZP healing will be applied.");
			HealingPercent = configHealingPercent.Value;
		}
	}
}
namespace TzpLeth.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch(typeof(TetraChemicalItem))]
	internal class PlayerControllerBPatch : GrabbableObject
	{
		[HarmonyPatch(typeof(TetraChemicalItem), "Update")]
		[HarmonyPrefix]
		private static void PatchBattery(ref Item ___itemProperties, ref Battery ___insertedBattery, ref float ___fuel)
		{
			___itemProperties.requiresBattery = false;
			___insertedBattery.charge = ___fuel;
			___insertedBattery.empty = false;
		}

		[HarmonyPatch(typeof(TetraChemicalItem), "Update")]
		[HarmonyPostfix]
		public static void healtzp(ref bool ___emittingGas, ref bool ___isHeld, PlayerControllerB __instance, ref float ___fuel, ref Item ___itemProperties, ref Battery ___insertedBattery)
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			if (TZPHEAL.InfiniteFuel && (int)(___fuel * 1000f) % 1000 < 500)
			{
				___fuel = 1f;
			}
			else if (TZPHEAL.ShowBatteryIcon)
			{
				___itemProperties.requiresBattery = true;
				___insertedBattery.charge = ___fuel;
				___insertedBattery.empty = false;
			}
			if (!(___emittingGas & ___isHeld) || !((NetworkBehaviour)__instance).IsOwner)
			{
				return;
			}
			int num = (int)(___fuel * 1000f) % 1000;
			GameNetworkManager.Instance.localPlayerController.inSpecialInteractAnimation = true;
			if (((NetworkBehaviour)__instance).IsOwner && num % 30 == 0 && GameNetworkManager.Instance.localPlayerController.health < 100)
			{
				HUDManager.Instance.DisplayStatusEffect("Healing ... " + (GameNetworkManager.Instance.localPlayerController.health + 1) + "%");
				int healingPercent = TZPHEAL.HealingPercent;
				GameNetworkManager.Instance.localPlayerController.DamagePlayer(-healingPercent, false, true, (CauseOfDeath)0, 0, false, default(Vector3));
				if (GameNetworkManager.Instance.localPlayerController.health >= 10 && GameNetworkManager.Instance.localPlayerController.criticallyInjured)
				{
					GameNetworkManager.Instance.localPlayerController.MakeCriticallyInjured(false);
				}
				HUDManager.Instance.HUDAnimator.ResetTrigger("SmallHit");
			}
			if (GameNetworkManager.Instance.localPlayerController.health >= 99)
			{
				HUDManager.Instance.DisplayStatusEffect("Healthy.\nGet to work!");
				HUDManager.Instance.statusEffectAnimator.SetTrigger("IndicateStatus");
			}
			GameNetworkManager.Instance.localPlayerController.inSpecialInteractAnimation = false;
		}
	}
}