Decompiled source of BaconBenchmark v1.0.0

BepInEx/plugins/BaconBenchmark.dll

Decompiled 37 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Profiling;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BaconBenchmark
{
	internal static class BenchHud
	{
		private static Canvas _canvas;

		private static Image _bg;

		private static Image _frame;

		private static Image _track;

		private static Image _barFillImg;

		private static TextMeshProUGUI _phase;

		private static TextMeshProUGUI _detail;

		private static TextMeshProUGUI _stats;

		private static TextMeshProUGUI _hint;

		private static RectTransform _barFill;

		internal static void ApplyThemeNow()
		{
			//IL_0048: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_canvas == (Object)null))
			{
				Ui.ApplyTheme();
				if ((Object)(object)_bg != (Object)null)
				{
					((Graphic)_bg).color = new Color(Ui.Window.r, Ui.Window.g, Ui.Window.b, 0.92f);
				}
				if ((Object)(object)_frame != (Object)null)
				{
					((Graphic)_frame).color = Ui.Line;
				}
				if ((Object)(object)_track != (Object)null)
				{
					((Graphic)_track).color = Ui.Track;
				}
				if ((Object)(object)_barFillImg != (Object)null)
				{
					((Graphic)_barFillImg).color = Ui.Main;
				}
				if ((Object)(object)_phase != (Object)null)
				{
					((Graphic)_phase).color = Ui.Main;
				}
				if ((Object)(object)_detail != (Object)null)
				{
					((Graphic)_detail).color = Ui.InkSoft;
				}
				if ((Object)(object)_stats != (Object)null)
				{
					((Graphic)_stats).color = Ui.Ink;
				}
				if ((Object)(object)_hint != (Object)null)
				{
					((Graphic)_hint).color = Ui.Warn;
				}
			}
		}

		internal static void Tick()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (!BenchRunner.Running)
			{
				if ((Object)(object)_canvas != (Object)null && ((Component)_canvas).gameObject.activeSelf)
				{
					((Component)_canvas).gameObject.SetActive(false);
				}
				return;
			}
			EnsureBuilt();
			if (!((Component)_canvas).gameObject.activeSelf)
			{
				ApplyThemeNow();
				((Component)_canvas).gameObject.SetActive(true);
			}
			((TMP_Text)_phase).text = "> BENCHMARK  ·  " + BenchRunner.PhaseLabel;
			((TMP_Text)_detail).text = BenchRunner.PhaseDetail;
			((TMP_Text)_stats).text = $"FPS  <b>{BenchRunner.LiveFps:0}</b>    1% LOW  <b>{BenchRunner.LiveLow1:0}</b>    RAM  <b>{BenchRunner.LiveRamMb} MB</b>";
			((TMP_Text)_hint).text = $"[{Settings.Hotkey.Value}] ABORT BENCHMARK";
			_barFill.anchorMax = new Vector2(Mathf.Clamp01(BenchRunner.PhaseProgress), 1f);
		}

		private static void EnsureBuilt()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_canvas != (Object)null))
			{
				Ui.Prepare();
				_canvas = Ui.Canvas("BaconBenchmark HUD", 96);
				Object.DontDestroyOnLoad((Object)(object)((Component)_canvas).gameObject);
				RectTransform obj = Ui.Empty((Transform)(object)Ui.Root(((Component)_canvas).transform, "HudRoot"), "Card");
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(1f, 1f);
				obj.pivot = val;
				Vector2 anchorMin = (obj.anchorMax = val);
				obj.anchorMin = anchorMin;
				obj.anchoredPosition = new Vector2(-18f, -18f);
				obj.sizeDelta = new Vector2(410f, 118f);
				_bg = Ui.Panel((Transform)(object)obj, "Bg", new Color(Ui.Window.r, Ui.Window.g, Ui.Window.b, 0.92f));
				Ui.Stretch(((Graphic)_bg).rectTransform);
				_frame = Ui.Frame((Transform)(object)obj, Ui.Line, 2f);
				_phase = Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)obj, "", 16f, Ui.Main, (TextAlignmentOptions)257), 14f, 10f, 382f, 22f);
				((TMP_Text)_phase).characterSpacing = 2f;
				_detail = Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)obj, "", 13f, Ui.InkSoft, (TextAlignmentOptions)257), 14f, 34f, 382f, 18f);
				((TMP_Text)_detail).overflowMode = (TextOverflowModes)1;
				_track = Ui.Place<Image>(Ui.Panel((Transform)(object)obj, "Track", Ui.Track), 14f, 58f, 382f, 6f);
				_barFillImg = Ui.Panel(((Component)_track).transform, "Fill", Ui.Main);
				_barFill = ((Graphic)_barFillImg).rectTransform;
				_barFill.anchorMin = Vector2.zero;
				_barFill.anchorMax = new Vector2(0f, 1f);
				RectTransform barFill = _barFill;
				anchorMin = (_barFill.offsetMax = Vector2.zero);
				barFill.offsetMin = anchorMin;
				_stats = Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)obj, "", 15f, Ui.Ink, (TextAlignmentOptions)257), 14f, 70f, 382f, 22f);
				_hint = Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)obj, "", 12f, Ui.Warn, (TextAlignmentOptions)257), 14f, 94f, 382f, 18f);
			}
		}
	}
	internal static class BenchRunner
	{
		private const string TempSave = "LCSaveFileBaconBench";

		private static Coroutine _routine;

		private static bool _abortRequested;

		private static bool _recording;

		private static bool _recordingLanding;

		private static bool _panning;

		private static float _panSpeed = 24f;

		private static FrameBucket _activeBucket;

		private static float _landingMaxMs;

		private static int _landingOver100;

		private static float _lastHudPoll;

		private static BenchmarkReport _pendingShow;

		internal static bool Running { get; private set; }

		internal static string PhaseLabel { get; private set; } = "";

		internal static string PhaseDetail { get; private set; } = "";

		internal static float PhaseProgress { get; private set; }

		internal static float PhaseRemainingSec { get; private set; }

		internal static float LiveFps { get; private set; }

		internal static float LiveLow1 { get; private set; }

		internal static int LiveRamMb { get; private set; }

		internal static void StartRun()
		{
			//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 (!Running && !((Object)(object)BenchHost.Instance == (Object)null))
			{
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name != "MainMenu" || (Object)(object)StartOfRound.Instance != (Object)null)
				{
					Plugin.Log.LogWarning((object)"BaconBenchmark: Start benchmark from the Main Menu.");
					return;
				}
				BenchUi.Close();
				_abortRequested = false;
				Running = true;
				_routine = ((MonoBehaviour)BenchHost.Instance).StartCoroutine(RunCoroutine());
			}
		}

		internal static void RequestAbort()
		{
			if (Running && !_abortRequested)
			{
				_abortRequested = true;
				PhaseLabel = "ABORTING...";
				PhaseDetail = "Returning to Main Menu & cleaning temp save";
				Plugin.Log.LogInfo((object)"BaconBenchmark: abort requested by user.");
			}
		}

		internal static void OnMainMenuLoaded()
		{
			if (_pendingShow != null)
			{
				BenchmarkReport pendingShow = _pendingShow;
				_pendingShow = null;
				BenchUi.OpenResults(pendingShow);
			}
		}

		internal static void Tick()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!Running)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			Key value = Settings.Hotkey.Value;
			if (current != null && (int)value != 0 && ((ButtonControl)current[value]).wasPressedThisFrame)
			{
				RequestAbort();
				return;
			}
			float unscaledDeltaTime = Time.unscaledDeltaTime;
			if (_recording && _activeBucket != null)
			{
				_activeBucket.Sample(unscaledDeltaTime);
				_activeBucket.PollRam();
			}
			else if (_recordingLanding && unscaledDeltaTime > 0f && unscaledDeltaTime < 30f)
			{
				float num = unscaledDeltaTime * 1000f;
				if (num > _landingMaxMs)
				{
					_landingMaxMs = num;
				}
				if (num > 100f)
				{
					_landingOver100++;
				}
			}
			if (_panning)
			{
				PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
				if ((Object)(object)val != (Object)null && !val.isPlayerDead)
				{
					((Component)val).transform.Rotate(0f, _panSpeed * unscaledDeltaTime, 0f, (Space)0);
				}
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (realtimeSinceStartup - _lastHudPoll >= 0.25f)
			{
				_lastHudPoll = realtimeSinceStartup;
				LiveRamMb = MemoryProbe.WorkingSetMbFast();
				if (_recording && _activeBucket != null)
				{
					_activeBucket.LiveEstimate(out var avgFps, out var low1Fps);
					LiveFps = avgFps;
					LiveLow1 = low1Fps;
				}
				else
				{
					LiveFps = ((unscaledDeltaTime > 0.0005f) ? (1f / unscaledDeltaTime) : 0f);
					LiveLow1 = LiveFps;
				}
			}
		}

		private unsafe static IEnumerator RunCoroutine()
		{
			float runStart = Time.realtimeSinceStartup;
			BenchPreset value = Settings.Preset.Value;
			PresetTiming timing = Settings.GetTiming(value);
			List<string> moonQueue = (timing.LandOnMoon ? Settings.SelectedMoonList() : new List<string> { Settings.SelectedMoonList()[0] });
			BenchWeather weather = Settings.Weather.Value;
			int seed = Settings.Seed.Value;
			bool pan = Settings.CameraPan.Value;
			bool flag = Chainloader.PluginInfos.ContainsKey("bacongamerules");
			bool flag2 = flag && Settings.IncludeGameRules.Value;
			string prevSaveName = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.currentSaveFileName : "LCSaveFile1");
			int prevSaveSlot = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.saveFileNum : 0);
			string gameRules = DescribeGameRules(flag2, prevSaveSlot);
			BenchmarkReport report = new BenchmarkReport
			{
				Id = DateTime.Now.ToString("yyyyMMdd-HHmmss"),
				Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
				Tag = (Settings.RunTag.Value?.Trim() ?? ""),
				Preset = timing.Label,
				MoonRequested = ((moonQueue.Count == 1) ? moonQueue[0] : $"{moonQueue.Count} moons"),
				MoonActual = ((moonQueue.Count == 1) ? moonQueue[0] : $"{moonQueue.Count} moons"),
				Weather = weather.ToString(),
				GameRules = gameRules,
				Seed = seed,
				CameraPan = pan
			};
			MemoryProbe.FillSystemInfo(report);
			report.MemMenu = MemoryProbe.Capture("MainMenu");
			FrameBucket bucketOrbit = new FrameBucket();
			FrameBucket bucketOutside = new FrameBucket();
			FrameBucket bucketInside = new FrameBucket();
			FrameBucket bucketReturn = new FrameBucket();
			FrameBucket bucketOverall = new FrameBucket();
			List<MoonRunStats> moonResults = new List<MoonRunStats>();
			CleanupTempSave();
			PhaseLabel = "HOSTING";
			PhaseDetail = (flag2 ? "Hosting stress test (with Game Rules)..." : "Hosting clean benchmark (Vanilla rules)...");
			PhaseProgress = 0.05f;
			PhaseRemainingSec = 0f;
			try
			{
				GameNetworkManager.Instance.currentSaveFileName = "LCSaveFileBaconBench";
				if (flag && !flag2)
				{
					GameNetworkManager.Instance.saveFileNum = -1;
				}
				GameNetworkManager.Instance.lobbyHostSettings = new HostSettings("BaconBenchmark", false, "");
				GameNetworkManager.Instance.StartHost();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"BaconBenchmark: failed to host lobby: {arg}");
				FinishCleanup(prevSaveName, prevSaveSlot, null);
				yield break;
			}
			yield return WaitUntil(delegate
			{
				//IL_001f: 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)
				if ((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					return ((Scene)(ref activeScene)).name == "SampleSceneRelay";
				}
				return false;
			}, 120f);
			if (_abortRequested || (Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				yield return SafeReturnToMenu(prevSaveName, prevSaveSlot, null);
				yield break;
			}
			MoonCatalog.CaptureFromRound();
			StartOfRound round = StartOfRound.Instance;
			round.allowLocalPlayerDeath = false;
			PhaseLabel = "SETTLING";
			PhaseDetail = "Preparing ship...";
			yield return WaitSeconds(4f);
			DismissExternalOverlays();
			int firstIdx = FindLevelIndex(round, moonQueue[0]);
			if (firstIdx >= 0 && round.currentLevelID != firstIdx)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				round.ChangeLevelServerRpc(firstIdx, ((Object)(object)val != (Object)null) ? val.groupCredits : 60);
				yield return WaitUntil(() => round.currentLevelID == firstIdx && !round.travellingToNewLevel, 30f);
				yield return WaitSeconds(1.5f);
			}
			if (_abortRequested)
			{
				yield return SafeReturnToMenu(prevSaveName, prevSaveSlot, null);
				yield break;
			}
			if ((Object)(object)round.currentLevel != (Object)null && moonQueue.Count == 1)
			{
				report.MoonActual = round.currentLevel.PlanetName;
			}
			DismissExternalOverlays();
			yield return MeasurePhase("ORBIT", "Ship in orbit (" + round.currentLevel?.PlanetName + ")", timing.OrbitSec, bucketOrbit, pan, 18f);
			report.MemOrbit = MemoryProbe.Capture("Orbit");
			report.Orbit = bucketOrbit.Compute("Orbit");
			bucketOverall.AppendFrom(bucketOrbit);
			if (_abortRequested)
			{
				yield return SafeReturnToMenu(prevSaveName, prevSaveSlot, null);
				yield break;
			}
			if (timing.LandOnMoon)
			{
				float sumLoadSec = 0f;
				for (int mIdx = 0; mIdx < moonQueue.Count; mIdx++)
				{
					if (_abortRequested)
					{
						break;
					}
					string moonQuery = moonQueue[mIdx];
					string prefix = ((moonQueue.Count > 1) ? $"[{mIdx + 1}/{moonQueue.Count}] " : "");
					if ((Object)(object)TimeOfDay.Instance != (Object)null)
					{
						TimeOfDay.Instance.timeUntilDeadline = Mathf.Max(TimeOfDay.Instance.timeUntilDeadline, TimeOfDay.Instance.totalTime * 2.5f);
					}
					int levelIdx = FindLevelIndex(round, moonQuery);
					if (levelIdx < 0)
					{
						Plugin.Log.LogWarning((object)("BaconBenchmark: moon '" + moonQuery + "' not found in StartOfRound.levels, skipping."));
						continue;
					}
					if (round.currentLevelID != levelIdx)
					{
						PhaseLabel = prefix + "ROUTING";
						PhaseDetail = "Routing ship to " + moonQuery + "...";
						Terminal val2 = Object.FindObjectOfType<Terminal>();
						round.ChangeLevelServerRpc(levelIdx, ((Object)(object)val2 != (Object)null) ? val2.groupCredits : 60);
						yield return WaitUntil(() => round.currentLevelID == levelIdx && !round.travellingToNewLevel, 30f);
						yield return WaitSeconds(1.5f);
					}
					if (_abortRequested)
					{
						break;
					}
					string actualMoon = (((Object)(object)round.currentLevel != (Object)null) ? round.currentLevel.PlanetName : moonQuery);
					string actualWeather = weather.ToString();
					if ((Object)(object)round.currentLevel != (Object)null)
					{
						if (weather != BenchWeather.Default && Enum.TryParse<LevelWeatherType>(weather.ToString(), ignoreCase: true, out LevelWeatherType result))
						{
							round.currentLevel.currentWeather = result;
							actualWeather = ((object)(*(LevelWeatherType*)(&result))/*cast due to .constrained prefix*/).ToString();
						}
						else
						{
							actualWeather = ((object)Unsafe.As<LevelWeatherType, LevelWeatherType>(ref round.currentLevel.currentWeather)/*cast due to .constrained prefix*/).ToString();
						}
					}
					PhaseLabel = prefix + "LANDING";
					PhaseDetail = $"Loading {actualMoon} (seed {seed})...";
					PhaseProgress = 0.25f;
					PhaseRemainingSec = 0f;
					round.overrideRandomSeed = true;
					round.overrideSeedNumber = seed;
					_landingMaxMs = 0f;
					_landingOver100 = 0;
					_recordingLanding = true;
					float landStart = Time.realtimeSinceStartup;
					round.StartGameServerRpc();
					yield return WaitUntil(() => round.shipHasLanded && (Object)(object)RoundManager.Instance != (Object)null && RoundManager.Instance.dungeonCompletedGenerating, 180f);
					_recordingLanding = false;
					float loadSec = Time.realtimeSinceStartup - landStart;
					if (_abortRequested || !round.shipHasLanded)
					{
						break;
					}
					RoundManager rm = RoundManager.Instance;
					string interiorName = (((Object)(object)rm != (Object)null && (Object)(object)rm.dungeonGenerator != (Object)null && rm.dungeonGenerator.Generator != null && (Object)(object)rm.dungeonGenerator.Generator.DungeonFlow != (Object)null) ? ((Object)rm.dungeonGenerator.Generator.DungeonFlow).name : "Unknown");
					int interiorNodes = (((Object)(object)rm != (Object)null && rm.insideAINodes != null) ? rm.insideAINodes.Count((GameObject n) => (Object)(object)n != (Object)null) : 0);
					int trapsCount = Object.FindObjectsOfType<Landmine>().Length + Object.FindObjectsOfType<Turret>().Length + Object.FindObjectsOfType<SpikeRoofTrap>().Length;
					yield return WaitSeconds(1.8f);
					MemorySnapshot snapLanded = MemoryProbe.Capture("Landed");
					if (mIdx == 0)
					{
						report.MemLanded = snapLanded;
						report.InteriorName = interiorName;
						report.InteriorNodes = interiorNodes;
						report.TrapsCount = trapsCount;
						report.Weather = actualWeather;
					}
					FrameBucket moonBucket = new FrameBucket();
					moonBucket.Reset();
					PlayerControllerB player = GameNetworkManager.Instance.localPlayerController;
					EntranceTeleport[] source = Object.FindObjectsOfType<EntranceTeleport>();
					EntranceTeleport front = ((IEnumerable<EntranceTeleport>)source).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => (Object)(object)e != (Object)null && e.isEntranceToBuilding && e.entranceId == 0)) ?? ((IEnumerable<EntranceTeleport>)source).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => (Object)(object)e != (Object)null && e.isEntranceToBuilding));
					EntranceTeleport back = ((IEnumerable<EntranceTeleport>)source).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => (Object)(object)e != (Object)null && !e.isEntranceToBuilding && e.entranceId == 0)) ?? ((IEnumerable<EntranceTeleport>)source).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport e) => (Object)(object)e != (Object)null && !e.isEntranceToBuilding));
					if (timing.OutsideSec > 0f && (Object)(object)player != (Object)null)
					{
						Vector3 outPos = (((Object)(object)round.shipDoorNode != (Object)null) ? (round.shipDoorNode.position + round.shipDoorNode.forward * 4f) : ((Component)player).transform.position);
						GameObject[] array = (GameObject[])(((Object)(object)rm != (Object)null && rm.outsideAINodes != null) ? ((Array)rm.outsideAINodes.Where((GameObject n) => (Object)(object)n != (Object)null).ToArray()) : ((Array)new GameObject[0]));
						if (array.Length != 0)
						{
							GameObject val3 = array.OrderBy((GameObject n) => Vector3.SqrMagnitude(n.transform.position - outPos)).First();
							outPos = val3.transform.position + Vector3.up * 0.5f;
						}
						player.TeleportPlayer(outPos, false, 0f, false, true);
						player.isInHangarShipRoom = false;
						player.isInElevator = false;
						yield return WaitSeconds(0.8f);
						FrameBucket subOut = new FrameBucket();
						yield return MeasurePhase(prefix + "OUTSIDE", actualMoon + " (" + actualWeather + ")", timing.OutsideSec, subOut, pan, 26f);
						bucketOutside.AppendFrom(subOut);
						moonBucket.AppendFrom(subOut);
						bucketOverall.AppendFrom(subOut);
					}
					if (_abortRequested)
					{
						break;
					}
					if (timing.InsideSec > 0f && (Object)(object)player != (Object)null && (Object)(object)front != (Object)null)
					{
						front.TeleportPlayer();
						yield return WaitSeconds(1f);
						GameObject[] nodes = (GameObject[])(((Object)(object)rm != (Object)null && rm.insideAINodes != null) ? ((Array)rm.insideAINodes.Where((GameObject n) => (Object)(object)n != (Object)null).ToArray()) : ((Array)new GameObject[0]));
						Random rng = new Random(seed);
						FrameBucket subOut = new FrameBucket();
						subOut.Reset();
						PhaseLabel = prefix + "INSIDE";
						_activeBucket = subOut;
						_recording = true;
						_panning = pan;
						_panSpeed = 30f;
						float startAt = Time.realtimeSinceStartup;
						float endAt = startAt + timing.InsideSec;
						float nextMove = startAt + timing.StepSec;
						int moves = 0;
						while (!_abortRequested && Time.realtimeSinceStartup < endAt)
						{
							float realtimeSinceStartup = Time.realtimeSinceStartup;
							PhaseRemainingSec = Mathf.Max(0f, endAt - realtimeSinceStartup);
							PhaseProgress = Mathf.Clamp01((realtimeSinceStartup - startAt) / timing.InsideSec);
							PhaseDetail = $"{actualMoon} · {interiorName} · Room {moves + 1} · {PhaseRemainingSec:0}s";
							if (nodes.Length != 0 && realtimeSinceStartup >= nextMove)
							{
								player.TeleportPlayer(nodes[rng.Next(nodes.Length)].transform.position + Vector3.up * 0.35f, false, 0f, false, true);
								moves++;
								nextMove = realtimeSinceStartup + timing.StepSec;
							}
							yield return null;
						}
						_recording = false;
						_panning = false;
						_activeBucket = null;
						bucketInside.AppendFrom(subOut);
						moonBucket.AppendFrom(subOut);
						bucketOverall.AppendFrom(subOut);
						if (!_abortRequested && (Object)(object)back != (Object)null)
						{
							back.TeleportPlayer();
							yield return WaitSeconds(1f);
						}
					}
					int num = (((Object)(object)rm != (Object)null && rm.SpawnedEnemies != null) ? rm.SpawnedEnemies.Count : 0);
					MemorySnapshot memorySnapshot = (report.MemMoonEnd = MemoryProbe.Capture("MoonEnd"));
					report.EnemiesSpawned += num;
					PhaseStats phaseStats = moonBucket.Compute(actualMoon, 40);
					moonResults.Add(new MoonRunStats
					{
						Moon = actualMoon,
						Weather = actualWeather,
						InteriorName = interiorName,
						InteriorNodes = interiorNodes,
						TrapsCount = trapsCount,
						EnemiesSpawned = num,
						LandingLoadSec = loadSec,
						LandingSlowestMs = _landingMaxMs,
						LandingOver100Ms = _landingOver100,
						AvgFps = phaseStats.AvgFps,
						Low1Fps = phaseStats.Low1Fps,
						Low01Fps = phaseStats.Low01Fps,
						P99Ms = phaseStats.P99Ms,
						MaxMs = phaseStats.MaxMs,
						Over33Ms = phaseStats.Over33Ms,
						Over100Ms = phaseStats.Over100Ms,
						RamLandedMb = snapLanded.TotalUsedMb,
						RamEndMb = memorySnapshot.TotalUsedMb,
						AudioMb = snapLanded.UnpackedAudioMb
					});
					sumLoadSec += loadSec;
					if (_landingMaxMs > report.LandingSlowestMs)
					{
						report.LandingSlowestMs = _landingMaxMs;
					}
					report.LandingOver100Ms += _landingOver100;
					if (_abortRequested)
					{
						break;
					}
					PhaseLabel = prefix + "LEAVING";
					PhaseDetail = "Returning from " + actualMoon + " to orbit...";
					PhaseProgress = 0.88f;
					PhaseRemainingSec = 0f;
					if ((Object)(object)player != (Object)null)
					{
						if (round.playerSpawnPositions != null && round.playerSpawnPositions.Length != 0)
						{
							player.TeleportPlayer(round.playerSpawnPositions[0].position, false, 0f, false, true);
						}
						player.isInHangarShipRoom = true;
						player.isInElevator = true;
					}
					yield return WaitSeconds(1.2f);
					round.EndGameServerRpc((int)(((Object)(object)player != (Object)null) ? player.playerClientId : 0));
					yield return WaitUntil(() => round.inShipPhase && !round.shipIsLeaving, 150f);
					if (_abortRequested)
					{
						break;
					}
					yield return WaitSeconds(2.5f);
					DismissExternalOverlays();
					if (mIdx == moonQueue.Count - 1)
					{
						yield return MeasurePhase("RETURN ORBIT", "Post-round orbit check", timing.ReturnOrbitSec, bucketReturn, pan, 18f);
						report.MemReturnOrbit = MemoryProbe.Capture("ReturnOrbit");
						report.ReturnOrbit = bucketReturn.Compute("ReturnOrbit");
						bucketOverall.AppendFrom(bucketReturn);
					}
				}
				if (moonResults.Count > 0)
				{
					report.LandingLoadSec = sumLoadSec / (float)moonResults.Count;
					report.Moons = moonResults.ToArray();
					report.MoonActual = ((moonResults.Count == 1) ? moonResults[0].Moon : $"{moonResults.Count} moons ({moonResults[0].Moon}..)");
				}
				report.Outside = bucketOutside.Compute("Outside");
				report.Inside = bucketInside.Compute("Inside");
			}
			if (_abortRequested && moonResults.Count == 0 && bucketOrbit.Count == 0)
			{
				yield return SafeReturnToMenu(prevSaveName, prevSaveSlot, null);
				yield break;
			}
			report.Overall = bucketOverall.Compute("Overall");
			report.TotalDurationSec = Time.realtimeSinceStartup - runStart;
			int num2 = Math.Max(Math.Max(report.MemMenu.TotalUsedMb, report.MemOrbit.TotalUsedMb), Math.Max(Math.Max(report.MemLanded.TotalUsedMb, report.MemMoonEnd.TotalUsedMb), report.MemReturnOrbit.TotalUsedMb));
			if (report.Overall.RamPeakMb > num2)
			{
				num2 = report.Overall.RamPeakMb;
			}
			foreach (MoonRunStats item in moonResults)
			{
				if (item.RamEndMb > num2)
				{
					num2 = item.RamEndMb;
				}
			}
			report.PeakWorkingSetMb = num2;
			if (report.MemReturnOrbit.TotalUsedMb > 0 && report.MemOrbit.TotalUsedMb > 0)
			{
				report.RoundRamDeltaMb = report.MemReturnOrbit.TotalUsedMb - report.MemOrbit.TotalUsedMb;
			}
			ReportStore.Save(report);
			yield return SafeReturnToMenu(prevSaveName, prevSaveSlot, report);
		}

		private static string DescribeGameRules(bool includeRules, int slot)
		{
			if (!Chainloader.PluginInfos.TryGetValue("bacongamerules", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return "Vanilla";
			}
			if (!includeRules)
			{
				return "Vanilla (isolated)";
			}
			try
			{
				object obj = ((object)value.Instance).GetType().Assembly.GetType("BaconGameRules.GameSetup")?.GetMethod("ForSlot", AccessTools.all)?.Invoke(null, new object[1] { slot });
				if (obj != null)
				{
					object obj2 = obj.GetType().GetField("Preset", AccessTools.all)?.GetValue(obj);
					object arg = obj2?.GetType().GetProperty("Value")?.GetValue(obj2);
					return $"Included (File {slot + 1}: {arg})";
				}
			}
			catch
			{
			}
			return $"Included (File {slot + 1})";
		}

		private static IEnumerator MeasurePhase(string label, string detail, float seconds, FrameBucket bucket, bool pan, float panSpeed)
		{
			if (!(seconds <= 0f))
			{
				PhaseLabel = label;
				PhaseDetail = detail;
				bucket.Reset();
				_activeBucket = bucket;
				_recording = true;
				_panning = pan;
				_panSpeed = panSpeed;
				float startAt = Time.realtimeSinceStartup;
				float endAt = startAt + seconds;
				while (!_abortRequested && Time.realtimeSinceStartup < endAt)
				{
					float realtimeSinceStartup = Time.realtimeSinceStartup;
					PhaseRemainingSec = Mathf.Max(0f, endAt - realtimeSinceStartup);
					PhaseProgress = Mathf.Clamp01((realtimeSinceStartup - startAt) / seconds);
					yield return null;
				}
				_recording = false;
				_panning = false;
				_activeBucket = null;
			}
		}

		private static IEnumerator SafeReturnToMenu(string prevSaveName, int prevSaveSlot, BenchmarkReport completedReport)
		{
			_recording = false;
			_recordingLanding = false;
			_panning = false;
			_activeBucket = null;
			PhaseLabel = "FINISHING";
			PhaseDetail = "Returning to Main Menu...";
			_pendingShow = completedReport;
			Scene activeScene;
			try
			{
				if ((Object)(object)GameNetworkManager.Instance != (Object)null)
				{
					GameNetworkManager.Instance.currentSaveFileName = prevSaveName;
					GameNetworkManager.Instance.saveFileNum = prevSaveSlot;
					activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).name != "MainMenu")
					{
						GameNetworkManager.Instance.Disconnect();
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Disconnect warning: " + ex.Message));
			}
			float deadline = Time.realtimeSinceStartup + 45f;
			while (true)
			{
				activeScene = SceneManager.GetActiveScene();
				if (!(((Scene)(ref activeScene)).name != "MainMenu") || !(Time.realtimeSinceStartup < deadline))
				{
					break;
				}
				yield return null;
			}
			FinishCleanup(prevSaveName, prevSaveSlot, completedReport);
		}

		private static void FinishCleanup(string prevSaveName, int prevSaveSlot, BenchmarkReport completedReport)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)GameNetworkManager.Instance != (Object)null)
				{
					if (!string.IsNullOrEmpty(prevSaveName))
					{
						GameNetworkManager.Instance.currentSaveFileName = prevSaveName;
					}
					GameNetworkManager.Instance.saveFileNum = prevSaveSlot;
				}
			}
			catch
			{
			}
			CleanupTempSave();
			Running = false;
			_abortRequested = false;
			_routine = null;
			if (completedReport != null)
			{
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name == "MainMenu" && _pendingShow != null)
				{
					_pendingShow = null;
					BenchUi.OpenResults(completedReport);
				}
			}
		}

		private static int FindLevelIndex(StartOfRound round, string query)
		{
			if ((Object)(object)round == (Object)null || round.levels == null || string.IsNullOrWhiteSpace(query))
			{
				return -1;
			}
			for (int i = 0; i < round.levels.Length; i++)
			{
				SelectableLevel val = round.levels[i];
				if (!((Object)(object)val == (Object)null) && !string.IsNullOrEmpty(val.PlanetName) && string.Equals(MoonCatalog.StripNumberPrefix(val.PlanetName).Trim(), query.Trim(), StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
			}
			for (int j = 0; j < round.levels.Length; j++)
			{
				SelectableLevel val2 = round.levels[j];
				if (!((Object)(object)val2 == (Object)null) && !string.IsNullOrEmpty(val2.PlanetName) && val2.PlanetName.IndexOf(query.Trim(), StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return j;
				}
			}
			return -1;
		}

		private static void DismissExternalOverlays()
		{
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("baconrpg", out var value) && (Object)(object)value.Instance != (Object)null)
				{
					Assembly assembly = ((object)value.Instance).GetType().Assembly;
					Type type = assembly.GetType("BaconRPG.CareerScreen");
					object obj = type?.GetProperty("IsOpen", AccessTools.all)?.GetValue(null);
					bool flag = default(bool);
					int num;
					if (obj is bool)
					{
						flag = (bool)obj;
						num = 1;
					}
					else
					{
						num = 0;
					}
					if (((uint)num & (flag ? 1u : 0u)) != 0)
					{
						type.GetMethod("Close", AccessTools.all)?.Invoke(null, null);
					}
					Type type2 = assembly.GetType("BaconRPG.ClipReel");
					obj = type2?.GetProperty("IsOpen", AccessTools.all)?.GetValue(null);
					bool flag2 = default(bool);
					int num2;
					if (obj is bool)
					{
						flag2 = (bool)obj;
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
					if (((uint)num2 & (flag2 ? 1u : 0u)) != 0)
					{
						type2.GetMethod("HideLocal", AccessTools.all)?.Invoke(null, null);
					}
				}
			}
			catch
			{
			}
		}

		internal static void CleanupTempSave()
		{
			try
			{
				string persistentDataPath = Application.persistentDataPath;
				if (string.IsNullOrEmpty(persistentDataPath) || !Directory.Exists(persistentDataPath))
				{
					return;
				}
				string[] array = new string[2] { "LCSaveFileBaconBench", "LCSaveFileBaconBench.moddata" };
				foreach (string path in array)
				{
					string path2 = Path.Combine(persistentDataPath, path);
					if (File.Exists(path2))
					{
						File.Delete(path2);
					}
				}
				string path3 = Path.Combine(persistentDataPath, "DawnLib");
				if (!Directory.Exists(path3))
				{
					return;
				}
				array = Directory.GetFiles(path3, "*LCSaveFileBaconBench*", SearchOption.AllDirectories);
				foreach (string path4 in array)
				{
					try
					{
						File.Delete(path4);
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
		}

		private static IEnumerator WaitSeconds(float sec)
		{
			float end = Time.realtimeSinceStartup + sec;
			while (!_abortRequested && Time.realtimeSinceStartup < end)
			{
				yield return null;
			}
		}

		private static IEnumerator WaitUntil(Func<bool> cond, float timeoutSec)
		{
			float end = Time.realtimeSinceStartup + timeoutSec;
			while (!_abortRequested && Time.realtimeSinceStartup < end)
			{
				bool flag = false;
				try
				{
					flag = cond();
				}
				catch
				{
				}
				if (flag)
				{
					break;
				}
				yield return null;
			}
		}
	}
	internal static class BenchUi
	{
		private enum Tab
		{
			Run,
			Results,
			History
		}

		private const float WinW = 1580f;

		private const float WinH = 940f;

		private const float Pad = 26f;

		private static Canvas _canvas;

		private static RectTransform _win;

		private static RectTransform _headerRow;

		private static RectTransform _tabRow;

		private static RectTransform _body;

		private static Image _winBg;

		private static Image _winFrame;

		private static Image _tabLine;

		private static bool _open;

		private static Tab _tab;

		private static BenchmarkReport _shown;

		private static BenchmarkReport _baseline;

		private static BenchmarkReport _confirmDelete;

		private static string _statusNote;

		private static Texture2D _graphTex;

		private static TMP_InputField _tagInput;

		internal static bool IsOpen
		{
			get
			{
				if (_open && (Object)(object)_canvas != (Object)null)
				{
					return ((Component)_canvas).gameObject.activeSelf;
				}
				return false;
			}
		}

		internal static void Tick()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (BenchRunner.Running)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			if (current == null)
			{
				return;
			}
			if (IsOpen && ((ButtonControl)current.escapeKey).wasPressedThisFrame)
			{
				Close();
			}
			else
			{
				if ((Object)(object)_tagInput != (Object)null && _tagInput.isFocused)
				{
					return;
				}
				Key value = Settings.Hotkey.Value;
				if ((int)value == 0 || !((ButtonControl)current[value]).wasPressedThisFrame)
				{
					return;
				}
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name == "MainMenu")
				{
					if (IsOpen)
					{
						Close();
					}
					else
					{
						Open();
					}
				}
			}
		}

		internal static void Open()
		{
			if (!BenchRunner.Running)
			{
				EnsureBuilt();
				MoonCatalog.Refresh();
				ReportStore.Reload();
				if (_shown == null && ReportStore.All.Count > 0)
				{
					_shown = ReportStore.All[0];
				}
				_open = true;
				_confirmDelete = null;
				_statusNote = null;
				((Component)_canvas).gameObject.SetActive(true);
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				Rebuild();
			}
		}

		internal static void OpenResults(BenchmarkReport report)
		{
			EnsureBuilt();
			ReportStore.Reload();
			_shown = report ?? ((ReportStore.All.Count > 0) ? ReportStore.All[0] : null);
			if (_baseline == null && _shown != null && ReportStore.All.Count > 1)
			{
				_baseline = ReportStore.All.FirstOrDefault((BenchmarkReport r) => r != _shown && string.Equals(r.MoonActual, _shown.MoonActual, StringComparison.OrdinalIgnoreCase));
			}
			_tab = Tab.Results;
			_open = true;
			_confirmDelete = null;
			_statusNote = ((_shown != null) ? "BENCHMARK COMPLETE · LOG SAVED TO BepInEx/BaconBenchmark/runs/" : null);
			((Component)_canvas).gameObject.SetActive(true);
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			Rebuild();
		}

		internal static void Close()
		{
			_open = false;
			_confirmDelete = null;
			_tagInput = null;
			if ((Object)(object)_canvas != (Object)null)
			{
				((Component)_canvas).gameObject.SetActive(false);
			}
		}

		private static void EnsureBuilt()
		{
			//IL_0056: 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_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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_canvas != (Object)null))
			{
				Ui.Prepare();
				_canvas = Ui.Canvas("BaconBenchmark Dashboard", 95);
				Object.DontDestroyOnLoad((Object)(object)((Component)_canvas).gameObject);
				Image obj = Ui.Panel(((Component)_canvas).transform, "Shade", new Color(0f, 0f, 0f, 0.86f));
				((Graphic)obj).raycastTarget = true;
				Ui.Stretch(((Graphic)obj).rectTransform);
				_win = Ui.Empty((Transform)(object)Ui.Root(((Component)_canvas).transform, "Root"), "Window");
				RectTransform win = _win;
				RectTransform win2 = _win;
				RectTransform win3 = _win;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0.5f, 0.5f);
				win3.pivot = val;
				Vector2 anchorMin = (win2.anchorMax = val);
				win.anchorMin = anchorMin;
				_win.sizeDelta = new Vector2(1580f, 940f);
				_win.anchoredPosition = Vector2.zero;
				_winBg = Ui.Panel((Transform)(object)_win, "Bg", Ui.Window);
				Ui.Stretch(((Graphic)_winBg).rectTransform);
				RawImage obj2 = ((Component)Ui.Empty((Transform)(object)_win, "Scanlines")).gameObject.AddComponent<RawImage>();
				Ui.Stretch(((Graphic)obj2).rectTransform);
				obj2.texture = (Texture)(object)Ui.ScanlineTexture();
				obj2.uvRect = new Rect(0f, 0f, 1f, 313.33334f);
				((Graphic)obj2).raycastTarget = false;
				_winFrame = Ui.Frame((Transform)(object)_win, Ui.Line, 2f);
				_headerRow = Ui.Place(Ui.Empty((Transform)(object)_win, "Header"), 26f, 16f, 1528f, 44f);
				_tabRow = Ui.Place(Ui.Empty((Transform)(object)_win, "Tabs"), 26f, 68f, 1528f, 38f);
				_tabLine = Ui.Place<Image>(Ui.Panel((Transform)(object)_win, "Line", Ui.Accent(0.32f)), 26f, 112f, 1528f, 1f);
				_body = Ui.Place(Ui.Empty((Transform)(object)_win, "Body"), 26f, 124f, 1528f, 790f);
			}
		}

		private static void Clear(RectTransform t)
		{
			for (int num = ((Transform)t).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)t).GetChild(num)).gameObject);
			}
		}

		private static void Rebuild()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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)
			if ((Object)(object)_canvas == (Object)null)
			{
				return;
			}
			Ui.ApplyTheme();
			if ((Object)(object)_winBg != (Object)null)
			{
				((Graphic)_winBg).color = Ui.Window;
			}
			if ((Object)(object)_winFrame != (Object)null)
			{
				((Graphic)_winFrame).color = Ui.Line;
			}
			if ((Object)(object)_tabLine != (Object)null)
			{
				((Graphic)_tabLine).color = Ui.Accent(0.32f);
			}
			_tagInput = null;
			if ((Object)(object)_graphTex != (Object)null)
			{
				Object.Destroy((Object)(object)_graphTex);
				_graphTex = null;
			}
			Clear(_headerRow);
			Clear(_tabRow);
			Clear(_body);
			float x = _headerRow.sizeDelta.x;
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_headerRow, "> BACON BENCHMARK  ·  v1.0.0", 24f, Ui.Main, (TextAlignmentOptions)257), 0f, 6f, 600f, 32f)).characterSpacing = 3f;
			string text = string.Format("{0}  {1}  {2}x{3}  {4}  {5} MODS", SystemInfo.graphicsDeviceName, "·", Screen.width, Screen.height, "·", Chainloader.PluginInfos.Count);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_headerRow, text, 13f, Ui.InkSoft, (TextAlignmentOptions)516), x - 960f, 12f, 620f, 22f)).overflowMode = (TextOverflowModes)1;
			string text2 = ((Settings.Theme.Value == BenchTheme.Original) ? "ORIGINAL" : ((Settings.Theme.Value == BenchTheme.TerminalGreen) ? "GREEN" : "CYAN"));
			Ui.Place<Image>(Ui.MenuButton((Transform)(object)_headerRow, "THEME: " + text2, 13f, delegate
			{
				BenchTheme[] array2 = (BenchTheme[])Enum.GetValues(typeof(BenchTheme));
				int num3 = (Array.IndexOf(array2, Settings.Theme.Value) + 1) % array2.Length;
				Settings.Theme.Value = array2[num3];
				BenchHud.ApplyThemeNow();
				Rebuild();
			}).Fill, x - 324f, 2f, 172f, 38f);
			Ui.Place<Image>(Ui.MenuButton((Transform)(object)_headerRow, "CLOSE [ESC]", 14f, Close).Fill, x - 142f, 2f, 142f, 38f);
			(Tab, string)[] obj = new(Tab, string)[3]
			{
				(Tab.Run, "RUN BENCHMARK"),
				(Tab.Results, "RESULTS"),
				(Tab.History, $"HISTORY ({ReportStore.All.Count})")
			};
			float num = 0f;
			(Tab, string)[] array = obj;
			for (int num2 = 0; num2 < array.Length; num2++)
			{
				(Tab, string) tuple = array[num2];
				Tab t = tuple.Item1;
				string item = tuple.Item2;
				bool filled = _tab == t;
				Ui.Place<Image>(Ui.MenuButton((Transform)(object)_tabRow, item, 14f, delegate
				{
					_tab = t;
					_confirmDelete = null;
					_statusNote = null;
					Rebuild();
				}, filled).Fill, num, 0f, 210f, 36f);
				num += 220f;
			}
			if (_tab == Tab.Run)
			{
				BuildRunTab();
			}
			else if (_tab == Tab.Results)
			{
				BuildResultsTab();
			}
			else
			{
				BuildHistoryTab();
			}
		}

		private static void BuildRunTab()
		{
			//IL_000b: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_0155: 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_0448: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0700: Unknown result type (might be due to invalid IL or missing references)
			//IL_0705: Unknown result type (might be due to invalid IL or missing references)
			//IL_070e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_0716: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_071d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0927: Unknown result type (might be due to invalid IL or missing references)
			//IL_0997: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b16: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c4a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d67: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d5b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d83: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d77: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d88: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dde: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e26: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e87: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f02: Unknown result type (might be due to invalid IL or missing references)
			float x = _body.sizeDelta.x;
			float y = _body.sizeDelta.y;
			float num = 630f;
			float num2 = num + 26f;
			float num3 = x - num2;
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "1. SELECT PRESET", 14f, Ui.Main, (TextAlignmentOptions)257), 0f, 0f, num, 20f)).characterSpacing = 3f;
			BenchPreset[] array = new BenchPreset[4]
			{
				BenchPreset.Quick,
				BenchPreset.Standard,
				BenchPreset.Stress,
				BenchPreset.OrbitOnly
			};
			float num4 = 26f;
			float num5 = (num - 12f) / 2f;
			float num6 = 74f;
			for (int i = 0; i < array.Length; i++)
			{
				BenchPreset p = array[i];
				PresetTiming timing = Settings.GetTiming(p);
				bool flag = Settings.Preset.Value == p;
				float x2 = (float)(i % 2) * (num5 + 12f);
				float y2 = num4 + (float)(i / 2) * (num6 + 8f);
				BenchButton benchButton = Ui.MenuButton((Transform)(object)_body, "", 14f, delegate
				{
					Settings.Preset.Value = p;
					Rebuild();
				});
				benchButton.Normal = (flag ? Ui.Accent(0.18f) : Ui.Surface);
				benchButton.Hover = (flag ? Ui.Accent(0.28f) : Ui.SurfaceHover);
				benchButton.FrameNormal = (flag ? Ui.Main : Ui.Line);
				benchButton.FrameHover = Ui.Main;
				benchButton.Apply(over: false);
				Ui.Place<Image>(benchButton.Fill, x2, y2, num5, num6);
				Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)benchButton.Fill).transform, timing.Label + (flag ? "  [SELECTED]" : ""), 15f, flag ? Ui.Main : Ui.Ink, (TextAlignmentOptions)257), 12f, 8f, num5 - 24f, 20f);
				Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)benchButton.Fill).transform, timing.Summary, 11.5f, Ui.InkSoft, (TextAlignmentOptions)257, wrap: true), 12f, 32f, num5 - 24f, 36f);
			}
			float num7 = num4 + 2f * (num6 + 8f) + 14f;
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "2. BENCHMARK PARAMETERS", 14f, Ui.Main, (TextAlignmentOptions)257), 0f, num7, num, 20f)).characterSpacing = 3f;
			num7 += 26f;
			BenchWeather[] weathers = (BenchWeather[])Enum.GetValues(typeof(BenchWeather));
			int wIdx = Array.IndexOf(weathers, Settings.Weather.Value);
			StepperRow((Transform)(object)_body, 0f, num7, num, "Weather override", "Force clear or heavy weather for identical runs.", Settings.Weather.Value.ToString().ToUpperInvariant(), delegate
			{
				Settings.Weather.Value = weathers[(wIdx + weathers.Length - 1) % weathers.Length];
				Rebuild();
			}, delegate
			{
				Settings.Weather.Value = weathers[(wIdx + 1) % weathers.Length];
				Rebuild();
			});
			num7 += 60f;
			StepperRow((Transform)(object)_body, 0f, num7, num - 108f, "Fixed map seed", "Same seed = identical dungeon layout for fair comparisons.", Settings.Seed.Value.ToString(), delegate
			{
				Settings.Seed.Value = Mathf.Max(1, Settings.Seed.Value - 1000);
				Rebuild();
			}, delegate
			{
				Settings.Seed.Value = Mathf.Min(99999999, Settings.Seed.Value + 1000);
				Rebuild();
			});
			Ui.Place<Image>(Ui.MenuButton((Transform)(object)_body, "RANDOM", 13f, delegate
			{
				Settings.Seed.Value = Random.Range(10000, 999999);
				Rebuild();
			}).Fill, num - 98f, num7 + 8f, 98f, 34f);
			num7 += 60f;
			bool flag2 = Chainloader.PluginInfos.ContainsKey("bacongamerules");
			bool incRules = Settings.IncludeGameRules.Value;
			Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "Game rules (mines / spawns)", 15f, Ui.Ink, (TextAlignmentOptions)257), 0f, num7 + 4f, num - 210f, 20f);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, (!flag2) ? "This option works with BaconGameRules. Without it, the game's own rules always apply." : (incRules ? "ON: includes active BaconGameRules (more mines/spawns) for stress testing." : "OFF: isolated from BaconGameRules (pure vanilla mines, traps & spawns)."), 11.5f, Ui.InkSoft, (TextAlignmentOptions)257), 0f, num7 + 26f, num - 210f, 18f)).overflowMode = (TextOverflowModes)1;
			BenchButton benchButton2 = Ui.MenuButton((Transform)(object)_body, (!flag2) ? "NEEDS BACONGAMERULES" : (incRules ? "INCLUDE (STRESS)" : "VANILLA (CLEAN)"), 12f, delegate
			{
				Settings.IncludeGameRules.Value = !incRules;
				Rebuild();
			}, filled: false, flag2);
			if (flag2 && incRules)
			{
				benchButton2.Normal = new Color(Ui.Gold.r, Ui.Gold.g, Ui.Gold.b, 0.22f);
				benchButton2.Hover = new Color(Ui.Gold.r, Ui.Gold.g, Ui.Gold.b, 0.34f);
				benchButton2.FrameNormal = (benchButton2.FrameHover = Ui.Gold);
				benchButton2.Apply(over: false);
				if ((Object)(object)benchButton2.Label != (Object)null)
				{
					((Graphic)benchButton2.Label).color = Ui.Gold;
				}
			}
			Ui.Place<Image>(benchButton2.Fill, num - 196f, num7 + 8f, 196f, 34f);
			Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "Div", Ui.Accent(0.08f)), 0f, num7 + 52f, num, 1f);
			num7 += 60f;
			bool pan = Settings.CameraPan.Value;
			Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "Smooth camera pan", 15f, Ui.Ink, (TextAlignmentOptions)257), 0f, num7 + 4f, num - 180f, 20f);
			Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "Gently rotates view so culling, lights & shadows are realistically tested.", 11.5f, Ui.InkSoft, (TextAlignmentOptions)257), 0f, num7 + 26f, num - 180f, 18f);
			BenchButton benchButton3 = Ui.MenuButton((Transform)(object)_body, pan ? "ON" : "OFF", 14f, delegate
			{
				Settings.CameraPan.Value = !pan;
				Rebuild();
			});
			if (pan)
			{
				benchButton3.Normal = Ui.Accent(0.18f);
				benchButton3.Hover = Ui.Accent(0.3f);
				benchButton3.FrameNormal = (benchButton3.FrameHover = Ui.Main);
				benchButton3.Apply(over: false);
				if ((Object)(object)benchButton3.Label != (Object)null)
				{
					((Graphic)benchButton3.Label).color = Ui.Main;
				}
			}
			Ui.Place<Image>(benchButton3.Fill, num - 160f, num7 + 8f, 160f, 34f);
			Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "Div", Ui.Accent(0.08f)), 0f, num7 + 52f, num, 1f);
			num7 += 60f;
			Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "Run label (optional)", 15f, Ui.Ink, (TextAlignmentOptions)257), 0f, num7 + 4f, 240f, 20f);
			Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "e.g. Before, After, AllModded, Stress", 11.5f, Ui.InkSoft, (TextAlignmentOptions)257), 0f, num7 + 26f, 320f, 18f);
			_tagInput = CreateInputField((Transform)(object)_body, num - 280f, num7 + 8f, 280f, 34f, Settings.RunTag.Value, "Optional tag...", delegate(string v)
			{
				Settings.RunTag.Value = v;
			});
			num7 += 60f;
			List<string> list = Settings.SelectedMoonList();
			PresetTiming timing2 = Settings.GetTiming(Settings.Preset.Value);
			string text = ((list.Count == 1) ? list[0].ToUpperInvariant() : string.Format("{0} MOONS ({1}{2})", list.Count, string.Join(", ", list.Take(3)), (list.Count > 3) ? "..." : ""));
			Image obj = Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "Safety", Ui.Surface), 0f, num7 + 4f, num, 66f);
			Ui.Frame(((Component)obj).transform, Ui.Line);
			Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)obj).transform, "QUEUE: " + timing2.Label + "  ·  " + text + "  ·  " + ((flag2 && incRules) ? "GAME RULES ON" : "VANILLA RULES") + "\n" + $"Uses isolated temp save (LCSaveFileBaconBench) — real saves 1-3 are never touched. Press [{Settings.Hotkey.Value}] anytime to abort.", 12f, Ui.InkSoft, (TextAlignmentOptions)257, wrap: true), 12f, 10f, num - 24f, 50f);
			Scene activeScene = SceneManager.GetActiveScene();
			bool flag3 = ((Scene)(ref activeScene)).name == "MainMenu" && (Object)(object)StartOfRound.Instance == (Object)null;
			string text2 = ((!flag3) ? "RETURN TO MAIN MENU TO RUN" : ((list.Count > 1 && timing2.LandOnMoon) ? $"START BENCHMARK ({list.Count} MOONS)" : "START BENCHMARK"));
			Ui.Place<Image>(Ui.MenuButton((Transform)(object)_body, text2, 19f, BenchRunner.StartRun, flag3, flag3).Fill, 0f, y - 58f, num, 54f);
			IReadOnlyList<MoonCatalog.MoonEntry> moons = MoonCatalog.All;
			int num8 = moons.Count((MoonCatalog.MoonEntry moonEntry) => moonEntry.Modded);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, string.Format("3. CHOOSE MOONS  {0}  {1} SELECTED OF {2} ({3} MODDED)", "·", list.Count, moons.Count, num8), 14f, Ui.Main, (TextAlignmentOptions)257), num2, 0f, num3, 20f)).characterSpacing = 2.5f;
			float qx = num2;
			QuickBtn($"ALL MOONS ({moons.Count((MoonCatalog.MoonEntry moonEntry) => !moonEntry.IsCompany)})", 156f, delegate
			{
				Settings.SetSelectedMoons(from moonEntry in moons
					where !moonEntry.IsCompany
					select moonEntry.Query);
				Rebuild();
			});
			QuickBtn($"ALL MODDED ({num8})", 152f, delegate
			{
				List<string> list2 = (from moonEntry in moons
					where moonEntry.Modded
					select moonEntry.Query).ToList();
				if (list2.Count > 0)
				{
					Settings.SetSelectedMoons(list2);
				}
				Rebuild();
			});
			QuickBtn("ALL VANILLA (11)", 146f, delegate
			{
				Settings.SetSelectedMoons(from moonEntry in moons
					where !moonEntry.Modded && !moonEntry.IsCompany
					select moonEntry.Query);
				Rebuild();
			});
			QuickBtn("RESET TO 1", 112f, delegate
			{
				Settings.SetSelectedMoons(new string[1] { "Experimentation" });
				Rebuild();
			});
			QuickBtn("REFRESH", 92f, delegate
			{
				MoonCatalog.Refresh();
				Rebuild();
			});
			Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, "Click moons to add/remove from the test queue (pick 1 moon, a custom list, all modded, or all moons).", 12f, Ui.InkSoft, (TextAlignmentOptions)257), num2, 62f, num3, 18f);
			int num9 = 3;
			float num10 = 9f;
			float num11 = (num3 - num10 * (float)(num9 - 1) - 6f) / (float)num9;
			float num12 = 54f;
			float contentH = (float)((moons.Count + num9 - 1) / num9) * (num12 + num10) + 12f;
			RectTransform parent = Ui.Scroller((Transform)(object)_body, num2, 86f, num3, y - 86f, contentH);
			for (int num13 = 0; num13 < moons.Count; num13++)
			{
				MoonCatalog.MoonEntry m = moons[num13];
				int num14 = list.FindIndex((string q) => string.Equals(q, m.Query, StringComparison.OrdinalIgnoreCase));
				bool flag4 = num14 >= 0;
				float x3 = (float)(num13 % num9) * (num11 + num10);
				float y3 = (float)(num13 / num9) * (num12 + num10);
				BenchButton benchButton4 = Ui.MenuButton((Transform)(object)parent, "", 14f, delegate
				{
					Settings.ToggleMoon(m.Query);
					Rebuild();
				});
				benchButton4.Normal = (flag4 ? Ui.Accent(0.22f) : Ui.Surface);
				benchButton4.Hover = (flag4 ? Ui.Accent(0.32f) : Ui.SurfaceHover);
				benchButton4.FrameNormal = (Color)(flag4 ? Ui.Main : (m.Modded ? new Color(Ui.Gold.r, Ui.Gold.g, Ui.Gold.b, 0.45f) : Ui.Line));
				benchButton4.FrameHover = Ui.Main;
				benchButton4.Apply(over: false);
				Ui.Place<Image>(benchButton4.Fill, x3, y3, num11, num12);
				((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)benchButton4.Fill).transform, m.Display, 14f, flag4 ? Ui.Main : Ui.Ink, (TextAlignmentOptions)257), 10f, 7f, num11 - 44f, 20f)).overflowMode = (TextOverflowModes)1;
				if (flag4)
				{
					Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)benchButton4.Fill).transform, $"#{num14 + 1}", 13f, Ui.Main, (TextAlignmentOptions)260), num11 - 44f, 8f, 34f, 18f);
				}
				Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)benchButton4.Fill).transform, m.Modded ? "MODDED MOON" : (m.IsCompany ? "COMPANY" : "VANILLA"), 11f, m.Modded ? Ui.Gold : Ui.InkFaint, (TextAlignmentOptions)257), 10f, 30f, num11 - 20f, 16f);
			}
			void QuickBtn(string label, float bw, Action onClick)
			{
				Ui.Place<Image>(Ui.MenuButton((Transform)(object)_body, label, 12.5f, onClick).Fill, qx, 26f, bw, 30f);
				qx += bw + 8f;
			}
		}

		private static void BuildResultsTab()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: 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_0382: 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_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aaf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b90: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f23: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e7c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e75: Unknown result type (might be due to invalid IL or missing references)
			//IL_119f: Unknown result type (might be due to invalid IL or missing references)
			//IL_11ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_11ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eaf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ea8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0edb: Unknown result type (might be due to invalid IL or missing references)
			//IL_1160: Unknown result type (might be due to invalid IL or missing references)
			//IL_13c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_1442: Unknown result type (might be due to invalid IL or missing references)
			//IL_143b: Unknown result type (might be due to invalid IL or missing references)
			float x = _body.sizeDelta.x;
			float y = _body.sizeDelta.y;
			if (_shown == null && ReportStore.All.Count > 0)
			{
				_shown = ReportStore.All[0];
			}
			if (_shown == null)
			{
				Ui.Stretch(((TMP_Text)Ui.Label((Transform)(object)_body, "No benchmark runs saved yet.\nOpen RUN BENCHMARK, pick a preset & moon(s), and click START BENCHMARK.", 20f, Ui.InkSoft, (TextAlignmentOptions)514, wrap: true)).rectTransform);
				return;
			}
			BenchmarkReport r = _shown;
			BenchmarkReport baseRun = ((_baseline != null && _baseline != r) ? _baseline : null);
			bool flag = _confirmDelete == r;
			string text = string.Format("{0}  {1}  {2}  {3}  {4}  {5}  SEED {6}  {7}  {8}", r.Preset, "·", r.MoonActual.ToUpperInvariant(), "·", r.Weather.ToUpperInvariant(), "·", r.Seed, "·", r.GameRules.ToUpperInvariant());
			if (!string.IsNullOrEmpty(r.Tag))
			{
				text = "[" + r.Tag.ToUpperInvariant() + "]  " + text;
			}
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, text, 15.5f, Ui.Main, (TextAlignmentOptions)257), 0f, 4f, x - 700f, 24f)).overflowMode = (TextOverflowModes)1;
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, string.Format("{0}  {1}  {2}  {3}  {4} @ {5} ({6} mods)", r.Timestamp, "·", r.Cpu, "·", r.Gpu, r.Resolution, r.ModCount), 12f, Ui.InkSoft, (TextAlignmentOptions)257), 0f, 28f, x - 700f, 18f)).overflowMode = (TextOverflowModes)1;
			float rx = x;
			if (flag)
			{
				BenchButton benchButton = ActBtn("CONFIRM DELETE", 160f, delegate
				{
					BenchmarkReport benchmarkReport = r;
					if (_baseline == benchmarkReport)
					{
						_baseline = null;
					}
					_confirmDelete = null;
					ReportStore.Delete(benchmarkReport);
					_shown = ((ReportStore.All.Count > 0) ? ReportStore.All[0] : null);
					_statusNote = "BENCHMARK RUN DELETED";
					Rebuild();
				}, filled: true);
				benchButton.Normal = Color.Lerp(Ui.Window, Ui.Warn, 0.85f);
				benchButton.Hover = Ui.Warn;
				benchButton.FrameNormal = (benchButton.FrameHover = Ui.Warn);
				benchButton.Apply(over: false);
				ActBtn("CANCEL", 92f, delegate
				{
					_confirmDelete = null;
					_statusNote = null;
					Rebuild();
				});
			}
			else
			{
				BenchButton benchButton2 = ActBtn("DELETE", 92f, delegate
				{
					_confirmDelete = r;
					_statusNote = "CLICK CONFIRM TO PERMANENTLY DELETE THIS RUN";
					Rebuild();
				});
				benchButton2.Normal = new Color(Ui.Warn.r, Ui.Warn.g, Ui.Warn.b, 0.12f);
				benchButton2.Hover = new Color(Ui.Warn.r, Ui.Warn.g, Ui.Warn.b, 0.26f);
				benchButton2.FrameNormal = (benchButton2.FrameHover = Ui.Warn);
				benchButton2.Apply(over: false);
				if ((Object)(object)benchButton2.Label != (Object)null)
				{
					((Graphic)benchButton2.Label).color = Ui.Warn;
				}
			}
			if (!string.IsNullOrEmpty(r.LogPath))
			{
				ActBtn("COPY LOG PATH", 148f, delegate
				{
					_confirmDelete = null;
					GUIUtility.systemCopyBuffer = r.LogPath;
					_statusNote = "LOG PATH COPIED · " + r.LogPath;
					Rebuild();
				});
			}
			ActBtn("COPY REPORT", 136f, delegate
			{
				_confirmDelete = null;
				GUIUtility.systemCopyBuffer = ReportStore.FormatMarkdown(r, baseRun);
				_statusNote = ((baseRun != null) ? "BEFORE/AFTER MARKDOWN REPORT COPIED (READY FOR DISCORD)" : "MARKDOWN BENCHMARK REPORT COPIED (READY FOR DISCORD)");
				Rebuild();
			}, filled: true);
			if (ReportStore.All.Count > 1)
			{
				string label = ((baseRun != null) ? ("VS: " + (string.IsNullOrEmpty(baseRun.Tag) ? baseRun.Timestamp.Substring(11, 5) : baseRun.Tag)) : "COMPARE: OFF");
				BenchButton benchButton3 = ActBtn(label, 170f, delegate
				{
					_confirmDelete = null;
					List<BenchmarkReport> list = ReportStore.All.Where((BenchmarkReport benchmarkReport) => benchmarkReport != r).ToList();
					if (list.Count == 0)
					{
						_baseline = null;
					}
					else if (_baseline == null)
					{
						_baseline = list[0];
					}
					else
					{
						int num11 = list.IndexOf(_baseline);
						_baseline = ((num11 < 0 || num11 + 1 >= list.Count) ? null : list[num11 + 1]);
					}
					Rebuild();
				});
				if (baseRun != null)
				{
					benchButton3.Normal = Ui.Accent(0.18f);
					benchButton3.Hover = Ui.Accent(0.3f);
					benchButton3.FrameNormal = (benchButton3.FrameHover = Ui.Main);
					benchButton3.Apply(over: false);
					if ((Object)(object)benchButton3.Label != (Object)null)
					{
						((Graphic)benchButton3.Label).color = Ui.Main;
					}
				}
			}
			float num = 54f;
			float num2 = 12f;
			float num3 = (x - num2 * 4f) / 5f;
			float num4 = 102f;
			HeroCard(0f, num, num3, num4, "AVERAGE FPS", $"{r.Overall.AvgFps:0.0}", string.Format("Avg {0:0.1} ms  {1}  Med {2:0.0}", r.Overall.AvgMs, "·", r.Overall.MedianFps), (baseRun != null) ? DeltaText(r.Overall.AvgFps - baseRun.Overall.AvgFps, baseRun.Overall.AvgFps, "FPS") : null, (baseRun != null) ? DeltaColor(r.Overall.AvgFps - baseRun.Overall.AvgFps, higherBetter: true) : Ui.Main);
			HeroCard((num3 + num2) * 1f, num, num3, num4, "1% LOW FPS", $"{r.Overall.Low1Fps:0.0}", string.Format("P99 {0:0.1} ms  {1}  >33ms: {2}", r.Overall.P99Ms, "·", r.Overall.Over33Ms), (baseRun != null) ? DeltaText(r.Overall.Low1Fps - baseRun.Overall.Low1Fps, baseRun.Overall.Low1Fps, "FPS") : null, (baseRun != null) ? DeltaColor(r.Overall.Low1Fps - baseRun.Overall.Low1Fps, higherBetter: true) : Ui.Good);
			HeroCard((num3 + num2) * 2f, num, num3, num4, "0.1% LOW FPS", $"{r.Overall.Low01Fps:0.0}", string.Format("P99.9 {0:0.1} ms  {1}  Max {2:0.0} ms", r.Overall.P999Ms, "·", r.Overall.MaxMs), (baseRun != null) ? DeltaText(r.Overall.Low01Fps - baseRun.Overall.Low01Fps, baseRun.Overall.Low01Fps, "FPS") : null, (baseRun != null) ? DeltaColor(r.Overall.Low01Fps - baseRun.Overall.Low01Fps, higherBetter: true) : Ui.Gold);
			HeroCard((num3 + num2) * 3f, num, num3, num4, "PEAK RAM (UNITY+C#)", $"{r.PeakWorkingSetMb} MB", string.Format("Audio: {0} MB  {1}  Delta: {2}{3} MB", r.MemLanded.UnpackedAudioMb, "·", (r.RoundRamDeltaMb >= 0) ? "+" : "", r.RoundRamDeltaMb), (baseRun != null) ? DeltaText(r.PeakWorkingSetMb - baseRun.PeakWorkingSetMb, baseRun.PeakWorkingSetMb, "MB") : null, (baseRun != null) ? DeltaColor(r.PeakWorkingSetMb - baseRun.PeakWorkingSetMb, higherBetter: false) : Ui.Main);
			HeroCard((num3 + num2) * 4f, num, num3, num4, "LANDING / HITCHES", (r.LandingLoadSec > 0f) ? $"{r.LandingLoadSec:0.1} s" : "ORBIT ONLY", string.Format("Gameplay >100ms: {0}  {1}  Load max: {2:0} ms", r.Overall.Over100Ms, "·", r.LandingSlowestMs), (baseRun != null && r.LandingLoadSec > 0f && baseRun.LandingLoadSec > 0f) ? DeltaText(r.LandingLoadSec - baseRun.LandingLoadSec, baseRun.LandingLoadSec, "s") : null, (baseRun != null) ? DeltaColor(r.LandingLoadSec - baseRun.LandingLoadSec, higherBetter: false) : Ui.Ink);
			num += num4 + 14f;
			float num5 = 180f;
			Image obj = Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "GraphBox", Ui.Surface), 0f, num, x, num5);
			Ui.Frame(((Component)obj).transform, Ui.Line);
			_graphTex = Ui.RenderFrametimeGraph(r.Overall.TimelineMs, baseRun?.Overall.TimelineMs, 960, 146, out var scaleMaxMs);
			RawImage obj2 = Ui.Place<RawImage>(((Component)Ui.Empty(((Component)obj).transform, "GraphImg")).gameObject.AddComponent<RawImage>(), 8f, 26f, x - 16f, num5 - 34f);
			obj2.texture = (Texture)(object)_graphTex;
			((Graphic)obj2).raycastTarget = false;
			string text2 = string.Format(arg2: ColorUtility.ToHtmlStringRGB(Ui.Main), format: "FRAMETIME TIMELINE (0 - {0:0} ms)   {1}   <color=#{2}>CURVE = CURRENT</color>   <color=#37C364>GREEN = 16.7ms (60 FPS)</color>   <color=#E1AF32>GOLD = 33.3ms (30 FPS)</color>   <color=#FF4C44>RED = SPIKE</color>", arg0: scaleMaxMs, arg1: "·");
			if (baseRun != null)
			{
				text2 += "   <color=#B9C3D2>DASHED = BASELINE</color>";
			}
			Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)obj).transform, text2, 12f, Ui.InkSoft, (TextAlignmentOptions)257), 12f, 5f, x - 24f, 18f);
			num += num5 + 14f;
			float num6 = 16f;
			float leftW = x * 0.57f;
			float num7 = leftW + num6;
			float rightW = x - num7;
			float num8 = y - num - 32f;
			bool num9 = r.Moons != null && r.Moons.Length > 1;
			Image pBox = Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "PhaseBox", Ui.Surface), 0f, num, leftW, num8);
			Ui.Frame(((Component)pBox).transform, Ui.Line);
			float py;
			if (num9)
			{
				((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)pBox).transform, $"PER-MOON BREAKDOWN ({r.Moons.Length} MOONS BENCHMARKED)", 13f, Ui.Main, (TextAlignmentOptions)257), 14f, 10f, leftW - 28f, 18f)).characterSpacing = 3f;
				TableHeader(((Component)pBox).transform, 34f, leftW, new(string, float)[8]
				{
					("MOON", 0.24f),
					("LOAD", 0.1f),
					("AVG", 0.11f),
					("1% LOW", 0.11f),
					("0.1%", 0.11f),
					("MAX ms", 0.11f),
					(">100ms", 0.1f),
					("RAM", 0.12f)
				});
				RectTransform parent = Ui.Scroller(((Component)pBox).transform, 0f, 60f, leftW, num8 - 68f, (float)r.Moons.Length * 32f + 8f);
				for (int num10 = 0; num10 < r.Moons.Length; num10++)
				{
					MoonRunStats moonRunStats = r.Moons[num10];
					TableRow((Transform)(object)parent, (float)num10 * 32f, leftW, new(string, float, Color)[8]
					{
						(moonRunStats.Moon, 0.24f, Ui.Ink),
						($"{moonRunStats.LandingLoadSec:0.1}s", 0.1f, Ui.InkSoft),
						($"{moonRunStats.AvgFps:0.0}", 0.11f, Ui.Main),
						($"{moonRunStats.Low1Fps:0.0}", 0.11f, Ui.Good),
						($"{moonRunStats.Low01Fps:0.0}", 0.11f, Ui.Gold),
						($"{moonRunStats.MaxMs:0.1}", 0.11f, (moonRunStats.MaxMs > 100f) ? Ui.Warn : Ui.InkSoft),
						(moonRunStats.Over100Ms.ToString(), 0.1f, (moonRunStats.Over100Ms > 0) ? Ui.Warn : Ui.Good),
						($"{moonRunStats.RamEndMb}M", 0.12f, Ui.InkSoft)
					});
				}
			}
			else
			{
				((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)pBox).transform, "PHASE PERFORMANCE BREAKDOWN", 13f, Ui.Main, (TextAlignmentOptions)257), 14f, 10f, leftW - 28f, 18f)).characterSpacing = 3f;
				py = 36f;
				TableHeader(((Component)pBox).transform, py, leftW, new(string, float)[8]
				{
					("PHASE", 0.18f),
					("DUR", 0.08f),
					("AVG FPS", 0.14f),
					("1% LOW", 0.14f),
					("0.1% LOW", 0.12f),
					("P99 ms", 0.11f),
					("MAX ms", 0.11f),
					(">100ms", 0.12f)
				});
				py += 26f;
				PhaseRow(r.Orbit, baseRun?.Orbit);
				PhaseRow(r.Outside, baseRun?.Outside);
				PhaseRow(r.Inside, baseRun?.Inside);
				PhaseRow(r.ReturnOrbit, baseRun?.ReturnOrbit);
				if (!string.IsNullOrEmpty(r.InteriorName))
				{
					Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)pBox).transform, $"Interior: {r.InteriorName} ({r.InteriorNodes} AI nodes, {r.TrapsCount} traps, {r.EnemiesSpawned} enemies)", 12f, Ui.InkFaint, (TextAlignmentOptions)257), 14f, num8 - 26f, leftW - 28f, 20f);
				}
			}
			Image mBox = Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "MemBox", Ui.Surface), num7, num, rightW, num8);
			Ui.Frame(((Component)mBox).transform, Ui.Line);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)mBox).transform, "MEMORY & AUDIO TIMELINE (UNITY + C#)", 13f, Ui.Main, (TextAlignmentOptions)257), 14f, 10f, rightW - 28f, 18f)).characterSpacing = 3f;
			float my = 36f;
			TableHeader(((Component)mBox).transform, my, rightW, new(string, float)[6]
			{
				("STAGE", 0.22f),
				("USED RAM", 0.18f),
				("UNITY", 0.16f),
				("RESERVED", 0.15f),
				("C# HEAP", 0.13f),
				("AUDIO", 0.16f)
			});
			my += 26f;
			MemRow(r.MemMenu, baseRun?.MemMenu);
			MemRow(r.MemOrbit, baseRun?.MemOrbit);
			MemRow(r.MemLanded, baseRun?.MemLanded);
			MemRow(r.MemMoonEnd, baseRun?.MemMoonEnd);
			MemRow(r.MemReturnOrbit, baseRun?.MemReturnOrbit);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)mBox).transform, "Perf mods: " + r.PerfMods, 12f, Ui.InkFaint, (TextAlignmentOptions)257), 14f, num8 - 26f, rightW - 28f, 20f)).overflowMode = (TextOverflowModes)1;
			string text3 = ((!string.IsNullOrEmpty(_statusNote)) ? _statusNote : ("Report log: " + r.LogPath));
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, text3, 13f, (!string.IsNullOrEmpty(_statusNote)) ? Ui.Main : Ui.InkFaint, (TextAlignmentOptions)257), 0f, y - 22f, x, 20f)).overflowMode = (TextOverflowModes)1;
			BenchButton ActBtn(string text4, float bw, Action onClick, bool filled = false)
			{
				rx -= bw;
				BenchButton benchButton4 = Ui.MenuButton((Transform)(object)_body, text4, 13f, onClick, filled);
				Ui.Place<Image>(benchButton4.Fill, rx, 2f, bw, 36f);
				rx -= 8f;
				return benchButton4;
			}
			void MemRow(MemorySnapshot m, MemorySnapshot bm)
			{
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				if (m != null && (m.TotalUsedMb != 0 || m.UnityAllocMb != 0))
				{
					string item = ((bm != null && bm.TotalUsedMb > 0) ? $"{m.TotalUsedMb} ({m.TotalUsedMb - bm.TotalUsedMb:+#;-#;0})" : $"{m.TotalUsedMb} MB");
					TableRow(((Component)mBox).transform, my, rightW, new(string, float, Color)[6]
					{
						(m.Label.ToUpperInvariant(), 0.22f, Ui.Ink),
						(item, 0.18f, Ui.Main),
						($"{m.UnityAllocMb} MB", 0.16f, Ui.InkSoft),
						($"{m.UnityReservedMb} MB", 0.15f, Ui.InkSoft),
						($"{m.MonoUsedMb} MB", 0.13f, Ui.InkSoft),
						($"{m.UnpackedAudioMb} MB", 0.16f, Ui.Gold)
					});
					my += 32f;
				}
			}
			void PhaseRow(PhaseStats p, PhaseStats bp)
			{
				//IL_00d1: 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_0113: 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_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
				if (p != null && p.Frames != 0)
				{
					string item = ((bp != null && bp.Frames > 0) ? $"{p.AvgFps:0.0} ({FormatSign(p.AvgFps - bp.AvgFps)})" : $"{p.AvgFps:0.0}");
					string item2 = ((bp != null && bp.Frames > 0) ? $"{p.Low1Fps:0.0} ({FormatSign(p.Low1Fps - bp.Low1Fps)})" : $"{p.Low1Fps:0.0}");
					TableRow(((Component)pBox).transform, py, leftW, new(string, float, Color)[8]
					{
						(p.Name.ToUpperInvariant(), 0.18f, Ui.Ink),
						($"{p.DurationSec:0}s", 0.08f, Ui.InkSoft),
						(item, 0.14f, Ui.Main),
						(item2, 0.14f, Ui.Good),
						($"{p.Low01Fps:0.0}", 0.12f, Ui.Gold),
						($"{p.P99Ms:0.1}", 0.11f, Ui.InkSoft),
						($"{p.MaxMs:0.1}", 0.11f, (p.MaxMs > 100f) ? Ui.Warn : Ui.InkSoft),
						(p.Over100Ms.ToString(), 0.12f, (p.Over100Ms > 0) ? Ui.Warn : Ui.Good)
					});
					py += 34f;
				}
			}
		}

		private static void BuildHistoryTab()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			float x = _body.sizeDelta.x;
			float y = _body.sizeDelta.y;
			IReadOnlyList<BenchmarkReport> all = ReportStore.All;
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, string.Format("SAVED BENCHMARK RUNS ({0})  {1}  STORED IN BepInEx/BaconBenchmark/runs/", all.Count, "·"), 14f, Ui.Main, (TextAlignmentOptions)257), 0f, 4f, x - 220f, 22f)).characterSpacing = 2f;
			Ui.Place<Image>(Ui.MenuButton((Transform)(object)_body, "COPY RUNS FOLDER", 13f, delegate
			{
				GUIUtility.systemCopyBuffer = ReportStore.RunsDir;
				_statusNote = "COPIED · " + ReportStore.RunsDir;
				Rebuild();
			}).Fill, x - 196f, 0f, 196f, 32f);
			if (all.Count == 0)
			{
				Ui.Stretch(((TMP_Text)Ui.Label((Transform)(object)_body, "No benchmark runs recorded yet.", 18f, Ui.InkSoft, (TextAlignmentOptions)514)).rectTransform);
				return;
			}
			float num = 58f;
			float num2 = 8f;
			RectTransform parent = Ui.Scroller((Transform)(object)_body, 0f, 42f, x, y - 72f, (float)all.Count * (num + num2) + 12f);
			for (int num3 = 0; num3 < all.Count; num3++)
			{
				BenchmarkReport run = all[num3];
				bool flag = _shown == run;
				bool isBase = _baseline == run;
				float y2 = (float)num3 * (num + num2);
				Image val = Ui.Place<Image>(Ui.Panel((Transform)(object)parent, "RunRow", flag ? Ui.Accent(0.12f) : Ui.Surface), 0f, y2, x - 8f, num);
				Ui.Frame(((Component)val).transform, flag ? Ui.Main : (isBase ? Ui.Gold : Ui.Line), (flag || isBase) ? 1.5f : 1f);
				string text = (string.IsNullOrEmpty(run.Tag) ? "" : ("[" + run.Tag + "]  "));
				string text2 = string.Format("{0}{1}  {2}  {3}  {4}  {5}  {6}  Seed {7}  {8}  {9}", text, run.Preset, "·", run.MoonActual, "·", run.Weather, "·", run.Seed, "·", run.GameRules);
				string text3 = string.Format("{0}  {1}  {2} mods  {3}  Avg {4:0.0} FPS  |  1% {5:0.0}  |  0.1% {6:0.0}  |  Peak {7} MB  |  Audio {8} MB", run.Timestamp, "·", run.ModCount, "·", run.Overall.AvgFps, run.Overall.Low1Fps, run.Overall.Low01Fps, run.PeakWorkingSetMb, run.MemLanded.UnpackedAudioMb);
				((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)val).transform, text2, 14.5f, Ui.Ink, (TextAlignmentOptions)257), 14f, 8f, x - 380f, 22f)).overflowMode = (TextOverflowModes)1;
				((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)val).transform, text3, 12.5f, Ui.InkSoft, (TextAlignmentOptions)257), 14f, 32f, x - 380f, 18f)).overflowMode = (TextOverflowModes)1;
				Ui.Place<Image>(Ui.MenuButton(((Component)val).transform, "VIEW", 13f, delegate
				{
					_shown = run;
					_tab = Tab.Results;
					Rebuild();
				}, flag).Fill, x - 122f, 12f, 102f, 34f);
				BenchButton benchButton = Ui.MenuButton(((Component)val).transform, isBase ? "BASELINE" : "COMPARE", 13f, delegate
				{
					_baseline = (isBase ? null : run);
					if (_shown == null || _shown == run)
					{
						_shown = ReportStore.All.FirstOrDefault((BenchmarkReport benchmarkReport) => benchmarkReport != run) ?? run;
					}
					_tab = Tab.Results;
					Rebuild();
				});
				if (isBase)
				{
					benchButton.Normal = new Color(Ui.Gold.r, Ui.Gold.g, Ui.Gold.b, 0.22f);
					benchButton.FrameNormal = (benchButton.FrameHover = Ui.Gold);
					benchButton.Apply(over: false);
					if ((Object)(object)benchButton.Label != (Object)null)
					{
						((Graphic)benchButton.Label).color = Ui.Gold;
					}
				}
				Ui.Place<Image>(benchButton.Fill, x - 246f, 12f, 114f, 34f);
			}
			if (!string.IsNullOrEmpty(_statusNote))
			{
				Ui.Place<TextMeshProUGUI>(Ui.Label((Transform)(object)_body, _statusNote, 13f, Ui.Main, (TextAlignmentOptions)257), 0f, y - 22f, x, 20f);
			}
		}

		private static void HeroCard(float x, float y, float w, float h, string title, string big, string sub, string delta, Color accent)
		{
			//IL_000a: 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_0041: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			Image val = Ui.Place<Image>(Ui.Panel((Transform)(object)_body, "Hero", Ui.Surface), x, y, w, h);
			Ui.Frame(((Component)val).transform, Ui.Line);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)val).transform, title, 12f, Ui.InkSoft, (TextAlignmentOptions)257), 14f, 10f, w - 28f, 16f)).characterSpacing = 2.5f;
			Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)val).transform, big, 30f, Ui.Ink, (TextAlignmentOptions)257), 14f, 30f, w - 28f, 36f);
			if (!string.IsNullOrEmpty(delta))
			{
				Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)val).transform, delta, 13.5f, accent, (TextAlignmentOptions)516), 14f, 38f, w - 28f, 22f);
			}
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(((Component)val).transform, sub, 11.5f, Ui.InkFaint, (TextAlignmentOptions)257), 14f, h - 22f, w - 28f, 18f)).overflowMode = (TextOverflowModes)1;
		}

		private static void TableHeader(Transform parent, float y, float w, (string text, float frac)[] cols)
		{
			//IL_0038: 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)
			float num = 14f;
			float num2 = w - 28f;
			for (int i = 0; i < cols.Length; i++)
			{
				(string text, float frac) tuple = cols[i];
				string item = tuple.text;
				float item2 = tuple.frac;
				float num3 = num2 * item2;
				Ui.Place<TextMeshProUGUI>(Ui.Label(parent, item, 11.5f, Ui.InkFaint, (TextAlignmentOptions)257), num, y, num3, 18f);
				num += num3;
			}
			Ui.Place<Image>(Ui.Panel(parent, "HLine", Ui.Accent(0.22f)), 14f, y + 20f, num2, 1f);
		}

		private static void TableRow(Transform parent, float y, float w, (string text, float frac, Color col)[] cols)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			float num = 14f;
			float num2 = w - 28f;
			for (int i = 0; i < cols.Length; i++)
			{
				(string text, float frac, Color col) tuple = cols[i];
				string item = tuple.text;
				float item2 = tuple.frac;
				Color item3 = tuple.col;
				float num3 = num2 * item2;
				((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(parent, item, 13.5f, item3, (TextAlignmentOptions)257), num, y, num3, 22f)).overflowMode = (TextOverflowModes)1;
				num += num3;
			}
			Ui.Place<Image>(Ui.Panel(parent, "RLine", Ui.Accent(0.08f)), 14f, y + 26f, num2, 1f);
		}

		private static void StepperRow(Transform parent, float x, float y, float w, string label, string desc, string val, Action down, Action up)
		{
			//IL_0014: 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_00e3: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			float num = 210f;
			float num2 = 34f;
			Ui.Place<TextMeshProUGUI>(Ui.Label(parent, label, 15f, Ui.Ink, (TextAlignmentOptions)257), x, y + 4f, w - num - 14f, 20f);
			((TMP_Text)Ui.Place<TextMeshProUGUI>(Ui.Label(parent, desc, 11.5f, Ui.InkSoft, (TextAlignmentOptions)257), x, y + 26f, w - num - 14f, 18f)).overflowMode = (TextOverflowModes)1;
			float num3 = x + w - num;
			Ui.Place<Image>(Ui.MenuButton(parent, "<", 15f, down).Fill, num3, y + 8f, num2, 34f);
			Ui.Place<Image>(Ui.MenuButton(parent, ">", 15f, up).Fill, num3 + num - num2, y + 8f, num2, 34f);
			Image obj = Ui.Place<Image>(Ui.Panel(parent, "Val", Ui.Window), num3 + num2 + 4f, y + 8f, num - num2 * 2f - 8f, 34f);
			Ui.Frame(((Component)obj).transform, Ui.Line);
			Ui.Stretch(((TMP_Text)Ui.Label(((Component)obj).transform, val, 14f, Ui.Main, (TextAlignmentOptions)514)).rectTransform);
			Ui.Place<Image>(Ui.Panel(parent, "Div", Ui.Accent(0.08f)), x, y + 52f, w, 1f);
		}

		private static TMP_InputField CreateInputField(Transform parent, float x, float y, float w, float h, string value, string placeholder, Action<string> onChanged)
		{
			//IL_0014: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			Image obj = Ui.Place<Image>(Ui.Panel(parent, "Input", Ui.Window), x, y, w, h);
			((Graphic)obj).raycastTarget = true;
			Ui.Frame(((Component)obj).transform, Ui.Line);
			RectTransform val = Ui.Empty(((Component)obj).transform, "Area");
			Ui.Stretch(val);
			val.offsetMin = new Vector2(8f, 4f);
			val.offsetMax = new Vector2(-8f, -4f);
			TextMeshProUGUI val2 = Ui.Label((Transform)(object)val, placeholder, 14f, Ui.InkFaint, (TextAlignmentOptions)4097);
			Ui.Stretch(((TMP_Text)val2).rectTransform);
			TextMeshProUGUI val3 = Ui.Label((Transform)(object)val, value ?? "", 14f, Ui.Main, (TextAlignmentOptions)4097);
			Ui.Stretch(((TMP_Text)val3).rectTransform);
			TMP_InputField obj2 = ((Component)obj).gameObject.AddComponent<TMP_InputField>();
			obj2.textViewport = val;
			obj2.textComponent = (TMP_Text)(object)val3;
			obj2.placeholder = (Graphic)(object)val2;
			obj2.characterLimit = 24;
			obj2.text = value ?? "";
			((UnityEvent<string>)(object)obj2.onValueChanged).AddListener((UnityAction<string>)delegate(string v)
			{
				onChanged?.Invoke(v);
			});
			return obj2;
		}

		private static string FormatSign(float d)
		{
			return ((d >= 0f) ? "+" : "") + d.ToString("0.0");
		}

		private static string DeltaText(float diff, float baseVal, string unit)
		{
			float num = ((Mathf.Abs(baseVal) > 0.01f) ? (diff / baseVal * 100f) : 0f);
			string arg = ((diff >= 0f) ? "+" : "");
			string text = ((unit == "MB") ? $"{arg}{diff:0}" : $"{arg}{diff:0.1}");
			return string.Format("{0} {1} ({2}{3:0}%)", text, unit, (num >= 0f) ? "+" : "", num);
		}

		private static Color DeltaColor(float diff, bool higherBetter)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Abs(diff) < 0.05f)
			{
				return Ui.InkSoft;
			}
			if (!(higherBetter ? (diff > 0f) : (diff < 0f)))
			{
				return Ui.Warn;
			}
			return Ui.Good;
		}
	}
	internal sealed class MenuButton : MonoBehaviour
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Open;
		}

		private static readonly Color Orange = new Color(1f, 0.42f, 0.13f);

		private static readonly Color Border = new Color(0.72f, 0.05f, 0.04f);

		private MenuManager _menu;

		private GameObject _button;

		[HarmonyPatch(typeof(MenuManager), "Start")]
		[HarmonyPostfix]
		private static void OnMenuStart(MenuManager __instance)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			try
			{
				if ((Object)(object)__instance == (Object)null || __instance.isInitScene || (Object)(object)__instance.menuButtons == (Object)null)
				{
					return;
				}
				Canvas componentInParent = __instance.menuButtons.GetComponentInParent<Canvas>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					GameObject val = new GameObject("BaconBenchmark MenuButton", new Type[1] { typeof(RectTransform) });
					val.transform.SetParent(((Component)componentInParent.rootCanvas).transform, false);
					Ui.Stretch((RectTransform)val.transform);
					MenuButton menuButton = val.AddComponent<MenuButton>();
					menuButton._menu = __instance;
					TMP_Text componentInChildren = __instance.menuButtons.GetComponentInChildren<TMP_Text>(true);
					if ((Object)(object)componentInChildren != (Object)null && (Object)(object)Ui.Font == (Object)null)
					{
						Ui.Font = componentInChildren.font;
					}
					menuButton.BuildButton(((Object)(object)componentInChildren != (Object)null) ? componentInChildren.font : Ui.Font);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("MenuButton failed: " + ex.Message));
			}
		}

		private void BuildButton(TMP_FontAsset font)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown