Decompiled source of HUD Update v0.1.3

plugins/HUD-Update/HUD-Update.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: AssemblyTitle("HUD Update")]
[assembly: AssemblyDescription("Nordic HUD for Valheim: guardian power, food diamonds, health and stamina.")]
[assembly: AssemblyCompany("Crevitka")]
[assembly: AssemblyProduct("HUD Update")]
[assembly: AssemblyCopyright("Copyright (c) 2026 Crevitka, MIT License")]
[assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.1.3.0")]
namespace UIReforge;

public enum HudStyle
{
	Bars,
	Chevron
}
public enum FoodIconColorMode
{
	Off,
	Tint,
	Glow,
	TintAndGlow
}
[BepInPlugin("crevitka.hudupdate", "HUD Update", "0.1.3")]
public class HudUpdatePlugin : BaseUnityPlugin
{
	private Harmony _harmony;

	internal static ConfigEntry<HudStyle> Style;

	internal static ConfigEntry<FoodIconColorMode> FoodColor;

	internal static ConfigEntry<float> FoodGlowStrength;

	private DateTime _configStamp;

	private float _nextConfigCheck;

	private string _iconStamp;

	private void Awake()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		try
		{
			Style = ((BaseUnityPlugin)this).Config.Bind<HudStyle>("General", "HudStyle", HudStyle.Bars, "Bars - guardian, food diamonds and straight health/stamina bars.\nChevron - guardian, 2x2 food grid and a red health chevron; stamina stays vanilla.\nCan be changed while the game runs: save this file and the HUD rebuilds.");
			Style.SettingChanged += delegate
			{
				HudState.RequestRebuild();
			};
			FoodColor = ((BaseUnityPlugin)this).Config.Bind<FoodIconColorMode>("Food", "FoodIconColor", FoodIconColorMode.Off, "Colour food icons by the stat they raise most: health = red, stamina = yellow, eitr = blue, balanced = white.\nOff - plain icons. Tint - the icon itself is coloured (only the mod's white icons, vanilla icons stay as is).\nGlow - a soft coloured glow around the icon. TintAndGlow - both.");
			FoodGlowStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Food", "FoodGlowStrength", 0.7f, new ConfigDescription("Glow opacity, 0 - invisible, 1 - strongest.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			_configStamp = SafeStamp();
			try
			{
				Directory.CreateDirectory(HudState.IconFolders[0]);
			}
			catch
			{
			}
			_harmony = new Harmony("crevitka.hudupdate");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"UIReforge loaded");
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)$"UIReforge init failed: {arg}");
		}
	}

	private DateTime SafeStamp()
	{
		try
		{
			return File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath);
		}
		catch
		{
			return DateTime.MinValue;
		}
	}

	private void Update()
	{
		if (Time.unscaledTime < _nextConfigCheck)
		{
			return;
		}
		_nextConfigCheck = Time.unscaledTime + 1f;
		string text = HudState.IconFolderStamp();
		if (_iconStamp == null)
		{
			_iconStamp = text;
		}
		else if (text != _iconStamp)
		{
			_iconStamp = text;
			HudState.ReloadIcons();
		}
		DateTime dateTime = SafeStamp();
		if (dateTime == _configStamp)
		{
			return;
		}
		_configStamp = dateTime;
		try
		{
			((BaseUnityPlugin)this).Config.Reload();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Config reload failed: " + ex.Message));
		}
	}

	private void OnDestroy()
	{
		try
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)$"UIReforge unpatch failed: {arg}");
		}
	}
}
internal static class HudState
{
	internal class FoodSlotUI
	{
		public GameObject Root;

		public Image Icon;

		public TextMeshProUGUI Timer;

		public TextMeshProUGUI[] TimerShadow;

		public Image VanillaIcon;

		public Image Glow;
	}

	internal class BuffUI
	{
		public GameObject Root;

		public Image Icon;

		public TextMeshProUGUI Timer;
	}

	internal enum FoodStat
	{
		Neutral,
		Health,
		Stamina,
		Eitr
	}

	internal static TextMeshProUGUI GuardianName;

	private static float nextInitAttempt;

	internal static HudStyle ActiveStyle = HudStyle.Bars;

	private static readonly List<GameObject> HiddenVanillaStamina = new List<GameObject>();

	internal static Image[] ChevronFast;

	internal static Image[] ChevronSlow;

	private static int guardianUpdateFrame = -1;

	internal static bool Initialized;

	internal static GameObject Panel;

	internal static Image HpFastImage;

	internal static Image HpSlowImage;

	internal static TextMeshProUGUI HpText;

	internal static float HpFastValue = -1f;

	internal static float HpSlowValue = -1f;

	internal static Image StaminaFastImage;

	internal static Image StaminaSlowImage;

	internal static TextMeshProUGUI StaminaText;

	internal static float StaminaFastValue = -1f;

	internal static float StaminaSlowValue = -1f;

	internal static readonly FoodSlotUI[] Slots = new FoodSlotUI[3];

	internal static BuffUI Buff;

	internal static Sprite DefaultFoodIcon;

	private static Sprite SolidBarSprite;

	internal static AssetBundle HudBundle;

	internal static AssetBundle FoodIconsBundle;

	private static readonly Dictionary<string, Sprite> EmbeddedFoodIcons = new Dictionary<string, Sprite>();

	private static bool embeddedIconsLoaded;

	internal static readonly Dictionary<string, Sprite> FoodIconOverrides = new Dictionary<string, Sprite>(StringComparer.OrdinalIgnoreCase);

	internal static GameObject VanillaGuardianRoot;

	internal static Image VanillaGuardianIcon;

	internal static Image VanillaGuardianTimeBar;

	internal static TextMeshProUGUI VanillaGuardianTimeText;

	internal static Text VanillaGuardianLegacyTimeText;

	internal static TextMeshProUGUI VanillaGuardianNameText;

	internal static Text VanillaGuardianLegacyNameText;

	internal const float TimerYOffset = -28f;

	internal const float BarTextRightOffset = -10f;

	internal static readonly string[] IconFolders = new string[2]
	{
		Path.Combine(Path.Combine(Paths.ConfigPath, "HUD-Update"), "Icons"),
		Path.Combine(Path.GetDirectoryName(typeof(HudUpdatePlugin).Assembly.Location) ?? Paths.PluginPath, "Icons")
	};

