Decompiled source of CAAP N v1.3.1

CruiseAssist.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using tanu.CruiseAssist;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CruiseAssist")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CruiseAssist")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9cdb5e0f-fb97-46ff-a4fb-a9a400443fd3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[HarmonyPatch(typeof(PlayerMove_Drift))]
internal class Patch_PlayerMoveDrift
{
	[HarmonyPatch("GameTick")]
	[HarmonyPrefix]
	public static void GameTick_Prefix(PlayerMove_Drift __instance)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Invalid comparison between Unknown and I4
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		if (!CruiseAssistPlugin.Enable || !CruiseAssistPlugin.TargetSelected || (int)((PlayerAction)__instance).controller.movementStateInFrame != 1)
		{
			return;
		}
		if (VFInput._moveForward.pressing || VFInput._pullUp.pressing)
		{
			CruiseAssistPlugin.Interrupt = true;
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.CancelOperate();
			});
		}
		else
		{
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.OperateDrift(__instance);
			});
		}
	}
}
[HarmonyPatch(typeof(PlayerMove_Fly))]
internal class Patch_PlayerMoveFly
{
	[HarmonyPatch("GameTick")]
	[HarmonyPrefix]
	public static void GameTick_Prefix(PlayerMove_Fly __instance)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Invalid comparison between Unknown and I4
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		if (!CruiseAssistPlugin.Enable || !CruiseAssistPlugin.TargetSelected || (int)((PlayerAction)__instance).controller.movementStateInFrame != 2)
		{
			return;
		}
		if (VFInput._moveForward.pressing || VFInput._pullUp.pressing)
		{
			CruiseAssistPlugin.Interrupt = true;
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.CancelOperate();
			});
		}
		else
		{
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.OperateFly(__instance);
			});
		}
	}
}
[HarmonyPatch(typeof(PlayerMove_Walk))]
internal class Patch_PlayerMoveWalk
{
	[HarmonyPatch("GameTick")]
	[HarmonyPrefix]
	public static void GameTick_Prefix(PlayerMove_Walk __instance)
	{
		//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_057b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0585: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Unknown result type (might be due to invalid IL or missing references)
		//IL_058f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05de: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_070d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0713: Invalid comparison between Unknown and I4
		//IL_0621: Unknown result type (might be due to invalid IL or missing references)
		//IL_062b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0630: Unknown result type (might be due to invalid IL or missing references)
		//IL_0635: Unknown result type (might be due to invalid IL or missing references)
		//IL_0716: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_0664: Unknown result type (might be due to invalid IL or missing references)
		//IL_066e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0673: Unknown result type (might be due to invalid IL or missing references)
		//IL_0678: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
		CruiseAssistPlugin.lastState = CruiseAssistPlugin.State;
		if (CruiseAssistPlugin.Interrupt)
		{
			CruiseAssistPlugin.lockOn = false;
			CruiseAssistPlugin.State = CruiseAssistState.INACTIVE;
			CruiseAssistPlugin.SelectTargetPlanet = null;
			CruiseAssistPlugin.SelectTargetStar = null;
			CruiseAssistPlugin.SelectTargetHive = null;
			CruiseAssistPlugin.SelectTargetMsg = null;
			CruiseAssistPlugin.SelectTargetEnemyIdF = 0;
			CruiseAssistPlugin.lastState = CruiseAssistState.INACTIVE;
			CruiseAssistPlugin.AbortPreloadStar();
		}
		CruiseAssistPlugin.State = CruiseAssistState.INACTIVE;
		CruiseAssistPlugin.Interrupt = false;
		CruiseAssistPlugin.TargetStar = null;
		CruiseAssistPlugin.TargetPlanet = null;
		CruiseAssistPlugin.TargetHive = null;
		CruiseAssistPlugin.TargetMsg = null;
		CruiseAssistPlugin.TargetEnemyId = 0;
		CruiseAssistPlugin.TargetRange = 0.0;
		CruiseAssistPlugin.TargetSelected = false;
		if (GameMain.localPlanet != null && (CruiseAssistPlugin.History.Count == 0 || CruiseAssistPlugin.History.Last() != GameMain.localPlanet.id))
		{
			if (CruiseAssistPlugin.History.Count >= 128)
			{
				CruiseAssistPlugin.History.RemoveAt(0);
			}
			CruiseAssistPlugin.History.Add(GameMain.localPlanet.id);
			ConfigManager.CheckConfig(ConfigManager.Step.STATE);
		}
		if (!CruiseAssistPlugin.Enable)
		{
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.SetInactive();
			});
			return;
		}
		int indicatorAstroId = GameMain.mainPlayer.navigation.indicatorAstroId;
		int indicatorEnemyId = GameMain.mainPlayer.navigation.indicatorEnemyId;
		int indicatorMsgId = GameMain.mainPlayer.navigation.indicatorMsgId;
		if ((Object)(object)UIRoot.instance.uiGame.starmap.focusHive != (Object)null)
		{
			return;
		}
		if (CruiseAssistPlugin.SelectTargetAstroId != indicatorAstroId)
		{
			CruiseAssistPlugin.SelectTargetAstroId = indicatorAstroId;
			if (indicatorAstroId == 0)
			{
				CruiseAssistPlugin.SelectTargetPlanet = null;
				CruiseAssistPlugin.SelectTargetStar = null;
			}
			else
			{
				if (indicatorAstroId > 1000000)
				{
					CruiseAssistPlugin.SelectTargetHive = GameMain.spaceSector.dfHivesByAstro[indicatorAstroId - 1000000];
					CruiseAssistPlugin.SelectTargetPlanet = null;
					CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.SelectTargetHive.starData;
				}
				else if (indicatorAstroId % 100 != 0)
				{
					CruiseAssistPlugin.SelectTargetPlanet = GameMain.galaxy.PlanetById(indicatorAstroId);
					CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.SelectTargetPlanet.star;
				}
				else
				{
					CruiseAssistPlugin.SelectTargetPlanet = null;
					CruiseAssistPlugin.SelectTargetStar = GameMain.galaxy.StarById(indicatorAstroId / 100);
				}
				CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
				{
					extension.SetTargetAstroId(indicatorAstroId);
				});
			}
		}
		if (CruiseAssistPlugin.SelectTargetEnemyId != indicatorEnemyId)
		{
			CruiseAssistPlugin.SelectTargetEnemyId = indicatorEnemyId;
			if (indicatorEnemyId != 0)
			{
				CruiseAssistPlugin.SelectTargetEnemyIdF = indicatorEnemyId;
				CruiseAssistPlugin.SelectTargetPlanet = null;
				CruiseAssistPlugin.SelectTargetStar = null;
				CruiseAssistPlugin.SelectTargetHive = null;
				CruiseAssistPlugin.SelectTargetMsg = null;
				CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
				{
					extension.SetTargetAstroId(indicatorAstroId);
				});
			}
			else
			{
				CruiseAssistPlugin.SelectTargetEnemyIdF = 0;
			}
		}
		if (CruiseAssistPlugin.SelectTargetMsgId != indicatorMsgId)
		{
			CruiseAssistPlugin.SelectTargetMsgId = indicatorMsgId;
			if (indicatorMsgId == 0)
			{
				CruiseAssistPlugin.SelectTargetMsg = null;
			}
			else
			{
				CruiseAssistPlugin.SelectTargetMsg = GameMain.gameScenario.cosmicMessageManager.messages[indicatorMsgId];
				CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.SelectTargetMsg.nearStar;
				CruiseAssistPlugin.SelectTargetEnemyIdF = 0;
				CruiseAssistPlugin.SelectTargetPlanet = null;
				CruiseAssistPlugin.SelectTargetHive = null;
				CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
				{
					extension.SetTargetAstroId(indicatorAstroId);
				});
			}
		}
		VectorLF3 val;
		if (CruiseAssistPlugin.SelectTargetStar != null)
		{
			if (GameMain.localStar != null && CruiseAssistPlugin.SelectTargetStar.id == GameMain.localStar.id)
			{
				if (CruiseAssistPlugin.SelectTargetPlanet == null && CruiseAssistPlugin.SelectTargetHive == null && GameMain.localPlanet != null)
				{
					CruiseAssistPlugin.SelectTargetStar = null;
					CruiseAssistPlugin.SelectTargetEnemyId = 0;
					CruiseAssistPlugin.SelectTargetAstroId = 0;
					GameMain.mainPlayer.navigation.indicatorAstroId = 0;
					CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
					{
						extension.SetInactive();
					});
					return;
				}
				if (CruiseAssistPlugin.SelectTargetPlanet != null)
				{
					if (GameMain.localPlanet != null && CruiseAssistPlugin.SelectTargetPlanet.id == GameMain.localPlanet.id)
					{
						CruiseAssistPlugin.Deactivate();
						return;
					}
					CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.SelectTargetPlanet;
				}
				else if (CruiseAssistPlugin.SelectTargetHive != null)
				{
					val = GameMain.spaceSector.astros[CruiseAssistPlugin.SelectTargetHive.hiveAstroId - 1000000].uPos - GameMain.mainPlayer.uPosition;
					if (((VectorLF3)(ref val)).magnitude < 30000.0)
					{
						CruiseAssistPlugin.Deactivate();
						return;
					}
					CruiseAssistPlugin.TargetHive = CruiseAssistPlugin.SelectTargetHive;
				}
				else if (CruiseAssistPlugin.SelectTargetMsg != null)
				{
					val = CruiseAssistPlugin.SelectTargetMsg.uPosition - GameMain.mainPlayer.uPosition;
					if (((VectorLF3)(ref val)).magnitude < 2000.0)
					{
						CruiseAssistPlugin.Deactivate();
						return;
					}
					CruiseAssistPlugin.TargetMsg = CruiseAssistPlugin.SelectTargetMsg;
				}
				else if (CruiseAssistPlugin.ReticuleTargetPlanet != null)
				{
					CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
				}
			}
			else
			{
				CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.SelectTargetStar;
				CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.SelectTargetPlanet;
				CruiseAssistPlugin.TargetHive = CruiseAssistPlugin.SelectTargetHive;
			}
		}
		else if (CruiseAssistPlugin.SelectTargetEnemyIdF != 0)
		{
			val = CruiseAssistPlugin.SelectTargetEnemy.pos - GameMain.mainPlayer.uPosition;
			if (((VectorLF3)(ref val)).magnitude < 3000.0)
			{
				CruiseAssistPlugin.Deactivate();
				return;
			}
			CruiseAssistPlugin.TargetEnemyId = CruiseAssistPlugin.SelectTargetEnemyId;
		}
		else if (CruiseAssistPlugin.ReticuleTargetPlanet != null)
		{
			CruiseAssistPlugin.SelectTargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
			CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.SelectTargetPlanet.star;
			CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
			CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.TargetPlanet.star;
		}
		else if (CruiseAssistPlugin.ReticuleTargetStar != null)
		{
			CruiseAssistPlugin.SelectTargetPlanet = null;
			CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.ReticuleTargetStar;
			CruiseAssistPlugin.TargetPlanet = null;
			CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.ReticuleTargetStar;
		}
		_ = ((PlayerAction)__instance).player;
		if (CruiseAssistPlugin.TargetPlanet != null)
		{
			CruiseAssistPlugin.State = CruiseAssistState.TO_PLANET;
			CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.TargetPlanet.star;
			val = CruiseAssistPlugin.TargetUPos - GameMain.mainPlayer.uPosition;
			CruiseAssistPlugin.TargetRange = ((VectorLF3)(ref val)).magnitude - (double)CruiseAssistPlugin.TargetPlanet.realRadius;
			CruiseAssistPlugin.TargetSelected = true;
		}
		else if (CruiseAssistPlugin.TargetHive != null)
		{
			CruiseAssistPlugin.State = CruiseAssistState.TO_HIVE;
			CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.TargetHive.starData;
			val = CruiseAssistPlugin.TargetUPos - GameMain.mainPlayer.uPosition;
			CruiseAssistPlugin.TargetRange = ((VectorLF3)(ref val)).magnitude - 30000.0;
			CruiseAssistPlugin.TargetSelected = true;
		}
		else if (CruiseAssistPlugin.TargetMsg != null)
		{
			CruiseAssistPlugin.State = CruiseAssistState.TO_MSG;
			CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.TargetMsg.nearStar;
			val = CruiseAssistPlugin.TargetUPos - GameMain.mainPlayer.uPosition;
			CruiseAssistPlugin.TargetRange = ((VectorLF3)(ref val)).magnitude - 2000.0;
			CruiseAssistPlugin.TargetSelected = true;
		}
		else if (CruiseAssistPlugin.TargetEnemyId != 0)
		{
			CruiseAssistPlugin.State = CruiseAssistState.TO_ENEMY;
			val = CruiseAssistPlugin.TargetUPos - GameMain.mainPlayer.uPosition;
			CruiseAssistPlugin.TargetRange = ((VectorLF3)(ref val)).magnitude;
			CruiseAssistPlugin.TargetSelected = true;
		}
		else
		{
			if (CruiseAssistPlugin.TargetStar == null)
			{
				CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
				{
					extension.SetInactive();
				});
				return;
			}
			CruiseAssistPlugin.State = CruiseAssistState.TO_STAR;
			val = CruiseAssistPlugin.TargetStar.uPosition - GameMain.mainPlayer.uPosition;
			CruiseAssistPlugin.TargetRange = ((VectorLF3)(ref val)).magnitude - (double)(CruiseAssistPlugin.TargetStar.viewRadius - 120f);
			CruiseAssistPlugin.TargetSelected = true;
		}
		if ((int)((PlayerAction)__instance).controller.movementStateInFrame > 0)
		{
			return;
		}
		if (VFInput._jump.pressing)
		{
			CruiseAssistPlugin.Interrupt = true;
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.CancelOperate();
			});
		}
		else
		{
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.OperateWalk(__instance);
			});
		}
	}
}
[HarmonyPatch(typeof(PlayerMove_Sail))]
internal class Patch_PlayerMoveSail
{
	[HarmonyPatch("GameTick")]
	[HarmonyPrefix]
	public static void GameTick_Prefix(PlayerMove_Sail __instance)
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: 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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		if (CruiseAssistPlugin.TargetStar?.id == GameMain.localStar?.id)
		{
			CruiseAssistPlugin.AbortPreloadStar();
		}
		if (!CruiseAssistPlugin.Enable || !CruiseAssistPlugin.TargetSelected)
		{
			return;
		}
		Player player = ((PlayerAction)__instance).player;
		if (!player.sailing)
		{
			return;
		}
		if (GameMain.mainPlayer.controller.input0 != Vector4.zero || (GameMain.mainPlayer.controller.input1 != Vector4.zero && GameMain.mainPlayer.controller.input1.y >= 0f))
		{
			CruiseAssistPlugin.Interrupt = true;
			CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.CancelOperate();
			});
			return;
		}
		bool operate = false;
		CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
		{
			operate |= extension.OperateSail(__instance);
		});
		if (operate)
		{
			return;
		}
		VectorLF3 val = CruiseAssistPlugin.TargetUPos - player.uPosition;
		float num = Vector3.Angle(VectorLF3.op_Implicit(val), VectorLF3.op_Implicit(player.uVelocity));
		float num2 = 1.6f / Mathf.Max(10f, num);
		_ = ((VectorLF3)(ref player.controller.actionSail.visual_uvel)).magnitude;
		if ((double)num < 0.5)
		{
			CruiseAssistPlugin.lockOn = true;
		}
		if (CruiseAssistPlugin.lockOn)
		{
			if (CruiseAssistPlugin.TargetStar != null)
			{
				CruiseAssistPlugin.TryPreloadStar(CruiseAssistPlugin.TargetStar);
			}
			player.uVelocity = VectorLF3.op_Implicit(Vector3.Slerp(VectorLF3.op_Implicit(player.uVelocity), VectorLF3.op_Implicit(((VectorLF3)(ref val)).normalized * ((VectorLF3)(ref player.uVelocity)).magnitude), 0.75f));
		}
		else
		{
			player.uVelocity = VectorLF3.op_Implicit(Vector3.Slerp(VectorLF3.op_Implicit(player.uVelocity), VectorLF3.op_Implicit(((VectorLF3)(ref val)).normalized * ((VectorLF3)(ref player.uVelocity)).magnitude), num2));
		}
		if (CruiseAssistPlugin.State == CruiseAssistState.TO_ENEMY)
		{
			player.controller.actionSail.warpSpeedControl = 1.0 - Math.Pow(Maths.Clamp01(1.0 - (((VectorLF3)(ref val)).magnitude - 3000.0) / 400000.0), 2.0) * 0.65;
		}
	}
}
namespace tanu.CruiseAssist;

