Decompiled source of CruiseAssistPlus v0.3.7

CruiseAssistPlus.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CruiseAssistPlus.Api;
using CruiseAssistPlus.Core;
using CruiseAssistPlus.Patches;
using CruiseAssistPlus.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CruiseAssistPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.7.0")]
[assembly: AssemblyInformationalVersion("0.3.7+5cc2b2c06ba217c8262962bd08ddc7675bae76e4")]
[assembly: AssemblyProduct("CruiseAssistPlus")]
[assembly: AssemblyTitle("CruiseAssistPlus")]
[assembly: AssemblyVersion("0.3.7.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 CruiseAssistPlus
{
	[BepInPlugin("com.livinginstinkt.dsp.cruiseassistplus", "CruiseAssistPlus", "0.3.7")]
	public class CruiseAssistPlusPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.livinginstinkt.dsp.cruiseassistplus";

		public const string Name = "CruiseAssistPlus";

		public const string Version = "0.3.7";

		internal static ManualLogSource Log;

		internal static CruiseAssistPlusPlugin Instance;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> RespectManualInput;

		internal static ConfigEntry<float> TurnRate;

		internal static ConfigEntry<float> MinTurnAngle;

		internal static ConfigEntry<int> UIScale;

		internal static ConfigEntry<bool> MiniView;

		internal static ConfigEntry<bool> HideHudWhenNotInSpace;

		internal static ConfigEntry<KeyboardShortcut> ToggleHudKey;

		internal static ConfigEntry<bool> BlockClickThrough;

		internal static ConfigEntry<bool> UseGameSkin;

		internal static ConfigEntry<bool> UseGameFont;

		internal static ConfigEntry<bool> MarkVisited;

		internal static ConfigEntry<bool> SelectFocus;

		internal static ConfigEntry<bool> HideDuplicateHistory;

		internal static ConfigEntry<bool> AutoDisableLockCursor;

		internal static ConfigEntry<bool> SeedInterceptEta;

		internal static ConfigEntry<float> ListRefreshSeconds;

		internal static ConfigEntry<int> MaxListRows;

		internal static ConfigEntry<bool> ShowSeeds;

		internal static ConfigEntry<bool> ShowCommunicators;

		internal static ConfigEntry<bool> DebugLog;

		internal static ConfigEntry<bool> DebugWindow;

		public static CruiseState State = CruiseState.Inactive;

		public static StarData TargetStar;

		public static PlanetData TargetPlanet;

		public static VectorLF3 TargetUPos;

		public static double TargetRange;

		public static NavTargetKind TargetKind;

		public static EnemyDFHiveSystem TargetHive;

		public static int TargetEnemyId;

		public static int TargetMsgId;

		public static string TargetName;

		public static double TargetClosingSpeed;

		public static bool SuppressAutoArrival;

		public static StarData SelectTargetStar;

		public static PlanetData SelectTargetPlanet;

		public static int SelectTargetAstroId;

		public static StarData ReticuleTargetStar;

		public static PlanetData ReticuleTargetPlanet;

		public static NavTargetKind SelectTargetKind = NavTargetKind.None;

		public static EnemyDFHiveSystem SelectTargetHive;

		public static int SelectTargetEnemyId;

		public static int SelectTargetMsgId;

		public static readonly List<int> History = new List<int>();

		public static readonly List<int> Bookmark = new List<int>();

		private static readonly List<INavigatorExtension> _extensions = new List<INavigatorExtension>();

		private Harmony _harmony;

		private static int _lastIndicatorAstroId = -1;

		private static int _lastIndicatorEnemyId = -1;

		private static int _lastIndicatorMsgId = -1;

		private static long _lastErrorLogTick;

		private static double _lastClosingRange = -1.0;

		private static int _lastClosingEnemyId;

		private static long _lastClosingTick;

		private static bool _stateLoaded;

		private static int _loadedSeed;

		public static bool NavEnabled
		{
			get
			{
				if (Enabled != null)
				{
					return Enabled.Value;
				}
				return false;
			}
		}

		public static float UIScaleFactor => (float)((UIScale != null) ? UIScale.Value : 100) / 100f;

		public static bool InSpace
		{
			get
			{
				if (GameMain.mainPlayer != null)
				{
					return GameMain.mainPlayer.sailing;
				}
				return false;
			}
		}

		public static IReadOnlyList<INavigatorExtension> Extensions => _extensions;

		private void Awake()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Expected O, but got Unknown
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Expected O, but got Unknown
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch. When off, sailing behaves exactly like vanilla.");
			RespectManualInput = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RespectManualInput", true, "When true, cruise steering yields the moment you provide movement input. If the mod seems to do nothing on the current game version, try setting this false (a Unity input change can make the game report phantom input every tick).");
			TurnRate = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "TurnRate", 1.6f, new ConfigDescription("Steering aggressiveness numerator (slerp = TurnRate / max(MinTurnAngle, angle)).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			MinTurnAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "MinTurnAngle", 10f, new ConfigDescription("Angle floor for the slerp denominator; larger = gentler turns.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 90f), Array.Empty<object>()));
			UIScale = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "UIScale", 150, new ConfigDescription("HUD scale percent.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(80, 240), Array.Empty<object>()));
			MiniView = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "MiniView", false, "Use the compact HUD layout.");
			HideHudWhenNotInSpace = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "HideHudWhenNotInSpace", false, "Auto-hide the CruiseAssist+ HUD while walking/building on a planet; show it in space.");
			ToggleHudKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("UI", "ToggleHudKey", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Hotkey to show/hide the CruiseAssist+ HUD (use it to reopen a closed HUD).");
			BlockClickThrough = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "BlockClickThrough", true, "Stop clicks on the mod's windows from also reaching what is behind them — placing or selecting a building, dragging the camera, zooming with the wheel, or hitting a DSP panel underneath. Applies to every window of this mod and of AutoPilotPlus. Turn off only if it ever misjudges the cursor position on your setup.");
			UseGameSkin = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "UseGameSkin", true, "Draw the windows in Dyson Sphere Program's style — dark translucent panel, cyan-steel edging, a real title bar — instead of Unity's default grey skin.");
			UseGameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "UseGameFont", true, "Use the typeface DSP's own interface uses (read from the live UI at runtime) rather than Unity's built-in fallback font.");
			MarkVisited = ((BaseUnityPlugin)this).Config.Bind<bool>("Setting", "MarkVisited", true, "Record visited planets in History.");
			SelectFocus = ((BaseUnityPlugin)this).Config.Bind<bool>("Setting", "SelectFocus", true, "Focus the starmap when picking a target.");
			HideDuplicateHistory = ((BaseUnityPlugin)this).Config.Bind<bool>("Setting", "HideDuplicateHistory", true, "Collapse repeats in History.");
			AutoDisableLockCursor = ((BaseUnityPlugin)this).Config.Bind<bool>("Setting", "AutoDisableLockCursor", false, "Auto-unlock the cursor when the sail panel opens (easier window interaction).");
			SeedInterceptEta = ((BaseUnityPlugin)this).Config.Bind<bool>("Setting", "SeedInterceptEta", true, "For a selected Dark Fog seed, show a real intercept ETA on the HUD — range ÷ the actual closing speed (measured from how fast the gap is shrinking, so it accounts for the seed's motion and your heading). Shows \"--\" when you're not gaining on it. When off, the HUD uses the naive range ÷ your speed like a star/planet.");
			ListRefreshSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Performance", "ListRefreshSeconds", 1f, new ConfigDescription("How often (seconds) the Destinations window rescans the galaxy and recomputes distances. Rows are drawn from a cached snapshot in between, so this is the only cost that scales with galaxy size. Raise it if the window still costs FPS on a very large map.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 10f), Array.Empty<object>()));
			MaxListRows = ((BaseUnityPlugin)this).Config.Bind<int>("Performance", "MaxListRows", 250, new ConfigDescription("Maximum entries listed per section, nearest first. Anything beyond the cap is reported as a '… N more' row rather than silently dropped.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(25, 2000), Array.Empty<object>()));
			ShowSeeds = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "ShowDarkFogSeeds", true, "List Dark Fog seeds in flight. This is the largest and most expensive section — it scans every hive's tinder pool, galaxy-wide once Universe Exploration 3 is researched. Turn it off if you only navigate to hives.");
			ShowCommunicators = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "ShowCommunicators", true, "List Dark Fog communicators / cosmic messages in the Dark Fog tab.");
			DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLog", false, "Verbose per-tick diagnostic logging (target resolution, guard trips, steering, arrival). Turn on to see WHY navigation is or isn't acting.");
			DebugWindow = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugWindow", false, "Show the on-screen debug overlay.");
			MainUI.LoadFromConfig(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.livinginstinkt.dsp.cruiseassistplus");
			_harmony.PatchAll(typeof(PlayerMovePatches));
			_harmony.PatchAll(typeof(GameMainPatches));
			_harmony.PatchAll(typeof(UISailPanelPatch));
			_harmony.PatchAll(typeof(InputBlockPatches));
			Log.LogInfo((object)"CruiseAssistPlus v0.3.7 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_harmony = null;
		}

		public static void RegisterExtension(INavigatorExtension ext)
		{
			if (ext != null && !_extensions.Contains(ext))
			{
				_extensions.Add(ext);
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogInfo((object)("Registered navigator extension: " + ext.GetType().FullName));
				}
			}
		}

		public static void UnregisterExtension(Type type)
		{
			_extensions.RemoveAll((INavigatorExtension e) => e.GetType() == type);
		}

		internal static void Dbg(string msg)
		{
			if (DebugLog != null && DebugLog.Value)
			{
				Log.LogInfo((object)("[dbg] " + msg));
			}
		}

		internal static void ThrottledError(string where, Exception e)
		{
			long gameTick = GameMain.gameTick;
			if (gameTick - _lastErrorLogTick >= 120)
			{
				_lastErrorLogTick = gameTick;
				Log.LogError((object)(where + ": " + e.GetType().Name + ": " + e.Message));
			}
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				KeyboardShortcut value = ToggleHudKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					MainUI.Visible = !MainUI.Visible;
				}
				PollIndicatorAndHistory();
			}
			catch (Exception e)
			{
				ThrottledError("Update", e);
			}
		}

		private static void PollIndicatorAndHistory()
		{
			if (GameMain.mainPlayer == null || GameMain.galaxy == null)
			{
				return;
			}
			EnsureLoaded();
			PlayerNavigation navigation = GameMain.mainPlayer.navigation;
			int indicatorAstroId = navigation.indicatorAstroId;
			if (indicatorAstroId != _lastIndicatorAstroId)
			{
				_lastIndicatorAstroId = indicatorAstroId;
				if (indicatorAstroId != 0 && SelectTargetAstroId != indicatorAstroId)
				{
					SetSelectionFromAstroId(indicatorAstroId, fromIndicator: true);
				}
			}
			int indicatorEnemyId = navigation.indicatorEnemyId;
			if (indicatorEnemyId != _lastIndicatorEnemyId)
			{
				_lastIndicatorEnemyId = indicatorEnemyId;
				if (indicatorEnemyId != 0 && SelectTargetEnemyId != indicatorEnemyId)
				{
					SelectEnemy(indicatorEnemyId);
				}
			}
			int indicatorMsgId = navigation.indicatorMsgId;
			if (indicatorMsgId != _lastIndicatorMsgId)
			{
				_lastIndicatorMsgId = indicatorMsgId;
				if (indicatorMsgId != 0 && SelectTargetMsgId != indicatorMsgId)
				{
					SelectMessage(indicatorMsgId);
				}
			}
			if (!MarkVisited.Value || GameMain.localPlanet == null)
			{
				return;
			}
			int pid = GameMain.localPlanet.id;
			if (History.Count != 0 && History[History.Count - 1] == pid)
			{
				return;
			}
			if (HideDuplicateHistory.Value)
			{
				History.RemoveAll((int x) => x == pid);
			}
			if (History.Count >= 128)
			{
				History.RemoveAt(0);
			}
			History.Add(pid);
			SaveState();
		}

		public static void SetSelectionFromAstroId(int astroId, bool fromIndicator = false)
		{
			if (astroId > 1000000)
			{
				if (DarkFog.TryResolveHive(astroId, out var hive))
				{
					SelectHive(hive);
				}
				return;
			}
			SelectTargetKind = ((astroId != 0) ? NavTargetKind.Astro : NavTargetKind.None);
			SelectTargetAstroId = astroId;
			SelectTargetHive = null;
			SelectTargetEnemyId = 0;
			SelectTargetMsgId = 0;
			Astro.Resolve(GameMain.galaxy, astroId, out var star, out var planet);
			SelectTargetStar = star;
			SelectTargetPlanet = planet;
			if (!fromIndicator && GameMain.mainPlayer != null)
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = astroId;
			}
			NotifyTargetChanged(astroId);
			Dbg($"selection set astroId={astroId} star={((star != null) ? star.displayName : null)} planet={((planet != null) ? planet.displayName : null)}");
		}

		public static void SelectHive(EnemyDFHiveSystem hive)
		{
			if (hive == null)
			{
				ClearSelection();
				return;
			}
			SelectTargetKind = NavTargetKind.Hive;
			SelectTargetHive = hive;
			SelectTargetStar = hive.starData;
			SelectTargetPlanet = null;
			SelectTargetAstroId = hive.hiveAstroId;
			SelectTargetEnemyId = 0;
			SelectTargetMsgId = 0;
			if (GameMain.mainPlayer != null)
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = hive.hiveAstroId;
			}
			NotifyTargetChanged(hive.hiveAstroId);
			Dbg($"selection set hive={hive.displayName} astroId={hive.hiveAstroId}");
		}

		public static void SelectEnemy(int enemyId)
		{
			if (enemyId <= 0)
			{
				ClearSelection();
				return;
			}
			SelectTargetKind = NavTargetKind.Enemy;
			SelectTargetEnemyId = enemyId;
			SelectTargetHive = null;
			SelectTargetStar = null;
			SelectTargetPlanet = null;
			SelectTargetAstroId = 0;
			SelectTargetMsgId = 0;
			if (GameMain.mainPlayer != null)
			{
				GameMain.mainPlayer.navigation.indicatorEnemyId = enemyId;
			}
			NotifyTargetChanged(0);
			Dbg($"selection set enemy={enemyId}");
		}

		public static void SelectMessage(int msgId)
		{
			if (msgId <= 0)
			{
				ClearSelection();
				return;
			}
			SelectTargetKind = NavTargetKind.Message;
			SelectTargetMsgId = msgId;
			SelectTargetHive = null;
			SelectTargetStar = null;
			SelectTargetPlanet = null;
			SelectTargetAstroId = 0;
			SelectTargetEnemyId = 0;
			if (GameMain.mainPlayer != null)
			{
				GameMain.mainPlayer.navigation.indicatorMsgId = msgId;
			}
			NotifyTargetChanged(0);
			Dbg($"selection set msg={msgId}");
		}

		public static void SelectStar(StarData star, PlanetData planet)
		{
			if (star == null && planet == null)
			{
				ClearSelection();
			}
			else
			{
				SetSelectionFromAstroId(planet?.id ?? (star.id * 100));
			}
		}

		public static void ClearSelection()
		{
			SelectTargetStar = null;
			SelectTargetPlanet = null;
			SelectTargetAstroId = 0;
			SelectTargetKind = NavTargetKind.None;
			SelectTargetHive = null;
			SelectTargetEnemyId = 0;
			SelectTargetMsgId = 0;
			if (GameMain.mainPlayer != null)
			{
				PlayerNavigation navigation = GameMain.mainPlayer.navigation;
				navigation.indicatorAstroId = 0;
				navigation.indicatorEnemyId = 0;
				navigation.indicatorMsgId = 0;
			}
			_lastIndicatorAstroId = 0;
			_lastIndicatorEnemyId = 0;
			_lastIndicatorMsgId = 0;
			_lastClosingRange = -1.0;
			TargetClosingSpeed = 0.0;
			NotifyTargetChanged(0);
			foreach (INavigatorExtension extension in _extensions)
			{
				try
				{
					extension.SetInactive();
				}
				catch
				{
				}
			}
			Dbg("selection cleared");
		}

		private static void NotifyTargetChanged(int astroId)
		{
			foreach (INavigatorExtension extension in _extensions)
			{
				try
				{
					extension.OnTargetChanged(astroId);
				}
				catch
				{
				}
			}
		}

		internal static void CruiseTick(PlayerMove_Sail move)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			State = CruiseState.Inactive;
			if (!NavEnabled)
			{
				return;
			}
			Player player = ((PlayerAction)move).player;
			if (player == null || !player.sailing || !ResolveActiveTarget(player))
			{
				return;
			}
			foreach (INavigatorExtension extension in _extensions)
			{
				if (extension.OperateSail(move))
				{
					return;
				}
			}
			if (RespectManualInput.Value)
			{
				PlayerController controller = ((PlayerAction)move).controller;
				if ((Object)(object)controller != (Object)null && Mathf.Abs(controller.input0.x) + Mathf.Abs(controller.input0.y) + Mathf.Abs(controller.input1.x) + Mathf.Abs(controller.input1.y) > 0.05f)
				{
					Dbg($"manual input present in0={controller.input0} in1={controller.input1} -> yield");
					return;
				}
			}
			double magnitude = ((VectorLF3)(ref move.visual_uvel)).magnitude;
			if (!(magnitude < 1.0))
			{
				VectorLF3 val = TargetUPos - player.uPosition;
				float num = Vector3.Angle(VectorLF3.op_Implicit(val), VectorLF3.op_Implicit(player.uVelocity));
				float num2 = TurnRate.Value / Mathf.Max(MinTurnAngle.Value, num);
				Vector3 val2 = VectorLF3.op_Implicit(((VectorLF3)(ref val)).normalized * magnitude);
				player.uVelocity = VectorLF3.op_Implicit(Vector3.Slerp(VectorLF3.op_Implicit(player.uVelocity), val2, num2));
				State = CruiseState.Guiding;
				Dbg($"cruise steer angle={num:0.0} t={num2:0.000} speed={magnitude:0} range={Astro.RangeToString(TargetRange)}");
			}
		}

		public static bool ResolveActiveTarget(Player player)
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			TargetStar = null;
			TargetPlanet = null;
			TargetHive = null;
			TargetEnemyId = 0;
			TargetMsgId = 0;
			TargetKind = NavTargetKind.None;
			TargetName = null;
			switch (SelectTargetKind)
			{
			case NavTargetKind.Hive:
				return ResolveHiveTarget(player);
			case NavTargetKind.Enemy:
				return ResolveEnemyTarget(player);
			case NavTargetKind.Message:
				return ResolveMessageTarget(player);
			default:
			{
				StarData localStar = GameMain.localStar;
				PlanetData localPlanet = GameMain.localPlanet;
				if (SelectTargetStar != null)
				{
					if (localStar != null && SelectTargetStar.id == localStar.id)
					{
						if (SelectTargetPlanet == null)
						{
							if (localPlanet != null && !SuppressAutoArrival)
							{
								Dbg("arrived (system goal) -> clear");
								ClearSelection();
								return false;
							}
							TargetStar = SelectTargetStar;
						}
						else if (localPlanet != null && SelectTargetPlanet.id == localPlanet.id)
						{
							if (!SuppressAutoArrival)
							{
								Dbg("arrived (planet goal) -> clear");
								ClearSelection();
								return false;
							}
							TargetPlanet = SelectTargetPlanet;
						}
						else
						{
							TargetPlanet = SelectTargetPlanet;
						}
					}
					else
					{
						TargetStar = SelectTargetStar;
					}
				}
				else if (ReticuleTargetPlanet != null)
				{
					TargetPlanet = ReticuleTargetPlanet;
				}
				else if (ReticuleTargetStar != null)
				{
					TargetStar = ReticuleTargetStar;
				}
				if (TargetPlanet != null)
				{
					TargetUPos = TargetPlanet.uPosition;
				}
				else
				{
					if (TargetStar == null)
					{
						return false;
					}
					TargetUPos = TargetStar.uPosition;
				}
				TargetKind = NavTargetKind.Astro;
				VectorLF3 val = TargetUPos - player.uPosition;
				TargetRange = ((VectorLF3)(ref val)).magnitude;
				return true;
			}
			}
		}

		private static bool ResolveHiveTarget(Player player)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			EnemyDFHiveSystem selectTargetHive = SelectTargetHive;
			if (selectTargetHive == null || !DarkFog.TryHivePos(selectTargetHive, out var pos))
			{
				Dbg("hive gone -> clear");
				ClearSelection();
				return false;
			}
			VectorLF3 val = pos - player.uPosition;
			double magnitude = ((VectorLF3)(ref val)).magnitude;
			if (magnitude < 30000.0)
			{
				Dbg("arrived (hive) -> clear");
				ClearSelection();
				return false;
			}
			TargetKind = NavTargetKind.Hive;
			TargetHive = selectTargetHive;
			TargetStar = selectTargetHive.starData;
			TargetUPos = pos;
			TargetRange = magnitude;
			TargetName = DarkFog.HiveName(selectTargetHive);
			return true;
		}

		private static bool ResolveEnemyTarget(Player player)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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)
			if (!DarkFog.TryResolveEnemy(SelectTargetEnemyId, out var pos, out var enemy))
			{
				Dbg("enemy gone -> clear");
				ClearSelection();
				return false;
			}
			VectorLF3 val = pos - player.uPosition;
			double magnitude = ((VectorLF3)(ref val)).magnitude;
			if (magnitude < 3000.0)
			{
				Dbg("arrived (enemy) -> clear");
				ClearSelection();
				return false;
			}
			TargetKind = NavTargetKind.Enemy;
			TargetEnemyId = SelectTargetEnemyId;
			TargetUPos = pos;
			TargetRange = magnitude;
			TargetName = DarkFog.EnemyName(enemy);
			UpdateClosingSpeed(SelectTargetEnemyId, magnitude);
			return true;
		}

		private static void UpdateClosingSpeed(int enemyId, double range)
		{
			long gameTick = GameMain.gameTick;
			long num = gameTick - _lastClosingTick;
			if (enemyId != _lastClosingEnemyId || _lastClosingRange < 0.0 || num <= 0 || num > 30)
			{
				_lastClosingEnemyId = enemyId;
				_lastClosingRange = range;
				_lastClosingTick = gameTick;
				TargetClosingSpeed = 0.0;
			}
			else
			{
				double num2 = (_lastClosingRange - range) / ((double)num / 60.0);
				TargetClosingSpeed = TargetClosingSpeed * 0.9 + num2 * 0.1;
				_lastClosingRange = range;
				_lastClosingTick = gameTick;
			}
		}

		private static bool ResolveMessageTarget(Player player)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!DarkFog.TryResolveMessage(SelectTargetMsgId, out var msg))
			{
				Dbg("msg gone -> clear");
				ClearSelection();
				return false;
			}
			VectorLF3 val = msg.uPosition - player.uPosition;
			double magnitude = ((VectorLF3)(ref val)).magnitude;
			if (magnitude < 2000.0)
			{
				Dbg("arrived (msg) -> clear");
				ClearSelection();
				return false;
			}
			TargetKind = NavTargetKind.Message;
			TargetMsgId = SelectTargetMsgId;
			TargetStar = msg.nearStar;
			TargetUPos = msg.uPosition;
			TargetRange = magnitude;
			TargetName = DarkFog.MessageName(msg);
			return true;
		}

		internal static void ForwardFly(PlayerMove_Fly m)
		{
			foreach (INavigatorExtension extension in _extensions)
			{
				try
				{
					if (extension.OperateFly(m))
					{
						break;
					}
				}
				catch (Exception e)
				{
					ThrottledError("OperateFly", e);
				}
			}
		}

		internal static void ForwardDrift(PlayerMove_Drift m)
		{
			foreach (INavigatorExtension extension in _extensions)
			{
				try
				{
					if (extension.OperateDrift(m))
					{
						break;
					}
				}
				catch (Exception e)
				{
					ThrottledError("OperateDrift", e);
				}
			}
		}

		internal static void ForwardWalk(PlayerMove_Walk m)
		{
			foreach (INavigatorExtension extension in _extensions)
			{
				try
				{
					if (extension.OperateWalk(m))
					{
						break;
					}
				}
				catch (Exception e)
				{
					ThrottledError("OperateWalk", e);
				}
			}
		}

		private static void EnsureLoaded()
		{
			if (!((Object)(object)Instance == (Object)null) && GameMain.galaxy != null && (!_stateLoaded || _loadedSeed != GameMain.galaxy.seed))
			{
				LoadState();
			}
		}

		public static void SaveState()
		{
			if ((Object)(object)Instance == (Object)null || GameMain.galaxy == null)
			{
				return;
			}
			int seed = GameMain.galaxy.seed;
			if (!_stateLoaded || _loadedSeed != seed)
			{
				return;
			}
			try
			{
				((BaseUnityPlugin)Instance).Config.Bind<string>("Save", $"History_{seed}", "", (ConfigDescription)null).Value = string.Join(",", History);
				((BaseUnityPlugin)Instance).Config.Bind<string>("Save", $"Bookmark_{seed}", "", (ConfigDescription)null).Value = string.Join(",", Bookmark);
				((BaseUnityPlugin)Instance).Config.Save();
				Dbg($"saved state seed={seed} history={History.Count} bookmarks={Bookmark.Count}");
			}
			catch (Exception e)
			{
				ThrottledError("SaveState", e);
			}
		}

		public static void LoadState()
		{
			if ((Object)(object)Instance == (Object)null || GameMain.galaxy == null)
			{
				return;
			}
			try
			{
				int seed = GameMain.galaxy.seed;
				History.Clear();
				Bookmark.Clear();
				ParseIds(((BaseUnityPlugin)Instance).Config.Bind<string>("Save", $"History_{seed}", "", (ConfigDescription)null).Value, History);
				ParseIds(((BaseUnityPlugin)Instance).Config.Bind<string>("Save", $"Bookmark_{seed}", "", (ConfigDescription)null).Value, Bookmark);
				_loadedSeed = seed;
				_stateLoaded = true;
				Dbg($"loaded state seed={seed} history={History.Count} bookmarks={Bookmark.Count}");
			}
			catch (Exception e)
			{
				ThrottledError("LoadState", e);
			}
		}

		private static void ParseIds(string csv, List<int> into)
		{
			if (string.IsNullOrEmpty(csv))
			{
				return;
			}
			string[] array = csv.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				if (int.TryParse(array[i], out var result) && result != 0)
				{
					into.Add(result);
				}
			}
		}

		private void OnGUI()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			UIBlocker.BeginPass();
			if ((Object)(object)GameMain.instance == (Object)null || GameMain.mainPlayer == null || (Object)(object)UIRoot.instance == (Object)null || (Object)(object)UIRoot.instance.uiGame == (Object)null || !((Component)UIRoot.instance.uiGame).gameObject.activeSelf)
			{
				return;
			}
			GUISkin skin = GUI.skin;
			Matrix4x4 matrix = GUI.matrix;
			try
			{
				DspSkin.Apply();
				float num = (float)UIScale.Value / 100f;
				GUIUtility.ScaleAroundPivot(new Vector2(num, num), Vector2.zero);
				MainUI.OnGUI();
				StarListUI.OnGUI();
				ConfigUI.OnGUI();
				if (DebugWindow.Value)
				{
					DebugUI.OnGUI();
				}
				foreach (INavigatorExtension extension in _extensions)
				{
					try
					{
						extension.OnGUI();
					}
					catch
					{
					}
				}
			}
			catch (Exception e)
			{
				ThrottledError("OnGUI", e);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.skin = skin;
			}
		}
	}
}
namespace CruiseAssistPlus.UI
{
	public static class ConfigUI
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__Draw;
		}

		private const int WinId = 68203;

		public static Rect Rect = new Rect(450f, 100f, 320f, 340f);

		public static bool Visible = false;

		private static ConfigEntry<float> _left;

		private static ConfigEntry<float> _top;

		public static void LoadFromConfig(ConfigFile cfg)
		{
			_left = cfg.Bind<float>("Window", "ConfigLeft", 450f, (ConfigDescription)null);
			_top = cfg.Bind<float>("Window", "ConfigTop", 100f, (ConfigDescription)null);
			((Rect)(ref Rect)).x = _left.Value;
			((Rect)(ref Rect)).y = _top.Value;
		}

		public static void OnGUI()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (Visible)
			{
				Rect rect = Rect;
				object obj = <>O.<0>__Draw;
				if (obj == null)
				{
					WindowFunction val = Draw;
					<>O.<0>__Draw = val;
					obj = (object)val;
				}
				Rect = GUILayout.Window(68203, rect, (WindowFunction)obj, "", Array.Empty<GUILayoutOption>());
				UIUtil.Settle(ref Rect);
				if (_left != null)
				{
					_left.Value = ((Rect)(ref Rect)).x;
					_top.Value = ((Rect)(ref Rect)).y;
				}
			}
		}

		private static void Draw(int id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			if (UIUtil.BeginTitleBar(Rect, "CruiseAssist+ Config").Button(DspSkin.Glyph("✕", "X")))
			{
				Visible = false;
			}
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Label("HUD", DspSkin.Header, Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.MiniView.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.MiniView.Value, "Compact HUD");
			CruiseAssistPlusPlugin.HideHudWhenNotInSpace.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.HideHudWhenNotInSpace.Value, "Hide HUD when not in space");
			GUILayout.Label($"Reopen HUD hotkey: {CruiseAssistPlusPlugin.ToggleHudKey.Value}", Array.Empty<GUILayoutOption>());
			GUILayout.Label($"UI Scale: {CruiseAssistPlusPlugin.UIScale.Value}%", Array.Empty<GUILayoutOption>());
			int num = (int)GUILayout.HorizontalSlider((float)CruiseAssistPlusPlugin.UIScale.Value, 80f, 240f, Array.Empty<GUILayoutOption>());
			num = Mathf.RoundToInt((float)num / 5f) * 5;
			CruiseAssistPlusPlugin.UIScale.Value = num;
			CruiseAssistPlusPlugin.BlockClickThrough.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.BlockClickThrough.Value, "Block clicks through windows");
			CruiseAssistPlusPlugin.UseGameSkin.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.UseGameSkin.Value, "Game-style windows");
			CruiseAssistPlusPlugin.UseGameFont.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.UseGameFont.Value, "Game font");
			GUILayout.Space(6f);
			GUILayout.Label("Navigation", DspSkin.Header, Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.RespectManualInput.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.RespectManualInput.Value, "Yield to manual input");
			CruiseAssistPlusPlugin.MarkVisited.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.MarkVisited.Value, "Record visited (History)");
			CruiseAssistPlusPlugin.HideDuplicateHistory.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.HideDuplicateHistory.Value, "Collapse duplicate history");
			CruiseAssistPlusPlugin.AutoDisableLockCursor.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.AutoDisableLockCursor.Value, "Unlock cursor on sail panel");
			CruiseAssistPlusPlugin.SeedInterceptEta.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.SeedInterceptEta.Value, "Seed intercept ETA on HUD");
			GUILayout.Space(6f);
			GUILayout.Label("Destinations list", DspSkin.Header, Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.ShowSeeds.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.ShowSeeds.Value, "List Dark Fog seeds");
			CruiseAssistPlusPlugin.ShowCommunicators.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.ShowCommunicators.Value, "List communicators");
			GUILayout.Label($"Refresh every: {CruiseAssistPlusPlugin.ListRefreshSeconds.Value:0.00}s", Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.ListRefreshSeconds.Value = Mathf.Round(GUILayout.HorizontalSlider(CruiseAssistPlusPlugin.ListRefreshSeconds.Value, 0.25f, 10f, Array.Empty<GUILayoutOption>()) * 20f) / 20f;
			GUILayout.Label($"Max rows per section: {CruiseAssistPlusPlugin.MaxListRows.Value}", Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.MaxListRows.Value = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)CruiseAssistPlusPlugin.MaxListRows.Value, 25f, 2000f, Array.Empty<GUILayoutOption>()) / 25f) * 25;
			GUILayout.Space(6f);
			GUILayout.Label("Steering", DspSkin.Header, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Turn rate: {CruiseAssistPlusPlugin.TurnRate.Value:0.0}", Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.TurnRate.Value = GUILayout.HorizontalSlider(CruiseAssistPlusPlugin.TurnRate.Value, 0.2f, 5f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Min turn angle: {CruiseAssistPlusPlugin.MinTurnAngle.Value:0}", Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.MinTurnAngle.Value = GUILayout.HorizontalSlider(CruiseAssistPlusPlugin.MinTurnAngle.Value, 1f, 45f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			GUILayout.Label("Debug", DspSkin.Header, Array.Empty<GUILayoutOption>());
			CruiseAssistPlusPlugin.DebugLog.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.DebugLog.Value, "Verbose debug logging");
			CruiseAssistPlusPlugin.DebugWindow.Value = UIUtil.Toggle(CruiseAssistPlusPlugin.DebugWindow.Value, "Show debug overlay");
			GUILayout.EndVertical();
			UIUtil.DragBar(Rect);
		}
	}
	public static class DebugUI
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__Draw;
		}

		private const int WinId = 68204;

		public static Rect Rect = new Rect(780f, 100f, 300f, 260f);

		public static void OnGUI()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Rect rect = Rect;
			object obj = <>O.<0>__Draw;
			if (obj == null)
			{
				WindowFunction val = Draw;
				<>O.<0>__Draw = val;
				obj = (object)val;
			}
			Rect = GUILayout.Window(68204, rect, (WindowFunction)obj, "", Array.Empty<GUILayoutOption>());
			UIUtil.Settle(ref Rect);
		}

		private static void Draw(int id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			UIUtil.BeginTitleBar(Rect, "CruiseAssist+ Debug");
			Player mainPlayer = GameMain.mainPlayer;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"State: {CruiseAssistPlusPlugin.State}", Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Enabled: {CruiseAssistPlusPlugin.NavEnabled}", Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Extensions: {CruiseAssistPlusPlugin.Extensions.Count}", Array.Empty<GUILayoutOption>());
			if (mainPlayer != null)
			{
				GUILayout.Label($"move state: {mainPlayer.movementState}   sailing: {mainPlayer.sailing}   warping: {mainPlayer.warping}", Array.Empty<GUILayoutOption>());
				PlanetData localPlanet = GameMain.localPlanet;
				VectorLF3 val;
				if (localPlanet != null)
				{
					val = mainPlayer.uPosition - localPlanet.uPosition;
					double num = ((VectorLF3)(ref val)).magnitude - (double)localPlanet.realRadius;
					string arg = (((Object)(object)mainPlayer.controller != (Object)null) ? $"   horzSpeed: {mainPlayer.controller.horzSpeed:0.0}" : "");
					GUILayout.Label($"altitude: {num:0} m{arg}", Array.Empty<GUILayoutOption>());
				}
				else
				{
					GUILayout.Label("altitude: - (in space)", Array.Empty<GUILayoutOption>());
				}
				val = mainPlayer.uVelocity;
				GUILayout.Label($"uVel: {((VectorLF3)(ref val)).magnitude:0.0}", Array.Empty<GUILayoutOption>());
				if ((Object)(object)mainPlayer.controller != (Object)null)
				{
					GUILayout.Label($"input0: {mainPlayer.controller.input0}\ninput1: {mainPlayer.controller.input1}", Array.Empty<GUILayoutOption>());
				}
			}
			StarData localStar = GameMain.localStar;
			GUILayout.Label("localStar: " + (((localStar != null) ? localStar.displayName : null) ?? "-"), Array.Empty<GUILayoutOption>());
			PlanetData localPlanet2 = GameMain.localPlanet;
			GUILayout.Label("localPlanet: " + (((localPlanet2 != null) ? localPlanet2.displayName : null) ?? "-"), Array.Empty<GUILayoutOption>());
			PlanetData targetPlanet = CruiseAssistPlusPlugin.TargetPlanet;
			StarData targetStar = CruiseAssistPlusPlugin.TargetStar;
			GUILayout.Label("target: " + ((targetPlanet != null) ? targetPlanet.displayName : ((targetStar != null) ? targetStar.displayName : "-")), Array.Empty<GUILayoutOption>());
			GUILayout.Label("range: " + Astro.RangeToString(CruiseAssistPlusPlugin.TargetRange), Array.Empty<GUILayoutOption>());
			GUILayout.Label($"indicatorAstroId: {((mainPlayer != null) ? mainPlayer.navigation.indicatorAstroId : 0)}", Array.Empty<GUILayoutOption>());
			GUILayout.Label($"dest rows: {DestinationList.Rows.Count}   last scan: {DestinationList.LastBuildMs:0.00} ms", Array.Empty<GUILayoutOption>());
			GUILayout.Label($"cursor over mod window: {UIBlocker.Blocking}", Array.Empty<GUILayoutOption>());
			GUILayout.Label("game font: " + (((Object)(object)DspSkin.GameFont != (Object)null) ? ((Object)DspSkin.GameFont).name : "-"), Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			UIUtil.DragBar(Rect);
		}
	}
	public static class MainUI
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__Draw;
		}

		private const int WinId = 68201;

		public static Rect Rect = new Rect(100f, 100f, 400f, 150f);

		public static bool Visible = true;

		public static bool Collapsed = false;

		private static ConfigEntry<float> _left;

		private static ConfigEntry<float> _top;

		private static ConfigEntry<bool> _collapsed;

		public static void LoadFromConfig(ConfigFile cfg)
		{
			_left = cfg.Bind<float>("Window", "MainLeft", 100f, (ConfigDescription)null);
			_top = cfg.Bind<float>("Window", "MainTop", 100f, (ConfigDescription)null);
			_collapsed = cfg.Bind<bool>("Window", "MainCollapsed", false, (ConfigDescription)null);
			((Rect)(ref Rect)).x = _left.Value;
			((Rect)(ref Rect)).y = _top.Value;
			Collapsed = _collapsed.Value;
			StarListUI.LoadFromConfig(cfg);
			ConfigUI.LoadFromConfig(cfg);
		}

		public static void OnGUI()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			if (Visible && (!CruiseAssistPlusPlugin.HideHudWhenNotInSpace.Value || CruiseAssistPlusPlugin.InSpace))
			{
				bool value = CruiseAssistPlusPlugin.MiniView.Value;
				((Rect)(ref Rect)).width = (value ? 280 : 400);
				((Rect)(ref Rect)).height = DspSkin.TitleH + (Collapsed ? 4f : (value ? 90f : 128f));
				Rect rect = Rect;
				object obj = <>O.<0>__Draw;
				if (obj == null)
				{
					WindowFunction val = Draw;
					<>O.<0>__Draw = val;
					obj = (object)val;
				}
				Rect = GUILayout.Window(68201, rect, (WindowFunction)obj, "", Array.Empty<GUILayoutOption>());
				UIUtil.Settle(ref Rect);
				if (_left != null)
				{
					_left.Value = ((Rect)(ref Rect)).x;
					_top.Value = ((Rect)(ref Rect)).y;
					_collapsed.Value = Collapsed;
				}
			}
		}

		private static void TitleBar()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			UIUtil.TitleBarCursor titleBarCursor = UIUtil.BeginTitleBar(Rect, "CruiseAssist+");
			if (titleBarCursor.Button(DspSkin.Glyph("✕", "X")))
			{
				Visible = false;
			}
			if (titleBarCursor.Button("Config", 46f))
			{
				ConfigUI.Visible = !ConfigUI.Visible;
			}
			if (titleBarCursor.Button(Collapsed ? "+" : DspSkin.Glyph("–", "-")))
			{
				Collapsed = !Collapsed;
			}
		}

		private static void Draw(int id)
		{
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			TitleBar();
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			double targetRange;
			int num2;
			string text2;
			if (!Collapsed)
			{
				bool flag = CruiseAssistPlusPlugin.State == CruiseState.Guiding;
				StarData targetStar = CruiseAssistPlusPlugin.TargetStar;
				PlanetData targetPlanet = CruiseAssistPlusPlugin.TargetPlanet;
				NavTargetKind targetKind = CruiseAssistPlusPlugin.TargetKind;
				string text = ((!string.IsNullOrEmpty(CruiseAssistPlusPlugin.TargetName)) ? CruiseAssistPlusPlugin.TargetName : ((targetPlanet != null) ? targetPlanet.displayName : ((targetStar != null) ? targetStar.displayName : "(no target)")));
				GUILayout.Label("Target: " + text, DspSkin.Tinted(DspSkin.Status, flag ? DspSkin.Accent : DspSkin.Ink), Array.Empty<GUILayoutOption>());
				if (targetKind != NavTargetKind.None)
				{
					targetRange = CruiseAssistPlusPlugin.TargetRange;
					double num;
					if (GameMain.mainPlayer == null)
					{
						num = 0.0;
					}
					else
					{
						VectorLF3 uVelocity = GameMain.mainPlayer.uVelocity;
						num = ((VectorLF3)(ref uVelocity)).magnitude;
					}
					double speed = num;
					if (targetKind == NavTargetKind.Enemy)
					{
						num2 = (CruiseAssistPlusPlugin.SeedInterceptEta.Value ? 1 : 0);
						if (num2 != 0)
						{
							text2 = Astro.EtaToString(targetRange, CruiseAssistPlusPlugin.TargetClosingSpeed);
							goto IL_00f2;
						}
					}
					else
					{
						num2 = 0;
					}
					text2 = Astro.EtaToString(targetRange, speed);
					goto IL_00f2;
				}
				if (!CruiseAssistPlusPlugin.NavEnabled)
				{
					GUILayout.Label("disabled", DspSkin.Note, Array.Empty<GUILayoutOption>());
				}
				else
				{
					GUILayout.Label("Pick a target from the destinations list.", DspSkin.Note, Array.Empty<GUILayoutOption>());
				}
				goto IL_0178;
			}
			goto IL_0271;
			IL_0178:
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool value = CruiseAssistPlusPlugin.Enabled.Value;
			if (GUILayout.Button(value ? "Enabled" : "Disabled", Array.Empty<GUILayoutOption>()))
			{
				CruiseAssistPlusPlugin.Enabled.Value = !value;
			}
			if (GUILayout.Button("Destinations", Array.Empty<GUILayoutOption>()))
			{
				StarListUI.Visible = !StarListUI.Visible;
			}
			if (GUILayout.Button("Cancel", Array.Empty<GUILayoutOption>()))
			{
				CruiseAssistPlusPlugin.ClearSelection();
			}
			GUILayout.EndHorizontal();
			bool flag2 = false;
			foreach (INavigatorExtension extension in CruiseAssistPlusPlugin.Extensions)
			{
				string text3 = null;
				try
				{
					text3 = extension.PanelLabel;
				}
				catch
				{
				}
				if (string.IsNullOrEmpty(text3))
				{
					continue;
				}
				if (!flag2)
				{
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					flag2 = true;
				}
				if (GUILayout.Button(text3, Array.Empty<GUILayoutOption>()))
				{
					try
					{
						extension.TogglePanel();
					}
					catch
					{
					}
				}
			}
			if (flag2)
			{
				GUILayout.EndHorizontal();
			}
			goto IL_0271;
			IL_0271:
			GUILayout.EndVertical();
			UIUtil.DragBar(Rect);
			return;
			IL_00f2:
			string text4 = text2;
			string text5 = ((num2 != 0) ? "Intercept" : "ETA");
			GUILayout.Label("Range: " + Astro.RangeToString(targetRange) + "    " + text5 + ": " + text4, Array.Empty<GUILayoutOption>());
			goto IL_0178;
		}
	}
	public static class StarListUI
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__Draw;
		}

		private const int WinId = 68202;

		private const float RowH = 22f;

		private const float MinW = 280f;

		private const float MinH = 200f;

		private const float MaxWH = 2000f;

		public static Rect Rect = new Rect(100f, 260f, 360f, 460f);

		public static bool Visible = false;

		private static readonly string[] Tabs = new string[4] { "Stars", "Dark Fog", "History", "Bookmark" };

		private static int _tab;

		private static Vector2 _scroll;

		private static int _expandedStarId = -1;

		private static string _filter = "";

		private static Rect _viewCache = new Rect(0f, 0f, 340f, 360f);

		private static bool _resizing;

		private static ConfigEntry<float> _left;

		private static ConfigEntry<float> _top;

		private static ConfigEntry<float> _width;

		private static ConfigEntry<float> _height;

		private static ConfigEntry<int> _tabCfg;

		public static void LoadFromConfig(ConfigFile cfg)
		{
			_left = cfg.Bind<float>("Window", "StarListLeft", 100f, (ConfigDescription)null);
			_top = cfg.Bind<float>("Window", "StarListTop", 260f, (ConfigDescription)null);
			_width = cfg.Bind<float>("Window", "StarListWidth", 360f, "Destinations window width. Drag the ◢ grip in the window's bottom-right corner to resize.");
			_height = cfg.Bind<float>("Window", "StarListHeight", 460f, "Destinations window height.");
			_tabCfg = cfg.Bind<int>("Window", "StarListTab", 0, (ConfigDescription)null);
			((Rect)(ref Rect)).x = _left.Value;
			((Rect)(ref Rect)).y = _top.Value;
			((Rect)(ref Rect)).width = Mathf.Clamp(_width.Value, 280f, 2000f);
			((Rect)(ref Rect)).height = Mathf.Clamp(_height.Value, 200f, 2000f);
			_tab = Mathf.Clamp(_tabCfg.Value, 0, Tabs.Length - 1);
		}

		public static void OnGUI()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (Visible)
			{
				Rect rect = Rect;
				object obj = <>O.<0>__Draw;
				if (obj == null)
				{
					WindowFunction val = Draw;
					<>O.<0>__Draw = val;
					obj = (object)val;
				}
				Rect = GUILayout.Window(68202, rect, (WindowFunction)obj, "", (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(((Rect)(ref Rect)).width),
					GUILayout.Height(((Rect)(ref Rect)).height)
				});
				UIUtil.Settle(ref Rect);
				if (_left != null)
				{
					_left.Value = ((Rect)(ref Rect)).x;
					_top.Value = ((Rect)(ref Rect)).y;
					_width.Value = ((Rect)(ref Rect)).width;
					_height.Value = ((Rect)(ref Rect)).height;
					_tabCfg.Value = _tab;
				}
			}
		}

		private static void Draw(int id)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			int tab = _tab;
			_tab = GUILayout.Toolbar(_tab, Tabs, Array.Empty<GUILayoutOption>());
			if (_tab != tab)
			{
				_scroll = Vector2.zero;
				DestinationList.Invalidate();
			}
			DrawFilterRow();
			if ((int)current.type == 8)
			{
				DestinationList.EnsureBuilt(_tab, _expandedStarId, _filter, GameMain.mainPlayer);
			}
			List<DestRow> rows = DestinationList.Rows;
			VirtualList virtualList = VirtualList.Begin(VirtualList.ReserveViewport(ref _viewCache), ref _scroll, rows.Count, 22f);
			if (rows.Count == 0)
			{
				GUI.Label(new Rect(4f, 4f, ((Rect)(ref virtualList.Content)).width - 8f, 22f), "(nothing to show)", DspSkin.Note);
			}
			else
			{
				for (int i = virtualList.First; i < virtualList.Last; i++)
				{
					DrawRow(virtualList.RowRect(i, 22f), rows[i]);
				}
			}
			virtualList.End();
			if (UIUtil.BeginTitleBar(Rect, "CruiseAssist+ Destinations").Button(DspSkin.Glyph("✕", "X")))
			{
				Visible = false;
			}
			DrawResizeGrip(current);
			UIUtil.DragBar(Rect);
		}

		private static void DrawFilterRow()
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Find", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			string text = GUILayout.TextField(_filter ?? "", Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(DspSkin.Glyph("×", "x"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
			{
				text = "";
				GUIUtility.keyboardControl = 0;
			}
			GUILayout.EndHorizontal();
			if (text != _filter)
			{
				_filter = text;
				_scroll.y = 0f;
			}
		}

		private static void DrawRow(Rect r, DestRow row)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref r)).x + (float)row.Indent * 14f;
			if (row.Kind == DestRowKind.Header || row.Kind == DestRowKind.Info)
			{
				GUI.Label(new Rect(num + 2f, ((Rect)(ref r)).y, ((Rect)(ref r)).xMax - num - 2f, ((Rect)(ref r)).height), row.Label, (row.Kind == DestRowKind.Header) ? DspSkin.Header : DspSkin.Note);
				return;
			}
			float num2 = ((Rect)(ref r)).xMax;
			if (row.Kind == DestRowKind.Star)
			{
				num2 -= 24f;
				bool flag = row.Star != null && _expandedStarId == row.Star.id;
				if (GUI.Button(new Rect(num2, ((Rect)(ref r)).y, 22f, ((Rect)(ref r)).height), flag ? "-" : "+") && row.Star != null)
				{
					_expandedStarId = (flag ? (-1) : row.Star.id);
					DestinationList.Invalidate();
				}
			}
			else if (row.Kind == DestRowKind.Hive || row.Kind == DestRowKind.Seed || row.Kind == DestRowKind.Comm)
			{
				num2 -= 40f;
				if (GUI.Button(new Rect(num2, ((Rect)(ref r)).y, 38f, ((Rect)(ref r)).height), "SET"))
				{
					SelectDarkFog(row);
				}
			}
			if (_tab == 3 && row.Kind == DestRowKind.Planet)
			{
				num2 -= 22f;
				if (GUI.Button(new Rect(num2, ((Rect)(ref r)).y, 20f, ((Rect)(ref r)).height), "v"))
				{
					Move(CruiseAssistPlusPlugin.Bookmark, row.Id, 1);
				}
				num2 -= 22f;
				if (GUI.Button(new Rect(num2, ((Rect)(ref r)).y, 20f, ((Rect)(ref r)).height), "^"))
				{
					Move(CruiseAssistPlusPlugin.Bookmark, row.Id, -1);
				}
			}
			if (row.Bookmarkable)
			{
				num2 -= 26f;
				bool flag2 = CruiseAssistPlusPlugin.Bookmark.Contains(row.Id);
				if (GUI.Button(new Rect(num2, ((Rect)(ref r)).y, 24f, ((Rect)(ref r)).height), flag2 ? DspSkin.Glyph("★", "+") : DspSkin.Glyph("☆", "-")))
				{
					ToggleBookmark(row.Id);
				}
			}
			if (!string.IsNullOrEmpty(row.Extra))
			{
				num2 -= 56f;
				GUI.Label(new Rect(num2, ((Rect)(ref r)).y, 54f, ((Rect)(ref r)).height), row.Extra, DspSkin.Right);
			}
			num2 -= 82f;
			GUI.Label(new Rect(num2, ((Rect)(ref r)).y, 80f, ((Rect)(ref r)).height), row.Range, DspSkin.Right);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(num, ((Rect)(ref r)).y, Mathf.Max(40f, num2 - num - 4f), ((Rect)(ref r)).height);
			if (row.Kind == DestRowKind.Star || row.Kind == DestRowKind.Planet)
			{
				if (GUI.Button(val, row.Label, DspSkin.Row))
				{
					CruiseAssistPlusPlugin.SelectStar(row.Star, row.Planet);
				}
			}
			else
			{
				GUI.Label(val, row.Label);
			}
		}

		private static void SelectDarkFog(DestRow row)
		{
			switch (row.Kind)
			{
			case DestRowKind.Hive:
				CruiseAssistPlusPlugin.SelectHive(row.Hive);
				break;
			case DestRowKind.Seed:
				CruiseAssistPlusPlugin.SelectEnemy(row.Id);
				break;
			case DestRowKind.Comm:
				CruiseAssistPlusPlugin.SelectMessage(row.Id);
				break;
			}
		}

		private static void ToggleBookmark(int planetId)
		{
			List<int> bookmark = CruiseAssistPlusPlugin.Bookmark;
			if (bookmark.Contains(planetId))
			{
				bookmark.Remove(planetId);
			}
			else if (bookmark.Count < 128)
			{
				bookmark.Add(planetId);
			}
			CruiseAssistPlusPlugin.SaveState();
			DestinationList.Invalidate();
		}

		private static void Move(List<int> list, int id, int delta)
		{
			int num = list.IndexOf(id);
			int num2 = num + delta;
			if (num >= 0 && num2 >= 0 && num2 < list.Count)
			{
				list.RemoveAt(num);
				list.Insert(num2, id);
				CruiseAssistPlusPlugin.SaveState();
				DestinationList.Invalidate();
			}
		}

		private static void DrawResizeGrip(Event e)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0074: Expected I4, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref Rect)).width - 16f, ((Rect)(ref Rect)).height - 16f, 14f, 14f);
			GUI.Label(val, DspSkin.Glyph("◢", "//"), DspSkin.Note);
			EventType type = e.type;
			switch ((int)type)
			{
			case 0:
				if (((Rect)(ref val)).Contains(e.mousePosition))
				{
					_resizing = true;
					e.Use();
				}
				break;
			case 3:
				if (_resizing)
				{
					Rect rect = Rect;
					((Rect)(ref rect)).width = Mathf.Clamp(e.mousePosition.x + 8f, 280f, 2000f);
					((Rect)(ref rect)).height = Mathf.Clamp(e.mousePosition.y + 8f, 200f, 2000f);
					Rect = rect;
					e.Use();
				}
				break;
			case 1:
				if (_resizing)
				{
					_resizing = false;
					e.Use();
				}
				break;
			case 2:
				break;
			}
		}
	}
	public struct VirtualList
	{
		public Rect Content;

		public int First;

		public int Last;

		public static Rect ReserveViewport(ref Rect cached)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.ExpandHeight(true)
			});
			if (((Rect)(ref rect)).width > 1f && ((Rect)(ref rect)).height > 1f)
			{
				cached = rect;
			}
			return cached;
		}

		public static VirtualList Begin(Rect view, ref Vector2 scroll, int rowCount, float rowHeight)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			VirtualList result = new VirtualList
			{
				Content = new Rect(0f, 0f, Mathf.Max(40f, ((Rect)(ref view)).width - 18f), (float)rowCount * rowHeight)
			};
			scroll = GUI.BeginScrollView(view, scroll, result.Content);
			result.First = Mathf.Max(0, Mathf.FloorToInt(scroll.y / rowHeight) - 1);
			result.Last = Mathf.Min(rowCount, result.First + Mathf.CeilToInt(((Rect)(ref view)).height / rowHeight) + 3);
			return result;
		}

		public Rect RowRect(int index, float rowHeight)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(0f, (float)index * rowHeight, ((Rect)(ref Content)).width, rowHeight - 2f);
		}

		public void End()
		{
			GUI.EndScrollView();
		}
	}
}
namespace CruiseAssistPlus.Patches
{
	public static class GameMainPatches
	{
		[HarmonyPatch(typeof(GameMain), "Begin")]
		[HarmonyPostfix]
		public static void BeginPostfix()
		{
			CruiseAssistPlusPlugin.LoadState();
		}

