Decompiled source of SimpleHealthBarMono v1.5.2

SimpleHealthBar-Mono.dll

Decompiled a month ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using FishNet;
using FishNet.Object;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ScheduleOne;
using ScheduleOne.DevUtilities;
using ScheduleOne.ItemFramework;
using ScheduleOne.NPCs;
using ScheduleOne.PlayerScripts;
using ScheduleOne.UI;
using ScheduleOne.UI.Phone;
using SimpleHealthBar;
using SimpleHealthBar.Helpers;
using SimpleHealthBar.NPCUtils;
using SimpleHealthBar.PlayerUtils;
using SimpleHealthBar.UI;
using TMPro;
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: MelonInfo(typeof(global::SimpleHealthBar.SimpleHealthBar), "SimpleHealthBar", "1.5.2", "iTidez", "https://www.nexusmods.com/schedule1/mods/1106")]
[assembly: MelonColor(1, 255, 0, 0)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyMetadata("NexusModID", "1106")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SimpleHealthBar-Mono")]
[assembly: AssemblyConfiguration("Release Mono")]
[assembly: AssemblyFileVersion("1.5.2.0")]
[assembly: AssemblyInformationalVersion("1.5.2")]
[assembly: AssemblyProduct("SimpleHealthBar-Mono")]
[assembly: AssemblyTitle("SimpleHealthBar-Mono")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.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 SimpleHealthBar
{
	public static class BuildInfo
	{
		public const string Name = "SimpleHealthBar";

		public const string Description = "Gives you a health bar above your inventory.";

		public const string Author = "iTidez";

		public const string Version = "1.5.2";

		public const string DownloadLink = "https://www.nexusmods.com/schedule1/mods/1106";
	}
	public class SimpleHealthBar : MelonMod
	{
		private static Instance Logger;

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			Preferences.Init();
			ModLogger.SetDebugEnabled(Preferences.EnableDebugLogging.Value);
			ModLogger.Info("SimpleHealthBar initialized successfully");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				ModLogger.Debug("Main scene loaded - starting initialization");
				MelonCoroutines.Start(Init());
				MelonCoroutines.Start(SafetyTimer());
			}
			else if (sceneName == "Menu")
			{
				PlayerHealthBarManager.Unload();
				NPCHealthManager.Unload();
				MultiplayerHandler.Unload();
			}
		}

		public override void OnUpdate()
		{
			PlayerHealthBarManager.OnUpdate();
			NPCHealthManager.OnUpdate();
			MultiplayerHandler.OnUpdate();
		}

		private IEnumerator SafetyTimer()
		{
			yield return Utils.WaitForSeconds(10f);
			if (!PlayerHealthBarManager.Initialized())
			{
				ModLogger.Warn("Safety timer triggered - managers not initialized, attempting fallback");
				ModLogger.Info("Current player state:");
				Utils.LogPlayerState();
				yield return FallbackInit();
			}
			else
			{
				ModLogger.Info("Safety timer: Managers already initialized successfully");
			}
		}

		private IEnumerator Init()
		{
			ModLogger.Info("Starting initialization - waiting for player to spawn...");
			Utils.LogPlayerState();
			yield return Utils.WaitForPlayerSpawned(Utils.ReturnNull());
			ModLogger.Info("Player detected - initializing health bar managers...");
			PlayerHealthBarManager.Init(Logger);
			NPCHealthManager.Init(Logger);
			MultiplayerHandler.Init(Logger);
			ModLogger.Info("All health bar managers initialized successfully!");
		}

		private void StartManagers()
		{
			PlayerHealthBarManager.Init(Logger);
			NPCHealthManager.Init(Logger);
			MultiplayerHandler.Init(Logger);
		}

		private IEnumerator FallbackInit()
		{
			ModLogger.Warn("Using fallback initialization - player detection may have failed");
			yield return Utils.WaitForSeconds(2f);
			if ((Object)(object)Player.Local != (Object)null && (Object)(object)((Component)Player.Local).gameObject != (Object)null)
			{
				ModLogger.Info("Player found in fallback - initializing managers");
				StartManagers();
			}
			else
			{
				ModLogger.Error("Player still not found in fallback - initialization failed");
			}
		}
	}
	public static class Preferences
	{
		public static MelonPreferences_Category Category;

		public static MelonPreferences_Entry<bool> FadeOutBar;

		public static MelonPreferences_Entry<bool> FadeHealthText;

		public static MelonPreferences_Entry<bool> ShowOnDamage;

		public static MelonPreferences_Category AnimationCategory;

		public static MelonPreferences_Entry<float> FadeDelay;

		public static MelonPreferences_Entry<float> FadeSpeed;

		public static MelonPreferences_Entry<float> FontSize;

		public static MelonPreferences_Category NPCHealthBar;

		public static MelonPreferences_Entry<bool> NPCHealthBarEnabled;

		public static MelonPreferences_Entry<bool> FadeOutNPCBar;

		public static MelonPreferences_Entry<float> NPCFadeOutDistance;

		public static MelonPreferences_Entry<float> NPCWorldSpaceRadius;

		public static MelonPreferences_Entry<float> NPCHeadOffset;

		public static MelonPreferences_Entry<float> NPCHealthBarScale;

		public static MelonPreferences_Category DebugCategory;

		public static MelonPreferences_Entry<bool> EnableDebugLogging;

		public static void Init()
		{
			Category = MelonPreferences.CreateCategory("SimpleHealthBar_HealthBar", "Bar Settings");
			AnimationCategory = MelonPreferences.CreateCategory("SimpleHealthBar_Animation", "Animation Settings");
			DebugCategory = MelonPreferences.CreateCategory("SimpleHealthBar_Debug", "Debug Settings");
			FadeOutBar = Category.CreateEntry<bool>("FadeOutBar", true, "Fade Out Health Bar", "Fades the health bar after a few seconds", false, false, (ValueValidator)null, (string)null);
			FadeHealthText = Category.CreateEntry<bool>("FadeOutHealthText", true, "Fade Out Health Text", "Fades out the text display showing your health", false, false, (ValueValidator)null, (string)null);
			ShowOnDamage = Category.CreateEntry<bool>("ShowOnDamage", true, "Show Bars Only When Damaged", "Hides player and NPC health bars while they are at full health", false, false, (ValueValidator)null, (string)null);
			FontSize = Category.CreateEntry<float>("FontSize", 14f, "Font Size", "Configures the font size of the text label HUD element", false, false, (ValueValidator)null, (string)null);
			FadeDelay = AnimationCategory.CreateEntry<float>("FadeDelay", 5f, "Fade Out Delay", "The amount of time in seconds it takes for the bar and text to disappear", false, false, (ValueValidator)null, (string)null);
			FadeSpeed = AnimationCategory.CreateEntry<float>("FadeSpeed", 2f, "Fade Speed", "Manages the speed of the fade transition", false, false, (ValueValidator)null, (string)null);
			NPCHealthBar = MelonPreferences.CreateCategory("SimpleHealthBar_NPCHealthBar", "NPC Health Bar");
			NPCHealthBarEnabled = NPCHealthBar.CreateEntry<bool>("NPCBarEnabled", true, "NPC Health Bar Enabled", "Enables the health bar for NPCs", false, false, (ValueValidator)null, (string)null);
			FadeOutNPCBar = NPCHealthBar.CreateEntry<bool>("FadeOutNPCBar", true, "Fade out NPC Health Bar", "Enables fading out the health bar for NPCs", false, false, (ValueValidator)null, (string)null);
			NPCFadeOutDistance = NPCHealthBar.CreateEntry<float>("NPCFadeOutDistance", 100f, "Distance from Player to Fade Out Bar", "Sets the distance from the player the NPC health bar should fade out", false, false, (ValueValidator)null, (string)null);
			NPCWorldSpaceRadius = NPCHealthBar.CreateEntry<float>("NPCWorldSpaceRadius", 50f, "NPC Health Bar Display Radius", "Maximum distance from player to display NPC health bars (in meters)", false, false, (ValueValidator)null, (string)null);
			NPCHeadOffset = NPCHealthBar.CreateEntry<float>("NPCHeadOffset", 2f, "NPC Head Offset", "Vertical offset above NPC transform for health bar position (in meters)", false, false, (ValueValidator)null, (string)null);
			NPCHealthBarScale = NPCHealthBar.CreateEntry<float>("NPCHealthBarScale", 1f, "NPC Health Bar Scale", "Multiplier for NPC health bar size (base scale: 0.005). Use simple values like 0.5, 1.0, 1.5, etc. Higher values = larger healthbars", false, false, (ValueValidator)null, (string)null);
			EnableDebugLogging = DebugCategory.CreateEntry<bool>("EnableDebugLogging", false, "Enable Debug Logging", "Enables detailed debug logging for troubleshooting", false, false, (ValueValidator)null, (string)null);
		}
	}
}
namespace SimpleHealthBar.UI
{
	public class HealthBar : IDisposable
	{
		private const float PlayerBarWidthPercent = 0.54f;