public class ListUtils
{
	public static string ToString(List<int> list)
	{
		if (list == null || list.Count == 0)
		{
			return "";
		}
		return list.Select((int id) => id.ToString()).Aggregate((string a, string b) => a + "," + b);
	}

	public static string ToString(List<string> list)
	{
		if (list == null || list.Count == 0)
		{
			return "";
		}
		return list.Aggregate((string a, string b) => a + "," + b);
	}

	public static List<int> ParseToIntList(string str)
	{
		if (str == null || str.Length == 0)
		{
			return new List<int>();
		}
		int result;
		return (from s in str.Split(new char[1] { ',' })
			where int.TryParse(s, out result)
			select s).Select(int.Parse).ToList();
	}

	public static List<string> ParseToStringList(string str)
	{
		if (str == null || str.Length == 0)
		{
			return new List<string>();
		}
		return str.Split(new char[1] { ',' }).ToList();
	}
}
public class CruiseAssistConfigManager : ConfigManager
{
	public CruiseAssistConfigManager(ConfigFile Config)
		: base(Config)
	{
	}

	protected override void CheckConfigImplements(Step step)
	{
		bool flag = false;
		if (step == Step.AWAKE)
		{
			ConfigManager.Bind("Base", "ModVersion", "1.3.1", "Don't change.").Value = "1.3.1";
			ConfigManager.Migration("State", "MainWindow0Left", 100, "State", "InfoWindowLeft");
			ConfigManager.Migration("State", "MainWindow0Top", 100, "State", "InfoWindowTop");
			ConfigManager.Migration("State", "MainWindow0Left", 100, "State", "MainWindowLeft");
			ConfigManager.Migration("State", "MainWindow0Top", 100, "State", "MainWindowTop");
			ConfigManager.Migration("State", "StarListWindow0Left", 100, "State", "StarListWindowLeft");
			ConfigManager.Migration("State", "StarListWindow0Top", 100, "State", "StarListWindowTop");
			flag = true;
		}
		switch (step)
		{
		case Step.AWAKE:
		case Step.GAME_MAIN_BEGIN:
		{
			CruiseAssistDebugUI.Show = ConfigManager.Bind("Debug", "DebugWindowShow", defaultValue: false).Value;
			CruiseAssistPlugin.Enable = ConfigManager.Bind("Setting", "Enable", defaultValue: true).Value;
			CruiseAssistPlugin.MarkVisitedFlag = ConfigManager.Bind("Setting", "MarkVisited", defaultValue: true).Value;
			CruiseAssistPlugin.SelectFocusFlag = ConfigManager.Bind("Setting", "SelectFocus", defaultValue: true).Value;
			CruiseAssistPlugin.HideDuplicateHistoryFlag = ConfigManager.Bind("Setting", "HideDuplicateHistory", defaultValue: true).Value;
			CruiseAssistPlugin.AutoDisableLockCursorFlag = ConfigManager.Bind("Setting", "AutoDisableLockCursor", defaultValue: false).Value;
			CruiseAssistPlugin.TrackDarkFogSeedsFlag = ConfigManager.Bind("Setting", "TrackDarkFogSeeds", defaultValue: true).Value;
			CruiseAssistPlugin.PreventNonTargetLoadingFlag = ConfigManager.Bind("Setting", "PreventNonTargetLoading", defaultValue: true).Value;
			CruiseAssistMainUI.Scale = ConfigManager.Bind("Setting", "UIScale", 150).Value;
			EnumUtils.TryParse<CruiseAssistMainUIViewMode>(ConfigManager.Bind("Setting", "MainWindowViewMode", CruiseAssistMainUIViewMode.FULL.ToString()).Value, out CruiseAssistMainUI.ViewMode);
			for (int j = 0; j < 2; j++)
			{
				((Rect)(ref CruiseAssistMainUI.Rect[j])).x = ConfigManager.Bind("State", $"MainWindow{j}Left", 100).Value;
				((Rect)(ref CruiseAssistMainUI.Rect[j])).y = ConfigManager.Bind("State", $"MainWindow{j}Top", 100).Value;
				((Rect)(ref CruiseAssistStarListUI.Rect[j])).x = ConfigManager.Bind("State", $"StarListWindow{j}Left", 100).Value;
				((Rect)(ref CruiseAssistStarListUI.Rect[j])).y = ConfigManager.Bind("State", $"StarListWindow{j}Top", 100).Value;
				((Rect)(ref CruiseAssistConfigUI.Rect[j])).x = ConfigManager.Bind("State", $"ConfigWindow{j}Left", 100).Value;
				((Rect)(ref CruiseAssistConfigUI.Rect[j])).y = ConfigManager.Bind("State", $"ConfigWindow{j}Top", 100).Value;
			}
			CruiseAssistStarListUI.ListSelected = ConfigManager.Bind("State", "StarListWindowListSelected", 0).Value;
			((Rect)(ref CruiseAssistDebugUI.Rect)).x = ConfigManager.Bind("State", "DebugWindowLeft", 100).Value;
			((Rect)(ref CruiseAssistDebugUI.Rect)).y = ConfigManager.Bind("State", "DebugWindowTop", 100).Value;
			if (!DSPGame.IsMenuDemo && GameMain.galaxy != null)
			{
				CruiseAssistPlugin.History = ListUtils.ParseToIntList(ConfigManager.Bind("Save", $"History_{GameMain.galaxy.seed}", "").Value);
				CruiseAssistPlugin.Bookmark = ListUtils.ParseToIntList(ConfigManager.Bind("Save", $"Bookmark_{GameMain.galaxy.seed}", "").Value);
			}
			else
			{
				CruiseAssistPlugin.History = new List<int>();
				CruiseAssistPlugin.Bookmark = new List<int>();
			}
			break;
		}
		case Step.STATE:
		{
			LogManager.LogInfo("check state.");
			flag |= ConfigManager.UpdateEntry("Setting", "Enable", CruiseAssistPlugin.Enable);
			flag |= ConfigManager.UpdateEntry("Setting", "MarkVisited", CruiseAssistPlugin.MarkVisitedFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "SelectFocus", CruiseAssistPlugin.SelectFocusFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "HideDuplicateHistory", CruiseAssistPlugin.HideDuplicateHistoryFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "AutoDisableLockCursor", CruiseAssistPlugin.AutoDisableLockCursorFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "TrackDarkFogSeeds", CruiseAssistPlugin.TrackDarkFogSeedsFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "PreventNonTargetLoading", CruiseAssistPlugin.PreventNonTargetLoadingFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "UIScale", (int)CruiseAssistMainUI.Scale);
			flag |= ConfigManager.UpdateEntry("Setting", "MainWindowViewMode", CruiseAssistMainUI.ViewMode.ToString());
			for (int i = 0; i < 2; i++)
			{
				flag |= ConfigManager.UpdateEntry("State", $"MainWindow{i}Left", (int)((Rect)(ref CruiseAssistMainUI.Rect[i])).x);
				flag |= ConfigManager.UpdateEntry("State", $"MainWindow{i}Top", (int)((Rect)(ref CruiseAssistMainUI.Rect[i])).y);
				flag |= ConfigManager.UpdateEntry("State", $"StarListWindow{i}Left", (int)((Rect)(ref CruiseAssistStarListUI.Rect[i])).x);
				flag |= ConfigManager.UpdateEntry("State", $"StarListWindow{i}Top", (int)((Rect)(ref CruiseAssistStarListUI.Rect[i])).y);
				flag |= ConfigManager.UpdateEntry("State", $"ConfigWindow{i}Left", (int)((Rect)(ref CruiseAssistConfigUI.Rect[i])).x);
				flag |= ConfigManager.UpdateEntry("State", $"ConfigWindow{i}Top", (int)((Rect)(ref CruiseAssistConfigUI.Rect[i])).y);
			}
			flag |= ConfigManager.UpdateEntry("State", "StarListWindowListSelected", CruiseAssistStarListUI.ListSelected);
			flag |= ConfigManager.UpdateEntry("State", "DebugWindowLeft", (int)((Rect)(ref CruiseAssistDebugUI.Rect)).x);
			flag |= ConfigManager.UpdateEntry("State", "DebugWindowTop", (int)((Rect)(ref CruiseAssistDebugUI.Rect)).y);
			if (!DSPGame.IsMenuDemo && GameMain.galaxy != null)
			{
				if (!ConfigManager.ContainsKey("Save", $"History_{GameMain.galaxy.seed}") || !ConfigManager.ContainsKey("Save", $"Bookmark_{GameMain.galaxy.seed}"))
				{
					ConfigManager.Bind("Save", $"History_{GameMain.galaxy.seed}", "");
					ConfigManager.Bind("Save", $"Bookmark_{GameMain.galaxy.seed}", "");
					flag = true;
				}
				flag |= ConfigManager.UpdateEntry("Save", $"History_{GameMain.galaxy.seed}", ListUtils.ToString(CruiseAssistPlugin.History));
				flag |= ConfigManager.UpdateEntry("Save", $"Bookmark_{GameMain.galaxy.seed}", ListUtils.ToString(CruiseAssistPlugin.Bookmark));
			}
			CruiseAssistMainUI.NextCheckGameTick = long.MaxValue;
			break;
		}
		}
		if (flag)
		{
			ConfigManager.Save();
		}
	}
}
public interface CruiseAssistExtensionAPI
{
	void CheckConfig(string step);

	void SetTargetAstroId(int astroId);

	bool OperateWalk(PlayerMove_Walk __instance);

	bool OperateDrift(PlayerMove_Drift __instance);

	bool OperateFly(PlayerMove_Fly __instance);

	bool OperateSail(PlayerMove_Sail __instance);

	void SetInactive();

	void CancelOperate();

	void OnGUI();

	bool CheckActive();
}
[BepInPlugin("nord.CruiseAssist", "CruiseAssist-N", "1.3.1")]
public class CruiseAssistPlugin : BaseUnityPlugin
{
	public const string ModGuid = "nord.CruiseAssist";

	public const string ModName = "CruiseAssist-N";

	public const string ModVersion = "1.3.1";

	public const double HIVE_IN_RANGE = 30000.0;

	public const double ENEMY_IN_RANGE = 3000.0;

	public const double MSG_IN_RANGE = 2000.0;

	public static bool Enable = true;

	public static bool Interrupt = false;

	public static bool TargetSelected = false;

	public static bool MarkVisitedFlag = true;

	public static bool SelectFocusFlag = false;

	public static bool HideDuplicateHistoryFlag = true;

	public static bool AutoDisableLockCursorFlag = false;

	public static bool TrackDarkFogSeedsFlag = true;

	public static bool PreventNonTargetLoadingFlag = true;

	public static StarData ReticuleTargetStar = null;

	public static PlanetData ReticuleTargetPlanet = null;

	public static StarData SelectTargetStar = null;

	public static PlanetData SelectTargetPlanet = null;

	public static EnemyDFHiveSystem SelectTargetHive = null;

	public static CosmicMessageData SelectTargetMsg = null;

	public static int SelectTargetAstroId = 0;

	public static int SelectTargetEnemyId = 0;

	public static int SelectTargetEnemyIdF = 0;

	public static int SelectTargetMsgId = 0;

	public static StarData TargetStar = null;

	public static PlanetData TargetPlanet = null;

	public static EnemyDFHiveSystem TargetHive = null;

	public static CosmicMessageData TargetMsg = null;

	public static int TargetEnemyId = 0;

	public static bool lockOn = false;

	public static StarData preloadStar = null;

	public static CruiseAssistState State = CruiseAssistState.INACTIVE;

	public static CruiseAssistState lastState = CruiseAssistState.INACTIVE;

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

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

	public static Func<StarData, string> GetStarName = (StarData star) => star.displayName;

	public static Func<PlanetData, string> GetPlanetName = (PlanetData planet) => planet.displayName;

	public static Func<EnemyDFHiveSystem, string> GetHiveName = (EnemyDFHiveSystem hive) => hive.displayName;

	public static Func<EnemyData, string> GetEnemyName = (EnemyData enemy) => ((Proto)((ProtoSet<EnemyProto>)(object)LDB.enemies).Select((int)enemy.protoId)).name;

	public static Func<CosmicMessageData, string> GetMsgName = delegate(CosmicMessageData msg)
	{
		int protoId = msg.protoId;
		string text = "";
		text = Localization.Translate("宇宙讯息");
		if (protoId > CosmicMessageProto.maxProtoId)
		{
			text = Localization.Translate("黑雾通讯器");
		}
		return text;
	};

	private Harmony harmony;

	internal static List<CruiseAssistExtensionAPI> extensions = new List<CruiseAssistExtensionAPI>();

	public static double TargetRange = 0.0;

	public static EnemyData SelectTargetEnemy => GameMain.spaceSector.enemyPool[SelectTargetEnemyId];

	public static EnemyData TargetEnemy => GameMain.spaceSector.enemyPool[TargetEnemyId];