		[HarmonyPatch(typeof(GameMain), "Pause")]
		[HarmonyPrefix]
		public static void PausePrefix()
		{
			CruiseAssistPlusPlugin.SaveState();
		}

		[HarmonyPatch(typeof(GameMain), "End")]
		[HarmonyPrefix]
		public static void EndPrefix()
		{
			CruiseAssistPlusPlugin.SaveState();
		}
	}
	public static class InputBlockPatches
	{
		private static bool Active
		{
			get
			{
				if (CruiseAssistPlusPlugin.BlockClickThrough != null && CruiseAssistPlusPlugin.BlockClickThrough.Value)
				{
					return UIBlocker.Blocking;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(VFInput), "UpdateGameStates")]
		[HarmonyPostfix]
		public static void UpdateGameStatesPostfix()
		{
			UIBlocker.UpdateCursorState();
			if (Active)
			{
				VFInput.onGUI = true;
				bool num = Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2);
				bool flag = Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2);
				if (!num || flag)
				{
					VFInput.onGUIOperate = true;
				}
				VFInput.inScrollView = true;
			}
		}

		[HarmonyPatch(typeof(EventSystem), "RaycastAll")]
		[HarmonyPrefix]
		public static bool RaycastAllPrefix(List<RaycastResult> raycastResults)
		{
			if (!Active)
			{
				return true;
			}
			raycastResults.Clear();
			return false;
		}
	}
	public static class PlayerMovePatches
	{
		[HarmonyPatch(typeof(PlayerMove_Sail), "GameTick")]
		[HarmonyPrefix]
		public static void SailPrefix(PlayerMove_Sail __instance)
		{
			try
			{
				CruiseAssistPlusPlugin.CruiseTick(__instance);
			}
			catch (Exception e)
			{
				CruiseAssistPlusPlugin.ThrottledError("SailPrefix", e);
			}
		}

		[HarmonyPatch(typeof(PlayerMove_Fly), "GameTick")]
		[HarmonyPrefix]
		public static void FlyPrefix(PlayerMove_Fly __instance)
		{
			CruiseAssistPlusPlugin.ForwardFly(__instance);
		}

		[HarmonyPatch(typeof(PlayerMove_Drift), "GameTick")]
		[HarmonyPrefix]
		public static void DriftPrefix(PlayerMove_Drift __instance)
		{
			CruiseAssistPlusPlugin.ForwardDrift(__instance);
		}

		[HarmonyPatch(typeof(PlayerMove_Walk), "GameTick")]
		[HarmonyPrefix]
		public static void WalkPrefix(PlayerMove_Walk __instance)
		{
			CruiseAssistPlusPlugin.ForwardWalk(__instance);
		}
	}
	public static class UISailPanelPatch
	{
		[HarmonyPatch(typeof(UISailPanel), "_OnOpen")]
		[HarmonyPrefix]
		public static void OnOpenPrefix()
		{
			if (CruiseAssistPlusPlugin.AutoDisableLockCursor != null && CruiseAssistPlusPlugin.AutoDisableLockCursor.Value && (Object)(object)UIRoot.instance != (Object)null && (Object)(object)UIRoot.instance.uiGame != (Object)null)
			{
				UIRoot.instance.uiGame.disableLockCursor = true;
			}
		}

		[HarmonyPatch(typeof(UISailPanel), "_OnClose")]
		[HarmonyPrefix]
		public static void OnClosePrefix()
		{
			CruiseAssistPlusPlugin.SaveState();
		}
	}
}
namespace CruiseAssistPlus.Core
{
	public static class DarkFog
	{
		private static readonly Dictionary<int, string> _enemyNames = new Dictionary<int, string>();

		private static SpaceSector Sector => GameMain.spaceSector;

		public static bool TryResolveHive(int astroId, out EnemyDFHiveSystem hive)
		{
			hive = null;
			SpaceSector sector = Sector;
			if (sector == null || astroId <= 1000000)
			{
				return false;
			}
			hive = sector.GetHiveByAstroId(astroId);
			return hive != null;
		}

		public static bool TryHivePos(EnemyDFHiveSystem hive, out VectorLF3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			pos = VectorLF3.zero;
			SpaceSector sector = Sector;
			if (sector == null || hive == null)
			{
				return false;
			}
			int num = hive.hiveAstroId - 1000000;
			if (sector.astros == null || num < 0 || num >= sector.astros.Length)
			{
				return false;
			}
			pos = sector.astros[num].uPos;
			return true;
		}

		public static string HiveName(EnemyDFHiveSystem hive)
		{
			if (hive == null)
			{
				return "Hive";
			}
			string text = ((hive.starData != null) ? hive.starData.displayName : "");
			if (!string.IsNullOrEmpty(text))
			{
				return text + " -" + hive.displayName;
			}
			return hive.displayName;
		}

		public static IEnumerable<(EnemyDFHiveSystem hive, VectorLF3 pos, double dist)> EnumerateHives(VectorLF3 from)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			SpaceSector sector = Sector;
			if (sector == null || sector.dfHivesByAstro == null)
			{
				yield break;
			}
			int observe = ((GameMain.history != null) ? GameMain.history.universeObserveLevel : 0);
			StarData localStar = GameMain.localStar;
			EnemyDFHiveSystem[] dfHivesByAstro = sector.dfHivesByAstro;
			foreach (EnemyDFHiveSystem val in dfHivesByAstro)
			{
				if (val != null && val.hasAnyStructureOrUnit && ((localStar != null && val.starData != null && val.starData.id == localStar.id) || observe >= 3) && TryHivePos(val, out var pos))
				{
					VectorLF3 item = pos;
					VectorLF3 val2 = pos - from;
					yield return (hive: val, pos: item, dist: ((VectorLF3)(ref val2)).magnitude);
				}
			}
		}

