Decompiled source of BlackBoxReborn v1.0.0

BlackBoxReborn.dll

Decompiled 2 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BlackBoxReborn.Stats;
using BlackBoxReborn.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BlackBoxReborn")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e314f017d037b4cd845437bb01b1258da16ff6a5")]
[assembly: AssemblyProduct("BlackBoxReborn")]
[assembly: AssemblyTitle("BlackBoxReborn")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BlackBoxReborn
{
	internal sealed class Controller : MonoBehaviour
	{
		internal static Controller Instance;

		private StatsPanel panel;

		private TruckMonitor monitor;

		private int errors;

		public StatsPanel Panel => panel;

		public TruckMonitor Monitor => monitor;

		private void Awake()
		{
			Instance = this;
			panel = ((Component)this).gameObject.AddComponent<StatsPanel>();
		}

		private void Update()
		{
			Guard(Tracker.Tick, "Tick");
			Guard(HandleInput, "Input");
			Guard(UpdateMonitor, "Monitor");
		}

		private void Guard(Action action, string where)
		{
			try
			{
				action();
			}
			catch (Exception arg)
			{
				if (errors++ < 20)
				{
					Plugin.Log.LogError((object)$"{where}: {arg}");
				}
			}
		}

		private void HandleInput()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			Keyboard current = Keyboard.current;
			if (current == null || (Object.op_Implicit((Object)(object)ChatManager.instance) && ChatManager.instance.chatActive))
			{
				return;
			}
			Key value = Settings.PanelKey.Value;
			if ((int)value != 0 && ((ButtonControl)current[value]).wasPressedThisFrame)
			{
				panel.Toggle();
			}
			if (panel.IsOpen)
			{
				if (((ButtonControl)current.leftArrowKey).wasPressedThisFrame)
				{
					panel.ChangeTab(-1);
				}
				if (((ButtonControl)current.rightArrowKey).wasPressedThisFrame)
				{
					panel.ChangeTab(1);
				}
				if (((ButtonControl)current.upArrowKey).wasPressedThisFrame)
				{
					panel.ChangeSelection(-1);
				}
				if (((ButtonControl)current.downArrowKey).wasPressedThisFrame)
				{
					panel.ChangeSelection(1);
				}
			}
		}

		private void UpdateMonitor()
		{
			bool flag = SemiFunc.RunIsLevel();
			bool flag2 = SemiFunc.RunIsShop() || SemiFunc.RunIsLobby();
			TruckScreenText instance = TruckScreenText.instance;
			if (!Settings.MonitorEnabled.Value || !(flag || flag2) || !Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)LevelGenerator.Instance) || !LevelGenerator.Instance.Generated)
			{
				if (Object.op_Implicit((Object)(object)monitor))
				{
					Object.Destroy((Object)(object)((Component)monitor).gameObject);
				}
				monitor = null;
			}
			else if (!Object.op_Implicit((Object)(object)monitor))
			{
				monitor = TruckMonitor.Create(Object.op_Implicit((Object)(object)((Component)instance).transform.parent) ? ((Component)instance).transform.parent : ((Component)instance).transform, flag2);
			}
		}
	}
	internal static class Loc
	{
		private static readonly Dictionary<string, (string en, string es)> Table = new Dictionary<string, (string, string)>
		{
			["tab.level"] = ("Level", "Nivel"),
			["tab.players"] = ("Players", "Jugadores"),
			["tab.run"] = ("Run", "Partida"),
			["hint.panel"] = ("{0} / Esc close  ·  ← → tabs  ·  ↑ ↓ player", "{0} / Esc cerrar  ·  ← → pestañas  ·  ↑ ↓ jugador"),
			["level.n"] = ("Level {0}", "Nivel {0}"),
			["level.none"] = ("No level recorded yet", "Aún no hay ningún nivel registrado"),
			["level.none.sub"] = ("Stats start when a level loads.", "Las estadísticas empiezan al cargar un nivel."),
			["live"] = ("LIVE", "EN DIRECTO"),
			["report"] = ("LEVEL REPORT", "INFORME DEL NIVEL"),
			["report.short"] = ("Report", "Informe"),
			["finished"] = ("Finished", "Terminado"),
			["kpi.extracted"] = ("Extracted", "Extraído"),
			["kpi.lost"] = ("Lost", "Perdido"),
			["kpi.discovered"] = ("Discovered", "Descubiertos"),
			["kpi.remaining"] = ("Remaining", "Restante"),
			["kpi.extracted.sub"] = ("{0}% of the map · {1} items", "{0}% del mapa · {1} objetos"),
			["kpi.lost.sub"] = ("{0} destroyed · {1} hits", "{0} destruidos · {1} golpes"),
			["kpi.discovered.sub"] = ("of {0} valuables", "de {0} objetos"),
			["kpi.remaining.sub"] = ("still on the map", "aún en el mapa"),
			["kpi.remaining.done"] = ("level closed", "nivel cerrado"),
			["bar.extracted"] = ("Extracted", "Extraído"),
			["bar.lost"] = ("Lost", "Perdido"),
			["bar.remaining"] = ("Left", "Queda"),
			["sec.damage"] = ("Damage to valuables", "Daños a objetos"),
			["sec.feed"] = ("Recent activity", "Actividad reciente"),
			["sec.feed.empty"] = ("Nothing yet. Handle with care.", "Nada todavía. Con cuidado."),
			["sec.damage.empty"] = ("Nobody has broken anything. Yet.", "Nadie ha roto nada. Todavía."),
			["sec.items"] = ("Valuables damaged by {0}", "Objetos dañados por {0}"),
			["sec.items.empty"] = ("Clean hands.", "Manos limpias."),
			["sec.levels"] = ("Levels", "Niveles"),
			["sec.runplayers"] = ("Whole run", "Toda la partida"),
			["col.player"] = ("Player", "Jugador"),
			["col.hauled"] = ("Hauled", "Extraído"),
			["col.broken"] = ("Broken", "Roto"),
			["col.destroyed"] = ("Destroyed", "Destruidos"),
			["col.hits"] = ("Hits", "Golpes"),
			["col.hurt"] = ("Damage taken", "Daño recibido"),
			["col.deaths"] = ("Deaths", "Muertes"),
			["col.level"] = ("Level", "Nivel"),
			["col.time"] = ("Time", "Tiempo"),
			["col.found"] = ("Found", "Halladas"),
			["run.extracted"] = ("Total extracted", "Total extraído"),
			["run.lost"] = ("Total lost", "Total perdido"),
			["run.levels"] = ("Levels", "Niveles"),
			["run.time"] = ("Time played", "Tiempo jugado"),
			["run.best"] = ("best: level {0} · {1}", "mejor: nivel {0} · {1}"),
			["run.avg"] = ("{0} per level", "{0} por nivel"),
			["last"] = ("Last", "Último"),
			["run.none"] = ("The run starts with the first level.", "La partida empieza con el primer nivel."),
			["badge.mvp"] = ("MVP", "MVP"),
			["badge.butter"] = ("BUTTERFINGERS", "MANAZAS"),
			["unknown"] = ("Environment", "Entorno"),
			["unknown.hint"] = ("enemies, falls, explosions", "enemigos, caídas, explosiones"),
			["destroyed"] = ("DESTROYED", "DESTRUIDO"),
			["feed.break"] = ("{0} damaged {1}", "{0} dañó {1}"),
			["feed.destroy"] = ("{0} destroyed {1}", "{0} destruyó {1}"),
			["feed.extract"] = ("{0} extracted", "{0} extraído"),
			["feed.extract.n"] = ("{0} valuables extracted", "{0} objetos extraídos"),
			["feed.fall"] = ("{0} fell off the map", "{0} se cayó del mapa"),
			["feed.fall.by"] = ("{0} dropped {1} into the void", "{0} tiró {1} al vacío"),
			["cause.hazard"] = ("A trap", "Una trampa"),
			["feed.death"] = ("{0} died", "{0} murió"),
			["feed.death.by"] = ("{0} was killed by {1}", "{1} mató a {0}"),
			["hud.left"] = ("left", "restante"),
			["page"] = ("{0}/{1}", "{0}/{1}"),
			["more"] = ("+{0} more", "+{0} más")
		};

		public static bool Spanish
		{
			get
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				switch (Settings.Language.Value)
				{
				case UiLanguage.English:
					return false;
				case UiLanguage.Spanish:
					return true;
				default:
					try
					{
						Locale selectedLocale = LocalizationSettings.SelectedLocale;
						int result;
						if ((Object)(object)selectedLocale != (Object)null)
						{
							LocaleIdentifier identifier = selectedLocale.Identifier;
							result = (((LocaleIdentifier)(ref identifier)).Code.StartsWith("es", StringComparison.OrdinalIgnoreCase) ? 1 : 0);
						}
						else
						{
							result = 0;
						}
						return (byte)result != 0;
					}
					catch
					{
						return false;
					}
				}
			}
		}

		public static string T(string key)
		{
			if (!Table.TryGetValue(key, out (string, string) value))
			{
				return key;
			}
			if (!Spanish)
			{
				return value.Item1;
			}
			return value.Item2;
		}

		public static string T(string key, params object[] args)
		{
			return string.Format(T(key), args);
		}
	}
	[BepInPlugin("vicxelcode.BlackBoxReborn", "Black Box Reborn", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "vicxelcode.BlackBoxReborn";

		public const string Name = "Black Box Reborn";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001b: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Settings.Bind(((BaseUnityPlugin)this).Config);
			new Harmony("vicxelcode.BlackBoxReborn").PatchAll(typeof(Plugin).Assembly);
			GameObject val = new GameObject("BlackBoxReborn")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<Controller>();
			Log.LogInfo((object)"Black Box Reborn 1.0.0 cargado");
		}
	}
	public enum UiLanguage
	{
		Auto,
		English,
		Spanish
	}
	public enum RemainingValueMode
	{
		InTruck,
		Always,
		Never
	}
	internal static class Settings
	{
		public static ConfigEntry<UiLanguage> Language;

		public static ConfigEntry<Key> PanelKey;

		public static ConfigEntry<float> PanelScale;

		public static ConfigEntry<bool> MonitorEnabled;

		public static ConfigEntry<float> MonitorPageSeconds;

		public static ConfigEntry<RemainingValueMode> RemainingValue;

		public static void Bind(ConfigFile cfg)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			Language = cfg.Bind<UiLanguage>("General", "Language", UiLanguage.Auto, "Language of the panel and the monitor. Auto follows the game language.");
			PanelKey = cfg.Bind<Key>("Panel", "ToggleKey", (Key)99, "Key that opens and closes the stats panel.");
			PanelScale = cfg.Bind<float>("Panel", "Scale", 1f, new ConfigDescription("Size of the stats panel.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 1.6f), Array.Empty<object>()));
			MonitorEnabled = cfg.Bind<bool>("Monitor", "Enabled", true, "Show the stats monitor inside the truck and the level report in the shop.");
			MonitorPageSeconds = cfg.Bind<float>("Monitor", "PageSeconds", 7f, new ConfigDescription("Seconds each page stays on the monitor when there are too many players to fit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 30f), Array.Empty<object>()));
			RemainingValue = cfg.Bind<RemainingValueMode>("HUD", "RemainingValue", RemainingValueMode.InTruck, "Show the value still left on the map next to the haul goal.");
		}
	}
}
namespace BlackBoxReborn.UI
{
	internal static class Format
	{
		public static string Money(float value)
		{
			int num = Mathf.RoundToInt(value);
			try
			{
				return SemiFunc.DollarGetString(num);
			}
			catch (Exception)
			{
				return num.ToString("#,0", CultureInfo.InvariantCulture);
			}
		}

		public static string Dollars(float value)
		{
			return "$" + Money(value);
		}

		public static string Loss(float value)
		{
			if (!(value >= 0.5f))
			{
				return "$0";
			}
			return "-$" + Money(value);
		}

		public static string Duration(float seconds)
		{
			if (seconds < 0f)
			{
				seconds = 0f;
			}
			int num = Mathf.FloorToInt(seconds);
			int num2 = num / 3600;
			int num3 = num / 60 % 60;
			int num4 = num % 60;
			if (num2 <= 0)
			{
				return $"{num3:00}:{num4:00}";
			}
			return $"{num2}:{num3:00}:{num4:00}";
		}

		public static string Ago(float seconds)
		{
			int num = Mathf.Max(0, Mathf.FloorToInt(seconds));
			if (Loc.Spanish)
			{
				if (num >= 60)
				{
					return $"hace {num / 60} min";
				}
				return $"hace {num} s";
			}
			if (num >= 60)
			{
				return $"{num / 60}m ago";
			}
			return $"{num}s ago";
		}

		public static string Percent(float value)
		{
			return Mathf.RoundToInt(value).ToString(CultureInfo.InvariantCulture);
		}
	}
	internal static class MonitorViews
	{
		private const float Pad = 34f;

		public static void Header(RectTransform p, float w, string left, LevelStats level, bool live)
		{
			//IL_0020: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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)
			Views.Logo(p, 34f, 26f, 64f);
			TextMeshProUGUI obj = Ui.Label((Transform)(object)p, "BLACK BOX", 76f, Theme.Text, (TextAlignmentOptions)513, bold: true).Display();
			((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
			((TMP_Text)obj).characterSpacing = 4f;
			((TMP_Text)obj).rectTransform.Place(118f, 18f, 420f, 80f);
			TextMeshProUGUI val = Ui.Label((Transform)(object)p, "", 54f, Theme.Text, (TextAlignmentOptions)516, bold: true).Display();
			((TMP_Text)val).overflowMode = (TextOverflowModes)0;
			if (live && level != null)
			{
				bool flag = Mathf.FloorToInt(Time.unscaledTime * 1.6f) % 2 == 0;
				((TMP_Text)val).text = "<color=" + Theme.Rich(flag ? Theme.Bad : Theme.Hex("5A1E1F")) + ">●</color> " + Format.Duration(level.Duration);
			}
			else
			{
				((TMP_Text)val).text = left;
				((Graphic)val).color = Theme.Accent;
			}
			((TMP_Text)val).rectTransform.Place(w / 2f, 24f, w / 2f - 34f, 70f);
		}

		private static void BigStat(RectTransform p, float x, float y, float w, float h, string label, string value, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)Ui.Box((Transform)(object)p, Theme.Surface, "Stat", round: true, 1.2f)).rectTransform.Place(x, y, w, h);
			((Graphic)Ui.Box((Transform)(object)p, color, "StatBar", round: true, 0.3f)).rectTransform.Place(x + 22f, y + 26f, 30f, 8f);
			TextMeshProUGUI obj = Ui.Label((Transform)(object)p, label.ToUpperInvariant(), 30f, Theme.Muted, (TextAlignmentOptions)513, bold: true);
			((TMP_Text)obj).characterSpacing = 3f;
			((TMP_Text)obj).rectTransform.Place(x + 62f, y + 10f, w - 80f, 40f);
			TextMeshProUGUI obj2 = Ui.Label((Transform)(object)p, value, 104f, color, (TextAlignmentOptions)513, bold: true).Display();
			((TMP_Text)obj2).enableAutoSizing = true;
			((TMP_Text)obj2).fontSizeMin = 40f;
			((TMP_Text)obj2).fontSizeMax = 104f;
			((TMP_Text)obj2).overflowMode = (TextOverflowModes)0;
			((TMP_Text)obj2).rectTransform.Place(x + 22f, y + 50f, w - 44f, h - 58f);
		}

		public static void Stats(RectTransform p, float y, float w, float h, LevelStats level, bool shop)
		{
			//IL_001c: 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_0050: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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)
			List<(string, string, Color)> list = new List<(string, string, Color)>
			{
				(Loc.T("kpi.extracted"), Format.Dollars(level.ValueExtracted), Theme.Good),
				(Loc.T("kpi.lost"), Format.Loss(level.ValueLost), (level.ValueLost > 0.5f) ? Theme.Bad : Theme.Muted),
				shop ? (Loc.T("kpi.discovered"), $"{level.ItemsDiscovered}/{level.ItemsSpawned}", Theme.Warn) : (Loc.T("kpi.remaining"), Format.Dollars(level.ValueRemaining), Theme.Info)
			};
			float num = (w - 68f - 36f) / 3f;
			for (int i = 0; i < list.Count; i++)
			{
				var (label, value, color) = list[i];
				BigStat(p, 34f + (float)i * (num + 18f), y, num, h, label, value, color);
			}
		}

		public static void Damage(RectTransform p, float y, float w, float h, LevelStats level)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			float num = 34f;
			float num2 = w - 68f;
			((Graphic)Ui.Box((Transform)(object)p, Theme.Surface, "Card", round: true, 1.2f)).rectTransform.Place(num, y, num2, h);
			TextMeshProUGUI obj = Ui.Label((Transform)(object)p, Loc.T("sec.damage").ToUpperInvariant(), 30f, Theme.Muted, (TextAlignmentOptions)513, bold: true);
			((TMP_Text)obj).characterSpacing = 3f;
			((TMP_Text)obj).rectTransform.Place(num + 26f, y + 12f, num2 - 52f, 40f);
			FeedEvent feedEvent = ((level.Feed.Count > 0) ? level.Feed[level.Feed.Count - 1] : null);
			if (feedEvent != null)
			{
				var (text, text2, color) = Views.Describe(feedEvent);
				((Graphic)Ui.Box((Transform)(object)p, Theme.Border, "Rule", round: false)).rectTransform.Place(num + 26f, y + h - 58f - 4f, num2 - 52f, 2f);
				Views.Dot(p, num + 26f, y + h - 29f - 9f, 18f, color);
				((TMP_Text)Ui.Label((Transform)(object)p, text, 34f, Theme.Muted, (TextAlignmentOptions)513)).rectTransform.Place(num + 58f, y + h - 58f, num2 * 0.68f, 58f);
				((TMP_Text)Ui.Label((Transform)(object)p, text2, 40f, color, (TextAlignmentOptions)516, bold: true).Display()).rectTransform.Place(num + num2 * 0.7f, y + h - 58f, num2 * 0.3f - 26f, 58f);
				h -= 58f;
			}
			List<PlayerStats> list = (from r in level.Players.Values
				where r.ValueBroken > 0.5f
				orderby r.ValueBroken descending
				select r).Take(3).ToList();
			if (list.Count == 0)
			{
				TextMeshProUGUI obj2 = Ui.Label((Transform)(object)p, Loc.T("sec.damage.empty"), 40f, Theme.Faint, (TextAlignmentOptions)514);
				((TMP_Text)obj2).fontStyle = (FontStyles)2;
				((TMP_Text)obj2).rectTransform.Place(num, y + 50f, num2, h - 60f);
				return;
			}
			float num3 = Mathf.Min(78f, (h - 60f) / (float)list.Count);
			float valueBroken = list[0].ValueBroken;
			for (int num4 = 0; num4 < list.Count; num4++)
			{
				PlayerStats playerStats = list[num4];
				float num5 = y + 56f + (float)num4 * num3;
				Views.Dot(p, num + 26f, num5 + num3 / 2f - 12f, 24f, Theme.Player(playerStats.Order, playerStats.IsUnknown));
				((TMP_Text)Ui.Label((Transform)(object)p, playerStats.IsUnknown ? Loc.T("unknown") : playerStats.Name, 46f, Theme.Text, (TextAlignmentOptions)513, bold: true)).rectTransform.Place(num + 66f, num5, num2 * 0.45f, num3);
				float x = num + num2 * 0.5f;
				float num6 = num2 * 0.2f;
				((Graphic)Ui.Box((Transform)(object)p, Theme.Track, "Track", round: true, 0.5f)).rectTransform.Place(x, num5 + num3 / 2f - 9f, num6, 18f);
				((Graphic)Ui.Box((Transform)(object)p, Theme.Bad, "Fill", round: true, 0.5f)).rectTransform.Place(x, num5 + num3 / 2f - 9f, Mathf.Max(18f, num6 * playerStats.ValueBroken / valueBroken), 18f);
				TextMeshProUGUI obj3 = Ui.Label((Transform)(object)p, Format.Loss(playerStats.ValueBroken), 66f, Theme.Bad, (TextAlignmentOptions)516, bold: true).Display();
				((TMP_Text)obj3).overflowMode = (TextOverflowModes)0;
				((TMP_Text)obj3).rectTransform.Place(num + num2 * 0.72f, num5, num2 * 0.28f - 26f, num3);
			}
		}

		public static void Players(RectTransform p, float y, float w, float h, IList<PlayerStats> players, int page, out int pages)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			pages = Mathf.Max(1, Mathf.CeilToInt((float)players.Count / 3f));
			page %= pages;
			List<PlayerStats> source = players.Where((PlayerStats r) => !r.IsUnknown).ToList();
			PlayerStats playerStats = (from r in source
				where r.ValueHauled > 0.5f
				orderby r.ValueHauled descending
				select r).FirstOrDefault();
			PlayerStats playerStats2 = (from r in source
				where r.ValueBroken > 0.5f
				orderby r.ValueBroken descending
				select r).FirstOrDefault();
			float num = 34f;
			float num2 = w - 68f;
			((Graphic)Ui.Box((Transform)(object)p, Theme.Surface, "Card", round: true, 1.2f)).rectTransform.Place(num, y, num2, h);
			(string, float, float)[] array = new(string, float, float)[2]
			{
				(Loc.T("col.hauled"), 0.5f, 0.75f),
				(Loc.T("col.broken"), 0.75f, 1f)
			};
			for (int num3 = 0; num3 < array.Length; num3++)
			{
				(string, float, float) tuple = array[num3];
				string item = tuple.Item1;
				float item2 = tuple.Item2;
				float item3 = tuple.Item3;
				TextMeshProUGUI obj = Ui.Label((Transform)(object)p, item.ToUpperInvariant(), 28f, Theme.Muted, (TextAlignmentOptions)516, bold: true);
				((TMP_Text)obj).characterSpacing = 3f;
				((TMP_Text)obj).rectTransform.Place(num + num2 * item2, y + 12f, num2 * (item3 - item2) - 26f, 36f);
			}
			List<PlayerStats> list = players.Skip(page * 3).Take(3).ToList();
			float num4 = Mathf.Min(82f, (h - 56f) / 3f);
			for (int num5 = 0; num5 < list.Count; num5++)
			{
				PlayerStats playerStats3 = list[num5];
				float num6 = y + 52f + (float)num5 * num4;
				Views.Dot(p, num + 26f, num6 + num4 / 2f - 12f, 24f, Theme.Player(playerStats3.Order, playerStats3.IsUnknown));
				string text = ((playerStats3 == playerStats) ? Loc.T("badge.mvp") : ((playerStats3 == playerStats2) ? Loc.T("badge.butter") : null));
				float num7 = num2 * 0.5f - 66f - ((text != null) ? 190f : 10f);
				TextMeshProUGUI obj2 = Ui.Label((Transform)(object)p, playerStats3.IsUnknown ? Loc.T("unknown") : playerStats3.Name, 44f, Theme.Text, (TextAlignmentOptions)513, bold: true);
				((TMP_Text)obj2).enableAutoSizing = true;
				((TMP_Text)obj2).fontSizeMin = 30f;
				((TMP_Text)obj2).fontSizeMax = 44f;
				float num8 = Mathf.Min(((TMP_Text)obj2).GetPreferredValues(((TMP_Text)obj2).text).x + 4f, num7);
				((TMP_Text)obj2).rectTransform.Place(num + 66f, num6, num8, num4);
				if (text != null)
				{
					Views.Pill(p, num + 78f + num8, num6 + num4 / 2f - 19f, text, (playerStats3 == playerStats) ? Theme.Good : Theme.Bad, Theme.Hex("101114"), 26f);
				}
				TextMeshProUGUI obj3 = Ui.Label((Transform)(object)p, Format.Dollars(playerStats3.ValueHauled), 62f, (playerStats3.ValueHauled > 0.5f) ? Theme.Good : Theme.Faint, (TextAlignmentOptions)516, bold: true).Display();
				((TMP_Text)obj3).overflowMode = (TextOverflowModes)0;
				((TMP_Text)obj3).rectTransform.Place(num + num2 * 0.5f, num6, num2 * 0.25f - 26f, num4);
				TextMeshProUGUI obj4 = Ui.Label((Transform)(object)p, Format.Loss(playerStats3.ValueBroken), 62f, (playerStats3.ValueBroken > 0.5f) ? Theme.Bad : Theme.Faint, (TextAlignmentOptions)516, bold: true).Display();
				((TMP_Text)obj4).overflowMode = (TextOverflowModes)0;
				((TMP_Text)obj4).rectTransform.Place(num + num2 * 0.75f, num6, num2 * 0.25f - 26f, num4);
			}
		}
	}
	internal sealed class StatsPanel : MonoBehaviour
	{
		public const float Width = 1180f;

		public const float Height = 700f;

		private const float HeaderH = 82f;

		private const float FooterH = 40f;

		private static readonly string[] Tabs = new string[3] { "tab.level", "tab.players", "tab.run" };

		private RectTransform root;

		private RectTransform content;

		private CanvasGroup group;

		private bool open;

		private float visibility;

		private int tab;

		private int selected;

		private int builtRevision = -1;

		private float nextRebuild;

		private bool dirty;

		public bool IsOpen => open;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("BlackBoxPanel", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			val.layer = 5;
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 900;
			CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			obj2.matchWidthOrHeight = 0.5f;
			root = Ui.Rect("Panel", val.transform);
			RectTransform obj3 = root;
			RectTransform obj4 = root;
			RectTransform obj5 = root;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			obj5.pivot = val2;
			Vector2 anchorMin = (obj4.anchorMax = val2);
			obj3.anchorMin = anchorMin;
			root.sizeDelta = new Vector2(1180f, 700f);
			group = ((Component)root).gameObject.AddComponent<CanvasGroup>();
			group.alpha = 0f;
			group.interactable = false;
			group.blocksRaycasts = false;
			((Graphic)Ui.Box((Transform)(object)root, Theme.Border, "Border", round: true, 0.9f)).rectTransform.Fill(-1f, -1f, -1f, -1f);
			((Graphic)Ui.Box((Transform)(object)root, Theme.Backdrop, "Backdrop", round: true, 0.9f)).rectTransform.Fill();
			((Graphic)Ui.Box((Transform)(object)root, Theme.Accent, "TopLine", round: false)).rectTransform.Place(28f, 0f, 120f, 3f);
			content = Ui.Rect("Content", (Transform)(object)root).Fill();
			((Component)root).gameObject.SetActive(false);
		}

		public void Toggle()
		{
			open = !open;
			if (open)
			{
				((Component)root).gameObject.SetActive(true);
				dirty = true;
			}
		}

		public void Close()
		{
			open = false;
		}

		public void ChangeTab(int delta)
		{
			tab = (tab + delta + Tabs.Length) % Tabs.Length;
			dirty = true;
		}

		public void SetTab(int index)
		{
			tab = Mathf.Clamp(index, 0, Tabs.Length - 1);
			dirty = true;
		}

		public void ChangeSelection(int delta)
		{
			if (tab == 1)
			{
				selected += delta;
				dirty = true;
			}
		}

		private void Update()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			float num = (open ? 1f : 0f);
			visibility = Mathf.MoveTowards(visibility, num, Time.unscaledDeltaTime * 7f);
			float num2 = 1f - Mathf.Pow(1f - visibility, 3f);
			group.alpha = num2;
			((Transform)root).localScale = Vector3.one * (Settings.PanelScale.Value * (0.96f + 0.04f * num2));
			if (!open && visibility <= 0f)
			{
				if (((Component)root).gameObject.activeSelf)
				{
					((Component)root).gameObject.SetActive(false);
				}
			}
			else if (dirty || Tracker.Revision != builtRevision || Time.unscaledTime >= nextRebuild)
			{
				Rebuild();
			}
		}

		private void Rebuild()
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			dirty = false;
			builtRevision = Tracker.Revision;
			nextRebuild = Time.unscaledTime + 1f;
			Ui.Clear((Transform)(object)content);
			RunStats run = Tracker.Run;
			LevelStats current = run.Current;
			Views.Header(content, 1180f, current, null);
			DrawTabs();
			RectTransform val = Ui.Rect("Body", (Transform)(object)content).Place(28f, 90f, 1124f, 562f);
			Rect rect = val.rect;
			float width = ((Rect)(ref rect)).width;
			rect = val.rect;
			float height = ((Rect)(ref rect)).height;
			switch (tab)
			{
			case 0:
				DrawLevel(val, width, height, current);
				break;
			case 1:
				DrawPlayers(val, width, height, current);
				break;
			default:
				DrawRun(val, width, height, run);
				break;
			}
			string text = ((object)Settings.PanelKey.Value/*cast due to .constrained prefix*/).ToString();
			((Graphic)Ui.Box((Transform)(object)content, Theme.Border, "FooterRule", round: false)).rectTransform.Place(28f, 660f, 1124f, 1f);
			((TMP_Text)Ui.Label((Transform)(object)content, Loc.T("hint.panel", text), 13f, Theme.Faint, (TextAlignmentOptions)513)).rectTransform.Place(28f, 662f, 700f, 36f);
			((TMP_Text)Ui.Label((Transform)(object)content, "v1.0.0", 13f, Theme.Faint, (TextAlignmentOptions)516)).rectTransform.Place(960f, 662f, 192f, 36f);
		}

		private void DrawTabs()
		{
			//IL_0039: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			float num = 1152f;
			for (int num2 = Tabs.Length - 1; num2 >= 0; num2--)
			{
				bool flag = num2 == tab;
				TextMeshProUGUI val = Ui.Label((Transform)(object)content, string.Format("<size=75%><color={0}>{1}</color></size>  {2}", Theme.Rich(flag ? Theme.Hex("5A2A08") : Theme.Faint), num2 + 1, Loc.T(Tabs[num2])), 15f, flag ? Theme.Hex("141518") : Theme.Muted, (TextAlignmentOptions)514, bold: true, "Tab");
				float num3 = ((TMP_Text)val).GetPreferredValues(((TMP_Text)val).text).x + 32f;
				num -= num3;
				Image obj = Ui.Box((Transform)(object)content, flag ? Theme.Accent : Theme.SurfaceHi, "TabBg", round: true, 0.45f);
				((Graphic)obj).rectTransform.Place(num, 24f, num3, 36f);
				((Component)obj).transform.SetSiblingIndex(((TMP_Text)val).transform.GetSiblingIndex());
				((TMP_Text)val).rectTransform.Place(num, 24f, num3, 36f);
				num -= 8f;
			}
		}

		private static void DrawEmpty(RectTransform body, float w, float h)
		{
			//IL_0035: 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)
			Views.Logo(body, w / 2f - 32f, h / 2f - 90f, 64f);
			((TMP_Text)Ui.Label((Transform)(object)body, Loc.T("level.none"), 22f, Theme.Text, (TextAlignmentOptions)514, bold: true)).rectTransform.Place(0f, h / 2f - 10f, w, 30f);
			((TMP_Text)Ui.Label((Transform)(object)body, Loc.T("level.none.sub"), 15f, Theme.Muted, (TextAlignmentOptions)514)).rectTransform.Place(0f, h / 2f + 24f, w, 24f);
		}

		private static void DrawLevel(RectTransform body, float w, float h, LevelStats level)
		{
			if (level == null)
			{
				DrawEmpty(body, w, h);
				return;
			}
			Views.LevelKpis(body, 0f, 0f, w, 116f, level);
			Views.ValueBar(body, 0f, 134f, w, level);
			float num = (w - 14f) / 2f;
			Views.DamageRanking(body, 0f, 196f, num, h - 196f, level);
			Views.Feed(body, num + 14f, 196f, num, h - 196f, level);
		}

		private void DrawPlayers(RectTransform body, float w, float h, LevelStats level)
		{
			if (level == null)
			{
				DrawEmpty(body, w, h);
				return;
			}
			List<PlayerStats> list = level.RankedPlayers.ToList();
			if (list.Count != 0)
			{
				selected = Mathf.Clamp(selected, 0, list.Count - 1);
				PlayerStats playerStats = list[selected];
				float num = Views.PlayerTable(body, 0f, 0f, w, h * 0.62f, list, playerStats.Id, compact: false);
				Views.ItemDetail(body, 0f, num + 14f, w, h - num - 14f, playerStats);
			}
		}

		private static void DrawRun(RectTransform body, float w, float h, RunStats run)
		{
			if (run.Levels.Count == 0)
			{
				DrawEmpty(body, w, h);
				return;
			}
			Views.RunKpis(body, 0f, 0f, w, 116f, run);
			float num = w * 0.6f;
			Views.LevelsTable(body, 0f, 132f, num - 7f, h - 132f, run);
			Views.RunPlayers(body, num + 7f, 132f, w - num - 7f, h - 132f, run.Totals());
		}
	}
	internal sealed class TruckMonitor : MonoBehaviour
	{
		public const float Width = 1180f;

		public const float Height = 664f;

		public static Vector3 LocalOffset = new Vector3(-24.1f, 2.95f, 0f);

		public static Vector3 LocalEuler = new Vector3(0f, 270f, 0f);

		public static float WorldWidth = 2.6f;

		private RectTransform content;

		private int builtRevision = -1;

		private float nextRebuild;

		private int page;

		private float nextPage;

		private bool shop;

		public static TruckMonitor Create(Transform anchor, bool shop)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("BlackBoxMonitor", new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)anchor).gameObject.layer
			};
			((Transform)(RectTransform)val.transform).SetParent(anchor, false);
			TruckMonitor truckMonitor = val.AddComponent<TruckMonitor>();
			truckMonitor.shop = shop;
			truckMonitor.Build();
			truckMonitor.ApplyPlacement();
			return truckMonitor;
		}

		public void ApplyPlacement()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)((Component)this).transform;
			((Transform)val).localPosition = LocalOffset;
			((Transform)val).localRotation = Quaternion.Euler(LocalEuler);
			float num = (Object.op_Implicit((Object)(object)((Component)this).transform.parent) ? ((Component)this).transform.parent.lossyScale.x : 1f);
			((Transform)val).localScale = Vector3.one * (WorldWidth / 1180f / Mathf.Max(0.0001f, num));
		}

		private void Build()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0028: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).gameObject.AddComponent<Canvas>().renderMode = (RenderMode)2;
			RectTransform val = (RectTransform)((Component)this).transform;
			val.sizeDelta = new Vector2(1180f, 664f);
			((Component)this).gameObject.AddComponent<CanvasScaler>().dynamicPixelsPerUnit = 3f;
			((Graphic)Ui.Box((Transform)(object)val, Theme.Hex("050506"), "Bezel", round: true, 1.2f)).rectTransform.Fill(-18f, -18f, -18f, -18f);
			((Graphic)Ui.Box((Transform)(object)val, Theme.Hex("0B0C0F"), "Screen", round: true, 0.6f)).rectTransform.Fill();
			content = Ui.Rect("Content", (Transform)(object)val).Fill();
		}

		private void Update()
		{
			if (Time.unscaledTime >= nextPage)
			{
				nextPage = Time.unscaledTime + Settings.MonitorPageSeconds.Value;
				page++;
				builtRevision = -1;
			}
			if (Tracker.Revision != builtRevision || !(Time.unscaledTime < nextRebuild))
			{
				builtRevision = Tracker.Revision;
				nextRebuild = Time.unscaledTime + 1f;
				Ui.Clear((Transform)(object)content);
				LevelStats current = Tracker.Run.Current;
				if (current == null)
				{
					MonitorViews.Header(content, 1180f, "", null, live: false);
				}
				else if (!shop)
				{
					MonitorViews.Header(content, 1180f, "", current, !current.Finished);
					MonitorViews.Stats(content, 118f, 1180f, 210f, current, shop: false);
					MonitorViews.Damage(content, 346f, 1180f, 288f, current);
				}
				else
				{
					MonitorViews.Header(content, 1180f, (Loc.T("report.short") + " · " + Loc.T("level.n", current.Number)).ToUpperInvariant(), current, live: false);
					MonitorViews.Stats(content, 118f, 1180f, 190f, current, shop: true);
					MonitorViews.Players(content, 326f, 1180f, 308f, current.RankedPlayers.ToList(), page, out var _);
				}
			}
		}
	}
	internal static class Theme
	{
		public static readonly Color Backdrop = Hex("0B0C0FF0");

		public static readonly Color Border = Hex("2A2E37");

		public static readonly Color Surface = Hex("15171CF5");

		public static readonly Color SurfaceHi = Hex("1D2027");

		public static readonly Color Track = Hex("262A32");

		public static readonly Color Text = Hex("ECEDF1");

		public static readonly Color Muted = Hex("8D929E");

		public static readonly Color Faint = Hex("5B606B");

		public static readonly Color Accent = Hex("FF7A1A");

		public static readonly Color Good = Hex("6CCB5F");

		public static readonly Color Bad = Hex("FF4D4F");

		public static readonly Color Warn = Hex("F5B841");

		public static readonly Color Info = Hex("5AA9FF");

		public static readonly Color Remaining = Hex("4A505C");

		private static readonly Color[] PlayerColors = (Color[])(object)new Color[8]
		{
			Hex("5AA9FF"),
			Hex("F5B841"),
			Hex("B07CFF"),
			Hex("4CD3C2"),
			Hex("FF6FA8"),
			Hex("9BD45A"),
			Hex("FF8A5A"),
			Hex("7F8CFF")
		};

		public static Color Player(int order, bool unknown)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!unknown)
			{
				return PlayerColors[Mathf.Abs(order) % PlayerColors.Length];
			}
			return Muted;
		}

		public static string Rich(Color c)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return "#" + ColorUtility.ToHtmlStringRGB(c);
		}

		public static Color Hex(string hex)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			ColorUtility.TryParseHtmlString("#" + hex, ref result);
			return result;
		}
	}
	internal static class Ui
	{
		private static Sprite rounded;

		private static TMP_FontAsset font;

		private static bool fontLogged;

		private static readonly string[] PreferredFonts = new string[1] { "LiberationSans SDF" };

		private static TMP_FontAsset display;

		public static Sprite Rounded
		{
			get
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: 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_0034: Expected O, but got Unknown
				//IL_011e: 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_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: 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)
				if (Object.op_Implicit((Object)(object)rounded))
				{
					return rounded;
				}
				Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)1,
					hideFlags = (HideFlags)61
				};
				Color32[] array = (Color32[])(object)new Color32[4096];
				for (int i = 0; i < 64; i++)
				{
					for (int j = 0; j < 64; j++)
					{
						float num = Mathf.Clamp((float)j + 0.5f, 20f, 44f);
						float num2 = Mathf.Clamp((float)i + 0.5f, 20f, 44f);
						float num3 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), new Vector2(num, num2));
						float num4 = Mathf.Clamp01(20f - num3 + 0.5f);
						array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num4 * 255f));
					}
				}
				val.SetPixels32(array);
				val.Apply(false, true);
				rounded = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(20f, 20f, 20f, 20f));
				((Object)rounded).hideFlags = (HideFlags)61;
				return rounded;
			}
		}

		public static TMP_FontAsset Font
		{
			get
			{
				if (Object.op_Implicit((Object)(object)font))
				{
					return font;
				}
				TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				if (!fontLogged)
				{
					fontLogged = true;
					Plugin.Log.LogDebug((object)("Fuentes TMP: " + string.Join(", ", source.Select((TMP_FontAsset f) => ((Object)f).name))));
				}
				string[] preferredFonts = PreferredFonts;
				foreach (string wanted in preferredFonts)
				{
					font = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => Object.op_Implicit((Object)(object)f) && ((Object)f).name.Equals(wanted, StringComparison.OrdinalIgnoreCase)));
					if (Object.op_Implicit((Object)(object)font))
					{
						return font;
					}
				}
				font = TMP_Settings.defaultFontAsset;
				if (!Object.op_Implicit((Object)(object)font))
				{
					font = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => Object.op_Implicit((Object)(object)f)));
				}
				return font;
			}
		}

		public static TMP_FontAsset DisplayFont
		{
			get
			{
				if (Object.op_Implicit((Object)(object)display))
				{
					return display;
				}
				display = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => Object.op_Implicit((Object)(object)f) && ((Object)f).name.StartsWith("Teko", StringComparison.OrdinalIgnoreCase)));
				if (!Object.op_Implicit((Object)(object)display))
				{
					return Font;
				}
				return display;
			}
		}

		public static TextMeshProUGUI Display(this TextMeshProUGUI t)
		{
			((TMP_Text)t).font = DisplayFont;
			return t;
		}

		public static RectTransform Rect(string name, Transform parent)
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = (Object.op_Implicit((Object)(object)parent) ? ((Component)parent).gameObject.layer : 5)
			}.transform;
			((Transform)val).SetParent(parent, false);
			return val;
		}

		public static RectTransform Fill(this RectTransform rt, float left = 0f, float top = 0f, float right = 0f, float bottom = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = new Vector2(left, bottom);
			rt.offsetMax = new Vector2(0f - right, 0f - top);
			return rt;
		}

		public static RectTransform Place(this RectTransform rt, float x, float y, float w, float h)
		{
			//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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rt.anchorMax = val;
			rt.anchorMin = val;
			rt.pivot = new Vector2(0f, 1f);
			rt.anchoredPosition = new Vector2(x, 0f - y);
			rt.sizeDelta = new Vector2(w, h);
			return rt;
		}

		public static Image Box(Transform parent, Color color, string name = "Box", bool round = true, float radiusScale = 1f)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Image val = ((Component)Rect(name, parent)).gameObject.AddComponent<Image>();
			((Graphic)val).color = color;
			((Graphic)val).raycastTarget = false;
			if (round)
			{
				val.sprite = Rounded;
				val.type = (Type)1;
				val.pixelsPerUnitMultiplier = 1f / Mathf.Max(0.05f, radiusScale);
			}
			return val;
		}

		public static TextMeshProUGUI Label(Transform parent, string text, float size, Color color, TextAlignmentOptions align = (TextAlignmentOptions)513, bool bold = false, string name = "Label")
		{
			//IL_0037: 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)
			TextMeshProUGUI val = ((Component)Rect(name, parent)).gameObject.AddComponent<TextMeshProUGUI>();
			TMP_FontAsset val2 = Font;
			if (Object.op_Implicit((Object)(object)val2))
			{
				((TMP_Text)val).font = val2;
			}
			((TMP_Text)val).text = text;
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((TMP_Text)val).fontStyle = (FontStyles)(bold ? 1 : 0);
			((TMP_Text)val).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).richText = true;
			return val;
		}

		public static void Clear(Transform t)
		{
			for (int num = t.childCount - 1; num >= 0; num--)
			{
				GameObject gameObject = ((Component)t.GetChild(num)).gameObject;
				gameObject.SetActive(false);
				Object.Destroy((Object)(object)gameObject);
			}
		}
	}
	internal static class Views
	{
		private enum Col
		{
			Player,
			Hauled,
			Broken,
			Destroyed,
			Hits,
			Hurt,
			Deaths
		}

		public const float Pad = 20f;

		private static readonly (Col col, float width)[] FullColumns = new(Col, float)[7]
		{
			(Col.Player, 0.3f),
			(Col.Hauled, 0.14f),
			(Col.Broken, 0.13f),
			(Col.Destroyed, 0.11f),
			(Col.Hits, 0.08f),
			(Col.Hurt, 0.14f),
			(Col.Deaths, 0.1f)
		};

		private static readonly (Col col, float width)[] CompactColumns = new(Col, float)[5]
		{
			(Col.Player, 0.36f),
			(Col.Hauled, 0.19f),
			(Col.Broken, 0.17f),
			(Col.Destroyed, 0.15f),
			(Col.Deaths, 0.13f)
		};

		public static void Logo(RectTransform parent, float x, float y, float size)
		{
			//IL_0001: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)Ui.Box((Transform)(object)parent, Theme.Accent, "Logo", round: true, size / 80f)).rectTransform.Place(x, y, size, size);
			float num = size * 0.56f;
			((Graphic)Ui.Box((Transform)(object)parent, Theme.Hex("111215"), "LogoInner", round: true, num / 90f)).rectTransform.Place(x + (size - num) / 2f, y + (size - num) / 2f - size * 0.04f, num, num * 0.82f);
			float num2 = size * 0.36f;
			((Graphic)Ui.Box((Transform)(object)parent, Theme.Accent, "LogoStripe", round: false)).rectTransform.Place(x + (size - num2) / 2f, y + size * 0.47f, num2, Mathf.Max(2f, size * 0.07f));
		}

		public static void Dot(RectTransform parent, float x, float y, float size, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)Ui.Box((Transform)(object)parent, color, "Dot", round: true, size / 40f)).rectTransform.Place(x, y, size, size);
		}

		public static float Pill(RectTransform parent, float x, float y, string text, Color bg, Color fg, float size = 12f)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = Ui.Label((Transform)(object)parent, text, size, fg, (TextAlignmentOptions)514, bold: true, "PillText");
			((TMP_Text)val).characterSpacing = 3f;
			float num = ((TMP_Text)val).GetPreferredValues(text).x + 16f;
			float num2 = size + 10f;
			Image obj = Ui.Box((Transform)(object)parent, bg, "Pill", round: true, num2 / 40f);
			((Graphic)obj).rectTransform.Place(x, y, num, num2);
			((Component)obj).transform.SetSiblingIndex(((TMP_Text)val).transform.GetSiblingIndex());
			((TMP_Text)val).rectTransform.Place(x, y, num, num2);
			return num;
		}

		public static float Card(RectTransform parent, float x, float y, float w, float h, string title)
		{
			//IL_0001: 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)
			((Graphic)Ui.Box((Transform)(object)parent, Theme.Surface, "Card", round: true, 0.7f)).rectTransform.Place(x, y, w, h);
			if (string.IsNullOrEmpty(title))
			{
				return 0f;
			}
			TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, title.ToUpperInvariant(), 14f, Theme.Muted, (TextAlignmentOptions)513, bold: true, "CardTitle");
			((TMP_Text)obj).characterSpacing = 4f;
			((TMP_Text)obj).rectTransform.Place(x + 20f, y + 14f, w - 40f, 20f);
			return 46f;
		}

		private static void Empty(RectTransform parent, float x, float y, float w, float h, string text)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, text, 16f, Theme.Faint, (TextAlignmentOptions)514);
			((TMP_Text)obj).fontStyle = (FontStyles)2;
			((TMP_Text)obj).rectTransform.Place(x, y, w, h);
		}

		private static string PlayerName(PlayerStats p)
		{
			if (!p.IsUnknown)
			{
				return p.Name;
			}
			return Loc.T("unknown");
		}

		private static void NameCell(RectTransform parent, float x, float y, float w, float h, PlayerStats p, float size, params (string text, Color bg)[] badges)
		{
			//IL_0026: 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_0043: 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_00d0: 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_00f8: 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)
			float num = size * 0.55f;
			Dot(parent, x, y + (h - num) / 2f, num, Theme.Player(p.Order, p.IsUnknown));
			TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, PlayerName(p), size, p.IsUnknown ? Theme.Muted : Theme.Text, (TextAlignmentOptions)513, !p.IsUnknown);
			float num2 = Mathf.Min(((TMP_Text)obj).GetPreferredValues(((TMP_Text)obj).text).x + 2f, w - num - 12f);
			((TMP_Text)obj).rectTransform.Place(x + num + 10f, y, num2, h);
			float num3 = x + num + 10f + num2 + 8f;
			for (int i = 0; i < badges.Length; i++)
			{
				var (text, bg) = badges[i];
				if (!(num3 > x + w - 40f))
				{
					num3 += Pill(parent, num3, y + (h - 22f) / 2f, text, bg, Theme.Hex("101114"), 11f) + 6f;
					continue;
				}
				break;
			}
		}

		public static void Header(RectTransform parent, float w, LevelStats level, string kicker)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			Logo(parent, 20f, 18f, 40f);
			TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, "BLACK BOX <size=60%><color=" + Theme.Rich(Theme.Accent) + ">REBORN</color></size>", 36f, Theme.Text, (TextAlignmentOptions)513, bold: true, "Title").Display();
			((TMP_Text)obj).characterSpacing = 3f;
			((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
			((TMP_Text)obj).rectTransform.Place(74f, 10f, 420f, 38f);
			List<string> list = new List<string>();
			if (!string.IsNullOrEmpty(kicker))
			{
				list.Add(kicker);
			}
			if (level != null)
			{
				list.Add(Loc.T("level.n", level.Number));
				list.Add(level.LevelName);
				list.Add(Format.Duration(level.Duration));
			}
			TextMeshProUGUI obj2 = Ui.Label((Transform)(object)parent, string.Join("  ·  ", list), 15f, Theme.Muted, (TextAlignmentOptions)513, bold: false, "Subtitle");
			float num = 74f;
			if (level != null && !level.Finished)
			{
				bool flag = Mathf.FloorToInt(Time.unscaledTime * 1.6f) % 2 == 0;
				Dot(parent, num, 50f, 9f, flag ? Theme.Bad : Theme.Hex("5A1E1F"));
				TextMeshProUGUI val = Ui.Label((Transform)(object)parent, Loc.T("live"), 13f, Theme.Bad, (TextAlignmentOptions)513, bold: true, "Live");
				((TMP_Text)val).characterSpacing = 3f;
				((TMP_Text)val).rectTransform.Place(num + 15f, 44f, 120f, 20f);
				num += 22f + ((TMP_Text)val).GetPreferredValues(((TMP_Text)val).text).x;
			}
			((TMP_Text)obj2).rectTransform.Place(num, 44f, w - num - 300f, 20f);
		}

		public static void Kpis(RectTransform parent, float x, float y, float w, float h, IList<(string label, string value, Color color, string sub)> items)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			float num = (w - 14f * (float)(items.Count - 1)) / (float)items.Count;
			for (int i = 0; i < items.Count; i++)
			{
				(string label, string value, Color color, string sub) tuple = items[i];
				string item = tuple.label;
				string item2 = tuple.value;
				Color item3 = tuple.color;
				string item4 = tuple.sub;
				float num2 = x + (float)i * (num + 14f);
				((Graphic)Ui.Box((Transform)(object)parent, Theme.Surface, "Kpi", round: true, 0.7f)).rectTransform.Place(num2, y, num, h);
				((Graphic)Ui.Box((Transform)(object)parent, item3, "KpiAccent", round: true, 0.1f)).rectTransform.Place(num2 + 20f, y + 18f, 18f, 4f);
				TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, item.ToUpperInvariant(), 13f, Theme.Muted, (TextAlignmentOptions)513, bold: true);
				((TMP_Text)obj).characterSpacing = 4f;
				((TMP_Text)obj).rectTransform.Place(num2 + 20f + 26f, y + 10f, num - 40f - 26f, 20f);
				TextMeshProUGUI obj2 = Ui.Label((Transform)(object)parent, item2, 50f, item3, (TextAlignmentOptions)513, bold: true, "KpiValue").Display();
				((TMP_Text)obj2).enableAutoSizing = true;
				((TMP_Text)obj2).fontSizeMin = 24f;
				((TMP_Text)obj2).fontSizeMax = 50f;
				((TMP_Text)obj2).characterSpacing = 1f;
				((TMP_Text)obj2).rectTransform.Place(num2 + 20f, y + 32f, num - 40f, 48f);
				((TMP_Text)Ui.Label((Transform)(object)parent, item4, 14f, Theme.Muted, (TextAlignmentOptions)513)).rectTransform.Place(num2 + 20f, y + h - 34f, num - 40f, 20f);
			}
		}

		public static void LevelKpis(RectTransform parent, float x, float y, float w, float h, LevelStats level)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			Kpis(parent, x, y, w, h, new(string, string, Color, string)[4]
			{
				(Loc.T("kpi.extracted"), Format.Dollars(level.ValueExtracted), Theme.Good, Loc.T("kpi.extracted.sub", Format.Percent(level.ExtractedPercent), level.ItemsExtracted)),
				(Loc.T("kpi.lost"), Format.Loss(level.ValueLost), (level.ValueLost > 0.5f) ? Theme.Bad : Theme.Text, Loc.T("kpi.lost.sub", level.ItemsDestroyed, level.Hits)),
				(Loc.T("kpi.discovered"), $"{level.ItemsDiscovered}<size=60%><color={Theme.Rich(Theme.Muted)}> / {level.ItemsSpawned}</color></size>", Theme.Warn, Loc.T("kpi.discovered.sub", level.ItemsSpawned)),
				(Loc.T("kpi.remaining"), Format.Dollars(level.ValueRemaining), level.Finished ? Theme.Muted : Theme.Info, level.Finished ? Loc.T("kpi.remaining.done") : Loc.T("kpi.remaining.sub"))
			});
		}

		public static void ValueBar(RectTransform parent, float x, float y, float w, LevelStats level)
		{
			//IL_004d: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			float num = (level.Finished ? 0f : level.ValueRemaining);
			float num2 = Mathf.Max(1f, level.ValueExtracted + level.ValueLost + num);
			(string, float, Color)[] array = new(string, float, Color)[3]
			{
				(Loc.T("bar.extracted"), level.ValueExtracted, Theme.Good),
				(Loc.T("bar.lost"), level.ValueLost, Theme.Bad),
				(Loc.T("bar.remaining"), num, Theme.Remaining)
			};
			float num3 = x;
			(string, float, Color)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				var (text, num4, color) = array2[i];
				Dot(parent, num3, y + 5f, 10f, color);
				TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, text + " <color=" + Theme.Rich(Theme.Text) + ">" + Format.Percent(num4 / num2 * 100f) + "%</color>", 14f, Theme.Muted, (TextAlignmentOptions)513);
				float num5 = ((TMP_Text)obj).GetPreferredValues(((TMP_Text)obj).text).x + 4f;
				((TMP_Text)obj).rectTransform.Place(num3 + 16f, y, num5, 20f);
				num3 += 16f + num5 + 22f;
			}
			float y2 = y + 28f;
			((Graphic)Ui.Box((Transform)(object)parent, Theme.Track, "BarTrack", round: true, 0.3f)).rectTransform.Place(x, y2, w, 12f);
			float num6 = x;
			array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				(string, float, Color) tuple2 = array2[i];
				float item = tuple2.Item2;
				Color item2 = tuple2.Item3;
				float num7 = w * item / num2;
				if (!(num7 < 1f))
				{
					((Graphic)Ui.Box((Transform)(object)parent, item2, "BarSegment", round: true, 0.3f)).rectTransform.Place(num6, y2, num7, 12f);
					num6 += num7;
				}
			}
		}

		public static void DamageRanking(RectTransform parent, float x, float y, float w, float h, LevelStats level)
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			float num = Card(parent, x, y, w, h, Loc.T("sec.damage"));
			List<PlayerStats> list = (from p in level.Players.Values
				where p.ValueBroken > 0.5f
				orderby p.ValueBroken descending
				select p).ToList();
			if (list.Count == 0)
			{
				Empty(parent, x, y + num, w, h - num - 10f, Loc.T("sec.damage.empty"));
				return;
			}
			float valueBroken = list[0].ValueBroken;
			int num2 = Mathf.Max(1, Mathf.FloorToInt((h - num - 10f) / 40f));
			float num3 = x + 20f;
			float num4 = w - 40f;
			for (int num5 = 0; num5 < Mathf.Min(num2, list.Count); num5++)
			{
				PlayerStats playerStats = list[num5];
				float num6 = y + num + (float)num5 * 40f;
				NameCell(parent, num3, num6, num4 * 0.36f, 40f, playerStats, 17f);
				float x2 = num3 + num4 * 0.38f;
				float num7 = num4 * 0.3f;
				((Graphic)Ui.Box((Transform)(object)parent, Theme.Track, "Track", round: true, 0.2f)).rectTransform.Place(x2, num6 + 20f - 4f, num7, 8f);
				((Graphic)Ui.Box((Transform)(object)parent, Theme.Bad, "Fill", round: true, 0.2f)).rectTransform.Place(x2, num6 + 20f - 4f, Mathf.Max(8f, num7 * playerStats.ValueBroken / valueBroken), 8f);
				((TMP_Text)Ui.Label((Transform)(object)parent, $"{Format.Loss(playerStats.ValueBroken)} <size=75%><color={Theme.Rich(Theme.Muted)}>· {playerStats.Hits}</color></size>", 17f, Theme.Bad, (TextAlignmentOptions)516, bold: true)).rectTransform.Place(num3 + num4 * 0.7f, num6, num4 * 0.3f, 40f);
			}
		}

		public static void Feed(RectTransform parent, float x, float y, float w, float h, LevelStats level)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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)
			float num = Card(parent, x, y, w, h, Loc.T("sec.feed"));
			if (level.Feed.Count == 0)
			{
				Empty(parent, x, y + num, w, h - num - 10f, Loc.T("sec.feed.empty"));
				return;
			}
			int count = Mathf.Max(1, Mathf.FloorToInt((h - num - 10f) / 36f));
			float num2 = x + 20f;
			float num3 = w - 40f;
			List<FeedEvent> list = Enumerable.Reverse(level.Feed).Take(count).ToList();
			for (int i = 0; i < list.Count; i++)
			{
				FeedEvent feedEvent = list[i];
				float num4 = y + num + (float)i * 36f;
				var (text, text2, color) = Describe(feedEvent);
				Dot(parent, num2, num4 + 18f - 4f, 8f, color);
				((TMP_Text)Ui.Label((Transform)(object)parent, text, 16f, Theme.Text, (TextAlignmentOptions)513)).rectTransform.Place(num2 + 18f, num4, num3 * 0.62f, 36f);
				((TMP_Text)Ui.Label((Transform)(object)parent, text2, 16f, color, (TextAlignmentOptions)516, bold: true)).rectTransform.Place(num2 + num3 * 0.6f, num4, num3 * 0.24f, 36f);
				((TMP_Text)Ui.Label((Transform)(object)parent, Format.Ago(Time.time - feedEvent.Time), 13f, Theme.Faint, (TextAlignmentOptions)516)).rectTransform.Place(num2 + num3 * 0.84f, num4, num3 * 0.16f, 36f);
			}
		}

		internal static (string text, string value, Color color) Describe(FeedEvent e)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			string text = "<b>" + e.Who + "</b>";
			return e.Kind switch
			{
				FeedKind.Break => (text: Loc.T("feed.break", text, e.What), value: Format.Loss(e.Value), color: Theme.Warn), 
				FeedKind.Destroy => (text: Loc.T("feed.destroy", text, e.What), value: Format.Loss(e.Value), color: Theme.Bad), 
				FeedKind.Fall => (text: (e.Who == null || e.Who == Loc.T("unknown")) ? Loc.T("feed.fall", e.What) : Loc.T("feed.fall.by", text, e.What), value: Format.Loss(e.Value), color: Theme.Bad), 
				FeedKind.Extract => (text: (e.Count > 1) ? Loc.T("feed.extract.n", e.Count) : Loc.T("feed.extract", e.What), value: "+" + Format.Dollars(e.Value), color: Theme.Good), 
				_ => (text: string.IsNullOrEmpty(e.What) ? Loc.T("feed.death", text) : Loc.T("feed.death.by", text, e.What), value: "", color: Theme.Info), 
			};
		}

		private static string Header(Col c)
		{
			return c switch
			{
				Col.Player => Loc.T("col.player"), 
				Col.Hauled => Loc.T("col.hauled"), 
				Col.Broken => Loc.T("col.broken"), 
				Col.Destroyed => Loc.T("col.destroyed"), 
				Col.Hits => Loc.T("col.hits"), 
				Col.Hurt => Loc.T("col.hurt"), 
				_ => Loc.T("col.deaths"), 
			};
		}

		public static float PlayerTable(RectTransform parent, float x, float y, float w, float maxH, IList<PlayerStats> players, string selectedId, bool compact, int first = 0, int count = int.MaxValue)
		{
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			(Col, float)[] array = (compact ? CompactColumns : FullColumns);
			List<PlayerStats> source = players.Where((PlayerStats p) => !p.IsUnknown).ToList();
			PlayerStats playerStats = (from p in source
				where p.ValueHauled > 0.5f
				orderby p.ValueHauled descending
				select p).FirstOrDefault();
			PlayerStats playerStats2 = (from p in source
				where p.ValueBroken > 0.5f
				orderby p.ValueBroken descending
				select p).FirstOrDefault();
			List<PlayerStats> list = players.Skip(first).Take(count).ToList();
			float num = Mathf.Clamp((maxH - 44f - 10f) / (float)Mathf.Max(1, list.Count), 30f, 46f);
			float num2 = 44f + num * (float)list.Count + 10f;
			Card(parent, x, y, w, num2, null);
			float num3 = x + 20f;
			float num4 = w - 40f;
			float num5 = num3;
			(Col, float)[] array2 = array;
			for (int num6 = 0; num6 < array2.Length; num6++)
			{
				(Col, float) tuple = array2[num6];
				Col item = tuple.Item1;
				float item2 = tuple.Item2;
				TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, Header(item).ToUpperInvariant(), 13f, Theme.Muted, (TextAlignmentOptions)((item == Col.Player) ? 513 : 516), bold: true);
				((TMP_Text)obj).characterSpacing = 3f;
				((TMP_Text)obj).rectTransform.Place(num5, y + 12f, num4 * item2, 24f);
				num5 += num4 * item2;
			}
			((Graphic)Ui.Box((Transform)(object)parent, Theme.Border, "Rule", round: false)).rectTransform.Place(num3, y + 44f - 2f, num4, 1f);
			for (int num7 = 0; num7 < list.Count; num7++)
			{
				PlayerStats playerStats3 = list[num7];
				float num8 = y + 44f + (float)num7 * num;
				if (playerStats3.Id == selectedId)
				{
					((Graphic)Ui.Box((Transform)(object)parent, Theme.SurfaceHi, "Selected", round: true, 0.3f)).rectTransform.Place(x + 6f, num8 + 2f, w - 12f, num - 4f);
					((Graphic)Ui.Box((Transform)(object)parent, Theme.Accent, "SelectedBar", round: true, 0.1f)).rectTransform.Place(x + 6f, num8 + 8f, 4f, num - 16f);
				}
				List<(string, Color)> list2 = new List<(string, Color)>();
				if (playerStats3 == playerStats)
				{
					list2.Add((Loc.T("badge.mvp"), Theme.Good));
				}
				if (playerStats3 == playerStats2)
				{
					list2.Add((Loc.T("badge.butter"), Theme.Bad));
				}
				num5 = num3;
				array2 = array;
				for (int num6 = 0; num6 < array2.Length; num6++)
				{
					(Col, float) tuple2 = array2[num6];
					Col item3 = tuple2.Item1;
					float item4 = tuple2.Item2;
					float num9 = num4 * item4;
					if (item3 == Col.Player)
					{
						NameCell(parent, num5, num8, num9 - 8f, num, playerStats3, 17f, list2.ToArray());
					}
					else
					{
						var (text, color) = Cell(item3, playerStats3);
						((TMP_Text)Ui.Label((Transform)(object)parent, text, 17f, color, (TextAlignmentOptions)516, item3 == Col.Hauled || item3 == Col.Broken)).rectTransform.Place(num5, num8, num9, num);
					}
					num5 += num9;
				}
			}
			return num2;
		}

		private static (string, Color) Cell(Col col, PlayerStats p)
		{
			//IL_0040: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			return col switch
			{
				Col.Hauled => (Format.Dollars(p.ValueHauled), (p.ValueHauled > 0.5f) ? Theme.Good : Theme.Faint), 
				Col.Broken => (Format.Loss(p.ValueBroken), (p.ValueBroken > 0.5f) ? Theme.Bad : Theme.Faint), 
				Col.Destroyed => (p.ItemsDestroyed.ToString(), (p.ItemsDestroyed > 0) ? Theme.Bad : Theme.Faint), 
				Col.Hits => (p.Hits.ToString(), (p.Hits > 0) ? Theme.Text : Theme.Faint), 
				Col.Hurt => ((p.DamageTaken > 0) ? $"{p.DamageTaken} HP" : "0", (p.DamageTaken > 0) ? Theme.Warn : Theme.Faint), 
				_ => (p.Deaths.ToString(), (p.Deaths > 0) ? Theme.Text : Theme.Faint), 
			};
		}

		public static void ItemDetail(RectTransform parent, float x, float y, float w, float h, PlayerStats p)
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			string text = ((p == null) ? "" : PlayerName(p));
			float num = Card(parent, x, y, w, h, Loc.T("sec.items", text));
			List<ItemDamage> list = p?.ItemsByLoss.ToList() ?? new List<ItemDamage>();
			if (list.Count == 0)
			{
				Empty(parent, x, y + num, w, h - num - 10f, Loc.T("sec.items.empty"));
				return;
			}
			int num2 = Mathf.Max(1, Mathf.FloorToInt((h - num - 8f) / 32f));
			int num3 = ((!(w > 700f)) ? 1 : 2);
			int num4 = num2;
			int num5 = Mathf.Min(list.Count, num4 * num3);
			if (num5 < list.Count)
			{
				num5 = Mathf.Max(0, num5 - 1);
			}
			float num6 = (w - 40f - (float)(num3 - 1) * 30f) / (float)num3;
			for (int i = 0; i < num5; i++)
			{
				ItemDamage itemDamage = list[i];
				int num7 = i / num4;
				float num8 = x + 20f + (float)num7 * (num6 + 30f);
				float num9 = y + num + (float)(i % num4) * 32f;
				((TMP_Text)Ui.Label((Transform)(object)parent, itemDamage.ItemName, 16f, Theme.Text, (TextAlignmentOptions)513)).rectTransform.Place(num8, num9, num6 * 0.5f, 32f);
				if (itemDamage.Destroyed)
				{
					Pill(parent, num8 + num6 * 0.5f, num9 + 6f, Loc.T("destroyed"), Theme.Hex("3A1517"), Theme.Bad, 10f);
				}
				((TMP_Text)Ui.Label((Transform)(object)parent, Format.Loss(itemDamage.ValueLost), 16f, Theme.Bad, (TextAlignmentOptions)516, bold: true)).rectTransform.Place(num8 + num6 * 0.7f, num9, num6 * 0.3f, 32f);
			}
			if (num5 < list.Count)
			{
				int num10 = num5 / num4;
				((TMP_Text)Ui.Label((Transform)(object)parent, Loc.T("more", list.Count - num5), 14f, Theme.Muted, (TextAlignmentOptions)513)).rectTransform.Place(x + 20f + (float)num10 * (num6 + 30f), y + num + (float)(num5 % num4) * 32f, num6, 32f);
			}
		}

		public static void RunKpis(RectTransform parent, float x, float y, float w, float h, RunStats run)
		{
			//IL_00a0: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			float num = run.Levels.Sum((LevelStats l) => l.ValueSpawned);
			float value = ((num > 0f) ? (run.ValueExtracted / num * 100f) : 0f);
			LevelStats levelStats = run.Levels.OrderByDescending((LevelStats l) => l.ValueExtracted).First();
			Kpis(parent, x, y, w, h, new(string, string, Color, string)[4]
			{
				(Loc.T("run.extracted"), Format.Dollars(run.ValueExtracted), Theme.Good, Loc.T("kpi.extracted.sub", Format.Percent(value), run.Levels.Sum((LevelStats l) => l.ItemsExtracted))),
				(Loc.T("run.lost"), Format.Loss(run.ValueLost), (run.ValueLost > 0.5f) ? Theme.Bad : Theme.Text, Loc.T("kpi.lost.sub", run.Levels.Sum((LevelStats l) => l.ItemsDestroyed), run.Levels.Sum((LevelStats l) => l.Hits))),
				(Loc.T("run.levels"), run.Levels.Count.ToString(), Theme.Accent, Loc.T("run.best", levelStats.Number, Format.Dollars(levelStats.ValueExtracted))),
				(Loc.T("run.time"), Format.Duration(run.Duration), Theme.Info, Loc.T("run.avg", Format.Duration(run.Duration / (float)Mathf.Max(1, run.Levels.Count))))
			});
		}

		public static void LevelsTable(RectTransform parent, float x, float y, float w, float h, RunStats run)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			float num = Card(parent, x, y, w, h, Loc.T("sec.levels"));
			(string, float, TextAlignmentOptions)[] array = new(string, float, TextAlignmentOptions)[6]
			{
				("#", 0.06f, (TextAlignmentOptions)513),
				(Loc.T("col.level"), 0.33f, (TextAlignmentOptions)513),
				(Loc.T("col.hauled"), 0.17f, (TextAlignmentOptions)516),
				(Loc.T("col.broken"), 0.15f, (TextAlignmentOptions)516),
				(Loc.T("col.found"), 0.15f, (TextAlignmentOptions)516),
				(Loc.T("col.time"), 0.14f, (TextAlignmentOptions)516)
			};
			float num2 = x + 20f;
			float num3 = w - 40f;
			float num4 = num2;
			(string, float, TextAlignmentOptions)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				(string, float, TextAlignmentOptions) tuple = array2[i];
				string item = tuple.Item1;
				float item2 = tuple.Item2;
				TextAlignmentOptions item3 = tuple.Item3;
				TextMeshProUGUI obj = Ui.Label((Transform)(object)parent, item.ToUpperInvariant(), 12f, Theme.Faint, item3, bold: true);
				((TMP_Text)obj).characterSpacing = 3f;
				((TMP_Text)obj).rectTransform.Place(num4, y + num - 4f, num3 * item2, 20f);
				num4 += num3 * item2;
			}
			int num5 = Mathf.Max(1, Mathf.FloorToInt((h - num - 24f) / 34f));
			List<LevelStats> list = run.Levels.Skip(Mathf.Max(0, run.Levels.Count - num5)).ToList();
			for (int j = 0; j < list.Count; j++)
			{
				LevelStats levelStats = list[j];
				float y2 = y + num + 20f + (float)j * 34f;
				(string, Color, bool)[] array3 = new(string, Color, bool)[6]
				{
					(levelStats.Number.ToString(), Theme.Muted, true),
					(levelStats.LevelName + (levelStats.Finished ? "" : ("  <color=" + Theme.Rich(Theme.Bad) + ">●</color>")), Theme.Text, false),
					(Format.Dollars(levelStats.ValueExtracted), Theme.Good, true),
					(Format.Loss(levelStats.ValueLost), (levelStats.ValueLost > 0.5f) ? Theme.Bad : Theme.Faint, false),
					($"{levelStats.ItemsDiscovered}/{levelStats.ItemsSpawned}", Theme.Warn, false),
					(Format.Duration(levelStats.Duration), Theme.Muted, false)
				};
				num4 = num2;
				for (int k = 0; k < array.Length; k++)
				{
					((TMP_Text)Ui.Label((Transform)(object)parent, array3[k].Item1, 16f, array3[k].Item2, array[k].Item3, array3[k].Item3)).rectTransform.Place(num4, y2, num3 * array[k].Item2, 34f);
					num4 += num3 * array[k].Item2;
				}
			}
		}

		public static void RunPlayers(RectTransform parent, float x, float y, float w, float h, List<PlayerStats> players)
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
			float num = Card(parent, x, y, w, h, Loc.T("sec.runplayers"));
			if (players.Count == 0)
			{
				Empty(parent, x, y + num, w, h - num - 10f, Loc.T("run.none"));
				return;
			}
			int num2 = Mathf.Max(1, Mathf.FloorToInt((h - num - 8f) / 52f));
			float num3 = x + 20f;
			float num4 = w - 40f;
			float num5 = Mathf.Max(1f, players.Max((PlayerStats p) => p.ValueHauled));
			for (int num6 = 0; num6 < Mathf.Min(num2, players.Count); num6++)
			{
				PlayerStats playerStats = players[num6];
				float num7 = y + num + (float)num6 * 52f;
				NameCell(parent, num3, num7, num4 * 0.55f, 26f, playerStats, 16f);
				((TMP_Text)Ui.Label((Transform)(object)parent, Format.Dollars(playerStats.ValueHauled), 16f, Theme.Good, (TextAlignmentOptions)516, bold: true)).rectTransform.Place(num3 + num4 * 0.5f, num7, num4 * 0.5f, 26f);
				((Graphic)Ui.Box((Transform)(object)parent, Theme.Track, "Track", round: true, 0.15f)).rectTransform.Place(num3, num7 + 30f, num4, 5f);
				((Graphic)Ui.Box((Transform)(object)parent, Theme.Good, "Fill", round: true, 0.15f)).rectTransform.Place(num3, num7 + 30f, Mathf.Max(5f, num4 * playerStats.ValueHauled / num5), 5f);
				string text = ((playerStats.Deaths > 0) ? string.Format("  ·  {0} {1}", playerStats.Deaths, Loc.T("col.deaths").ToLowerInvariant()) : "");
				((TMP_Text)Ui.Label((Transform)(object)parent, Format.Loss(playerStats.ValueBroken) + text, 12f, Theme.Muted, (TextAlignmentOptions)516)).rectTransform.Place(num3 + num4 * 0.4f, num7 + 34f, num4 * 0.6f, 16f);
			}
		}
	}
}
namespace BlackBoxReborn.Stats
{
	internal enum CauseKind
	{
		None,
		Enemy,
		Hazard,
		PlayerItem,
		Fall
	}
	internal struct Cause
	{
		public CauseKind Kind;