		private const float PlayerBarCenterX = 0.5f;

		private const float PlayerBarHeight = 18f;

		private const float PlayerCompassGap = 8f;

		private const float PlayerFallbackY = -86f;

		private GameObject HealthBarObject;

		private Slider HealthSlider;

		private Image BackgroundImage;

		private Image FillImage;

		private RectTransform HealthTextDisplay;

		private TextMeshProUGUI HealthText;

		private Transform CanvasRoot;

		private Vector2 AnchorMin;

		private Vector2 AnchorMax;

		private Vector2 AnchoredPos;

		private float LastHealthUpdateTime;

		private float PauseAccumulated;

		private float PauseStartTime;

		private float CurrentFill;

		private float FadeSpeed = 2f;

		private float FadeDelay = 4f;

		private float FontSize = 12f;

		private bool LastPhoneOpened;

		private bool IsHidden;

		private bool IsSpawned;

		public HealthBarType BarType { get; private set; }

		public HealthBar(HealthBarType id, Transform interactionCanvas)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01ce: 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_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			BarType = id;
			CanvasRoot = interactionCanvas;
			HealthBarObject = new GameObject(id.ToString() + "HealthBar");
			HealthBarObject.transform.SetParent(interactionCanvas, false);
			RectTransform val = HealthBarObject.AddComponent<RectTransform>();
			HealthSlider = HealthBarObject.AddComponent<Slider>();
			val.sizeDelta = new Vector2(0f, (id == HealthBarType.Player) ? 18f : 2f);
			HealthSlider.minValue = 0f;
			HealthSlider.maxValue = 100f;
			HealthSlider.value = 100f;
			CreatePlayerBackground(id, val);
			GameObject val2 = new GameObject(id.ToString() + "HealthBarFill");
			val2.transform.SetParent(((Component)val).transform, false);
			RectTransform val3 = val2.AddComponent<RectTransform>();
			FillImage = val2.AddComponent<Image>();
			((Graphic)FillImage).color = Color.red;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.offsetMin = Vector2.zero;
			val3.offsetMax = Vector2.zero;
			HealthSlider.fillRect = val3;
			GameObject val4 = new GameObject(id.ToString() + "TextGroup");
			val4.transform.SetParent((id == HealthBarType.Player) ? ((Component)val).transform : val2.transform, false);
			HealthTextDisplay = val4.AddComponent<RectTransform>();
			HealthTextDisplay.anchorMin = new Vector2(0f, 1f);
			HealthTextDisplay.anchorMax = new Vector2(0f, 1f);
			HealthTextDisplay.pivot = new Vector2(0f, 1f);
			HealthTextDisplay.sizeDelta = new Vector2(400f, 20f);
			HealthText = val4.AddComponent<TextMeshProUGUI>();
			((TMP_Text)HealthText).alignment = (TextAlignmentOptions)513;
			((TMP_Text)HealthText).fontSize = FontSize;
			SetupCustomDisplay();
			Shadow val5 = val4.AddComponent<Shadow>();
			val5.effectColor = Color.black;
			val5.effectDistance = new Vector2(1f, -1f);
		}

		public HealthBar(HealthBarType id, Transform interactionCanvas, Vector2 anchoredPos)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01ce: 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_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			BarType = id;
			CanvasRoot = interactionCanvas;
			HealthBarObject = new GameObject(id.ToString() + "HealthBar");
			HealthBarObject.transform.SetParent(interactionCanvas, false);
			RectTransform val = HealthBarObject.AddComponent<RectTransform>();
			HealthSlider = HealthBarObject.AddComponent<Slider>();
			val.sizeDelta = new Vector2(0f, (id == HealthBarType.Player) ? 18f : 2f);
			HealthSlider.minValue = 0f;
			HealthSlider.maxValue = 100f;
			HealthSlider.value = 0f;
			CreatePlayerBackground(id, val);
			GameObject val2 = new GameObject(id.ToString() + "HealthBarFill");
			val2.transform.SetParent(((Component)val).transform, false);
			RectTransform val3 = val2.AddComponent<RectTransform>();
			FillImage = val2.AddComponent<Image>();
			((Graphic)FillImage).color = Color.red;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.offsetMin = Vector2.zero;
			val3.offsetMax = Vector2.zero;
			HealthSlider.fillRect = val3;
			GameObject val4 = new GameObject(id.ToString() + "TextGroup");
			val4.transform.SetParent((id == HealthBarType.Player) ? ((Component)val).transform : val2.transform, false);
			HealthTextDisplay = val4.AddComponent<RectTransform>();
			HealthTextDisplay.anchorMin = new Vector2(0f, 1f);
			HealthTextDisplay.anchorMax = new Vector2(0f, 1f);
			HealthTextDisplay.pivot = new Vector2(0f, 1f);
			HealthTextDisplay.sizeDelta = new Vector2(400f, 20f);
			HealthText = val4.AddComponent<TextMeshProUGUI>();
			((TMP_Text)HealthText).alignment = (TextAlignmentOptions)513;
			((TMP_Text)HealthText).fontSize = FontSize;
			AnchoredPos = anchoredPos;
			SetupCustomDisplay();
			Shadow val5 = val4.AddComponent<Shadow>();
			val5.effectColor = Color.black;
			val5.effectDistance = new Vector2(1f, -1f);
		}

		private void SetupCustomDisplay()
		{
			//IL_0040: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_0185: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: 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)
			RectTransform component = HealthBarObject.GetComponent<RectTransform>();
			switch (BarType)
			{
			case HealthBarType.Player:
			{
				float num = 0.27f;
				AnchorMin = new Vector2(0.5f - num, 1f);
				AnchorMax = new Vector2(0.5f + num, 1f);
				AnchoredPos = GetPlayerAnchoredPosition(component);
				HealthTextDisplay.anchorMin = Vector2.zero;
				HealthTextDisplay.anchorMax = Vector2.one;
				HealthTextDisplay.pivot = new Vector2(0.5f, 0.5f);
				HealthTextDisplay.offsetMin = Vector2.zero;
				HealthTextDisplay.offsetMax = Vector2.zero;
				HealthTextDisplay.anchoredPosition = Vector2.zero;
				((TMP_Text)HealthText).alignment = (TextAlignmentOptions)514;
				((TMP_Text)HealthText).fontSize = Mathf.Min(Preferences.FontSize.Value, 14f);
				((Graphic)HealthText).color = Color.white;
				((TMP_Text)HealthText).outlineColor = Color32.op_Implicit(Color.black);
				((TMP_Text)HealthText).outlineWidth = 0.2f;
				((TMP_Text)HealthText).textWrappingMode = (TextWrappingModes)0;
				ModLogger.Debug("Player Healthbar created at " + ((object)Unsafe.As<Vector2, Vector2>(ref AnchoredPos)/*cast due to .constrained prefix*/).ToString());
				break;
			}
			case HealthBarType.NPC:
				AnchorMin = new Vector2(0.3f, 0f);
				AnchorMax = new Vector2(0.7f, 0f);
				AnchoredPos = new Vector2(5f, 1000f);
				HealthTextDisplay.anchoredPosition = new Vector2(300f, 20f);
				ModLogger.Debug("NPC Healthbar created at " + ((object)Unsafe.As<Vector2, Vector2>(ref AnchoredPos)/*cast due to .constrained prefix*/).ToString());
				break;
			case HealthBarType.Multiplayer:
				AnchorMin = new Vector2(0.8f, 0f);
				AnchorMax = new Vector2(0.99f, 0f);
				((TMP_Text)HealthText).fontSize = 10f;
				ModLogger.Debug("Multiplayer Healthbar created at " + ((object)Unsafe.As<Vector2, Vector2>(ref AnchoredPos)/*cast due to .constrained prefix*/).ToString());
				break;
			}
			component.anchorMin = AnchorMin;
			component.anchorMax = AnchorMax;
			component.anchoredPosition = AnchoredPos;
		}

		private void CreatePlayerBackground(HealthBarType id, RectTransform barBase)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (id == HealthBarType.Player)
			{
				GameObject val = new GameObject(id.ToString() + "HealthBarBackground");
				val.transform.SetParent(((Component)barBase).transform, false);
				RectTransform val2 = val.AddComponent<RectTransform>();
				BackgroundImage = val.AddComponent<Image>();
				((Graphic)BackgroundImage).color = new Color(0.12f, 0.12f, 0.12f, 0.9f);
				val2.anchorMin = Vector2.zero;
				val2.anchorMax = Vector2.one;
				val2.offsetMin = Vector2.zero;
				val2.offsetMax = Vector2.zero;
			}
		}

		private Vector2 GetPlayerAnchoredPosition(RectTransform barBase)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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)
			Transform canvasRoot = CanvasRoot;
			RectTransform val = (RectTransform)(object)((canvasRoot is RectTransform) ? canvasRoot : null);
			RectTransform val2 = FindRectTransformByName(CanvasRoot, "Compass");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return new Vector2(0f, -86f);
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			val2.GetWorldCorners(array);
			float num = float.MaxValue;
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val3 = ((Transform)val).InverseTransformPoint(array[i]);
				num = Mathf.Min(num, val3.y);
			}
			float num2 = num - 8f - barBase.sizeDelta.y * 0.5f;
			Rect rect = val.rect;
			return new Vector2(0f, num2 - ((Rect)(ref rect)).yMax);
		}

		private RectTransform FindRectTransformByName(Transform root, string namePart)
		{
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			if (((Object)root).name.IndexOf(namePart, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return (RectTransform)(object)((root is RectTransform) ? root : null);
			}
			for (int i = 0; i < root.childCount; i++)
			{
				RectTransform val = FindRectTransformByName(root.GetChild(i), namePart);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		public void SetSpawned(bool isSpawned)
		{
			IsSpawned = isSpawned;
		}

		public bool GetSpawned()
		{
			return IsSpawned;
		}

		public void SetAnchoredPosition(Vector2 anchoredPosition)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			AnchoredPos = anchoredPosition;
			AnchoredPos = anchoredPosition;
			RectTransform component = HealthBarObject.GetComponent<RectTransform>();
			component.anchoredPosition = anchoredPosition;
		}

		public Vector2 GetAnchoredPosition()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return AnchoredPos;
		}

		public void SetCurrentHealth(float health)
		{
			CurrentFill = health;
		}

		public float GetCurrentHealth()
		{
			return CurrentFill;
		}

		public void Update()
		{
			bool flag = (Object)(object)FillImage != (Object)null;
			bool flag2 = (Object)(object)HealthText != (Object)null;
			if (flag && flag2)
			{
				HealthBarType barType = BarType;
				HealthBarType healthBarType = barType;
				if (healthBarType == HealthBarType.NPC)
				{
					UpdateNPC();
				}
			}
		}

		public void Update(bool var)
		{
			switch (BarType)
			{
			case HealthBarType.Player:
				UpdatePlayer(var);
				break;
			case HealthBarType.Multiplayer:
				UpdateMultiplayer(var);
				break;
			}
		}

		private void UpdatePlayer(bool phoneOpen)
		{
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)FillImage != (Object)null;
			bool flag2 = (Object)(object)HealthText != (Object)null;
			if (phoneOpen)
			{
				if (!LastPhoneOpened)
				{
					LastHealthUpdateTime = Time.time;
				}
				LastPhoneOpened = true;
				if ((Object)(object)BackgroundImage != (Object)null)
				{
					Color color = ((Graphic)BackgroundImage).color;
					color.a = Mathf.Lerp(color.a, 0.9f, Time.deltaTime * 2f);
					((Graphic)BackgroundImage).color = color;
				}
				if (flag)
				{
					Color color2 = ((Graphic)FillImage).color;
					color2.a = Mathf.Lerp(color2.a, 1f, Time.deltaTime * 2f);
					((Graphic)FillImage).color = color2;
				}
				if (flag2)
				{
					((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, 1f, Time.deltaTime * 2f);
				}
				return;
			}
			if (LastPhoneOpened)
			{
				PauseAccumulated += Time.time - PauseStartTime;
				LastPhoneOpened = false;
			}
			float value = Mathf.Lerp(HealthSlider.value, CurrentFill, Time.deltaTime * FadeDelay);
			HealthSlider.value = value;
			float num = 1f;
			if (flag)
			{
				Color color3 = ((Graphic)FillImage).color;
				color3.a = Mathf.Lerp(color3.a, num, Time.deltaTime * FadeSpeed);
				((Graphic)FillImage).color = color3;
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				Color color4 = ((Graphic)BackgroundImage).color;
				color4.a = Mathf.Lerp(color4.a, num * 0.9f, Time.deltaTime * FadeSpeed);
				((Graphic)BackgroundImage).color = color4;
			}
			if (flag2)
			{
				((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, num, Time.deltaTime * FadeSpeed);
			}
		}

		private void UpdateNPC()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)FillImage != (Object)null;
			bool flag2 = (Object)(object)HealthText != (Object)null;
			if (!(flag && flag2))
			{
				return;
			}
			float value = Mathf.Lerp(HealthSlider.value, CurrentFill, Time.deltaTime * FadeDelay);
			HealthSlider.value = value;
			float num = Time.time - LastHealthUpdateTime;
			float num2 = 1f;
			if (Preferences.FadeHealthText.Value)
			{
				num2 = ((num > FadeDelay) ? 0f : 1f);
			}
			bool value2 = Preferences.FadeOutBar.Value;
			if (flag)
			{
				Color color = ((Graphic)FillImage).color;
				color.a = Mathf.Lerp(color.a, num2, Time.deltaTime * FadeSpeed);
				if (!value2)
				{
					color.a = 1f;
				}
				((Graphic)FillImage).color = color;
			}
			if (flag2)
			{
				if (!Preferences.FadeHealthText.Value)
				{
					((TMP_Text)HealthText).alpha = 1f;
				}
				else
				{
					((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, num2, Time.deltaTime * FadeSpeed);
				}
			}
		}

		private void UpdateMultiplayer(bool isSpawned)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)FillImage != (Object)null;
			bool flag2 = (Object)(object)HealthText != (Object)null;
			if (isSpawned)
			{
				float value = Mathf.Lerp(HealthSlider.value, CurrentFill, Time.deltaTime * FadeDelay);
				HealthSlider.value = value;
				bool value2 = Preferences.FadeOutBar.Value;
				if (flag)
				{
					Color color = ((Graphic)FillImage).color;
					color.a = 1f;
					((Graphic)FillImage).color = Color.Lerp(((Graphic)FillImage).color, color, Time.deltaTime * FadeSpeed);
				}
				if (flag2)
				{
					((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, 1f, Time.deltaTime * FadeSpeed);
				}
			}
			else
			{
				Hide();
			}
		}

		public void UpdateText()
		{
			CurrentFill = GetCurrentHealth();
			string text = $"{Mathf.FloorToInt(GetCurrentHealth())} / 100 HP";
			if (((TMP_Text)HealthText).text != text)
			{
				((TMP_Text)HealthText).text = text;
				LastHealthUpdateTime = Time.time;
			}
		}

		public void UpdateText(string name)
		{
			CurrentFill = GetCurrentHealth();
			string text = $"{name} - {Mathf.FloorToInt(GetCurrentHealth())} / 100 HP";
			if (CurrentFill == 0f)
			{
				((TMP_Text)HealthText).text = "";
			}
			if (((TMP_Text)HealthText).text != text)
			{
				((TMP_Text)HealthText).text = text;
				LastHealthUpdateTime = Time.time;
			}
		}

		public void Show()
		{
			switch (BarType)
			{
			case HealthBarType.Player:
				ShowPlayer();
				break;
			case HealthBarType.NPC:
				ShowNPC();
				break;
			case HealthBarType.Multiplayer:
				ShowMultiplayer();
				break;
			}
		}

		public void Hide()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)FillImage != (Object)null;
			bool flag2 = (Object)(object)HealthText != (Object)null;
			if (flag)
			{
				Color color = ((Graphic)FillImage).color;
				color.a = 0f;
				((Graphic)FillImage).color = Color.Lerp(((Graphic)FillImage).color, color, Time.deltaTime * FadeSpeed);
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				Color color2 = ((Graphic)BackgroundImage).color;
				color2.a = 0f;
				((Graphic)BackgroundImage).color = Color.Lerp(((Graphic)BackgroundImage).color, color2, Time.deltaTime * FadeSpeed);
			}
			if (flag2)
			{
				((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, 0f, Time.deltaTime * FadeSpeed);
			}
			IsHidden = true;
		}

		public void HideImmediately()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)FillImage != (Object)null)
			{
				Color color = ((Graphic)FillImage).color;
				color.a = 0f;
				((Graphic)FillImage).color = color;
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				Color color2 = ((Graphic)BackgroundImage).color;
				color2.a = 0f;
				((Graphic)BackgroundImage).color = color2;
			}
			if ((Object)(object)HealthText != (Object)null)
			{
				((TMP_Text)HealthText).alpha = 0f;
			}
			IsHidden = true;
		}

		public void ShowPlayer()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//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_0067: Unknown result type (might be due to invalid IL or missing references)
			//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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			LastHealthUpdateTime = Time.time;
			PauseAccumulated = 0f;
			bool flag = (Object)(object)FillImage != (Object)null;
			bool flag2 = (Object)(object)HealthText != (Object)null;
			if (flag)
			{
				Color color = ((Graphic)FillImage).color;
				color.a = 1f;
				((Graphic)FillImage).color = Color.Lerp(((Graphic)FillImage).color, color, FadeSpeed);
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				Color color2 = ((Graphic)BackgroundImage).color;
				color2.a = 0.9f;
				((Graphic)BackgroundImage).color = Color.Lerp(((Graphic)BackgroundImage).color, color2, FadeSpeed);
			}
			if (flag2)
			{
				((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, 1f, FadeSpeed);
			}
		}

		public void ShowNPC()
		{
			//IL_0039: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (Preferences.NPCHealthBarEnabled.Value)
			{
				LastHealthUpdateTime = Time.time;
				if ((Object)(object)FillImage != (Object)null)
				{
					Color color = ((Graphic)FillImage).color;
					color.a = 1f;
					((Graphic)FillImage).color = Color.Lerp(((Graphic)FillImage).color, color, FadeSpeed);
				}
				if ((Object)(object)HealthText != (Object)null)
				{
					((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, 1f, FadeSpeed);
				}
			}
		}

		public void ShowMultiplayer()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			if (!Preferences.FadeOutBar.Value)
			{
				LastHealthUpdateTime = Time.time;
				bool flag = (Object)(object)FillImage != (Object)null;
				bool flag2 = (Object)(object)HealthText != (Object)null;
				if (flag)
				{
					Color color = ((Graphic)FillImage).color;
					color.a = 1f;
					((Graphic)FillImage).color = Color.Lerp(((Graphic)FillImage).color, color, FadeSpeed);
				}
				if (flag2)
				{
					((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, 1f, FadeSpeed);
				}
			}
		}

		public void Dispose()
		{
			throw new NotImplementedException();
		}
	}
	public enum HealthBarType
	{
		Player,
		NPC,
		Multiplayer
	}
	public class WorldSpaceHealthBar
	{
		private const float PlayerMaxHealth = 100f;

		private const string LoadingPlayerName = "Loading player...";

		private GameObject CanvasObject;

		private Slider HealthSlider;

		private Image FillImage;

		private TextMeshProUGUI HealthText;

		private NPC TargetNPC;

		private Player TargetPlayer;

		private Transform TargetTransform;

		private float CurrentFill;

		private float FadeSpeed = 2f;

		private float FadeDelay = 4f;

		private Camera MainCamera;

		public WorldSpaceHealthBar(NPC npc)
		{
			if ((Object)(object)npc == (Object)null || (Object)(object)((Component)npc).transform == (Object)null)
			{
				ModLogger.Error("Cannot create world-space health bar: NPC or transform is null");
				return;
			}
			TargetNPC = npc;
			TargetTransform = ((Component)npc).transform;
			Create(npc.FullName);
		}

		public WorldSpaceHealthBar(Player player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)((Component)player).transform == (Object)null)
			{
				ModLogger.Error("Cannot create world-space health bar: player or transform is null");
				return;
			}
			TargetPlayer = player;
			TargetTransform = ((Component)player).transform;
			Create(GetDisplayName());
		}

		private void Create(string displayName)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			MainCamera = Camera.main;
			CanvasObject = new GameObject("WorldSpaceHealthBar_" + displayName);
			CanvasObject.transform.SetParent(TargetTransform, false);
			CanvasObject.transform.localPosition = new Vector3(0f, Preferences.NPCHeadOffset.Value, 0f);
			float num = 0.005f * Preferences.NPCHealthBarScale.Value;
			CanvasObject.transform.localScale = new Vector3(num, num, num);
			Canvas val = CanvasObject.AddComponent<Canvas>();
			val.renderMode = (RenderMode)2;
			val.sortingOrder = 100;
			CanvasScaler val2 = CanvasObject.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)0;
			val2.scaleFactor = 1f;
			CanvasObject.AddComponent<GraphicRaycaster>();
			GameObject val3 = new GameObject("HealthBarBase");
			val3.transform.SetParent(CanvasObject.transform, false);
			RectTransform val4 = val3.AddComponent<RectTransform>();
			val4.sizeDelta = new Vector2(120f, 6f);
			val4.anchoredPosition = Vector2.zero;
			((Transform)val4).localPosition = Vector3.zero;
			((Transform)val4).localRotation = Quaternion.identity;
			((Transform)val4).localScale = Vector3.one;
			HealthSlider = val3.AddComponent<Slider>();
			HealthSlider.minValue = 0f;
			HealthSlider.maxValue = 100f;
			GameObject val5 = new GameObject("HealthBarFill");
			val5.transform.SetParent(val3.transform, false);
			RectTransform val6 = val5.AddComponent<RectTransform>();
			FillImage = val5.AddComponent<Image>();
			((Graphic)FillImage).color = Color.red;
			val6.anchorMin = Vector2.zero;
			val6.anchorMax = Vector2.one;
			val6.offsetMin = Vector2.zero;
			val6.offsetMax = Vector2.zero;
			HealthSlider.fillRect = val6;
			GameObject val7 = new GameObject("HealthTextGroup");
			val7.transform.SetParent(val3.transform, false);
			RectTransform val8 = val7.AddComponent<RectTransform>();
			val8.anchorMin = new Vector2(0.5f, 0.5f);
			val8.anchorMax = new Vector2(0.5f, 0.5f);
			val8.pivot = new Vector2(0.5f, 0.5f);
			val8.sizeDelta = new Vector2(250f, 20f);
			val8.anchoredPosition = new Vector2(0f, 12f);
			HealthText = val7.AddComponent<TextMeshProUGUI>();
			((TMP_Text)HealthText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)HealthText).fontSize = 8f;
			val7.AddComponent<Shadow>().effectColor = Color.black;
			if (TryGetHealth(out var health))
			{
				CurrentFill = health;
				HealthSlider.value = health;
				UpdateText(GetDisplayName());
			}
			SetVisibilityImmediately(ShouldBeVisible());
			ModLogger.Debug("Created world-space health bar for " + displayName);
		}

		public void Update()
		{
			if (IsValid())
			{
				UpdateBillboard();
				if (TryGetHealth(out var health))
				{
					CurrentFill = health;
					UpdateText(GetDisplayName());
				}
				UpdateVisuals();
			}
		}

		private bool TryGetHealth(out float health)
		{
			if ((Object)(object)TargetNPC != (Object)null && (Object)(object)TargetNPC.Health != (Object)null)
			{
				health = TargetNPC.Health.Health;
				return true;
			}
			if ((Object)(object)TargetPlayer != (Object)null && (Object)(object)TargetPlayer.Health != (Object)null)
			{
				health = TargetPlayer.Health.CurrentHealth;
				return true;
			}
			health = 0f;
			return false;
		}

		private string GetDisplayName()
		{
			if ((Object)(object)TargetNPC != (Object)null)
			{
				return TargetNPC.FullName;
			}
			if ((Object)(object)TargetPlayer != (Object)null && !string.IsNullOrWhiteSpace(TargetPlayer.PlayerName))
			{
				return TargetPlayer.PlayerName;
			}
			return "Loading player...";
		}

		private void UpdateBillboard()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0070: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val;
			if ((Object)(object)Player.Local != (Object)null)
			{
				val = Player.Local.CameraPosition;
			}
			else if ((Object)(object)MainCamera != (Object)null)
			{
				val = ((Component)MainCamera).transform.position;
			}
			else
			{
				MainCamera = Camera.main;
				if ((Object)(object)MainCamera == (Object)null)
				{
					return;
				}
				val = ((Component)MainCamera).transform.position;
			}
			Vector3 val2 = val - CanvasObject.transform.position;
			if (((Vector3)(ref val2)).sqrMagnitude > 0.001f)
			{
				CanvasObject.transform.rotation = Quaternion.LookRotation(-val2);
			}
		}

		private void UpdateVisuals()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			if (!((Object)(object)FillImage == (Object)null) && !((Object)(object)HealthText == (Object)null))
			{
				float value = Mathf.Lerp(HealthSlider.value, CurrentFill, Time.deltaTime * FadeDelay);
				HealthSlider.value = value;
				float num = (ShouldBeVisible() ? 1f : 0f);
				Color color = ((Graphic)FillImage).color;
				color.a = Mathf.Lerp(color.a, num, Time.deltaTime * FadeSpeed);
				((Graphic)FillImage).color = color;
				((TMP_Text)HealthText).alpha = Mathf.Lerp(((TMP_Text)HealthText).alpha, num, Time.deltaTime * FadeSpeed);
			}
		}

		private bool ShouldBeVisible()
		{
			if ((Object)(object)TargetNPC != (Object)null)
			{
				if (!Preferences.NPCHealthBarEnabled.Value || (Object)(object)TargetNPC.Health == (Object)null)
				{
					return false;
				}
				if (TargetNPC.Health.IsDead || TargetNPC.Health.IsKnockedOut || TargetNPC.isInBuilding)
				{
					return false;
				}
				return !Preferences.ShowOnDamage.Value || TargetNPC.Health.MaxHealth <= 0f || TargetNPC.Health.Health < TargetNPC.Health.MaxHealth;
			}
			if ((Object)(object)TargetPlayer == (Object)null || (Object)(object)TargetPlayer.Health == (Object)null || ((NetworkBehaviour)TargetPlayer).IsOffline)
			{
				return false;
			}
			return !Preferences.ShowOnDamage.Value || TargetPlayer.Health.CurrentHealth < 100f;
		}

		private void SetVisibilityImmediately(bool isVisible)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			float num = (isVisible ? 1f : 0f);
			if ((Object)(object)FillImage != (Object)null)
			{
				Color color = ((Graphic)FillImage).color;
				color.a = num;
				((Graphic)FillImage).color = color;
			}
			if ((Object)(object)HealthText != (Object)null)
			{
				((TMP_Text)HealthText).alpha = num;
			}
		}

		private void UpdateText(string name)
		{
			if (!((Object)(object)HealthText == (Object)null))
			{
				((TMP_Text)HealthText).text = ((CurrentFill <= 0f) ? string.Empty : $"{name} - {Mathf.FloorToInt(CurrentFill)} / 100 HP");
			}
		}

		public void Hide()
		{
			SetVisibilityImmediately(isVisible: false);
		}

		public void Destroy()
		{
			if ((Object)(object)CanvasObject != (Object)null)
			{
				Object.Destroy((Object)(object)CanvasObject);
				CanvasObject = null;
			}
		}

		public bool IsValid()
		{
			return (Object)(object)CanvasObject != (Object)null && (Object)(object)TargetTransform != (Object)null && ((Object)(object)TargetNPC != (Object)null || (Object)(object)TargetPlayer != (Object)null);
		}

		public NPC GetNPC()
		{
			return TargetNPC;
		}
	}
}
namespace SimpleHealthBar.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("SimpleHealthBar.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace SimpleHealthBar.PlayerUtils
{
	internal class MultiplayerHandler
	{
		private static readonly Dictionary<Player, WorldSpaceHealthBar> MultiplayerHealthbars = new Dictionary<Player, WorldSpaceHealthBar>();

		private static bool HasInitialized;

		public static void Init(Instance logger)
		{
			HasInitialized = true;
			CheckCreate();
			ModLogger.Info("World-space multiplayer health bar handler initialized");
		}

		public static void OnUpdate()
		{
			if (!HasInitialized)
			{
				return;
			}
			CheckCreate();
			foreach (Player player in Player.PlayerList)
			{
				if (!((Object)(object)player == (Object)null) && !player.IsLocalPlayer && MultiplayerHealthbars.TryGetValue(player, out var value))
				{
					if (IsReadyForHealthbar(player) && value.IsValid())
					{
						value.Update();
					}
					else
					{
						value.Hide();
					}
				}
			}
		}

		public static void CheckCreate()
		{
			if (!HasInitialized)
			{
				return;
			}
			HashSet<Player> hashSet = new HashSet<Player>();
			foreach (Player player in Player.PlayerList)
			{
				if ((Object)(object)player == (Object)null || player.IsLocalPlayer)
				{
					continue;
				}
				hashSet.Add(player);
				if (((NetworkBehaviour)player).IsOffline)
				{
					RemoveHealthbar(player);
					continue;
				}
				if (MultiplayerHealthbars.TryGetValue(player, out var value))
				{
					if (value.IsValid())
					{
						continue;
					}
					RemoveHealthbar(player);
				}
				if (IsReadyForHealthbar(player))
				{
					CreatePlayerHealthbar(player);
				}
			}
			List<Player> list = new List<Player>();
			foreach (Player key in MultiplayerHealthbars.Keys)
			{
				if (!hashSet.Contains(key))
				{
					list.Add(key);
				}
			}
			foreach (Player item in list)
			{
				RemoveHealthbar(item);
			}
		}

		private static bool IsReadyForHealthbar(Player player)
		{
			return (Object)(object)player != (Object)null && !player.IsLocalPlayer && ((NetworkBehaviour)player).IsSpawned && (Object)(object)player.Health != (Object)null && (Object)(object)((Component)player).transform != (Object)null;
		}

		private static void CreatePlayerHealthbar(Player player)
		{
			if (IsReadyForHealthbar(player) && !MultiplayerHealthbars.ContainsKey(player))
			{
				WorldSpaceHealthBar worldSpaceHealthBar = new WorldSpaceHealthBar(player);
				if (worldSpaceHealthBar.IsValid())
				{
					MultiplayerHealthbars[player] = worldSpaceHealthBar;
					ModLogger.Debug("Created world-space health bar for multiplayer player '" + player.PlayerName + "'");
				}
			}
		}

		private static void RemoveHealthbar(Player player)
		{
			if (MultiplayerHealthbars.TryGetValue(player, out var value))
			{
				value.Destroy();
				MultiplayerHealthbars.Remove(player);
			}
		}

		public static void Unload()
		{
			foreach (WorldSpaceHealthBar value in MultiplayerHealthbars.Values)
			{
				value.Destroy();
			}
			MultiplayerHealthbars.Clear();
			HasInitialized = false;
		}

		public static bool Initialized()
		{
			return HasInitialized;
		}
	}
	internal class PlayerHealthBarManager
	{
		private const float FullHealth = 100f;

		private static Player LocalPlayer;

		private static HealthBar HealthBar;

		private static bool HasInitialized;

		public static void Init(Instance logger)
		{
			ModLogger.Info("Initializing Player Health Bar");
			LocalPlayer = Player.Local;
			HealthBar = new HealthBar(HealthBarType.Player, ((Component)Singleton<HUD>.instance).transform);
			HasInitialized = true;
			ModLogger.Info("Player Healthbar Initialized!");
		}

		public static void OnUpdate()
		{
			if (!HasInitialized)
			{
				return;
			}
			Phone instance = PlayerSingleton<Phone>.Instance;
			bool var = (Object)(object)instance != (Object)null && instance.IsOpen;
			if (HealthBar == null || !((Object)(object)LocalPlayer != (Object)null))
			{
				return;
			}
			float currentHealth = LocalPlayer.Health.CurrentHealth;
			float currentHealth2 = HealthBar.GetCurrentHealth();
			if (currentHealth != currentHealth2)
			{
				ModLogger.Debug($"Health changed from {currentHealth2} to {currentHealth}");
				HealthBar.SetCurrentHealth(currentHealth);
				HealthBar.UpdateText();
			}
			if (Preferences.ShowOnDamage.Value && currentHealth >= 100f)
			{
				HealthBar.HideImmediately();
				return;
			}
			if (currentHealth != currentHealth2)
			{
				HealthBar.Show();
			}
			HealthBar.Update(var);
		}

		public static void Unload()
		{
			HasInitialized = false;
			HealthBar = null;
		}

		public static bool Initialized()
		{
			return HasInitialized;
		}
	}
}
namespace SimpleHealthBar.NPCUtils
{
	public static class NPCHealthManager
	{
		private static NPCManager NPCManager;

		private static Dictionary<NPC, WorldSpaceHealthBar> HealthBars;

		private static bool IsInitialized;

		public static void Init(Instance logger)
		{
			IsInitialized = NetworkSingleton<NPCManager>.InstanceExists;
			if (IsInitialized)
			{
				NPCManager = NetworkSingleton<NPCManager>.Instance;
				HealthBars = new Dictionary<NPC, WorldSpaceHealthBar>();
				ModLogger.Info("NPC Healthbar Manager Initialized!");
			}
			else
			{
				ModLogger.Error("NPCManager not found, aborting NPC health reporting!");
			}
		}

		private static float GetSquaredDistanceFromPlayer(NPC npc)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)npc == (Object)null || (Object)(object)Player.Local == (Object)null)
			{
				return float.MaxValue;
			}
			if ((Object)(object)npc.Movement == (Object)null || (Object)(object)npc.Health == (Object)null)
			{
				return float.MaxValue;
			}
			Vector3 position = ((Component)npc).transform.position;
			Vector3 val = position - Player.Local.CameraPosition;
			return ((Vector3)(ref val)).sqrMagnitude;
		}

		public static void OnUpdate()
		{
			if (!IsInitialized || HealthBars == null || (Object)(object)NPCManager == (Object)null)
			{
				return;
			}
			if (!Preferences.NPCHealthBarEnabled.Value)
			{
				CleanupAllHealthbars();
				return;
			}
			float value = Preferences.NPCWorldSpaceRadius.Value;
			value *= value;
			HashSet<NPC> hashSet = new HashSet<NPC>();
			foreach (NPC item in NPCManager.NPCRegistry)
			{
				if ((Object)(object)item == (Object)null || (Object)(object)item.Health == (Object)null || (Object)(object)((Component)item).transform == (Object)null)
				{
					continue;
				}
				float squaredDistanceFromPlayer = GetSquaredDistanceFromPlayer(item);
				if (!(squaredDistanceFromPlayer <= value))
				{
					continue;
				}
				hashSet.Add(item);
				if (!HealthBars.ContainsKey(item))
				{
					try
					{
						WorldSpaceHealthBar value2 = new WorldSpaceHealthBar(item);
						HealthBars[item] = value2;
						ModLogger.Debug("Created health bar for " + item.FullName);
					}
					catch (Exception ex)
					{
						ModLogger.Error("Failed to create health bar for " + item.FullName + ": " + ex.Message);
					}
				}
				else
				{
					WorldSpaceHealthBar worldSpaceHealthBar = HealthBars[item];
					if (worldSpaceHealthBar != null && worldSpaceHealthBar.IsValid())
					{
						worldSpaceHealthBar.Update();
						continue;
					}
					HealthBars.Remove(item);
					worldSpaceHealthBar?.Destroy();
				}
			}
			List<NPC> list = new List<NPC>();
			foreach (KeyValuePair<NPC, WorldSpaceHealthBar> healthBar in HealthBars)
			{
				NPC key = healthBar.Key;
				WorldSpaceHealthBar value3 = healthBar.Value;
				if ((Object)(object)key == (Object)null || (Object)(object)((Component)key).transform == (Object)null || !hashSet.Contains(key))
				{
					list.Add(key);
					value3?.Destroy();
				}
			}
			foreach (NPC item2 in list)
			{
				HealthBars.Remove(item2);
			}
		}

		public static void Unload()
		{
			CleanupAllHealthbars();
			IsInitialized = false;
			HealthBars = null;
		}

		private static void CleanupAllHealthbars()
		{
			if (HealthBars == null)
			{
				return;
			}
			foreach (KeyValuePair<NPC, WorldSpaceHealthBar> healthBar in HealthBars)
			{
				if (healthBar.Value != null)
				{
					healthBar.Value.Destroy();
				}
			}
			HealthBars.Clear();
		}

		public static bool Initialized()
		{
			return IsInitialized;
		}
	}
}
namespace SimpleHealthBar.Helpers
{
	public static class MelonLoggerExtensions
	{
		private static string GetLoggerName(Instance logger)
		{
			return typeof(Instance).GetField("Name", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(logger) as string;
		}

		private static void InvokeNativeMsg(Color namesectionColor, Color textColor, string nameSection, string message)
		{
			typeof(MelonLogger).GetMethod("NativeMsg", BindingFlags.Static | BindingFlags.NonPublic)?.Invoke(null, new object[5]
			{
				namesectionColor,
				textColor,
				nameSection,
				message ?? "null",
				false
			});
		}

		private static string GetCallerInfo()
		{
			StackTrace stackTrace = new StackTrace();
			for (int i = 2; i < stackTrace.FrameCount; i++)
			{
				StackFrame frame = stackTrace.GetFrame(i);
				MethodBase method = frame.GetMethod();
				if (!(method?.DeclaringType == null))
				{
					return method.DeclaringType.FullName + "." + method.Name;
				}
			}
			return "unknown";
		}
	}
	public static class ModLogger
	{
		private static Instance Logger = new Instance("SimpleHealthBar-ModLogger");

