Decompiled source of MonsterHPBars v2.0.2

MonsterHPBars.dll

Decompiled 21 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MonsterHPBars")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.2")]
[assembly: AssemblyInformationalVersion("2.0.2+48510df4983b60fe42faacb98f66ed8bea073730")]
[assembly: AssemblyProduct("MonsterHPBars")]
[assembly: AssemblyTitle("MonsterHPBars")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 MonsterHPBars
{
	public sealed class HPBarManager : MonoBehaviour
	{
		private Canvas? _overlayCanvas;

		private Transform? _canvasTransform;

		private Camera? _mainCamera;

		private Transform? _localPlayerTransform;

		private readonly Dictionary<Unit, HPBarUI> _activeBars = new Dictionary<Unit, HPBarUI>();

		private readonly Queue<HPBarUI> _freePool = new Queue<HPBarUI>();

		private readonly List<HPBarUI> _allCreatedBars = new List<HPBarUI>();

		private readonly HashSet<Unit> _currentFrameUnits = new HashSet<Unit>();

		private readonly List<Unit> _toRemoveUnits = new List<Unit>();

		private static readonly Dictionary<string, float> _heightCache = new Dictionary<string, float>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<IDamageable, float> _damageTimes = new Dictionary<IDamageable, float>();

		public static HPBarManager Instance { get; private set; } = null;

		public static void NotifyDamage(IDamageable damageable)
		{
			if (damageable != null)
			{
				_damageTimes[damageable] = Time.time;
			}
		}

		private void Awake()
		{
			Instance = this;
			BuildCanvas();
		}

		private void BuildCanvas()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("MonsterHPBars_OverlayCanvas");
			Object.DontDestroyOnLoad((Object)(object)val);
			_overlayCanvas = val.AddComponent<Canvas>();
			_overlayCanvas.renderMode = (RenderMode)0;
			_overlayCanvas.sortingOrder = 2000;
			CanvasScaler obj = val.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			val.AddComponent<GraphicRaycaster>();
			_canvasTransform = val.transform;
		}

		private HPBarUI GetFreeBar()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (_freePool.Count > 0)
			{
				return _freePool.Dequeue();
			}
			HPBarUI hPBarUI = new GameObject($"HPBarUI_{_allCreatedBars.Count}").AddComponent<HPBarUI>();
			hPBarUI.BuildUI(_canvasTransform, MonsterHPBarsPlugin.BarWidth.Value, MonsterHPBarsPlugin.BarHeight.Value);
			_allCreatedBars.Add(hPBarUI);
			return hPBarUI;
		}

		private void LateUpdate()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			if (!MonsterHPBarsPlugin.IsModEnabled)
			{
				HideAllBars();
				return;
			}
			if ((Object)(object)_mainCamera == (Object)null || !((Component)_mainCamera).gameObject.activeInHierarchy)
			{
				_mainCamera = Camera.main;
			}
			if ((Object)(object)_mainCamera == (Object)null)
			{
				HideAllBars();
				return;
			}
			if ((Object)(object)_localPlayerTransform == (Object)null || !((Component)_localPlayerTransform).gameObject.activeInHierarchy)
			{
				_localPlayerTransform = FindLocalPlayer();
			}
			if ((Object)(object)UnitManager.I == (Object)null || UnitManager.I.ActiveUnits == null)
			{
				HideAllBars();
				return;
			}
			Vector3 val = (((Object)(object)_localPlayerTransform != (Object)null) ? _localPlayerTransform.position : Vector3.zero);
			bool flag = (Object)(object)_localPlayerTransform != (Object)null;
			float num = MonsterHPBarsPlugin.ShowRadius.Value * MonsterHPBarsPlugin.ShowRadius.Value;
			bool value = MonsterHPBarsPlugin.ShowOnlyEnemies.Value;
			bool value2 = MonsterHPBarsPlugin.ShowBossOnly.Value;
			bool value3 = MonsterHPBarsPlugin.AlwaysVisible.Value;
			float value4 = MonsterHPBarsPlugin.VisibilityDuration.Value;
			float deltaTime = Time.deltaTime;
			float time = Time.time;
			_currentFrameUnits.Clear();
			foreach (Unit activeUnit in UnitManager.I.ActiveUnits)
			{
				if ((Object)(object)activeUnit == (Object)null || activeUnit.isPlayerCharacter)
				{
					continue;
				}
				IDamageable damageable = activeUnit.Damageable;
				if (damageable == null || !damageable.IsAlive || activeUnit.IsDead || damageable.CurrentHealth <= 0f || (value2 && !activeUnit.isBoss) || (value && (int)activeUnit.Team != 0))
				{
					continue;
				}
				Vector3 position = ((Component)activeUnit).transform.position;
				if (flag)
				{
					Vector3 val2 = position - val;
					if (((Vector3)(ref val2)).sqrMagnitude > num)
					{
						continue;
					}
				}
				float num2 = Mathf.Max(damageable.MaxHealth, 1f);
				float num3 = Mathf.Clamp(damageable.CurrentHealth, 0f, num2) / num2;
				if (!value3 && num3 >= 1f && (!_damageTimes.TryGetValue(damageable, out var value5) || time - value5 > value4))
				{
					continue;
				}
				float unitHeightCached = GetUnitHeightCached(activeUnit);
				float num4 = MonsterHPBarsPlugin.BarHeightPadding.Value;
				if (activeUnit.isBoss)
				{
					num4 += MonsterHPBarsPlugin.BossHeightPadding.Value;
				}
				Vector3 val3 = position + Vector3.up * (unitHeightCached + num4);
				Vector3 val4 = _mainCamera.WorldToScreenPoint(val3);
				if (!(val4.z <= 0f))
				{
					_currentFrameUnits.Add(activeUnit);
					if (!_activeBars.TryGetValue(activeUnit, out HPBarUI value6))
					{
						value6 = GetFreeBar();
						value6.ResetState(num3);
						string unitName = CleanUnitName(activeUnit.UnitName);
						value6.Setup(unitName, activeUnit.isBoss, activeUnit.isEliteUnit);
						_activeBars[activeUnit] = value6;
					}
					_damageTimes.TryGetValue(damageable, out var value7);
					value6.UpdateBar(num3, value7, deltaTime);
					((Transform)value6.RectTransform).position = val4;
					value6.SetVisible(visible: true);
				}
			}
			_toRemoveUnits.Clear();
			foreach (KeyValuePair<Unit, HPBarUI> activeBar in _activeBars)
			{
				Unit key = activeBar.Key;
				if (((Object)(object)key == (Object)null || !_currentFrameUnits.Contains(key)) && (Object)(object)key != (Object)null)
				{
					_toRemoveUnits.Add(key);
				}
			}
			foreach (Unit toRemoveUnit in _toRemoveUnits)
			{
				if (_activeBars.TryGetValue(toRemoveUnit, out HPBarUI value8))
				{
					value8.SetVisible(visible: false);
					_freePool.Enqueue(value8);
					_activeBars.Remove(toRemoveUnit);
				}
			}
		}

		private Transform? FindLocalPlayer()
		{
			if ((Object)(object)UnitManager.I != (Object)null && UnitManager.I.ActiveUnits != null)
			{
				foreach (Unit activeUnit in UnitManager.I.ActiveUnits)
				{
					if ((Object)(object)activeUnit != (Object)null && activeUnit.isPlayerCharacter)
					{
						return ((Component)activeUnit).transform;
					}
				}
			}
			return null;
		}

		private static float GetUnitHeightCached(Unit unit)
		{
			string key = unit.UnitName ?? "Default";
			if (_heightCache.TryGetValue(key, out var value))
			{
				return value;
			}
			float num = CalculateUnitHeight(unit);
			_heightCache[key] = num;
			return num;
		}

		private static float CalculateUnitHeight(Unit unit)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)unit.SpatialEntity != (Object)null)
			{
				float collisionCenterYFloat = unit.SpatialEntity.CollisionCenterYFloat;
				float collisionHeightFloat = unit.SpatialEntity.CollisionHeightFloat;
				if (collisionHeightFloat > 0.1f)
				{
					return collisionCenterYFloat + collisionHeightFloat / 2f;
				}
			}
			Renderer[] componentsInChildren = ((Component)unit).GetComponentsInChildren<Renderer>(true);
			if (componentsInChildren != null && componentsInChildren.Length != 0)
			{
				float num = 0f;
				float y = ((Component)unit).transform.position.y;
				bool flag = false;
				Renderer[] array = componentsInChildren;
				Bounds bounds;
				foreach (Renderer val in array)
				{
					if (val.enabled && ((Component)val).gameObject.activeInHierarchy && ((object)val).GetType().Name.Contains("SkinnedMeshRenderer"))
					{
						bounds = val.bounds;
						float num2 = ((Bounds)(ref bounds)).max.y - y;
						if (num2 > num)
						{
							num = num2;
							flag = true;
						}
					}
				}
				if (!flag)
				{
					array = componentsInChildren;
					foreach (Renderer val2 in array)
					{
						if (!val2.enabled || !((Component)val2).gameObject.activeInHierarchy || !((object)val2).GetType().Name.Contains("MeshRenderer"))
						{
							continue;
						}
						string text = ((Object)((Component)val2).gameObject).name.ToLower();
						if (!text.Contains("shadow") && !text.Contains("decal") && !text.Contains("ui") && !text.Contains("outline") && !text.Contains("range") && !text.Contains("weapon"))
						{
							bounds = val2.bounds;
							float num3 = ((Bounds)(ref bounds)).max.y - y;
							if (num3 > num)
							{
								num = num3;
								flag = true;
							}
						}
					}
				}
				if (flag && num > 0.3f)
				{
					return num;
				}
			}
			return 2f;
		}

		private static string CleanUnitName(string rawName)
		{
			if (string.IsNullOrEmpty(rawName))
			{
				return "";
			}
			if (rawName.StartsWith("boss_", StringComparison.OrdinalIgnoreCase))
			{
				rawName = rawName.Substring(5);
			}
			try
			{
				return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(rawName.Replace('_', ' ').Trim());
			}
			catch
			{
				return rawName.Replace('_', ' ').Trim();
			}
		}

		private void HideAllBars()
		{
			foreach (KeyValuePair<Unit, HPBarUI> activeBar in _activeBars)
			{
				if ((Object)(object)activeBar.Value != (Object)null)
				{
					activeBar.Value.SetVisible(visible: false);
					_freePool.Enqueue(activeBar.Value);
				}
			}
			_activeBars.Clear();
		}
	}
	public sealed class HPBarUI : MonoBehaviour
	{
		private Image? _bgImage;

		private Image? _fillImage;

		private RectTransform? _fillRT;

		private Image? _delayedFillImage;

		private RectTransform? _delayedFillRT;

		private Text? _nameText;

		private Image? _borderImage;

		private float _delayedFill = 1f;

		private float _lastFillAmount = -99f;

		private float _lastDelayedFill = -99f;

		private bool _isBoss;

		private bool _isElite;

		private string _cachedName = "";

		public RectTransform RectTransform { get; private set; }

		public void BuildUI(Transform parent, float width, float height)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Expected O, but got Unknown
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Expected O, but got Unknown
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			((Object)((Component)this).gameObject).name = "HPBarUI_Pooled";
			((Component)this).transform.SetParent(parent, false);
			RectTransform = ((Component)this).gameObject.AddComponent<RectTransform>();
			RectTransform.sizeDelta = new Vector2(width + 16f, 40f);
			float value = MonsterHPBarsPlugin.BarOpacity.Value;
			GameObject val = new GameObject("HPBg");
			val.transform.SetParent(((Component)this).transform, false);
			_bgImage = val.AddComponent<Image>();
			((Graphic)_bgImage).color = new Color(0.04f, 0.04f, 0.06f, 0.5f * value);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = Vector2.zero;
			component.sizeDelta = new Vector2(width + 3f, height + 3f);
			GameObject val2 = new GameObject("HPDelayFill");
			val2.transform.SetParent(((Component)this).transform, false);
			_delayedFillImage = val2.AddComponent<Image>();
			((Graphic)_delayedFillImage).color = new Color(0.95f, 0.9f, 0.2f, 0.35f * value);
			_delayedFillRT = val2.GetComponent<RectTransform>();
			_delayedFillRT.anchorMin = new Vector2(0.5f, 0.5f);
			_delayedFillRT.anchorMax = new Vector2(0.5f, 0.5f);
			_delayedFillRT.pivot = new Vector2(0f, 0.5f);
			_delayedFillRT.anchoredPosition = new Vector2((0f - width) / 2f, 0f);
			_delayedFillRT.sizeDelta = new Vector2(width, height);
			GameObject val3 = new GameObject("HPFill");
			val3.transform.SetParent(((Component)this).transform, false);
			_fillImage = val3.AddComponent<Image>();
			Color value2 = MonsterHPBarsPlugin.HealthyColor.Value;
			value2.a *= value;
			((Graphic)_fillImage).color = value2;
			_fillRT = val3.GetComponent<RectTransform>();
			_fillRT.anchorMin = new Vector2(0.5f, 0.5f);
			_fillRT.anchorMax = new Vector2(0.5f, 0.5f);
			_fillRT.pivot = new Vector2(0f, 0.5f);
			_fillRT.anchoredPosition = new Vector2((0f - width) / 2f, 0f);
			_fillRT.sizeDelta = new Vector2(width, height);
			GameObject val4 = new GameObject("HPBorder");
			val4.transform.SetParent(((Component)this).transform, false);
			_borderImage = val4.AddComponent<Image>();
			RectTransform component2 = val4.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			component2.pivot = new Vector2(0.5f, 0.5f);
			component2.anchoredPosition = Vector2.zero;
			component2.sizeDelta = new Vector2(width + 6f, height + 6f);
			val4.transform.SetSiblingIndex(0);
			val4.SetActive(false);
			GameObject val5 = new GameObject("NameLabel");
			val5.transform.SetParent(((Component)this).transform, false);
			_nameText = val5.AddComponent<Text>();
			_nameText.fontSize = 12;
			_nameText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			_nameText.alignment = (TextAnchor)4;
			((Graphic)_nameText).color = new Color(1f, 1f, 1f, 0.8f * value);
			RectTransform component3 = val5.GetComponent<RectTransform>();
			component3.anchoredPosition = new Vector2(0f, 20f);
			component3.sizeDelta = new Vector2(width + 30f, 18f);
		}

		public void ResetState(float initialFill)
		{
			_delayedFill = Mathf.Clamp01(initialFill);
			_lastFillAmount = -99f;
			_lastDelayedFill = -99f;
			_cachedName = "";
		}

		public void Setup(string unitName, bool isBoss, bool isElite)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			_isBoss = isBoss;
			_isElite = isElite;
			float value = MonsterHPBarsPlugin.BarOpacity.Value;
			if ((Object)(object)_borderImage != (Object)null)
			{
				if (isBoss || isElite)
				{
					((Component)_borderImage).gameObject.SetActive(true);
					Color color = (isBoss ? MonsterHPBarsPlugin.BossColor.Value : MonsterHPBarsPlugin.EliteColor.Value);
					color.a = 0.65f * value;
					((Graphic)_borderImage).color = color;
				}
				else
				{
					((Component)_borderImage).gameObject.SetActive(false);
				}
			}
			if ((Object)(object)_nameText != (Object)null)
			{
				bool flag = MonsterHPBarsPlugin.ShowLabel.Value && !string.IsNullOrWhiteSpace(unitName) && !unitName.Equals("Unit", StringComparison.OrdinalIgnoreCase);
				((Component)_nameText).gameObject.SetActive(flag);
				if (flag && _cachedName != unitName)
				{
					_nameText.text = unitName;
					_cachedName = unitName;
					Color color2 = (Color)(isBoss ? MonsterHPBarsPlugin.BossColor.Value : (isElite ? MonsterHPBarsPlugin.EliteColor.Value : new Color(1f, 1f, 1f, 0.8f)));
					color2.a *= value;
					((Graphic)_nameText).color = color2;
					_nameText.fontStyle = (FontStyle)((isBoss || isElite) ? 1 : 0);
				}
			}
		}

		public void UpdateBar(float fill, float lastDamageTime, float deltaTime)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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)
			fill = Mathf.Clamp01(fill);
			float value = MonsterHPBarsPlugin.BarOpacity.Value;
			if (fill < _delayedFill)
			{
				if (Time.time - lastDamageTime > 0.3f)
				{
					_delayedFill = Mathf.MoveTowards(_delayedFill, fill, 0.8f * deltaTime);
				}
			}
			else
			{
				_delayedFill = fill;
			}
			float value2 = MonsterHPBarsPlugin.BarWidth.Value;
			float value3 = MonsterHPBarsPlugin.BarHeight.Value;
			if ((Object)(object)_delayedFillRT != (Object)null && Mathf.Abs(_delayedFill - _lastDelayedFill) > 0.001f)
			{
				_delayedFillRT.sizeDelta = new Vector2(value2 * _delayedFill, value3);
				_lastDelayedFill = _delayedFill;
			}
			if ((Object)(object)_delayedFillImage != (Object)null)
			{
				((Graphic)_delayedFillImage).color = new Color(0.95f, 0.9f, 0.2f, 0.35f * value);
			}
			if ((Object)(object)_fillRT != (Object)null && (Object)(object)_fillImage != (Object)null)
			{
				if (Mathf.Abs(fill - _lastFillAmount) > 0.001f)
				{
					_fillRT.sizeDelta = new Vector2(value2 * fill, value3);
					_lastFillAmount = fill;
				}
				Color val = ((fill <= MonsterHPBarsPlugin.CriticalThreshold.Value) ? MonsterHPBarsPlugin.CriticalColor.Value : ((!(fill <= MonsterHPBarsPlugin.DamagedThreshold.Value)) ? MonsterHPBarsPlugin.HealthyColor.Value : MonsterHPBarsPlugin.DamagedColor.Value));
				val.a *= value;
				((Graphic)_fillImage).color = Color.Lerp(((Graphic)_fillImage).color, val, deltaTime * 8f);
			}
			if ((Object)(object)_bgImage != (Object)null)
			{
				((Graphic)_bgImage).color = new Color(0.04f, 0.04f, 0.06f, 0.5f * value);
			}
		}

		public void SetVisible(bool visible)
		{
			if (((Component)this).gameObject.activeSelf != visible)
			{
				((Component)this).gameObject.SetActive(visible);
			}
		}
	}
	[BepInPlugin("com.sineusarena.monsterhpbars", "Monster HP Bars", "2.0.2")]
	public class MonsterHPBarsPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static MonsterHPBarsPlugin Instance { get; private set; } = null;

		internal static ManualLogSource Log { get; private set; } = null;

		public static bool IsModEnabled { get; private set; } = true;

		public static ConfigEntry<KeyboardShortcut> ToggleKey { get; private set; } = null;

		public static ConfigEntry<bool> ShowOnlyEnemies { get; private set; } = null;

		public static ConfigEntry<bool> ShowBossOnly { get; private set; } = null;

		public static ConfigEntry<float> ShowRadius { get; private set; } = null;

		public static ConfigEntry<float> BarWidth { get; private set; } = null;

		public static ConfigEntry<float> BarHeight { get; private set; } = null;

		public static ConfigEntry<float> BarOpacity { get; private set; } = null;

		public static ConfigEntry<float> BarHeightPadding { get; private set; } = null;

		public static ConfigEntry<float> BossHeightPadding { get; private set; } = null;

		public static ConfigEntry<bool> ShowLabel { get; private set; } = null;

		public static ConfigEntry<Color> HealthyColor { get; private set; } = null;

		public static ConfigEntry<Color> DamagedColor { get; private set; } = null;

		public static ConfigEntry<Color> CriticalColor { get; private set; } = null;

		public static ConfigEntry<Color> EliteColor { get; private set; } = null;

		public static ConfigEntry<Color> BossColor { get; private set; } = null;

		public static ConfigEntry<float> DamagedThreshold { get; private set; } = null;

		public static ConfigEntry<float> CriticalThreshold { get; private set; } = null;

		public static ConfigEntry<bool> AlwaysVisible { get; private set; } = null;

		public static ConfigEntry<float> VisibilityDuration { get; private set; } = null;

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			_harmony = new Harmony("com.sineusarena.monsterhpbars");
			_harmony.PatchAll(typeof(UnitPatches));
			((Component)this).gameObject.AddComponent<HPBarManager>();
			Log.LogInfo((object)"Monster HP Bars v2.0.2 loaded successfully! Press F4 to toggle.");
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = ToggleKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				ToggleMod();
			}
		}

		private void ToggleMod()
		{
			IsModEnabled = !IsModEnabled;
			Log.LogInfo((object)("Monster HP Bars toggled " + (IsModEnabled ? "ON" : "OFF")));
		}

		private void BindConfig()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: 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_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - General", "ToggleKey", new KeyboardShortcut((KeyCode)285, Array.Empty<KeyCode>()), "Key to toggle the mod on/off.");
			ShowOnlyEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ShowOnlyEnemies", true, "Only show HP bars on enemy (Neutral team) units.");
			ShowBossOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ShowBossOnly", false, "Only show HP bars on boss units.");
			ShowRadius = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "ShowRadius", 40f, "Only show HP bars within this distance (in units) from the player.");
			AlwaysVisible = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "AlwaysVisible", true, "Always show bars, even when unit is at full health.");
			VisibilityDuration = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "VisibilityDuration", 5f, "Seconds the bar stays visible after damage (when AlwaysVisible is false).");
			BarWidth = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "BarWidth", 90f, "Width of the HP bar in pixels.");
			BarHeight = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "BarHeight", 7f, "Height of the HP bar in pixels.");
			BarOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "BarOpacity", 0.65f, "Overall opacity/transparency of the HP bar (0.0 = invisible, 1.0 = fully opaque).");
			BarHeightPadding = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "BarHeightPadding", 1.5f, "Additional vertical padding above the unit's head.");
			BossHeightPadding = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "BossHeightPadding", 0.5f, "Extra vertical padding added *only* to boss health bars.");
			ShowLabel = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Appearance", "ShowLabel", true, "Show unit name label above the bar.");
			HealthyColor = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "HealthyColor", new Color(0.15f, 0.85f, 0.25f, 0.65f), "Bar color at high HP.");
			DamagedColor = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "DamagedColor", new Color(0.95f, 0.75f, 0.1f, 0.65f), "Bar color at medium HP.");
			CriticalColor = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "CriticalColor", new Color(0.95f, 0.15f, 0.1f, 0.65f), "Bar color at low HP.");
			EliteColor = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "EliteColor", new Color(0.75f, 0.2f, 0.95f, 0.8f), "Accent color for elite units.");
			BossColor = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "BossColor", new Color(0.95f, 0.4f, 0.05f, 0.85f), "Accent color for boss units.");
			DamagedThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Colors", "DamagedThreshold", 0.6f, "HP fraction below which the 'DamagedColor' is used.");
			CriticalThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Colors", "CriticalThreshold", 0.25f, "HP fraction below which the 'CriticalColor' is used.");
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.sineusarena.monsterhpbars";

		public const string PLUGIN_NAME = "Monster HP Bars";

		public const string PLUGIN_VERSION = "2.0.2";
	}
	internal static class UnitPatches
	{
		[HarmonyPatch(typeof(SimpleDamageable), "TakeDamage")]
		[HarmonyPostfix]
		private static void SimpleDamageable_TakeDamage_Postfix(SimpleDamageable __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				HPBarManager.NotifyDamage((IDamageable)(object)__instance);
			}
		}
	}
}