Decompiled source of RiskUIFix v1.0.2

RiskUIFix.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using MaterialHud;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.UI;
using ZioConfigFile;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RiskUIFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("RiskUIFix")]
[assembly: AssemblyTitle("RiskUIFix")]
[assembly: AssemblyVersion("1.0.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RiskUIFix
{
	internal static class CollapseDisplayCompatibility
	{
		internal const string PluginGuid = "Gorakh.CollapseDisplay";

		private static Type _providerType;

		private static FieldInfo _typeField;

		private static object _hudType;

		private static object _allyListType;

		private static bool _available;

		private static bool _initialized;

		internal static void Initialize()
		{
			if (_initialized)
			{
				return;
			}
			_initialized = true;
			if (Chainloader.PluginInfos.ContainsKey("Gorakh.CollapseDisplay"))
			{
				_providerType = Type.GetType("CollapseDisplay.HealthBarTypeProvider, CollapseDisplay", throwOnError: false);
				_typeField = _providerType?.GetField("Type", BindingFlags.Instance | BindingFlags.Public);
				if (_providerType == null || _typeField == null || !_typeField.FieldType.IsEnum || !Enum.IsDefined(_typeField.FieldType, "Hud") || !Enum.IsDefined(_typeField.FieldType, "AllyList"))
				{
					RiskUIFixPlugin.Log.LogWarning((object)"CollapseDisplay was found, but its health-bar type provider API was unavailable.");
					return;
				}
				_hudType = Enum.Parse(_typeField.FieldType, "Hud");
				_allyListType = Enum.Parse(_typeField.FieldType, "AllyList");
				_available = true;
				RegisterPrefab(RiskUIPlugin.CreateHud(), _hudType);
				RegisterPrefab(RiskUIPlugin.CreateAllyCard(), _allyListType);
			}
		}

		internal static void RegisterHud(HealthBar[] healthBars)
		{
			if (_available && healthBars != null)
			{
				RegisterHealthBars(healthBars, _hudType);
			}
		}

		private static void RegisterPrefab(GameObject prefab, object type)
		{
			if (Object.op_Implicit((Object)(object)prefab))
			{
				RegisterHealthBars(prefab.GetComponentsInChildren<HealthBar>(true), type);
			}
		}

		private static void RegisterHealthBars(HealthBar[] healthBars, object type)
		{
			foreach (HealthBar val in healthBars)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Component val2 = ((Component)val).GetComponent(_providerType);
					if (!Object.op_Implicit((Object)(object)val2))
					{
						val2 = ((Component)val).gameObject.AddComponent(_providerType);
					}
					_typeField.SetValue(val2, type);
				}
			}
		}
	}
	internal static class CompatibilityConfig
	{
		internal static ZioConfigEntry<bool> AddKeyItemButton { get; private set; }

		internal static ZioConfigEntry<float> KeyItemButtonScale { get; private set; }

		internal static ZioConfigEntry<float> KeyItemButtonSpacing { get; private set; }

		internal static ZioConfigEntry<Color> KeyItemButtonAccent { get; private set; }

		internal static ZioConfigEntry<bool> OverrideNewTierColors { get; private set; }

		internal static ZioConfigEntry<Color> HexItemColor { get; private set; }

		internal static ZioConfigEntry<Color> HallowedItemColor { get; private set; }

		internal static void Initialize()
		{
			//IL_0086: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			AddKeyItemButton = ConfigHelper.Bind<bool>("Hallowed Concepts Compatibility", "Show Key Item Button", true, "Adds the current game's key-item/spell slot to the left of RiskUI's primary skill.", (Action<ZioConfigEntry<bool>>)null, (object)null);
			KeyItemButtonScale = ConfigHelper.Bind<float>("Hallowed Concepts Compatibility", "Key Item Button Scale", 1f, "Scale of the injected key-item button.", (Action<ZioConfigEntry<float>>)null, (object)2f);
			KeyItemButtonSpacing = ConfigHelper.Bind<float>("Hallowed Concepts Compatibility", "Key Item Button Spacing", 8f, "Gap between the injected key-item/spell slot and the primary skill.", (Action<ZioConfigEntry<float>>)null, (object)64f);
			KeyItemButtonAccent = ConfigHelper.Bind<Color>("Hallowed Concepts Compatibility", "Key Item Button Accent", Color32.op_Implicit(new Color32((byte)240, (byte)91, (byte)91, byte.MaxValue)), "RiskUI-style accent used for the new key-item button frame and cooldown text.", (Action<ZioConfigEntry<Color>>)null, (object)null);
			OverrideNewTierColors = ConfigHelper.Bind<bool>("Hallowed Concepts Compatibility", "Override New Item Tier Colors", false, "Overrides the game's Hex and Hallowed item colors in RiskUI. Disabled uses the official tier colors.", (Action<ZioConfigEntry<bool>>)null, (object)null);
			HexItemColor = ConfigHelper.Bind<Color>("Hallowed Concepts Compatibility", "Hex Item Color", Color32.op_Implicit(new Color32((byte)190, (byte)72, (byte)222, byte.MaxValue)), "Optional RiskUI glow and tooltip color for Hex items.", (Action<ZioConfigEntry<Color>>)null, (object)null);
			HallowedItemColor = ConfigHelper.Bind<Color>("Hallowed Concepts Compatibility", "Hallowed Item Color", Color32.op_Implicit(new Color32((byte)238, (byte)205, (byte)106, byte.MaxValue)), "Optional RiskUI glow and tooltip color for Hallowed items (internally called Page items).", (Action<ZioConfigEntry<Color>>)null, (object)null);
		}
	}
	internal static class HealthBarCompatibility
	{
		private enum StyleField
		{
			TrailingUnder,
			InstantHealth,
			TrailingOver,
			Shield,
			Curse,
			Barrier,
			Hull,
			Flash,
			Cull,
			LowHealthOver,
			LowHealthUnder,
			Magnetic,
			Osp,
			EchoDamage,
			LunarRuin,
			RepairingDrone,
			CollectiveElite,
			AcolyteSacrifice,
			DisabledHeal,
			RegainableHealth
		}

		private sealed class StyleFieldDefinition
		{
			internal readonly StyleField Field;

			internal readonly string Key;

			internal readonly string Description;

			internal readonly bool SupportsRainbow;

			internal StyleFieldDefinition(StyleField field, string key, string description, bool supportsRainbow = true)
			{
				Field = field;
				Key = key;
				Description = description;
				SupportsRainbow = supportsRainbow;
			}
		}

		private sealed class StyleBinding
		{
			internal HealthBarStyle Style;

			internal StyleField Field;

			internal ZioConfigEntry<Color> Entry;

			internal bool SupportsRainbow;

			internal bool IsRainbow;

			internal void OnSettingChanged(ZioConfigEntryBase _, object __, bool ___)
			{
				ApplyConfiguredColor(this);
			}
		}

		private static readonly StyleFieldDefinition[] StyleFields = new StyleFieldDefinition[20]
		{
			new StyleFieldDefinition(StyleField.TrailingUnder, "Trailing Under", "The delayed portion left behind when health is lost."),
			new StyleFieldDefinition(StyleField.InstantHealth, "Instant Health", "The immediate healing portion of the health bar."),
			new StyleFieldDefinition(StyleField.TrailingOver, "Trailing Over", "The main health-bar color."),
			new StyleFieldDefinition(StyleField.Shield, "Shield", "Shield health."),
			new StyleFieldDefinition(StyleField.Curse, "Curse", "Maximum-health reduction such as Shaped Glass."),
			new StyleFieldDefinition(StyleField.Barrier, "Barrier", "Temporary barrier health."),
			new StyleFieldDefinition(StyleField.Hull, "Hull", "Mechanical hull health."),
			new StyleFieldDefinition(StyleField.Flash, "Flash", "Feedback overlay used by specialized health bars."),
			new StyleFieldDefinition(StyleField.Cull, "Cull", "Frozen and execute threshold display."),
			new StyleFieldDefinition(StyleField.LowHealthOver, "Low Health Over", "Low-health overlay used by effects such as Delicate Watch."),
			new StyleFieldDefinition(StyleField.LowHealthUnder, "Low Health Under", "Low-health underlay."),
			new StyleFieldDefinition(StyleField.Magnetic, "Magnetic", "DLC3 magnetic-charge overlay.", supportsRainbow: false),
			new StyleFieldDefinition(StyleField.Osp, "OSP", "Remaining one-shot-protection threshold."),
			new StyleFieldDefinition(StyleField.EchoDamage, "Echo Damage", "Delayed echo-damage health."),
			new StyleFieldDefinition(StyleField.LunarRuin, "Lunar Ruin", "Lunar ruin health."),
			new StyleFieldDefinition(StyleField.RepairingDrone, "Repairing Drone", "Drone repair health."),
			new StyleFieldDefinition(StyleField.CollectiveElite, "Collective Elite", "Reserved Alloyed Collective elite overlay.", supportsRainbow: false),
			new StyleFieldDefinition(StyleField.AcolyteSacrifice, "Acolyte Sacrifice", "Full-bar overlay while a target is marked for Acolyte sacrifice.", supportsRainbow: false),
			new StyleFieldDefinition(StyleField.DisabledHeal, "Disabled Healing", "Health that cannot currently be healed."),
			new StyleFieldDefinition(StyleField.RegainableHealth, "Regainable Health", "Health that can be regained by the current game mechanics.")
		};

		private static readonly List<StyleBinding> Bindings = new List<StyleBinding>();

		private static readonly List<StyleBinding> RainbowBindings = new List<StyleBinding>();

		private static readonly HashSet<HealthBarStyle> RegisteredStyles = new HashSet<HealthBarStyle>();

		private static HealthBarStyle _fallbackStyle;

		private static bool _rainbowUpdateSubscribed;

		internal static void Initialize(HealthBarStyle fallbackStyle)
		{
			Shutdown();
			_fallbackStyle = fallbackStyle;
		}

		internal static void RegisterTargets(IReadOnlyList<HealthBarTargetDefinition> targets)
		{
			foreach (HealthBarTargetDefinition target in targets)
			{
				RegisterTarget(target);
			}
		}

		internal static void Shutdown()
		{
			SetRainbowUpdateSubscription(subscribe: false);
			foreach (StyleBinding binding in Bindings)
			{
				if (binding.Entry != null)
				{
					((ZioConfigEntryBase)binding.Entry).SettingChanged -= binding.OnSettingChanged;
				}
			}
			Bindings.Clear();
			RainbowBindings.Clear();
			RegisteredStyles.Clear();
			_fallbackStyle = null;
		}

		internal static void RegisterStyle(HealthBarStyle style, string category)
		{
			RegisterTarget(new HealthBarTargetDefinition
			{
				Category = category,
				Style = style
			});
		}

		internal static void EnsureCurrentFields(HealthBarStyle style)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0096: 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_00c0: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)style) && Object.op_Implicit((Object)(object)_fallbackStyle) && !((Object)(object)style == (Object)(object)_fallbackStyle))
			{
				CopyIfUninitialized(ref style.hullBarStyle, _fallbackStyle.hullBarStyle);
				CopyIfUninitialized(ref style.flashBarStyle, _fallbackStyle.flashBarStyle);
				CopyIfUninitialized(ref style.cullBarStyle, _fallbackStyle.cullBarStyle);
				CopyIfUninitialized(ref style.lowHealthOverStyle, _fallbackStyle.lowHealthOverStyle);
				CopyIfUninitialized(ref style.lowHealthUnderStyle, _fallbackStyle.lowHealthUnderStyle);
				CopyIfUninitialized(ref style.magneticStyle, _fallbackStyle.magneticStyle);
				CopyIfUninitialized(ref style.ospStyle, _fallbackStyle.ospStyle);
				CopyIfUninitialized(ref style.echoDamageStyle, _fallbackStyle.echoDamageStyle);
				CopyIfUninitialized(ref style.lunarRuinStyle, _fallbackStyle.lunarRuinStyle);
				CopyIfUninitialized(ref style.repairingDroneStyle, _fallbackStyle.repairingDroneStyle);
				CopyIfUninitialized(ref style.collectiveEliteStyle, _fallbackStyle.collectiveEliteStyle);
				CopyIfUninitialized(ref style.acolyteSacrificeStyle, _fallbackStyle.acolyteSacrificeStyle);
				CopyIfUninitialized(ref style.disabledHealStyle, _fallbackStyle.disabledHealStyle);
				CopyIfUninitialized(ref style.regainableHealthStyle, _fallbackStyle.regainableHealthStyle);
			}
		}

		private static void RegisterTarget(HealthBarTargetDefinition target)
		{
			HealthBarStyle val = target.Style;
			if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)target.HealthBar))
			{
				val = (target.Style = target.HealthBar.style);
			}
			if (!Object.op_Implicit((Object)(object)val) || !RegisteredStyles.Add(val))
			{
				return;
			}
			EnsureCurrentFields(val);
			if (!string.IsNullOrEmpty(target.IndividualKey))
			{
				BindStyleField(val, target.Category, target.IndividualKey, target.IndividualDescription ?? "RiskUI health-bar accent color.", StyleField.TrailingOver);
				return;
			}
			StyleFieldDefinition[] styleFields = StyleFields;
			foreach (StyleFieldDefinition styleFieldDefinition in styleFields)
			{
				BindStyleField(val, target.Category, styleFieldDefinition.Key, styleFieldDefinition.Description, styleFieldDefinition.Field, styleFieldDefinition.SupportsRainbow);
			}
		}

		private static void BindStyleField(HealthBarStyle style, string category, string key, string description, StyleField field, bool supportsRainbow = true)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			ZioConfigEntry<Color> val = ConfigHelper.Bind<Color>(category, key, GetBarStyle(style, field).baseColor, description, (Action<ZioConfigEntry<Color>>)null, (object)null);
			StyleBinding styleBinding = new StyleBinding
			{
				Style = style,
				Field = field,
				Entry = val,
				SupportsRainbow = supportsRainbow
			};
			Bindings.Add(styleBinding);
			((ZioConfigEntryBase)val).SettingChanged += styleBinding.OnSettingChanged;
			ApplyConfiguredColor(styleBinding);
		}

		private static void ApplyConfiguredColor(StyleBinding binding)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0032: 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_0073: 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)
			if (!Object.op_Implicit((Object)(object)binding.Style) || binding.Entry == null)
			{
				SetRainbow(binding, enabled: false);
				return;
			}
			Color value = binding.Entry.Value;
			bool flag = binding.SupportsRainbow && value == Color.clear && GetBarStyle(binding.Style, binding.Field).enabled;
			SetRainbow(binding, flag);
			GetBarStyle(binding.Style, binding.Field).baseColor = (flag ? GetRainbowColor() : value);
		}

		private static void SetRainbow(StyleBinding binding, bool enabled)
		{
			if (binding.IsRainbow != enabled)
			{
				binding.IsRainbow = enabled;
				if (enabled)
				{
					RainbowBindings.Add(binding);
				}
				else
				{
					RainbowBindings.Remove(binding);
				}
				SetRainbowUpdateSubscription(RainbowBindings.Count > 0);
			}
		}

		private static void SetRainbowUpdateSubscription(bool subscribe)
		{
			if (_rainbowUpdateSubscribed != subscribe)
			{
				_rainbowUpdateSubscribed = subscribe;
				if (subscribe)
				{
					RoR2Application.onUpdate += UpdateRainbowStyles;
				}
				else
				{
					RoR2Application.onUpdate -= UpdateRainbowStyles;
				}
			}
		}

		private static void UpdateRainbowStyles()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Color rainbowColor = GetRainbowColor();
			for (int num = RainbowBindings.Count - 1; num >= 0; num--)
			{
				StyleBinding styleBinding = RainbowBindings[num];
				if (!Object.op_Implicit((Object)(object)styleBinding.Style))
				{
					RainbowBindings.RemoveAt(num);
					styleBinding.IsRainbow = false;
				}
				else
				{
					GetBarStyle(styleBinding.Style, styleBinding.Field).baseColor = rainbowColor;
				}
			}
			if (RainbowBindings.Count == 0)
			{
				SetRainbowUpdateSubscription(subscribe: false);
			}
		}

		private static Color GetRainbowColor()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return Color.HSVToRGB(Mathf.Sin(Time.time) * 0.5f + 0.5f, 1f, 1f);
		}

		private static void CopyIfUninitialized(ref BarStyle destination, BarStyle source)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			if (!destination.enabled && destination.baseColor == Color.clear && !Object.op_Implicit((Object)(object)destination.sprite) && destination.sizeDelta == 0f)
			{
				destination = source;
			}
		}

		private static ref BarStyle GetBarStyle(HealthBarStyle style, StyleField field)
		{
			return field switch
			{
				StyleField.TrailingUnder => ref style.trailingUnderHealthBarStyle, 
				StyleField.InstantHealth => ref style.instantHealthBarStyle, 
				StyleField.TrailingOver => ref style.trailingOverHealthBarStyle, 
				StyleField.Shield => ref style.shieldBarStyle, 
				StyleField.Curse => ref style.curseBarStyle, 
				StyleField.Barrier => ref style.barrierBarStyle, 
				StyleField.Hull => ref style.hullBarStyle, 
				StyleField.Flash => ref style.flashBarStyle, 
				StyleField.Cull => ref style.cullBarStyle, 
				StyleField.LowHealthOver => ref style.lowHealthOverStyle, 
				StyleField.LowHealthUnder => ref style.lowHealthUnderStyle, 
				StyleField.Magnetic => ref style.magneticStyle, 
				StyleField.Osp => ref style.ospStyle, 
				StyleField.EchoDamage => ref style.echoDamageStyle, 
				StyleField.LunarRuin => ref style.lunarRuinStyle, 
				StyleField.RepairingDrone => ref style.repairingDroneStyle, 
				StyleField.CollectiveElite => ref style.collectiveEliteStyle, 
				StyleField.AcolyteSacrifice => ref style.acolyteSacrificeStyle, 
				StyleField.DisabledHeal => ref style.disabledHealStyle, 
				StyleField.RegainableHealth => ref style.regainableHealthStyle, 
				_ => throw new ArgumentOutOfRangeException("field", field, null), 
			};
		}
	}
	internal sealed class RiskUIFixHudMarker : MonoBehaviour
	{
	}
	internal sealed class RiskUIFixSpellSlotLayout : MonoBehaviour
	{
		internal RectTransform PrimaryRect;

		internal float Scale = 1f;

		internal float Spacing = 8f;

		private RectTransform _rect;

		private Vector2 _lastAnchorMin;

		private Vector2 _lastAnchorMax;

		private Vector2 _lastPivot;

		private Vector2 _lastSizeDelta;

		private Vector2 _lastPosition;

		private Vector3 _lastScale;

		private bool _hasLayout;

		private void Awake()
		{
			_rect = ((Component)this).GetComponent<RectTransform>();
		}

		private void LateUpdate()
		{
			//IL_0021: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00db: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_rect) && Object.op_Implicit((Object)(object)PrimaryRect))
			{
				Vector2 anchorMin = PrimaryRect.anchorMin;
				Vector2 anchorMax = PrimaryRect.anchorMax;
				Vector2 pivot = PrimaryRect.pivot;
				Vector2 sizeDelta = PrimaryRect.sizeDelta;
				Rect rect = PrimaryRect.rect;
				float num = Mathf.Abs(((Rect)(ref rect)).width);
				float num2 = Mathf.Abs(sizeDelta.x);
				if (num2 > num)
				{
					num = num2;
				}
				if (64f > num)
				{
					num = 64f;
				}
				Vector2 val = PrimaryRect.anchoredPosition - new Vector2(num * (1f + Scale) * 0.5f + Spacing, 0f);
				Vector3 val2 = ((Transform)PrimaryRect).localScale * Scale;
				if (!_hasLayout || !(_lastAnchorMin == anchorMin) || !(_lastAnchorMax == anchorMax) || !(_lastPivot == pivot) || !(_lastSizeDelta == sizeDelta) || !(_lastPosition == val) || !(_lastScale == val2))
				{
					_hasLayout = true;
					_lastAnchorMin = anchorMin;
					_lastAnchorMax = anchorMax;
					_lastPivot = pivot;
					_lastSizeDelta = sizeDelta;
					_lastPosition = val;
					_lastScale = val2;
					_rect.anchorMin = _lastAnchorMin;
					_rect.anchorMax = _lastAnchorMax;
					_rect.pivot = _lastPivot;
					_rect.sizeDelta = _lastSizeDelta;
					_rect.anchoredPosition = _lastPosition;
					((Transform)_rect).localRotation = Quaternion.identity;
					((Transform)_rect).localScale = _lastScale;
				}
			}
		}
	}
	internal static class HudCompatibility
	{
		private static readonly Assembly RiskUIAssembly = typeof(RiskUIPlugin).Assembly;

		private static readonly FieldInfo HealthBarStyleField = AccessTools.Field(typeof(HealthBar), "_style");

		private static readonly FieldInfo HealthBarAllyStyleField = AccessTools.Field(typeof(HealthBar), "_allyStyle");

		private static readonly Dictionary<string, HealthBarStyle> SharedReplacementStyles = new Dictionary<string, HealthBarStyle>(StringComparer.Ordinal);

		private static bool _loggedHealthBarFailure;

		private static bool _loggedObjectiveFailure;

		private static bool _loggedItemIconFallback;

		private static bool _loggedKeyItemFailure;

		internal static bool IsRiskUI(HUD hud)
		{
			if (!Object.op_Implicit((Object)(object)hud))
			{
				return false;
			}
			if (((Object)hud).name.IndexOf("RiskUI", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			MonoBehaviour[] componentsInChildren = ((Component)hud).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && ((object)val).GetType().Assembly == RiskUIAssembly)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool IsPatchedRiskUI(HUD hud)
		{
			if (Object.op_Implicit((Object)(object)hud))
			{
				return Object.op_Implicit((Object)(object)((Component)hud).GetComponent<RiskUIFixHudMarker>());
			}
			return false;
		}

		internal static void Apply(HUD hud)
		{
			if (Object.op_Implicit((Object)(object)hud) && !Object.op_Implicit((Object)(object)((Component)hud).GetComponent<RiskUIFixHudMarker>()) && IsRiskUI(hud))
			{
				((Component)hud).gameObject.AddComponent<RiskUIFixHudMarker>();
				HealthBar[] componentsInChildren = ((Component)hud).GetComponentsInChildren<HealthBar>(true);
				RepairHealthBars(componentsInChildren, hud.healthBar, registerReplacementStyles: true);
				EnsureCompatibleObjectivePanel(hud);
				EnsureCompatibleEquipmentIcons(hud);
				EnsureCompatibleItemPrefab(hud);
				CollapseDisplayCompatibility.RegisterHud(componentsInChildren);
				if (CompatibilityConfig.AddKeyItemButton.Value && !Object.op_Implicit((Object)(object)hud.keyItemIcon))
				{
					InjectKeyItemButton(hud);
				}
			}
		}

		internal static void Shutdown()
		{
			foreach (HealthBarStyle value in SharedReplacementStyles.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			SharedReplacementStyles.Clear();
		}

		internal static void PrepareRiskUIHealthBars(IReadOnlyList<HealthBar> riskHealthBars)
		{
			GameObject val = RiskUIPlugin.CreateHud();
			HUD val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<HUD>() : null);
			RepairHealthBars(riskHealthBars, Object.op_Implicit((Object)(object)val2) ? val2.healthBar : null, registerReplacementStyles: false);
		}

		private static void RepairHealthBars(IReadOnlyList<HealthBar> riskHealthBars, HealthBar playerHealthBar, bool registerReplacementStyles)
		{
			HealthBar[] healthBars = VanillaHudProvider.HealthBars;
			if (HealthBarStyleField == null || HealthBarAllyStyleField == null || riskHealthBars == null || riskHealthBars.Count == 0 || healthBars == null || healthBars.Length == 0)
			{
				LogErrorOnce(ref _loggedHealthBarFailure, "Could not repair RiskUI's health bars because the current style fields or fallback components were unavailable.");
				return;
			}
			foreach (HealthBar riskHealthBar in riskHealthBars)
			{
				HealthBar val = FindMatchingHealthBar(healthBars, ((Object)riskHealthBar).name) ?? VanillaHudProvider.HealthBar ?? FindFirstHealthBar(healthBars);
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				bool flag = (Object)(object)riskHealthBar == (Object)(object)playerHealthBar;
				string text = (flag ? "Recoloring Player HealthBar" : ("Recoloring " + ((Object)riskHealthBar).name));
				HealthBarStyle val2 = GetStyle(HealthBarStyleField, riskHealthBar);
				if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.barPrefab))
				{
					HealthBarStyle source = GetStyle(HealthBarStyleField, val) ?? GetStyle(HealthBarStyleField, VanillaHudProvider.HealthBar);
					val2 = GetOrCreateHealthBarStyle(text + "/" + ((Object)riskHealthBar).name + "/Regular/" + ((Object)val).name, source, "RiskUIFix_" + ((Object)riskHealthBar).name + "_Style", flag, text, registerReplacementStyles);
					if (Object.op_Implicit((Object)(object)val2))
					{
						HealthBarStyleField.SetValue(riskHealthBar, val2);
					}
				}
				else
				{
					HealthBarCompatibility.EnsureCurrentFields(val2);
					NormalizeRiskUIHealthLayers(val2);
					if (flag && registerReplacementStyles)
					{
						HealthBarCompatibility.RegisterStyle(val2, text);
					}
				}
				HealthBarStyle style = GetStyle(HealthBarAllyStyleField, riskHealthBar);
				if (!Object.op_Implicit((Object)(object)style) || !Object.op_Implicit((Object)(object)style.barPrefab))
				{
					style = val2;
					if (Object.op_Implicit((Object)(object)style))
					{
						HealthBarAllyStyleField.SetValue(riskHealthBar, style);
					}
					continue;
				}
				HealthBarCompatibility.EnsureCurrentFields(style);
				NormalizeRiskUIHealthLayers(style);
				if (flag && registerReplacementStyles)
				{
					HealthBarCompatibility.RegisterStyle(style, text);
				}
			}
		}

		private static void EnsureCompatibleObjectivePanel(HUD hud)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			ObjectivePanelController componentInChildren = ((Component)hud).GetComponentInChildren<ObjectivePanelController>(true);
			ObjectivePanelController objectivePanel = VanillaHudProvider.ObjectivePanel;
			GameObject objectiveTrackerPrefab = VanillaHudProvider.ObjectiveTrackerPrefab;
			if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)objectiveTrackerPrefab))
			{
				LogErrorOnce(ref _loggedObjectiveFailure, "Could not repair RiskUI's objective panel because the current objective prefab was unavailable.");
				return;
			}
			componentInChildren.objectiveTrackerPrefab = objectiveTrackerPrefab;
			if (Object.op_Implicit((Object)(object)objectivePanel))
			{
				componentInChildren.checkboxActiveSprite = objectivePanel.checkboxActiveSprite;
				componentInChildren.checkboxSuccessSprite = objectivePanel.checkboxSuccessSprite;
				componentInChildren.checkboxFailSprite = objectivePanel.checkboxFailSprite;
			}
			if (!Object.op_Implicit((Object)(object)((Component)componentInChildren).transform.Find("Label")))
			{
				Transform val = (Object.op_Implicit((Object)(object)objectivePanel) ? ((Component)objectivePanel).transform.Find("Label") : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)componentInChildren).transform, false);
					((Object)obj).name = "Label";
					obj.SetActive(false);
				}
				else
				{
					GameObject val2 = new GameObject("Label", new Type[2]
					{
						typeof(RectTransform),
						typeof(TextMeshProUGUI)
					});
					val2.transform.SetParent(((Component)componentInChildren).transform, false);
					val2.SetActive(false);
				}
			}
		}

		private static void EnsureCompatibleItemPrefab(HUD hud)
		{
			ItemInventoryDisplay itemInventoryDisplay = hud.itemInventoryDisplay;
			if (!Object.op_Implicit((Object)(object)itemInventoryDisplay) || !Object.op_Implicit((Object)(object)itemInventoryDisplay.itemIconPrefab))
			{
				return;
			}
			ItemIcon component = itemInventoryDisplay.itemIconPrefab.GetComponent<ItemIcon>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.asyncRawImage) && Object.op_Implicit((Object)(object)component.spriteAsNumberManager) && Object.op_Implicit((Object)(object)component.durationImage) && Object.op_Implicit((Object)(object)component.disabledImage) && Object.op_Implicit((Object)(object)component.rentalImage))
			{
				return;
			}
			ItemIcon itemIcon = VanillaHudProvider.ItemIcon;
			if (!Object.op_Implicit((Object)(object)itemIcon))
			{
				LogErrorOnce(ref _loggedItemIconFallback, "RiskUI's item icon is outdated, but the current fallback icon was unavailable.");
				return;
			}
			itemInventoryDisplay.itemIconPrefab = ((Component)itemIcon).gameObject;
			if (!_loggedItemIconFallback)
			{
				_loggedItemIconFallback = true;
				RiskUIFixPlugin.Log.LogWarning((object)"RiskUI's serialized item icon lacks current fields; using the current item icon with RiskUI tier coloring.");
			}
		}

		private static void EnsureCompatibleEquipmentIcons(HUD hud)
		{
			if (hud.equipmentIcons != null)
			{
				EquipmentIcon[] equipmentIcons = hud.equipmentIcons;
				for (int i = 0; i < equipmentIcons.Length; i++)
				{
					EnsureCompatibleEquipmentIcon(equipmentIcons[i]);
				}
			}
		}

		private static void EnsureCompatibleEquipmentIcon(EquipmentIcon equipmentIcon)
		{
			if (Object.op_Implicit((Object)(object)equipmentIcon) && Object.op_Implicit((Object)(object)equipmentIcon.iconImage) && !Object.op_Implicit((Object)(object)equipmentIcon.asyncIconImage))
			{
				AsyncRawImage val = ((Component)equipmentIcon.iconImage).GetComponent<AsyncRawImage>();
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = ((Component)equipmentIcon.iconImage).gameObject.AddComponent<AsyncRawImage>();
				}
				((AsyncViewable<Texture, RawImage>)(object)val).renderer = equipmentIcon.iconImage;
				equipmentIcon.asyncIconImage = val;
			}
		}

		private static void InjectKeyItemButton(HUD hud)
		{
			HUD hud2 = VanillaHudProvider.Hud;
			if (!Object.op_Implicit((Object)(object)hud2) || !Object.op_Implicit((Object)(object)hud2.keyItemIcon))
			{
				LogErrorOnce(ref _loggedKeyItemFailure, "The current HUD did not provide a key-item button to inject.");
				return;
			}
			SkillIcon val = FindFirstComponent<SkillIcon>(hud.skillIcons);
			EquipmentIcon val2 = FindFirstComponent<EquipmentIcon>(hud.equipmentIcons);
			Transform val3 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).transform.parent : (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).transform.parent : (Object.op_Implicit((Object)(object)hud.mainContainer) ? hud.mainContainer.transform : ((Component)hud).transform)));
			GameObject val4 = Object.Instantiate<GameObject>(((Component)hud2.keyItemIcon).gameObject, val3, false);
			((Object)val4).name = "RiskUIFix_KeyItemButton";
			KeyItemIcon component = val4.GetComponent<KeyItemIcon>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				Object.Destroy((Object)(object)val4);
				LogErrorOnce(ref _loggedKeyItemFailure, "The cloned key-item button had no KeyItemIcon component.");
				return;
			}
			hud.keyItemIcon = component;
			PositionKeyItemButton(val4, val);
			RemoveKeyBindingDecoration(component);
			ApplyRiskUIStyle(component, (Component)(Object.op_Implicit((Object)(object)val) ? ((object)val) : ((object)val2)));
		}

		private static void PositionKeyItemButton(GameObject cloneObject, SkillIcon primaryIcon)
		{
			//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_0054: 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)
			RectTransform component = cloneObject.GetComponent<RectTransform>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			float num = Mathf.Clamp(CompatibilityConfig.KeyItemButtonScale.Value, 0.1f, 2f);
			if (!Object.op_Implicit((Object)(object)primaryIcon))
			{
				((Transform)component).localScale = Vector3.one * num;
				return;
			}
			RectTransform component2 = ((Component)primaryIcon).GetComponent<RectTransform>();
			if (!Object.op_Implicit((Object)(object)component2))
			{
				((Transform)component).localScale = Vector3.one * num;
				return;
			}
			float spacing = Mathf.Max(0f, CompatibilityConfig.KeyItemButtonSpacing.Value);
			LayoutElement val = cloneObject.GetComponent<LayoutElement>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = cloneObject.AddComponent<LayoutElement>();
			}
			val.ignoreLayout = true;
			RiskUIFixSpellSlotLayout riskUIFixSpellSlotLayout = cloneObject.AddComponent<RiskUIFixSpellSlotLayout>();
			riskUIFixSpellSlotLayout.PrimaryRect = component2;
			riskUIFixSpellSlotLayout.Scale = num;
			riskUIFixSpellSlotLayout.Spacing = spacing;
			cloneObject.transform.SetAsLastSibling();
		}

		private static void RemoveKeyBindingDecoration(KeyItemIcon keyItemIcon)
		{
			GameObject gameObject = ((Component)keyItemIcon).gameObject;
			InputBindingDisplayController[] componentsInChildren = gameObject.GetComponentsInChildren<InputBindingDisplayController>(true);
			foreach (InputBindingDisplayController obj in componentsInChildren)
			{
				TMP_Text component = ((Component)obj).GetComponent<TMP_Text>();
				((Behaviour)obj).enabled = false;
				if (Object.op_Implicit((Object)(object)component))
				{
					component.text = string.Empty;
					((Component)component).gameObject.SetActive(false);
				}
				Transform parent = ((Component)obj).transform.parent;
				if (Object.op_Implicit((Object)(object)parent) && (Object)(object)parent != (Object)(object)gameObject.transform && (!Object.op_Implicit((Object)(object)keyItemIcon.displayRoot) || (Object)(object)parent != (Object)(object)keyItemIcon.displayRoot.transform))
				{
					((Component)parent).gameObject.SetActive(false);
				}
			}
			if (Object.op_Implicit((Object)(object)keyItemIcon.flashPanelObject))
			{
				keyItemIcon.flashPanelObject.SetActive(false);
				keyItemIcon.flashPanelObject = null;
			}
			if (Object.op_Implicit((Object)(object)keyItemIcon.flashReminderPanelObject))
			{
				keyItemIcon.flashReminderPanelObject.SetActive(false);
				keyItemIcon.flashReminderPanelObject = null;
			}
		}

		private static void ApplyRiskUIStyle(KeyItemIcon keyItemIcon, Component referenceIcon)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			Color value = CompatibilityConfig.KeyItemButtonAccent.Value;
			Image[] componentsInChildren = ((Component)keyItemIcon).GetComponentsInChildren<Image>(true);
			foreach (Image val in componentsInChildren)
			{
				string name = ((Object)val).name;
				if (name.IndexOf("back", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("border", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("frame", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("outline", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("flash", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					((Graphic)val).color = new Color(value.r, value.g, value.b, ((Graphic)val).color.a);
				}
			}
			if (Object.op_Implicit((Object)(object)keyItemIcon.cooldownText))
			{
				((Graphic)keyItemIcon.cooldownText).color = value;
				TMP_Text val2 = (Object.op_Implicit((Object)(object)referenceIcon) ? referenceIcon.GetComponentInChildren<TMP_Text>(true) : null);
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.font))
				{
					((TMP_Text)keyItemIcon.cooldownText).font = val2.font;
					((TMP_Text)keyItemIcon.cooldownText).fontSize = val2.fontSize;
				}
			}
		}

		private static HealthBarStyle GetStyle(FieldInfo field, HealthBar healthBar)
		{
			if (!(field != null) || !Object.op_Implicit((Object)(object)healthBar))
			{
				return null;
			}
			object? value = field.GetValue(healthBar);
			return (HealthBarStyle)((value is HealthBarStyle) ? value : null);
		}

		private static HealthBarStyle GetOrCreateHealthBarStyle(string key, HealthBarStyle source, string name, bool useRiskUIAccent, string configCategory, bool registerStyle)
		{
			if (SharedReplacementStyles.TryGetValue(key, out var value))
			{
				if (useRiskUIAccent && registerStyle)
				{
					HealthBarCompatibility.RegisterStyle(value, configCategory);
				}
				return value;
			}
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			HealthBarStyle val = Object.Instantiate<HealthBarStyle>(source);
			((Object)val).name = name;
			HealthBarCompatibility.EnsureCurrentFields(val);
			NormalizeRiskUIHealthLayers(val);
			if (useRiskUIAccent)
			{
				ApplyRiskUIDefaultAccent(val);
				if (registerStyle)
				{
					HealthBarCompatibility.RegisterStyle(val, configCategory);
				}
			}
			SharedReplacementStyles.Add(key, val);
			return val;
		}

		private static void NormalizeRiskUIHealthLayers(HealthBarStyle style)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			BarStyle trailingOverHealthBarStyle = style.trailingOverHealthBarStyle;
			CopyBarGeometry(ref style.trailingUnderHealthBarStyle, trailingOverHealthBarStyle);
			CopyBarGeometry(ref style.instantHealthBarStyle, trailingOverHealthBarStyle);
			CopyBarGeometry(ref style.shieldBarStyle, trailingOverHealthBarStyle);
			CopyBarGeometry(ref style.curseBarStyle, trailingOverHealthBarStyle);
			CopyBarGeometry(ref style.barrierBarStyle, trailingOverHealthBarStyle);
		}

		private static void CopyBarGeometry(ref BarStyle destination, BarStyle source)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			destination.sprite = source.sprite;
			destination.imageType = source.imageType;
			destination.sizeDelta = source.sizeDelta;
		}

		private static HealthBar FindMatchingHealthBar(HealthBar[] healthBars, string name)
		{
			foreach (HealthBar val in healthBars)
			{
				if (Object.op_Implicit((Object)(object)val) && string.Equals(((Object)val).name, name, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
			}
			return null;
		}

		private static HealthBar FindFirstHealthBar(HealthBar[] healthBars)
		{
			return FindFirstComponent<HealthBar>(healthBars);
		}

		private static T FindFirstComponent<T>(T[] components) where T : Object
		{
			if (components == null)
			{
				return default(T);
			}
			foreach (T val in components)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return default(T);
		}

		private static void LogErrorOnce(ref bool logged, string message)
		{
			if (!logged)
			{
				logged = true;
				RiskUIFixPlugin.Log.LogError((object)message);
			}
		}

		private static void ApplyRiskUIDefaultAccent(HealthBarStyle style)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001c: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			Color value = CompatibilityConfig.KeyItemButtonAccent.Value;
			SetBarColor(ref style.trailingUnderHealthBarStyle, Color.Lerp(value, Color.black, 0.35f));
			SetBarColor(ref style.instantHealthBarStyle, value);
			SetBarColor(ref style.trailingOverHealthBarStyle, value);
		}

		private static void SetBarColor(ref BarStyle barStyle, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			barStyle.baseColor = color;
		}
	}
	[HarmonyPatch]
	internal static class ItemIconCompatibilityPatches
	{
		private sealed class LegacyRemapperBinding
		{
			internal RedToColorRemapperIndividual Remapper;

			internal ZioConfigEntry<Color> Entry;

			internal bool Subscribed;

			internal bool IsRainbow;

			internal void OnSettingChanged(ZioConfigEntryBase _, object __, bool ___)
			{
				ApplyLegacyRemapper(this);
			}
		}

		private static readonly Dictionary<RedToColorRemapperIndividual, LegacyRemapperBinding> LegacyRemapperBindings = new Dictionary<RedToColorRemapperIndividual, LegacyRemapperBinding>();

		private static readonly List<LegacyRemapperBinding> RainbowRemapperBindings = new List<LegacyRemapperBinding>();

		private static bool _rainbowUpdateSubscribed;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(RedToColorRemapperIndividual), "Startup")]
		private static bool ReplaceLegacyRemapperStartup(RedToColorRemapperIndividual __instance)
		{
			GetOrCreateLegacyRemapperBinding(__instance, subscribe: false);
			((Behaviour)__instance).enabled = false;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(RedToColorRemapperIndividual), "Awake", new Type[] { })]
		private static bool ReplaceLegacyRemapperAwake(RedToColorRemapperIndividual __instance)
		{
			ApplyLegacyRemapper(GetOrCreateLegacyRemapperBinding(__instance, subscribe: true));
			((Behaviour)__instance).enabled = false;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(RedToColorRemapperIndividual), "OnEnable", new Type[] { })]
		private static bool ReplaceLegacyRemapperOnEnable(RedToColorRemapperIndividual __instance)
		{
			ApplyLegacyRemapper(GetOrCreateLegacyRemapperBinding(__instance, subscribe: true));
			((Behaviour)__instance).enabled = false;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(RedToColorRemapperIndividual), "OnDestroy", new Type[] { })]
		private static bool ReplaceLegacyRemapperOnDestroy(RedToColorRemapperIndividual __instance)
		{
			RemoveLegacyRemapperBinding(__instance);
			return false;
		}

		internal static void Shutdown()
		{
			SetRainbowUpdateSubscription(subscribe: false);
			foreach (LegacyRemapperBinding value in LegacyRemapperBindings.Values)
			{
				if (value.Subscribed && value.Entry != null)
				{
					((ZioConfigEntryBase)value.Entry).SettingChanged -= value.OnSettingChanged;
				}
			}
			LegacyRemapperBindings.Clear();
			RainbowRemapperBindings.Clear();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemIcon), "SetItemIndex", new Type[] { typeof(SetItemIndexArgs) })]
		private static void ApplyCurrentTierStyle(ItemIcon __instance, SetItemIndexArgs args)
		{
			//IL_0014: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			if (CompatibilityConfig.OverrideNewTierColors != null && CompatibilityConfig.OverrideNewTierColors.Value && TryGetOverrideColor(ItemCatalog.GetItemDef(args.newItemIndex), out var color) && HudCompatibility.IsPatchedRiskUI(((Component)__instance).GetComponentInParent<HUD>()))
			{
				ApplyColor(__instance.glowImage, __instance.tooltipProvider, color);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MaterialItemIcon), "SetItemIndex", new Type[]
		{
			typeof(ItemIndex),
			typeof(int)
		})]
		private static void ApplyCurrentTierStyleToMaterialIcon(MaterialItemIcon __instance, ItemIndex newItemIndex)
		{
			//IL_0000: 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_0019: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			ItemDef itemDef = ItemCatalog.GetItemDef(newItemIndex);
			if (!((Object)(object)itemDef == (Object)null))
			{
				if ((int)itemDef.tier == 13 && itemDef.DoesNotContainTag((ItemTag)9) && Object.op_Implicit((Object)(object)__instance.tooltipProvider))
				{
					__instance.tooltipProvider.bodyToken = Language.GetStringFormatted("HEXTIER_PICKUP_SUFFIX", new object[1] { Language.GetString(itemDef.pickupToken) });
				}
				if (CompatibilityConfig.OverrideNewTierColors != null && CompatibilityConfig.OverrideNewTierColors.Value && TryGetOverrideColor(itemDef, out var color))
				{
					ApplyColor(__instance.glowImage, __instance.tooltipProvider, color);
				}
			}
		}

		private static bool TryGetOverrideColor(ItemDef itemDef, out Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			color = Color.white;
			if ((Object)(object)itemDef == (Object)null)
			{
				return false;
			}
			if ((int)itemDef.tier == 13)
			{
				color = CompatibilityConfig.HexItemColor.Value;
				return true;
			}
			if ((int)itemDef.tier == 12)
			{
				color = CompatibilityConfig.HallowedItemColor.Value;
				return true;
			}
			return false;
		}

		private static void ApplyColor(RawImage glow, TooltipProvider tooltip, Color color)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_001c: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)glow))
			{
				((Graphic)glow).color = new Color(color.r, color.g, color.b, ((Graphic)glow).color.a);
			}
			if (Object.op_Implicit((Object)(object)tooltip))
			{
				tooltip.titleColor = color;
			}
		}

		private static LegacyRemapperBinding GetOrCreateLegacyRemapperBinding(RedToColorRemapperIndividual remapper, bool subscribe)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (!LegacyRemapperBindings.TryGetValue(remapper, out var value))
			{
				value = new LegacyRemapperBinding
				{
					Remapper = remapper,
					Entry = ConfigHelper.Bind<Color>("Recoloring", remapper.configKey, GetTargetColor(remapper.target), remapper.configDesc, (Action<ZioConfigEntry<Color>>)null, (object)null)
				};
				LegacyRemapperBindings.Add(remapper, value);
			}
			if (subscribe && !value.Subscribed && value.Entry != null)
			{
				((ZioConfigEntryBase)value.Entry).SettingChanged += value.OnSettingChanged;
				value.Subscribed = true;
			}
			return value;
		}

		private static void RemoveLegacyRemapperBinding(RedToColorRemapperIndividual remapper)
		{
			if (LegacyRemapperBindings.TryGetValue(remapper, out var value))
			{
				if (value.Subscribed && value.Entry != null)
				{
					((ZioConfigEntryBase)value.Entry).SettingChanged -= value.OnSettingChanged;
				}
				SetRainbow(value, enabled: false);
				LegacyRemapperBindings.Remove(remapper);
			}
		}

		private static void ApplyLegacyRemapper(LegacyRemapperBinding binding)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_002a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			if (binding.Entry == null || !Object.op_Implicit((Object)(object)binding.Remapper))
			{
				SetRainbow(binding, enabled: false);
				return;
			}
			Color value = binding.Entry.Value;
			bool flag = value == Color.clear;
			SetRainbow(binding, flag);
			SetTargetColor(binding.Remapper.target, flag ? GetRainbowColor() : value);
		}

		private static Color GetTargetColor(MonoBehaviour target)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = (TextMeshProUGUI)(object)((target is TextMeshProUGUI) ? target : null);
			if (val != null)
			{
				return ((Graphic)val).color;
			}
			Image val2 = (Image)(object)((target is Image) ? target : null);
			if (val2 != null)
			{
				return ((Graphic)val2).color;
			}
			HealthBar val3 = (HealthBar)(object)((target is HealthBar) ? target : null);
			if (val3 != null && Object.op_Implicit((Object)(object)val3.style))
			{
				return val3.style.trailingOverHealthBarStyle.baseColor;
			}
			return Color.black;
		}

		private static void SetTargetColor(MonoBehaviour target, Color color)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = (TextMeshProUGUI)(object)((target is TextMeshProUGUI) ? target : null);
			if (val != null)
			{
				((Graphic)val).color = color;
				return;
			}
			Image val2 = (Image)(object)((target is Image) ? target : null);
			if (val2 != null)
			{
				((Graphic)val2).color = color;
				return;
			}
			HealthBar val3 = (HealthBar)(object)((target is HealthBar) ? target : null);
			if (val3 != null && Object.op_Implicit((Object)(object)val3.style))
			{
				HealthBarStyle style = val3.style;
				BarStyle trailingOverHealthBarStyle = style.trailingOverHealthBarStyle;
				trailingOverHealthBarStyle.baseColor = color;
				style.trailingOverHealthBarStyle = trailingOverHealthBarStyle;
			}
		}

		private static void SetRainbow(LegacyRemapperBinding binding, bool enabled)
		{
			if (binding.IsRainbow != enabled)
			{
				binding.IsRainbow = enabled;
				if (enabled)
				{
					RainbowRemapperBindings.Add(binding);
				}
				else
				{
					RainbowRemapperBindings.Remove(binding);
				}
				SetRainbowUpdateSubscription(RainbowRemapperBindings.Count > 0);
			}
		}

		private static void SetRainbowUpdateSubscription(bool subscribe)
		{
			if (_rainbowUpdateSubscribed != subscribe)
			{
				_rainbowUpdateSubscribed = subscribe;
				if (subscribe)
				{
					RoR2Application.onUpdate += UpdateRainbowRemappers;
				}
				else
				{
					RoR2Application.onUpdate -= UpdateRainbowRemappers;
				}
			}
		}

		private static void UpdateRainbowRemappers()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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)
			Color rainbowColor = GetRainbowColor();
			for (int num = RainbowRemapperBindings.Count - 1; num >= 0; num--)
			{
				LegacyRemapperBinding legacyRemapperBinding = RainbowRemapperBindings[num];
				if (!Object.op_Implicit((Object)(object)legacyRemapperBinding.Remapper))
				{
					RainbowRemapperBindings.RemoveAt(num);
					legacyRemapperBinding.IsRainbow = false;
				}
				else
				{
					SetTargetColor(legacyRemapperBinding.Remapper.target, rainbowColor);
				}
			}
			if (RainbowRemapperBindings.Count == 0)
			{
				SetRainbowUpdateSubscription(subscribe: false);
			}
		}

		private static Color GetRainbowColor()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return Color.HSVToRGB(Mathf.Sin(Time.time) * 0.5f + 0.5f, 1f, 1f);
		}
	}
	[BepInPlugin("youss.riskuifix", "RiskUI Fix", "1.0.2")]
	[BepInDependency("bubbet.riskui", "1.5.2")]
	[BepInDependency("bubbet.zioconfigfile", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class RiskUIFixPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "youss.riskuifix";

		public const string PluginName = "RiskUI Fix";

		public const string PluginVersion = "1.0.2";

		private Harmony _harmony;

		private bool _gameLoaded;

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("youss.riskuifix");
			_harmony.PatchAll(typeof(ItemIconCompatibilityPatches));
			_harmony.PatchAll(typeof(RunInfoCompatibility));
			try
			{
				RiskUIPrefabSanitizer.Sanitize();
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to prepare RiskUI prefabs: {arg}");
			}
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnGameLoaded));
			CameraRigController.OnHUDUpdated = (Action)Delegate.Combine(CameraRigController.OnHUDUpdated, new Action(OnHudUpdated));
		}

		private void OnDestroy()
		{
			RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(OnGameLoaded));
			CameraRigController.OnHUDUpdated = (Action)Delegate.Remove(CameraRigController.OnHUDUpdated, new Action(OnHudUpdated));
			RunInfoCompatibility.Shutdown();
			ItemIconCompatibilityPatches.Shutdown();
			HealthBarCompatibility.Shutdown();
			HudCompatibility.Shutdown();
		}

		private void OnGameLoaded()
		{
			if (_gameLoaded)
			{
				return;
			}
			_gameLoaded = true;
			try
			{
				CompatibilityConfig.Initialize();
				VanillaHudProvider.Initialize();
				RunInfoCompatibility.Initialize(VanillaHudProvider.ScoreboardStripPrefab);
				HealthBarCompatibility.Initialize(Object.op_Implicit((Object)(object)VanillaHudProvider.HealthBar) ? VanillaHudProvider.HealthBar.style : null);
				HudCompatibility.PrepareRiskUIHealthBars(RiskUIPrefabSanitizer.RiskUIHealthBars);
				CollapseDisplayCompatibility.Initialize();
				HealthBarCompatibility.RegisterTargets(RiskUIPrefabSanitizer.HealthBarTargets);
				foreach (HUD readOnlyInstance in HUD.readOnlyInstanceList)
				{
					TryApplyHud(readOnlyInstance);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"RiskUI Fix 1.0.2 initialized.");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"RiskUI compatibility initialization failed: {arg}");
			}
		}

		private void OnHudUpdated()
		{
			if (!_gameLoaded)
			{
				return;
			}
			foreach (HUD readOnlyInstance in HUD.readOnlyInstanceList)
			{
				TryApplyHud(readOnlyInstance);
			}
		}

		private void TryApplyHud(HUD hud)
		{
			try
			{
				HudCompatibility.Apply(hud);
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to update a RiskUI HUD: {arg}");
			}
		}
	}
	internal sealed class HealthBarTargetDefinition
	{
		internal string Category;

		internal HealthBar HealthBar;

		internal HealthBarStyle Style;

		internal string IndividualKey;

		internal string IndividualDescription;
	}
	internal static class RiskUIPrefabSanitizer
	{
		private static readonly List<HealthBarTargetDefinition> Targets = new List<HealthBarTargetDefinition>();

		private static readonly List<HealthBar> PrefabHealthBars = new List<HealthBar>();

		private static bool _sanitized;

		internal static IReadOnlyList<HealthBarTargetDefinition> HealthBarTargets => Targets;

		internal static IReadOnlyList<HealthBar> RiskUIHealthBars => PrefabHealthBars;

		internal static void Sanitize()
		{
			if (_sanitized)
			{
				return;
			}
			_sanitized = true;
			Targets.Clear();
			PrefabHealthBars.Clear();
			GameObject[] obj = new GameObject[6]
			{
				RiskUIPlugin.CreateHud(),
				RiskUIPlugin.CreateClassicRunHud(),
				RiskUIPlugin.CreateSimulcrum(),
				RiskUIPlugin.CreateAllyCard(),
				RiskUIPlugin.BaseWaveUI,
				RiskUIPlugin.EnemyInfoPanel
			};
			HashSet<GameObject> hashSet = new HashSet<GameObject>();
			GameObject[] array = (GameObject[])(object)obj;
			foreach (GameObject val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && hashSet.Add(val))
				{
					SanitizePrefab(val);
				}
			}
		}

		private static void SanitizePrefab(GameObject prefab)
		{
			ArtifactDisplayPanelController[] componentsInChildren = prefab.GetComponentsInChildren<ArtifactDisplayPanelController>(true);
			foreach (ArtifactDisplayPanelController val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val.iconPrefab))
				{
					RawImage component = val.iconPrefab.GetComponent<RawImage>();
					if (Object.op_Implicit((Object)(object)component) && !Object.op_Implicit((Object)(object)((Component)component).GetComponent<AsyncRawImage>()))
					{
						AsyncRawImage obj = ((Component)component).gameObject.AddComponent<AsyncRawImage>();
						((AsyncViewable<Texture, RawImage>)(object)obj).renderer = component;
						((AsyncViewable<Texture, RawImage>)(object)obj).disableWhileLoading = true;
					}
				}
			}
			HealthBar[] componentsInChildren2 = prefab.GetComponentsInChildren<HealthBar>(true);
			foreach (HealthBar val2 in componentsInChildren2)
			{
				if (Object.op_Implicit((Object)(object)val2) && !PrefabHealthBars.Contains(val2))
				{
					PrefabHealthBars.Add(val2);
				}
			}
			HealthbarRecolor[] componentsInChildren3 = prefab.GetComponentsInChildren<HealthbarRecolor>(true);
			foreach (HealthbarRecolor val3 in componentsInChildren3)
			{
				if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.healthBar))
				{
					AddTarget(new HealthBarTargetDefinition
					{
						Category = "Recoloring " + val3.whichBar,
						HealthBar = val3.healthBar,
						Style = val3.healthBar.style
					});
				}
				Object.DestroyImmediate((Object)(object)val3, true);
			}
			RedToColorRemapperIndividual[] componentsInChildren4 = prefab.GetComponentsInChildren<RedToColorRemapperIndividual>(true);
			foreach (RedToColorRemapperIndividual val4 in componentsInChildren4)
			{
				HealthBar val5 = (HealthBar)(Object.op_Implicit((Object)(object)val4) ? /*isinst with value type is only supported in some contexts*/: null);
				if (Object.op_Implicit((Object)(object)val5))
				{
					AddTarget(new HealthBarTargetDefinition
					{
						Category = "Recoloring",
						HealthBar = val5,
						Style = val5.style,
						IndividualKey = val4.configKey,
						IndividualDescription = val4.configDesc
					});
					Object.DestroyImmediate((Object)(object)val4, true);
				}
			}
		}

		private static void AddTarget(HealthBarTargetDefinition target)
		{
			foreach (HealthBarTargetDefinition target2 in Targets)
			{
				if ((Object)(object)target2.HealthBar == (Object)(object)target.HealthBar && (Object)(object)target2.Style == (Object)(object)target.Style && string.Equals(target2.Category, target.Category, StringComparison.Ordinal) && string.Equals(target2.IndividualKey, target.IndividualKey, StringComparison.Ordinal))
				{
					return;
				}
			}
			Targets.Add(target);
		}
	}
	[HarmonyPatch]
	internal static class RunInfoCompatibility
	{
		private static GameObject _currentStripPrefab;

		private static bool _loggedReplacement;

		internal static void Initialize(GameObject currentScoreboardStripPrefab)
		{
			_currentStripPrefab = currentScoreboardStripPrefab;
			if (!Object.op_Implicit((Object)(object)_currentStripPrefab))
			{
				RiskUIFixPlugin.Log.LogWarning((object)"The current vanilla scoreboard strip was unavailable; legacy rows cannot be replaced.");
			}
		}

		internal static void Shutdown()
		{
			_currentStripPrefab = null;
			_loggedReplacement = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ScoreboardController), "Awake")]
		private static void ReplaceLegacyStripBeforeAllocator(ScoreboardController __instance)
		{
			if (Object.op_Implicit((Object)(object)_currentStripPrefab) && UsesLegacyStrip(__instance.stripPrefab))
			{
				__instance.stripPrefab = _currentStripPrefab;
				if (!_loggedReplacement)
				{
					_loggedReplacement = true;
					RiskUIFixPlugin.Log.LogDebug((object)"Replaced RiskUI's legacy scoreboard row before allocation.");
				}
			}
		}

		private static bool UsesLegacyStrip(GameObject stripPrefab)
		{
			if (!Object.op_Implicit((Object)(object)stripPrefab))
			{
				return false;
			}
			ScoreboardStrip component = stripPrefab.GetComponent<ScoreboardStrip>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)component.keyItemIcon) || !Object.op_Implicit((Object)(object)component.itemInventoryDisplay) || !Object.op_Implicit((Object)(object)component.itemInventoryDisplay.itemIconPrefab))
			{
				return true;
			}
			ItemIcon component2 = component.itemInventoryDisplay.itemIconPrefab.GetComponent<ItemIcon>();
			if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component2.asyncRawImage) && Object.op_Implicit((Object)(object)component2.spriteAsNumberManager) && Object.op_Implicit((Object)(object)component2.durationImage) && Object.op_Implicit((Object)(object)component2.disabledImage))
			{
				return !Object.op_Implicit((Object)(object)component2.rentalImage);
			}
			return true;
		}
	}
	internal static class VanillaHudProvider
	{
		private const string CurrentItemIconAddress = "RoR2/Base/UI/ItemIcon.prefab";

		private const string CurrentScoreboardStripLegacyPath = "Prefabs/UI/ScoreboardStrip";

		private static bool _initialized;

		internal static HUD Hud { get; private set; }

		internal static ItemIcon ItemIcon { get; private set; }

		internal static HealthBar HealthBar { get; private set; }

		internal static HealthBar[] HealthBars { get; private set; }

		internal static ObjectivePanelController ObjectivePanel { get; private set; }

		internal static GameObject ObjectiveTrackerPrefab { get; private set; }

		internal static GameObject ScoreboardStripPrefab { get; private set; }

		internal static void Initialize()
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				_initialized = true;
				GameObject val = LegacyResourcesAPI.Load<GameObject>("Prefabs/HUDSimple");
				Hud = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<HUD>() : null);
				if (Object.op_Implicit((Object)(object)Hud))
				{
					HealthBar = (Object.op_Implicit((Object)(object)Hud.healthBar) ? Hud.healthBar : ((Component)Hud).GetComponentInChildren<HealthBar>(true));
					HealthBars = ((Component)Hud).GetComponentsInChildren<HealthBar>(true);
					ObjectivePanel = ((Component)Hud).GetComponentInChildren<ObjectivePanelController>(true);
				}
				ObjectiveTrackerPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/ClassicRun/ObjectiveStrip.prefab").WaitForCompletion();
				GameObject val2 = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/UI/ItemIcon.prefab").WaitForCompletion();
				ItemIcon = (Object.op_Implicit((Object)(object)val2) ? val2.GetComponent<ItemIcon>() : null);
				ScoreboardStripPrefab = LegacyResourcesAPI.Load<GameObject>("Prefabs/UI/ScoreboardStrip");
				if (!Object.op_Implicit((Object)(object)Hud))
				{
					RiskUIFixPlugin.Log.LogError((object)"Could not load the current vanilla HUD prefab.");
				}
				if (!Object.op_Implicit((Object)(object)ObjectiveTrackerPrefab))
				{
					RiskUIFixPlugin.Log.LogError((object)"Could not load the current objective-row prefab.");
				}
				if (!Object.op_Implicit((Object)(object)ItemIcon))
				{
					RiskUIFixPlugin.Log.LogError((object)"Could not load the current item-icon prefab.");
				}
				if (!Object.op_Implicit((Object)(object)ScoreboardStripPrefab))
				{
					RiskUIFixPlugin.Log.LogError((object)"Could not load the current vanilla scoreboard strip prefab.");
				}
			}
		}
	}
}