		public static bool TryResolveEnemy(int enemyId, out VectorLF3 pos, out EnemyData enemy)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			pos = VectorLF3.zero;
			enemy = default(EnemyData);
			SpaceSector sector = Sector;
			if (sector == null || sector.enemyPool == null)
			{
				return false;
			}
			if (enemyId <= 0 || enemyId >= sector.enemyPool.Length)
			{
				return false;
			}
			ref EnemyData reference = ref sector.enemyPool[enemyId];
			if (reference.id != enemyId || reference.protoId <= 0)
			{
				return false;
			}
			sector.TransformFromAstro_ref(reference.astroId, ref pos, ref reference.pos);
			enemy = reference;
			return true;
		}

		public static string EnemyName(EnemyData enemy)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (_enemyNames.TryGetValue(enemy.protoId, out var value))
			{
				return value;
			}
			EnemyProto val = ((ProtoSet<EnemyProto>)(object)LDB.enemies)?.Select((int)enemy.protoId);
			if (val == null)
			{
				return "Seed";
			}
			string name = ((Proto)val).name;
			_enemyNames[enemy.protoId] = name;
			return name;
		}

		public static IEnumerable<(int enemyId, EnemyData enemy, VectorLF3 pos, EnemyDFHiveSystem targetHive)> EnumerateSeeds(VectorLF3 from)
		{
			SpaceSector sector = Sector;
			if (sector == null || sector.dfHivesByAstro == null)
			{
				yield break;
			}
			EnemyDFHiveSystem[] dfHivesByAstro = sector.dfHivesByAstro;
			foreach (EnemyDFHiveSystem val in dfHivesByAstro)
			{
				if (val == null || val.tinders == null || val.tinders.count == 0 || val.tinders.buffer == null)
				{
					continue;
				}
				DFTinderComponent[] buffer = val.tinders.buffer;
				int cursor = val.tinders.cursor;
				for (int j = 1; j < cursor && j < buffer.Length; j++)
				{
					if (((DFTinderComponent)(ref buffer[j])).ID > 0 && buffer[j].stage >= -1 && buffer[j].direction > 0)
					{
						int enemyId = buffer[j].enemyId;
						if (TryResolveEnemy(enemyId, out var pos, out var enemy))
						{
							EnemyDFHiveSystem hiveByAstroId = sector.GetHiveByAstroId(buffer[j].targetHiveAstroId);
							yield return (enemyId: enemyId, enemy: enemy, pos: pos, targetHive: hiveByAstroId);
						}
					}
				}
			}
		}

		public static bool TryResolveMessage(int msgId, out CosmicMessageData msg)
		{
			msg = null;
			CosmicMessageManager val = GameMain.gameScenario?.cosmicMessageManager;
			if (val == null || val.messages == null)
			{
				return false;
			}
			if (msgId <= 0 || msgId >= val.messages.Length)
			{
				return false;
			}
			msg = val.messages[msgId];
			if (msg != null)
			{
				return msg.protoId == msgId;
			}
			return false;
		}

		public static bool IsCommunicator(CosmicMessageData msg)
		{
			if (msg != null)
			{
				return msg.doodadProtoId == 5;
			}
			return false;
		}

		public static string MessageName(CosmicMessageData msg)
		{
			return Localization.Translate(IsCommunicator(msg) ? "黑雾通讯器" : "宇宙讯息");
		}

		public static IEnumerable<(int msgId, CosmicMessageData msg, double dist)> EnumerateCommunicators(VectorLF3 from)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			CosmicMessageManager mgr = GameMain.gameScenario?.cosmicMessageManager;
			if (mgr == null || mgr.messages == null)
			{
				yield break;
			}
			for (int i = 1; i < mgr.messages.Length; i++)
			{
				CosmicMessageData val = mgr.messages[i];
				if (val != null && val.protoId == i && val.doodadProtoId == 5 && mgr.IsMessageVisible(i))
				{
					int item = i;
					VectorLF3 val2 = val.uPosition - from;
					yield return (msgId: item, msg: val, dist: ((VectorLF3)(ref val2)).magnitude);
				}
			}
		}
	}
	public enum DestRowKind
	{
		Header,
		Info,
		Star,
		Planet,
		Hive,
		Seed,
		Comm
	}
	public struct DestRow
	{
		public DestRowKind Kind;

		public string Label;

		public string Range;

		public string Extra;

		public int Indent;

		public int Id;

		public StarData Star;

		public PlanetData Planet;

		public EnemyDFHiveSystem Hive;

		public bool Bookmarkable;

		public double Dist;

		public double EtaUnits;

		public double EtaSpeed;
	}
	public static class DestinationList
	{
		public const int TabStars = 0;

		public const int TabDarkFog = 1;

		public const int TabHistory = 2;

		public const int TabBookmark = 3;

		private const int MaxSeedScan = 20000;

		private static readonly List<DestRow> _rows = new List<DestRow>(512);

		private static float _builtAt = float.NegativeInfinity;

		private static int _key = int.MinValue;

		private static bool _dirty = true;

		private static DestRow[] _scratch = new DestRow[256];

		private static double[] _scratchKeys = new double[256];

		private static int _scratchCount;

		public static List<DestRow> Rows => _rows;

		public static float LastBuildMs { get; private set; }

		private static float RefreshSeconds
		{
			get
			{
				if (CruiseAssistPlusPlugin.ListRefreshSeconds == null)
				{
					return 1f;
				}
				return CruiseAssistPlusPlugin.ListRefreshSeconds.Value;
			}
		}

		private static int MaxRows
		{
			get
			{
				if (CruiseAssistPlusPlugin.MaxListRows == null)
				{
					return 250;
				}
				return CruiseAssistPlusPlugin.MaxListRows.Value;
			}
		}

		private static bool ShowSeeds
		{
			get
			{
				if (CruiseAssistPlusPlugin.ShowSeeds != null)
				{
					return CruiseAssistPlusPlugin.ShowSeeds.Value;
				}
				return true;
			}
		}

		private static bool ShowComms
		{
			get
			{
				if (CruiseAssistPlusPlugin.ShowCommunicators != null)
				{
					return CruiseAssistPlusPlugin.ShowCommunicators.Value;
				}
				return true;
			}
		}

		public static void Invalidate()
		{
			_dirty = true;
		}

		public static void EnsureBuilt(int tab, int expandedStarId, string filter, Player player)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			int num = SnapshotKey(tab, expandedStarId, filter);
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (!_dirty && num == _key && realtimeSinceStartup - _builtAt < RefreshSeconds)
			{
				return;
			}
			_dirty = false;
			_key = num;
			_builtAt = realtimeSinceStartup;
			float realtimeSinceStartup2 = Time.realtimeSinceStartup;
			_rows.Clear();
			try
			{
				VectorLF3 p = player?.uPosition ?? VectorLF3.zero;
				string filter2 = (string.IsNullOrEmpty(filter) ? null : filter);
				switch (tab)
				{
				case 0:
					BuildStars(p, expandedStarId, filter2);
					break;
				case 1:
					BuildDarkFog(p, filter2);
					break;
				case 2:
					BuildIdList(p, CruiseAssistPlusPlugin.History, reverse: true, filter2);
					break;
				case 3:
					BuildIdList(p, CruiseAssistPlusPlugin.Bookmark, reverse: false, filter2);
					break;
				}
			}
			catch (Exception e)
			{
				_rows.Clear();
				AddInfo("List unavailable (see log).");
				CruiseAssistPlusPlugin.ThrottledError("DestinationList.Build", e);
			}
			LastBuildMs = (Time.realtimeSinceStartup - realtimeSinceStartup2) * 1000f;
		}

		private static int SnapshotKey(int tab, int expandedStarId, string filter)
		{
			return (int)(((uint)(((((((tab * 397) ^ expandedStarId) * 397) ^ (filter?.GetHashCode() ?? 0)) * 397) ^ MaxRows) * 397) ^ (ShowSeeds ? 1u : 0u)) * 397) ^ (ShowComms ? 2 : 0);
		}

		private static void BuildStars(VectorLF3 p, int expandedStarId, string filter)
		{
			//IL_00a1: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			GalaxyData galaxy = GameMain.galaxy;
			if (galaxy == null || galaxy.stars == null)
			{
				AddInfo("No galaxy data.");
				return;
			}
			ScratchClear();
			StarData[] stars = galaxy.stars;
			foreach (StarData val in stars)
			{
				if (val != null)
				{
					string displayName = val.displayName;
					if (Matches(displayName, filter))
					{
						double num = Distance(val.uPosition, p);
						ScratchAdd(num, new DestRow
						{
							Kind = DestRowKind.Star,
							Label = displayName,
							Star = val,
							Id = val.id * 100,
							Dist = num
						});
					}
				}
			}
			if (FlushScratch(expandedStarId, p) == 0)
			{
				AddInfo((filter != null) ? "  (no star matches the filter)" : "  (no stars)");
			}
		}

		private static void BuildDarkFog(VectorLF3 p, string filter)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			if (GameMain.spaceSector == null)
			{
				AddInfo("No Dark Fog data (not in a running game).");
				return;
			}
			AddHeader("Hives");
			ScratchClear();
			foreach (var item3 in DarkFog.EnumerateHives(p))
			{
				string text = DarkFog.HiveName(item3.hive);
				if (Matches(text, filter))
				{
					double item = item3.dist;
					DestRow row = new DestRow
					{
						Kind = DestRowKind.Hive,
						Label = text
					};
					(row.Hive, _, row.Dist) = item3;
					ScratchAdd(item, row);
				}
			}
			if (FlushScratch() == 0)
			{
				AddInfo("  (none visible)");
			}
			AddHeader("Seeds");
			if (!ShowSeeds)
			{
				AddInfo("  (disabled in config)");
			}
			else
			{
				ScratchClear();
				int num = 0;
				bool flag = false;
				foreach (var item4 in DarkFog.EnumerateSeeds(p))
				{
					if (++num > 20000)
					{
						flag = true;
						break;
					}
					string text2 = ((item4.targetHive != null && item4.targetHive.starData != null) ? (" → " + item4.targetHive.starData.displayName) : "");
					string text3 = DarkFog.EnemyName(item4.enemy) + text2;
					if (Matches(text3, filter))
					{
						double num2 = Distance(item4.pos, p);
						VectorLF3 pos;
						double etaUnits = ((item4.targetHive != null && DarkFog.TryHivePos(item4.targetHive, out pos)) ? Distance(item4.pos, pos) : num2);
						DestRow row = new DestRow
						{
							Kind = DestRowKind.Seed,
							Label = text3,
							Id = item4.enemyId,
							Dist = num2,
							EtaUnits = etaUnits
						};
						Vector3 vel = item4.enemy.vel;
						row.EtaSpeed = ((Vector3)(ref vel)).magnitude;
						ScratchAdd(num2, row);
					}
				}
				if (FlushScratch() == 0)
				{
					AddInfo("  (none in flight)");
				}
				if (flag)
				{
					AddInfo("  (scan limit reached — some seeds not listed)");
				}
			}
			AddHeader("Communicators");
			if (!ShowComms)
			{
				AddInfo("  (disabled in config)");
				return;
			}
			ScratchClear();
			foreach (var item5 in DarkFog.EnumerateCommunicators(p))
			{
				string text4 = ((item5.msg.nearStar != null) ? (" (" + item5.msg.nearStar.displayName + ")") : "");
				string text5 = DarkFog.MessageName(item5.msg) + text4;
				if (Matches(text5, filter))
				{
					double item2 = item5.dist;
					DestRow row = new DestRow
					{
						Kind = DestRowKind.Comm,
						Label = text5
					};
					(row.Id, _, row.Dist) = item5;
					ScratchAdd(item2, row);
				}
			}
			if (FlushScratch() == 0)
			{
				AddInfo("  (none in range)");
			}
		}

		private static void BuildIdList(VectorLF3 p, List<int> ids, bool reverse, string filter)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			GalaxyData galaxy = GameMain.galaxy;
			if (galaxy == null)
			{
				AddInfo("No galaxy data.");
				return;
			}
			ScratchClear();
			for (int i = 0; i < ids.Count; i++)
			{
				int index = (reverse ? (ids.Count - 1 - i) : i);
				int num = ids[index];
				PlanetData val = galaxy.PlanetById(num);
				if (val != null)
				{
					string displayName = val.displayName;
					if (Matches(displayName, filter))
					{
						ScratchAdd(i, new DestRow
						{
							Kind = DestRowKind.Planet,
							Label = displayName,
							Star = val.star,
							Planet = val,
							Id = num,
							Bookmarkable = true,
							Dist = Distance(val.uPosition, p)
						});
					}
				}
			}
			if (FlushScratch() == 0)
			{
				AddInfo((filter != null) ? "  (nothing matches the filter)" : "  (empty)");
			}
		}

		private static void ScratchClear()
		{
			_scratchCount = 0;
		}

		private static void ScratchAdd(double sortKey, DestRow row)
		{
			if (_scratchCount == _scratch.Length)
			{
				Array.Resize(ref _scratch, _scratchCount * 2);
				Array.Resize(ref _scratchKeys, _scratchCount * 2);
			}
			_scratchKeys[_scratchCount] = sortKey;
			_scratch[_scratchCount] = row;
			_scratchCount++;
		}

		private static int FlushScratch()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return FlushScratch(-1, VectorLF3.zero);
		}

		private static int FlushScratch(int expandStarId, VectorLF3 from)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			int scratchCount = _scratchCount;
			if (scratchCount == 0)
			{
				return 0;
			}
			Array.Sort(_scratchKeys, _scratch, 0, scratchCount);
			int maxRows = MaxRows;
			int num = ((scratchCount < maxRows) ? scratchCount : maxRows);
			for (int i = 0; i < num; i++)
			{
				DestRow item = _scratch[i];
				item.Range = Astro.RangeToString(item.Dist);
				if (item.Kind == DestRowKind.Seed)
				{
					item.Extra = Astro.EtaToString(item.EtaUnits, item.EtaSpeed);
				}
				_rows.Add(item);
				if (item.Kind != DestRowKind.Star || item.Star == null || item.Star.id != expandStarId)
				{
					continue;
				}
				PlanetData[] planets = item.Star.planets;
				if (planets == null)
				{
					continue;
				}
				PlanetData[] array = planets;
				foreach (PlanetData val in array)
				{
					if (val != null)
					{
						_rows.Add(new DestRow
						{
							Kind = DestRowKind.Planet,
							Label = val.displayName,
							Range = Astro.RangeToString(Distance(val.uPosition, from)),
							Indent = 1,
							Star = item.Star,
							Planet = val,
							Id = val.id,
							Bookmarkable = true
						});
					}
				}
			}
			if (scratchCount > num)
			{
				AddInfo($"  … {scratchCount - num} more not shown (nearest {num} listed — raise MaxListRows or filter)");
			}
			_scratchCount = 0;
			return num;
		}

		private static void AddHeader(string text)
		{
			_rows.Add(new DestRow
			{
				Kind = DestRowKind.Header,
				Label = text
			});
		}

		private static void AddInfo(string text)
		{
			_rows.Add(new DestRow
			{
				Kind = DestRowKind.Info,
				Label = text
			});
		}

		private static bool Matches(string name, string filter)
		{
			if (filter != null)
			{
				if (name != null)
				{
					return name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0;
				}
				return false;
			}
			return true;
		}

		private static double Distance(VectorLF3 a, VectorLF3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			double num = a.x - b.x;
			double num2 = a.y - b.y;
			double num3 = a.z - b.z;
			return Math.Sqrt(num * num + num2 * num2 + num3 * num3);
		}
	}
	public static class DspSkin
	{
		public static readonly Color Panel = Rgba(14, 20, 27, 0.94f);

		public static readonly Color TitleFill = Rgba(26, 36, 46, 0.98f);

		public static readonly Color Edge = Rgba(60, 96, 116, 0.9f);

		public static readonly Color Accent = Rgba(79, 190, 224, 1f);

		public static readonly Color AccentDim = Rgba(42, 104, 126, 1f);

		public static readonly Color Ink = Rgba(205, 220, 229, 1f);

		public static readonly Color InkDim = Rgba(126, 144, 156, 1f);

		public static readonly Color Ok = Rgba(98, 217, 122, 1f);

		public static readonly Color Warn = Rgba(232, 163, 61, 1f);

		public static readonly Color Field = Rgba(7, 11, 15, 0.95f);

		public static readonly Color Control = Rgba(24, 34, 44, 0.95f);

		public static readonly Color ControlHi = Rgba(37, 56, 71, 0.98f);

		public static readonly float TitleH = 24f;

		private const int BarPx = 24;

		private static GUISkin _skin;

		private static GUISkin _default;

		private static Font _probedFont;

		private static int _fontProbes;

		private static bool _builtStyled;

		private static Font _builtFont;

		private static readonly List<Texture2D> _owned = new List<Texture2D>(32);

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

		public static GUIStyle Header { get; private set; }

		public static GUIStyle Note { get; private set; }

		public static GUIStyle Status { get; private set; }

		public static GUIStyle TitleButton { get; private set; }

		public static GUIStyle Title { get; private set; }

		public static GUIStyle Right { get; private set; }

		public static GUIStyle Row { get; private set; }

		public static GUIStyle CheckOff { get; private set; }

		public static GUIStyle CheckOn { get; private set; }

		public static GUIStyle CheckLabel { get; private set; }

		public static GUIStyle CheckLabelHover { get; private set; }

		public static string CheckMark { get; private set; }

		public static int Generation { get; private set; }

		public static Font GameFont => _builtFont;

		public static void Apply()
		{
			if ((Object)(object)_default == (Object)null)
			{
				_default = GUI.skin;
			}
			bool flag = CruiseAssistPlusPlugin.UseGameSkin == null || CruiseAssistPlusPlugin.UseGameSkin.Value;
			Font val = ((CruiseAssistPlusPlugin.UseGameFont == null || CruiseAssistPlusPlugin.UseGameFont.Value) ? ProbeGameFont() : null);
			if ((Object)(object)_skin == (Object)null || _builtStyled != flag || (Object)(object)_builtFont != (Object)(object)val)
			{
				Build(flag, val);
			}
			if (flag && (Object)(object)_skin != (Object)null)
			{
				GUI.skin = _skin;
			}
		}

		public static string Glyph(params string[] choices)
		{
			if (choices == null || choices.Length == 0)
			{
				return "";
			}
			string text = choices[^1];
			Font val = (((Object)(object)_skin != (Object)null) ? _skin.font : null);
			if ((Object)(object)val == (Object)null || !val.dynamic)
			{
				return text;
			}
			if (_glyphs.TryGetValue(text, out var value))
			{
				return value;
			}
			string text2 = text;
			for (int i = 0; i < choices.Length; i++)
			{
				if (FontHasAll(val, choices[i]))
				{
					text2 = choices[i];
					break;
				}
			}
			_glyphs[text] = text2;
			return text2;
		}

		private static bool FontHasAll(Font font, string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return true;
			}
			for (int i = 0; i < s.Length; i++)
			{
				if (!font.HasCharacter(s[i]))
				{
					return false;
				}
			}
			return true;
		}

		public static GUIStyle Tinted(GUIStyle style, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_002a: 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_0037: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(style);
			val.normal.textColor = color;
			val.hover.textColor = color;
			val.active.textColor = color;
			val.focused.textColor = color;
			return val;
		}

		private static void Build(bool styled, Font font)
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01ec: 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_020e: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Expected O, but got Unknown
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Expected O, but got Unknown
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Expected O, but got Unknown
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Expected O, but got Unknown
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Expected O, but got Unknown
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Expected O, but got Unknown
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _owned.Count; i++)
			{
				if ((Object)(object)_owned[i] != (Object)null)
				{
					Object.Destroy((Object)(object)_owned[i]);
				}
			}
			_owned.Clear();
			_glyphs.Clear();
			if ((Object)(object)_skin != (Object)null)
			{
				Object.Destroy((Object)(object)_skin);
			}
			_skin = Object.Instantiate<GUISkin>(_default);
			((Object)_skin).name = "CruiseAssistPlus";
			((Object)_skin).hideFlags = (HideFlags)61;
			_builtStyled = styled;
			_builtFont = font;
			GUIStyle[] array;
			if (!styled)
			{
				if ((Object)(object)font != (Object)null)
				{
					_skin.font = font;
					array = AllStyles(_skin);
					foreach (GUIStyle val in array)
					{
						if (val != null)
						{
							val.font = font;
						}
					}
				}
				_skin.window.padding.top = 28;
				DeriveStyles();
				Generation++;
				return;
			}
			Texture2D val2 = Framed(Control, Edge);
			Texture2D background = Framed(ControlHi, Accent);
			Texture2D background2 = Framed(AccentDim, Accent);
			Texture2D background3 = Framed(Field, Edge);
			Texture2D tex = WindowTexture();
			GUIStyle window = _skin.window;
			SetAll(window, tex);
			window.border = new RectOffset(1, 1, 24, 1);
			window.padding = new RectOffset(8, 8, 28, 6);
			window.overflow = new RectOffset(0, 0, 0, 0);
			window.contentOffset = Vector2.zero;
			SetAll(_skin.box, val2);
			_skin.box.border = new RectOffset(1, 1, 1, 1);
			_skin.box.overflow = new RectOffset(0, 0, 0, 0);
			Ink4(_skin.box, Ink);
			_skin.label.padding = new RectOffset(2, 2, 2, 2);
			Ink4(_skin.label, Ink);
			GUIStyle button = _skin.button;
			button.border = new RectOffset(1, 1, 1, 1);
			button.padding = new RectOffset(6, 6, 3, 3);
			button.margin = new RectOffset(2, 2, 2, 2);
			button.overflow = new RectOffset(0, 0, 0, 0);
			button.alignment = (TextAnchor)4;
			button.normal.background = val2;
			button.hover.background = background;
			button.active.background = background2;
			button.focused.background = val2;
			button.onNormal.background = background2;
			button.onHover.background = background;
			button.onActive.background = background2;
			button.onFocused.background = background2;
			Ink4(button, Ink);
			button.hover.textColor = Accent;
			button.active.textColor = Color.white;
			button.onNormal.textColor = Color.white;
			button.onHover.textColor = Color.white;
			CopyLook(button, _skin.FindStyle("buttonleft"));
			CopyLook(button, _skin.FindStyle("buttonmid"));
			CopyLook(button, _skin.FindStyle("buttonright"));
			GUIStyle textField = _skin.textField;
			textField.border = new RectOffset(1, 1, 1, 1);
			textField.padding = new RectOffset(5, 3, 3, 3);
			textField.overflow = new RectOffset(0, 0, 0, 0);
			textField.normal.background = background3;
			textField.hover.background = background3;
			textField.active.background = background3;
			textField.focused.background = Framed(Field, Accent);
			Ink4(textField, Ink);
			textField.focused.textColor = Color.white;
			_skin.settings.cursorColor = Accent;
			_skin.settings.selectionColor = new Color(Accent.r, Accent.g, Accent.b, 0.35f);
			Ink4(_skin.toggle, Ink);
			Track(_skin.horizontalSlider);
			Thumb(_skin.horizontalSliderThumb);
			Track(_skin.verticalSlider);
			Thumb(_skin.verticalSliderThumb);
			Track(_skin.horizontalScrollbar);
			Thumb(_skin.horizontalScrollbarThumb);
			Track(_skin.verticalScrollbar);
			Thumb(_skin.verticalScrollbarThumb);
			Blank(_skin.horizontalScrollbarLeftButton);
			Blank(_skin.horizontalScrollbarRightButton);
			Blank(_skin.verticalScrollbarUpButton);
			Blank(_skin.verticalScrollbarDownButton);
			Blank(_skin.scrollView);
			array = AllStyles(_skin);
			foreach (GUIStyle val3 in array)
			{
				if (val3 != null)
				{
					if ((Object)(object)font != (Object)null)
					{
						val3.font = font;
					}
					val3.fontSize = 14;
					val3.wordWrap = false;
					val3.richText = false;
				}
			}
			_skin.font = (((Object)(object)font != (Object)null) ? font : _skin.font);
			DeriveStyles();
			Generation++;
		}

		private static void DeriveStyles()
		{
			//IL_0010: 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_0021: Expected O, but got Unknown
			//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_003c: Expected O, but got Unknown
			//IL_0046: 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_0057: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00bd: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_00f3: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or