		private static bool IsDebugEnabled = false;

		public static void SetDebugEnabled(bool enabled)
		{
			IsDebugEnabled = enabled;
		}

		public static void Debug(string message)
		{
			if (IsDebugEnabled)
			{
				Logger.Msg("[DEBUG] " + message);
			}
		}

		public static void Error(string message)
		{
			Logger.Error(message);
		}

		public static void Warn(string message)
		{
			Logger.Warning(message);
		}

		public static void Info(string message)
		{
			Logger.Msg(message);
		}
	}
	public static class Il2CppListExtensions
	{
		public static IEnumerable<T> AsEnumerable<T>(this List<T> list)
		{
			return list ?? new List<T>();
		}
	}
	public static class Utils
	{
		public static T? FindObjectByName<T>(string objectName) where T : Object
		{
			try
			{
				T[] array = Resources.FindObjectsOfTypeAll<T>();
				foreach (T val in array)
				{
					if (!(((Object)val).name != objectName))
					{
						return val;
					}
				}
				return default(T);
			}
			catch (Exception ex)
			{
				ModLogger.Error("Error finding " + typeof(T).Name + " '" + objectName + "': " + ex.Message);
				return default(T);
			}
		}

		public static List<T> GetAllComponentsInChildrenRecursive<T>(GameObject obj) where T : Component
		{
			List<T> list = new List<T>();
			if ((Object)(object)obj == (Object)null)
			{
				return list;
			}
			T[] components = obj.GetComponents<T>();
			if (components.Length != 0)
			{
				list.AddRange(components);
			}
			for (int i = 0; i < obj.transform.childCount; i++)
			{
				Transform child = obj.transform.GetChild(i);
				list.AddRange(GetAllComponentsInChildrenRecursive<T>(((Component)child).gameObject));
			}
			return list;
		}