	public static VectorLF3 TargetUPos
	{
		get
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if (TargetPlanet != null)
			{
				return TargetPlanet.uPosition;
			}
			if (TargetHive != null)
			{
				return GameMain.spaceSector.astros[TargetHive.hiveAstroId - 1000000].uPos;
			}
			if (TargetEnemyId != 0)
			{
				VectorLF3 zero = VectorLF3.zero;
				ref EnemyData reference = ref GameMain.spaceSector.enemyPool[TargetEnemyId];
				GameMain.spaceSector.TransformFromAstro_ref(reference.astroId, ref zero, ref reference.pos);
				return zero;
			}
			if (TargetMsg != null)
			{
				return TargetMsg.uPosition;
			}
			if (TargetStar == null)
			{
				return GameMain.mainPlayer.uPosition;
			}
			return TargetStar.uPosition;
		}
	}

	public static bool CheckActive()
	{
		return State != CruiseAssistState.INACTIVE;
	}

	public void Awake()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		LogManager.Logger = ((BaseUnityPlugin)this).Logger;
		new CruiseAssistConfigManager(((BaseUnityPlugin)this).Config);
		ConfigManager.CheckConfig(ConfigManager.Step.AWAKE);
		harmony = new Harmony("nord.CruiseAssist.Patch");
		harmony.PatchAll(typeof(Patch_GameMain));
		harmony.PatchAll(typeof(Patch_UISailPanel));
		harmony.PatchAll(typeof(Patch_UIStarmap));
		harmony.PatchAll(typeof(Patch_UITechTree));
		harmony.PatchAll(typeof(Patch_PlayerMoveWalk));
		harmony.PatchAll(typeof(Patch_PlayerMoveDrift));
		harmony.PatchAll(typeof(Patch_PlayerMoveFly));
		harmony.PatchAll(typeof(Patch_PlayerMoveSail));
		harmony.PatchAll(typeof(Patch_DeterminLocalPlanet));
	}

	public void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	public void OnGUI()
	{
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		if (DSPGame.IsMenuDemo || GameMain.mainPlayer == null)
		{
			return;
		}
		UIGame uiGame = UIRoot.instance.uiGame;
		if (!uiGame.guideComplete || ((ManualBehaviour)uiGame.techTree).active || ((ManualBehaviour)uiGame.escMenu).active || ((ManualBehaviour)uiGame.dysonEditor).active || uiGame.hideAllUI0 || uiGame.hideAllUI1 || ((Object)(object)UIMilkyWayLoadingSplash.instance != (Object)null && ((ManualBehaviour)UIMilkyWayLoadingSplash.instance).active) || ((Object)(object)UIRoot.instance.uiMilkyWay != (Object)null && ((ManualBehaviour)UIRoot.instance.uiMilkyWay).active) || VFInput.inCombatScreenGUI || ((ManualBehaviour)uiGame.controlPanelWindow).active)
		{
			return;
		}
		bool extensionActive = false;
		extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
		{
			extensionActive |= extension.CheckActive();
		});
		if (GameMain.mainPlayer.sailing || ((ManualBehaviour)uiGame.starmap).active || extensionActive)
		{
			CruiseAssistMainUI.wIdx = (((ManualBehaviour)uiGame.starmap).active ? 1 : 0);
			float num = CruiseAssistMainUI.Scale / 100f;
			GUIUtility.ScaleAroundPivot(new Vector2(num, num), Vector2.zero);
			CruiseAssistMainUI.OnGUI();
			if (CruiseAssistStarListUI.Show[CruiseAssistMainUI.wIdx])
			{
				CruiseAssistStarListUI.OnGUI();
			}
			if (CruiseAssistConfigUI.Show[CruiseAssistMainUI.wIdx])
			{
				CruiseAssistConfigUI.OnGUI();
			}
			if (CruiseAssistDebugUI.Show)
			{
				CruiseAssistDebugUI.OnGUI();
			}
			bool flag = false;
			flag = ResetInput(CruiseAssistMainUI.Rect[CruiseAssistMainUI.wIdx], num);
			if (!flag && CruiseAssistStarListUI.Show[CruiseAssistMainUI.wIdx])
			{
				flag = ResetInput(CruiseAssistStarListUI.Rect[CruiseAssistMainUI.wIdx], num);
			}
			if (!flag && CruiseAssistConfigUI.Show[CruiseAssistMainUI.wIdx])
			{
				flag = ResetInput(CruiseAssistConfigUI.Rect[CruiseAssistMainUI.wIdx], num);
			}
			if (!flag && CruiseAssistDebugUI.Show)
			{
				flag = ResetInput(CruiseAssistDebugUI.Rect, num);
			}
			extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
			{
				extension.OnGUI();
			});
		}
	}

	private bool ResetInput(Rect rect, float scale)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		float num = ((Rect)(ref rect)).xMin * scale;
		float num2 = ((Rect)(ref rect)).xMax * scale;
		float num3 = ((Rect)(ref rect)).yMin * scale;
		float num4 = ((Rect)(ref rect)).yMax * scale;
		float x = Input.mousePosition.x;
		float num5 = (float)Screen.height - Input.mousePosition.y;
		if (num <= x && x <= num2 && num3 <= num5 && num5 <= num4 && (((IEnumerable<int>)new int[3] { 0, 1, 2 }).Any((Func<int, bool>)Input.GetMouseButton) || Input.mouseScrollDelta.y != 0f))
		{
			Input.ResetInputAxes();
			return true;
		}
		return false;
	}

	public static void RegistExtension(CruiseAssistExtensionAPI extension)
	{
		extensions.Add(extension);
	}

	public static void UnregistExtension(Type type)
	{
		extensions.RemoveAll((CruiseAssistExtensionAPI extension) => extension.GetType().FullName == type.FullName);
	}

	public static void Deactivate()
	{
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		SelectTargetStar = null;
		SelectTargetHive = null;
		SelectTargetPlanet = null;
		SelectTargetMsg = null;
		SelectTargetAstroId = 0;
		SelectTargetEnemyId = 0;
		SelectTargetMsgId = 0;
		GameMain.mainPlayer.navigation.indicatorAstroId = 0;
		GameMain.mainPlayer.navigation.indicatorEnemyId = 0;
		GameMain.mainPlayer.navigation.indicatorMsgId = 0;
		lockOn = false;
		AbortPreloadStar();
		extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
		{
			extension.SetInactive();
		});
		Player mainPlayer = GameMain.mainPlayer;
		if (lastState != CruiseAssistState.INACTIVE && State == CruiseAssistState.INACTIVE && mainPlayer.warping && mainPlayer.warpCommand)
		{
			mainPlayer.warpCommand = false;
			VFAudio.Create("warp-end", mainPlayer.transform, Vector3.zero, true, 0, -1, -1L);
		}
	}

	public static EnemyDFHiveSystem GetSeedsTargetHive(EnemyData seed)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if (seed.dfTinderId <= 0)
		{
			return null;
		}
		EnemyDFHiveSystem hiveByAstroId = GameMain.spaceSector.GetHiveByAstroId(seed.astroId);
		if (hiveByAstroId == null)
		{
			return null;
		}
		ref DFTinderComponent reference = ref hiveByAstroId.tinders.buffer[seed.dfTinderId];
		if (reference.id == seed.dfTinderId && reference.direction > 0 && reference.stage >= -1)
		{
			return GameMain.spaceSector.GetHiveByAstroId(reference.targetHiveAstroId);
		}
		return null;
	}

	public static void TryPreloadStar(StarData star)
	{
		if (GameMain.localStar == null && star?.id != preloadStar?.id && !star.loaded && GameMain.isRunning)
		{
			if (preloadStar != null)
			{
				AbortPreloadStar();
			}
			preloadStar = star;
			LogManager.LogInfo("Try to preload the star.");
		}
	}

	public static void AbortPreloadStar()
	{
		if (preloadStar != null)
		{
			if (GameMain.localStar?.id != preloadStar.id && preloadStar.loaded)
			{
				LogManager.LogInfo("Abort star's preloading.");
			}
			preloadStar = null;
		}
	}
}
public abstract class ConfigManager
{
	public enum Step
	{
		AWAKE,
		GAME_MAIN_BEGIN,
		UNIVERSE_GEN_CREATE_GALAXY,
		STATE
	}

	private static ConfigManager instance;

	private static Dictionary<ConfigDefinition, string> orphanedEntries;

	public static ConfigFile Config { get; private set; }

	protected ConfigManager(ConfigFile config)
	{
		instance = this;
		Config = config;
		Config.SaveOnConfigSet = false;
	}

	public static void CheckConfig(Step step)
	{
		instance.CheckConfigImplements(step);
	}

	protected abstract void CheckConfigImplements(Step step);

	public static ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
	{
		return Config.Bind<T>(configDefinition, defaultValue, configDescription);
	}

	public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
	{
		return Config.Bind<T>(section, key, defaultValue, configDescription);
	}

	public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
	{
		return Config.Bind<T>(section, key, defaultValue, description);
	}

	public static ConfigEntry<T> GetEntry<T>(ConfigDefinition configDefinition)
	{
		try
		{
			return (ConfigEntry<T>)(object)Config[configDefinition];
		}
		catch (KeyNotFoundException ex)
		{
			LogManager.LogError($"{ex.GetType()}: configDefinition={configDefinition}");
			throw;
		}
	}

	public static ConfigEntry<T> GetEntry<T>(string section, string key)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		return GetEntry<T>(new ConfigDefinition(section, key));
	}

	public static T GetValue<T>(ConfigDefinition configDefinition)
	{
		return GetEntry<T>(configDefinition).Value;
	}

	public static T GetValue<T>(string section, string key)
	{
		return GetEntry<T>(section, key).Value;
	}

	public static bool ContainsKey(ConfigDefinition configDefinition)
	{
		return Config.ContainsKey(configDefinition);
	}

	public static bool ContainsKey(string section, string key)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		return Config.ContainsKey(new ConfigDefinition(section, key));
	}

	public static bool UpdateEntry<T>(string section, string key, T value) where T : IComparable
	{
		ConfigEntry<T> entry = GetEntry<T>(section, key);
		if (entry.Value.CompareTo(value) == 0)
		{
			return false;
		}
		entry.Value = value;
		return true;
	}

	public static bool RemoveEntry(ConfigDefinition key)
	{
		return Config.Remove(key);
	}

	public static Dictionary<ConfigDefinition, string> GetOrphanedEntries()
	{
		if (orphanedEntries == null)
		{
			orphanedEntries = Traverse.Create((object)Config).Property<Dictionary<ConfigDefinition, string>>("OrphanedEntries", (object[])null).Value;
		}
		return orphanedEntries;
	}

	public static void Migration<T>(string newSection, string newKey, T defaultValue, string oldSection, string oldKey)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		GetOrphanedEntries();
		ConfigDefinition key = new ConfigDefinition(oldSection, oldKey);
		if (orphanedEntries.TryGetValue(key, out var value))
		{
			((ConfigEntryBase)Bind(newSection, newKey, defaultValue)).SetSerializedValue(value);
			orphanedEntries.Remove(key);
			LogManager.LogInfo("migration " + oldSection + "." + oldKey + "(" + value + ") => " + newSection + "." + newKey);
		}
	}

	public static void Save(bool clearOrphanedEntries = false)
	{
		if (clearOrphanedEntries)
		{
			GetOrphanedEntries().Clear();
		}
		Config.Save();
		LogManager.LogInfo("save config.");
	}
}
[HarmonyPatch(typeof(GameData), "ArriveStar")]
public class Patch_ArriveStar
{
	[HarmonyPrefix]
	public static bool ArriveStar_Prefix(StarData star)
	{
		if (CruiseAssistPlugin.preloadStar != null && CruiseAssistPlugin.preloadStar.id != star?.id)
		{
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(GameData), "DetermineLocalPlanet")]
public class Patch_DeterminLocalPlanet
{
	[HarmonyPrefix]
	public static bool DetermineLocalPlanet_Prefix(ref bool __result)
	{
		if (!CruiseAssistPlugin.PreventNonTargetLoadingFlag)
		{
			return true;
		}
		StarData val = null;
		PlanetData val2 = null;
		GameMain.data.GetNearestStarPlanet(ref val, ref val2);
		if (CruiseAssistPlugin.preloadStar != null && val?.id != CruiseAssistPlugin.preloadStar.id)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(UIStarmap))]
public class Patch_UIStarmap
{
	[HarmonyPatch("_OnClose")]
	[HarmonyPrefix]
	public static void OnClose_Prefix()
	{
		ConfigManager.CheckConfig(ConfigManager.Step.STATE);
		CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
		{
			extension.CheckConfig(ConfigManager.Step.STATE.ToString());
		});
	}
}
[HarmonyPatch(typeof(UITechTree))]
public class Patch_UITechTree
{
	[HarmonyPatch("_OnOpen")]
	[HarmonyPrefix]
	public static void OnOpen_Prefix()
	{
		ConfigManager.CheckConfig(ConfigManager.Step.STATE);
		CruiseAssistPlugin.extensions.ForEach(delegate(CruiseAssistExtensionAPI extension)
		{
			extension.CheckConfig(ConfigManager.Step.STATE.ToString());
		});
	}
}
public class CruiseAssistConfigUI
{
	private static int wIdx = 0;

	public const float WindowWidth = 400f;

	public const float WindowHeight = 400f;

	public static bool[] Show = new bool[2];

	public static Rect[] Rect = (Rect[])(object)new Rect[2]
	{
		new Rect(0f, 0f, 400f, 400f),
		new Rect(0f, 0f, 400f, 400f)
	};

	private static float lastCheckWindowLeft = float.MinValue;

	private static float lastCheckWindowTop = float.MinValue;

	public static float TempScale = 150f;

	private static GUIStyle windowStyle;

	private static GUIStyle mainWindowStyleLabelStyle;

	private static GUIStyle mainWindowStyleButtonStyle;

	private static GUIStyle uiScaleTitleLabelStyle;

	private static GUIStyle scaleSliderStyle;

	private static GUIStyle scaleSliderThumbStyle;

	private static GUIStyle uiScaleValueLabelStyle;

	private static GUIStyle scaleSetButtonStyle;

	private static GUIStyle toggleStyle;

	private static GUIStyle closeButtonStyle;