		public string Name;

		public PlayerAvatar Player;
	}
	internal static class DestroyCauses
	{
		public const float FallHeight = -50f;

		public static HurtCollider ActiveHurt;

		private static readonly Dictionary<int, Cause> Pending = new Dictionary<int, Cause>();

		public static void Clear()
		{
			Pending.Clear();
		}

		public static void Record(PhysGrabObjectImpactDetector detector)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)detector) && Object.op_Implicit((Object)(object)detector.valuableObject))
			{
				Pending[((Object)detector.valuableObject).GetInstanceID()] = Resolve(((Component)detector).transform.position.y);
			}
		}

		public static Cause Take(int valuableId, float lastY)
		{
			if (Pending.TryGetValue(valuableId, out var value))
			{
				Pending.Remove(valuableId);
				return value;
			}
			if (!(lastY < -50f))
			{
				return default(Cause);
			}
			return new Cause
			{
				Kind = CauseKind.Fall
			};
		}

		private static Cause Resolve(float y)
		{
			HurtCollider activeHurt = ActiveHurt;
			if (Object.op_Implicit((Object)(object)activeHurt))
			{
				if (Object.op_Implicit((Object)(object)activeHurt.enemyHost))
				{
					return new Cause
					{
						Kind = CauseKind.Enemy,
						Name = Tracker.EnemyName(activeHurt.enemyHost)
					};
				}
				ItemAttributes componentInParent = ((Component)activeHurt).GetComponentInParent<ItemAttributes>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					PhysGrabObject component = ((Component)componentInParent).GetComponent<PhysGrabObject>();
					return new Cause
					{
						Kind = CauseKind.PlayerItem,
						Name = (Object.op_Implicit((Object)(object)componentInParent.item) ? componentInParent.item.itemName : ((Object)componentInParent).name),
						Player = (Object.op_Implicit((Object)(object)component) ? component.lastPlayerGrabbing : null)
					};
				}
				return new Cause
				{
					Kind = CauseKind.Hazard,
					Name = Loc.T("cause.hazard")
				};
			}
			if (!(y < -50f))
			{
				return default(Cause);
			}
			return new Cause
			{
				Kind = CauseKind.Fall
			};
		}
	}
	internal sealed class ItemDamage
	{
		public string ItemName;

		public float ValueLost;

		public bool Destroyed;
	}
	internal sealed class PlayerStats
	{
		public const string UnknownId = "?";

		public string Id;

		public string Name;

		public int Order;

		public float ValueHauled;

		public float ItemsHauled;

		public float ValueBroken;

		public int Hits;

		public int ItemsDestroyed;

		public int DamageTaken;

		public int Deaths;

		public readonly Dictionary<int, ItemDamage> Items = new Dictionary<int, ItemDamage>();

		public bool IsUnknown => Id == "?";

		public bool HasActivity
		{
			get
			{
				if (!(ValueHauled > 0f) && !(ValueBroken > 0f) && Hits <= 0 && DamageTaken <= 0)
				{
					return Deaths > 0;
				}
				return true;
			}
		}

		public IEnumerable<ItemDamage> ItemsByLoss => Items.Values.OrderByDescending((ItemDamage i) => i.ValueLost);

		public void AddFrom(PlayerStats other)
		{
			ValueHauled += other.ValueHauled;
			ItemsHauled += other.ItemsHauled;
			ValueBroken += other.ValueBroken;
			Hits += other.Hits;
			ItemsDestroyed += other.ItemsDestroyed;
			DamageTaken += other.DamageTaken;
			Deaths += other.Deaths;
		}
	}
	internal enum FeedKind
	{
		Break,
		Destroy,
		Extract,
		Death,
		Fall
	}
	internal sealed class FeedEvent
	{
		public FeedKind Kind;

		public string Who;

		public string What;

		public float Value;

		public int Count;

		public float Time;
	}
	internal sealed class LevelStats
	{
		public int Number;

		public string LevelName;

		public float StartTime;

		public float EndTime = -1f;

		public float ValueSpawned;

		public int ItemsSpawned;

		public float ValueExtracted;

		public int ItemsExtracted;

		public float ValueLost;

		public int ItemsDestroyed;

		public int ItemsDiscovered;

		public int Hits;

		public int Deaths;

		public float ValueRemaining;

		public readonly Dictionary<string, PlayerStats> Players = new Dictionary<string, PlayerStats>();

		public readonly List<FeedEvent> Feed = new List<FeedEvent>();

		public bool Finished => EndTime >= 0f;

		public float Duration => (Finished ? EndTime : Time.time) - StartTime;

		public float ExtractedPercent
		{
			get
			{
				if (!(ValueSpawned > 0f))
				{
					return 0f;
				}
				return Mathf.Clamp01(ValueExtracted / ValueSpawned) * 100f;
			}
		}

		public IEnumerable<PlayerStats> RankedPlayers => from p in Players.Values
			where !p.IsUnknown || p.HasActivity
			orderby p.IsUnknown, p.ValueHauled descending, p.Order
			select p;
	}
	internal sealed class RunStats
	{
		public readonly List<LevelStats> Levels = new List<LevelStats>();

		public LevelStats Current
		{
			get
			{
				if (Levels.Count <= 0)
				{
					return null;
				}
				return Levels[Levels.Count - 1];
			}
		}

		public float ValueExtracted => Levels.Sum((LevelStats l) => l.ValueExtracted);

		public float ValueLost => Levels.Sum((LevelStats l) => l.ValueLost);

		public float Duration => Levels.Sum((LevelStats l) => l.Duration);

		public List<PlayerStats> Totals()
		{
			Dictionary<string, PlayerStats> dictionary = new Dictionary<string, PlayerStats>();
			foreach (LevelStats level in Levels)
			{
				foreach (PlayerStats value2 in level.Players.Values)
				{
					if (!dictionary.TryGetValue(value2.Id, out var value))
					{
						value = new PlayerStats
						{
							Id = value2.Id,
							Name = value2.Name,
							Order = value2.Order
						};
						dictionary[value2.Id] = value;
					}
					value.Name = value2.Name;
					value.AddFrom(value2);
				}
			}
			return (from p in dictionary.Values
				where !p.IsUnknown || p.HasActivity
				orderby p.IsUnknown, p.ValueHauled descending, p.Order
				select p).ToList();
		}
	}
	internal static class Tracker
	{
		private sealed class TrackedValuable
		{
			public ValuableObject Obj;

			public int Id;

			public string Name;

			public bool Surplus;

			public bool Destroyed;

			public bool Absorbed;

			public bool Done;

			public float AbsorbedValue;

			public float Original;

			public readonly Dictionary<string, float> Carry = new Dictionary<string, float>();

			public Seen Last;
		}

		private sealed class TrackedBox
		{
			public ItemValuableBox Box;

			public readonly List<TrackedValuable> Contents = new List<TrackedValuable>();

			public readonly Dictionary<string, float> Carry = new Dictionary<string, float>();

			public Seen Last;
		}

		private struct Seen
		{
			public float Value;

			public bool Dead;

			public float Y;

			public string Toucher;

			public string Ever;

			public float EverTime;
		}

		private const float DestroyThreshold = 0.15f;

		private const float CartCarryWeight = 0.5f;

		private const int FeedSize = 8;

		private const float SpawnGrace = 30f;

		private static readonly Dictionary<int, TrackedValuable> Valuables = new Dictionary<int, TrackedValuable>();

		private static readonly Dictionary<int, TrackedBox> Boxes = new Dictionary<int, TrackedBox>();

		private static readonly Dictionary<string, int> LastHealth = new Dictionary<string, int>();

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

		private static readonly Dictionary<string, int> Orders = new Dictionary<string, int>();

		private static LevelGenerator levelGenerator;

		private static LevelGenerator staleGenerator;

		private static string saveFile;

		private static bool startTimeFixed;

		private static float nextHealthPoll;

		private static float nextRemainingCalc;

		private static float nextRosterSync;

		private const float RecentTouchSeconds = 10f;

		private const float ContactDistance = 1.5f;

		public static RunStats Run { get; private set; } = new RunStats();

		public static int Revision { get; private set; }

		public static LevelStats OpenLevel
		{
			get
			{
				LevelStats current = Run.Current;
				if (current == null || current.Finished)
				{
					return null;
				}
				return current;
			}
		}

		public static void Tick()
		{
			if (!SemiFunc.RunIsLevel())
			{
				staleGenerator = LevelGenerator.Instance;
				CloseLevel();
				return;
			}
			LevelStats levelStats = EnsureLevel();
			if (levelStats == null)
			{
				return;
			}
			if (!startTimeFixed && Object.op_Implicit((Object)(object)levelGenerator) && levelGenerator.Generated)
			{
				levelStats.StartTime = Time.time;
				startTimeFixed = true;
			}
			Observe(levelStats, Time.deltaTime);
			if (Time.time >= nextRosterSync)
			{
				nextRosterSync = Time.time + 1f;
				SyncRoster(levelStats);
			}
			if (Time.time >= nextHealthPoll)
			{
				nextHealthPoll = Time.time + 0.2f;
				PollHealth(levelStats);
			}
			if (Time.time >= nextRemainingCalc)
			{
				nextRemainingCalc = Time.time + 0.25f;
				float num = ComputeRemaining();
				if (!Mathf.Approximately(num, levelStats.ValueRemaining))
				{
					levelStats.ValueRemaining = num;
					Revision++;
				}
			}
		}

		private static LevelStats EnsureLevel()
		{
			LevelGenerator instance = LevelGenerator.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)RunManager.instance) || (Object)(object)instance == (Object)(object)staleGenerator)
			{
				return null;
			}
			if ((Object)(object)instance == (Object)(object)levelGenerator)
			{
				return OpenLevel;
			}
			CloseLevel();
			string text = (Object.op_Implicit((Object)(object)StatsManager.instance) ? StatsManager.instance.saveFileCurrent : null);
			int num = RunManager.instance.levelsCompleted + 1;
			if (Run.Current != null && (num <= Run.Current.Number || text != saveFile))
			{
				Run = new RunStats();
				Orders.Clear();
			}
			saveFile = text;
			levelGenerator = instance;
			startTimeFixed = false;
			DestroyCauses.Clear();
			Valuables.Clear();
			Boxes.Clear();
			LastHealth.Clear();
			LevelStats levelStats = new LevelStats
			{
				Number = num,
				LevelName = LevelName(RunManager.instance.levelCurrent),
				StartTime = Time.time
			};
			Run.Levels.Add(levelStats);
			SyncRoster(levelStats);
			Revision++;
			Plugin.Log.LogInfo((object)$"Nivel {levelStats.Number} ({levelStats.LevelName}) empieza");
			return levelStats;
		}

		private static void CloseLevel()
		{
			LevelStats openLevel = OpenLevel;
			levelGenerator = null;
			if (openLevel != null)
			{
				openLevel.EndTime = Time.time;
				Valuables.Clear();
				Boxes.Clear();
				LastHealth.Clear();
				Revision++;
				Plugin.Log.LogInfo((object)($"Nivel {openLevel.Number} terminado: extraído {openLevel.ValueExtracted:0} de {openLevel.ValueSpawned:0}, " + $"perdido {openLevel.ValueLost:0} ({openLevel.ItemsDestroyed} destruidos), restante {openLevel.ValueRemaining:0}; " + $"cuadre {openLevel.ValueExtracted + openLevel.ValueLost + openLevel.ValueRemaining - openLevel.ValueSpawned:+0;-0;0}"));
			}
		}

		public static void OnValuableSpawned(ValuableObject valuable)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)valuable) || !SemiFunc.RunIsLevel())
			{
				return;
			}
			Scene scene = ((Component)valuable).gameObject.scene;
			if (((Scene)(ref scene)).IsValid())
			{
				LevelStats levelStats = EnsureLevel();
				if (levelStats != null)
				{
					Track(levelStats, valuable);
				}
			}
		}

		public static void OnDiscovered(ValuableObject valuable)
		{
			if (Object.op_Implicit((Object)(object)valuable) && !valuable.discovered)
			{
				LevelStats openLevel = OpenLevel;
				if (openLevel != null && Valuables.ContainsKey(((Object)valuable).GetInstanceID()))
				{
					openLevel.ItemsDiscovered++;
					Revision++;
				}
			}
		}

		public static void OnBreak(PhysGrabObjectImpactDetector detector, float valueLost)
		{
			ValuableObject val = (Object.op_Implicit((Object)(object)detector) ? detector.valuableObject : null);
			if (!Object.op_Implicit((Object)(object)val) || !SemiFunc.RunIsLevel())
			{
				return;
			}
			LevelStats levelStats = EnsureLevel();
			if (levelStats == null)
			{
				return;
			}
			TrackedValuable trackedValuable = Track(levelStats, val);
			if (!trackedValuable.Done && !trackedValuable.Destroyed)
			{
				float dollarValueCurrent = val.dollarValueCurrent;
				bool flag = dollarValueCurrent - valueLost < val.dollarValueOriginal * 0.15f && !SemiFunc.RunIsTutorial();
				float num = (flag ? dollarValueCurrent : Mathf.Min(valueLost, dollarValueCurrent));
				if (!(num <= 0f))
				{
					ApplyLoss(levelStats, trackedValuable, num, flag, BreakCulprits(levelStats, trackedValuable, detector.physGrabObject));
				}
			}
		}

		public static void OnDestroyedByImpactDetector(PhysGrabObjectImpactDetector detector)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			ValuableObject val = (Object.op_Implicit((Object)(object)detector) ? detector.valuableObject : null);
			LevelStats openLevel = OpenLevel;
			if (Object.op_Implicit((Object)(object)val) && openLevel != null && Valuables.TryGetValue(((Object)val).GetInstanceID(), out var value) && !value.Done && !value.Destroyed && !value.Absorbed)
			{
				Cause cause = DestroyCauses.Take(value.Id, ((Component)detector).transform.position.y);
				CausedDestroy(openLevel, value, val.dollarValueCurrent, cause, Culprits(openLevel, detector.physGrabObject));
			}
		}

		private static void CausedDestroy(LevelStats level, TrackedValuable tracked, float value, Cause cause, List<PlayerStats> touchers)
		{
			bool flag = touchers.TrueForAll((PlayerStats p) => p.IsUnknown);
			List<PlayerStats> list = new List<PlayerStats> { Player(level, "?") };
			Plugin.Log.LogInfo((object)($"{tracked.Name} (${value:0}) destruido sin golpe: causa={cause.Kind} {cause.Name} " + $"a los {Time.time - level.StartTime:0.0} s"));
			int num;
			switch (cause.Kind)
			{
			case CauseKind.Fall:
				num = 0;
				goto IL_00cb;
			case CauseKind.Hazard:
				num = 1;
				goto IL_00cb;
			case CauseKind.PlayerItem:
				if (Ready(cause.Player))
				{
					ApplyLoss(level, tracked, value, destroyed: true, new List<PlayerStats> { Player(level, cause.Player) }, cause.Player.playerName + " (" + cause.Name + ")");
					break;
				}
				goto case CauseKind.Enemy;
			case CauseKind.Enemy:
				ApplyLoss(level, tracked, value, destroyed: true, list, cause.Name);
				break;
			default:
				{
					ApplyLoss(level, tracked, value, destroyed: true, touchers);
					break;
				}
				IL_00cb:
				if (!flag || (startTimeFixed && !(Time.time - level.StartTime < 30f)))
				{
					if (num == 0)
					{
						ApplyLoss(level, tracked, value, destroyed: true, flag ? list : touchers, null, FeedKind.Fall);
						break;
					}
					if (num == 1)
					{
						goto case CauseKind.Enemy;
					}
				}
				Unspawn(level, tracked);
				break;
			}
		}

		private static void Unspawn(LevelStats level, TrackedValuable tracked)
		{
			tracked.Done = true;
			if (!tracked.Surplus)
			{
				level.ValueSpawned -= tracked.Original;
				level.ItemsSpawned--;
				if (Object.op_Implicit((Object)(object)tracked.Obj) && tracked.Obj.discovered)
				{
					level.ItemsDiscovered--;
				}
				Revision++;
				Plugin.Log.LogInfo((object)(tracked.Name + " se perdió al generarse el nivel: se descuenta del botín"));
			}
		}

		public static void OnAbsorbed(ItemValuableBox box, PhysGrabObject target)
		{
			if (OpenLevel == null || !Object.op_Implicit((Object)(object)box) || !Object.op_Implicit((Object)(object)target))
			{
				return;
			}
			ValuableObject component = ((Component)target).GetComponent<ValuableObject>();
			if (Object.op_Implicit((Object)(object)component) && Valuables.TryGetValue(((Object)component).GetInstanceID(), out var value) && !value.Done && !value.Absorbed)
			{
				value.Absorbed =