Decompiled source of EnemyHealthBars v1.1.0

NoteBoxz.EnemyHealthBars.dll

Decompiled 2 hours 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.Configuration;
using BepInEx.Logging;
using EnemyHealthBars.Scripts;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
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("DissonanceVoip")]
[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.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("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("NoteBoxz.EnemyHealthBars")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EnemyHealthBars")]
[assembly: AssemblyTitle("NoteBoxz.EnemyHealthBars")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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
{
	[BepInPlugin("NoteBoxz.EnemyHealthBars", "EnemyHealthBars", "1.0.0")]
	public class EnemyHealthBars : BaseUnityPlugin
	{
		public enum HPLayoutEnum
		{
			Bar,
			Circle
		}

		public enum VisibiltySettings
		{
			AlwaysShow,
			OnlyShowWhenDamaged
		}

		internal static ConfigEntry<float> VisDistance;

		internal static ConfigEntry<float> VisDuration;

		internal static ConfigEntry<float> DefultYoffset;

		internal static ConfigEntry<float> HPScale;

		internal static ConfigEntry<string> OverrideOffset;

		internal static ConfigEntry<string> Color1;

		internal static ConfigEntry<string> Color2;

		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 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");
			Logger.LogInfo((object)"NoteBoxz.EnemyHealthBars v1.0.0 has loaded!");
		}

		public void BindConfigs()
		{
			HPLayout = ((BaseUnityPlugin)this).Config.Bind<HPLayoutEnum>("Settings", "HP Layout", HPLayoutEnum.Bar, "The way the HP Bar will look");
			VisSettings = ((BaseUnityPlugin)this).Config.Bind<VisibiltySettings>("Settings", "Visibilty Settings", VisibiltySettings.OnlyShowWhenDamaged, "");
			VisSettings.SettingChanged += delegate
			{
				UpdateAllBars();
			};
			VisDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Visibilty Distance", 12f, "");
			VisDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Visibilty Duration", 5f, "");
			BlackList = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Enemy Blacklist", "Pikmin,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");
			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) (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) (255,0,0,255)");
		}

		public void UpdateAllBars()
		{
			try
			{
				HealthBar[] array = Object.FindObjectsOfType<HealthBar>();
				HealthBar[] array2 = array;
				foreach (HealthBar healthBar in array2)
				{
					healthBar.UpdateLayoutVisibilty();
				}
			}
			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, "assets");
			assetBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)assetBundle == (Object)null)
			{
				throw new InvalidOperationException("Failed to load AssetBundle.");
			}
		}

		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.0.0";
	}
}
namespace EnemyHealthBars.Scripts
{
	public class HealthBar : MonoBehaviour
	{
		public EnemyAI AI = null;

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

		public HPLayout CurLayout = null;

		public Vector3 Offset;

		public float NormalizedHP;

		private int InitalHP;

		public float Timer;

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

		public void Update()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)AI == (Object)null))
			{
				CurLayout = Layouts[(int)EnemyHealthBars.HPLayout.Value];
				((Component)this).transform.localPosition = Offset;
				NormalizedHP = (float)AI.enemyHP / (float)InitalHP;
				if (((Component)CurLayout).gameObject.activeSelf)
				{
					CurLayout.Bar.fillAmount = NormalizedHP;
				}
			}
		}

		public void LateUpdate()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localScale = new Vector3(EnemyHealthBars.HPScale.Value, EnemyHealthBars.HPScale.Value, EnemyHealthBars.HPScale.Value);
			if ((Object)(object)CurLayout == (Object)null)
			{
				return;
			}
			if ((Object)(object)CurLayout.Bar != (Object)null)
			{
				Color? val = null;
				val = EnemyHealthBars.ParseColor(EnemyHealthBars.Color1.Value);
				if (val.HasValue)
				{
					((Graphic)CurLayout.Bar).color = val.Value;
				}
			}
			if ((Object)(object)CurLayout.BottomBar != (Object)null)
			{
				Color? val2 = null;
				val2 = EnemyHealthBars.ParseColor(EnemyHealthBars.Color2.Value);
				if (val2.HasValue)
				{
					((Graphic)CurLayout.BottomBar).color = val2.Value;
				}
			}
			switch (EnemyHealthBars.VisSettings.Value)
			{
			case EnemyHealthBars.VisibiltySettings.AlwaysShow:
				((Component)CurLayout).gameObject.SetActive((Object)(object)AI != (Object)null && !AI.isEnemyDead && Vector3.Distance(((Component)StartOfRound.Instance.localPlayerController).transform.position, ((Component)this).transform.position) < EnemyHealthBars.VisDistance.Value);
				break;
			case EnemyHealthBars.VisibiltySettings.OnlyShowWhenDamaged:
				((Component)CurLayout).gameObject.SetActive(Timer > 0f);
				if (Timer > 0f)
				{
					Timer -= Time.deltaTime;
				}
				break;
			}
		}

		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);
				}
			}
		}
	}
	public class HPLayout : MonoBehaviour
	{
		public Image Bar = null;

		public Image BottomBar = null;
	}
	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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			if (!EnemyHealthBars.GetParsedAttackBlacklist().Contains(__instance.enemyType.enemyName))
			{
				HealthBar component = Object.Instantiate<GameObject>(EnemyHealthBars.HPBarPrefab, ((Component)__instance).transform).GetComponent<HealthBar>();
				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);
				}
			}
		}

		[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)
		{
		}
	}
}