Decompiled source of EnemyHealthBars v1.4.0

NoteBoxz.EnemyHealthBars.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EnemyHealthBars.Scripts;
using GameNetcodeStuff;
using HarmonyLib;
using LethalMin;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("DunGen")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")]
[assembly: IgnoresAccessChecksTo("Unity.XR.Management")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")]
[assembly: AssemblyCompany("NoteBoxz.EnemyHealthBars")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0")]
[assembly: AssemblyProduct("EnemyHealthBars")]
[assembly: AssemblyTitle("NoteBoxz.EnemyHealthBars")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 RockMod.Script
{
	public class LookAtMainCamera : MonoBehaviour
	{
		private Camera mainCamera = null;

		private void Start()
		{
			mainCamera = Camera.current;
		}

		private void LateUpdate()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if (!StartOfRound.Instance.localPlayerController.isPlayerDead)
			{
				mainCamera = StartOfRound.Instance.localPlayerController.gameplayCamera;
			}
			else
			{
				mainCamera = StartOfRound.Instance.spectateCamera;
			}
			if ((Object)(object)mainCamera != (Object)null && 2f * ((Component)this).transform.position - ((Component)mainCamera).transform.position != Vector3.zero)
			{
				((Component)this).transform.LookAt(2f * ((Component)this).transform.position - ((Component)mainCamera).transform.position);
			}
		}
	}
}
namespace EnemyHealthBars
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("NoteBoxz.EnemyHealthBars", "EnemyHealthBars", "1.4.0")]
	public class EnemyHealthBars : BaseUnityPlugin
	{
		public enum HPLayoutEnum
		{
			Bar,
			Circle,
			Text
		}

		public enum VisibiltySettings
		{
			AlwaysShow,
			OnlyShowWhenDamaged
		}

		internal static ConfigEntry<bool> ShowTextOnTop;

		internal static ConfigEntry<float> VisDistance;

		internal static ConfigEntry<float> VisDuration;

		internal static ConfigEntry<float> DefultYoffset;

		internal static ConfigEntry<float> HPScale;

		internal static ConfigEntry<bool> TweenHP;

		internal static ConfigEntry<bool> RenderInFront;

		internal static ConfigEntry<bool> ShowDecimals;

		internal static ConfigEntry<float> DistanceFadeRange;

		internal static ConfigEntry<string> OverrideOffset;

		internal static ConfigEntry<string> Color1;

		internal static ConfigEntry<string> Color2;

		internal static ConfigEntry<string> Color3;

		public static EnemyHealthBars Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static AssetBundle assetBundle { get; private set; }

		internal static GameObject HPBarPrefab { get; set; }

		internal static Material? OverlayUIMaterial { get; private set; }

		internal static TMP_FontAsset? OverlayFont { get; private set; }

		internal static TMP_FontAsset? NormalFont { get; private set; }

		public static bool IsLethalMinLoaded => Chainloader.PluginInfos.ContainsKey("NoteBoxz.LethalMin");

		internal static ConfigEntry<HPLayoutEnum> HPLayout { get; set; }

		internal static ConfigEntry<VisibiltySettings> VisSettings { get; set; }

		internal static ConfigEntry<string> BlackList { get; set; }

		public static List<string> GetParsedAttackBlacklist()
		{
			if (string.IsNullOrEmpty(BlackList.Value))
			{
				return new List<string>();
			}
			return BlackList.Value.Split(',').ToList();
		}

		public static Vector3? ParseVector3(string input)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(input))
			{
				return null;
			}
			string[] array = input.Split(' ');
			if (array.Length != 3)
			{
				return null;
			}
			if (float.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2) && float.TryParse(array[2], out var result3))
			{
				return new Vector3(result, result2, result3);
			}
			return null;
		}

		public static Color? ParseColor(string input)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			string[] array = input.Trim('(', ')').Split(',');
			if (array.Length == 4 && int.TryParse(array[0], out var result) && int.TryParse(array[1], out var result2) && int.TryParse(array[2], out var result3) && int.TryParse(array[3], out var result4))
			{
				return new Color((float)result / 255f, (float)result2 / 255f, (float)result3 / 255f, (float)result4 / 255f);
			}
			return null;
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			BindConfigs();
			LoadAssetBundle();
			HPBarPrefab = assetBundle.LoadAsset<GameObject>("Assets/ModAsset/HPBar.prefab");
			LoadOverlayAssets();
			Logger.LogInfo((object)"NoteBoxz.EnemyHealthBars v1.4.0 has loaded!");
		}

		public void BindConfigs()
		{
			HPLayout = ((BaseUnityPlugin)this).Config.Bind<HPLayoutEnum>("Settings", "HP Layout", HPLayoutEnum.Bar, "The way the HP Bar will look");
			HPLayout.SettingChanged += delegate
			{
				UpdateAllBars();
			};
			VisSettings = ((BaseUnityPlugin)this).Config.Bind<VisibiltySettings>("Settings", "Visibilty Settings", VisibiltySettings.OnlyShowWhenDamaged, "");
			VisSettings.SettingChanged += delegate
			{
				UpdateAllBars();
			};
			ShowTextOnTop = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Show Text On Top", true, "Shows the HP Text ontop of the bar no matter the layout");
			ShowTextOnTop.SettingChanged += delegate
			{
				UpdateAllBars();
			};
			VisDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Visibilty Distance", 35f, "");
			DistanceFadeRange = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Distance Fade Range", 12f, "Distance at which the health bar begins to fade out. The bar is fully visible closer than this value, and fully invisible at Visibility Distance.");
			VisDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Visibilty Duration", 5f, "");
			BlackList = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Enemy Blacklist", "Pikmin,Puffmin,Docile Locust Bees,Manticoil", "The list of enemy names that wont have Health Bars (separated by commas, no spaces in between) (item1,item2,item3...)");
			DefultYoffset = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Defult Y Offset", 0.5f, "The Y offset for the defult HealthBar Offset (Will not take affect if Override Offset is set)");
			OverrideOffset = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Override Offset", "", "The offset position of the health bar on an enemy. The top of an enemy's hitbox is defult (sperated by spaces, no commas, no brackets) 0 4 0");
			HPScale = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Scale", 1f, "The size of the Health Bar");
			TweenHP = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Tween HP", true, "Whether to smoothly interpolate the HP bar or snap directly to the values");
			ShowDecimals = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Show Decimals", true, "Whether to show decimal values in the HP text");
			RenderInFront = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Render In Front", true, "Renders the health bars on top of all world geometry (visible through walls). Disable to let walls occlude them.");
			RenderInFront.SettingChanged += delegate
			{
				UpdateAllBars();
			};
			Color1 = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Primary Color", "(0,255,0,255)", "The primary color of the Health Bar, (With parentheses, seperated by commas, no spaces, 255 max value, RGBA) (0,255,0,255)");
			Color2 = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Secondary Color", "(255,0,0,255)", "The secondary color of the Health Bar, (With parentheses, seperated by commas, no spaces, 255 max value, RGBA) (255,0,0,255)");
			Color3 = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Background Color", "(0,0,0,200)", "The background color of the Health Bar, (With parentheses, seperated by commas, no spaces, 255 max value, RGBA) (0,0,0,200)");
		}

		public void UpdateAllBars()
		{
			try
			{
				HealthBar[] array = Object.FindObjectsOfType<HealthBar>();
				HealthBar[] array2 = array;
				foreach (HealthBar healthBar in array2)
				{
					healthBar.UpdateLayoutVisibilty();
					healthBar.ApplyOverlayShaders();
				}
			}
			catch (Exception arg)
			{
				Logger.LogWarning((object)$"Failed to Update All HP Bars due to: {arg}");
			}
		}

		internal static void LoadAssetBundle()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (directoryName == null)
			{
				throw new InvalidOperationException("Unable to determine assembly location.");
			}
			string text = Path.Combine(directoryName, "enemyhpassets");
			assetBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)assetBundle == (Object)null)
			{
				throw new InvalidOperationException("Failed to load AssetBundle.");
			}
		}

		internal static void LoadOverlayAssets()
		{
			OverlayUIMaterial = assetBundle.LoadAsset<Material>("Assets/ModAsset/UIOverall.mat");
			if ((Object)(object)OverlayUIMaterial == (Object)null)
			{
				Logger.LogWarning((object)"UIOverall.mat not found in the asset bundle - bar graphics may be occluded by walls. Did you rebuild the bundle?");
			}
			else
			{
				OverlayUIMaterial.renderQueue = 3500;
			}
			OverlayFont = assetBundle.LoadAsset<TMP_FontAsset>("Assets/ModAsset/3270-RegPonitShaded.asset");
			if ((Object)(object)OverlayFont == (Object)null)
			{
				Logger.LogWarning((object)"3270-RegPonitShaded font asset not found - HP text may be occluded by walls.");
			}
			else
			{
				((TMP_Asset)OverlayFont).material.renderQueue = 3500;
			}
			NormalFont = assetBundle.LoadAsset<TMP_FontAsset>("Assets/ModAsset/3270-RegPonitNonOverall.asset");
			if ((Object)(object)NormalFont == (Object)null)
			{
				Logger.LogWarning((object)"3270-RegPonitNonOverall font asset not found - HP text may not revert when rendering on top is disabled.");
			}
		}

		internal static void Patch()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.EnemyHealthBars");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.EnemyHealthBars";

		public const string PLUGIN_NAME = "EnemyHealthBars";

		public const string PLUGIN_VERSION = "1.4.0";
	}
}
namespace EnemyHealthBars.Scripts
{
	public class HealthBar : MonoBehaviour
	{
		public EnemyAI AI = null;

