Decompiled source of AtlyssExecuteHPIndicator v1.1.0

plugins/AtlyssExecuteHPIndicator.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AtlyssExecuteHPIndicator.Config;
using AtlyssExecuteHPIndicator.Model;
using AtlyssExecuteHPIndicator.Utils;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;
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: AssemblyCompany("AtlyssExecuteHPIndicator")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0381790b2563f4b9c07ba48633cb25b520002b5b")]
[assembly: AssemblyProduct("AtlyssExecuteHPIndicator")]
[assembly: AssemblyTitle("AtlyssExecuteHPIndicator")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 AtlyssExecuteHPIndicator.Utils
{
	internal static class ColorUtils
	{
		public static Color Parse(string hex)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (ColorUtility.TryParseHtmlString(hex, ref result))
			{
				return result;
			}
			return Color.white;
		}
	}
}
namespace AtlyssExecuteHPIndicator.Model
{
	internal static class StatusEntityGUIAccess
	{
		private static readonly FieldInfo healthBarObjectField = typeof(StatusEntityGUI).GetField("_healthBarObject", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo healthBarFillField = typeof(StatusEntityGUI).GetField("_healthBarFill", BindingFlags.Instance | BindingFlags.NonPublic);

		public static GameObject GetHealthBarObject(StatusEntityGUI gui)
		{
			object? obj = healthBarObjectField?.GetValue(gui);
			return (GameObject)((obj is GameObject) ? obj : null);
		}

		public static Image GetHealthBarFill(StatusEntityGUI gui)
		{
			object? obj = healthBarFillField?.GetValue(gui);
			return (Image)((obj is Image) ? obj : null);
		}
	}
	internal class TrackedCreep
	{
		public CreepBehavior Behavior;

		public Image Foreground;

		public Image Background;
	}
}
namespace AtlyssExecuteHPIndicator.Config
{
	internal static class AtlyssExecuteHPIndicatorConfig
	{
		internal static ConfigEntry<float> ExecuteHPPercent;

		internal static ConfigEntry<string> NormalLowHPColor;

		internal static ConfigEntry<string> NormalHighHPColor;

		internal static ConfigEntry<string> EliteColor;

		internal static ConfigEntry<string> BackgroundNormalColor;

		internal static ConfigEntry<string> BackgroundEliteColor;

		internal static void Init(ConfigFile config)
		{
			ExecuteHPPercent = config.Bind<float>("HP Percent", "Execute HP threshold (0.0 – 1.0)", 0.299f, "Enemies can be executed when their HP is at or below this percentage");
			NormalLowHPColor = config.Bind<string>("Colors", "NormalLowHP", "#e3852d", "Color of normal enemies when HP is low");
			NormalHighHPColor = config.Bind<string>("Colors", "NormalHighHP", "#5de882", "Color of normal enemies when HP is high");
			EliteColor = config.Bind<string>("Colors", "Elite", "#5704d4", "Color of elite enemies");
			BackgroundNormalColor = config.Bind<string>("Colors", "BackgroundNormal", "#00000099", "Background color for normal enemies");
			BackgroundEliteColor = config.Bind<string>("Colors", "BackgroundElite", "#090017", "Background color for elite enemies");
		}
	}
}
namespace AtlyssExecuteHPIndicatorMod
{
	[BepInPlugin("com.BLKNeko.AtlyssExecuteHPIndicator", "com.BLKNeko.Atlyss Execute HP Indicator", "1.1.0")]
	public class AtlyssExecuteHPIndicatorPlugin : BaseUnityPlugin
	{
		public const string MODUID = "com.BLKNeko.AtlyssExecuteHPIndicator";

		public const string MODNAME = "com.BLKNeko.Atlyss Execute HP Indicator";

		public const string MODVERSION = "1.1.0";

		private int scanCounter;

		private static readonly Dictionary<Image, TrackedCreep> tracked = new Dictionary<Image, TrackedCreep>();

		private void Awake()
		{
			AtlyssExecuteHPIndicatorConfig.Init(((BaseUnityPlugin)this).Config);
		}

		private void FixedUpdate()
		{
			if (++scanCounter >= 30)
			{
				scanCounter = 0;
				ScanForCreeps();
				Cleanup();
			}
			UpdateBars();
		}

		private void ScanForCreeps()
		{
			CreepBehavior[] array = Object.FindObjectsOfType<CreepBehavior>();
			foreach (CreepBehavior val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Creep baseCreep = val._baseCreep;
				if ((Object)(object)baseCreep == (Object)null)
				{
					continue;
				}
				StatusEntityGUI component = ((Component)baseCreep).GetComponent<StatusEntityGUI>();
				if (!((Object)(object)component == (Object)null))
				{
					Image healthBarFill = StatusEntityGUIAccess.GetHealthBarFill(component);
					Image healthBarBackground = GetHealthBarBackground(component);
					if (!((Object)(object)healthBarFill == (Object)null) && !((Object)(object)healthBarBackground == (Object)null))
					{
						tracked[healthBarFill] = new TrackedCreep
						{
							Behavior = val,
							Foreground = healthBarFill,
							Background = healthBarBackground
						};
					}
				}
			}
		}

		private void UpdateBars()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			Color val = ColorUtils.Parse(AtlyssExecuteHPIndicatorConfig.NormalLowHPColor.Value);
			Color val2 = ColorUtils.Parse(AtlyssExecuteHPIndicatorConfig.NormalHighHPColor.Value);
			Color color = ColorUtils.Parse(AtlyssExecuteHPIndicatorConfig.EliteColor.Value);
			Color color2 = ColorUtils.Parse(AtlyssExecuteHPIndicatorConfig.BackgroundNormalColor.Value);
			Color color3 = ColorUtils.Parse(AtlyssExecuteHPIndicatorConfig.BackgroundEliteColor.Value);
			foreach (KeyValuePair<Image, TrackedCreep> item in tracked)
			{
				TrackedCreep value = item.Value;
				if (!((Object)(object)value.Behavior == (Object)null) && !((Object)(object)value.Foreground == (Object)null) && !((Object)(object)value.Background == (Object)null))
				{
					bool isElite = value.Behavior._scriptCreep._isElite;
					float fillAmount = value.Foreground.fillAmount;
					if (!isElite)
					{
						((Graphic)value.Foreground).color = ((fillAmount <= AtlyssExecuteHPIndicatorConfig.ExecuteHPPercent.Value) ? val : val2);
						((Graphic)value.Background).color = color2;
					}
					else
					{
						((Graphic)value.Foreground).color = color;
						((Graphic)value.Background).color = color3;
					}
				}
			}
		}

		private Image GetHealthBarBackground(StatusEntityGUI gui)
		{
			GameObject healthBarObject = StatusEntityGUIAccess.GetHealthBarObject(gui);
			if ((Object)(object)healthBarObject == (Object)null)
			{
				return null;
			}
			Transform val = healthBarObject.transform.Find("_healthbarFill");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return ((Component)val).GetComponent<Image>();
		}

		private void Cleanup()
		{
			List<Image> list = new List<Image>();
			foreach (KeyValuePair<Image, TrackedCreep> item in tracked)
			{
				if ((Object)(object)item.Key == (Object)null || (Object)(object)item.Value.Behavior == (Object)null || !Object.op_Implicit((Object)(object)((Component)item.Value.Behavior).gameObject))
				{
					list.Add(item.Key);
				}
			}
			foreach (Image item2 in list)
			{
				tracked.Remove(item2);
			}
		}
	}
}