		public static bool Is<T>(object obj, out T result) where T : class
		{
			if (obj is T val)
			{
				result = val;
				return true;
			}
			result = null;
			return false;
		}

		public static List<StorableItemDefinition> GetAllStorableItemDefinitions()
		{
			List<ItemRegister> list = Singleton<Registry>.Instance.ItemRegistry.ToList();
			List<StorableItemDefinition> list2 = new List<StorableItemDefinition>();
			foreach (ItemRegister item in list)
			{
				if ((Object)(object)item.Definition != (Object)null && Is<StorableItemDefinition>(item.Definition, out var result))
				{
					list2.Add(result);
				}
				else
				{
					ModLogger.Warn("Definition " + ((object)item.Definition)?.GetType().FullName + " is not a StorableItemDefinition");
				}
			}
			return list2.ToList();
		}

		public static IEnumerator WaitForPlayer(IEnumerator routine)
		{
			while ((Object)(object)Player.Local == (Object)null || (Object)(object)((Component)Player.Local).gameObject == (Object)null)
			{
				yield return null;
			}
			MelonCoroutines.Start(routine);
		}

		public static IEnumerator WaitForPlayerSpawned(IEnumerator routine)
		{
			float startTime = Time.time;
			float timeout = 30f;
			ModLogger.Info("WaitForPlayerSpawned started - waiting for player to be fully spawned...");
			while (Time.time - startTime < timeout)
			{
				if ((Object)(object)Player.Local != (Object)null && (Object)(object)((Component)Player.Local).gameObject != (Object)null)
				{
					if (((Component)Player.Local).gameObject.activeInHierarchy && (Object)(object)Player.Local.Health != (Object)null)
					{
						ModLogger.Info("Player fully spawned on Mono - starting initialization");
						break;
					}
					if ((Object)(object)((Component)Player.Local).gameObject == (Object)null)
					{
						ModLogger.Info("Player.Local.gameObject is null");
					}
					else if (!((Component)Player.Local).gameObject.activeInHierarchy)
					{
						ModLogger.Info("Player.Local.gameObject is not active");
					}
					else if ((Object)(object)Player.Local.Health == (Object)null)
					{
						ModLogger.Info("Player.Local.Health is null");
					}
				}
				else if ((Object)(object)Player.Local == (Object)null)
				{
					ModLogger.Info("Player.Local is null");
				}
				else if ((Object)(object)((Component)Player.Local).gameObject == (Object)null)
				{
					ModLogger.Info("Player.Local.gameObject is null");
				}
				yield return WaitForSeconds(0.1f);
			}
			if (Time.time - startTime >= timeout)
			{
				ModLogger.Warn("Timeout waiting for player to spawn - proceeding anyway");
			}
			MelonCoroutines.Start(routine);
		}