		public Object? PikminEnemy = null;

		public HPLayout[] Layouts = new HPLayout[1];

		public HPLayout CurLayout = null;

		public Vector3 Offset;

		public float NormalizedHP;

		private int InitalHP;

		public float Timer;

		private float LethalMinHP = 0f;

		private float DisplayedNormalizedHP = 1f;

		private float DisplayedRawHP;

		public float TweenSpeed = 10f;

		private float ShowFade = 0f;

		public float FadeSpeed = 7f;

		public float DeathHoldTime = 1f;

		public float DeathFadeSpeed = 1f;

		private bool WasDead = false;

		private float DeathTimer = 0f;

		public void Start()
		{
			UpdateLayoutVisibilty();
			ApplyOverlayShaders();
			if (!((Object)(object)AI == (Object)null))
			{
				InitalHP = AI.enemyHP;
				if (EnemyHealthBars.IsLethalMinLoaded)
				{
					GetLMPikminEnemy();
				}
			}
		}

		private void GetLMPikminEnemy()
		{
			PikminEnemy = (Object?)(object)((Component)AI).GetComponent<PikminEnemy>();
			Object? pikminEnemy = PikminEnemy;
			PikminEnemy val = (PikminEnemy)(object)((pikminEnemy is PikminEnemy) ? pikminEnemy : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			val.OnHit.AddListener((UnityAction<float>)delegate
			{
				if (EnemyHealthBars.VisSettings.Value == EnemyHealthBars.VisibiltySettings.OnlyShowWhenDamaged && !EnemyHealthBars.GetParsedAttackBlacklist().Contains(AI.enemyType.enemyName))
				{
					Timer = EnemyHealthBars.VisDuration.Value;
				}
			});
		}

		public void Update()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)AI == (Object)null)
			{
				return;
			}
			if (EnemyHealthBars.IsLethalMinLoaded)
			{
				SetLethalMinHP();
			}
			HPLayout hPLayout = Layouts[(int)EnemyHealthBars.HPLayout.Value];
			if ((Object)(object)hPLayout != (Object)(object)CurLayout)
			{
				HPLayout curLayout = CurLayout;
				if (curLayout != null)
				{
					((Component)curLayout).gameObject.SetActive(false);
				}
				CurLayout = hPLayout;
			}
			((Component)this).transform.localPosition = Offset;
			NormalizedHP = (AI.isEnemyDead ? 0f : (((float)AI.enemyHP - LethalMinHP) / (float)InitalHP));
			float num = (AI.isEnemyDead ? 0f : ((float)AI.enemyHP - LethalMinHP));
			if (EnemyHealthBars.TweenHP.Value)
			{
				DisplayedNormalizedHP = Mathf.Lerp(DisplayedNormalizedHP, NormalizedHP, Time.deltaTime * TweenSpeed);
				DisplayedRawHP = Mathf.Lerp(DisplayedRawHP, num, Time.deltaTime * TweenSpeed);
			}
			else
			{
				DisplayedNormalizedHP = NormalizedHP;
				DisplayedRawHP = num;
			}
			if (!((Component)CurLayout).gameObject.activeSelf)
			{
				return;
			}
			if ((Object)(object)CurLayout.Bar != (Object)null)
			{
				CurLayout.Bar.fillAmount = DisplayedNormalizedHP;
			}
			if ((Object)(object)CurLayout.text != (Object)null)
			{
				string text = (EnemyHealthBars.ShowDecimals.Value ? "F2" : "F0");
				if (CurLayout.DontShowMaxOnText)
				{
					CurLayout.text.text = DisplayedRawHP.ToString(text) ?? "";
				}
				else
				{
					CurLayout.text.text = DisplayedRawHP.ToString(text) + "/" + InitalHP.ToString(text);
				}
			}
		}

		public void SetLethalMinHP()
		{
			if (PikminEnemy != (Object)null)
			{
				ref float lethalMinHP = ref LethalMinHP;
				Object? pikminEnemy = PikminEnemy;
				lethalMinHP = ((PikminEnemy)(((pikminEnemy is PikminEnemy) ? pikminEnemy : null)?)).DamageCounter ?? 0f;
			}
		}

		public void LateUpdate()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			float value = EnemyHealthBars.HPScale.Value;
			Vector3 val = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.lossyScale : Vector3.one);
			((Component)this).transform.localScale = new Vector3(value / Mathf.Max(Mathf.Abs(val.x), 0.0001f), value / Mathf.Max(Mathf.Abs(val.y), 0.0001f), value / Mathf.Max(Mathf.Abs(val.z), 0.0001f));
			if ((Object)(object)CurLayout == (Object)null)
			{
				return;
			}
			Color? val2 = null;
			val2 = EnemyHealthBars.ParseColor(EnemyHealthBars.Color1.Value);
			Color? val3 = null;
			val3 = EnemyHealthBars.ParseColor(EnemyHealthBars.Color2.Value);
			Color? val4 = null;
			val4 = EnemyHealthBars.ParseColor(EnemyHealthBars.Color3.Value);
			if ((Object)(object)CurLayout.Bar != (Object)null && val2.HasValue)
			{
				((Graphic)CurLayout.Bar).color = val2.Value;
			}
			if ((Object)(object)CurLayout.BottomBar != (Object)null && val3.HasValue)
			{
				((Graphic)CurLayout.BottomBar).color = val3.Value;
			}
			if ((Object)(object)CurLayout.text != (Object)null && val2.HasValue && val3.HasValue)
			{
				Color val5 = Color.Lerp(val3.Value, val2.Value, NormalizedHP);
				if (!CurLayout.OnlyHasText)
				{
					((Color)(ref val5))..ctor(val5.r * 0.5f, val5.g * 0.5f, val5.b * 0.5f, val5.a);
				}
				((Graphic)CurLayout.text).color = val5;
			}
			if ((Object)(object)CurLayout.BG != (Object)null && val4.HasValue)
			{
				((Graphic)CurLayout.BG).color = val4.Value;
			}
			UpdateFade();
		}

		private void UpdateFade()
		{
			bool flag = (Object)(object)AI != (Object)null && AI.isEnemyDead;
			if (flag && !WasDead)
			{
				WasDead = true;
				DeathTimer = ((ShowFade > 0.01f) ? DeathHoldTime : 0f);
			}
			else if (!flag && WasDead)
			{
				WasDead = false;
			}
			float num = FadeSpeed;
			float num2;
			if (flag)
			{
				if (DeathTimer > 0f)
				{
					DeathTimer -= Time.deltaTime;
					num2 = 1f;
				}
				else
				{
					num2 = 0f;
					num = DeathFadeSpeed;
				}
			}
			else
			{
				switch (EnemyHealthBars.VisSettings.Value)
				{
				case EnemyHealthBars.VisibiltySettings.AlwaysShow:
					num2 = 1f;
					break;
				case EnemyHealthBars.VisibiltySettings.OnlyShowWhenDamaged:
					num2 = ((Timer > 0f) ? 1f : 0f);
					if (Timer > 0f)
					{
						Timer -= Time.deltaTime;
					}
					break;
				default:
					num2 = 0f;
					break;
				}
			}
			ShowFade = Mathf.MoveTowards(ShowFade, num2, Time.deltaTime * num);
			float num3 = ShowFade * GetDistanceFade();
			bool flag2 = num3 > 0.001f;
			if (((Component)CurLayout).gameObject.activeSelf != flag2)
			{
				((Component)CurLayout).gameObject.SetActive(flag2);
			}
			if ((Object)(object)CurLayout.CanvasGroup != (Object)null)
			{
				CurLayout.CanvasGroup.alpha = num3;
			}
		}

		private float GetDistanceFade()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				return 1f;
			}
			float num = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
			float value = EnemyHealthBars.VisDistance.Value;
			float value2 = EnemyHealthBars.DistanceFadeRange.Value;
			float num2 = value - value2;
			if (num2 <= 0f)
			{
				return (num < value) ? 1f : 0f;
			}
			return Mathf.Clamp01((value - num) / num2);
		}

		public void ApplyOverlayShaders()
		{
			bool value = EnemyHealthBars.RenderInFront.Value;
			TMP_FontAsset val = (value ? EnemyHealthBars.OverlayFont : EnemyHealthBars.NormalFont);
			if ((Object)(object)val != (Object)null)
			{
				TMP_Text[] componentsInChildren = ((Component)this).GetComponentsInChildren<TMP_Text>(true);
				foreach (TMP_Text val2 in componentsInChildren)
				{
					val2.font = val;
				}
			}
			Material material = (value ? EnemyHealthBars.OverlayUIMaterial : null);
			Image[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Image>(true);
			foreach (Image val3 in componentsInChildren2)
			{
				((Graphic)val3).material = material;
			}
		}

		public void UpdateLayoutVisibilty()
		{
			HPLayout[] layouts = Layouts;
			foreach (HPLayout hPLayout in layouts)
			{
				if ((Object)(object)hPLayout != (Object)(object)CurLayout)
				{
					((Component)hPLayout).gameObject.SetActive(false);
				}
				else
				{
					((Component)hPLayout).gameObject.SetActive(true);
				}
				if ((Object)(object)hPLayout.text != (Object)null)
				{
					((Component)hPLayout.text).gameObject.SetActive(hPLayout.OnlyHasText || EnemyHealthBars.ShowTextOnTop.Value);
				}
			}
		}
	}
	public class HPLayout : MonoBehaviour
	{
		public Image Bar = null;

		public Image BottomBar = null;

		public Image BG = null;

		public TMP_Text text = null;

		public CanvasGroup CanvasGroup = null;

		public bool DontShowMaxOnText = false;

		public bool OnlyHasText = false;
	}
	public class TestBar : MonoBehaviour
	{
		public Image img = null;

		public float A;

		public float B;

		private void Update()
		{
			img.fillAmount = A / B;
		}
	}
}
namespace EnemyHealthBars.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	public class EnemyAIPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPosfix(EnemyAI __instance)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!EnemyHealthBars.GetParsedAttackBlacklist().Contains(__instance.enemyType.enemyName))
				{
					HealthBar component = Object.Instantiate<GameObject>(EnemyHealthBars.HPBarPrefab, ((Component)__instance).transform).GetComponent<HealthBar>();
					((Object)((Component)component).gameObject).name = ((Object)((Component)component).gameObject).name.Replace("(Clone)", "") ?? "";
					component.AI = __instance;
					Vector3? val = EnemyHealthBars.ParseVector3(EnemyHealthBars.OverrideOffset.Value);
					if (val.HasValue)
					{
						component.Offset = val.Value;
					}
					else if ((Object)(object)((Component)__instance).GetComponentInChildren<NavMeshAgent>() != (Object)null)
					{
						component.Offset = new Vector3(0f, ((Component)__instance).GetComponentInChildren<NavMeshAgent>().height + EnemyHealthBars.DefultYoffset.Value, 0f);
					}
				}
			}
			catch (Exception arg)
			{
				Debug.Log((object)$"Failed to give {((Object)__instance).name} a health bar due to: {arg}");
			}
		}

		[HarmonyPatch("HitEnemy")]
		[HarmonyPostfix]
		private static void HitEnemy(EnemyAI __instance)
		{
			if (EnemyHealthBars.VisSettings.Value == EnemyHealthBars.VisibiltySettings.OnlyShowWhenDamaged && !EnemyHealthBars.GetParsedAttackBlacklist().Contains(__instance.enemyType.enemyName))
			{
				HealthBar componentInChildren = ((Component)__instance).GetComponentInChildren<HealthBar>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.Timer = EnemyHealthBars.VisDuration.Value;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}