	public static void OnGUI()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_0068: 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_001d: 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)
		CruiseAssistMainUI.StyleStuff();
		wIdx = CruiseAssistMainUI.wIdx;
		windowStyle = (GUIStyle)(((object)windowStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.WindowStyle)
		{
			fontSize = 11
		}));
		Rect[wIdx] = GUILayout.Window(99030293, Rect[wIdx], new WindowFunction(WindowFunction), "CruiseAssist - Config", windowStyle, Array.Empty<GUILayoutOption>());
		float num = CruiseAssistMainUI.Scale / 100f;
		if ((float)Screen.width / num < ((Rect)(ref Rect[wIdx])).xMax)
		{
			((Rect)(ref Rect[wIdx])).x = (float)Screen.width / num - ((Rect)(ref Rect[wIdx])).width;
		}
		if (((Rect)(ref Rect[wIdx])).x < 0f)
		{
			((Rect)(ref Rect[wIdx])).x = 0f;
		}
		if ((float)Screen.height / num < ((Rect)(ref Rect[wIdx])).yMax)
		{
			((Rect)(ref Rect[wIdx])).y = (float)Screen.height / num - ((Rect)(ref Rect[wIdx])).height;
		}
		if (((Rect)(ref Rect[wIdx])).y < 0f)
		{
			((Rect)(ref Rect[wIdx])).y = 0f;
		}
		if (lastCheckWindowLeft != float.MinValue && (((Rect)(ref Rect[wIdx])).x != lastCheckWindowLeft || ((Rect)(ref Rect[wIdx])).y != lastCheckWindowTop))
		{
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		lastCheckWindowLeft = ((Rect)(ref Rect[wIdx])).x;
		lastCheckWindowTop = ((Rect)(ref Rect[wIdx])).y;
	}

	public static void WindowFunction(int windowId)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_007d: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_040c: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0502: Unknown result type (might be due to invalid IL or missing references)
		//IL_0545: Unknown result type (might be due to invalid IL or missing references)
		//IL_054a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0555: Unknown result type (might be due to invalid IL or missing references)
		//IL_0560: Unknown result type (might be due to invalid IL or missing references)
		//IL_0589: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		mainWindowStyleLabelStyle = (GUIStyle)(((object)mainWindowStyleLabelStyle) ?? ((object)new GUIStyle(GUI.skin.label)
		{
			fixedWidth = 120f,
			fixedHeight = 20f,
			fontSize = 12,
			alignment = (TextAnchor)3
		}));
		GUILayout.Label("Main Window Style :", mainWindowStyleLabelStyle, Array.Empty<GUILayoutOption>());
		mainWindowStyleButtonStyle = (GUIStyle)(((object)mainWindowStyleButtonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseToolbarButtonStyle)
		{
			fixedWidth = 80f,
			fixedHeight = 20f,
			fontSize = 12
		}));
		string[] array = new string[2] { "FULL", "MINI" };
		int num = ((CruiseAssistMainUI.ViewMode != CruiseAssistMainUIViewMode.FULL) ? 1 : 0);
		GUI.changed = false;
		int num2 = GUILayout.Toolbar(num, array, mainWindowStyleButtonStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
		}
		if (num2 != num)
		{
			switch (num2)
			{
			case 0:
				CruiseAssistMainUI.ViewMode = CruiseAssistMainUIViewMode.FULL;
				break;
			case 1:
				CruiseAssistMainUI.ViewMode = CruiseAssistMainUIViewMode.MINI;
				break;
			}
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		uiScaleTitleLabelStyle = (GUIStyle)(((object)uiScaleTitleLabelStyle) ?? ((object)new GUIStyle(GUI.skin.label)
		{
			fixedWidth = 60f,
			fixedHeight = 20f,
			fontSize = 12,
			alignment = (TextAnchor)3
		}));
		GUILayout.Label("UI Scale :", uiScaleTitleLabelStyle, Array.Empty<GUILayoutOption>());
		object obj = scaleSliderStyle;
		if (obj == null)
		{
			GUIStyle val = new GUIStyle(CruiseAssistMainUI.BaseHorizontalSliderStyle)
			{
				fixedWidth = 180f
			};
			val.margin.top = 10;
			val.alignment = (TextAnchor)3;
			obj = (object)val;
		}
		scaleSliderStyle = (GUIStyle)obj;
		scaleSliderThumbStyle = (GUIStyle)(((object)scaleSliderThumbStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseHorizontalSliderThumbStyle)));
		TempScale = GUILayout.HorizontalSlider(TempScale, 80f, 240f, scaleSliderStyle, scaleSliderThumbStyle, Array.Empty<GUILayoutOption>());
		TempScale = (int)TempScale / 5 * 5;
		uiScaleValueLabelStyle = (GUIStyle)(((object)uiScaleValueLabelStyle) ?? ((object)new GUIStyle(GUI.skin.label)
		{
			fixedWidth = 40f,
			fixedHeight = 20f,
			fontSize = 12,
			alignment = (TextAnchor)3
		}));
		GUILayout.Label(TempScale.ToString("0") + "%", uiScaleValueLabelStyle, Array.Empty<GUILayoutOption>());
		object obj2 = scaleSetButtonStyle;
		if (obj2 == null)
		{
			GUIStyle val2 = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
			{
				fixedWidth = 60f,
				fixedHeight = 18f
			};
			val2.margin.top = 6;
			val2.fontSize = 12;
			obj2 = (object)val2;
		}
		scaleSetButtonStyle = (GUIStyle)obj2;
		if (GUILayout.Button("SET", scaleSetButtonStyle, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.Scale = TempScale;
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUILayout.EndHorizontal();
		toggleStyle = (GUIStyle)(((object)toggleStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseToggleStyle)
		{
			fixedHeight = 20f,
			fontSize = 12,
			alignment = (TextAnchor)3
		}));
		GUI.changed = false;
		CruiseAssistPlugin.MarkVisitedFlag = GUILayout.Toggle(CruiseAssistPlugin.MarkVisitedFlag, "Mark the visited system and planet.", toggleStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		CruiseAssistPlugin.SelectFocusFlag = GUILayout.Toggle(CruiseAssistPlugin.SelectFocusFlag, "Focus when target selected.", toggleStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		CruiseAssistPlugin.HideDuplicateHistoryFlag = GUILayout.Toggle(CruiseAssistPlugin.HideDuplicateHistoryFlag, "Hide duplicate history.", toggleStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		CruiseAssistPlugin.AutoDisableLockCursorFlag = GUILayout.Toggle(CruiseAssistPlugin.AutoDisableLockCursorFlag, "Disable lock cursor when starting sail mode.", toggleStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		CruiseAssistPlugin.TrackDarkFogSeedsFlag = GUILayout.Toggle(CruiseAssistPlugin.TrackDarkFogSeedsFlag, "Display all active Dark Fog seeds in starlist.", toggleStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		CruiseAssistPlugin.PreventNonTargetLoadingFlag = GUILayout.Toggle(CruiseAssistPlugin.PreventNonTargetLoadingFlag, "Prevent loading of non-target stars when CruiseAssist is active.", toggleStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUILayout.FlexibleSpace();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		closeButtonStyle = (GUIStyle)(((object)closeButtonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
		{
			fixedWidth = 80f,
			fixedHeight = 20f,
			fontSize = 12
		}));
		if (GUILayout.Button("Close", closeButtonStyle, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			Show[wIdx] = false;
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow();
	}
}
public class CruiseAssistDebugUI
{
	public static bool Show = false;

	public static Rect Rect = new Rect(0f, 0f, 400f, 400f);

	private static float lastCheckWindowLeft = float.MinValue;

	private static float lastCheckWindowTop = float.MinValue;

	private static long nextCheckGameTick = long.MaxValue;

	private static Vector2 scrollPos = Vector2.zero;

	public static int trackedTinders = 0;

	public static void OnGUI()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.window);
		val.fontSize = 11;
		Rect = GUILayout.Window(99030294, Rect, new WindowFunction(WindowFunction), "CruiseAssist - Debug", val, Array.Empty<GUILayoutOption>());
		_ = CruiseAssistMainUI.Scale / 100f;
		if ((float)Screen.width < ((Rect)(ref Rect)).xMax)
		{
			((Rect)(ref Rect)).x = (float)Screen.width - ((Rect)(ref Rect)).width;
		}
		if (((Rect)(ref Rect)).x < 0f)
		{
			((Rect)(ref Rect)).x = 0f;
		}
		if ((float)Screen.height < ((Rect)(ref Rect)).yMax)
		{
			((Rect)(ref Rect)).y = (float)Screen.height - ((Rect)(ref Rect)).height;
		}
		if (((Rect)(ref Rect)).y < 0f)
		{
			((Rect)(ref Rect)).y = 0f;
		}
		if (lastCheckWindowLeft != float.MinValue && (((Rect)(ref Rect)).x != lastCheckWindowLeft || ((Rect)(ref Rect)).y != lastCheckWindowTop))
		{
			nextCheckGameTick = GameMain.gameTick + 300;
		}
		lastCheckWindowLeft = ((Rect)(ref Rect)).x;
		lastCheckWindowTop = ((Rect)(ref Rect)).y;
		if (nextCheckGameTick <= GameMain.gameTick)
		{
			ConfigManager.CheckConfig(ConfigManager.Step.STATE);
			nextCheckGameTick = long.MaxValue;
		}
	}

	public static void WindowFunction(int windowId)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.fontSize = 12;
		scrollPos = GUILayout.BeginScrollView(scrollPos, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"trackedTinders={trackedTinders}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.lockOn={CruiseAssistPlugin.lockOn}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.preloadStar={CruiseAssistPlugin.preloadStar?.id}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.localStar={GameMain.localStar?.id}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.localPlanet={GameMain.localPlanet?.id}", val, Array.Empty<GUILayoutOption>());
		StarData preloadStar = CruiseAssistPlugin.preloadStar;
		GUILayout.Label($"CruiseAssist.preloadStar.loaded={((preloadStar != null) ? new bool?(preloadStar.loaded) : null)}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.ReticuleTargetStar.id={CruiseAssistPlugin.ReticuleTargetStar?.id}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.ReticuleTargetPlanet.id={CruiseAssistPlugin.ReticuleTargetPlanet?.id}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.SelectTargetStar.id={CruiseAssistPlugin.SelectTargetStar?.id}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.SelectTargetPlanet.id={CruiseAssistPlugin.SelectTargetPlanet?.id}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.SelectTargetMsg.protoId={CruiseAssistPlugin.SelectTargetMsg?.protoId}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.TargetUPos={CruiseAssistPlugin.TargetUPos}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.uPosition={GameMain.mainPlayer.uPosition}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.navigation.indicatorAstroId={GameMain.mainPlayer.navigation.indicatorAstroId}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.navigation.indicatorEnemyId={GameMain.mainPlayer.navigation.indicatorEnemyId}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.navigation.indicatorMsgId={GameMain.mainPlayer.navigation.indicatorMsgId}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input0.w={GameMain.mainPlayer.controller.input0.w}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input0.x={GameMain.mainPlayer.controller.input0.x}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input0.y={GameMain.mainPlayer.controller.input0.y}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input0.z={GameMain.mainPlayer.controller.input0.z}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input1.w={GameMain.mainPlayer.controller.input1.w}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input1.x={GameMain.mainPlayer.controller.input1.x}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input1.y={GameMain.mainPlayer.controller.input1.y}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.controller.input1.z={GameMain.mainPlayer.controller.input1.z}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"VFInput._sailSpeedUp={VFInput._sailSpeedUp}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.Enable={CruiseAssistPlugin.Enable}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"CruiseAssist.History={CruiseAssistPlugin.History.Count()}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label("CruiseAssist.History=" + ListUtils.ToString(CruiseAssistPlugin.History), val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GUI.skin.window.margin.top={GUI.skin.window.margin.top}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GUI.skin.window.border.top={GUI.skin.window.border.top}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GUI.skin.window.padding.top={GUI.skin.window.padding.top}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GUI.skin.window.overflow.top={GUI.skin.window.overflow.top}", val, Array.Empty<GUILayoutOption>());
		GUILayout.EndScrollView();
		GUILayout.EndVertical();
		GUI.DragWindow();
	}
}
public enum CruiseAssistMainUIViewMode
{
	FULL,
	MINI
}
public class CruiseAssistStarListUI
{
	private static int wIdx = 0;

	public const float WindowWidth = 440f;

	public const float WindowHeight = 480f;

	public static bool[] Show = new bool[2];

	public static Rect[] Rect = (Rect[])(object)new Rect[2]
	{
		new Rect(0f, 0f, 440f, 480f),
		new Rect(0f, 0f, 440f, 480f)
	};

	public static int ListSelected = 0;

	public static int[] actionSelected = new int[3];

	private static float lastCheckWindowLeft = float.MinValue;

	private static float lastCheckWindowTop = float.MinValue;

	private static Vector2[] scrollPos = (Vector2[])(object)new Vector2[3]
	{
		Vector2.zero,
		Vector2.zero,
		Vector2.zero
	};

	private const string VisitedMark = "● ";

	private const string NonVisitMark = "";

	public static GUIStyle windowStyle = null;

	public static GUIStyle mainWindowStyleButtonStyle = null;

	public static GUIStyle nameLabelStyle = null;

	public static GUIStyle nRangeLabelStyle = null;

	public static GUIStyle hRangeLabelStyle = null;

	public static GUIStyle nActionButtonStyle = null;

	public static GUIStyle hActionButtonStyle = null;

	public static GUIStyle nSortButtonStyle = null;

	public static GUIStyle hSortButtonStyle = null;

	public static GUIStyle nViewButtonStyle = null;

	public static GUIStyle hViewButtonStyle = null;

	public static GUIStyle buttonStyle = null;

	public static GUIContent cheapText = null;

	public static string[][] listButtonModeName = new string[3][]
	{
		new string[2] { "Target", "Bookmark" },
		new string[3] { "Target", "Bookmark", "Delete" },
		new string[3] { "Target", "Sort", "Delete" }
	};

	public static GUIContent getCheapGUIContent(string text)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		cheapText = (GUIContent)(((object)cheapText) ?? ((object)new GUIContent()));
		cheapText.text = text;
		return cheapText;
	}

	public static void OnGUI()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_0067: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		wIdx = CruiseAssistMainUI.wIdx;
		windowStyle = (GUIStyle)(((object)windowStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.WindowStyle)));
		windowStyle.fontSize = 11;
		Rect[wIdx] = GUILayout.Window(99030292, Rect[wIdx], new WindowFunction(WindowFunction), "CruiseAssist - StarList", windowStyle, Array.Empty<GUILayoutOption>());
		float num = CruiseAssistMainUI.Scale / 100f;
		if ((float)Screen.width / num < ((Rect)(ref Rect[wIdx])).xMax)
		{
			((Rect)(ref Rect[wIdx])).x = (float)Screen.width / num - ((Rect)(ref Rect[wIdx])).width;
		}
		if (((Rect)(ref Rect[wIdx])).x < 0f)
		{
			((Rect)(ref Rect[wIdx])).x = 0f;
		}
		if ((float)Screen.height / num < ((Rect)(ref Rect[wIdx])).yMax)
		{
			((Rect)(ref Rect[wIdx])).y = (float)Screen.height / num - ((Rect)(ref Rect[wIdx])).height;
		}
		if (((Rect)(ref Rect[wIdx])).y < 0f)
		{
			((Rect)(ref Rect[wIdx])).y = 0f;
		}
		if (lastCheckWindowLeft != float.MinValue && (((Rect)(ref Rect[wIdx])).x != lastCheckWindowLeft || ((Rect)(ref Rect[wIdx])).y != lastCheckWindowTop))
		{
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		lastCheckWindowLeft = ((Rect)(ref Rect[wIdx])).x;
		lastCheckWindowTop = ((Rect)(ref Rect[wIdx])).y;
	}

	public static void WindowFunction(int windowId)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Unknown result type (might be due to invalid IL or missing references)
		//IL_059e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0603: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		mainWindowStyleButtonStyle = (GUIStyle)(((object)mainWindowStyleButtonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)));
		mainWindowStyleButtonStyle.fixedWidth = 80f;
		mainWindowStyleButtonStyle.fixedHeight = 20f;
		mainWindowStyleButtonStyle.fontSize = 12;
		string[] array = new string[3] { "Normal", "History", "Bookmark" };
		GUI.changed = false;
		int num = GUILayout.Toolbar(ListSelected, array, mainWindowStyleButtonStyle, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
		}
		if (num != ListSelected)
		{
			ListSelected = num;
			CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUILayout.EndHorizontal();
		scrollPos[ListSelected] = GUILayout.BeginScrollView(scrollPos[ListSelected], GUIStyle.none, CruiseAssistMainUI.BaseVerticalScrollBarStyle, Array.Empty<GUILayoutOption>());
		nameLabelStyle = (GUIStyle)(((object)nameLabelStyle) ?? ((object)new GUIStyle(GUI.skin.label)));
		nameLabelStyle.fixedWidth = 240f;
		nameLabelStyle.stretchHeight = true;
		nameLabelStyle.fontSize = 14;
		nameLabelStyle.alignment = (TextAnchor)3;
		nRangeLabelStyle = (GUIStyle)(((object)nRangeLabelStyle) ?? ((object)new GUIStyle(GUI.skin.label)));
		nRangeLabelStyle.fixedWidth = 60f;
		nRangeLabelStyle.fixedHeight = 20f;
		nRangeLabelStyle.fontSize = 14;
		nRangeLabelStyle.alignment = (TextAnchor)5;
		hRangeLabelStyle = (GUIStyle)(((object)hRangeLabelStyle) ?? ((object)new GUIStyle(nRangeLabelStyle)));
		hRangeLabelStyle.fixedHeight = 40f;
		nActionButtonStyle = (GUIStyle)(((object)nActionButtonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)));
		nActionButtonStyle.fixedWidth = 40f;
		nActionButtonStyle.fixedHeight = 18f;
		nActionButtonStyle.margin.top = 6;
		nActionButtonStyle.fontSize = 12;
		hActionButtonStyle = (GUIStyle)(((object)hActionButtonStyle) ?? ((object)new GUIStyle(nActionButtonStyle)));
		hActionButtonStyle.margin.top = 16;
		nSortButtonStyle = (GUIStyle)(((object)nSortButtonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)));
		nSortButtonStyle.fixedWidth = 20f;
		nSortButtonStyle.fixedHeight = 18f;
		nSortButtonStyle.margin.top = 6;
		nSortButtonStyle.fontSize = 12;
		hSortButtonStyle = (GUIStyle)(((object)hSortButtonStyle) ?? ((object)new GUIStyle(nSortButtonStyle)));
		hSortButtonStyle.margin.top = 16;
		nViewButtonStyle = (GUIStyle)(((object)nViewButtonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)));
		nViewButtonStyle.fixedWidth = 20f;
		nViewButtonStyle.fixedHeight = 18f;
		nViewButtonStyle.margin.top = 6;
		nViewButtonStyle.fontSize = 12;
		hViewButtonStyle = (GUIStyle)(((object)hViewButtonStyle) ?? ((object)new GUIStyle(nViewButtonStyle)));
		hViewButtonStyle.margin.top = 16;
		if (ListSelected == 0)
		{
			List<DFTinderComponent> activeTinders = null;
			CruiseAssistDebugUI.trackedTinders = 0;
			if (CruiseAssistPlugin.TrackDarkFogSeedsFlag)
			{
				activeTinders = new List<DFTinderComponent>();
				EnemyDFHiveSystem[] dfHivesByAstro = GameMain.spaceSector.dfHivesByAstro;
				foreach (EnemyDFHiveSystem val in dfHivesByAstro)
				{
					if (val == null || val.tinderCount == 0)
					{
						continue;
					}
					CruiseAssistDebugUI.trackedTinders += val.tinders.cursor;
					for (int j = 1; j < val.tinders.cursor; j++)
					{
						if (((DFTinderComponent)(ref val.tinders.buffer[j])).ID > 0)
						{
							DFTinderComponent val2 = val.tinders.buffer[j];
							if (val2.stage >= -1 && val2.direction > 0)
							{
								activeTinders.Add(val2);
							}
						}
					}
				}
			}
			CollectionExtensions.Do<Tuple<StarData, double>>((IEnumerable<Tuple<StarData, double>>)(from tuple in GameMain.galaxy.stars.Select(delegate(StarData star)
				{
					//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0016: Unknown result type (might be due to invalid IL or missing references)
					VectorLF3 val9 = star.uPosition - GameMain.mainPlayer.uPosition;
					return new Tuple<StarData, double>(star, ((VectorLF3)(ref val9)).magnitude);
				})
				orderby tuple.v2
				select tuple), (Action<Tuple<StarData, double>>)delegate(Tuple<StarData, double> tuple)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_0664: Unknown result type (might be due to invalid IL or missing references)
				//IL_0678: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_06be: Unknown result type (might be due to invalid IL or missing references)
				//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0602: Unknown result type (might be due to invalid IL or missing references)
				//IL_0607: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0267: Unknown result type (might be due to invalid IL or missing references)
				//IL_0823: Unknown result type (might be due to invalid IL or missing references)
				//IL_0284: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
				StarData star3 = tuple.v1;
				double range = tuple.v2;
				string starName = CruiseAssistPlugin.GetStarName(star3);
				bool flag3 = false;
				List<Tuple<EnemyData, double>> list = new List<Tuple<EnemyData, double>>();
				VectorLF3 val6;
				if (activeTinders != null)
				{
					foreach (DFTinderComponent item in activeTinders)
					{
						EnemyDFHiveSystem hiveByAstroId = GameMain.spaceSector.GetHiveByAstroId(item.targetHiveAstroId);
						if (hiveByAstroId != null && hiveByAstroId.starData.id == star3.id)
						{
							EnemyData val5 = GameMain.spaceSector.enemyPool[item.enemyId];
							val6 = val5.pos - GameMain.mainPlayer.uPosition;
							double magnitude2 = ((VectorLF3)(ref val6)).magnitude;
							list.Add(new Tuple<EnemyData, double>(val5, magnitude2));
						}
					}
					list.Sort((Tuple<EnemyData, double> tuple1, Tuple<EnemyData, double> tuple2) => tuple1.v2.CompareTo(tuple2.v2));
					foreach (Tuple<EnemyData, double> item2 in list)
					{
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
						EnemyData v = item2.v1;
						double v2 = item2.v2;
						nameLabelStyle.normal.textColor = Color.red;
						nRangeLabelStyle.normal.textColor = Color.red;
						if (CruiseAssistPlugin.TargetEnemyId != 0 && v.id == CruiseAssistPlugin.TargetEnemyId)
						{
							nameLabelStyle.normal.textColor = CruiseAssistMainUI.enemyTextColor;
							nRangeLabelStyle.normal.textColor = CruiseAssistMainUI.enemyTextColor;
						}
						string text3 = starName + " ← " + CruiseAssistPlugin.GetEnemyName(v);
						GUILayout.Label(text3, nameLabelStyle, Array.Empty<GUILayoutOption>());
						float num5 = nameLabelStyle.CalcHeight(getCheapGUIContent(text3), nameLabelStyle.fixedWidth);
						GUILayout.FlexibleSpace();
						GUILayout.Label(CruiseAssistMainUI.RangeToString(v2), (num5 < 30f) ? nRangeLabelStyle : hRangeLabelStyle, Array.Empty<GUILayoutOption>());
						if (GUILayout.Button((actionSelected[ListSelected] == 0) ? "SET" : "-", (num5 < 30f) ? nActionButtonStyle : hActionButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectEnemy(v.id);
							}
						}
						if (actionSelected[ListSelected] == 0 && GUILayout.Button("-", (num5 < 30f) ? nSortButtonStyle : hSortButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
						}
						GUILayout.EndHorizontal();
					}
				}
				UIStarmap starmap = UIRoot.instance.uiGame.starmap;
				if (GameMain.localStar != null && star3.id == GameMain.localStar.id)
				{
					flag3 = true;
				}
				else if ((star3.id == CruiseAssistPlugin.SelectTargetStar?.id || star3.id == starmap.focusStar?.star.id || star3.id == starmap.focusPlanet?.planet.star.id || star3.id == starmap.focusHive?.hive.starData.id || star3.id == starmap.viewStar?.id || star3.id == starmap.viewPlanet?.star.id || star3.id == starmap.viewHive?.starData.id) && GameMain.history.universeObserveLevel >= ((range >= 14400000.0) ? 4 : 3))
				{
					flag3 = true;
				}
				if (flag3)
				{
					CollectionExtensions.Do<Tuple<EnemyDFHiveSystem, double>>((IEnumerable<Tuple<EnemyDFHiveSystem, double>>)(from tuple2 in GameMain.spaceSector.dfHivesByAstro.Where((EnemyDFHiveSystem hive) => hive != null && hive.starData.id == star3.id && hive.hasAnyStructureOrUnit).Select(delegate(EnemyDFHiveSystem hive)
						{
							//IL_001c: Unknown result type (might be due to invalid IL or missing references)
							//IL_0026: Unknown result type (might be due to invalid IL or missing references)
							//IL_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)
							VectorLF3 val8 = GameMain.spaceSector.astros[hive.hiveAstroId - 1000000].uPos - GameMain.mainPlayer.uPosition;
							return new Tuple<EnemyDFHiveSystem, double>(hive, ((VectorLF3)(ref val8)).magnitude);
						})
						orderby tuple2.v2
						select tuple2), (Action<Tuple<EnemyDFHiveSystem, double>>)delegate(Tuple<EnemyDFHiveSystem, double> tuple2)
					{
						//IL_0023: 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_0064: 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_0130: Unknown result type (might be due to invalid IL or missing references)
						//IL_0192: Unknown result type (might be due to invalid IL or missing references)
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
						EnemyDFHiveSystem v5 = tuple2.v1;
						double v6 = tuple2.v2;
						nameLabelStyle.normal.textColor = Color.white;
						nRangeLabelStyle.normal.textColor = Color.white;
						if (CruiseAssistPlugin.SelectTargetHive != null && v5.hiveAstroId == CruiseAssistPlugin.SelectTargetHive.hiveAstroId)
						{
							nameLabelStyle.normal.textColor = CruiseAssistMainUI.hiveTextColor;
							nRangeLabelStyle.normal.textColor = CruiseAssistMainUI.hiveTextColor;
						}
						string text7 = starName + " - " + CruiseAssistPlugin.GetHiveName(v5);
						GUILayout.Label(text7, nameLabelStyle, Array.Empty<GUILayoutOption>());
						float num8 = nameLabelStyle.CalcHeight(getCheapGUIContent(text7), nameLabelStyle.fixedWidth);
						GUILayout.FlexibleSpace();
						GUILayout.Label(CruiseAssistMainUI.RangeToString(v6), (num8 < 30f) ? nRangeLabelStyle : hRangeLabelStyle, Array.Empty<GUILayoutOption>());
						if (GUILayout.Button((actionSelected[ListSelected] == 0) ? "SET" : "-", (num8 < 30f) ? nActionButtonStyle : hActionButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectHive(star3, v5);
							}
						}
						if (actionSelected[ListSelected] == 0 && GUILayout.Button("V", (num8 < 30f) ? nViewButtonStyle : hViewButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectHive(star3, v5, set: false);
							}
						}
						GUILayout.EndHorizontal();
					});
					IEnumerable<Tuple<PlanetData, double>> enumerable4 = star3.planets.Select(delegate(PlanetData planet)
					{
						//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
						//IL_0016: Unknown result type (might be due to invalid IL or missing references)
						VectorLF3 val7 = planet.uPosition - GameMain.mainPlayer.uPosition;
						return new Tuple<PlanetData, double>(planet, ((VectorLF3)(ref val7)).magnitude);
					});
					val6 = star3.uPosition - GameMain.mainPlayer.uPosition;
					CollectionExtensions.Do<Tuple<PlanetData, double>>((IEnumerable<Tuple<PlanetData, double>>)(from tuple2 in CollectionExtensions.AddItem<Tuple<PlanetData, double>>(enumerable4, new Tuple<PlanetData, double>(null, ((VectorLF3)(ref val6)).magnitude))
						orderby tuple2.v2
						select tuple2), (Action<Tuple<PlanetData, double>>)delegate(Tuple<PlanetData, double> tuple2)
					{
						//IL_0024: Unknown result type (might be due to invalid IL or missing references)
						//IL_0038: Unknown result type (might be due to invalid IL or missing references)
						//IL_0140: Unknown result type (might be due to invalid IL or missing references)
						//IL_0154: Unknown result type (might be due to invalid IL or missing references)
						//IL_0077: Unknown result type (might be due to invalid IL or missing references)
						//IL_008b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0265: Unknown result type (might be due to invalid IL or missing references)
						//IL_0323: Unknown result type (might be due to invalid IL or missing references)
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
						PlanetData v3 = tuple2.v1;
						double v4 = tuple2.v2;
						nameLabelStyle.normal.textColor = Color.white;
						nRangeLabelStyle.normal.textColor = Color.white;
						float num7;
						if (v3 == null)
						{
							if (CruiseAssistPlugin.SelectTargetPlanet == null && CruiseAssistPlugin.SelectTargetStar != null && star3.id == CruiseAssistPlugin.SelectTargetStar.id)
							{
								nameLabelStyle.normal.textColor = Color.cyan;
								nRangeLabelStyle.normal.textColor = Color.cyan;
							}
							string text5 = starName;
							if (CruiseAssistPlugin.MarkVisitedFlag)
							{
								text5 = ((star3.planets.Where((PlanetData p) => p.factory != null).Count() > 0) ? "● " : "") + text5;
							}
							GUILayout.Label(text5, nameLabelStyle, Array.Empty<GUILayoutOption>());
							num7 = nameLabelStyle.CalcHeight(getCheapGUIContent(text5), nameLabelStyle.fixedWidth);
						}
						else
						{
							if (CruiseAssistPlugin.SelectTargetPlanet != null && v3.id == CruiseAssistPlugin.SelectTargetPlanet.id)
							{
								nameLabelStyle.normal.textColor = Color.cyan;
								nRangeLabelStyle.normal.textColor = Color.cyan;
							}
							string text6 = starName + " - " + CruiseAssistPlugin.GetPlanetName(v3);
							if (CruiseAssistPlugin.MarkVisitedFlag)
							{
								text6 = ((v3.factory != null) ? "● " : "") + text6;
							}
							GUILayout.Label(text6, nameLabelStyle, Array.Empty<GUILayoutOption>());
							num7 = nameLabelStyle.CalcHeight(getCheapGUIContent(text6), nameLabelStyle.fixedWidth);
						}
						GUILayout.FlexibleSpace();
						GUILayout.Label(CruiseAssistMainUI.RangeToString((v3 == null) ? range : v4), (num7 < 30f) ? nRangeLabelStyle : hRangeLabelStyle, Array.Empty<GUILayoutOption>());
						if (GUILayout.Button((actionSelected[ListSelected] == 0) ? "SET" : ((v3 == null) ? "-" : (CruiseAssistPlugin.Bookmark.Contains(v3.id) ? "DEL" : "ADD")), (num7 < 30f) ? nActionButtonStyle : hActionButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectStar(star3, v3);
							}
							else if (v3 != null)
							{
								if (CruiseAssistPlugin.Bookmark.Contains(v3.id))
								{
									CruiseAssistPlugin.Bookmark.Remove(v3.id);
								}
								else if (CruiseAssistPlugin.Bookmark.Count <= 128)
								{
									CruiseAssistPlugin.Bookmark.Add(v3.id);
									CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
								}
							}
						}
						if (actionSelected[ListSelected] == 0 && GUILayout.Button("V", (num7 < 30f) ? nViewButtonStyle : hViewButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectStar(star3, v3, set: false);
							}
						}
						GUILayout.EndHorizontal();
					});
				}
				else
				{
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					nameLabelStyle.normal.textColor = Color.white;
					nRangeLabelStyle.normal.textColor = Color.white;
					if (CruiseAssistPlugin.SelectTargetStar != null && star3.id == CruiseAssistPlugin.SelectTargetStar.id)
					{
						nameLabelStyle.normal.textColor = Color.cyan;
						nRangeLabelStyle.normal.textColor = Color.cyan;
					}
					string text4 = starName;
					if (CruiseAssistPlugin.MarkVisitedFlag)
					{
						text4 = ((star3.planets.Where((PlanetData p) => p.factory != null).Count() > 0) ? "● " : "") + text4;
					}
					GUILayout.Label(text4, nameLabelStyle, Array.Empty<GUILayoutOption>());
					float num6 = nameLabelStyle.CalcHeight(getCheapGUIContent(text4), nameLabelStyle.fixedWidth);
					GUILayout.FlexibleSpace();
					GUILayout.Label(CruiseAssistMainUI.RangeToString(range), (num6 < 30f) ? nRangeLabelStyle : hRangeLabelStyle, Array.Empty<GUILayoutOption>());
					if (GUILayout.Button((actionSelected[ListSelected] == 0) ? "SET" : "-", (num6 < 30f) ? nActionButtonStyle : hActionButtonStyle, Array.Empty<GUILayoutOption>()))
					{
						VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
						if (actionSelected[ListSelected] == 0)
						{
							SelectStar(star3, null);
						}
					}
					if (actionSelected[ListSelected] == 0 && GUILayout.Button("V", (num6 < 30f) ? nViewButtonStyle : hViewButtonStyle, Array.Empty<GUILayoutOption>()))
					{
						VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
						if (actionSelected[ListSelected] == 0)
						{
							SelectStar(star3, null, set: false);
						}
					}
					GUILayout.EndHorizontal();
				}
			});
		}
		else if (ListSelected == 1 || ListSelected == 2)
		{
			bool highlighted = false;
			IEnumerable<int> enumerable2;
			if (ListSelected != 1)
			{
				IEnumerable<int> enumerable = CruiseAssistPlugin.Bookmark.ToList();
				enumerable2 = enumerable;
			}
			else
			{
				enumerable2 = Enumerable.Reverse(CruiseAssistPlugin.History);
			}
			IEnumerable<int> enumerable3 = enumerable2;
			if (ListSelected == 1 && actionSelected[ListSelected] != 2 && CruiseAssistPlugin.HideDuplicateHistoryFlag)
			{
				enumerable3 = enumerable3.Distinct();
			}
			int listIndex = -1;
			CollectionExtensions.Do<int>(enumerable3, (Action<int>)delegate(int id)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_005d: 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)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_01de: Unknown result type (might be due to invalid IL or missing references)
				//IL_0442: Unknown result type (might be due to invalid IL or missing references)
				//IL_0246: Unknown result type (might be due to invalid IL or missing references)
				int num2 = listIndex + 1;
				listIndex = num2;
				PlanetData val3 = GameMain.galaxy.PlanetById(id);
				if (val3 != null)
				{
					StarData star2 = val3.star;
					string text = CruiseAssistPlugin.GetStarName(star2);
					VectorLF3 val4 = val3.uPosition - GameMain.mainPlayer.uPosition;
					double magnitude = ((VectorLF3)(ref val4)).magnitude;
					nameLabelStyle.normal.textColor = Color.white;
					nRangeLabelStyle.normal.textColor = Color.white;
					if (!highlighted && CruiseAssistPlugin.SelectTargetPlanet != null && val3.id == CruiseAssistPlugin.SelectTargetPlanet.id)
					{
						nameLabelStyle.normal.textColor = Color.cyan;
						nRangeLabelStyle.normal.textColor = Color.cyan;
						highlighted = true;
					}
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					string text2 = text + " - " + CruiseAssistPlugin.GetPlanetName(val3);
					if (CruiseAssistPlugin.MarkVisitedFlag)
					{
						text2 = ((val3.factory != null) ? "● " : "") + text2;
					}
					GUILayout.Label(text2, nameLabelStyle, Array.Empty<GUILayoutOption>());
					float num3 = nameLabelStyle.CalcHeight(getCheapGUIContent(text2), nameLabelStyle.fixedWidth);
					GUILayout.FlexibleSpace();
					GUILayout.Label(CruiseAssistMainUI.RangeToString(magnitude), (num3 < 30f) ? nRangeLabelStyle : hRangeLabelStyle, Array.Empty<GUILayoutOption>());
					if (ListSelected == 2 && actionSelected[ListSelected] == 1)
					{
						int num4 = CruiseAssistPlugin.Bookmark.IndexOf(id);
						bool flag = num4 == 0;
						bool flag2 = num4 == CruiseAssistPlugin.Bookmark.Count - 1;
						if (GUILayout.Button(flag2 ? "-" : "↓", (num3 < 30f) ? nSortButtonStyle : hSortButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (!flag2)
							{
								CruiseAssistPlugin.Bookmark.RemoveAt(num4);
								CruiseAssistPlugin.Bookmark.Insert(num4 + 1, id);
							}
						}
						if (GUILayout.Button(flag ? "-" : "↑", (num3 < 30f) ? nSortButtonStyle : hSortButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (!flag)
							{
								CruiseAssistPlugin.Bookmark.RemoveAt(num4);
								CruiseAssistPlugin.Bookmark.Insert(num4 - 1, id);
							}
						}
					}
					else
					{
						if (GUILayout.Button((actionSelected[ListSelected] == 0) ? "SET" : ((actionSelected[ListSelected] != 2) ? (CruiseAssistPlugin.Bookmark.Contains(id) ? "DEL" : "ADD") : ((ListSelected == 1 && listIndex == 0) ? "-" : "DEL")), (num3 < 30f) ? nActionButtonStyle : hActionButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectStar(star2, val3);
							}
							else if (actionSelected[ListSelected] == 1)
							{
								if (ListSelected == 1)
								{
									if (CruiseAssistPlugin.Bookmark.Contains(id))
									{
										CruiseAssistPlugin.Bookmark.Remove(id);
									}
									else if (CruiseAssistPlugin.Bookmark.Count <= 128)
									{
										CruiseAssistPlugin.Bookmark.Add(id);
										CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
									}
								}
							}
							else if (actionSelected[ListSelected] == 2)
							{
								if (ListSelected == 1)
								{
									if (listIndex != 0)
									{
										CruiseAssistPlugin.History.RemoveAt(CruiseAssistPlugin.History.Count - 1 - listIndex);
										CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
									}
								}
								else if (ListSelected == 2)
								{
									CruiseAssistPlugin.Bookmark.Remove(val3.id);
									CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300;
								}
							}
						}
						if (actionSelected[ListSelected] == 0 && GUILayout.Button("V", (num3 < 30f) ? nViewButtonStyle : hViewButtonStyle, Array.Empty<GUILayoutOption>()))
						{
							VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
							if (actionSelected[ListSelected] == 0)
							{
								SelectStar(star2, val3, set: false);
							}
						}
					}
					GUILayout.EndHorizontal();
				}
			});
		}
		GUILayout.EndScrollView();
		GUILayout.FlexibleSpace();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		buttonStyle = (GUIStyle)(((object)buttonStyle) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)));
		buttonStyle.fixedWidth = 80f;
		buttonStyle.fixedHeight = 20f;
		buttonStyle.fontSize = 12;
		if (GUILayout.Button(listButtonModeName[ListSelected][actionSelected[ListSelected]], buttonStyle, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			actionSelected[ListSelected]++;
			actionSelected[ListSelected] %= listButtonModeName[ListSelected].Length;
		}
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("Close", buttonStyle, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			Show[wIdx] = false;
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow();
	}

	public static void SelectStar(StarData star, PlanetData planet, bool set = true)
	{
		UIGame uiGame = UIRoot.instance.uiGame;
		if (CruiseAssistPlugin.SelectFocusFlag && ((ManualBehaviour)uiGame.starmap).active)
		{
			if (star != null)
			{
				UIStarmapStar val = uiGame.starmap.starUIs.Where((UIStarmapStar s) => s.star.id == star.id).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					UIStarmap_OnStarClick(uiGame.starmap, val);
					uiGame.starmap.OnCursorFunction2Click(0);
				}
			}
			if (planet != null)
			{
				UIStarmapPlanet val2 = uiGame.starmap.planetUIs.Where((UIStarmapPlanet p) => p.planet.id == planet.id).FirstOrDefault();
				if ((Object)(object)val2 != (Object)null)
				{
					UIStarmap_OnPlanetClick(uiGame.starmap, val2);
					uiGame.starmap.OnCursorFunction2Click(0);
				}
			}
		}
		if (set)
		{
			if (planet != null)
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = planet.id;
			}
			else if (star != null)
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = star.id * 100;
			}
			else
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = 0;
			}
		}
	}

	public static void SelectHive(StarData star, EnemyDFHiveSystem hive, bool set = true)
	{
		UIGame uiGame = UIRoot.instance.uiGame;
		if (CruiseAssistPlugin.SelectFocusFlag && ((ManualBehaviour)uiGame.starmap).active)
		{
			if (star != null)
			{
				UIStarmapStar val = uiGame.starmap.starUIs.Where((UIStarmapStar s) => s.star.id == star.id).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					UIStarmap_OnStarClick(uiGame.starmap, val);
					uiGame.starmap.OnCursorFunction2Click(0);
				}
			}
			if (hive != null)
			{
				UIStarmapDFHive val2 = uiGame.starmap.dfHiveUIs.Where((UIStarmapDFHive p) => p.hive.hiveAstroId == hive.hiveAstroId).FirstOrDefault();
				if ((Object)(object)val2 != (Object)null)
				{
					UIStarmap_OnHiveClick(uiGame.starmap, val2);
					uiGame.starmap.OnCursorFunction2Click(0);
				}
			}
		}
		if (set)
		{
			if (hive != null)
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = hive.hiveAstroId;
			}
			else if (star != null)
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = star.id * 100;
			}
			else
			{
				GameMain.mainPlayer.navigation.indicatorAstroId = 0;
			}
		}
	}

	public static void SelectEnemy(int enemyId)
	{
		if (enemyId != 0)
		{
			GameMain.mainPlayer.navigation.indicatorEnemyId = enemyId;
		}
	}

	private static void UIStarmap_OnStarClick(UIStarmap starmap, UIStarmapStar star)
	{
		Traverse val = Traverse.Create((object)starmap);
		if ((Object)(object)starmap.focusStar != (Object)(object)star)
		{
			starmap.screenCameraController.DisablePositionLock();
			starmap.focusPlanet = null;
			starmap.focusHive = null;
			starmap.focusStar = star;
			val.Field("_lastClickTime").SetValue((object)0.0);
		}
		val.Field("forceUpdateCursorView").SetValue((object)true);
	}

	private static void UIStarmap_OnPlanetClick(UIStarmap starmap, UIStarmapPlanet planet)
	{
		Traverse val = Traverse.Create((object)starmap);
		if ((Object)(object)starmap.focusPlanet != (Object)(object)planet)
		{
			if ((starmap.viewPlanet != null && planet.planet != starmap.viewPlanet) || starmap.viewStar != null)
			{
				starmap.screenCameraController.DisablePositionLock();
			}
			starmap.focusPlanet = planet;
			starmap.focusHive = null;
			starmap.focusStar = null;
			val.Field("_lastClickTime").SetValue((object)0.0);
		}
		val.Field("forceUpdateCursorView").SetValue((object)tru

AutoPilot.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using tanu.CruiseAssist;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace tanu.AutoPilot;

internal class AutoPilotConfigManager : ConfigManager
{
	internal AutoPilotConfigManager(ConfigFile Config)
		: base(Config)
	{
	}

	protected override void CheckConfigImplements(Step step)
	{
		bool flag = false;
		if (step == Step.AWAKE)
		{
			ConfigManager.Bind("Base", "ModVersion", "1.3.1", "Don't change.").Value = "1.3.1";
			flag = true;
		}
		if (step == Step.AWAKE || step == Step.GAME_MAIN_BEGIN)
		{
			AutoPilotDebugUI.Show = ConfigManager.Bind("Debug", "DebugWindowShow", defaultValue: false).Value;
			AutoPilotPlugin.Conf.MinEnergyPer = ConfigManager.Bind("Setting", "MinEnergyPer", 20).Value;
			AutoPilotPlugin.Conf.MaxSpeed = ConfigManager.Bind("Setting", "MaxSpeed", 2000).Value;
			AutoPilotPlugin.Conf.WarpMinRangeAU = ConfigManager.Bind("Setting", "WarpMinRangeAU", 2).Value;
			AutoPilotPlugin.Conf.SpeedToWarp = ConfigManager.Bind("Setting", "WarpSpeed", 400).Value;
			AutoPilotPlugin.Conf.LocalWarpFlag = ConfigManager.Bind("Setting", "LocalWarp", defaultValue: false).Value;
			AutoPilotPlugin.Conf.AutoStartFlag = ConfigManager.Bind("Setting", "AutoStart", defaultValue: true).Value;
			AutoPilotPlugin.Conf.MainWindowJoinFlag = ConfigManager.Bind("Setting", "MainWindowJoin", defaultValue: true).Value;
			for (int i = 0; i < 2; i++)
			{
				((Rect)(ref AutoPilotMainUI.Rect[i])).x = ConfigManager.Bind("State", $"MainWindow{i}Left", 100).Value;
				((Rect)(ref AutoPilotMainUI.Rect[i])).y = ConfigManager.Bind("State", $"MainWindow{i}Top", 100).Value;
				((Rect)(ref AutoPilotConfigUI.Rect[i])).x = ConfigManager.Bind("State", $"ConfigWindow{i}Left", 100).Value;
				((Rect)(ref AutoPilotConfigUI.Rect[i])).y = ConfigManager.Bind("State", $"ConfigWindow{i}Top", 100).Value;
			}
			((Rect)(ref AutoPilotDebugUI.Rect)).x = ConfigManager.Bind("State", "DebugWindowLeft", 100).Value;
			((Rect)(ref AutoPilotDebugUI.Rect)).y = ConfigManager.Bind("State", "DebugWindowTop", 100).Value;
		}
		else if (step == Step.STATE)
		{
			LogManager.LogInfo("check state.");
			flag |= ConfigManager.UpdateEntry("Setting", "MinEnergyPer", AutoPilotPlugin.Conf.MinEnergyPer);
			flag |= ConfigManager.UpdateEntry("Setting", "MaxSpeed", AutoPilotPlugin.Conf.MaxSpeed);
			flag |= ConfigManager.UpdateEntry("Setting", "WarpMinRangeAU", AutoPilotPlugin.Conf.WarpMinRangeAU);
			flag |= ConfigManager.UpdateEntry("Setting", "WarpSpeed", AutoPilotPlugin.Conf.SpeedToWarp);
			flag |= ConfigManager.UpdateEntry("Setting", "LocalWarp", AutoPilotPlugin.Conf.LocalWarpFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "AutoStart", AutoPilotPlugin.Conf.AutoStartFlag);
			flag |= ConfigManager.UpdateEntry("Setting", "MainWindowJoin", AutoPilotPlugin.Conf.MainWindowJoinFlag);
			for (int j = 0; j < 2; j++)
			{
				flag |= ConfigManager.UpdateEntry("State", $"MainWindow{j}Left", (int)((Rect)(ref AutoPilotMainUI.Rect[j])).x);
				flag |= ConfigManager.UpdateEntry("State", $"MainWindow{j}Top", (int)((Rect)(ref AutoPilotMainUI.Rect[j])).y);
				flag |= ConfigManager.UpdateEntry("State", $"ConfigWindow{j}Left", (int)((Rect)(ref AutoPilotConfigUI.Rect[j])).x);
				flag |= ConfigManager.UpdateEntry("State", $"ConfigWindow{j}Top", (int)((Rect)(ref AutoPilotConfigUI.Rect[j])).y);
			}
			flag |= ConfigManager.UpdateEntry("State", "DebugWindowLeft", (int)((Rect)(ref AutoPilotDebugUI.Rect)).x);
			flag |= ConfigManager.UpdateEntry("State", "DebugWindowTop", (int)((Rect)(ref AutoPilotDebugUI.Rect)).y);
			AutoPilotMainUI.NextCheckGameTick = long.MaxValue;
		}
		if (flag)
		{
			ConfigManager.Save();
		}
	}
}
internal class AutoPilotConfigUI
{
	public static GUIStyle guistyle = null;

	public static GUIStyle guistyle2 = null;

	public static GUIStyle guistyle3 = null;

	private static int wIdx = 0;

	public const float WindowWidth = 400f;

	public const float WindowHeight = 400f;

	public static bool[] Show = new bool[2];

	public static Rect[] Rect = (Rect[])(object)new Rect[2]
	{
		new Rect(0f, 0f, 400f, 400f),
		new Rect(0f, 0f, 400f, 400f)
	};

	private static float[] lastCheckWindowLeft = new float[2]
	{
		float.MinValue,
		float.MinValue
	};

	private static float[] lastCheckWindowTop = new float[2]
	{
		float.MinValue,
		float.MinValue
	};

	public static string TempMinEnergyPer;

	public static string TempMaxSpeed;

	public static string TempWarpMinRangeAU;

	public static string TempSpeedToWarp;

	public static void OnGUI()
	{
		//IL_0023: 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_0048: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		wIdx = CruiseAssistMainUI.wIdx;
		Rect[wIdx] = GUILayout.Window(99031292, Rect[wIdx], new WindowFunction(WindowFunction), "AutoPilot - Config", CruiseAssistMainUI.WindowStyle, Array.Empty<GUILayoutOption>());
		float num = CruiseAssistMainUI.Scale / 100f;
		if ((float)Screen.width / num < ((Rect)(ref Rect[wIdx])).xMax)
		{
			((Rect)(ref Rect[wIdx])).x = (float)Screen.width / num - ((Rect)(ref Rect[wIdx])).width;
		}
		if (((Rect)(ref Rect[wIdx])).x < 0f)
		{
			((Rect)(ref Rect[wIdx])).x = 0f;
		}
		if ((float)Screen.height / num < ((Rect)(ref Rect[wIdx])).yMax)
		{
			((Rect)(ref Rect[wIdx])).y = (float)Screen.height / num - ((Rect)(ref Rect[wIdx])).height;
		}
		if (((Rect)(ref Rect[wIdx])).y < 0f)
		{
			((Rect)(ref Rect[wIdx])).y = 0f;
		}
		if (lastCheckWindowLeft[wIdx] != float.MinValue && (((Rect)(ref Rect[wIdx])).x != lastCheckWindowLeft[wIdx] || ((Rect)(ref Rect[wIdx])).y != lastCheckWindowTop[wIdx]))
		{
			AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		lastCheckWindowLeft[wIdx] = ((Rect)(ref Rect[wIdx])).x;
		lastCheckWindowTop[wIdx] = ((Rect)(ref Rect[wIdx])).y;
	}

	public static void WindowFunction(int windowId)
	{
		//IL_001d: 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_02ce: 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)
		//IL_038b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0431: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		guistyle = (GUIStyle)(((object)guistyle) ?? ((object)new GUIStyle(GUI.skin.label)));
		guistyle.fontSize = 12;
		guistyle.fixedHeight = 20f;
		guistyle.alignment = (TextAnchor)3;
		guistyle2 = (GUIStyle)(((object)guistyle2) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseTextFieldStyle)));
		guistyle2.fontSize = 12;
		guistyle2.fixedWidth = 60f;
		guistyle.fixedHeight = 20f;
		guistyle2.alignment = (TextAnchor)5;
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		guistyle.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Min Energy Percent (0-100 default:20)"), guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr = GUILayout.TextField(TempMinEnergyPer, guistyle2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempMinEnergyPer, instr, 0, 100, ref AutoPilotPlugin.Conf.MinEnergyPer);
		guistyle.fixedWidth = 20f;
		GUILayout.Label("%", guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		guistyle.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Max Speed (0-2000 default:2000)"), guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr2 = GUILayout.TextField(TempMaxSpeed, guistyle2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempMaxSpeed, instr2, 0, 2000, ref AutoPilotPlugin.Conf.MaxSpeed);
		guistyle.fixedWidth = 20f;
		GUILayout.Label("m/s", guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		guistyle.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Warp Min Range (0-60 default:2)"), guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr3 = GUILayout.TextArea(TempWarpMinRangeAU, guistyle2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempWarpMinRangeAU, instr3, 0, 60, ref AutoPilotPlugin.Conf.WarpMinRangeAU);
		guistyle.fixedWidth = 20f;
		GUILayout.Label("AU", guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		guistyle.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Speed to warp (0-2000 default:400)"), guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr4 = GUILayout.TextArea(TempSpeedToWarp, guistyle2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempSpeedToWarp, instr4, 0, 2000, ref AutoPilotPlugin.Conf.SpeedToWarp);
		guistyle.fixedWidth = 20f;
		GUILayout.Label("m/s", guistyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		guistyle3 = (GUIStyle)(((object)guistyle3) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseToggleStyle)));
		guistyle3.fixedHeight = 20f;
		guistyle3.fontSize = 12;
		guistyle3.alignment = (TextAnchor)6;
		GUI.changed = false;
		AutoPilotPlugin.Conf.LocalWarpFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.LocalWarpFlag, Localization.Translate("Warp to planet in local system."), guistyle3, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		AutoPilotPlugin.Conf.AutoStartFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.AutoStartFlag, Localization.Translate("Start AutoPilot when set target planet."), guistyle3, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUI.changed = false;
		AutoPilotPlugin.Conf.MainWindowJoinFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.MainWindowJoinFlag, Localization.Translate("Join AutoPilot window to CruiseAssist window."), guistyle3, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		GUILayout.EndVertical();
		if (GUI.Button(new Rect(((Rect)(ref Rect[wIdx])).width - 16f, 1f, 16f, 16f), "", CruiseAssistMainUI.CloseButtonStyle))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			Show[wIdx] = false;
		}
		GUI.DragWindow();
	}

	private static bool SetValue(ref string temp, string instr, int min, int max, ref int value)
	{
		if (string.IsNullOrEmpty(instr))
		{
			temp = string.Empty;
			return false;
		}
		if (int.TryParse(instr, out var result))
		{
			if (result < min)
			{
				result = min;
			}
			else if (max < result)
			{
				result = max;
			}
			value = result;
			temp = value.ToString();
			return true;
		}
		return false;
	}
}
internal class AutoPilotDebugUI
{
	public static bool Show = false;

	public static Rect Rect = new Rect(0f, 0f, 400f, 400f);

	private static float lastCheckWindowLeft = float.MinValue;

	private static float lastCheckWindowTop = float.MinValue;

	private static Vector2 scrollPos = Vector2.zero;

	public static void OnGUI()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.window);
		val.fontSize = 11;
		Rect = GUILayout.Window(99031293, Rect, new WindowFunction(WindowFunction), "AutoPilot - Debug", val, Array.Empty<GUILayoutOption>());
		_ = CruiseAssistMainUI.Scale / 100f;
		if ((float)Screen.width < ((Rect)(ref Rect)).xMax)
		{
			((Rect)(ref Rect)).x = (float)Screen.width - ((Rect)(ref Rect)).width;
		}
		if (((Rect)(ref Rect)).x < 0f)
		{
			((Rect)(ref Rect)).x = 0f;
		}
		if ((float)Screen.height < ((Rect)(ref Rect)).yMax)
		{
			((Rect)(ref Rect)).y = (float)Screen.height - ((Rect)(ref Rect)).height;
		}
		if (((Rect)(ref Rect)).y < 0f)
		{
			((Rect)(ref Rect)).y = 0f;
		}
		if (lastCheckWindowLeft != float.MinValue && (((Rect)(ref Rect)).x != lastCheckWindowLeft || ((Rect)(ref Rect)).y != lastCheckWindowTop))
		{
			AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300;
		}
		lastCheckWindowLeft = ((Rect)(ref Rect)).x;
		lastCheckWindowTop = ((Rect)(ref Rect)).y;
		if (AutoPilotMainUI.NextCheckGameTick <= GameMain.gameTick)
		{
			ConfigManager.CheckConfig(ConfigManager.Step.STATE);
		}
	}

	public static void WindowFunction(int windowId)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: 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_00a1: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.fontSize = 12;
		scrollPos = GUILayout.BeginScrollView(scrollPos, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"GameMain.mainPlayer.uPosition={GameMain.mainPlayer.uPosition}", val, Array.Empty<GUILayoutOption>());
		if (GameMain.localPlanet != null && CruiseAssistPlugin.TargetUPos != VectorLF3.zero)
		{
			Player mainPlayer = GameMain.mainPlayer;
			VectorLF3 targetUPos = CruiseAssistPlugin.TargetUPos;
			VectorLF3 val2 = targetUPos - mainPlayer.uPosition;
			double magnitude = ((VectorLF3)(ref val2)).magnitude;
			val2 = targetUPos - GameMain.localPlanet.uPosition;
			double magnitude2 = ((VectorLF3)(ref val2)).magnitude;
			VectorLF3 val3 = mainPlayer.uPosition - GameMain.localPlanet.uPosition;
			VectorLF3 val4 = CruiseAssistPlugin.TargetUPos - GameMain.localPlanet.uPosition;
			GUILayout.Label("range1=" + RangeToString(magnitude), val, Array.Empty<GUILayoutOption>());
			GUILayout.Label("range2=" + RangeToString(magnitude2), val, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"range1>range2={magnitude > magnitude2}", val, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"angle={Vector3.Angle(VectorLF3.op_Implicit(val3), VectorLF3.op_Implicit(val4))}", val, Array.Empty<GUILayoutOption>());
		}
		Mecha mecha = GameMain.mainPlayer.mecha;
		GUILayout.Label($"mecha.coreEnergy={mecha.coreEnergy}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"mecha.coreEnergyCap={mecha.coreEnergyCap}", val, Array.Empty<GUILayoutOption>());
		double num = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
		GUILayout.Label($"energyPer={num}", val, Array.Empty<GUILayoutOption>());
		double magnitude3 = ((VectorLF3)(ref GameMain.mainPlayer.controller.actionSail.visual_uvel)).magnitude;
		GUILayout.Label("spped=" + RangeToString(magnitude3), val, Array.Empty<GUILayoutOption>());
		EMovementState movementStateInFrame = GameMain.mainPlayer.controller.movementStateInFrame;
		GUILayout.Label($"movementStateInFrame={movementStateInFrame}", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"safeToGo={AutoPilotPlugin.safeToGo}", val, Array.Empty<GUILayoutOption>());
		GUIStyle val5 = new GUIStyle(GUI.skin.toggle);
		val5.fixedHeight = 20f;
		val5.fontSize = 12;
		val5.alignment = (TextAnchor)6;
		GUI.changed = false;
		AutoPilotPlugin.Conf.IgnoreGravityFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.IgnoreGravityFlag, "Ignore gravity.", val5, Array.Empty<GUILayoutOption>());
		if (GUI.changed)
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
		}
		GUILayout.EndScrollView();
		GUILayout.EndVertical();
		GUI.DragWindow();
	}

	public static string RangeToString(double range)
	{
		if (range < 10000.0)
		{
			return (int)(range + 0.5) + "m ";
		}
		if (range < 600000.0)
		{
			return (range / 40000.0).ToString("0.00") + "AU";
		}
		return (range / 2400000.0).ToString("0.00") + "Ly";
	}
}
internal class AutoPilotExtension : CruiseAssistExtensionAPI
{
	public bool CheckActive()
	{
		return AutoPilotPlugin.State == AutoPilotState.ACTIVE;
	}