		public static void LogPlayerState()
		{
			try
			{
				if ((Object)(object)Player.Local == (Object)null)
				{
					ModLogger.Debug("Player.Local is null");
					return;
				}
				ModLogger.Info("Player.Local found: " + ((object)Player.Local).GetType().FullName);
				if ((Object)(object)((Component)Player.Local).gameObject == (Object)null)
				{
					ModLogger.Debug("Player.Local.gameObject is null");
					return;
				}
				ModLogger.Info($"Player.Local.gameObject: {((Object)((Component)Player.Local).gameObject).name} (Active: {((Component)Player.Local).gameObject.activeInHierarchy})");
				if ((Object)(object)Player.Local.Health == (Object)null)
				{
					ModLogger.Debug("Player.Local.Health is null");
				}
				else
				{
					ModLogger.Info("Player.Local.Health: " + ((object)Player.Local.Health).GetType().FullName);
				}
			}
			catch (Exception ex)
			{
				ModLogger.Error("Error logging player state: " + ex.Message);
			}
		}

		public static IEnumerator WaitForNetwork(IEnumerator routine)
		{
			while (!InstanceFinder.IsServer && !InstanceFinder.IsClient)
			{
				yield return null;
			}
			MelonCoroutines.Start(routine);
		}

		public static IEnumerator WaitForNotNull(object? obj, float timeout = float.NaN, Action? onTimeout = null, Action? onFinish = null)
		{
			float startTime = Time.time;
			while (obj == null)
			{
				if (!float.IsNaN(timeout) && Time.time - startTime > timeout)
				{
					onTimeout?.Invoke();
					yield break;
				}
				yield return null;
			}
			onFinish?.Invoke();
		}

		public static IEnumerator ReturnNull()
		{
			yield return null;
		}

		public static IEnumerator WaitForSeconds(float seconds)
		{
			float startTime = Time.time;
			while (Time.time - startTime < seconds)
			{
				yield return null;
			}
		}

		public static IEnumerator WaitForNetworkSingleton<T>(IEnumerator coroutine) where T : NetworkSingleton<T>
		{
			while (!NetworkSingleton<T>.InstanceExists)
			{
				yield return null;
			}
			yield return coroutine;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}