Decompiled source of StaminaStats v1.1.5

plugins/com.StaminaStats.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.StaminaStats")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.5.0")]
[assembly: AssemblyInformationalVersion("1.1.5")]
[assembly: AssemblyProduct("com.StaminaStats")]
[assembly: AssemblyTitle("StaminaStats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.5.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace StaminaStats
{
	[BepInPlugin("com.StaminaStats", "StaminaStats", "1.1.5")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(StaminaBar), "Update")]
		private class StaminaBarPatch
		{
			private static void Postfix(StaminaBar __instance)
			{
				try
				{
					if (!((Object)(object)Character.observedCharacter == (Object)null))
					{
						if (!_elementsCreated || (Object)(object)_staminaTextContainer == (Object)null)
						{
							CreateStaminaTextElements(__instance);
							_elementsCreated = true;
						}
						UpdateStaminaText(__instance);
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Error in StaminaBar patch: " + ex.Message));
				}
			}
		}

		[HarmonyPatch(typeof(StaminaBar), "Start")]
		private class StaminaBarStartPatch
		{
			private static void Postfix(StaminaBar __instance)
			{
				try
				{
					if (_verboseLogging.Value)
					{
						Log.LogInfo((object)"StaminaBar Start detected - ensuring UI is reset");
					}
					if (__instance.afflictions != null && __instance.afflictions.Length != 0 && _afflictionTexts.Count > 0)
					{
						ResetAfflictionUI();
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Error in StaminaBar Start patch: " + ex.Message));
				}
			}
		}

		[HarmonyPatch(typeof(BarAffliction), "UpdateAffliction")]
		private class BarAfflictionPatch
		{
			private static void Postfix(BarAffliction __instance, StaminaBar bar)
			{
				try
				{
					if (!((Object)(object)Character.observedCharacter == (Object)null))
					{
						UpdateAfflictionText(__instance, bar);
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Error in BarAffliction patch: " + ex.Message));
				}
			}
		}

		[HarmonyPatch(typeof(StaminaBar), "ChangeBar")]
		private class StaminaBarChangeBarPatch
		{
			private static void Postfix(StaminaBar __instance)
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: 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_0125: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if ((Object)(object)Character.observedCharacter == (Object)null)
					{
						return;
					}
					if (_verboseLogging.Value)
					{
						Log.LogInfo((object)"StaminaBar ChangeBar called, enumerating afflictions:");
						for (int i = 0; i < __instance.afflictions.Length; i++)
						{
							BarAffliction val = __instance.afflictions[i];
							bool activeSelf = ((Component)val).gameObject.activeSelf;
							STATUSTYPE afflictionType = val.afflictionType;
							float num = Character.observedCharacter.refs.afflictions.GetCurrentStatus(afflictionType) * 100f;
							Log.LogInfo((object)$"  - Affliction {i}: {afflictionType}, Active: {activeSelf}, Value: {num:F0}%, Width: {val.width}");
						}
					}
					foreach (STATUSTYPE value in Enum.GetValues(typeof(STATUSTYPE)))
					{
						float currentStatus = Character.observedCharacter.refs.afflictions.GetCurrentStatus(value);
						if (currentStatus > 0f && !_afflictionTexts.ContainsKey(value))
						{
							BarAffliction val3 = FindAffliction(__instance, value);
							if ((Object)(object)val3 != (Object)null)
							{
								UpdateAfflictionText(val3, __instance);
							}
						}
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Error in StaminaBar ChangeBar patch: " + ex.Message));
				}
			}
		}

		public class AfflictionTextTracker : MonoBehaviour
		{
			private BarAffliction _affliction;

			private RectTransform _textRect;

			private float _verticalOffset;

			private STATUSTYPE _statusType;

			public void Initialize(BarAffliction affliction, float verticalOffset)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: 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)
				_affliction = affliction;
				_textRect = ((Component)this).GetComponent<RectTransform>();
				_verticalOffset = verticalOffset;
				_statusType = affliction.afflictionType;
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)$"Initialized AfflictionTextTracker for {_statusType}");
				}
			}

			public void UpdateWidth(float width)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_textRect != (Object)null)
				{
					_textRect.sizeDelta = new Vector2(width, _textRect.sizeDelta.y);
				}
			}

			public void UpdateAffliction(BarAffliction newAffliction)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)newAffliction != (Object)null && (Object)(object)_affliction != (Object)(object)newAffliction)
				{
					_affliction = newAffliction;
					if (_verboseLogging.Value)
					{
						Log.LogInfo((object)$"Updated affliction reference for {_statusType}");
					}
				}
			}

			private void LateUpdate()
			{
				//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_004e: 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)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_affliction == (Object)null || (Object)(object)_textRect == (Object)null)
				{
					return;
				}
				Canvas componentInParent = ((Component)_affliction).GetComponentInParent<Canvas>();
				if (!((Object)(object)componentInParent != (Object)null))
				{
					return;
				}
				RectTransform component = ((Component)_affliction).GetComponent<RectTransform>();
				Vector3 position = ((Transform)component).position;
				((Transform)_textRect).position = new Vector3(position.x, position.y + _verticalOffset, ((Transform)_textRect).position.z);
				float num = 0f;
				if ((Object)(object)Character.observedCharacter != (Object)null)
				{
					num = Character.observedCharacter.refs.afflictions.GetCurrentStatus(_statusType) * 100f;
				}
				TextMeshProUGUI val = default(TextMeshProUGUI);
				if (num > 0f && ((Component)this).TryGetComponent<TextMeshProUGUI>(ref val))
				{
					string text = (_showPercentageSign.Value ? $"{num:F0}%" : $"{num:F0}");
					if (((TMP_Text)val).text != text)
					{
						((TMP_Text)val).text = text;
					}
				}
				bool flag = num > 0f;
				if (((Component)this).gameObject.activeSelf != flag)
				{
					((Component)this).gameObject.SetActive(flag);
				}
			}
		}

		public const string PluginVersion = "1.1.5";

		private static Harmony? _harmony;

		private static bool _elementsCreated = false;

		private static ConfigEntry<bool> _showPercentageSign;

		private static ConfigEntry<int> _staminaFontSize;

		private static ConfigEntry<int> _afflictionFontSize;

		private static ConfigEntry<float> _outlineThickness;

		private static ConfigEntry<bool> _verboseLogging;

		private static GameObject? _staminaTextContainer;

		private static TextMeshProUGUI? _staminaText;

		private static TextMeshProUGUI? _extraStaminaText;

		private static Dictionary<STATUSTYPE, TextMeshProUGUI> _afflictionTexts = new Dictionary<STATUSTYPE, TextMeshProUGUI>();

		private static Canvas _afflictionCanvas;

		private static TMP_FontAsset? _gameFont = null;

		private static Material? _textMaterial = null;

		private static readonly Color LowStaminaColor = new Color(1f, 0.3f, 0.3f);

		private static readonly Color MediumStaminaColor = new Color(1f, 0.92f, 0.016f);

		private static readonly Color HighStaminaColor = new Color(0.5f, 1f, 0.5f);

		private static readonly Color ExtraStaminaColor = new Color(1f, 0.92f, 0.016f);

		private static readonly Dictionary<STATUSTYPE, Color> StatusColors = new Dictionary<STATUSTYPE, Color>
		{
			{
				(STATUSTYPE)0,
				new Color(1f, 0.3f, 0.3f)
			},
			{
				(STATUSTYPE)1,
				new Color(0.9f, 0.6f, 0.1f)
			},
			{
				(STATUSTYPE)2,
				new Color(0.2f, 0.6f, 0.9f)
			},
			{
				(STATUSTYPE)3,
				new Color(0.6f, 0.1f, 0.6f)
			},
			{
				(STATUSTYPE)4,
				new Color(0.9f, 0.4f, 0.4f)
			},
			{
				(STATUSTYPE)5,
				new Color(0.5f, 0.1f, 0.5f)
			},
			{
				(STATUSTYPE)6,
				new Color(1f, 0.4f, 0.8f)
			},
			{
				(STATUSTYPE)7,
				new Color(0.6f, 0.4f, 0.2f)
			},
			{
				(STATUSTYPE)8,
				new Color(1f, 0.3f, 0.1f)
			}
		};

		public const string Id = "com.StaminaStats";

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


		public static string Name => "StaminaStats";

		public static string Version => "1.1.5";

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0096: 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_00a6: 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_00b2: Expected I4, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			InitializeConfig();
			_harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			_harmony.PatchAll();
			Log.LogInfo((object)("Plugin " + ((BaseUnityPlugin)this).Info.Metadata.Name + " v1.1.5 loaded"));
			if (_verboseLogging.Value)
			{
				Log.LogInfo((object)"Available STATUSTYPE enum values:");
				foreach (STATUSTYPE value in Enum.GetValues(typeof(STATUSTYPE)))
				{
					Log.LogInfo((object)$"  - {(object)value} (Value: {(int)value})");
				}
			}
			Application.logMessageReceived += new LogCallback(OnLogMessageReceived);
		}

		private void OnDestroy()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Application.logMessageReceived -= new LogCallback(OnLogMessageReceived);
			CleanupUIElements();
		}

		private void OnLogMessageReceived(string logString, string stackTrace, LogType logType)
		{
			if (logString.Contains("RUN STARTED"))
			{
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)"Detected new run starting! Resetting affliction UI elements...");
				}
				ResetAfflictionUI();
			}
		}

		private static void ResetAfflictionUI()
		{
			try
			{
				CleanupAfflictionTexts();
				_elementsCreated = false;
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)"Affliction UI elements reset successfully");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error resetting affliction UI: " + ex.Message));
			}
		}

		private static void CleanupAfflictionTexts()
		{
			try
			{
				if (_afflictionTexts.Count <= 0)
				{
					return;
				}
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)$"Cleaning up {_afflictionTexts.Count} affliction text elements");
				}
				foreach (KeyValuePair<STATUSTYPE, TextMeshProUGUI> item in _afflictionTexts.ToList())
				{
					if ((Object)(object)item.Value != (Object)null && (Object)(object)((Component)item.Value).gameObject != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)item.Value).gameObject);
					}
				}
				_afflictionTexts.Clear();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error cleaning up affliction texts: " + ex.Message));
			}
		}

		private static void CleanupUIElements()
		{
			try
			{
				CleanupAfflictionTexts();
				if ((Object)(object)_staminaTextContainer != (Object)null)
				{
					Object.Destroy((Object)(object)_staminaTextContainer);
					_staminaTextContainer = null;
					_staminaText = null;
					_extraStaminaText = null;
				}
				if ((Object)(object)_afflictionCanvas != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_afflictionCanvas).gameObject);
					_afflictionCanvas = null;
				}
				_elementsCreated = false;
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)"All UI elements cleaned up");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error cleaning up UI elements: " + ex.Message));
			}
		}

		private void InitializeConfig()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			_showPercentageSign = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowPercentageSign", false, "Whether to show a percentage sign (%) after numeric values.");
			_staminaFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "StaminaFontSize", 18, new ConfigDescription("Font size for stamina text display.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 32), Array.Empty<object>()));
			_afflictionFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "AfflictionFontSize", 16, new ConfigDescription("Font size for affliction text display.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 32), Array.Empty<object>()));
			_outlineThickness = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "TextOutlineThickness", 0.1f, new ConfigDescription("Thickness of the text outline for better readability. Higher values make text more readable against busy backgrounds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 0.3f), Array.Empty<object>()));
			_verboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Enable detailed logging for debugging purposes.");
			if (_verboseLogging.Value)
			{
				Log.LogInfo((object)"Configuration loaded:");
				Log.LogInfo((object)$"  - Show percentage sign: {_showPercentageSign.Value}");
				Log.LogInfo((object)$"  - Stamina font size: {_staminaFontSize.Value}");
				Log.LogInfo((object)$"  - Affliction font size: {_afflictionFontSize.Value}");
				Log.LogInfo((object)$"  - Text outline thickness: {_outlineThickness.Value}");
			}
		}

		private static BarAffliction FindAffliction(StaminaBar staminaBar, STATUSTYPE type)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			BarAffliction[] afflictions = staminaBar.afflictions;
			foreach (BarAffliction val in afflictions)
			{
				if (val.afflictionType == type)
				{
					return val;
				}
			}
			return null;
		}

		private static void EnsureAfflictionCanvas()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_afflictionCanvas == (Object)null)
			{
				GameObject val = new GameObject("AfflictionTextCanvas");
				Object.DontDestroyOnLoad((Object)(object)val);
				_afflictionCanvas = val.AddComponent<Canvas>();
				_afflictionCanvas.renderMode = (RenderMode)0;
				_afflictionCanvas.sortingOrder = 100;
				CanvasScaler val2 = val.AddComponent<CanvasScaler>();
				val2.uiScaleMode = (ScaleMode)1;
				val2.referenceResolution = new Vector2(1920f, 1080f);
				val2.screenMatchMode = (ScreenMatchMode)1;
				GraphicRaycaster val3 = val.AddComponent<GraphicRaycaster>();
				val.layer = LayerMask.NameToLayer("UI");
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)"Created top-level affliction canvas");
				}
			}
		}

		private static void UpdateAfflictionText(BarAffliction affliction, StaminaBar bar)
		{
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_011f: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Component)affliction).gameObject.activeSelf && !_afflictionTexts.ContainsKey(affliction.afflictionType))
				{
					return;
				}
				STATUSTYPE afflictionType = affliction.afflictionType;
				float num = Character.observedCharacter.refs.afflictions.GetCurrentStatus(afflictionType) * 100f;
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)$"Processing affliction: {afflictionType}, active={((Component)affliction).gameObject.activeSelf}, width={affliction.width}, value={num:F0}%");
				}
				TextMeshProUGUI value = null;
				if (!_afflictionTexts.TryGetValue(afflictionType, out value) || (Object)(object)value == (Object)null)
				{
					if ((Object)(object)_gameFont == (Object)null)
					{
						FindGameTextStyle();
					}
					EnsureAfflictionCanvas();
					GameObject val = new GameObject($"{afflictionType}Text");
					val.transform.SetParent(((Component)_afflictionCanvas).transform, false);
					value = val.AddComponent<TextMeshProUGUI>();
					RectTransform component = val.GetComponent<RectTransform>();
					component.anchorMin = new Vector2(0.5f, 0.5f);
					component.anchorMax = new Vector2(0.5f, 0.5f);
					component.pivot = new Vector2(0.5f, 0.5f);
					float num2 = Mathf.Max(40f, affliction.width * 0.8f);
					component.sizeDelta = new Vector2(num2, 24f);
					val.AddComponent<AfflictionTextTracker>().Initialize(affliction, -15f);
					SetupGameTextStyle(value, _afflictionFontSize.Value, (TextAlignmentOptions)514);
					((Graphic)value).raycastTarget = false;
					_afflictionTexts[afflictionType] = value;
					if (_verboseLogging.Value)
					{
						Log.LogInfo((object)$"Created new text component for {afflictionType}");
					}
				}
				else
				{
					((TMP_Text)value).fontSize = _afflictionFontSize.Value;
					((TMP_Text)value).outlineWidth = _outlineThickness.Value;
					AfflictionTextTracker component2 = ((Component)value).GetComponent<AfflictionTextTracker>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.UpdateWidth(Mathf.Max(40f, affliction.width * 0.8f));
						component2.UpdateAffliction(affliction);
					}
				}
				string text = (_showPercentageSign.Value ? $"{num:F0}%" : $"{num:F0}");
				((TMP_Text)value).text = text;
				if (StatusColors.TryGetValue(afflictionType, out var value2))
				{
					((Graphic)value).color = value2;
				}
				else
				{
					Image componentInChildren = ((Component)affliction).GetComponentInChildren<Image>();
					if (componentInChildren != null)
					{
						Color color = ((Graphic)componentInChildren).color;
						float num3 = default(float);
						float num4 = default(float);
						float num5 = default(float);
						Color.RGBToHSV(color, ref num3, ref num4, ref num5);
						((Graphic)value).color = Color.HSVToRGB(num3, Mathf.Clamp01(num4 * 1.2f), Mathf.Clamp01(num5 * 1.3f));
					}
				}
				if (((Component)value).gameObject.activeSelf != num > 0f)
				{
					((Component)value).gameObject.SetActive(num > 0f);
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)$"Error updating affliction text for {affliction.afflictionType}: {ex.Message}");
				if (_verboseLogging.Value)
				{
					Log.LogError((object)("Stack trace: " + ex.StackTrace));
				}
			}
		}

		private static void CreateStaminaTextElements(StaminaBar staminaBar)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)_staminaTextContainer != (Object)null)
				{
					Object.Destroy((Object)(object)_staminaTextContainer);
					_staminaTextContainer = null;
					_staminaText = null;
					_extraStaminaText = null;
				}
				if ((Object)(object)_gameFont == (Object)null)
				{
					FindGameTextStyle();
				}
				_staminaTextContainer = new GameObject("StaminaTextContainer");
				_staminaTextContainer.transform.SetParent(((Component)staminaBar).transform, false);
				GameObject val = new GameObject("StaminaText");
				val.transform.SetParent(_staminaTextContainer.transform, false);
				_staminaText = val.AddComponent<TextMeshProUGUI>();
				RectTransform component = val.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.5f, 0.5f);
				component.anchorMax = new Vector2(0.5f, 0.5f);
				component.pivot = new Vector2(1f, 0f);
				component.sizeDelta = new Vector2(60f, 30f);
				component.anchoredPosition = new Vector2(20f, 25f);
				SetupGameTextStyle(_staminaText, _staminaFontSize.Value, (TextAlignmentOptions)516);
				GameObject val2 = new GameObject("ExtraStaminaText");
				val2.transform.SetParent(_staminaTextContainer.transform, false);
				_extraStaminaText = val2.AddComponent<TextMeshProUGUI>();
				RectTransform component2 = val2.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0.5f, 0.5f);
				component2.anchorMax = new Vector2(0.5f, 0.5f);
				component2.pivot = new Vector2(0f, 0f);
				component2.sizeDelta = new Vector2(60f, 30f);
				component2.anchoredPosition = new Vector2(24f, 25f);
				SetupGameTextStyle(_extraStaminaText, _staminaFontSize.Value, (TextAlignmentOptions)513);
				((Graphic)_extraStaminaText).color = ExtraStaminaColor;
				if (_verboseLogging.Value)
				{
					Log.LogInfo((object)"Created stamina text elements");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error creating stamina text: " + ex.Message));
				_elementsCreated = false;
			}
		}

		private static void FindGameTextStyle()
		{
			try
			{
				TextMeshProUGUI[] array = Resources.FindObjectsOfTypeAll<TextMeshProUGUI>();
				TextMeshProUGUI[] array2 = array;
				foreach (TextMeshProUGUI val in array2)
				{
					if (((Object)val).name == "InteractNameText" || ((Object)val).name == "InteractPromptText" || ((Object)val).name == "ItemPromptMain")
					{
						_gameFont = ((TMP_Text)val).font;
						_textMaterial = ((Graphic)val).material;
						if (_verboseLogging.Value)
						{
							Log.LogInfo((object)("Found game font: " + ((Object)_gameFont).name));
						}
						return;
					}
				}
				TMP_FontAsset[] array3 = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				int num = 0;
				if (num < array3.Length)
				{
					TMP_FontAsset gameFont = array3[num];
					_gameFont = gameFont;
					if (_verboseLogging.Value)
					{
						Log.LogInfo((object)("Using fallback game font: " + ((Object)_gameFont).name));
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error finding game text style: " + ex.Message));
			}
		}

		private static void SetupGameTextStyle(TextMeshProUGUI text, int fontSize, TextAlignmentOptions alignment)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)text).fontSize = fontSize;
			((TMP_Text)text).alignment = alignment;
			((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)text).overflowMode = (TextOverflowModes)0;
			((Graphic)text).color = Color.white;
			if ((Object)(object)_gameFont != (Object)null)
			{
				((TMP_Text)text).font = _gameFont;
			}
			if ((Object)(object)_textMaterial != (Object)null)
			{
				((Graphic)text).material = _textMaterial;
			}
			Shadow val = ((Component)text).gameObject.AddComponent<Shadow>();
			val.effectColor = new Color(0f, 0f, 0f, 0.95f);
			val.effectDistance = new Vector2(2f, -2f);
			((TMP_Text)text).outlineWidth = _outlineThickness.Value;
			((TMP_Text)text).outlineColor = Color32.op_Implicit(new Color(0f, 0f, 0f, 1f));
			((TMP_Text)text).enableAutoSizing = false;
			((TMP_Text)text).fontStyle = (FontStyles)1;
			((TMP_Text)text).faceColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			Canvas.ForceUpdateCanvases();
		}

		private static void UpdateStaminaText(StaminaBar staminaBar)
		{
			try
			{
				if ((Object)(object)_staminaText == (Object)null || (Object)(object)Character.observedCharacter == (Object)null)
				{
					return;
				}
				float num = Character.observedCharacter.data.currentStamina * 100f;
				float num2 = Character.observedCharacter.data.extraStamina * 100f;
				((TMP_Text)_staminaText).fontSize = _staminaFontSize.Value;
				((TMP_Text)_staminaText).outlineWidth = _outlineThickness.Value;
				if ((Object)(object)_extraStaminaText != (Object)null)
				{
					((TMP_Text)_extraStaminaText).fontSize = _staminaFontSize.Value;
					((TMP_Text)_extraStaminaText).outlineWidth = _outlineThickness.Value;
				}
				((TMP_Text)_staminaText).text = (_showPercentageSign.Value ? $"{num:F0}%" : $"{num:F0}");
				if ((Object)(object)_extraStaminaText != (Object)null)
				{
					if (num2 > 0f)
					{
						((Component)_extraStaminaText).gameObject.SetActive(true);
						((TMP_Text)_extraStaminaText).text = (_showPercentageSign.Value ? $"  +{num2:F0}%" : $"  +{num2:F0}");
					}
					else
					{
						((Component)_extraStaminaText).gameObject.SetActive(false);
					}
				}
				UpdateStaminaTextColor(num, Character.observedCharacter.GetMaxStamina() * 100f, num2, staminaBar);
				if ((Object)(object)_staminaTextContainer != (Object)null)
				{
					bool active = ((Component)staminaBar.staminaBar).gameObject.activeSelf && !Character.observedCharacter.data.fullyPassedOut && !Character.observedCharacter.data.dead;
					_staminaTextContainer.SetActive(active);
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error updating stamina text: " + ex.Message));
			}
		}

		private static void UpdateStaminaTextColor(float currentStamina, float maxStamina, float extraStamina, StaminaBar staminaBar)
		{
			//IL_0026: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			try
			{
				if (!((Object)(object)_staminaText == (Object)null))
				{
					float num = currentStamina / maxStamina;
					Image component = ((Component)staminaBar.staminaBar).GetComponent<Image>();
					Color val;
					if (component == null)
					{
						val = ((num < 0.25f) ? LowStaminaColor : ((!(num < 0.5f)) ? HighStaminaColor : MediumStaminaColor));
					}
					else
					{
						Color color = ((Graphic)component).color;
						float num2 = default(float);
						float num3 = default(float);
						float num4 = default(float);
						Color.RGBToHSV(color, ref num2, ref num3, ref num4);
						val = Color.HSVToRGB(num2, Mathf.Clamp01(num3 * 1.2f), Mathf.Clamp01(num4 * 1.3f));
					}
					float num5 = default(float);
					float num6 = default(float);
					float num7 = default(float);
					Color.RGBToHSV(val, ref num5, ref num6, ref num7);
					val = Color.HSVToRGB(num5, num6, Mathf.Max(0.8f, num7));
					((Graphic)_staminaText).color = val;
					if ((Object)(object)_extraStaminaText != (Object)null)
					{
						((Graphic)_extraStaminaText).color = ExtraStaminaColor;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error updating text color: " + ex.Message));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}