Decompiled source of DSPAutoPilot v0.1.1

DSPAutoPilot.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AutoPilot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoPilot")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3c5eb20b-5191-447a-96ae-5d7860bc3631")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.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)
		{
			ConfigEntry<string> val = ConfigManager.Bind("Base", "ModVersion", "0.0.4", "Don't change.");
			val.Value = "0.0.4";
			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", 1200).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 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_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_001f: 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_0040: Expected O, but got Unknown
		//IL_003b: 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)
		GUIStyle val = new GUIStyle(GUI.skin.window);
		val.fontSize = 11;
		Rect = GUILayout.Window(99031293, Rect, new WindowFunction(WindowFunction), "AutoPilot - Debug", val, Array.Empty<GUILayoutOption>());
		float num = 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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: 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)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: 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_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: 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>());
		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 void CheckConfig(string step)
	{
		EnumUtils.TryParse<ConfigManager.Step>(step, out var result);
		ConfigManager.CheckConfig(result);
	}

	public void SetTargetAstroId(int astroId)
	{
		AutoPilotPlugin.State = ((!AutoPilotPlugin.Conf.AutoStartFlag) ? AutoPilotState.INACTIVE : AutoPilotState.ACTIVE);
		AutoPilotPlugin.InputSailSpeedUp = false;
	}

	public bool OperateWalk(PlayerMove_Walk __instance)
	{
		//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)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_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)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_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)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: 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_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_033d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		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 = false;
		AutoPilotPlugin.SpeedUp = false;
		AutoPilotPlugin.InputSailSpeedUp = false;
		if (player.warping)
		{
			return false;
		}
		if (AutoPilotPlugin.EnergyPer < (double)AutoPilotPlugin.Conf.MinEnergyPer)
		{
			return false;
		}
		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)
		{
			if ((AutoPilotPlugin.Conf.LocalWarpFlag || GameMain.localStar == null || CruiseAssistPlugin.TargetStar.id != GameMain.localStar.id) && (double)AutoPilotPlugin.Conf.WarpMinRangeAU * 40000.0 <= CruiseAssistPlugin.TargetRange && (double)AutoPilotPlugin.Conf.SpeedToWarp <= AutoPilotPlugin.Speed && 1 <= AutoPilotPlugin.WarperCount && mecha.coreEnergy > mecha.warpStartPowerPerSpeed * (double)mecha.maxWarpSpeed && mecha.UseWarper())
			{
				player.warpCommand = true;
				VFAudio.Create("warp-begin", player.transform, Vector3.zero, true, 0, -1, -1L);
			}
			return false;
		}
		VectorLF3 val = player.uPosition - GameMain.localPlanet.uPosition;
		if (120.0 < AutoPilotPlugin.Speed && (double)Math.Max(GameMain.localPlanet.realRadius, 800f) < ((VectorLF3)(ref val)).magnitude - (double)GameMain.localPlanet.realRadius)
		{
			return false;
		}
		VectorLF3 val2 = player.uPosition - GameMain.localPlanet.uPosition;
		VectorLF3 val3 = CruiseAssistPlugin.TargetUPos - GameMain.localPlanet.uPosition;
		VectorLF3 val4;
		if (Vector3.Angle(VectorLF3.op_Implicit(val2), VectorLF3.op_Implicit(val3)) > 90f)
		{
			val4 = val;
			AutoPilotPlugin.LeavePlanet = true;
		}
		else
		{
			VectorLF3 val5 = CruiseAssistPlugin.TargetUPos - player.uPosition;
			val4 = val5;
		}
		float num = Vector3.Angle(VectorLF3.op_Implicit(val4), VectorLF3.op_Implicit(player.uVelocity));
		float num2 = 1.6f / Mathf.Max(10f, num);
		double num3 = Math.Min(AutoPilotPlugin.Speed, 120.0);
		player.uVelocity = VectorLF3.op_Implicit(Vector3.Slerp(VectorLF3.op_Implicit(player.uVelocity), VectorLF3.op_Implicit(((VectorLF3)(ref val4)).normalized * num3), num2));
		return true;
	}

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

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

	public void OnGUI()
	{
		//IL_0059: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		UIGame uiGame = 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_0029: 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)
		//IL_0092: 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)
		{
			int[] source = new int[3] { 0, 1, 2 };
			if (((IEnumerable<int>)source).Any((Func<int, bool>)Input.GetMouseButton) || Input.mouseScrollDelta.y != 0f)
			{
				Input.ResetInputAxes();
				return true;
			}
		}
		return false;
	}
}
internal class AutoPilotMainUI
{
	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_000b: 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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Invalid comparison between Unknown and I4
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Invalid comparison between Unknown and I4
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected O, but got Unknown
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		wIdx = CruiseAssistMainUI.wIdx;
		CruiseAssistMainUIViewMode viewMode = CruiseAssistMainUI.ViewMode;
		CruiseAssistMainUIViewMode val = viewMode;
		if ((int)val > 0)
		{
			if ((int)val == 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 val2 = new GUIStyle(CruiseAssistMainUI.WindowStyle);
		val2.fontSize = 11;
		Rect[wIdx] = GUILayout.Window(99031291, Rect[wIdx], new WindowFunction(WindowFunction), "AutoPilot", val2, 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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Expected O, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_030c: 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_033a: Expected O, but got Unknown
		//IL_0392: 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_0432: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_048c: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: 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)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: 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 val = new GUIStyle(GUI.skin.label);
			val.fontSize = 12;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			string text = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : (((double)AutoPilotPlugin.Conf.MinEnergyPer < AutoPilotPlugin.EnergyPer) ? "OK" : "NG"));
			val.normal.textColor = ((text == "OK") ? Color.cyan : ((text == "NG") ? Color.red : Color.white));
			GUILayout.Label("Energy : " + text, val, 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"))))));
			val.normal.textColor = ((text2 == "OK") ? Color.cyan : ((text2 == "NG") ? Color.red : Color.white));
			GUILayout.Label("Warper : " + text2, val, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			string text3 = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : (AutoPilotPlugin.LeavePlanet ? "ON" : "OFF"));
			val.normal.textColor = ((text3 == "ON") ? Color.cyan : Color.white);
			GUILayout.Label("Leave Planet : " + text3, val, Array.Empty<GUILayoutOption>());
			string text4 = ((AutoPilotPlugin.State == AutoPilotState.INACTIVE) ? "---" : (AutoPilotPlugin.SpeedUp ? "ON" : "OFF"));
			val.normal.textColor = ((text4 == "ON") ? Color.cyan : Color.white);
			GUILayout.Label("Speed UP : " + text4, val, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.FlexibleSpace();
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUIStyle val2 = new GUIStyle(GUI.skin.label);
		val2.fixedWidth = 160f;
		val2.fixedHeight = 32f;
		val2.fontSize = 14;
		val2.alignment = (TextAnchor)3;
		if (AutoPilotPlugin.State == AutoPilotState.INACTIVE)
		{
			GUILayout.Label("Auto Pilot Inactive.", val2, Array.Empty<GUILayoutOption>());
		}
		else
		{
			val2.normal.textColor = Color.cyan;
			GUILayout.Label("Auto Pilot Active.", val2, Array.Empty<GUILayoutOption>());
		}
		GUILayout.FlexibleSpace();
		GUIStyle val3 = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle);
		val3.fixedWidth = 50f;
		val3.fixedHeight = 18f;
		val3.fontSize = 11;
		val3.alignment = (TextAnchor)4;
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Config", val3, 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", val3, 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("-", val3, Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Stop", val3, 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("Appun.DSP.plugin.AutoPilot", "DSPAutoPilot", "0.1.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 = 1200;

		public static bool LocalWarpFlag = false;

		public static bool AutoStartFlag = true;

		public static bool IgnoreGravityFlag = true;

		public static bool MainWindowJoinFlag = true;
	}

	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 void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		LogManager.Logger = ((BaseUnityPlugin)this).Logger;
		new AutoPilotConfigManager(((BaseUnityPlugin)this).Config);
		ConfigManager.CheckConfig(ConfigManager.Step.AWAKE);
		harmony = new Harmony("tanu.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_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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 AutoPilotConfigUI
{
	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_0024: 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_0049: Expected O, but got Unknown
		//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)
		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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Expected O, but got Unknown
		//IL_02cc: 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_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: 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;
		val.fixedHeight = 20f;
		val.alignment = (TextAnchor)3;
		GUIStyle val2 = new GUIStyle(CruiseAssistMainUI.BaseTextFieldStyle);
		val2.fontSize = 12;
		val2.fixedWidth = 60f;
		val.fixedHeight = 20f;
		val2.alignment = (TextAnchor)5;
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		val.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Min Energy Percent (0-100 default:20)"), val, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr = GUILayout.TextField(TempMinEnergyPer, val2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempMinEnergyPer, instr, 0, 100, ref AutoPilotPlugin.Conf.MinEnergyPer);
		val.fixedWidth = 20f;
		GUILayout.Label("%", val, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		val.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Max Speed (0-2000 default:2000)"), val, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr2 = GUILayout.TextField(TempMaxSpeed, val2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempMaxSpeed, instr2, 0, 2000, ref AutoPilotPlugin.Conf.MaxSpeed);
		val.fixedWidth = 20f;
		GUILayout.Label("m/s", val, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		val.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Warp Min Range (1-60 default:2)"), val, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr3 = GUILayout.TextArea(TempWarpMinRangeAU, val2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempWarpMinRangeAU, instr3, 1, 60, ref AutoPilotPlugin.Conf.WarpMinRangeAU);
		val.fixedWidth = 20f;
		GUILayout.Label("AU", val, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		val.fixedWidth = 240f;
		GUILayout.Label(Localization.Translate("Speed to warp (0-2000 default:1200)"), val, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string instr4 = GUILayout.TextArea(TempSpeedToWarp, val2, Array.Empty<GUILayoutOption>());
		SetValue(ref TempSpeedToWarp, instr4, 0, 2000, ref AutoPilotPlugin.Conf.SpeedToWarp);
		val.fixedWidth = 20f;
		GUILayout.Label("m/s", val, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUIStyle val3 = new GUIStyle(CruiseAssistMainUI.BaseToggleStyle);
		val3.fixedHeight = 20f;
		val3.fontSize = 12;
		val3.alignment = (TextAnchor)6;
		GUI.changed = false;
		AutoPilotPlugin.Conf.LocalWarpFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.LocalWarpFlag, Localization.Translate("Warp to planet in local system."), val3, 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."), val3, 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."), val3, 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 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;
		}
	}
}