	public void CheckConfig(string step)
	{
		EnumUtils.TryParse<ConfigManager.Step>(step, out var result);
		ConfigManager.CheckConfig(result);
	}

	public void SetTargetAstroId(int astroId)
	{
		LogManager.LogInfo("Trying set auto start.");
		AutoPilotPlugin.State = ((!AutoPilotPlugin.Conf.AutoStartFlag) ? AutoPilotState.INACTIVE : AutoPilotState.ACTIVE);
		AutoPilotPlugin.InputSailSpeedUp = false;
	}

	public bool OperateWalk(PlayerMove_Walk __instance)
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: 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)
		if (AutoPilotPlugin.State == AutoPilotState.INACTIVE)
		{
			return false;
		}
		Player player = ((PlayerAction)__instance).player;
		Mecha mecha = player.mecha;
		AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
		AutoPilotPlugin.Speed = ((VectorLF3)(ref player.controller.actionSail.visual_uvel)).magnitude;
		AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
		AutoPilotPlugin.LeavePlanet = true;
		AutoPilotPlugin.SpeedUp = false;
		AutoPilotPlugin.InputSailSpeedUp = false;
		if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
		{
			player.controller.universalGravity = VectorLF3.zero;
			player.controller.localGravity = VectorLF3.op_Implicit(VectorLF3.zero);
		}
		((PlayerAction)__instance).controller.input0.z = 1f;
		return true;
	}

	public bool OperateDrift(PlayerMove_Drift __instance)
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: 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)
		if (AutoPilotPlugin.State == AutoPilotState.INACTIVE)
		{
			return false;
		}
		Player player = ((PlayerAction)__instance).player;
		Mecha mecha = player.mecha;
		AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
		AutoPilotPlugin.Speed = ((VectorLF3)(ref player.controller.actionSail.visual_uvel)).magnitude;
		AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
		AutoPilotPlugin.LeavePlanet = true;
		AutoPilotPlugin.SpeedUp = false;
		AutoPilotPlugin.InputSailSpeedUp = false;
		if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
		{
			player.controller.universalGravity = VectorLF3.zero;
			player.controller.localGravity = VectorLF3.op_Implicit(VectorLF3.zero);
		}
		((PlayerAction)__instance).controller.input0.z = 1f;
		return true;
	}

	public bool OperateFly(PlayerMove_Fly __instance)
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: 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)
		if (AutoPilotPlugin.State == AutoPilotState.INACTIVE)
		{
			return false;
		}
		Player player = ((PlayerAction)__instance).player;
		Mecha mecha = player.mecha;
		AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
		AutoPilotPlugin.Speed = ((VectorLF3)(ref player.controller.actionSail.visual_uvel)).magnitude;
		AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
		AutoPilotPlugin.LeavePlanet = true;
		AutoPilotPlugin.SpeedUp = false;
		AutoPilotPlugin.InputSailSpeedUp = false;
		if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
		{
			player.controller.universalGravity = VectorLF3.zero;
			player.controller.localGravity = VectorLF3.op_Implicit(VectorLF3.zero);
		}
		PlayerController controller = ((PlayerAction)__instance).controller;
		controller.input0.y = controller.input0.y + 1f;
		PlayerController controller2 = ((PlayerAction)__instance).controller;
		controller2.input1.y = controller2.input1.y + 1f;
		return true;
	}

	public bool OperateSail(PlayerMove_Sail __instance)
	{
		//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_0020: 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_002f: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//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_003d: 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_0055: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: 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)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		if (AutoPilotPlugin.lastVisitedPlanet != null)
		{
			if (GameMain.localStar != null)
			{
				VectorLF3 uPosition = ((PlayerAction)__instance).player.uPosition;
				VectorLF3 targetUPos = CruiseAssistPlugin.TargetUPos;
				VectorLF3 val = AutoPilotPlugin.lastVisitedPlanet.uPosition - uPosition;
				VectorLF3 val2 = targetUPos - uPosition;
				double num = Math.Abs(VectorLF3.Dot(val, val2)) / ((VectorLF3)(ref val2)).magnitude;
				VectorLF3 val3 = ((VectorLF3)(ref val2)).normalized * num - val;
				if (VectorLF3.Dot(val, val2) < 0.0 || ((VectorLF3)(ref val2)).magnitude < num || ((VectorLF3)(ref val3)).magnitude > (double)AutoPilotPlugin.lastVisitedPlanet.realRadius + 400.0)
				{
					AutoPilotPlugin.safeToGo = true;
				}
				else
				{
					AutoPilotPlugin.safeToGo = false;
				}
			}
			else
			{
				AutoPilotPlugin.safeToGo = true;
			}
		}
		else
		{
			AutoPilotPlugin.safeToGo = true;
		}
		bool result;
		if (AutoPilotPlugin.State == AutoPilotState.INACTIVE)
		{
			result = false;
		}
		else
		{
			Player player = ((PlayerAction)__instance).player;
			Mecha mecha = player.mecha;
			AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
			AutoPilotPlugin.Speed = ((VectorLF3)(ref player.controller.actionSail.visual_uvel)).magnitude;
			AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
			AutoPilotPlugin.LeavePlanet = false;
			AutoPilotPlugin.SpeedUp = false;
			AutoPilotPlugin.InputSailSpeedUp = false;
			if (player.warping)
			{
				result = false;
				AutoPilotPlugin.warped = true;
			}
			else if (AutoPilotPlugin.EnergyPer < (double)AutoPilotPlugin.Conf.MinEnergyPer)
			{
				result = false;
			}
			else
			{
				if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
				{
					player.controller.universalGravity = VectorLF3.zero;
					player.controller.localGravity = VectorLF3.op_Implicit(VectorLF3.zero);
				}
				if (AutoPilotPlugin.Speed < (double)AutoPilotPlugin.Conf.MaxSpeed)
				{
					AutoPilotPlugin.InputSailSpeedUp = true;
					AutoPilotPlugin.SpeedUp = true;
				}
				if (GameMain.localPlanet == null && AutoPilotPlugin.safeToGo)
				{
					if ((AutoPilotPlugin.Conf.LocalWarpFlag || GameMain.localStar == null || (CruiseAssistPlugin.TargetStar != null && CruiseAssistPlugin.TargetStar.id != GameMain.localStar.id) || CruiseAssistPlugin.TargetEnemyId != 0) && (double)AutoPilotPlugin.Conf.WarpMinRangeAU * 40000.0 <= CruiseAssistPlugin.TargetRange && (double)AutoPilotPlugin.Conf.SpeedToWarp <= AutoPilotPlugin.Speed && 1 <= AutoPilotPlugin.WarperCount && mecha.coreEnergy > mecha.warpStartPowerPerSpeed * (double)mecha.maxWarpSpeed && !AutoPilotPlugin.warped && mecha.UseWarper())
					{
						player.warpCommand = true;
						AutoPilotPlugin.warped = true;
						VFAudio.Create("warp-begin", player.transform, Vector3.zero, true, 0, -1, -1L);
					}
					result = false;
				}
				else
				{
					if (GameMain.localPlanet != null)
					{
						AutoPilotPlugin.lastVisitedPlanet = GameMain.localPlanet;
					}
					if (AutoPilotPlugin.lastVisitedPlanet == null)
					{
						return false;
					}
					VectorLF3 val4 = player.uPosition - AutoPilotPlugin.lastVisitedPlanet.uPosition;
					if (AutoPilotPlugin.safeToGo && (GameMain.localPlanet == null || ((VectorLF3)(ref val4)).magnitude > (double)AutoPilotPlugin.lastVisitedPlanet.realRadius + 400.0))
					{
						result = false;
					}
					else
					{
						VectorLF3 val5 = val4;
						AutoPilotPlugin.LeavePlanet = true;
						float num2 = Vector3.Angle(VectorLF3.op_Implicit(val5), VectorLF3.op_Implicit(player.uVelocity));
						float num3 = 1.6f / Mathf.Max(10f, num2);
						VectorLF3 val6 = VectorLF3.op_Implicit(Vector3.Slerp(VectorLF3.op_Implicit(player.uVelocity), VectorLF3.op_Implicit(((VectorLF3)(ref val5)).normalized * Math.Max(AutoPilotPlugin.Speed, 200.0)), num3));
						val6 -= player.uVelocity;
						player.controller.actionSail.UseSailEnergy(ref val6, 1.5);
						player.uVelocity += val6;
						result = true;
					}
				}
			}
		}
		return result;
	}

	public void SetInactive()
	{
		AutoPilotPlugin.State = AutoPilotState.INACTIVE;
		AutoPilotPlugin.InputSailSpeedUp = false;
		AutoPilotPlugin.warped = false;
	}

	public void CancelOperate()
	{
		SetInactive();
	}

	public void OnGUI()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		_ = UIRoot.instance.uiGame;
		float scale = CruiseAssistMainUI.Scale / 100f;
		AutoPilotMainUI.OnGUI();
		if (AutoPilotConfigUI.Show[CruiseAssistMainUI.wIdx])
		{
			AutoPilotConfigUI.OnGUI();
		}
		if (AutoPilotDebugUI.Show)
		{
			AutoPilotDebugUI.OnGUI();
		}
		bool flag = ResetInput(AutoPilotMainUI.Rect[CruiseAssistMainUI.wIdx], scale);
		if (!flag && AutoPilotConfigUI.Show[CruiseAssistMainUI.wIdx])
		{
			flag = ResetInput(AutoPilotConfigUI.Rect[CruiseAssistMainUI.wIdx], scale);
		}
		if (!flag && AutoPilotDebugUI.Show)
		{
			flag = ResetInput(AutoPilotDebugUI.Rect, scale);
		}
	}

	private bool ResetInput(Rect rect, float scale)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		float num = ((Rect)(ref rect)).xMin * scale;
		float num2 = ((Rect)(ref rect)).xMax * scale;
		float num3 = ((Rect)(ref rect)).yMin * scale;
		float num4 = ((Rect)(ref rect)).yMax * scale;
		float x = Input.mousePosition.x;
		float num5 = (float)Screen.height - Input.mousePosition.y;
		if (num <= x && x <= num2 && num3 <= num5 && num5 <= num4 && (((IEnumerable<int>)new int[3] { 0, 1, 2 }).Any((Func<int, bool>)Input.GetMouseButton) || Input.mouseScrollDelta.y != 0f))
		{
			Input.ResetInputAxes();
			return true;
		}
		return false;
	}
}
internal class AutoPilotMainUI
{
	public static GUIStyle guistyle = null;