	private static readonly HashSet<string> NonFoodIcons = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "HealthIcon", "StaminaIcon", "chevron_shape", "chevron_outline", "Eikthyr", "TheElder", "Bonemass" };

	private static readonly List<Object> LoadedIconObjects = new List<Object>();

	internal static readonly Color PanelDark = new Color(0.105f, 0.105f, 0.085f, 0.93f);

	internal static readonly Color HpColor = new Color(0.66f, 0.12f, 0.12f, 1f);

	internal static readonly Color HpTrailColor = new Color(0.93f, 0.78f, 0.72f, 1f);

	internal static readonly Color StaminaColor = new Color(0.84f, 0.65f, 0.43f, 1f);

	internal static readonly Color StaminaTrailColor = new Color(0.97f, 0.9f, 0.78f, 1f);

	private const float BarLeft = 238f;

	private const float BarWidth = 266f;

	private const float BarHeight = 27f;

	private const float PlateWidth = 34f;

	private const float HpBarY = 122f;

	private const float StaminaBarY = 88f;

	private const float FoodTimerRim = 1f;

	private static readonly Color FoodTimerRimColor = new Color(0f, 0f, 0f, 0.85f);

	internal static readonly Color ChevronRed = new Color(0.678f, 0.086f, 0.086f, 1f);

	internal static readonly Color ChevronTrail = new Color(0.95f, 0.8f, 0.72f, 1f);

	internal static readonly Color ChevronTrack = new Color(0.07f, 0.05f, 0.04f, 0.55f);

	internal static readonly Color ChevronOutline = new Color(0f, 0f, 0f, 1f);

	internal static readonly Color ChevronCell = new Color(0f, 0f, 0f, 0.72f);

	internal static readonly Color FoodBackplate = new Color(0.66f, 0.64f, 0.3f, 0.55f);

	private const float ChevX0 = -79.71f;

	private const float ChevX1 = 118.96f;

	private const float ChevY0 = -87.96f;

	private const float ChevY1 = 117.38f;

	private const float ChevCorner = 14f;

	private const float ChevBand = 44f;

	private static readonly Vector2[] ChevPath = (Vector2[])(object)new Vector2[5]
	{
		new Vector2(-85.04f, 86.71f),
		new Vector2(-25.04f, 86.71f),
		new Vector2(-1.04f, 108.04f),
		new Vector2(107.89f, 0.31f),
		new Vector2(16.29f, -95.96f)
	};

	private static Sprite solidSprite;

	private static readonly Dictionary<string, Sprite> cutSprites = new Dictionary<string, Sprite>();

	private static readonly Dictionary<string, string> GuardianEmblems = new Dictionary<string, string>(StringComparer.Ordinal)
	{
		{ "GP_Eikthyr", "Eikthyr" },
		{ "GP_TheElder", "TheElder" },
		{ "GP_Bonemass", "Bonemass" }
	};

	private static readonly Dictionary<Sprite, Sprite> GlowSprites = new Dictionary<Sprite, Sprite>();

	private static Sprite radialGlow;

	private const float GlowScale = 1.7f;

	private static readonly Dictionary<string, string> FoodGlyphByPrefab = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
	{
		{ "Raspberry", "raspberry" },
		{ "Blueberries", "berries" },
		{ "Cloudberry", "berries" },
		{ "Vineberry", "berries" },
		{ "Mushroom", "mushroom" },
		{ "MushroomYellow", "mushroom" },
		{ "MushroomBlue", "mushroom" },
		{ "MushroomJotunPuffs", "mushroom" },
		{ "MushroomMagecap", "mushroom" },
		{ "MushroomSmokePuff", "mushroom" },
		{ "MagicallyStuffedShroom", "mushroom" },
		{ "Carrot", "carrot" },
		{ "Turnip", "turnip" },
		{ "Onion", "onion" },
		{ "Honey", "honey" },
		{ "RoyalJelly", "honey" },
		{ "CookedMeat", "steak" },
		{ "CookedDeerMeat", "steak" },
		{ "CookedWolfMeat", "steak" },
		{ "CookedLoxMeat", "steak" },
		{ "SerpentMeatCooked", "steak" },
		{ "CookedBugMeat", "steak" },
		{ "CookedAsksvinMeat", "steak" },
		{ "CookedVoltureMeat", "steak" },
		{ "CookedBoneMawSerpentMeat", "steak" },
		{ "MeatPlatter", "steak" },
		{ "NeckTailGrilled", "drumstick" },
		{ "CookedChickenMeat", "drumstick" },
		{ "CookedHareMeat", "drumstick" },
		{ "HoneyGlazedChicken", "drumstick" },
		{ "FishCooked", "fish" },
		{ "FishWraps", "fish" },
		{ "FishAndBread", "fish" },
		{ "CookedEgg", "egg" },
		{ "MushroomOmelette", "omelette" },
		{ "BoarJerky", "jerky" },
		{ "WolfJerky", "jerky" },
		{ "WolfMeatSkewer", "skewer" },
		{ "CarrotSoup", "stew" },
		{ "DeerStew", "stew" },
		{ "TurnipStew", "stew" },
		{ "SerpentStew", "stew" },
		{ "BlackSoup", "stew" },
		{ "MinceMeatSauce", "stew" },
		{ "YggdrasilPorridge", "stew" },
		{ "SizzlingBerryBroth", "stew" },
		{ "FierySvinstew", "stew" },
		{ "MashedMeat", "stew" },
		{ "ScorchingMedley", "stew" },
		{ "QueensJam", "jam" },
		{ "SpicyMarmalade", "jam" },
		{ "ShocklateSmoothie", "drink" },
		{ "SparklingShroomshake", "drink" },
		{ "Bread", "bread" },
		{ "LoxPie", "pie" },
		{ "PiquantPie", "pie" },
		{ "RoastedCrustPie", "pie" },
		{ "MisthareSupreme", "pie" },
		{ "Salad", "salad" },
		{ "MarinatedGreens", "salad" },
		{ "Eyescream", "icecream" },
		{ "Fiddleheadfern", "fern" },
		{ "SeekerAspic", "aspic" },
		{ "BloodPudding", "aspic" },
		{ "FeastMeadows", "feast" },
		{ "FeastBlackforest", "feast" },
		{ "FeastSwamps", "feast" },
		{ "FeastMountains", "feast" },
		{ "FeastOceans", "feast" },
		{ "FeastPlains", "feast" },
		{ "FeastMistlands", "feast" },
		{ "FeastAshlands", "feast" },
		{ "FeastDeepNorth", "feast" },
		{ "Poteitr", "potato" },
		{ "BakedPoteitr", "potato" },
		{ "MeatballsMashedPoteitr", "potato" },
		{ "Pancakes", "pancake" },
		{ "OvenPancake", "pancake" },
		{ "VikingCupcake", "cupcake" },
		{ "Kale", "kale" },
		{ "KaleChips", "kale" },
		{ "Oat", "grain" },
		{ "GlowWorm", "worm" },
		{ "OatMilk", "drink" },
		{ "Lingondricka", "drink" },
		{ "OatmealLingonberryJam", "stew" },
		{ "MooseKebab", "skewer" },
		{ "PulledBear", "steak" },
		{ "CookedSealBlubber", "steak" },
		{ "CookedMooseMeat", "steak" },
		{ "CookedBjornMeat", "steak" },
		{ "SmokedMooseMeat", "steak" },
		{ "SmokedFish", "fish" },
		{ "FishSoup", "stew" },
		{ "SealSoup", "stew" }
	};

	private static readonly string[][] FoodGlyphKeywords = new string[45][]
	{
		new string[2] { "feast", "feast" },
		new string[2] { "pancake", "pancake" },
		new string[2] { "cupcake", "cupcake" },
		new string[2] { "kebab", "skewer" },
		new string[2] { "milk", "drink" },
		new string[2] { "soup", "stew" },
		new string[2] { "broth", "stew" },
		new string[2] { "porridge", "stew" },
		new string[2] { "sauce", "stew" },
		new string[2] { "medley", "stew" },
		new string[2] { "pie", "pie" },
		new string[2] { "supreme", "pie" },
		new string[2] { "jam", "jam" },
		new string[2] { "marmalade", "jam" },
		new string[2] { "smoothie", "drink" },
		new string[2] { "shake", "drink" },
		new string[2] { "mead", "drink" },
		new string[2] { "jerky", "jerky" },
		new string[2] { "skewer", "skewer" },
		new string[2] { "bread", "bread" },
		new string[2] { "salad", "salad" },
		new string[2] { "greens", "salad" },
		new string[2] { "omelette", "omelette" },
		new string[2] { "egg", "egg" },
		new string[2] { "aspic", "aspic" },
		new string[2] { "pudding", "aspic" },
		new string[2] { "fish", "fish" },
		new string[2] { "chicken", "drumstick" },
		new string[2] { "hare", "drumstick" },
		new string[2] { "necktail", "drumstick" },
		new string[2] { "meat", "steak" },
		new string[2] { "raspberr", "raspberry" },
		new string[2] { "berr", "berries" },
		new string[2] { "shroom", "mushroom" },
		new string[2] { "carrot", "carrot" },
		new string[2] { "turnip", "turnip" },
		new string[2] { "onion", "onion" },
		new string[2] { "honey", "honey" },
		new string[2] { "jelly", "honey" },
		new string[2] { "fern", "fern" },
		new string[2] { "cream", "icecream" },
		new string[2] { "poteitr", "potato" },
		new string[2] { "potato", "potato" },
		new string[2] { "kale", "kale" },
		new string[2] { "worm", "worm" }
	};

	internal static HudStyle CurrentStyle
	{
		[CompilerGenerated]
		get
		{
			return (HudUpdatePlugin.Style != null) ? HudUpdatePlugin.Style.Value : HudStyle.Bars;
		}
	}

	internal static void RequestRebuild()
	{
		Reset();
		nextInitAttempt = 0f;
	}

	internal static void Reset()
	{
		Initialized = false;
		guardianUpdateFrame = -1;
		foreach (GameObject item in HiddenVanillaStamina)
		{
			if ((Object)(object)item != (Object)null)
			{
				item.SetActive(true);
			}
		}
		HiddenVanillaStamina.Clear();
		ChevronFast = null;
		ChevronSlow = null;
		if ((Object)(object)Panel != (Object)null)
		{
			Object.Destroy((Object)(object)Panel);
		}
		Panel = null;
		GuardianName = null;
		HpFastImage = null;
		HpSlowImage = null;
		HpText = null;
		HpFastValue = -1f;
		HpSlowValue = -1f;
		StaminaFastImage = null;
		StaminaSlowImage = null;
		StaminaText = null;
		StaminaFastValue = -1f;
		StaminaSlowValue = -1f;
		for (int i = 0; i < Slots.Length; i++)
		{
			Slots[i] = null;
		}
		Buff = null;
		VanillaGuardianRoot = null;
		VanillaGuardianIcon = null;
		VanillaGuardianTimeBar = null;
		VanillaGuardianTimeText = null;
		VanillaGuardianLegacyTimeText = null;
		VanillaGuardianNameText = null;
		VanillaGuardianLegacyNameText = null;
	}

	internal static void EnsureInit(Hud hud)
	{
		if (Initialized)
		{
			bool flag = ActiveStyle != CurrentStyle || (Object)(object)Panel == (Object)null || Buff == null || (Object)(object)hud == (Object)null || (Object)(object)hud.m_rootObject == (Object)null;
			if (!flag && (Object)(object)Panel != (Object)null)
			{
				try
				{
					if ((Object)(object)Panel.transform.parent != (Object)(object)hud.m_rootObject.transform)
					{
						flag = true;
					}
				}
				catch
				{
					flag = true;
				}
			}
			if (flag)
			{
				Reset();
			}
		}
		if (Initialized || (Object)(object)hud == (Object)null || (Object)(object)hud.m_rootObject == (Object)null || Time.unscaledTime < nextInitAttempt)
		{
			return;
		}
		nextInitAttempt = Time.unscaledTime + 5f;
		try
		{
			if ((Object)(object)HudBundle == (Object)null)
			{
				HudBundle = LoadHudBundle();
			}
			if ((Object)(object)HudBundle == (Object)null)
			{
				Debug.LogError((object)"[UIReforge] Failed to load the HUD bundle (embedded and prefabs/hudPrefab)");
				return;
			}
			GameObject val = HudBundle.LoadAsset<GameObject>("healthpanel");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"[UIReforge] Failed to load prefab 'healthpanel' from bundle");
				return;
			}
			DefaultFoodIcon = HudBundle.LoadAsset<Sprite>("default-food-icon");
			LoadFoodIconsBundle();
			TmpFontFix.ApplyFontsToPrefab(val);
			Panel = Object.Instantiate<GameObject>(val, hud.m_rootObject.transform);
			((Object)Panel).name = "CustomHealthPanel";
			TmpFontFix.FixFontsOnInstance(Panel);
			MonoBehaviour[] componentsInChildren = Panel.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if (((object)val2).GetType().Name == "GuiBar")
				{
					((Behaviour)val2).enabled = false;
				}
			}
			FindReferences(Panel);
			if ((Object)(object)HpFastImage == (Object)null || (Object)(object)StaminaFastImage == (Object)null || (Object)(object)HpText == (Object)null || (Object)(object)StaminaText == (Object)null || Buff == null || (Object)(object)Buff.Icon == (Object)null || (Object)(object)Buff.Timer == (Object)null || Slots.Any((FoodSlotUI slot) => slot == null || (Object)(object)slot.Icon == (Object)null || (Object)(object)slot.Timer == (Object)null))
			{
				throw new InvalidDataException("HUD prefab is missing required bars, labels or food slots");
			}
			ActiveStyle = CurrentStyle;
			if (ActiveStyle == HudStyle.Chevron)
			{
				ApplyChevronLayout();
			}
			else
			{
				ApplyReferenceLayout();
			}
			CaptureVanillaGuardian(hud);
			HideVanillaGuardianVisuals();
			if ((Object)(object)hud.m_healthPanel != (Object)null)
			{
				((Component)hud.m_healthPanel).gameObject.SetActive(false);
			}
			if (ActiveStyle == HudStyle.Bars)
			{
				HideVanillaStamina(hud);
			}
			Initialized = true;
			Debug.Log((object)("[UIReforge] Custom HUD initialized 0.1.3, style " + ActiveStyle));
		}
		catch (Exception ex)
		{
			Reset();
			Debug.LogError((object)("[UIReforge] Init error: " + ex));
		}
	}

	private static AssetBundle LoadHudBundle()
	{
		try
		{
			using Stream stream = typeof(HudUpdatePlugin).Assembly.GetManifestResourceStream("UIReforge.Bundles.hudPrefab");
			if (stream != null)
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				AssetBundle val = AssetBundle.LoadFromMemory(memoryStream.ToArray());
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UIReforge] Embedded HUD bundle failed: " + ex.Message));
		}
		string text = FindPluginFile("prefabs", "hudPrefab");
		return (!File.Exists(text)) ? null : AssetBundle.LoadFromFile(text);
	}

	private static string FindPluginFile(string folder, string file)
	{
		string text = Path.Combine(Path.GetDirectoryName(typeof(HudUpdatePlugin).Assembly.Location) ?? Paths.PluginPath, folder, file);
		return (!File.Exists(text)) ? Path.Combine(Paths.PluginPath, folder, file) : text;
	}

	internal static void LoadFoodIconsBundle()
	{
		try
		{
			FoodIconOverrides.Clear();
			string text = FindPluginFile("prefabs", "food_icons");
			if (!File.Exists(text))
			{
				return;
			}
			if ((Object)(object)FoodIconsBundle == (Object)null)
			{
				FoodIconsBundle = AssetBundle.LoadFromFile(text);
			}
			if ((Object)(object)FoodIconsBundle == (Object)null)
			{
				Debug.LogError((object)"[UIReforge] Failed to load food_icons bundle");
				return;
			}
			Sprite[] array = FoodIconsBundle.LoadAllAssets<Sprite>();
			Sprite[] array2 = array;
			foreach (Sprite val in array2)
			{
				if ((Object)(object)val != (Object)null)
				{
					FoodIconOverrides[((Object)val).name] = val;
				}
			}
			Debug.Log((object)$"[UIReforge] Loaded food icon overrides: {FoodIconOverrides.Count}");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UIReforge] LoadFoodIconsBundle error: " + ex));
		}
		finally
		{
			LoadEmbeddedFoodIcons();
		}
	}

	private static void LoadEmbeddedFoodIcons()
	{
		if (!embeddedIconsLoaded)
		{
			embeddedIconsLoaded = true;
			Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			Assembly assembly = typeof(HudUpdatePlugin).Assembly;
			foreach (string item in from n in assembly.GetManifestResourceNames()
				where n.StartsWith("UIReforge.Icons.", StringComparison.Ordinal) && n.EndsWith(".png", StringComparison.OrdinalIgnoreCase)
				select n)
			{
				dictionary[item.Substring("UIReforge.Icons.".Length, item.Length - "UIReforge.Icons.".Length - 4)] = null;
			}
			for (int num = IconFolders.Length - 1; num >= 0; num--)
			{
				try
				{
					if (Directory.Exists(IconFolders[num]))
					{
						string[] files = Directory.GetFiles(IconFolders[num], "*.png");
						foreach (string text in files)
						{
							dictionary[Path.GetFileNameWithoutExtension(text)] = text;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[UIReforge] Could not read " + IconFolders[num] + ": " + ex.Message));
				}
			}
			int num3 = 0;
			foreach (KeyValuePair<string, string> item2 in dictionary)
			{
				string key = item2.Key;
				Sprite val = null;
				if (item2.Value != null)
				{
					try
					{
						val = CreateIconSprite(key, File.ReadAllBytes(item2.Value));
						num3++;
					}
					catch (Exception ex2)
					{
						Debug.LogWarning((object)("[UIReforge] Icon " + item2.Value + " skipped: " + ex2.Message));
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					using Stream stream = assembly.GetManifestResourceStream("UIReforge.Icons." + key + ".png");
					if (stream == null)
					{
						continue;
					}
					using (MemoryStream memoryStream = new MemoryStream())
					{
						stream.CopyTo(memoryStream);
						try
						{
							val = CreateIconSprite(key, memoryStream.ToArray());
						}
						catch (Exception ex3)
						{
							Debug.LogWarning((object)("[UIReforge] Could not load embedded icon " + key + ": " + ex3.Message));
						}
					}
					goto IL_0270;
				}
				goto IL_0270;
				IL_0270:
				if ((Object)(object)val != (Object)null)
				{
					EmbeddedFoodIcons[key] = val;
				}
			}
			Debug.Log((object)("[UIReforge] Icons: " + EmbeddedFoodIcons.Count + " (" + num3 + " from Icons folders)"));
		}
		foreach (KeyValuePair<string, Sprite> embeddedFoodIcon in EmbeddedFoodIcons)
		{
			FoodIconOverrides[embeddedFoodIcon.Key] = embeddedFoodIcon.Value;
		}
	}

	private static Sprite CreateIconSprite(string key, byte[] png)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0049: 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)
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		try
		{
			if (!ImageConversion.LoadImage(val, png, false))
			{
				throw new InvalidDataException("not a valid PNG");
			}
			((Object)val).name = key;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			((Object)val2).name = key;
			if (!NonFoodIcons.Contains(key) && !key.StartsWith("GP_", StringComparison.OrdinalIgnoreCase))
			{
				Sprite val3 = BuildGlowSprite(val, key);
				GlowSprites[val2] = val3;
				LoadedIconObjects.Add((Object)(object)val3);
				LoadedIconObjects.Add((Object)(object)val3.texture);
			}
			val.Apply(false, true);
			Object.DontDestroyOnLoad((Object)(object)val);
			Object.DontDestroyOnLoad((Object)(object)val2);
			LoadedIconObjects.Add((Object)(object)val2);
			LoadedIconObjects.Add((Object)(object)val);
			return val2;
		}
		catch
		{
			Object.Destroy((Object)(object)val);
			throw;
		}
	}

	internal static void ReloadIcons()
	{
		RequestRebuild();
		foreach (Object loadedIconObject in LoadedIconObjects)
		{
			if (loadedIconObject != (Object)null)
			{
				Object.Destroy(loadedIconObject);
			}
		}
		LoadedIconObjects.Clear();
		GlowSprites.Clear();
		EmbeddedFoodIcons.Clear();
		FoodIconOverrides.Clear();
		embeddedIconsLoaded = false;
		Debug.Log((object)"[UIReforge] Icons folder changed, reloading icons");
	}

	internal static string IconFolderStamp()
	{
		StringBuilder stringBuilder = new StringBuilder();
		string[] iconFolders = IconFolders;
		foreach (string path in iconFolders)
		{
			try
			{
				if (Directory.Exists(path))
				{
					string[] files = Directory.GetFiles(path, "*.png");
					foreach (string text in files)
					{
						stringBuilder.Append(text).Append(File.GetLastWriteTimeUtc(text).Ticks).Append(';');
					}
				}
			}
			catch
			{
			}
		}
		return stringBuilder.ToString();
	}

	internal static void FindReferences(GameObject root)
	{
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Expected O, but got Unknown
		//IL_0101: 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)
		//IL_02dd: Expected O, but got Unknown
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Expected O, but got Unknown
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		FindBarGroup(root.transform.Find("Health"), out HpFastImage, out HpSlowImage, out HpText);
		FindBarGroup(root.transform.Find("Stamina"), out StaminaFastImage, out StaminaSlowImage, out StaminaText);
		Transform val = root.transform.Find("Buff");
		if ((Object)(object)val != (Object)null)
		{
			BuffUI buffUI = new BuffUI();
			buffUI.Root = ((Component)val).gameObject;
			Transform obj = val.Find("buffIcon");
			buffUI.Icon = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			Transform obj2 = val.Find("time");
			buffUI.Timer = ((obj2 != null) ? ((Component)obj2).GetComponent<TextMeshProUGUI>() : null);
			Buff = buffUI;
			if ((Object)(object)Buff.Root != (Object)null)
			{
				Buff.Root.SetActive(false);
			}
			if ((Object)(object)Buff.Icon != (Object)null)
			{
				((Graphic)Buff.Icon).color = Color.white;
				Buff.Icon.preserveAspect = true;
				((Graphic)Buff.Icon).raycastTarget = false;
			}
			if ((Object)(object)Buff.Timer != (Object)null)
			{
				SetupDiamondTimerText(Buff.Timer);
				((TMP_Text)Buff.Timer).transform.SetAsLastSibling();
			}
		}
		else
		{
			Buff = null;
		}
		List<Transform> list = new List<Transform>();
		foreach (Transform item in root.transform)
		{
			Transform val2 = item;
			if (((Object)val2).name.IndexOf("food", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				list.Add(val2);
			}
		}
		list.Sort((Transform a, Transform b) => string.Compare(((Object)a).name, ((Object)b).name, StringComparison.Ordinal));
		for (int num = 0; num < Slots.Length; num++)
		{
			if (num >= list.Count)
			{
				Slots[num] = null;
				continue;
			}
			Transform val3 = list[num];
			FoodSlotUI foodSlotUI = new FoodSlotUI();
			foodSlotUI.Root = ((Component)val3).gameObject;
			foodSlotUI.Timer = ((Component)val3).GetComponentInChildren<TextMeshProUGUI>(true);
			FoodSlotUI foodSlotUI2 = foodSlotUI;
			foodSlotUI2.VanillaIcon = FindVanillaFoodIconImage(val3);
			if ((Object)(object)DefaultFoodIcon == (Object)null && (Object)(object)foodSlotUI2.VanillaIcon != (Object)null)
			{
				DefaultFoodIcon = foodSlotUI2.VanillaIcon.sprite;
			}
			if ((Object)(object)foodSlotUI2.VanillaIcon != (Object)null)
			{
				((Behaviour)foodSlotUI2.VanillaIcon).enabled = false;
			}
			GameObject val4 = new GameObject("UIReforgeGlow", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val4.transform.SetParent(val3, false);
			foodSlotUI2.Glow = val4.GetComponent<Image>();
			((Graphic)foodSlotUI2.Glow).raycastTarget = false;
			((Behaviour)foodSlotUI2.Glow).enabled = false;
			GameObject val5 = new GameObject("UIReforgeIcon", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val5.transform.SetParent(val3, false);
			RectTransform component = val5.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			foodSlotUI2.Icon = val5.GetComponent<Image>();
			((Graphic)foodSlotUI2.Icon).raycastTarget = false;
			foodSlotUI2.Icon.preserveAspect = true;
			((Component)foodSlotUI2.Icon).transform.SetAsLastSibling();
			if ((Object)(object)foodSlotUI2.Timer != (Object)null)
			{
				SetupDiamondTimerText(foodSlotUI2.Timer);
				((TMP_Text)foodSlotUI2.Timer).transform.SetAsLastSibling();
			}
			Slots[num] = foodSlotUI2;
		}
	}

	internal static void Place(RectTransform rt, float x, float y, float width, float height, bool fromBottomLeft = false, float rotation = 0f)
	{
		//IL_0029: 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)
		//IL_002e: 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_0036: 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_0052: 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_0076: 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)
		if (!((Object)(object)rt == (Object)null))
		{
			Vector2 anchorMin = (rt.anchorMax = (Vector2)((!fromBottomLeft) ? new Vector2(0.5f, 0.5f) : Vector2.zero));
			rt.anchorMin = anchorMin;
			rt.pivot = new Vector2(0.5f, 0.5f);
			((Transform)rt).localScale = Vector3.one;
			((Transform)rt).localRotation = Quaternion.Euler(0f, 0f, rotation);
			rt.anchoredPosition = new Vector2(x, y);
			rt.sizeDelta = new Vector2(width, height);
		}
	}

	private static void BuildGuardian(RectTransform root, Vector2 center, Vector2 iconPos, Vector2 iconSize, float nameY, bool outlinedName)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		if (Buff == null || (Object)(object)Buff.Root == (Object)null)
		{
			return;
		}
		RectTransform component = Buff.Root.GetComponent<RectTransform>();
		RectTransform component2 = new GameObject("GuardianContent", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
		((Transform)component2).SetParent((Transform)(object)root, false);
		Place(component2, center.x, center.y, 142f, 142f, fromBottomLeft: true);
		((Transform)component).SetParent((Transform)(object)component2, false);
		Place(component, 0f, 0f, 100f, 100f, fromBottomLeft: false, 45f);
		((Component)component).gameObject.SetActive(true);
		TintDiamond((Transform)(object)component);
		if ((Object)(object)Buff.Icon != (Object)null)
		{
			((Component)Buff.Icon).transform.SetParent((Transform)(object)component2, false);
			Place(((Graphic)Buff.Icon).rectTransform, iconPos.x, iconPos.y, iconSize.x, iconSize.y);
		}
		if ((Object)(object)Buff.Timer != (Object)null)
		{
			((TMP_Text)Buff.Timer).transform.SetParent((Transform)(object)component2, false);
			Place(((TMP_Text)Buff.Timer).rectTransform, 0f, nameY - 20f, 130f, 18f);
			StyleText(Buff.Timer, bold: false);
			((TMP_Text)Buff.Timer).fontSize = 13f;
			((TMP_Text)Buff.Timer).alignment = (TextAlignmentOptions)514;
			GuardianName = Object.Instantiate<TextMeshProUGUI>(Buff.Timer, (Transform)(object)component2);
			((Object)GuardianName).name = "GuardianName";
			Place(((TMP_Text)GuardianName).rectTransform, 0f, nameY, 150f, 24f);
			StyleText(GuardianName, bold: true);
			((TMP_Text)GuardianName).fontSize = ((!outlinedName) ? 17 : 18);
			if (outlinedName)
			{
				Outline(GuardianName, 0.16f);
			}
			if (outlinedName)
			{
				Outline(Buff.Timer, 0.14f);
			}
			((TMP_Text)GuardianName).text = string.Empty;
		}
		Buff.Root = ((Component)component2).gameObject;
	}

	private static void BuildTimerShadows()
	{
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: 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)
		FoodSlotUI[] slots = Slots;
		foreach (FoodSlotUI foodSlotUI in slots)
		{
			if (foodSlotUI == null || (Object)(object)foodSlotUI.Timer == (Object)null)
			{
				continue;
			}
			TextMeshProUGUI timer = foodSlotUI.Timer;
			if ((Object)(object)((TMP_Text)timer).font != (Object)null && (Object)(object)((TMP_Asset)((TMP_Text)timer).font).material != (Object)null)
			{
				((TMP_Text)timer).fontSharedMaterial = ((TMP_Asset)((TMP_Text)timer).font).material;
			}
			List<TextMeshProUGUI> list = new List<TextMeshProUGUI>();
			int siblingIndex = ((TMP_Text)timer).transform.GetSiblingIndex();
			for (int j = -1; j <= 1; j++)
			{
				for (int k = -1; k <= 1; k++)
				{
					if (j == 0 && k == 0)
					{
						continue;
					}
					TextMeshProUGUI val = Object.Instantiate<TextMeshProUGUI>(timer, ((TMP_Text)timer).transform.parent);
					((Object)val).name = "TimerRim";
					foreach (Transform item in ((TMP_Text)val).transform)
					{
						Transform val2 = item;
						Object.Destroy((Object)(object)((Component)val2).gameObject);
					}
					((TMP_Text)val).fontSharedMaterial = ((TMP_Text)timer).fontSharedMaterial;
					((Graphic)val).color = FoodTimerRimColor;
					((Graphic)val).raycastTarget = false;
					((TMP_Text)val).rectTransform.anchoredPosition = ((TMP_Text)timer).rectTransform.anchoredPosition + new Vector2((float)j, (float)k) * 1f;
					((TMP_Text)val).transform.SetSiblingIndex(siblingIndex);
					list.Add(val);
				}
			}
			((TMP_Text)timer).transform.SetAsLastSibling();
			foodSlotUI.TimerShadow = list.ToArray();
		}
	}

	internal static void SyncTimerShadow(FoodSlotUI slot)
	{
		if (slot?.TimerShadow == null || (Object)(object)slot.Timer == (Object)null)
		{
			return;
		}
		TextMeshProUGUI[] timerShadow = slot.TimerShadow;
		foreach (TextMeshProUGUI val in timerShadow)
		{
			if (!((Object)(object)val == (Object)null))
			{
				if (((TMP_Text)val).text != ((TMP_Text)slot.Timer).text)
				{
					((TMP_Text)val).text = ((TMP_Text)slot.Timer).text;
				}
				((Behaviour)val).enabled = ((Behaviour)slot.Timer).enabled;
			}
		}
	}

	private static void Outline(TextMeshProUGUI text, float width)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		((TMP_Text)text).outlineColor = new Color32((byte)12, (byte)10, (byte)8, byte.MaxValue);
		((TMP_Text)text).outlineWidth = width;
		try
		{
			((TMP_Text)text).fontMaterial.SetFloat(ShaderUtilities.ID_FaceDilate, width);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UIReforge] Face dilate failed: " + ex.Message));
		}
	}

	internal static void ApplyReferenceLayout()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
		RectTransform component = Panel.GetComponent<RectTransform>();
		Place(component, 32f, 26f, 550f, 200f, fromBottomLeft: true);
		component.pivot = Vector2.zero;
		Transform val = Panel.transform.Find("darken");
		if ((Object)(object)val != (Object)null)
		{
			((Component)val).gameObject.SetActive(false);
		}
		BuildGuardian(component, new Vector2(80f, 105f), new Vector2(2f, 12f), new Vector2(98f, 90f), -52f, outlinedName: false);
		float[] array = new float[3] { 158f, 209f, 158f };
		float[] array2 = new float[3] { 153f, 105f, 57f };
		for (int i = 0; i < Slots.Length; i++)
		{
			FoodSlotUI foodSlotUI = Slots[i];
			if (foodSlotUI != null)
			{
				Place(foodSlotUI.Root.GetComponent<RectTransform>(), array[i], array2[i], 62.5f, 62.5f, fromBottomLeft: true);
				Transform obj = foodSlotUI.Root.transform.Find("substrate");
				RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				Place(val2, 0f, 0f, 62.5f, 62.5f, fromBottomLeft: false, 45f);
				TintDiamond((Transform)(object)val2);
				if ((Object)(object)foodSlotUI.Icon != (Object)null)
				{
					Place(((Graphic)foodSlotUI.Icon).rectTransform, 0f, 2f, 28f, 28f);
				}
				PlaceGlow(foodSlotUI);
				SetupDiamondTimerText(foodSlotUI.Timer);
			}
		}
		BuildBar("Health", 122f, cutFromBottom: false, HpColor, HpTrailColor, ref HpFastImage, ref HpSlowImage, ref HpText);
		BuildBar("Stamina", 88f, cutFromBottom: true, StaminaColor, StaminaTrailColor, ref StaminaFastImage, ref StaminaSlowImage, ref StaminaText);
		LayoutResourceIcon("HealthIcon", 122f);
		LayoutResourceIcon("StaminaIcon", 88f);
		BuildTimerShadows();
		Graphic[] componentsInChildren = Panel.GetComponentsInChildren<Graphic>(true);
		foreach (Graphic val3 in componentsInChildren)
		{
			val3.raycastTarget = false;
		}
	}

	internal static void ApplyChevronLayout()
	{
		//IL_002c: 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_007f: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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_00b8: 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_00c8: 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_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_00e9: 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_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		RectTransform component = Panel.GetComponent<RectTransform>();
		Place(component, 32f, 26f, 550f, 200f, fromBottomLeft: true);
		component.pivot = Vector2.zero;
		Transform val = Panel.transform.Find("darken");
		if ((Object)(object)val != (Object)null)
		{
			((Component)val).gameObject.SetActive(false);
		}
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(80f, 105f);
		Vector2 val3 = val2 + new Vector2(77f, 0f);
		Vector2[] array = (Vector2[])(object)new Vector2[3]
		{
			val3 + new Vector2(-1.28f, 45.62f),
			val3 + new Vector2(46.72f, 0.28f),
			val3 + new Vector2(-1.28f, -46.38f)
		};
		for (int i = 0; i < Slots.Length; i++)
		{
			FoodSlotUI foodSlotUI = Slots[i];
			if (foodSlotUI != null)
			{
				Place(foodSlotUI.Root.GetComponent<RectTransform>(), array[i].x, array[i].y, 60f, 60f, fromBottomLeft: true);
				Transform obj = foodSlotUI.Root.transform.Find("substrate");
				RectTransform val4 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				Place(val4, 0f, 0f, 60f, 60f, fromBottomLeft: false, 45f);
				TintDiamond((Transform)(object)val4);
				Image val5 = ((!((Object)(object)val4 != (Object)null)) ? null : ((Component)val4).GetComponent<Image>());
				if ((Object)(object)val5 != (Object)null)
				{
					((Graphic)val5).color = ChevronCell;
				}
				if ((Object)(object)foodSlotUI.Icon != (Object)null)
				{
					Place(((Graphic)foodSlotUI.Icon).rectTransform, 0f, 0f, 33f, 33f);
				}
				PlaceGlow(foodSlotUI);
				SetupDiamondTimerText(foodSlotUI.Timer);
				if ((Object)(object)foodSlotUI.Timer != (Object)null)
				{
					((TMP_Text)foodSlotUI.Timer).rectTransform.anchoredPosition = new Vector2(10.2f, -13.5f);
					StyleText(foodSlotUI.Timer, bold: false);
					((TMP_Text)foodSlotUI.Timer).fontSize = 11f;
				}
			}
		}
		BuildGuardian(component, val2, new Vector2(2f, 12f), new Vector2(98f, 90f), -51.3f, outlinedName: false);
		if ((Object)(object)GuardianName != (Object)null)
		{
			((TMP_Text)GuardianName).fontSize = 16f;
		}
		Image val6 = ((Buff == null || !((Object)(object)Buff.Root != (Object)null)) ? null : ((IEnumerable<Image>)Buff.Root.GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)((Image img) => (Object)(object)Buff.Icon == (Object)null || (Object)(object)img != (Object)(object)Buff.Icon)));
		if ((Object)(object)val6 != (Object)null)
		{
			((Graphic)val6).color = ChevronCell;
		}
		BuildChevron(component, val3);
		string[] array2 = new string[4] { "Health", "Stamina", "HealthIcon", "StaminaIcon" };
		foreach (string text in array2)
		{
			Transform val7 = Panel.transform.Find(text);
			if ((Object)(object)val7 != (Object)null && (Object)(object)((Component)val7).GetComponent<TextMeshProUGUI>() == (Object)null)
			{
				((Component)val7).gameObject.SetActive(false);
			}
		}
		StaminaFastImage = (StaminaSlowImage = null);
		StaminaText = null;
		BuildTimerShadows();
		Graphic[] componentsInChildren = Panel.GetComponentsInChildren<Graphic>(true);
		foreach (Graphic val8 in componentsInChildren)
		{
			val8.raycastTarget = false;
		}
	}

	private static void BuildChevron(RectTransform root, Vector2 c)
	{
		//IL_00cc: 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_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: 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_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		FoodIconOverrides.TryGetValue("chevron_shape", out var value);
		FoodIconOverrides.TryGetValue("chevron_outline", out var value2);
		if ((Object)(object)value == (Object)null)
		{
			throw new InvalidDataException("chevron_shape.png is not embedded");
		}
		Vector2 mid = default(Vector2);
		((Vector2)(ref mid))..ctor(19.625f, 14.709999f);
		RectTransform val = NewRect("HpChevron", (Transform)(object)root);
		Place(val, c.x + mid.x, c.y + mid.y, 198.67f, 205.34f, fromBottomLeft: true);
		Image component = ((Component)NewRect("track", (Transform)(object)val, typeof(Image))).GetComponent<Image>();
		Stretch(((Graphic)component).rectTransform);
		component.sprite = value;
		((Graphic)component).color = ChevronTrack;
		Image component2 = ((Component)NewRect("fill", (Transform)(object)val, typeof(Image), typeof(Mask))).GetComponent<Image>();
		Stretch(((Graphic)component2).rectTransform);
		component2.sprite = value;
		((Component)component2).GetComponent<Mask>().showMaskGraphic = false;
		ChevronSlow = BuildChevronSegments("slow", ((Component)component2).transform, mid, ChevronTrail);
		ChevronFast = BuildChevronSegments("fast", ((Component)component2).transform, mid, ChevronRed);
		HpFastImage = (HpSlowImage = null);
		if ((Object)(object)value2 != (Object)null)
		{
			Image component3 = ((Component)NewRect("outline", (Transform)(object)val, typeof(Image))).GetComponent<Image>();
			Stretch(((Graphic)component3).rectTransform);
			component3.sprite = value2;
			((Graphic)component3).color = ChevronOutline;
		}
		if ((Object)(object)HpText != (Object)null)
		{
			((TMP_Text)HpText).transform.SetParent((Transform)(object)root, false);
			RectTransform rectTransform = ((TMP_Text)HpText).rectTransform;
			Vector2 anchorMin = (rectTransform.anchorMax = Vector2.zero);
			rectTransform.anchorMin = anchorMin;
			rectTransform.pivot = new Vector2(0f, 0.5f);
			((Transform)rectTransform).localScale = Vector3.one;
			((Transform)rectTransform).localRotation = Quaternion.identity;
			rectTransform.anchoredPosition = new Vector2(c.x - 79.71f, c.y + 102f);
			rectTransform.sizeDelta = new Vector2(90f, 22f);
			StyleText(HpText, bold: true);
			((TMP_Text)HpText).fontSize = 16f;
			((TMP_Text)HpText).alignment = (TextAlignmentOptions)513;
			((TMP_Text)HpText).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)HpText).overflowMode = (TextOverflowModes)0;
		}
	}

	private static void Stretch(RectTransform rt)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		rt.anchorMin = Vector2.zero;
		rt.anchorMax = Vector2.one;
		rt.pivot = new Vector2(0.5f, 0.5f);
		Vector2 offsetMin = (rt.offsetMax = Vector2.zero);
		rt.offsetMin = offsetMin;
		((Transform)rt).localScale = Vector3.one;
		((Transform)rt).localRotation = Quaternion.identity;
	}

	private static Image[] BuildChevronSegments(string name, Transform parent, Vector2 mid, Color color)
	{
		//IL_0055: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_0084: 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_009d: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: 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_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		Image[] array = (Image[])(object)new Image[ChevPath.Length - 1];
		for (int i = 0; i < array.Length; i++)
		{
			Image component = ((Component)NewRect(name + i, parent, typeof(Image))).GetComponent<Image>();
			RectTransform rectTransform = ((Graphic)component).rectTransform;
			Vector2 val = ChevPath[i + 1] - ChevPath[i];
			Vector2 anchorMin = (rectTransform.anchorMax = new Vector2(0.5f, 0.5f));
			rectTransform.anchorMin = anchorMin;
			rectTransform.pivot = new Vector2(0f, 0.5f);
			((Transform)rectTransform).localScale = Vector3.one;
			((Transform)rectTransform).localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(val.y, val.x) * 57.29578f);
			rectTransform.anchoredPosition = ChevPath[i] - mid;
			rectTransform.sizeDelta = new Vector2(0f, 44f);
			component.sprite = SolidSprite();
			((Graphic)component).color = color;
			((Behaviour)component).enabled = false;
			array[i] = component;
		}
		return array;
	}

	internal static void SetChevronFill(Image[] segments, float value)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: 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)
		if (segments == null)
		{
			return;
		}
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(19.625f, 14.709999f);
		float num = 0f;
		for (int i = 0; i < segments.Length; i++)
		{
			float num2 = num;
			Vector2 val2 = ChevPath[i + 1] - ChevPath[i];
			num = num2 + ((Vector2)(ref val2)).magnitude;
		}
		float num3 = Mathf.Clamp01(value) * num;
		for (int j = 0; j < segments.Length; j++)
		{
			Image val3 = segments[j];
			if (!((Object)(object)val3 == (Object)null))
			{
				Vector2 val4 = ChevPath[j + 1] - ChevPath[j];
				float magnitude = ((Vector2)(ref val4)).magnitude;
				float num4 = Mathf.Clamp(num3, 0f, magnitude);
				num3 -= magnitude;
				((Behaviour)val3).enabled = num4 > 0.05f;
				if (((Behaviour)val3).enabled)
				{
					Vector2 val5 = val4 / magnitude;
					float num5 = ((j <= 0) ? 0f : 14f);
					float num6 = ((!(num4 >= magnitude - 0.05f) || j >= segments.Length - 1) ? 0f : 14f);
					RectTransform rectTransform = ((Graphic)val3).rectTransform;
					rectTransform.anchoredPosition = ChevPath[j] - val - val5 * num5;
					rectTransform.sizeDelta = new Vector2(num5 + num4 + num6, 44f);
				}
			}
		}
	}

	private static void TintDiamond(Transform diamond)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)diamond == (Object)null))
		{
			Image component = ((Component)diamond).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				((Graphic)component).color = PanelDark;
			}
		}
	}

	private static RectTransform NewRect(string name, Transform parent, params Type[] components)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		List<Type> list = new List<Type>();
		list.Add(typeof(RectTransform));
		List<Type> list2 = list;
		list2.AddRange(components);
		GameObject val = new GameObject(name, list2.ToArray());
		val.transform.SetParent(parent, false);
		return val.GetComponent<RectTransform>();
	}

	private static void PlaceLeft(RectTransform rt, float left, float width, float height)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		Vector2 anchorMin = (rt.anchorMax = new Vector2(0f, 0.5f));
		rt.anchorMin = anchorMin;
		rt.pivot = new Vector2(0f, 0.5f);
		((Transform)rt).localScale = Vector3.one;
		((Transform)rt).localRotation = Quaternion.identity;
		rt.anchoredPosition = new Vector2(left, 0f);
		rt.sizeDelta = new Vector2(width, height);
	}

	private static void BuildBar(string name, float y, bool cutFromBottom, Color fill, Color trail, ref Image fast, ref Image slow, ref TextMeshProUGUI text)
	{
		//IL_00a6: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_0191: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: 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)
		Transform val = Panel.transform.Find(name);
		RectTransform val2 = NewRect("UIReforge" + name, Panel.transform);
		Place(val2, 371f, y, 266f, 27f, fromBottomLeft: true);
		float num = 232f;
		Sprite sprite = CreateCutSprite(num, 27f, cutFromBottom);
		Image component = ((Component)NewRect("track", (Transform)(object)val2, typeof(Image))).GetComponent<Image>();
		PlaceLeft(((Graphic)component).rectTransform, 0f, num, 27f);
		component.sprite = sprite;
		Color panelDark = PanelDark;
		float r = panelDark.r;
		Color panelDark2 = PanelDark;
		float g = panelDark2.g;
		Color panelDark3 = PanelDark;
		((Graphic)component).color = new Color(r, g, panelDark3.b, 0.75f);
		slow = NewFilled("slow", (Transform)(object)val2, sprite, trail, num);
		fast = NewFilled("fast", (Transform)(object)val2, sprite, fill, num);
		Image component2 = ((Component)NewRect("plate", (Transform)(object)val2, typeof(Image))).GetComponent<Image>();
		PlaceLeft(((Graphic)component2).rectTransform, num, 34f, 27f);
		component2.sprite = SolidSprite();
		((Graphic)component2).color = PanelDark;
		if ((Object)(object)text != (Object)null)
		{
			((TMP_Text)text).transform.SetParent(((Component)component2).transform, false);
			RectTransform rectTransform = ((TMP_Text)text).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.pivot = new Vector2(0.5f, 0.5f);
			((Transform)rectTransform).localScale = Vector3.one;
			((Transform)rectTransform).localRotation = Quaternion.identity;
			rectTransform.offsetMin = new Vector2(1f, 0f);
			rectTransform.offsetMax = new Vector2(-1f, 0f);
			StyleText(text, bold: true);
			((TMP_Text)text).fontSize = 15f;
			((TMP_Text)text).alignment = (TextAlignmentOptions)514;
			((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)text).overflowMode = (TextOverflowModes)0;
		}
		if ((Object)(object)val != (Object)null)
		{
			((Component)val).gameObject.SetActive(false);
		}
	}

	private static Image NewFilled(string name, Transform parent, Sprite sprite, Color color, float width)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		Image component = ((Component)NewRect(name, parent, typeof(Image))).GetComponent<Image>();
		PlaceLeft(((Graphic)component).rectTransform, 0f, width, 27f);
		component.sprite = sprite;
		((Graphic)component).color = color;
		component.type = (Type)3;
		component.fillMethod = (FillMethod)0;
		component.fillOrigin = 0;
		component.fillAmount = 1f;
		component.preserveAspect = false;
		return component;
	}

	private static Sprite SolidSprite()
	{
		//IL_0029: 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)
		if ((Object)(object)solidSprite == (Object)null)
		{
			solidSprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 4f, 4f), new Vector2(0.5f, 0.5f));
			Object.DontDestroyOnLoad((Object)(object)solidSprite);
		}
		return solidSprite;
	}

	private static Sprite CreateCutSprite(float width, float height, bool cutFromBottom)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		string text = width + "x" + height + ((!cutFromBottom) ? "t" : "b");
		if (cutSprites.TryGetValue(text, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		int num = Mathf.RoundToInt(width * 4f);
		int num2 = Mathf.RoundToInt(height * 4f);
		Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Texture)val).filterMode = (FilterMode)1;
		Color32[] array = (Color32[])(object)new Color32[num * num2];
		for (int i = 0; i < num2; i++)
		{
			float num3 = ((!cutFromBottom) ? ((float)(num2 - i) - 0.5f) : ((float)i + 0.5f));
			for (int j = 0; j < num; j++)
			{
				float num4 = Mathf.Clamp01((float)j + 0.5f - num3 + 0.5f);
				ref Color32 reference = ref array[i * num + j];
				reference = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num4 * 255f));
			}
		}
		val.SetPixels32(array);
		val.Apply(false, true);
		Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num2), new Vector2(0.5f, 0.5f), 100f);
		((Object)val2).name = "UIReforgeBarCut_" + text;
		Object.DontDestroyOnLoad((Object)(object)val);
		Object.DontDestroyOnLoad((Object)(object)val2);
		cutSprites[text] = val2;
		return val2;
	}

	internal static void SetupDiamondTimerText(TextMeshProUGUI text)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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 (!((Object)(object)text == (Object)null))
		{
			RectTransform rectTransform = ((TMP_Text)text).rectTransform;
			rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
			rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
			rectTransform.pivot = new Vector2(0.5f, 0.5f);
			rectTransform.anchoredPosition = new Vector2(12f, -13f);
			rectTransform.sizeDelta = new Vector2(46f, 20f);
			StyleText(text, bold: true);
			((TMP_Text)text).fontSize = 14f;
			((TMP_Text)text).alignment = (TextAlignmentOptions)514;
			((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)text).overflowMode = (TextOverflowModes)0;
		}
	}

	private static void LayoutResourceIcon(string name, float y)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		Transform val = Panel.transform.Find(name);
		Image val2 = ((!((Object)(object)val != (Object)null)) ? null : ((Component)val).GetComponent<Image>());
		if ((Object)(object)val2 == (Object)null)
		{
			GameObject val3 = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val3.transform.SetParent(Panel.transform, false);
			val2 = val3.GetComponent<Image>();
		}
		if (FoodIconOverrides.TryGetValue(name, out var value))
		{
			val2.sprite = value;
		}
		((Graphic)val2).color = Color.white;
		val2.preserveAspect = true;
		((Behaviour)val2).enabled = (Object)(object)val2.sprite != (Object)null;
		Place(((Graphic)val2).rectTransform, 514f, y, 12f, 14f, fromBottomLeft: true);
		((Component)val2).transform.SetAsLastSibling();
	}

	private static void StyleText(TextMeshProUGUI text, bool bold)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//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)
		((TMP_Text)text).enableAutoSizing = false;
		((TMP_Text)text).fontStyle = (FontStyles)(bold ? 1 : 0);
		((Graphic)text).color = Color.white;
		((TMP_Text)text).faceColor = Color32.op_Implicit(Color.white);
		((TMP_Text)text).outlineWidth = 0f;
		((TMP_Text)text).enableVertexGradient = false;
		((TMP_Text)text).characterSpacing = 0f;
	}

	internal static void FindBarGroup(Transform groupRoot, out Image fastImage, out Image slowImage, out TextMeshProUGUI text)
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		fastImage = null;
		slowImage = null;
		text = null;
		if ((Object)(object)groupRoot == (Object)null)
		{
			return;
		}
		Transform val = groupRoot.Find("Mask");
		Transform val2 = groupRoot.Find("Mask/fast/bar");
		Transform val3 = groupRoot.Find("Mask/slow/bar");
		if ((Object)(object)val2 != (Object)null)
		{
			fastImage = ((Component)val2).GetComponent<Image>();
			SetupFilledBar(fastImage);
		}
		if ((Object)(object)val3 != (Object)null)
		{
			slowImage = ((Component)val3).GetComponent<Image>();
			SetupFilledBar(slowImage);
		}
		text = ((Component)groupRoot).GetComponentInChildren<TextMeshProUGUI>(true);
		if ((Object)(object)text != (Object)null)
		{
			RectTransform rectTransform = ((TMP_Text)text).rectTransform;
			object obj = ((val is RectTransform) ? val : null);
			RectTransform val4 = default(RectTransform);
			if (obj != null)
			{
				val4 = (RectTransform)obj;
				obj = val4;
			}
			if (obj != null)
			{
				((Transform)rectTransform).SetParent((Transform)(object)val4, true);
			}
			rectTransform.anchorMin = new Vector2(1f, 0.5f);
			rectTransform.anchorMax = new Vector2(1f, 0.5f);
			rectTransform.pivot = new Vector2(1f, 0.5f);
			rectTransform.anchoredPosition = new Vector2(-10f, 0f);
			rectTransform.sizeDelta = new Vector2(80f, rectTransform.sizeDelta.y);
			((TMP_Text)text).alignment = (TextAlignmentOptions)516;
			((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)text).overflowMode = (TextOverflowModes)0;
			((TMP_Text)text).transform.SetAsLastSibling();
		}
	}

	internal static void SetupFilledBar(Image img)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)img == (Object)null))
		{
			img.type = (Type)3;
			img.fillMethod = (FillMethod)0;
			img.fillOrigin = 0;
			if ((Object)(object)SolidBarSprite == (Object)null)
			{
				SolidBarSprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f));
			}
			img.sprite = SolidBarSprite;
			img.preserveAspect = false;
		}
	}

	internal static void HideVanillaStamina(Hud hud)
	{
		string[] array = new string[4] { "Stamina", "stamina", "StaminaBar", "StaminaPanel" };
		Transform[] componentsInChildren = hud.m_rootObject.GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			string[] array2 = array;
			foreach (string a in array2)
			{
				if (string.Equals(a, ((Object)val).name, StringComparison.OrdinalIgnoreCase) && ((Object)(object)Panel == (Object)null || !val.IsChildOf(Panel.transform)))
				{
					if (((Component)val).gameObject.activeSelf)
					{
						HiddenVanillaStamina.Add(((Component)val).gameObject);
					}
					((Component)val).gameObject.SetActive(false);
					break;
				}
			}
		}
	}

	internal static void CaptureVanillaGuardian(Hud hud)
	{
		try
		{
			if ((Object)(object)hud?.m_rootObject == (Object)null)
			{
				return;
			}
			Transform val = FindDeepChild(hud.m_rootObject.transform, "GuardianPower");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)"[UIReforge] Vanilla GuardianPower not found");
				return;
			}
			VanillaGuardianRoot = ((Component)val).gameObject;
			Transform obj = val.Find("Icon");
			VanillaGuardianIcon = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			Transform val2 = val.Find("TimeBar");
			if ((Object)(object)val2 != (Object)null)
			{
				VanillaGuardianTimeBar = ((Component)val2).GetComponent<Image>();
				if ((Object)(object)VanillaGuardianTimeBar == (Object)null)
				{
					VanillaGuardianTimeBar = ((Component)val2).GetComponentInChildren<Image>(true);
				}
			}
			Transform obj2 = val.Find("TimeText");
			VanillaGuardianTimeText = ((obj2 != null) ? ((Component)obj2).GetComponent<TextMeshProUGUI>() : null);
			if ((Object)(object)VanillaGuardianTimeText == (Object)null)
			{
				VanillaGuardianTimeText = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			}
			Transform obj3 = val.Find("TimeText");
			VanillaGuardianLegacyTimeText = ((obj3 != null) ? ((Component)obj3).GetComponent<Text>() : null);
			if ((Object)(object)VanillaGuardianLegacyTimeText == (Object)null)
			{
				VanillaGuardianLegacyTimeText = ((Component)val).GetComponentInChildren<Text>(true);
			}
			Transform obj4 = val.Find("Name");
			VanillaGuardianNameText = ((obj4 != null) ? ((Component)obj4).GetComponent<TextMeshProUGUI>() : null);
			if ((Object)(object)VanillaGuardianNameText == (Object)null)
			{
				VanillaGuardianNameText = ((IEnumerable<TextMeshProUGUI>)((Component)val).GetComponentsInChildren<TextMeshProUGUI>(true)).FirstOrDefault((Func<TextMeshProUGUI, bool>)((TextMeshProUGUI x) => ((Object)x).name == "Name"));
			}
			Transform obj5 = val.Find("Name");
			VanillaGuardianLegacyNameText = ((obj5 != null) ? ((Component)obj5).GetComponent<Text>() : null);
			if ((Object)(object)VanillaGuardianLegacyNameText == (Object)null)
			{
				VanillaGuardianLegacyNameText = ((IEnumerable<Text>)((Component)val).GetComponentsInChildren<Text>(true)).FirstOrDefault((Func<Text, bool>)((Text x) => ((Object)x).name == "Name"));
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UIReforge] CaptureVanillaGuardian error: " + ex));
		}
	}

	internal static void HideVanillaGuardianVisuals()
	{
		try
		{
			if (!((Object)(object)VanillaGuardianRoot == (Object)null))
			{
				Graphic[] componentsInChildren = VanillaGuardianRoot.GetComponentsInChildren<Graphic>(true);
				foreach (Graphic val in componentsInChildren)
				{
					((Behaviour)val).enabled = false;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UIReforge] HideVanillaGuardianVisuals error: " + ex));
		}
	}

	internal static void RefreshGuardian(Hud hud)
	{
		if (guardianUpdateFrame == Time.frameCount)
		{
			return;
		}
		guardianUpdateFrame = Time.frameCount;
		try
		{
			if (!((Object)(object)hud == (Object)null))
			{
				if ((Object)(object)VanillaGuardianRoot == (Object)null)
				{
					CaptureVanillaGuardian(hud);
				}
				HideVanillaGuardianVisuals();
				SyncGuardianFromVanilla();
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UIReforge] RefreshGuardian error: " + ex));
		}
	}

	internal static void SyncGuardianFromVanilla()
	{
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (Buff == null || (Object)(object)Buff.Root == (Object)null)
			{
				return;
			}
			if ((Object)(object)VanillaGuardianRoot == (Object)null)
			{
				Buff.Root.SetActive(false);
				return;
			}
			string text = string.Empty;
			if ((Object)(object)VanillaGuardianTimeText != (Object)null)
			{
				text = ((TMP_Text)VanillaGuardianTimeText).text;
			}
			else if ((Object)(object)VanillaGuardianLegacyTimeText != (Object)null)
			{
				text = VanillaGuardianLegacyTimeText.text;
			}
			string text2 = string.Empty;
			if ((Object)(object)VanillaGuardianNameText != (Object)null)
			{
				text2 = ((TMP_Text)VanillaGuardianNameText).text;
			}
			else if ((Object)(object)VanillaGuardianLegacyNameText != (Object)null)
			{
				text2 = VanillaGuardianLegacyNameText.text;
			}
			if ((Object)(object)GuardianName != (Object)null)
			{
				((TMP_Text)GuardianName).text = text2.ToUpperInvariant();
			}
			Sprite vanillaSprite = ((!((Object)(object)VanillaGuardianIcon != (Object)null)) ? null : VanillaGuardianIcon.sprite);
			Sprite val = ResolveGuardianIcon(text2, vanillaSprite);
			bool flag = (Object)(object)val != (Object)null || !string.IsNullOrWhiteSpace(text);
			Buff.Root.SetActive(flag);
			if (!flag)
			{
				return;
			}
			if ((Object)(object)Buff.Icon != (Object)null)
			{
				Buff.Icon.sprite = val;
				((Behaviour)Buff.Icon).enabled = true;
				((Component)Buff.Icon).gameObject.SetActive(true);
				((Graphic)Buff.Icon).color = Color.white;
				Buff.Icon.preserveAspect = true;
				((Component)Buff.Icon).transform.localScale = Vector3.one;
				((Component)Buff.Icon).transform.SetAsLastSibling();
			}
			if ((Object)(object)Buff.Timer != (Object)null)
			{
				float num = 0f;
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					StatusEffect val2 = default(StatusEffect);
					Player.m_localPlayer.GetGuardianPowerHUD(ref val2, ref num);
				}
				((TMP_Text)Buff.Timer).text = text;
				((Behaviour)Buff.Timer).enabled = num > 0f;
				((TMP_Text)Buff.Timer).transform.SetAsLastSibling();
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UIReforge] SyncGuardianFromVanilla error: " + ex));
		}
	}

	internal static Sprite ResolveGuardianIcon(string guardianName, Sprite vanillaSprite)
	{
		try
		{
			string text = ((!((Object)(object)Player.m_localPlayer != (Object)null)) ? null : Player.m_localPlayer.GetGuardianPowerName());
			if (!string.IsNullOrEmpty(text) && GuardianEmblems.TryGetValue(text, out var value) && FoodIconOverrides.TryGetValue(value, out var value2))
			{
				return value2;
			}
			if (!string.IsNullOrEmpty(text) && FoodIconOverrides.TryGetValue(text, out var value3))
			{
				return value3;
			}
			if (!string.IsNullOrWhiteSpace(guardianName))
			{
				string text2 = guardianName.ToLowerInvariant().Replace("$", string.Empty).Replace("guardian_", string.Empty);
				foreach (KeyValuePair<string, string> guardianEmblem in GuardianEmblems)
				{
					if (text2.Contains(guardianEmblem.Value.ToLowerInvariant().Replace("the", string.Empty)) && FoodIconOverrides.TryGetValue(guardianEmblem.Value, out var value4))
					{
						return value4;
					}
				}
				if (FoodIconOverrides.TryGetValue(guardianName, out var value5))
				{
					return value5;
				}
			}
			if ((Object)(object)vanillaSprite != (Object)null && FoodIconOverrides.TryGetValue(((Object)vanillaSprite).name, out var value6))
			{
				return value6;
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UIReforge] ResolveGuardianIcon error: " + ex));
		}
		return vanillaSprite;
	}

	internal static Transform FindDeepChild(Transform parent, string exactName)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		if ((Object)(object)parent == (Object)null)
		{
			return null;
		}
		foreach (Transform item in parent)
		{
			Transform val = item;
			if (string.Equals(((Object)val).name, exactName, StringComparison.Ordinal))
			{
				return val;
			}
			Transform val2 = FindDeepChild(val, exactName);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		return null;
	}

	internal static Image FindVanillaFoodIconImage(Transform slotTr)
	{
		//IL_004a: 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_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_0074: 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_0089: 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)
		Image[] componentsInChildren = ((Component)slotTr).GetComponentsInChildren<Image>(true);
		foreach (Image val in componentsInChildren)
		{
			if (!(((Object)val).name == "UIReforgeIcon") && !(((Object)val).name == "UIReforgeGlow"))
			{
				RectTransform rectTransform = ((Graphic)val).rectTransform;
				if ((!(rectTransform.anchorMin == Vector2.zero) || !(rectTransform.anchorMax == Vector2.one) || !(rectTransform.offsetMin == Vector2.zero) || !(rectTransform.offsetMax == Vector2.zero)) && (val.preserveAspect || ((Object)val).name.ToLower().Contains("icon")))
				{
					return val;
				}
			}
		}
		return null;
	}

	internal static string FormatTime(float seconds)
	{
		int num = Mathf.CeilToInt(Mathf.Max(0f, seconds));
		return (num < 60) ? $"{num}s" : $"{Mathf.CeilToInt((float)num / 60f)}m";
	}

	internal static FoodStat DominantStat(ItemData item)
	{
		SharedData val = item?.m_shared;
		if (val == null)
		{
			return FoodStat.Neutral;
		}
		float[] array = new float[3] { val.m_food, val.m_foodStamina, val.m_foodEitr };
		int num = 0;
		for (int i = 1; i < array.Length; i++)
		{
			if (array[i] > array[num])
			{
				num = i;
			}
		}
		float num2 = 0f;
		for (int j = 0; j < array.Length; j++)
		{
			if (j != num)
			{
				num2 = Mathf.Max(num2, array[j]);
			}
		}
		if (array[num] <= 0f || array[num] < num2 * 1.3f)
		{
			return FoodStat.Neutral;
		}
		return num switch
		{
			0 => FoodStat.Health, 
			1 => FoodStat.Stamina, 
			_ => FoodStat.Eitr, 
		};
	}

	internal static Color GlowColor(FoodStat stat)
	{
		//IL_002d: 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_0061: 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)
		return (Color)(stat switch
		{
			FoodStat.Health => new Color(1f, 0.22f, 0.18f, 1f), 
			FoodStat.Stamina => new Color(1f, 0.78f, 0.22f, 1f), 
			FoodStat.Eitr => new Color(0.32f, 0.58f, 1f, 1f), 
			_ => new Color(1f, 1f, 1f, 0.5f), 
		});
	}

	internal static Color TintColor(FoodStat stat)
	{
		//IL_002d: 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_0061: 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)
		return (Color)(stat switch
		{
			FoodStat.Health => new Color(1f, 0.64f, 0.6f, 1f), 
			FoodStat.Stamina => new Color(1f, 0.88f, 0.56f, 1f), 
			FoodStat.Eitr => new Color(0.68f, 0.8f, 1f, 1f), 
			_ => Color.white, 
		});
	}

	internal static bool IsStyledIcon(Sprite sprite)
	{
		return (Object)(object)sprite != (Object)null && (GlowSprites.ContainsKey(sprite) || FoodIconOverrides.ContainsValue(sprite));
	}

	private static void PlaceGlow(FoodSlotUI slot)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0057: 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_0065: 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_0079: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)slot?.Glow == (Object)null) && !((Object)(object)slot.Icon == (Object)null))
		{
			RectTransform rectTransform = ((Graphic)slot.Icon).rectTransform;
			Place(((Graphic)slot.Glow).rectTransform, rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y, rectTransform.sizeDelta.x * 1.7f, rectTransform.sizeDelta.y * 1.7f);
		}
	}

	internal static void UpdateFoodColour(FoodSlotUI slot, Sprite icon, ItemData item, float blink)
	{
		//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_0082: 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)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		FoodIconColorMode foodIconColorMode = ((HudUpdatePlugin.FoodColor != null) ? HudUpdatePlugin.FoodColor.Value : FoodIconColorMode.Off);
		FoodStat stat = DominantStat(item);
		bool flag = foodIconColorMode == FoodIconColorMode.Tint || foodIconColorMode == FoodIconColorMode.TintAndGlow;
		bool flag2 = foodIconColorMode == FoodIconColorMode.Glow || foodIconColorMode == FoodIconColorMode.TintAndGlow;
		if ((Object)(object)slot.Icon != (Object)null)
		{
			Color color = ((!flag || !IsStyledIcon(icon)) ? Color.white : TintColor(stat));
			color.a = blink;
			((Graphic)slot.Icon).color = color;
		}
		if (!((Object)(object)slot.Glow == (Object)null))
		{
			float num = ((HudUpdatePlugin.FoodGlowStrength == null) ? 0.7f : HudUpdatePlugin.FoodGlowStrength.Value);
			((Behaviour)slot.Glow).enabled = flag2 && (Object)(object)icon != (Object)null && num > 0f;
			if (((Behaviour)slot.Glow).enabled)
			{
				slot.Glow.sprite = ((!((Object)(object)icon != (Object)null) || !GlowSprites.TryGetValue(icon, out var value)) ? RadialGlow() : value);
				Color color2 = GlowColor(stat);
				color2.a *= num * blink;
				((Graphic)slot.Glow).color = color2;
			}
		}
	}

	internal static void HideFoodGlow(FoodSlotUI slot)
	{
		if ((Object)(object)slot?.Glow != (Object)null)
		{
			((Behaviour)slot.Glow).enabled = false;
		}
	}

	private static Sprite BuildGlowSprite(Texture2D source, string key)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.RoundToInt(37.647057f);
		int num2 = (64 - num) / 2;
		float[] array = new float[4096];
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				array[(i + num2) * 64 + j + num2] = source.GetPixelBilinear(((float)j + 0.5f) / (float)num, ((float)i + 0.5f) / (float)num).a;
			}
		}
		float[] array2 = new float[4096];
		for (int k = 0; k < 3; k++)
		{
			BoxBlur(array, array2, 64, 3, horizontal: true);
			BoxBlur(array2, array, 64, 3, horizontal: false);
		}
		float num3 = 0f;
		float[] array3 = array;
		foreach (float num4 in array3)
		{
			num3 = Mathf.Max(num3, num4);
		}
		if (num3 <= 0f)
		{
			num3 = 1f;
		}
		Color32[] array4 = (Color32[])(object)new Color32[4096];
		for (int m = 0; m < array4.Length; m++)
		{
			ref Color32 reference = ref array4[m];
			reference = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(Mathf.Pow(array[m] / num3, 0.8f) * 255f));
		}
		Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Object)val).name = key + "_glow";
		Texture2D val2 = val;
		val2.SetPixels32(array4);
		val2.Apply(false, true);
		Sprite val3 = Sprite.Create(val2, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		((Object)val3).name = key + "_glow";
		Object.DontDestroyOnLoad((Object)(object)val2);
		Object.DontDestroyOnLoad((Object)(object)val3);
		return val3;
	}

	private static void BoxBlur(float[] src, float[] dst, int size, int radius, bool horizontal)
	{
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num = 0f;
				for (int k = -radius; k <= radius; k++)
				{
					int num2 = ((!horizontal) ? j : (j + k));
					int num3 = ((!horizontal) ? (i + k) : i);
					if (num2 >= 0 && num3 >= 0 && num2 < size && num3 < size)
					{
						num += src[num3 * size + num2];
					}
				}
				dst[i * size + j] = num / (float)(radius * 2 + 1);
			}
		}
	}

	private static Sprite RadialGlow()
	{
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)radialGlow != (Object)null)
		{
			return radialGlow;
		}
		Color32[] array = (Color32[])(object)new Color32[4096];
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				float num = ((float)j + 0.5f) / 64f * 2f - 1f;
				float num2 = ((float)i + 0.5f) / 64f * 2f - 1f;
				float num3 = Mathf.Sqrt(num * num + num2 * num2);
				float num4 = Mathf.Clamp01(1f - num3);
				ref Color32 reference = ref array[i * 64 + j];
				reference = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num4 * num4 * 255f));
			}
		}
		Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		Texture2D val2 = val;
		val2.SetPixels32(array);
		val2.Apply(false, true);
		radialGlow = Sprite.Create(val2, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		Object.DontDestroyOnLoad((Object)(object)val2);
		Object.DontDestroyOnLoad((Object)(object)radialGlow);
		return radialGlow;
	}

	private static Sprite FoodGlyph(string glyph)
	{
		Sprite value;
		return (glyph == null || !FoodIconOverrides.TryGetValue("food_" + glyph, out value)) ? null : value;
	}

	internal static Sprite ResolveFoodIcon(Food food)
	{
		ItemData val = food?.m_item;
		if (val == null)
		{
			return DefaultFoodIcon;
		}
		string text = ((!((Object)(object)val.m_dropPrefab != (Object)null)) ? null : ((Object)val.m_dropPrefab).name);
		string text2 = ((val.m_shared == null) ? null : val.m_shared.m_name);
		if (text2 != null && FoodIconOverrides.TryGetValue(text2, out var value))
		{
			return value;
		}
		if (text != null && FoodIconOverrides.TryGetValue(text, out var value2))
		{
			return value2;
		}
		string text3 = text2?.Replace("$item_", string.Empty).Replace("_", string.Empty);
		if (text3 != null && FoodIconOverrides.TryGetValue(text3, out var value3))
		{
			return value3;
		}
		if (text != null && FoodGlyphByPrefab.TryGetValue(text, out var value4))
		{
			Sprite val2 = FoodGlyph(value4);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		string text4 = ((text ?? string.Empty) + " " + (text3 ?? string.Empty)).ToLowerInvariant();
		string[][] foodGlyphKeywords = FoodGlyphKeywords;
		foreach (string[] array in foodGlyphKeywords)
		{
			if (text4.Contains(array[0]))
			{
				Sprite val3 = FoodGlyph(array[1]);
				if ((Object)(object)val3 != (Object)null)
				{
					return val3;
				}
				break;
			}
		}
		if (val.m_shared != null && val.m_shared.m_icons != null && val.m_shared.m_icons.Length > 0)
		{
			return val.m_shared.m_icons[0];
		}
		return DefaultFoodIcon;
	}
}
[HarmonyPatch]
internal static class HudHealthPatch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method(typeof(Hud), "UpdateHealth", (Type[])null, (Type[])null);
	}

	private static bool Prefix(Hud __instance)
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return true;
		}
		HudState.EnsureInit(__instance);
		if ((Object)(object)HudState.Panel == (Object)null)
		{
			return true;
		}
		HudState.RefreshGuardian(__instance);
		float health = ((Character)localPlayer).GetHealth();
		float num = Mathf.Max(1f, ((Character)localPlayer).GetMaxHealth());
		float num2 = Mathf.Clamp01(health / num);
		if (HudState.HpFastValue < 0f)
		{
			HudState.HpFastValue = num2;
			HudState.HpSlowValue = num2;
		}
		float deltaTime = Time.deltaTime;
		HudState.HpFastValue = num2;
		HudState.HpSlowValue = ((!(num2 >= HudState.HpSlowValue)) ? Mathf.MoveTowards(HudState.HpSlowValue, num2, 0.3f * deltaTime) : num2);
		if ((Object)(object)HudState.HpFastImage != (Object)null)
		{
			HudState.HpFastImage.fillAmount = HudState.HpFastValue;
		}
		if ((Object)(object)HudState.HpSlowImage != (Object)null)
		{
			HudState.HpSlowImage.fillAmount = HudState.HpSlowValue;
		}
		HudState.SetChevronFill(HudState.ChevronFast, HudState.HpFastValue);
		HudState.SetChevronFill(HudState.ChevronSlow, HudState.HpSlowValue);
		if ((Object)(object)HudState.HpText != (Object)null)
		{
			((TMP_Text)HudState.HpText).text = ((HudState.ActiveStyle != HudStyle.Chevron) ? Mathf.RoundToInt(health).ToString() : (Mathf.RoundToInt(health) + " HP"));
		}
		return false;
	}
}
[HarmonyPatch]
internal static class HudStaminaPatch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method(typeof(Hud), "UpdateStamina", (Type[])null, (Type[])null);
	}

	private static bool Prefix(Hud __instance)
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return true;
		}
		HudState.EnsureInit(__instance);
		if ((Object)(object)HudState.Panel == (Object)null)
		{
			return true;
		}
		HudState.RefreshGuardian(__instance);
		if (HudState.ActiveStyle == HudStyle.Chevron)
		{
			return true;
		}
		float stamina = localPlayer.GetStamina();
		float num = Mathf.Max(1f, ((Character)localPlayer).GetMaxStamina());
		float num2 = Mathf.Clamp01(stamina / num);
		if (HudState.StaminaFastValue < 0f)
		{
			HudState.StaminaFastValue = num2;
			HudState.StaminaSlowValue = num2;
		}
		float deltaTime = Time.deltaTime;
		HudState.StaminaFastValue = num2;
		HudState.StaminaSlowValue = ((!(num2 >= HudState.StaminaSlowValue)) ? Mathf.MoveTowards(HudState.StaminaSlowValue, num2, 1.2f * deltaTime) : num2);
		if ((Object)(object)HudState.StaminaFastImage != (Object)null)
		{
			HudState.StaminaFastImage.fillAmount = HudState.StaminaFastValue;
		}
		if ((Object)(object)HudState.StaminaSlowImage != (Object)null)
		{
			HudState.StaminaSlowImage.fillAmount = HudState.StaminaSlowValue;
		}
		if ((Object)(object)HudState.StaminaText != (Object)null)
		{
			((TMP_Text)HudState.StaminaText).text = Mathf.RoundToInt(stamina).ToString();
		}
		return false;
	}
}
[HarmonyPatch]
internal static class HudFoodPatch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method(typeof(Hud), "UpdateFood", (Type[])null, (Type[])null);
	}

	private static bool Prefix(Hud __instance)
	{
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return true;
		}
		HudState.EnsureInit(__instance);
		if ((Object)(object)HudState.Panel == (Object)null)
		{
			return true;
		}
		List<Food> foods = localPlayer.GetFoods();
		for (int i = 0; i < HudState.Slots.Length; i++)
		{
			HudState.FoodSlotUI foodSlotUI = HudState.Slots[i];
			if (foodSlotUI == null || (Object)(object)foodSlotUI.Root == (Object)null)
			{
				continue;
			}
			if (i < foods.Count)
			{
				foodSlotUI.Root.SetActive(true);
				Food val = foods[i];
				Sprite val2 = HudState.ResolveFoodIcon(val);
				if ((Object)(object)foodSlotUI.Icon != (Object)null)
				{
					foodSlotUI.Icon.sprite = val2;
					((Behaviour)foodSlotUI.Icon).enabled = true;
					((Transform)((Graphic)foodSlotUI.Icon).rectTransform).localScale = Vector3.one;
				}
				float blink = ((!val.CanEatAgain()) ? 1f : (0.7f + Mathf.Sin(Time.time * 5f) * 0.3f));
				HudState.UpdateFoodColour(foodSlotUI, val2, val.m_item, blink);
				if ((Object)(object)foodSlotUI.Timer != (Object)null)
				{
					((TMP_Text)foodSlotUI.Timer).text = HudState.FormatTime(val.m_time);
					((Behaviour)foodSlotUI.Timer).enabled = true;
				}
				HudState.SyncTimerShadow(foodSlotUI);
			}
			else
			{
				foodSlotUI.Root.SetActive(true);
				if ((Object)(object)foodSlotUI.Icon != (Object)null)
				{
					foodSlotUI.Icon.sprite = HudState.DefaultFoodIcon;
					((Behaviour)foodSlotUI.Icon).enabled = (Object)(object)HudState.DefaultFoodIcon != (Object)null;
					((Graphic)foodSlotUI.Icon).color = new Color(1f, 1f, 1f, 0.35f);
					((Transform)((Graphic)foodSlotUI.Icon).rectTransform).localScale = Vector3.one;
				}
				HudState.HideFoodGlow(foodSlotUI);
				if ((Object)(object)foodSlotUI.Timer != (Object)null)
				{
					((Behaviour)foodSlotUI.Timer).enabled = false;
				}
				HudState.SyncTimerShadow(foodSlotUI);
			}
		}
		return false;
	}
}
internal static class TmpFontFix
{
	private static TMP_FontAsset _defaultFont;

