Decompiled source of LiveExperienceTracker v1.0.2

LiveExperienceTracker.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.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 LiveExperienceTracker
{
	[BepInPlugin("dsoltyka.LiveExperienceTracker", "LiveExperienceTracker", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "dsoltyka.LiveExperienceTracker";

		private Harmony _harmony;

		internal static ManualLogSource Log { get; private set; }

		internal static Settings Settings { get; private set; }

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Settings = new Settings(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("dsoltyka.LiveExperienceTracker");
			_harmony.PatchAll(typeof(SkillGainPatches));
			((Component)this).gameObject.AddComponent<TrackerHud>();
			Log.LogInfo((object)"LiveExperienceTracker 1.0.2 loaded");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal sealed class Settings
	{
		public ConfigEntry<float> DisplaySeconds { get; }

		public ConfigEntry<float> FadeSeconds { get; }

		public ConfigEntry<int> DecimalPlaces { get; }

		public ConfigEntry<int> FontSize { get; }

		public ConfigEntry<float> BarWidth { get; }

		public ConfigEntry<float> BarHeight { get; }

		public ConfigEntry<float> ElementSpacing { get; }

		public ConfigEntry<float> RowSpacing { get; }

		public ConfigEntry<float> OffsetX { get; }

		public ConfigEntry<float> OffsetY { get; }

		public ConfigEntry<Color> SkillNameColor { get; }

		public ConfigEntry<Color> ValueColor { get; }

		public ConfigEntry<Color> GainColor { get; }

		public ConfigEntry<Color> BarFillColor { get; }

		public ConfigEntry<Color> BarBackgroundColor { get; }

		public event Action Changed;

		public Settings(ConfigFile config)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			DisplaySeconds = config.Bind<float>("1 - General", "DisplaySeconds", 5f, new ConfigDescription("How long a skill row stays visible after its last XP gain, in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 60f), Array.Empty<object>()));
			FadeSeconds = config.Bind<float>("1 - General", "FadeSeconds", 0.5f, new ConfigDescription("How long a row spends fading out at the end of its display time. 0 disables the fade.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			DecimalPlaces = config.Bind<int>("1 - General", "DecimalPlaces", 2, new ConfigDescription("Decimal places used for XP numbers.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 4), Array.Empty<object>()));
			FontSize = config.Bind<int>("2 - Layout", "FontSize", 16, new ConfigDescription("Font size of the row text.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 40), Array.Empty<object>()));
			BarWidth = config.Bind<float>("2 - Layout", "BarWidth", 120f, new ConfigDescription("Width of the progress bar in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(20f, 600f), Array.Empty<object>()));
			BarHeight = config.Bind<float>("2 - Layout", "BarHeight", 10f, new ConfigDescription("Height of the progress bar in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 40f), Array.Empty<object>()));
			ElementSpacing = config.Bind<float>("2 - Layout", "ElementSpacing", 6f, new ConfigDescription("Horizontal gap between the name, bar and numbers.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
			RowSpacing = config.Bind<float>("2 - Layout", "RowSpacing", 2f, new ConfigDescription("Vertical gap between skill rows.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
			OffsetX = config.Bind<float>("2 - Layout", "OffsetX", 0f, "Horizontal offset from the left edge of the health panel, in pixels. Positive moves right.");
			OffsetY = config.Bind<float>("2 - Layout", "OffsetY", 4f, "Vertical gap above the health panel, in pixels. Positive moves up.");
			SkillNameColor = config.Bind<Color>("3 - Colors", "SkillName", new Color(1f, 0.85f, 0.2f), "Color of the skill name.");
			ValueColor = config.Bind<Color>("3 - Colors", "Values", Color.white, "Color of the (current / needed) XP text.");
			GainColor = config.Bind<Color>("3 - Colors", "Gain", new Color(0.4f, 1f, 0.4f), "Color of the +XP text.");
			BarFillColor = config.Bind<Color>("3 - Colors", "BarFill", new Color(1f, 0.75f, 0.15f), "Fill color of the progress bar.");
			BarBackgroundColor = config.Bind<Color>("3 - Colors", "BarBackground", new Color(0f, 0f, 0f, 0.6f), "Background color of the progress bar.");
			config.SettingChanged += delegate
			{
				this.Changed?.Invoke();
			};
		}
	}
	internal readonly struct SkillGain
	{
		public readonly SkillType Type;

		public readonly string Name;

		public readonly float Level;

		public readonly float Accumulator;

		public readonly float Required;

		public readonly float Gained;

		public readonly bool LeveledUp;

		public SkillGain(SkillType type, string name, float level, float accumulator, float required, float gained, bool leveledUp)
		{
			//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)
			Type = type;
			Name = name;
			Level = level;
			Accumulator = accumulator;
			Required = required;
			Gained = gained;
			LeveledUp = leveledUp;
		}
	}
	[HarmonyPatch]
	internal static class SkillGainPatches
	{
		private static readonly FieldRef<Skills, Player> PlayerRef = AccessTools.FieldRefAccess<Skills, Player>("m_player");

		private static readonly Func<Skill, float> NextLevelRequirement = CreateNextLevelRequirement();

		private static Skills s_raising;

		public static event Action<SkillGain> SkillGained;

		[HarmonyPatch(typeof(Skills), "RaiseSkill")]
		[HarmonyPrefix]
		private static void RaiseSkill_Prefix(Skills __instance)
		{
			s_raising = __instance;
		}

		[HarmonyPatch(typeof(Skills), "RaiseSkill")]
		[HarmonyFinalizer]
		private static void RaiseSkill_Finalizer()
		{
			s_raising = null;
		}

		[HarmonyPatch(typeof(Skill), "Raise")]
		[HarmonyPrefix]
		private static void Raise_Prefix(Skill __instance, out float __state)
		{
			__state = __instance.m_level;
		}

		[HarmonyPatch(typeof(Skill), "Raise")]
		[HarmonyPostfix]
		private static void Raise_Postfix(Skill __instance, float factor, bool __result, float __state)
		{
			//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_0072: 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)s_raising == (Object)null || __instance.m_info == null || __state >= 100f)
			{
				return;
			}
			Player val = PlayerRef.Invoke(s_raising);
			if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			float num = __instance.m_info.m_increseStep * factor * Game.m_skillGainRate;
			if (num <= 0f)
			{
				return;
			}
			SkillType skill = __instance.m_info.m_skill;
			SkillGain obj = new SkillGain(skill, ResolveName(skill), __instance.m_level, __instance.m_accumulator, NextLevelRequirement(__instance), num, __result);
			try
			{
				SkillGainPatches.SkillGained?.Invoke(obj);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"SkillGained handler threw: {arg}");
			}
		}

		private unsafe static string ResolveName(SkillType type)
		{
			string text = ((object)(*(SkillType*)(&type))/*cast due to .constrained prefix*/).ToString();
			Localization instance = Localization.instance;
			if (instance == null)
			{
				return text;
			}
			string text2 = instance.Localize("$skill_" + text.ToLowerInvariant());
			if (!string.IsNullOrEmpty(text2) && !text2.StartsWith("["))
			{
				return text2;
			}
			return text;
		}

		private static Func<Skill, float> CreateNextLevelRequirement()
		{
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(Skill), "GetNextLevelRequirement", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					return AccessTools.MethodDelegate<Func<Skill, float>>(methodInfo, (object)null, true);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Falling back to built-in level requirement formula: " + ex.Message));
				}
			}
			return (Skill skill) => Mathf.Pow(Mathf.Floor(skill.m_level + 1f), 1.5f) * 0.5f + 0.5f;
		}
	}
	internal sealed class SkillRow
	{
		private readonly CanvasGroup _group;

		private readonly TextMeshProUGUI _name;

		private readonly TextMeshProUGUI _value;

		private readonly TextMeshProUGUI _gain;

		private readonly RectTransform _fill;

		private float _expiresAt;

		public string SortKey { get; private set; }

		public RectTransform Rect { get; }

		private SkillRow(RectTransform rect, CanvasGroup group, TextMeshProUGUI name, TextMeshProUGUI value, TextMeshProUGUI gain, RectTransform fill)
		{
			Rect = rect;
			_group = group;
			_name = name;
			_value = value;
			_gain = gain;
			_fill = fill;
		}

		public static SkillRow Create(Transform parent, TMP_FontAsset font, Material fontMaterial, Settings s)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			GameObject val = new GameObject("SkillRow", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasGroup),
				typeof(HorizontalLayoutGroup)
			});
			val.transform.SetParent(parent, false);
			HorizontalLayoutGroup component = val.GetComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component).spacing = s.ElementSpacing.Value;
			((LayoutGroup)component).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			TextMeshProUGUI name = CreateText(val.transform, "Name", font, fontMaterial, s.FontSize.Value, s.SkillNameColor.Value);
			RectTransform fill = CreateBar(val.transform, s);
			TextMeshProUGUI value = CreateText(val.transform, "Value", font, fontMaterial, s.FontSize.Value, s.ValueColor.Value);
			TextMeshProUGUI gain = CreateText(val.transform, "Gain", font, fontMaterial, s.FontSize.Value, s.GainColor.Value);
			return new SkillRow((RectTransform)val.transform, val.GetComponent<CanvasGroup>(), name, value, gain, fill);
		}

		public void Apply(in SkillGain gain, float expiresAt, int decimals)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			string text = "F" + Mathf.Clamp(decimals, 0, 6);
			CultureInfo invariantCulture = CultureInfo.InvariantCulture;
			SortKey = gain.Name;
			((TMP_Text)_name).text = gain.Name;
			TextMeshProUGUI value = _value;
			string[] obj = new string[5] { "(", null, null, null, null };
			float accumulator = gain.Accumulator;
			obj[1] = accumulator.ToString(text, invariantCulture);
			obj[2] = " / ";
			accumulator = gain.Required;
			obj[3] = accumulator.ToString(text, invariantCulture);
			obj[4] = ")";
			((TMP_Text)value).text = string.Concat(obj);
			TextMeshProUGUI gain2 = _gain;
			accumulator = gain.Gained;
			((TMP_Text)gain2).text = "+" + accumulator.ToString(text, invariantCulture);
			float num = ((gain.Required > 0f) ? Mathf.Clamp01(gain.Accumulator / gain.Required) : 0f);
			_fill.anchorMax = new Vector2(num, 1f);
			_expiresAt = expiresAt;
			_group.alpha = 1f;
		}

		public bool Tick(float now, float fadeSeconds)
		{
			float num = _expiresAt - now;
			if (num <= 0f)
			{
				return false;
			}
			_group.alpha = ((fadeSeconds > 0f) ? Mathf.Clamp01(num / fadeSeconds) : 1f);
			return true;
		}

		public void Destroy()
		{
			if ((Object)(object)Rect != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)Rect).gameObject);
			}
		}

		private static TextMeshProUGUI CreateText(Transform parent, string objectName, TMP_FontAsset font, Material fontMaterial, int fontSize, Color color)
		{
			//IL_0014: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(objectName, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val2).font = font;
			}
			if ((Object)(object)fontMaterial != (Object)null)
			{
				((TMP_Text)val2).fontSharedMaterial = fontMaterial;
			}
			((TMP_Text)val2).fontSize = fontSize;
			((Graphic)val2).color = color;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((Graphic)val2).raycastTarget = false;
			return val2;
		}

		private static RectTransform CreateBar(Transform parent, Settings s)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_0109: 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)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			GameObject val = new GameObject("Bar", new Type[3]
			{
				typeof(RectTransform),
				typeof(LayoutElement),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			LayoutElement component = val.GetComponent<LayoutElement>();
			component.preferredWidth = s.BarWidth.Value;
			component.preferredHeight = s.BarHeight.Value;
			component.minWidth = s.BarWidth.Value;
			component.minHeight = s.BarHeight.Value;
			Image component2 = val.GetComponent<Image>();
			((Graphic)component2).color = s.BarBackgroundColor.Value;
			((Graphic)component2).raycastTarget = false;
			GameObject val2 = new GameObject("Fill", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val2.transform.SetParent(val.transform, false);
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = new Vector2(0f, 1f);
			val3.pivot = new Vector2(0f, 0.5f);
			val3.offsetMin = new Vector2(1f, 1f);
			val3.offsetMax = new Vector2(-1f, -1f);
			Image component3 = val2.GetComponent<Image>();
			((Graphic)component3).color = s.BarFillColor.Value;
			((Graphic)component3).raycastTarget = false;
			return val3;
		}
	}
	internal sealed class TrackerHud : MonoBehaviour
	{
		private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];

		private readonly Dictionary<SkillType, SkillRow> _rows = new Dictionary<SkillType, SkillRow>();

		private readonly List<SkillType> _expired = new List<SkillType>();

		private readonly List<RectTransform> _anchorRects = new List<RectTransform>();

		private RectTransform _root;

		private RectTransform _anchor;

		private TMP_FontAsset _font;

		private Material _fontMaterial;

		private bool _rebuildRequested;

		private static Settings S => Plugin.Settings;

		private void OnEnable()
		{
			SkillGainPatches.SkillGained += OnSkillGained;
			S.Changed += RequestRebuild;
		}

		private void OnDisable()
		{
			SkillGainPatches.SkillGained -= OnSkillGained;
			S.Changed -= RequestRebuild;
			DestroyRoot();
		}

		private void OnSkillGained(SkillGain gain)
		{
			//IL_0010: 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 (EnsureRoot())
			{
				if (!_rows.TryGetValue(gain.Type, out var value))
				{
					value = SkillRow.Create((Transform)(object)_root, _font, _fontMaterial, S);
					_rows.Add(gain.Type, value);
					value.Apply(in gain, Time.time + S.DisplaySeconds.Value, S.DecimalPlaces.Value);
					SortRows();
				}
				else
				{
					value.Apply(in gain, Time.time + S.DisplaySeconds.Value, S.DecimalPlaces.Value);
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)Hud.instance == (Object)null || (Object)(object)_root == (Object)null)
			{
				if (_rows.Count > 0)
				{
					_rows.Clear();
				}
				_root = null;
				_anchor = null;
			}
			else if (_rebuildRequested)
			{
				_rebuildRequested = false;
				DestroyRoot();
			}
			else
			{
				ExpireRows();
				if (_rows.Count > 0)
				{
					PositionAboveHealthPanel();
				}
			}
		}

		private void ExpireRows()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (_rows.Count == 0)
			{
				return;
			}
			float time = Time.time;
			float value = S.FadeSeconds.Value;
			foreach (KeyValuePair<SkillType, SkillRow> row in _rows)
			{
				if (!row.Value.Tick(time, value))
				{
					_expired.Add(row.Key);
				}
			}
			foreach (SkillType item in _expired)
			{
				_rows[item].Destroy();
				_rows.Remove(item);
			}
			_expired.Clear();
		}

		private void SortRows()
		{
			int num = 0;
			foreach (SkillRow item in _rows.Values.OrderBy<SkillRow, string>((SkillRow r) => r.SortKey, StringComparer.CurrentCultureIgnoreCase))
			{
				((Transform)item.Rect).SetSiblingIndex(num++);
			}
		}

		private void PositionAboveHealthPanel()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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)
			if ((Object)(object)_anchor == (Object)null)
			{
				_anchor = Hud.instance.m_healthPanel;
			}
			if ((Object)(object)_anchor == (Object)null)
			{
				_root.anchoredPosition = new Vector2(S.OffsetX.Value, S.OffsetY.Value + 220f);
				return;
			}
			float minX = float.PositiveInfinity;
			float maxY = float.NegativeInfinity;
			((Component)_anchor).GetComponentsInChildren<RectTransform>(false, _anchorRects);
			foreach (RectTransform anchorRect in _anchorRects)
			{
				AccumulateBounds(anchorRect, ref minX, ref maxY);
			}
			_anchorRects.Clear();
			((Transform)_root).position = new Vector3(minX, maxY, ((Transform)_anchor).position.z);
			RectTransform root = _root;
			root.anchoredPosition += new Vector2(S.OffsetX.Value, S.OffsetY.Value);
		}

		private static void AccumulateBounds(RectTransform rect, ref float minX, ref float maxY)
		{
			rect.GetWorldCorners(Corners);
			for (int i = 0; i < 4; i++)
			{
				if (Corners[i].x < minX)
				{
					minX = Corners[i].x;
				}
				if (Corners[i].y > maxY)
				{
					maxY = Corners[i].y;
				}
			}
		}

		private bool EnsureRoot()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_009c: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_rootObject == (Object)null)
			{
				return false;
			}
			if ((Object)(object)_root != (Object)null)
			{
				return true;
			}
			ResolveFont(instance);
			GameObject val = new GameObject("LiveExperienceTracker", new Type[3]
			{
				typeof(RectTransform),
				typeof(VerticalLayoutGroup),
				typeof(ContentSizeFitter)
			});
			val.transform.SetParent(instance.m_rootObject.transform, false);
			_root = (RectTransform)val.transform;
			_root.anchorMin = Vector2.zero;
			_root.anchorMax = Vector2.zero;
			_root.pivot = Vector2.zero;
			VerticalLayoutGroup component = val.GetComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component).spacing = S.RowSpacing.Value;
			((LayoutGroup)component).childAlignment = (TextAnchor)6;
			((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			ContentSizeFitter component2 = val.GetComponent<ContentSizeFitter>();
			component2.horizontalFit = (FitMode)2;
			component2.verticalFit = (FitMode)2;
			_anchor = null;
			return true;
		}

		private void ResolveFont(Hud hud)
		{
			TMP_Text healthText = hud.m_healthText;
			if ((Object)(object)healthText != (Object)null && (Object)(object)healthText.font != (Object)null)
			{
				_font = healthText.font;
				_fontMaterial = healthText.fontSharedMaterial;
			}
			else
			{
				_font = ((GUIManager.Instance != null) ? GUIManager.Instance.TMP_Norse : null);
				_fontMaterial = null;
			}
		}

		private void RequestRebuild()
		{
			_rebuildRequested = true;
		}

		private void DestroyRoot()
		{
			_rows.Clear();
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_root).gameObject);
			}
			_root = null;
			_anchor = null;
		}
	}
	internal static class BuildInfo
	{
		public const string Name = "LiveExperienceTracker";

		public const string Version = "1.0.2";
	}
}