	public static GUIStyle guistyle2 = null;

	public static GUIStyle guistyle3 = null;

	private static int wIdx = 0;

	public const float WindowWidthFull = 398f;

	public const float WindowHeightFull = 150f;

	public const float WindowWidthMini = 288f;

	public const float WindowHeightMini = 70f;

	public static Rect[] Rect = (Rect[])(object)new Rect[2]
	{
		new Rect(0f, 0f, 398f, 150f),
		new Rect(0f, 0f, 398f, 150f)
	};

	private static float[] lastCheckWindowLeft = new float[2]
	{
		float.MinValue,
		float.MinValue
	};

	private static float[] lastCheckWindowTop = new float[2]
	{
		float.MinValue,
		float.MinValue
	};

	public static long NextCheckGameTick = long.MaxValue;

	public static void OnGUI()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0015: Invalid comparison between Unknown and I4
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Expected O, but got Unknown
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		wIdx = CruiseAssistMainUI.wIdx;
		CruiseAssistMainUIViewMode viewMode = CruiseAssistMainUI.ViewMode;
		if ((int)viewMode != 0)
		{
			if ((int)viewMode == 1)
			{
				((Rect)(ref Rect[wIdx])).width = ((Rect)(ref CruiseAssistMainUI.Rect[wIdx])).width;
				((Rect)(ref Rect[wIdx])).height = 70f;
			}
		}
		else
		{
			((Rect)(ref Rect[wIdx])).width = ((Rect)(ref CruiseAssistMainUI.Rect[wIdx])).width;
			((Rect)(ref Rect[wIdx])).height = 150f;
		}
		GUIStyle windowStyle = CruiseAssistMainUI.WindowStyle;
		windowStyle.fontSize = 11;
		Rect[wIdx] = GUILayout.Window(99031291, Rect[wIdx], new WindowFunction(WindowFunction), "AutoPilot", windowStyle, Array.Empty<GUILayoutOption>());
		float num = CruiseAssistMainUI.Scale / 100f;
		if (AutoPilotPlugin.Conf.MainWindowJoinFlag)
		{
			((Rect)(ref Rect[wIdx])).x = ((Rect)(ref CruiseAssistMainUI.Rect[CruiseAssistMainUI.wIdx])).x;
			((Rect)(ref Rect[wIdx])).y = ((Rect)(ref CruiseAssistMainUI.Rect[CruiseAssistMainUI.wIdx])).yMax;
		}
		if ((float)Screen.width / num < ((Rect)(ref Rect[wIdx])).xMax)
		{
			((Rect)(ref Rect[wIdx])).x = (float)Screen.width / num - ((Rect)(ref Rect[wIdx])).width;
		}
		if (((Rect)(ref Rect[wIdx])).x < 0f)
		{
			((Rect)(ref Rect[wIdx])).x = 0f;
		}
		if ((float)Screen.height / num < ((Rect)(ref Rect[wIdx])).yMax)
		{
			((Rect)(ref Rect[wIdx])).y = (float)Screen.height / num - ((Rect)(ref Rect[wIdx])).height;
		}
		if (((Rect)(ref Rect[wIdx])).y < 0f)
		{
			((Rect)(ref Rect[wIdx])).y = 0f;
		}
		if (lastCheckWindowLeft[wIdx] != float.MinValue && (((Rect)(ref Rect[wIdx])).x != lastCheckWindowLeft[wIdx] || ((Rect)(ref Rect[wIdx])).y != lastCheckWindowTop[wIdx]))
		{
			NextCheckGameTick = GameMain.gameTick + 300;
		}
		lastCheckWindowLeft[wIdx] = ((Rect)(ref Rect[wIdx])).x;
		lastCheckWindowTop[wIdx] = ((Rect)(ref Rect[wIdx])).y;
		if (NextCheckGameTick <= GameMain.gameTick)
		{
			ConfigManager.CheckConfig(ConfigManager.Step.STATE);
		}
	}

	public static void WindowFunction(int windowId)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Invalid comparison between Unknown and I4
		//IL_02b8: 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_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		if ((int)CruiseAssistMainUI.ViewMode == 0)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			guistyle = (GUIStyle)(((object)guistyle) ?? ((object)new GUIStyle(GUI.skin.label)));
			guistyle.fontSize = 12;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			string text = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : (((double)AutoPilotPlugin.Conf.MinEnergyPer < AutoPilotPlugin.EnergyPer) ? "OK" : "NG"));
			guistyle.normal.textColor = ((text == "OK") ? Color.cyan : ((text == "NG") ? Color.red : Color.white));
			GUILayout.Label("Energy : " + text, guistyle, Array.Empty<GUILayoutOption>());
			string text2 = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : ((CruiseAssistPlugin.TargetStar == null) ? "---" : (GameMain.mainPlayer.warping ? "---" : ((!AutoPilotPlugin.Conf.LocalWarpFlag && GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id == GameMain.localStar.id) ? "---" : ((CruiseAssistPlugin.TargetRange < (double)(AutoPilotPlugin.Conf.WarpMinRangeAU * 40000)) ? "---" : ((AutoPilotPlugin.WarperCount < 1) ? "NG" : "OK"))))));
			guistyle.normal.textColor = ((text2 == "OK") ? Color.cyan : ((text2 == "NG") ? Color.red : Color.white));
			GUILayout.Label("Warper : " + text2, guistyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			string text3 = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : (AutoPilotPlugin.LeavePlanet ? "ON" : "OFF"));
			guistyle.normal.textColor = ((text3 == "ON") ? Color.cyan : Color.white);
			GUILayout.Label("Leave Planet : " + text3, guistyle, Array.Empty<GUILayoutOption>());
			string text4 = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : (AutoPilotPlugin.SpeedUp ? "ON" : "OFF"));
			guistyle.normal.textColor = ((text4 == "ON") ? Color.cyan : Color.white);
			GUILayout.Label("Speed UP : " + text4, guistyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.FlexibleSpace();
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		guistyle2 = (GUIStyle)(((object)guistyle2) ?? ((object)new GUIStyle(GUI.skin.label)));
		guistyle2.fixedWidth = 160f;
		guistyle2.fixedHeight = 32f;
		guistyle2.fontSize = 14;
		guistyle2.alignment = (TextAnchor)3;
		if (AutoPilotPlugin.State == AutoPilotState.INACTIVE)
		{
			guistyle2.normal.textColor = Color.white;
			GUILayout.Label("Auto Pilot Inactive.", guistyle2, Array.Empty<GUILayoutOption>());
		}
		else
		{
			guistyle2.normal.textColor = Color.cyan;
			GUILayout.Label("Auto Pilot Active.", guistyle2, Array.Empty<GUILayoutOption>());
		}
		GUILayout.FlexibleSpace();
		guistyle3 = (GUIStyle)(((object)guistyle3) ?? ((object)new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)));
		guistyle3.fixedWidth = 50f;
		guistyle3.fixedHeight = 18f;
		guistyle3.fontSize = 11;
		guistyle3.alignment = (TextAnchor)4;
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Config", guistyle3, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			bool[] show = AutoPilotConfigUI.Show;
			int num = wIdx;
			show[num] = !show[num];
			if (AutoPilotConfigUI.Show[wIdx])
			{
				AutoPilotConfigUI.TempMinEnergyPer = AutoPilotPlugin.Conf.MinEnergyPer.ToString();
				AutoPilotConfigUI.TempMaxSpeed = AutoPilotPlugin.Conf.MaxSpeed.ToString();
				AutoPilotConfigUI.TempWarpMinRangeAU = AutoPilotPlugin.Conf.WarpMinRangeAU.ToString();
				AutoPilotConfigUI.TempSpeedToWarp = AutoPilotPlugin.Conf.SpeedToWarp.ToString();
			}
		}
		if (GUILayout.Button("Start", guistyle3, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			AutoPilotPlugin.State = AutoPilotState.ACTIVE;
		}
		GUILayout.EndVertical();
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Button("-", guistyle3, Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Stop", guistyle3, Array.Empty<GUILayoutOption>()))
		{
			VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
			AutoPilotPlugin.State = AutoPilotState.INACTIVE;
		}
		GUILayout.EndVertical();
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow();
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("nord.AutoPilot", "Autopilot-N", "1.3.1")]
public class AutoPilotPlugin : BaseUnityPlugin
{
	public class Conf
	{
		public static int MinEnergyPer = 20;

		public static int MaxSpeed = 2000;

		public static int WarpMinRangeAU = 2;

		public static int SpeedToWarp = 400;

		public static bool LocalWarpFlag = false;

		public static bool AutoStartFlag = true;

		public static bool IgnoreGravityFlag = true;

		public static bool MainWindowJoinFlag = true;
	}

	public const string ModGuid = "nord.AutoPilot";

	public const string ModName = "Autopilot-N";

	public const string ModVersion = "1.3.1";

	public static double EnergyPer = 0.0;

	public static double Speed = 0.0;

	public static int WarperCount = 0;

	public static bool LeavePlanet = false;

	public static bool SpeedUp = false;

	public static AutoPilotState State = AutoPilotState.INACTIVE;

	public static bool InputSailSpeedUp = false;

	private Harmony harmony;

	public static bool safeToGo = false;

	public static PlanetData lastVisitedPlanet = null;

	public static bool warped = false;

	public void Awake()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		LogManager.Logger = ((BaseUnityPlugin)this).Logger;
		new AutoPilotConfigManager(((BaseUnityPlugin)this).Config);
		ConfigManager.CheckConfig(ConfigManager.Step.AWAKE);
		harmony = new Harmony("nord.AutoPilot.Patch");
		harmony.PatchAll(typeof(Patch_VFInput));
		CruiseAssistPlugin.RegistExtension((CruiseAssistExtensionAPI)(object)new AutoPilotExtension());
	}

	public void OnDestroy()
	{
		CruiseAssistPlugin.UnregistExtension(typeof(AutoPilotExtension));
		harmony.UnpatchSelf();
	}
}
public enum AutoPilotState
{
	ACTIVE,
	INACTIVE
}
internal abstract class ConfigManager
{
	public enum Step
	{
		AWAKE,
		GAME_MAIN_BEGIN,
		STATE
	}