	private static bool _logged;

	private static TMP_FontAsset GetDefaultFont()
	{
		if ((Object)(object)_defaultFont != (Object)null)
		{
			return _defaultFont;
		}
		_defaultFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name == "LiberationSans SDF"));
		if ((Object)(object)_defaultFont == (Object)null)
		{
			_defaultFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name.Contains("LiberationSans")));
		}
		if ((Object)(object)_defaultFont == (Object)null)
		{
			_defaultFont = (from f in Resources.FindObjectsOfTypeAll<TMP_FontAsset>()
				where (Object)(object)f != (Object)null && ((Object)f).name.IndexOf("Sans", StringComparison.OrdinalIgnoreCase) >= 0
				orderby (!(((Object)f).name == "NotoSansJP-Regular SDF")) ? 1 : 0
				select f).ThenBy<TMP_FontAsset, string>((TMP_FontAsset f) => ((Object)f).name, StringComparer.Ordinal).FirstOrDefault();
		}
		if ((Object)(object)_defaultFont == (Object)null)
		{
			_defaultFont = TMP_Settings.defaultFontAsset ?? (from f in Resources.FindObjectsOfTypeAll<TMP_FontAsset>()
				where (Object)(object)f != (Object)null
				select f).OrderBy<TMP_FontAsset, string>((TMP_FontAsset f) => ((Object)f).name, StringComparer.Ordinal).FirstOrDefault();
		}
		if (!_logged)
		{
			_logged = true;
			Debug.Log((object)((!((Object)(object)_defaultFont != (Object)null)) ? "[UIReforge] TMP default font NOT FOUND" : $"[UIReforge] TMP default font: {((Object)_defaultFont).name}"));
		}
		return _defaultFont;
	}

	public static void ApplyFontsToPrefab(GameObject prefabRoot)
	{
		if ((Object)(object)prefabRoot == (Object)null)
		{
			return;
		}
		TMP_FontAsset defaultFont = GetDefaultFont();
		if ((Object)(object)defaultFont == (Object)null)
		{
			return;
		}
		TMP_Text[] componentsInChildren = prefabRoot.GetComponentsInChildren<TMP_Text>(true);
		TMP_Text[] array = componentsInChildren;
		foreach (TMP_Text val in array)
		{
			if (!((Object)(object)val == (Object)null) && (Object)(object)val.font == (Object)null)
			{
				val.font = defaultFont;
				val.enableAutoSizing = false;
			}
		}
		TMP_SubMeshUI[] componentsInChildren2 = prefabRoot.GetComponentsInChildren<TMP_SubMeshUI>(true);
		TMP_SubMeshUI[] array2 = componentsInChildren2;
		foreach (TMP_SubMeshUI val2 in array2)
		{
			if (!((Object)(object)val2 == (Object)null) && (Object)(object)val2.textComponent != (Object)null && (Object)(object)val2.textComponent.font == (Object)null)
			{
				val2.textComponent.font = defaultFont;
				val2.textComponent.enableAutoSizing = false;
			}
		}
	}

	public static void FixFontsOnInstance(GameObject root)
	{
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		TMP_FontAsset defaultFont = GetDefaultFont();
		if ((Object)(object)defaultFont == (Object)null)
		{
			return;
		}
		TMP_Text[] componentsInChildren = root.GetComponentsInChildren<TMP_Text>(true);
		TMP_Text[] array = componentsInChildren;
		foreach (TMP_Text val in array)
		{
			if (!((Object)(object)val == (Object)null) && (Object)(object)val.font == (Object)null)
			{
				val.font = defaultFont;
				val.enableAutoSizing = false;
				val.ForceMeshUpdate(false, false);
			}
		}
	}
}