	private static ConfigManager instance;

	private static Dictionary<ConfigDefinition, string> orphanedEntries;

	public static ConfigFile Config { get; private set; }

	protected ConfigManager(ConfigFile config)
	{
		instance = this;
		Config = config;
		Config.SaveOnConfigSet = false;
	}

	public static void CheckConfig(Step step)
	{
		instance.CheckConfigImplements(step);
	}

	protected abstract void CheckConfigImplements(Step step);

	public static ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
	{
		return Config.Bind<T>(configDefinition, defaultValue, configDescription);
	}

	public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
	{
		return Config.Bind<T>(section, key, defaultValue, configDescription);
	}

	public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
	{
		return Config.Bind<T>(section, key, defaultValue, description);
	}

	public static ConfigEntry<T> GetEntry<T>(ConfigDefinition configDefinition)
	{
		try
		{
			return (ConfigEntry<T>)(object)Config[configDefinition];
		}
		catch (KeyNotFoundException ex)
		{
			LogManager.LogError($"{ex.GetType()}: configDefinition={configDefinition}");
			throw;
		}
	}

	public static ConfigEntry<T> GetEntry<T>(string section, string key)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		return GetEntry<T>(new ConfigDefinition(section, key));
	}

	public static T GetValue<T>(ConfigDefinition configDefinition)
	{
		return GetEntry<T>(configDefinition).Value;
	}

	public static T GetValue<T>(string section, string key)
	{
		return GetEntry<T>(section, key).Value;
	}

	public static bool ContainsKey(ConfigDefinition configDefinition)
	{
		return Config.ContainsKey(configDefinition);
	}

	public static bool ContainsKey(string section, string key)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		return Config.ContainsKey(new ConfigDefinition(section, key));
	}

	public static bool UpdateEntry<T>(string section, string key, T value) where T : IComparable
	{
		ConfigEntry<T> entry = GetEntry<T>(section, key);
		if (entry.Value.CompareTo(value) == 0)
		{
			return false;
		}
		entry.Value = value;
		return true;
	}

	public static bool RemoveEntry(ConfigDefinition key)
	{
		return Config.Remove(key);
	}

	public static Dictionary<ConfigDefinition, string> GetOrphanedEntries()
	{
		if (orphanedEntries == null)
		{
			orphanedEntries = Traverse.Create((object)Config).Property<Dictionary<ConfigDefinition, string>>("OrphanedEntries", (object[])null).Value;
		}
		return orphanedEntries;
	}

	public static void Migration<T>(string newSection, string newKey, T defaultValue, string oldSection, string oldKey)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		GetOrphanedEntries();
		ConfigDefinition key = new ConfigDefinition(oldSection, oldKey);
		if (orphanedEntries.TryGetValue(key, out var value))
		{
			((ConfigEntryBase)Bind(newSection, newKey, defaultValue)).SetSerializedValue(value);
			orphanedEntries.Remove(key);
			LogManager.LogInfo("migration " + oldSection + "." + oldKey + "(" + value + ") => " + newSection + "." + newKey);
		}
	}

	public static void Save(bool clearOrphanedEntries = false)
	{
		if (clearOrphanedEntries)
		{
			GetOrphanedEntries().Clear();
		}
		Config.Save();
		LogManager.LogInfo("save config.");
	}

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

	public static void Reload()
	{
		Config.Reload();
	}
}
internal class EnumUtils
{
	public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct
	{
		if (value == null || !Enum.IsDefined(typeof(TEnum), value))
		{
			result = (TEnum)Enum.GetValues(typeof(TEnum)).GetValue(0);
			return false;
		}
		result = (TEnum)Enum.Parse(typeof(TEnum), value);
		return true;
	}
}
internal static class LogManager
{
	public static ManualLogSource Logger { private get; set; }

	public static void LogInfo(object data)
	{
		Logger.LogInfo(data);
	}

	public static void LogInfo(MethodBase method)
	{
		Logger.LogInfo((object)(method.DeclaringType.Name + "." + method.Name));
	}

	public static void LogInfo(MethodBase method, object data)
	{
		Logger.LogInfo((object)(method.DeclaringType.Name + "." + method.Name + ": " + data));
	}

	public static void LogError(object data)
	{
		Logger.LogError(data);
	}

	public static void LogError(MethodBase method, object data)
	{
		Logger.LogError((object)(method.DeclaringType.Name + "." + method.Name + ": " + data));
	}
}
[HarmonyPatch(typeof(VFInput))]
internal class Patch_VFInput
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPostfix]
	public static void SailSpeedUp_Postfix(ref bool __result)
	{
		if (AutoPilotPlugin.State != AutoPilotState.INACTIVE && AutoPilotPlugin.InputSailSpeedUp)
		{
			__result = true;
		}
	}
}