Decompiled source of DSPEasy Starport v0.0.1

DSPEasy.Starport.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using DSPEasy.Framework.Save;
using DSPEasy.Framework.UI;
using DSPEasy.Starport.Deployment;
using DSPEasy.Starport.Persistence;
using DSPEasy.Starport.Starmap;
using DSPEasy.Starport.UI;
using DSPEasy.Starport.World;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DSPEasy.Starport
{
	public class StarportManager : MonoBehaviour
	{
		public static readonly List<StarportPlanet> Starports = new List<StarportPlanet>();

		public static readonly List<StarportDeployment> Deployments = new List<StarportDeployment>();

		public const int MaxStarportLevel = 7;

		public const int MaxSubstationLevel = 1;

		public const double StationEnergyMwPerLevel = 30.0;

		public const double GateBaseEnergyGj = 1.0;

		public const double GateEnergyPerLyGj = 0.5;

		public const double GateSameSystemBaseGj = 0.6;

		public const double GateSameSystemPerAuGj = 0.0083;

		public static bool GateConsumeWarper = true;

		public static bool SubstationConsumeWarper = true;

		public const int GateWarperCost = 1;

		public const double MaxBoostGj = 298.0;

		public const float MaxDeploySpeedAuPerSec = 60.15f;

		public const int WarperItemId = 1210;

		public const int ShipItemId = 5002;

		private static StarData deploymentTargetStar;

		private StarportPlanet gateTransitSource;

		private StarportPlanet gateTransitTarget;

		private PlanetData gateTransitPlanet;

		private long gateTransitStartTick;

		private long gateTransitEndTick;

		private long gateEjectEndTick;

		private VectorLF3 gateEjectFrom;

		private VectorLF3 gateEjectTo;

		private Vector3 gateEjectUp;

		private bool gateTransitPrevDisableController;

		private bool gateTransitSourceReleased;

		private bool gateTransitHoldingController;

		private StarportPlanet landingTarget;

		private long landingLockUntil;

		public const float DeckGrid = 1.3333333f;

		private static readonly FieldRef<GameData, PlanetData> LocalPlanetField = AccessTools.FieldRefAccess<GameData, PlanetData>("<localPlanet>k__BackingField");

		private static string notice = "";

		private static float noticeUntil;

		private static int gpuResetVersion;

		private StarportPanel panel;

		private static int sequenceCounter;

		private long nextStationCleanupTick;

		public const string NamePrefix = "【星港】";

		public const string SubstationPrefix = "【星港-子站】";

		public const string NameEnglish = "Starport";

		internal static readonly List<PlanetData> RetiredPlanets = new List<PlanetData>();

		public static StarportManager Instance { get; private set; }

		public StarportPlanet Selected { get; private set; }

		public static StarData DeploymentTargetStar
		{
			get
			{
				if (!IsStarInCurrentGalaxy(deploymentTargetStar))
				{
					deploymentTargetStar = GameMain.localStar;
				}
				return deploymentTargetStar;
			}
		}

		public bool IsGateTransiting
		{
			get
			{
				if (gateTransitTarget == null)
				{
					return gateTransitPlanet != null;
				}
				return true;
			}
		}

		public float GateTransitProgress
		{
			get
			{
				if ((gateTransitTarget == null && gateTransitPlanet == null) || gateTransitEndTick <= gateTransitStartTick)
				{
					return 0f;
				}
				return Mathf.Clamp01((float)(GameMain.gameTick - gateTransitStartTick) / (float)(gateTransitEndTick - gateTransitStartTick));
			}
		}

		public static int GpuResetVersion => gpuResetVersion;

		public static void OnGpuReset()
		{
			gpuResetVersion++;
		}

		public static void Notify(string message)
		{
			notice = message;
			noticeUntil = Time.unscaledTime + 6f;
			Plugin.Log.LogInfo((object)("[Starport] " + message));
		}

		public static void ClearLocalPlanet()
		{
			if (GameMain.data != null)
			{
				LocalPlanetField.Invoke(GameMain.data) = null;
			}
		}

		private static void ResetBuildMenuForUnload()
		{
			UIGame val = (((Object)(object)UIRoot.instance != (Object)null) ? UIRoot.instance.uiGame : null);
			UIBuildMenu val2 = (((Object)(object)val != (Object)null) ? val.buildMenu : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			try
			{
				int currentCategory = val2.currentCategory;
				bool active = ((ManualBehaviour)val2).active;
				if (currentCategory != 0)
				{
					val2.SetCurrentCategory(0);
				}
				((ManualBehaviour)val2)._Close();
				if (active || currentCategory != 0)
				{
					Plugin.Log.LogInfo((object)("[Starport] 起飞前收起建造栏 category=" + currentCategory));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Starport] 起飞前收起建造栏失败:" + ex.Message));
			}
		}

		private static void UnloadLocalPlanetForGate(string reason)
		{
			if (GameMain.data == null || GameMain.data.localPlanet == null)
			{
				return;
			}
			PlanetData localPlanet = GameMain.data.localPlanet;
			ResetBuildMenuForUnload();
			if (IsStation(localPlanet))
			{
				ReleaseStationRenderers(localPlanet);
				if (localPlanet.factoryLoaded)
				{
					localPlanet.UnloadFactory();
				}
				ClearLocalPlanet();
				if (GameMain.mainPlayer != null)
				{
					GameMain.mainPlayer.planetId = 0;
				}
			}
			else
			{
				GameMain.data.LeavePlanet();
			}
			Plugin.Log.LogInfo((object)("[Starport] 星门起飞卸载当前星球 id=" + localPlanet.id + " " + localPlanet.displayName + " reason=" + reason));
		}

		public static void SelectStation(StarportPlanet station)
		{
			if (station != null && Starports.Contains(station))
			{
				Instance.Selected = station;
			}
		}

		public static StarportPlanet GetSelectedOrFirst()
		{
			if ((Object)(object)Instance != (Object)null && Instance.Selected != null && Starports.Contains(Instance.Selected))
			{
				return Instance.Selected;
			}
			if (Starports.Count > 0)
			{
				if ((Object)(object)Instance != (Object)null)
				{
					Instance.Selected = Starports[0];
				}
				return Starports[0];
			}
			return null;
		}

		public void LoadPlasmaAmmo()
		{
			StarportPlasma.LoadFromPlayer(GetSelectedOrFirst(), out var message);
			Notify(message);
		}

		private void OnGUI()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!(Time.unscaledTime >= noticeUntil) && !string.IsNullOrEmpty(notice))
			{
				GUIStyle val = new GUIStyle(GUI.skin.label);
				val.wordWrap = true;
				val.fontSize = 12;
				GUI.Label(new Rect(20f, 20f, Mathf.Min((float)Screen.width - 40f, 1800f), 140f), notice, val);
			}
		}

		private void Awake()
		{
			Instance = this;
			panel = ((Component)this).gameObject.AddComponent<StarportPanel>();
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}

		private void OnDestroy()
		{
			RestoreGateTransitController();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void Update()
		{
			if (!((Object)(object)GameMain.instance == (Object)null) && GameMain.data != null && GameMain.isRunning)
			{
				try
				{
					UpdateGateTransit();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("[Starport] 星门航渡异常:" + ex));
					CancelGateTransit("星门航渡异常,已中断并解锁;详见 Player.log");
				}
				HandleHotkeys();
				if (GameMain.localStar != null)
				{
					UpdateOrbit();
					StabilizeLanding();
					UpdatePlanetViewPan();
					UpdateStationEnergy(Time.deltaTime);
					UpdateDeployments();
					EnsureNearbyStationFactory();
					EnsureStationInfrastructure();
					RefreshNearbyStation();
					CleanupDistantStationRenderers();
				}
			}
		}

		private void LateUpdate()
		{
			if (!((Object)(object)GameMain.instance == (Object)null) && GameMain.data != null && GameMain.isRunning)
			{
				StarportSpaceLabels.UpdateAll();
			}
		}

		private void HandleHotkeys()
		{
			if (Input.GetKeyDown((KeyCode)290) && (Object)(object)panel != (Object)null)
			{
				panel.Toggle();
			}
		}

		public static double DistanceLy(VectorLF3 a, VectorLF3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			VectorLF3 val = a - b;
			return ((VectorLF3)(ref val)).magnitude / 2400000.0;
		}

		public static VectorLF3 OrbitPoint(StarData star, float orbitAu)
		{
			//IL_000e: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			double num = (double)orbitAu * 40000.0;
			return star.uPosition + new VectorLF3(Math.Cos(0.0) * num, 0.0, Math.Sin(0.0) * num);
		}

		public static VectorLF3 StationDeckCenter(StarportPlanet station)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_004f: 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)
			if (station == null || station.Planet == null)
			{
				if (station == null)
				{
					return VectorLF3.zero;
				}
				return OrbitPoint(station.Star, station.OrbitRadiusAu);
			}
			return station.Planet.uPosition - new VectorLF3((double)station.Planet.realRadius, 0.0, 0.0);
		}

		public static Vector3 GetStationUp(PlanetData planet)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003a: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			StarportPlanet starportPlanet = Find(planet);
			if (starportPlanet != null && starportPlanet.Star != null)
			{
				VectorLF3 val = starportPlanet.Star.uPosition - planet.uPosition;
				Vector3 val2 = VectorLF3.op_Implicit(Maths.QInvRotateLF(planet.runtimeRotation, val));
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				if (((Vector3)(ref normalized)).sqrMagnitude > 0.001f)
				{
					return normalized;
				}
			}
			return Vector3.left;
		}

		public static bool IsOnDeck(StarportPlanet station, Player player)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_004c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (station == null || station.Planet == null || player == null)
			{
				return false;
			}
			PlanetData planet = station.Planet;
			VectorLF3 val = Maths.QInvRotateLF(planet.runtimeRotation, player.uPosition - planet.uPosition);
			float num = 0f - planet.realRadius;
			if (val.x >= (double)(num - 8f) && val.x <= (double)(num + 1.5f) && Math.Abs(val.y) <= (double)(station.DeckHalf + 3f))
			{
				return Math.Abs(val.z) <= (double)(station.DeckHalf + 3f);
			}
			return false;
		}

		public static bool IsInStationAirspace(StarportPlanet station, Player player)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_004c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (station == null || station.Planet == null || player == null)
			{
				return false;
			}
			PlanetData planet = station.Planet;
			VectorLF3 val = Maths.QInvRotateLF(planet.runtimeRotation, player.uPosition - planet.uPosition);
			float num = 0f - planet.realRadius;
			if (val.x >= (double)(num - 160f) && val.x <= (double)(num + 2f) && Math.Abs(val.y) <= (double)(station.DeckHalf + 4f))
			{
				return Math.Abs(val.z) <= (double)(station.DeckHalf + 4f);
			}
			return false;
		}

		public static bool IsBuildingMode()
		{
			PlayerController val = ((GameMain.mainPlayer != null) ? GameMain.mainPlayer.controller : null);
			if ((Object)(object)val == (Object)null || val.actionBuild == null)
			{
				return false;
			}
			return val.actionBuild.activeTool != null;
		}

		public static void ApplyStationSoftLimit(Player player)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			if (player == null || GameMain.data == null || (int)player.movementState < 2)
			{
				return;
			}
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				PlanetData planet = starportPlanet.Planet;
				if (planet == null || planet.factory == null)
				{
					continue;
				}
				VectorLF3 val = Maths.QInvRotateLF(planet.runtimeRotation, player.uPosition - planet.uPosition);
				float num = 0f - planet.realRadius - (float)val.x;
				if (num < -20f || num > 150f || Math.Abs(val.y) > (double)(starportPlanet.DeckHalf + 60f) || Math.Abs(val.z) > (double)(starportPlanet.DeckHalf + 60f))
				{
					continue;
				}
				VectorLF3 val2 = Maths.QInvRotateLF(planet.runtimeRotation, player.uVelocity);
				if (val2.x <= 0.1)
				{
					continue;
				}
				float num2 = (float)((VectorLF3)(ref val2)).magnitude;
				if (!(num2 <= 40f))
				{
					if (player.warpCommand || player.warpState > 0.001f)
					{
						player.warpCommand = false;
						player.warpState = 0f;
						Notify("接近星港,已退出曲速");
					}
					float num3 = Mathf.Lerp(40f, 120f, Mathf.Clamp01(num / 150f));
					if (num2 > num3)
					{
						val2 *= (double)(num3 / num2);
						player.uVelocity = Maths.QRotateLF(planet.runtimeRotation, val2);
					}
				}
			}
		}

		public static void SnapDeck(PlanetData planet, Vector3 pos, bool onTerrain, out Vector3 result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			SnapDeck(planet, pos, onTerrain, 1, out result);
		}

		public static void SnapDeck(PlanetData planet, Vector3 pos, bool onTerrain, int gridSize, out Vector3 result)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			StarportPlanet starportPlanet = Find(planet);
			float num = 1.3333333f * (float)Mathf.Max(1, gridSize);
			float num2 = starportPlanet?.DeckHalf ?? 50f;
			if (starportPlanet == null || (Object)(object)starportPlanet.Deck == (Object)null)
			{
				float num3 = Mathf.Clamp(Mathf.Round(pos.y / num) * num, 0f - num2, num2);
				float num4 = Mathf.Clamp(Mathf.Round(pos.z / num) * num, 0f - num2, num2);
				result = new Vector3(0f - planet.realRadius, num3, num4);
				return;
			}
			Transform transform = starportPlanet.Deck.transform;
			Vector3 val = transform.InverseTransformPoint(pos);
			val.y = Mathf.Clamp(Mathf.Round(val.y / num) * num, 0f - num2, num2);
			val.z = Mathf.Clamp(Mathf.Round(val.z / num) * num, 0f - num2, num2);
			if (GameMain.mainPlayer != null && (Object)(object)GameMain.mainPlayer.controller != (Object)null && GameMain.mainPlayer.controller.actionBuild != null && GameMain.mainPlayer.controller.actionBuild.activeTool is BuildTool_Path && val.x > 0.5f)
			{
				val.x = Mathf.Clamp(Mathf.Round(val.x / 1.3333333f) * 1.3333333f, 0f, 80f);
			}
			else
			{
				val.x = 0f;
			}
			result = transform.TransformPoint(val);
		}

		public static float FindFreeOrbit(StarData star, float preferred)
		{
			if (star == null)
			{
				return -1f;
			}
			float result = -1f;
			float num = float.MaxValue;
			for (int i = 2; i <= 250; i++)
			{
				float num2 = (float)i * 0.1f;
				if (IsOrbitFree(star, num2, out var _))
				{
					float num3 = Mathf.Abs(num2 - preferred);
					if (num3 < num)
					{
						num = num3;
						result = num2;
					}
				}
			}
			return result;
		}

		public static bool IsOrbitFree(StarData star, float au, out string reason)
		{
			reason = "";
			if (star == null)
			{
				reason = "没有恒星";
				return false;
			}
			if (au < 0.2f || au > 25f)
			{
				reason = "超出 0.2..25 AU";
				return false;
			}
			if (star.planets != null)
			{
				for (int i = 0; i < star.planetCount; i++)
				{
					PlanetData val = star.planets[i];
					if (val != null && Mathf.Abs(val.orbitRadius - au) < 0.1f)
					{
						reason = "与行星 " + val.displayName + "(" + val.orbitRadius.ToString("0.##") + " AU)冲突";
						return false;
					}
				}
			}
			if (star.hiveAstroOrbits != null)
			{
				for (int j = 0; j < star.hiveAstroOrbits.Length; j++)
				{
					AstroOrbitData val2 = star.hiveAstroOrbits[j];
					if (val2 != null && Mathf.Abs(val2.orbitRadius - au) < 0.1f)
					{
						reason = "与黑雾巢轨道(" + val2.orbitRadius.ToString("0.##") + " AU)冲突";
						return false;
					}
				}
			}
			for (int k = 0; k < Starports.Count; k++)
			{
				StarportPlanet starportPlanet = Starports[k];
				if (starportPlanet != null && starportPlanet.Star == star && Mathf.Abs(starportPlanet.OrbitRadiusAu - au) < 0.1f)
				{
					reason = "与星港 " + starportPlanet.Label + "(" + starportPlanet.OrbitRadiusAu.ToString("0.##") + " AU)冲突";
					return false;
				}
			}
			for (int l = 0; l < Deployments.Count; l++)
			{
				StarportDeployment starportDeployment = Deployments[l];
				if (starportDeployment != null && starportDeployment.TargetStar == star && Mathf.Abs(starportDeployment.OrbitAu - au) < 0.1f)
				{
					reason = "与在途" + (starportDeployment.IsSubstation ? "子站" : "星港") + "(" + starportDeployment.OrbitAu.ToString("0.##") + " AU)冲突";
					return false;
				}
			}
			return true;
		}

		private static bool IsStarInCurrentGalaxy(StarData star)
		{
			if (star == null || GameMain.galaxy == null || GameMain.galaxy.stars == null)
			{
				return false;
			}
			StarData[] stars = GameMain.galaxy.stars;
			for (int i = 0; i < stars.Length; i++)
			{
				if (stars[i] == star)
				{
					return true;
				}
			}
			return false;
		}

		public static void SetDeploymentTargetStar(StarData star)
		{
			if (star != null)
			{
				deploymentTargetStar = star;
			}
		}

		private static void CycleDeploymentTargetStar(int direction)
		{
			GalaxyData galaxy = GameMain.galaxy;
			if (galaxy == null || galaxy.stars == null || galaxy.stars.Length == 0)
			{
				return;
			}
			StarData[] stars = galaxy.stars;
			int num = -1;
			StarData val = DeploymentTargetStar;
			for (int i = 0; i < stars.Length; i++)
			{
				if (stars[i] == val)
				{
					num = i;
					break;
				}
			}
			int num2 = ((direction >= 0) ? 1 : (-1));
			for (int j = 1; j <= stars.Length; j++)
			{
				int num3 = (num + num2 * j) % stars.Length;
				if (num3 < 0)
				{
					num3 += stars.Length;
				}
				StarData val2 = stars[num3];
				if (val2 != null && val2.planetCount > 0)
				{
					deploymentTargetStar = val2;
					break;
				}
			}
		}

		public static void CycleDeploymentTargetStarNext()
		{
			CycleDeploymentTargetStar(1);
		}

		public static void CycleDeploymentTargetStarPrev()
		{
			CycleDeploymentTargetStar(-1);
		}

		private void UpdateDeployments()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (GameMain.data == null)
			{
				return;
			}
			_ = GameMain.data.relativeRot;
			for (int num = Deployments.Count - 1; num >= 0; num--)
			{
				StarportDeployment starportDeployment = Deployments[num];
				if (starportDeployment == null)
				{
					Deployments.RemoveAt(num);
				}
				else
				{
					UpdateDeploymentShip(starportDeployment);
					if (GameMain.gameTick >= starportDeployment.EndTick)
					{
						Deployments.RemoveAt(num);
						CompleteDeployment(starportDeployment);
					}
				}
			}
		}

		private void UpdateDeploymentShip(StarportDeployment deployment)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004f: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)deployment.Ship == (Object)null))
			{
				float num = Mathf.Clamp01(deployment.Progress);
				VectorLF3 val = deployment.SourceUPos + (deployment.TargetUPos - deployment.SourceUPos) * (double)num;
				Vector3 position = VectorLF3.op_Implicit(Maths.QInvRotateLF(GameMain.data.relativeRot, val - GameMain.data.relativePos));
				deployment.Ship.transform.position = position;
				VectorLF3 val2 = deployment.TargetUPos - deployment.SourceUPos;
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor((float)val2.x, (float)val2.y, (float)val2.z);
				if (((Vector3)(ref val3)).sqrMagnitude > 0.001f)
				{
					deployment.Ship.transform.rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, Vector3.up);
				}
			}
		}

		private GameObject CreateDeploymentShip()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("StarportDeploymentShip");
			val.layer = 9;
			PrefabDesc val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(5002)?.prefabDesc;
			Mesh val3 = null;
			Material[] array = null;
			float num = 4f;
			if (val2 != null && val2.lodMeshes != null && val2.lodMeshes.Length != 0)
			{
				val3 = val2.lodMeshes[0];
				if ((Object)(object)val3 != (Object)null)
				{
					Bounds bounds = val3.bounds;
					Vector3 size = ((Bounds)(ref bounds)).size;
					num = 4f / Mathf.Max(0.1f, ((Vector3)(ref size)).magnitude);
				}
			}
			if (val2 != null && val2.lodMaterials != null && val2.lodMaterials.Length != 0)
			{
				array = val2.lodMaterials[0];
			}
			if ((Object)(object)val3 != (Object)null)
			{
				val.AddComponent<MeshFilter>().sharedMesh = val3;
				MeshRenderer val4 = val.AddComponent<MeshRenderer>();
				if (array != null)
				{
					((Renderer)val4).sharedMaterials = array;
				}
				((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val4).receiveShadows = false;
			}
			else
			{
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)1);
				((Object)obj).name = "FallbackShip";
				obj.transform.SetParent(val.transform, false);
				obj.transform.localScale = new Vector3(1.2f, 3f, 1.2f);
				Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			}
			val.transform.localScale = Vector3.one * num;
			val.transform.SetParent(((Component)this).transform, true);
			return val;
		}

		private void CompleteDeployment(StarportDeployment deployment)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)deployment.Ship != (Object)null)
			{
				Object.Destroy((Object)(object)deployment.Ship);
				deployment.Ship = null;
			}
			if (deployment.TargetStar != null)
			{
				int sequence = ((deployment.Sequence > 0) ? deployment.Sequence : NextSequence());
				StarportPlanet starportPlanet = StarportPlanetFactory.Create(deployment.TargetStar, sequence, deployment.OrbitAu, (float)deployment.DeckSize * 0.5f);
				if (starportPlanet == null)
				{
					Notify("运输船抵达,但创建星港失败,见 Player.log");
					return;
				}
				starportPlanet.Level = deployment.Level;
				starportPlanet.IsSubstation = deployment.IsSubstation;
				starportPlanet.Parent = deployment.Parent;
				starportPlanet.EnergyStoredGj = StationEnergyCapacityForLevel(deployment.Level);
				starportPlanet.ViewPan = Vector3.zero;
				string text = (string.IsNullOrEmpty(deployment.TargetStar.displayName) ? "星港" : deployment.TargetStar.displayName) + "-" + sequence.ToString("00");
				string name = (string.IsNullOrEmpty(deployment.RequestedName) ? text : deployment.RequestedName.Trim());
				ApplyStationName(starportPlanet, name);
				SelectStation(starportPlanet);
				StarportStarmap.RefreshOpen();
				Notify("运输船已抵达," + (starportPlanet.IsSubstation ? "子站" : "星港") + "创建完成:" + starportPlanet.Label + "(" + (starportPlanet.DeckHalf * 2f).ToString("0") + " m)");
			}
		}

		public bool BeginDeployment(bool substation, float orbitAu, string requestedName)
		{
			return BeginDeployment(DeploymentTargetStar, substation, orbitAu, requestedName, null);
		}

		public bool BeginDeployment(StarData star, bool substation, float orbitAu, string requestedName)
		{
			return BeginDeployment(star, substation, orbitAu, requestedName, null);
		}

		public bool BeginDeployment(StarData star, bool substation, float orbitAu, string requestedName, IList<StarportPlanet> boostStations)
		{
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: 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_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer == null || star == null)
			{
				Notify("没有目标恒星/玩家,无法投放");
				return false;
			}
			int level = ((!substation) ? 1 : 0);
			int deckSize = DeckSizeForLevel(level);
			int num = 0;
			for (int i = 0; i < Starports.Count; i++)
			{
				if (Starports[i] != null && Starports[i].Star == star)
				{
					num++;
				}
			}
			for (int j = 0; j < Deployments.Count; j++)
			{
				if (Deployments[j] != null && Deployments[j].TargetStar == star)
				{
					num++;
				}
			}
			if (num >= 8)
			{
				Notify("本星系已有/在途 8 座星港,达到上限");
				return false;
			}
			StarportPlanet starportPlanet = GetSelectedOrFirst();
			if (starportPlanet != null && (starportPlanet.Planet == null || starportPlanet.Star == null))
			{
				starportPlanet = null;
			}
			if (substation && starportPlanet == null)
			{
				Notify("子站必须从一座已建好的星港投放,先选一座星港");
				return false;
			}
			bool flag = substation && SubstationConsumeWarper;
			if (flag && !HasWarpers(mainPlayer))
			{
				Notify("缺少 1 个翘曲器;可关闭“子站翘曲器”改为能量加价");
				return false;
			}
			if (orbitAu <= 0f)
			{
				orbitAu = FindFreeOrbit(star, substation ? 15f : 1f);
				if (orbitAu <= 0f)
				{
					Notify("本星系没有可用空轨道(0.2..25 AU,间隔 0.1 AU)");
					return false;
				}
			}
			if (orbitAu < 0.2f || orbitAu > 25f)
			{
				Notify("轨道需在 0.2..25 AU");
				return false;
			}
			orbitAu = Mathf.Round(orbitAu * 10f) / 10f;
			if (orbitAu < 0.2f)
			{
				orbitAu = 0.2f;
			}
			if (orbitAu > 25f)
			{
				orbitAu = 25f;
			}
			if (!IsOrbitFree(star, orbitAu, out var reason))
			{
				float num2 = FindFreeOrbit(star, orbitAu);
				Notify("轨道 " + orbitAu.ToString("0.##") + " AU 不可用:" + reason + ((num2 > 0f) ? (";最近的空轨道约 " + num2.ToString("0.##") + " AU") : ""));
				return false;
			}
			bool flag2 = Starports.Count == 0 && Deployments.Count == 0;
			VectorLF3 val = ((starportPlanet != null && starportPlanet.Planet != null) ? StationDeckCenter(starportPlanet) : mainPlayer.uPosition);
			VectorLF3 val2 = OrbitPoint(star, orbitAu);
			VectorLF3 val3 = val2 - val;
			double num3 = ((VectorLF3)(ref val3)).magnitude / 40000.0;
			double num4 = 0.0;
			if (substation)
			{
				if (starportPlanet == null)
				{
					Notify("发射子站需要先在列表中选中一座源星港");
					return false;
				}
				num4 = SubstationLaunchEnergyGj(starportPlanet, star, orbitAu, flag);
				if (starportPlanet.EnergyStoredGj < num4)
				{
					Notify("源星港储能不足,需要 " + num4.ToString("0.###") + " GJ");
					return false;
				}
			}
			double scale = (substation ? 0.1 : 1.0);
			if (!flag2 && !StarportCosts.Consume(scale, out var error))
			{
				Notify("建站资源不足:" + error);
				return false;
			}
			if (starportPlanet != null && num4 > 0.0)
			{
				starportPlanet.EnergyStoredGj -= num4;
			}
			if (flag)
			{
				int num5 = default(int);
				mainPlayer.mecha.warpStorage.TakeItem(1210, 1, ref num5);
			}
			double num6 = 0.0;
			if (star != GameMain.localStar && boostStations != null)
			{
				for (int k = 0; k < boostStations.Count; k++)
				{
					if (!(num6 < 298.0))
					{
						break;
					}
					StarportPlanet starportPlanet2 = boostStations[k];
					if (starportPlanet2 != null && starportPlanet2.Star == GameMain.localStar)
					{
						double num7 = Math.Min(BoostAvailableGj(starportPlanet2), 298.0 - num6);
						if (!(num7 <= 0.0))
						{
							starportPlanet2.EnergyStoredGj -= num7;
							num6 += num7;
						}
					}
				}
			}
			int sourceLevel = starportPlanet?.Level ?? 0;
			double num8 = Math.Min(60.150001525878906, (double)DeploySpeedAuPerSec(sourceLevel) + 0.2 * num6);
			long num9 = (long)Math.Ceiling(num3 / num8 * 60.0);
			if (num9 < 60)
			{
				num9 = 60L;
			}
			StarportDeployment starportDeployment = new StarportDeployment
			{
				TargetStar = star,
				Sequence = NextSequence(),
				OrbitAu = orbitAu,
				DeckSize = deckSize,
				Level = level,
				IsSubstation = substation,
				Parent = (substation ? starportPlanet : null),
				SourceLevel = sourceLevel,
				BoostGj = num6,
				RequestedName = requestedName,
				SourceUPos = val,
				TargetUPos = val2,
				DistanceAu = num3,
				SpeedAuPerSec = num8,
				StartTick = GameMain.gameTick,
				EndTick = GameMain.gameTick + num9
			};
			starportDeployment.Ship = CreateDeploymentShip();
			Deployments.Add(starportDeployment);
			string text = (substation ? "子站" : "星港");
			Notify("已发射运输船:" + text + " · " + num3.ToString("0.##") + " AU · " + num8.ToString("0.##") + " AU/s · 约 " + ((double)num9 / 60.0).ToString("0") + " 秒" + ((!substation) ? "" : (flag ? " · 耗 1 翘曲器" : " · 不耗翘曲器(能量加价)")));
			return true;
		}

		public void DeploySubstation(float orbitAu, string requestedName)
		{
			BeginDeployment(substation: true, orbitAu, requestedName);
		}

		public void CreateStation()
		{
			CreateStation(100, 0f, null);
		}

		public void CreateStation(int deckSize, float orbitAu, string requestedName)
		{
			BeginDeployment(substation: false, orbitAu, requestedName);
		}

		public static double StationEnergyCapacityForLevel(int level)
		{
			return Mathf.Clamp(level, 0, 7) switch
			{
				0 => 8.0, 
				1 => 16.0, 
				2 => 32.0, 
				3 => 64.0, 
				4 => 128.0, 
				5 => 256.0, 
				6 => 512.0, 
				_ => 1024.0, 
			};
		}

		public static int DeckSizeForLevel(int level)
		{
			if (level <= 0)
			{
				return 50;
			}
			return level switch
			{
				1 => 100, 
				2 => 200, 
				_ => 300, 
			};
		}

		public static int MaxLevelFor(StarportPlanet station)
		{
			if (station == null || !station.IsSubstation)
			{
				return 7;
			}
			return 1;
		}

		public static float DeploySpeedAuPerSec(int sourceLevel)
		{
			return 0.2f + 0.05f * (float)Mathf.Clamp(sourceLevel, 0, 7);
		}

		public static double BoostAvailableGj(StarportPlanet station)
		{
			if (station == null)
			{
				return 0.0;
			}
			double num = StationEnergyCapacityForLevel(station.Level) * 0.4;
			return Math.Max(0.0, station.EnergyStoredGj - num);
		}

		public static double GateOneWayEnergyGj(double distanceLy)
		{
			return 1.0 + 0.5 * Math.Max(0.0, distanceLy);
		}

		public static double GateSameSystemEnergyGj(double distanceAu, bool useWarper)
		{
			double num = Math.Max(0.0, distanceAu);
			double num2 = 0.6 + 0.0083 * num;
			if (!useWarper)
			{
				num2 *= 1.0 + 0.00333 * num;
			}
			return num2;
		}

		public static double GateJumpEnergyGj(double distance, bool sameSystem, bool useWarper)
		{
			if (!sameSystem)
			{
				return GateOneWayEnergyGj(distance) * (useWarper ? 1.0 : (1.0 + 0.2 * Math.Max(0.0, distance)));
			}
			return GateSameSystemEnergyGj(distance, useWarper);
		}

		public static void GateQuote(StarportPlanet target, bool useWarper, out double cost, out double distance, out bool sameSystem, out StarportPlanet current, out double available)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0042: 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_005d: 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_0076: 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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			current = FindPlayerStation();
			Player mainPlayer = GameMain.mainPlayer;
			StarData val = ((current != null) ? current.Star : GameMain.localStar);
			sameSystem = target != null && target.Star == val;
			VectorLF3 val2 = ((current != null) ? StationDeckCenter(current) : (mainPlayer?.uPosition ?? VectorLF3.zero));
			VectorLF3 val3 = ((target != null) ? StationDeckCenter(target) : val2);
			double num;
			if (!sameSystem)
			{
				num = DistanceLy(val2, val3);
			}
			else
			{
				VectorLF3 val4 = val3 - val2;
				num = ((VectorLF3)(ref val4)).magnitude / 40000.0;
			}
			distance = num;
			cost = ((target != null) ? GateJumpEnergyGj(distance, sameSystem, useWarper) : 0.0);
			available = target?.EnergyStoredGj ?? 0.0;
			if (current != null && current != target)
			{
				available += current.EnergyStoredGj;
			}
		}

		public static void GatePlanetQuote(PlanetData planet, bool useWarper, out double cost, out double distance, out bool sameSystem, out StarportPlanet current, out double available)
		{
			//IL_005f: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			current = FindPlayerStation();
			Player mainPlayer = GameMain.mainPlayer;
			StarData val = ((current != null) ? current.Star : GameMain.localStar);
			sameSystem = planet != null && (planet.star == null || planet.star == val);
			VectorLF3 val2 = ((current != null) ? StationDeckCenter(current) : (mainPlayer?.uPosition ?? VectorLF3.zero));
			VectorLF3 val3 = planet?.uPosition ?? val2;
			double num;
			if (!sameSystem)
			{
				num = DistanceLy(val2, val3);
			}
			else
			{
				VectorLF3 val4 = val3 - val2;
				num = ((VectorLF3)(ref val4)).magnitude / 40000.0;
			}
			distance = num;
			cost = ((planet != null) ? GateJumpEnergyGj(distance, sameSystem, useWarper) : 0.0);
			available = ((current != null) ? current.EnergyStoredGj : 0.0);
		}

		public static double SubstationLaunchEnergyGj(StarportPlanet source, StarData targetStar, float orbitAu)
		{
			return SubstationLaunchEnergyGj(source, targetStar, orbitAu, SubstationConsumeWarper);
		}

		public static double SubstationLaunchEnergyGj(StarportPlanet source, StarData targetStar, float orbitAu, bool useWarper)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0054: 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)
			if (targetStar == null)
			{
				return 0.0;
			}
			Player mainPlayer = GameMain.mainPlayer;
			VectorLF3 val = ((source != null && source.Planet != null) ? StationDeckCenter(source) : (mainPlayer?.uPosition ?? VectorLF3.zero));
			VectorLF3 val2 = OrbitPoint(targetStar, orbitAu);
			StarData val3 = ((source != null) ? source.Star : GameMain.localStar);
			if (targetStar != val3)
			{
				return GateJumpEnergyGj(DistanceLy(val, val2), sameSystem: false, useWarper);
			}
			VectorLF3 val4 = val2 - val;
			return GateSameSystemEnergyGj(((VectorLF3)(ref val4)).magnitude / 40000.0, useWarper);
		}

		public static bool HasWarpers(Player player)
		{
			if (player != null && player.mecha != null && player.mecha.warpStorage != null)
			{
				return player.mecha.warpStorage.GetItemCount(1210) >= 1;
			}
			return false;
		}

		private void UpdateStationEnergy(float deltaTime)
		{
			if (deltaTime <= 0f)
			{
				return;
			}
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				if (starportPlanet != null && starportPlanet.Planet != null)
				{
					double num = Mathf.Max(1, starportPlanet.Level);
					double num2 = 30.0 * num * num;
					starportPlanet.EnergyStoredGj = Math.Min(StationEnergyCapacityForLevel(starportPlanet.Level), starportPlanet.EnergyStoredGj + num2 * 0.001 * (double)deltaTime);
					StarportPlasma.Update(starportPlanet);
				}
			}
		}

		public static float GateSpeedLyPerSec(Player player)
		{
			float num = ((player != null && player.mecha != null) ? player.mecha.maxWarpSpeed : 1000000f);
			return Mathf.Clamp(0.4167f * Mathf.Pow(num / 1000000f, 2f), 0.4167f, 30f);
		}

		public void GateJumpToPlanet(PlanetData planet)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: 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_023e: 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_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			Player mainPlayer = GameMain.mainPlayer;
			if (planet == null || mainPlayer == null)
			{
				Notify("需要目标行星");
				return;
			}
			if (IsGateTransiting)
			{
				Notify("星门正在航渡中");
				return;
			}
			StarportPlanet starportPlanet = FindPlayerStation();
			if (starportPlanet == null)
			{
				Notify("需要站在星港/子站 500 m 内才能使用星门");
				return;
			}
			if (planet.star == null && starportPlanet.Star != null)
			{
				planet.star = starportPlanet.Star;
			}
			if ((int)planet.type == 5 || IsStation(planet))
			{
				Notify("该目标不能作为星门行星落点");
				return;
			}
			bool gateConsumeWarper = GateConsumeWarper;
			if (gateConsumeWarper && !HasWarpers(mainPlayer))
			{
				Notify("缺少 1 个翘曲器;可关闭“消耗翘曲器”改为能量加价");
				return;
			}
			GatePlanetQuote(planet, gateConsumeWarper, out var cost, out var distance, out var sameSystem, out var current, out var available);
			if (current == null || !sameSystem)
			{
				Notify("行星目标只对本星系开放");
				return;
			}
			if (available + 1E-06 < cost)
			{
				Notify("储能不足:当前站 " + available.ToString("0.##") + "/" + cost.ToString("0.##") + " GJ");
				return;
			}
			current.EnergyStoredGj -= cost;
			if (gateConsumeWarper)
			{
				int num = default(int);
				mainPlayer.mecha.warpStorage.TakeItem(1210, 1, ref num);
			}
			float num2 = GateSpeedLyPerSec(mainPlayer);
			double num3 = distance / 60.0;
			double num4 = Math.Max(1.5, num3 / (double)num2);
			long num5 = Math.Max(90L, (long)Math.Ceiling(num4 * 60.0));
			UnloadLocalPlanetForGate("行星跃迁起飞");
			gateTransitSource = current;
			gateTransitTarget = null;
			gateTransitPlanet = planet;
			gateTransitStartTick = GameMain.gameTick;
			gateEjectEndTick = gateTransitStartTick + 90;
			gateTransitEndTick = gateEjectEndTick + num5;
			gateEjectFrom = mainPlayer.uPosition;
			gateEjectUp = (((Object)(object)current.Deck != (Object)null) ? current.Deck.transform.right : (((Object)(object)mainPlayer.transform != (Object)null) ? mainPlayer.transform.up : Vector3.up));
			gateEjectTo = StationDeckCenter(current) + VectorLF3.op_Implicit(gateEjectUp) * 1500.0;
			gateTransitSourceReleased = false;
			if (GameMain.data != null)
			{
				gateTransitPrevDisableController = GameMain.data.disableController;
				gateTransitHoldingController = true;
				GameMain.data.disableController = true;
			}
			Notify("星门充能:行星 " + planet.displayName + "," + distance.ToString("0.##") + " AU,约 " + num4.ToString("0.#") + " 秒;耗 " + cost.ToString("0.##") + " GJ" + (gateConsumeWarper ? " + 1 翘曲器" : "(不耗翘曲器,能量加价)") + ";先垂直弹射 1500 m");
		}

		public void GateJump(StarportPlanet target)
		{
			//IL_01cb: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: 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_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//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_024b: Unknown result type (might be due to invalid IL or missing references)
			Player mainPlayer = GameMain.mainPlayer;
			if (target == null || target.Planet == null || mainPlayer == null)
			{
				Notify("需要目标星港");
				return;
			}
			if (IsGateTransiting)
			{
				Notify("星门正在航渡中");
				return;
			}
			bool gateConsumeWarper = GateConsumeWarper;
			if (gateConsumeWarper && !HasWarpers(mainPlayer))
			{
				Notify("缺少 1 个翘曲器;可关闭“消耗翘曲器”改为能量加价");
				return;
			}
			GateQuote(target, gateConsumeWarper, out var cost, out var distance, out var sameSystem, out var current, out var available);
			if (available + 1E-06 < cost)
			{
				Notify("储能不足:目标站 + 当前站 " + available.ToString("0.##") + "/" + cost.ToString("0.##") + " GJ");
				return;
			}
			double num = cost;
			double num2 = Math.Min(target.EnergyStoredGj, num);
			target.EnergyStoredGj -= num2;
			num -= num2;
			if (num > 0.0 && current != null && current != target)
			{
				double num3 = Math.Min(current.EnergyStoredGj, num);
				current.EnergyStoredGj -= num3;
				num -= num3;
			}
			if (gateConsumeWarper)
			{
				int num4 = default(int);
				mainPlayer.mecha.warpStorage.TakeItem(1210, 1, ref num4);
			}
			float num5 = GateSpeedLyPerSec(mainPlayer);
			double num6 = (sameSystem ? (distance / 60.0) : distance);
			double num7 = Math.Max(1.5, num6 / (double)num5);
			long num8 = Math.Max(90L, (long)Math.Ceiling(num7 * 60.0));
			gateTransitSource = current;
			gateTransitTarget = target;
			gateTransitStartTick = GameMain.gameTick;
			gateEjectEndTick = gateTransitStartTick + 90;
			gateTransitEndTick = gateEjectEndTick + num8;
			VectorLF3 val = ((current != null) ? StationDeckCenter(current) : mainPlayer.uPosition);
			gateEjectFrom = mainPlayer.uPosition;
			gateEjectUp = ((current != null && (Object)(object)current.Deck != (Object)null) ? current.Deck.transform.right : (((Object)(object)mainPlayer.transform != (Object)null) ? mainPlayer.transform.up : Vector3.up));
			gateEjectTo = val + VectorLF3.op_Implicit(gateEjectUp) * 1500.0;
			UnloadLocalPlanetForGate("站跃迁起飞");
			gateTransitSourceReleased = false;
			if (GameMain.data != null)
			{
				gateTransitPrevDisableController = GameMain.data.disableController;
				gateTransitHoldingController = true;
				GameMain.data.disableController = true;
			}
			Notify("星门充能:" + (sameSystem ? (distance.ToString("0.##") + " AU") : (distance.ToString("0.##") + " ly")) + ",速度 " + num5.ToString("0.###") + " ly/s,约 " + num7.ToString("0.#") + " 秒;耗 " + cost.ToString("0.##") + " GJ" + (gateConsumeWarper ? " + 1 翘曲器" : "(不耗翘曲器,能量加价)") + ";先垂直弹射 1500 m");
		}

		private unsafe void CompleteGateJumpToPlanet(PlanetData planet)
		{
			//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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_0079: 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_0089: 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_00cd: 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_00d3: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_01f2: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: 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_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			Player mainPlayer = GameMain.mainPlayer;
			if (planet == null || mainPlayer == null)
			{
				RestoreGateTransitController();
				Notify("行星落点失败:目标不可用");
				return;
			}
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				if (starportPlanet != null && starportPlanet.Planet != null)
				{
					ReleaseStationRenderers(starportPlanet.Planet);
					ClearStationUi(starportPlanet.Planet);
				}
			}
			Vector3 val = planet.birthPoint;
			if (((Vector3)(ref val)).sqrMagnitude < 1f)
			{
				val = Vector3.up * planet.realRadius;
			}
			val = ((Vector3)(ref val)).normalized * (planet.realRadius + 10f);
			Quaternion val2 = Maths.SphericalRotation(val, 0f);
			if (!planet.loaded && !planet.loading)
			{
				planet.Load();
			}
			mainPlayer.uPosition = planet.uPosition + VectorLF3.op_Implicit(planet.runtimeRotation * val);
			mainPlayer.uVelocity = planet.GetUniversalVelocityAtLocalPoint(GameMain.gameTime, val);
			mainPlayer.warpState = 0f;
			mainPlayer.warpCommand = false;
			mainPlayer.movementState = (EMovementState)0;
			mainPlayer.planetId = planet.id;
			if ((Object)(object)mainPlayer.controller != (Object)null)
			{
				mainPlayer.controller.movementStateInFrame = (EMovementState)0;
			}
			try
			{
				GameMain.data.ArrivePlanet(planet);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Starport] 行星落地 ArrivePlanet 失败 planet=" + planet.id + " " + planet.displayName + ":" + ex));
				RestoreGateTransitController();
				Notify("行星落地失败:" + planet.displayName + ",请查看日志");
				return;
			}
			mainPlayer.planetId = planet.id;
			mainPlayer.uVelocity = planet.GetUniversalVelocityAtLocalPoint(GameMain.gameTime, val);
			mainPlayer.transform.localPosition = val;
			mainPlayer.transform.localRotation = val2;
			mainPlayer.uRotation = planet.runtimeRotation * val2;
			if ((Object)(object)mainPlayer.controller != (Object)null)
			{
				mainPlayer.controller.velocity = Vector3.zero;
				mainPlayer.controller.velocityOnLanding = Vector3.zero;
				mainPlayer.controller.movementStateInFrame = (EMovementState)0;
			}
			landingTarget = null;
			RestoreGateTransitController();
			ManualLogSource log = Plugin.Log;
			string[] obj = new string[14]
			{
				"[Starport] 行星落地 planet=",
				planet.id.ToString(),
				" ",
				planet.displayName,
				" local=",
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			Vector3 val3 = val;
			obj[5] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
			obj[6] = " radius=";
			obj[7] = planet.realRadius.ToString();
			obj[8] = " birth=";
			val3 = planet.birthPoint;
			obj[9] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
			obj[10] = " loaded=";
			obj[11] = planet.loaded.ToString();
			obj[12] = " factoryLoaded=";
			obj[13] = planet.factoryLoaded.ToString();
			log.LogInfo((object)string.Concat(obj));
			Notify("星门跃迁到行星 " + planet.displayName);
		}

		private void UpdateGateTransit()
		{
			//IL_00a6: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: 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_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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_027f: 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_02b9: Unknown result type (might be due to invalid IL or missing references)
			if (gateTransitTarget == null && gateTransitPlanet == null)
			{
				return;
			}
			StarportPlanet starportPlanet = gateTransitTarget;
			PlanetData val = gateTransitPlanet;
			if ((gateTransitSource != null && !Starports.Contains(gateTransitSource)) || (val == null && (!Starports.Contains(starportPlanet) || starportPlanet.Planet == null)))
			{
				CancelGateTransit("目标已不存在,跃迁中断");
				return;
			}
			Player mainPlayer = GameMain.mainPlayer;
			long gameTick = GameMain.gameTick;
			if (gameTick < gateEjectEndTick && mainPlayer != null)
			{
				float num = Mathf.Clamp01((float)(gameTick - gateTransitStartTick) / Mathf.Max(1f, (float)(gateEjectEndTick - gateTransitStartTick)));
				mainPlayer.uPosition = gateEjectFrom + (gateEjectTo - gateEjectFrom) * (double)num;
				mainPlayer.uVelocity = VectorLF3.op_Implicit(gateEjectUp) * 1000.0;
				mainPlayer.planetId = 0;
				mainPlayer.movementState = (EMovementState)3;
				mainPlayer.warpState = 1f;
				mainPlayer.warpCommand = false;
				if ((Object)(object)mainPlayer.controller != (Object)null)
				{
					mainPlayer.controller.movementStateInFrame = (EMovementState)3;
				}
				return;
			}
			if (gameTick < gateTransitEndTick && mainPlayer != null)
			{
				if (!gateTransitSourceReleased && gateTransitSource != null && gateTransitSource.Planet != null)
				{
					gateTransitSourceReleased = true;
					ReleaseStationRenderers(gateTransitSource.Planet);
				}
				float num2 = Mathf.Clamp01((float)(gameTick - gateEjectEndTick) / Mathf.Max(1f, (float)(gateTransitEndTick - gateEjectEndTick)));
				VectorLF3 val3;
				if (val != null)
				{
					Vector3 val2 = val.birthPoint;
					if (((Vector3)(ref val2)).sqrMagnitude < 1f)
					{
						val2 = Vector3.up * val.realRadius;
					}
					val2 = ((Vector3)(ref val2)).normalized * (val.realRadius + 10f);
					val3 = val.uPosition + VectorLF3.op_Implicit(val.runtimeRotation * val2);
				}
				else
				{
					val3 = StationDeckCenter(starportPlanet);
				}
				VectorLF3 val4 = val3 - gateEjectTo;
				mainPlayer.uPosition = gateEjectTo + val4 * (double)num2;
				double num3 = Math.Max(1.0, (double)(gateTransitEndTick - gameTick) / 60.0);
				mainPlayer.uVelocity = ((((VectorLF3)(ref val4)).magnitude > 0.001) ? (val4 * (1.0 / num3)) : VectorLF3.zero);
				mainPlayer.planetId = 0;
				mainPlayer.movementState = (EMovementState)3;
				mainPlayer.warpState = 1f;
				mainPlayer.warpCommand = false;
				if ((Object)(object)mainPlayer.controller != (Object)null)
				{
					mainPlayer.controller.movementStateInFrame = (EMovementState)3;
				}
				return;
			}
			if (mainPlayer != null)
			{
				mainPlayer.uVelocity = VectorLF3.zero;
				mainPlayer.warpState = 0f;
				mainPlayer.warpCommand = false;
				if (val == null)
				{
					mainPlayer.uPosition = StationDeckCenter(starportPlanet);
				}
				mainPlayer.movementState = (EMovementState)3;
				if ((Object)(object)mainPlayer.controller != (Object)null)
				{
					mainPlayer.controller.movementStateInFrame = (EMovementState)3;
				}
			}
			gateTransitTarget = null;
			gateTransitPlanet = null;
			gateTransitSource = null;
			if (val != null)
			{
				CompleteGateJumpToPlanet(val);
				return;
			}
			TeleportToStation(starportPlanet);
			Notify("星门航渡结束,正在落站:" + starportPlanet.Label);
		}

		private void CancelGateTransit(string message)
		{
			//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)
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer != null)
			{
				mainPlayer.uVelocity = VectorLF3.zero;
				mainPlayer.warpState = 0f;
				mainPlayer.warpCommand = false;
			}
			gateTransitTarget = null;
			gateTransitPlanet = null;
			gateTransitSource = null;
			RestoreGateTransitController();
			Notify(message);
		}

		private void RestoreGateTransitController()
		{
			if (gateTransitHoldingController)
			{
				gateTransitHoldingController = false;
				if (GameMain.data != null)
				{
					GameMain.data.disableController = gateTransitPrevDisableController;
				}
			}
		}

		internal static void ClearSessionState(bool destroyRuntime)
		{
			if (destroyRuntime)
			{
				if (Starports.Count > 0 || RetiredPlanets.Count > 0)
				{
					Plugin.Log.LogInfo((object)("[Starport] 清理运行时站点:站 " + Starports.Count + " 座、退役占位 " + RetiredPlanets.Count + " 座,伪星球标记为未加载"));
				}
				for (int i = 0; i < Starports.Count; i++)
				{
					StarportPlanet starportPlanet = Starports[i];
					if (starportPlanet == null)
					{
						continue;
					}
					if ((Object)(object)starportPlanet.Deck != (Object)null)
					{
						starportPlanet.Deck.SetActive(false);
						Object.Destroy((Object)(object)starportPlanet.Deck);
						starportPlanet.Deck = null;
					}
					if (starportPlanet.Planet != null)
					{
						starportPlanet.Planet.factoryLoaded = false;
						if ((Object)(object)starportPlanet.Planet.gameObject != (Object)null)
						{
							starportPlanet.Planet.gameObject.SetActive(false);
							Object.Destroy((Object)(object)starportPlanet.Planet.gameObject);
						}
					}
				}
				for (int j = 0; j < RetiredPlanets.Count; j++)
				{
					PlanetData val = RetiredPlanets[j];
					if (val != null)
					{
						val.factoryLoaded = false;
						if ((Object)(object)val.gameObject != (Object)null)
						{
							val.gameObject.SetActive(false);
							Object.Destroy((Object)(object)val.gameObject);
						}
					}
				}
				for (int k = 0; k < Deployments.Count; k++)
				{
					StarportDeployment starportDeployment = Deployments[k];
					if (starportDeployment != null && (Object)(object)starportDeployment.Ship != (Object)null)
					{
						Object.Destroy((Object)(object)starportDeployment.Ship);
						starportDeployment.Ship = null;
					}
				}
			}
			Starports.Clear();
			Deployments.Clear();
			RetiredPlanets.Clear();
			if ((Object)(object)Instance != (Object)null)
			{
				Instance.Selected = null;
			}
			sequenceCounter = 0;
		}

		internal static void ApplyRestoredSequence(int maxSequence)
		{
			if (maxSequence > sequenceCounter)
			{
				sequenceCounter = maxSequence;
			}
		}

		internal static void SelectRestored()
		{
			if (!((Object)(object)Instance == (Object)null))
			{
				Instance.Selected = ((Starports.Count > 0) ? Starports[0] : null);
			}
		}

		private void UpdatePlanetViewPan()
		{
			//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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00ac: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00e6: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			UIGame val = (((Object)(object)UIRoot.instance != (Object)null) ? UIRoot.instance.uiGame : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val.planetDetail == (Object)null || !((ManualBehaviour)val.planetDetail).active)
			{
				return;
			}
			StarportPlanet starportPlanet = FindViewStation();
			if (starportPlanet == null || (Object)(object)starportPlanet.Deck == (Object)null || !Input.GetMouseButton(2) || VFInput.inFullscreenGUI)
			{
				return;
			}
			Vector2 mouseMoveAxis = VFInput.mouseMoveAxis;
			if (!(((Vector2)(ref mouseMoveAxis)).sqrMagnitude <= 0f))
			{
				Transform transform = starportPlanet.Deck.transform;
				float num = 1f;
				starportPlanet.ViewPan += transform.up * (mouseMoveAxis.x * num) - transform.forward * (mouseMoveAxis.y * num);
				float num2 = starportPlanet.DeckHalf * 1.6f;
				Vector3 viewPan = starportPlanet.ViewPan;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(viewPan.y, viewPan.z);
				if (((Vector2)(ref val2)).magnitude > num2)
				{
					val2 = ((Vector2)(ref val2)).normalized * num2;
					starportPlanet.ViewPan = new Vector3(0f, val2.x, val2.y);
				}
			}
		}

		private void EnsureStationInfrastructure()
		{
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				if (starportPlanet != null && starportPlanet.Planet != null && starportPlanet.Planet.factoryLoaded && GameMain.localPlanet == starportPlanet.Planet)
				{
					try
					{
						StarportInfrastructure.Ensure(starportPlanet);
					}
					catch (Exception ex)
					{
						starportPlanet.InfrastructureReady = true;
						Plugin.Log.LogError((object)("[Starport] 注入隐藏基础设施异常:" + ex));
					}
				}
			}
		}

		private void EnsureNearbyStationFactory()
		{
			//IL_003c: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (IsGateTransiting)
			{
				return;
			}
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer == null)
			{
				return;
			}
			for (int i = 0; i < Starports.Count; i++)
			{
				PlanetData planet = Starports[i].Planet;
				if (planet != null && !planet.factoryLoaded && !planet.factoryLoading)
				{
					VectorLF3 val = mainPlayer.uPosition - planet.uPosition;
					double num = ((VectorLF3)(ref val)).magnitude - (double)planet.realRadius;
					if (num > -100.0 && num < 1500.0)
					{
						Notify("进入星港范围,加载站工厂…");
						planet.LoadFactory();
					}
				}
			}
		}

		private void RefreshNearbyStation()
		{
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer != null)
			{
				StarportPlanet starportPlanet = FindNearbyStation(mainPlayer, 1500f);
				if (starportPlanet != null && starportPlanet.Planet != null && starportPlanet.Planet.factoryLoaded && starportPlanet.RenderVersion != gpuResetVersion)
				{
					RefreshStationRenderers(starportPlanet.Planet);
				}
			}
		}

		private void CleanupDistantStationRenderers()
		{
			//IL_005c: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer == null || GameMain.gameTick < nextStationCleanupTick)
			{
				return;
			}
			nextStationCleanupTick = GameMain.gameTick + 120;
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				if (starportPlanet != null && starportPlanet.Planet != null && starportPlanet.Planet.factoryLoaded && starportPlanet.Planet.factory != null)
				{
					VectorLF3 val = mainPlayer.uPosition - StationDeckCenter(starportPlanet);
					if (((VectorLF3)(ref val)).magnitude > 2000.0)
					{
						ReleaseStationRenderers(starportPlanet.Planet);
					}
				}
			}
		}

		private void UpdateOrbit()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_0159: 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_0160: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				PlanetData planet = starportPlanet.Planet;
				if (planet == null || (Object)(object)planet.gameObject == (Object)null)
				{
					continue;
				}
				double num = (double)starportPlanet.OrbitRadiusAu * 40000.0;
				float orbitPhase = starportPlanet.OrbitPhase;
				VectorLF3 val = starportPlanet.Star.uPosition + new VectorLF3(Math.Cos(orbitPhase) * num, 0.0, Math.Sin(orbitPhase) * num);
				VectorLF3 val2 = (planet.runtimePositionNext = (planet.uPositionNext = (planet.runtimePosition = (planet.uPosition = val + new VectorLF3((double)planet.realRadius, 0.0, 0.0)))));
				planet.runtimeRotation = Quaternion.identity;
				planet.runtimeRotationNext = Quaternion.identity;
				StarportPlanetFactory.UpdateAstroData(planet);
				Vector3 position = VectorLF3.op_Implicit(Maths.QInvRotateLF(GameMain.data.relativeRot, val2 - GameMain.data.relativePos));
				planet.gameObject.transform.position = position;
				planet.gameObject.transform.rotation = Quaternion.identity;
				if ((Object)(object)starportPlanet.Deck != (Object)null)
				{
					VectorLF3 val3 = val - GameMain.data.relativePos;
					Vector3 position2 = VectorLF3.op_Implicit(Maths.QInvRotateLF(GameMain.data.relativeRot, val3));
					starportPlanet.Deck.transform.position = position2;
					VectorLF3 val4 = starportPlanet.Star.uPosition - val;
					float num2 = Mathf.Atan2((float)val4.z, (float)val4.x) * 57.29578f;
					starportPlanet.Deck.transform.rotation = Quaternion.Euler(0f, num2, 0f);
					starportPlanet.Deck.SetActive(true);
					if ((Object)(object)starportPlanet.DeckGrid == (Object)null)
					{
						Transform val5 = starportPlanet.Deck.transform.Find("StarportDeckGrid");
						starportPlanet.DeckGrid = (((Object)(object)val5 != (Object)null) ? ((Component)val5).gameObject : null);
					}
					if ((Object)(object)starportPlanet.DeckGrid != (Object)null)
					{
						starportPlanet.DeckGrid.SetActive(IsBuildingMode());
					}
				}
			}
		}

		public static StarportPlanet FindPlayerStation(float maxDistance = 500f)
		{
			//IL_002f: 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_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)
			Player mainPlayer = GameMain.mainPlayer;
			if (mainPlayer == null)
			{
				return null;
			}
			StarportPlanet result = null;
			double num = maxDistance;
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				if (starportPlanet != null && starportPlanet.Planet != null)
				{
					VectorLF3 val = mainPlayer.uPosition - StationDeckCenter(starportPlanet);
					double magnitude = ((VectorLF3)(ref val)).magnitude;
					if (magnitude < num)
					{
						num = magnitude;
						result = starportPlanet;
					}
				}
			}
			return result;
		}

		public static string StationTypeName(StarportPlanet station)
		{
			if (station == null || !station.IsSubstation)
			{
				return "星港";
			}
			return "星港 - 子站";
		}

		public static string StationId(StarportPlanet station)
		{
			if (station == null || station.Sequence <= 0)
			{
				return "??";
			}
			return station.Sequence.ToString("00");
		}

		public static string StationDisplayName(StarportPlanet station)
		{
			if (station == null)
			{
				return "?";
			}
			if (!string.IsNullOrEmpty(station.Label))
			{
				return station.Label;
			}
			return "?";
		}

		public static string StationShortName(StarportPlanet station)
		{
			if (station == null)
			{
				return "?";
			}
			string text = station.Label ?? "";
			int num = text.IndexOf('】');
			text = ((num < 0) ? text.Replace("【星港-子站】", "").Replace("【星港】", "") : text.Substring(num + 1));
			text = text.Trim();
			if (text.Length <= 0)
			{
				return "站" + StationId(station);
			}
			return text;
		}

		public static int NextSequence()
		{
			int num = sequenceCounter;
			for (int i = 0; i < Starports.Count; i++)
			{
				if (Starports[i] != null)
				{
					num = Math.Max(num, Starports[i].Sequence);
				}
			}
			for (int j = 0; j < Deployments.Count; j++)
			{
				if (Deployments[j] != null)
				{
					num = Math.Max(num, Deployments[j].Sequence);
				}
			}
			sequenceCounter = num + 1;
			return sequenceCounter;
		}

		public static int NextSequence(StarData star)
		{
			return NextSequence();
		}

		public static void Register(StarportPlanet station)
		{
			if (!Starports.Contains(station))
			{
				Starports.Add(station);
			}
		}

		public static void Unregister(StarportPlanet station)
		{
			Starports.Remove(station);
		}

		public static StarportPlanet Find(PlanetData planet)
		{
			for (int i = 0; i < Starports.Count; i++)
			{
				if (Starports[i].Planet == planet)
				{
					return Starports[i];
				}
			}
			return null;
		}

		public static StarportPlanet FindByAstroId(int astroId)
		{
			for (int i = 0; i < Starports.Count; i++)
			{
				if (Starports[i].Planet != null && Starports[i].Planet.id == astroId)
				{
					return Starports[i];
				}
			}
			return null;
		}

		public static bool IsStation(PlanetData planet)
		{
			if (planet != null)
			{
				return Find(planet) != null;
			}
			return false;
		}

		public static StarportPlanet FindViewStation()
		{
			StarportPlanet starportPlanet = Find(GameMain.localPlanet);
			if (starportPlanet != null)
			{
				return starportPlanet;
			}
			UIGame val = (((Object)(object)UIRoot.instance != (Object)null) ? UIRoot.instance.uiGame : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val.planetDetail != (Object)null)
			{
				starportPlanet = Find(val.planetDetail.planet);
				if (starportPlanet != null)
				{
					return starportPlanet;
				}
			}
			if ((Object)(object)val != (Object)null && (Object)(object)val.starmap != (Object)null)
			{
				starportPlanet = Find(val.starmap.viewPlanet);
				if (starportPlanet == null && (Object)(object)val.starmap.focusPlanet != (Object)null)
				{
					starportPlanet = Find(val.starmap.focusPlanet.planet);
				}
			}
			return starportPlanet;
		}

		public static StarportPlanet FindNearbyStation(Player player, float maxDistance)
		{
			//IL_0043: 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_0050: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			if (player == null)
			{
				return null;
			}
			StarportPlanet result = null;
			double num = maxDistance;
			for (int i = 0; i < Starports.Count; i++)
			{
				StarportPlanet starportPlanet = Starports[i];
				PlanetData planet = starportPlanet.Planet;
				if (planet != null && planet.factoryLoaded && planet.factory != null)
				{
					VectorLF3 val = Maths.QInvRotateLF(planet.runtimeRotation, player.uPosition - planet.uPosition);
					float num2 = Mathf.Abs((float)val.x + planet.realRadius);
					if (!(Mathf.Abs((float)val.y) > starportPlanet.DeckHalf + 100f) && !(Mathf.Abs((float)val.z) > starportPlanet.DeckHalf + 100f) && (double)num2 < num)
					{
						num = num2;
						result = starportPlanet;
					}
				}
			}
			return result;
		}

		public static void ApplyStationName(StarportPlanet station, string name)
		{
			if (station == null || station.Planet == null)
			{
				return;
			}
			string text = (name ?? "").Trim();
			int num = text.IndexOf('】');
			if (num >= 0)
			{
				text = text.Substring(num + 1).Trim();
			}
			else
			{
				if (text.StartsWith("【星港-子站】"))
				{
					text = text.Substring("【星港-子站】".Length).Trim();
				}
				if (text.StartsWith("【星港】"))
				{
					text = text.Substring("【星港】".Length).Trim();
				}
			}
			if (text.Length == 0)
			{
				text = "未命名";
			}
			string text2 = ((station.Star != null) ? station.Star.displayName : "未知星系");
			string text3 = (station.Label = "【" + StationTypeName(station) + " - " + text2 + " / " + StationId(station) + "】" + text);
			station.Planet.overrideName = text3;
			station.Planet.name = text3;
			if (GameMain.galaxy != null)
			{
				GameMain.galaxy.NotifyAstroNameChange(station.Planet.id);
			}
			StarportStarmap.RefreshOpen();
		}

		public void RenameStation(string name)
		{
			StarportPlanet selectedOrFirst = GetSelectedOrFirst();
			if (selectedOrFirst == null)
			{
				Notify("还没有站");
				return;
			}
			if (string.IsNullOrEmpty(name) || name.Trim().Length == 0)
			{
				Notify("名字不能为空");
				return;
			}
			ApplyStationName(selectedOrFirst, name.Trim());
			Notify("已改名:" + selectedOrFirst.Label);
		}

		private static void ClearStationUi(PlanetData planet)
		{
			UIGame val = (((Object)(object)UIRoot.instance != (Object)null) ? UIRoot.instance.uiGame : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)val.veinDetail != (Object)null)
				{
					val.veinDetail.SetInspectPlanet((PlanetData)null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Starport] 清理矿脉详情失败:" + ex.Message));
			}
			try
			{
				if ((Object)(object)val.markerDetail != (Object)null)
				{
					val.markerDetail.SetInspectPlanet((PlanetData)null);
				}
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("[Starport] 清理标记详情失败:" + ex2.Message));
			}
			try
			{
				val.SetPlanetDetail((PlanetData)null);
				if ((Object)(object)val.planetDetail != (Object)null && val.planetDetail.planet == planet)
				{
					val.planetDetail.planet = null;
				}
				if ((Object)(object)val.shieldDetail != (Object)null && val.shieldDetail.planet == planet)
				{
					val.shieldDetail.planet = null;
				}
				val.SetZScreenDetail((PlanetData)null);
			}
			catch (Exception ex3)
			{
				Plugin.Log.LogWarning((object)("[Starport] 清理行星详情失败:" + ex3.Message));
			}
		}

		public static void RebuildStationRenderers(PlanetData planet)
		{
			if (planet != null && planet.factory != null && GameMain.gpuiManager != null)
			{
				StarportPlanet starportPlanet = Find(planet);
				if (starportPlanet != null)
				{
					ClearStationModels(planet.factory, removeCombatStats: false);
					starportPlanet.RenderVersion = -1;
					RefreshStationRenderers(planet);
				}
			}
		}

		public static void ReleaseStationRenderers(PlanetData planet)
		{
			if (planet == null || planet.factory == null || GameMain.gpuiManager == null)
			{
				return;
			}
			ClearStationModels(planet.factory, removeCombatStats: true);
			try
			{
				CargoTraffic cargoTraffic = planet.factory.cargoTraffic;
				if (cargoTraffic != null)
				{
					cargoTraffic.DestroyRenderingBatches();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Starport] 清站传送带渲染失败:" + ex.Message));
			}
			StarportPlanet starportPlanet = Find(planet);
			if (starportPlanet != null)
			{
				starportPlanet.RenderVersion = -1;
			}
		}

		private static void ClearStationModels(PlanetFactory factory, bool removeCombatStats)
		{
			if (factory == null || factory.entityPool == null || GameMain.gpuiManager == null)
			{
				return;
			}
			PlanetData planet = factory.planet;
			for (int i = 1; i < factory.entityCursor; i++)
			{
				ref EntityData reference = ref factory.entityPool[i];
				if (reference.modelId != 0)
				{
					try
					{
						GameMain.gpuiManager.RemoveModel((int)reference.modelIndex, reference.modelId, true);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("[Starport] 移除站模型失败 entity=" + i + ":" + ex.Message));
					}
					reference.modelId = 0;
				}
				try
				{
					if (reference.colliderId != 0 && planet != null && planet.physics != null)
					{
						planet.physics.RemoveLinkedColliderData(reference.colliderId);
					}
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogWarning((object)("[Starport] 移除站碰撞体失败 entity=" + i + ":" + ex2.Message));
				}
				try
				{
					if (reference.audioId != 0 && planet != null && planet.audio != null)
					{
						planet.audio.RemoveAudioData(reference.audioId);
					}
					if (reference.mmblockId != 0 && factory.blockContainer != null)
					{
						factory.blockContainer.RemoveMiniBlock(reference.mmblockId);
					}
				}
				catch (Exception ex3)
				{
					Plugin.Log.LogWarning((object)("[Starport] 移除站显示附属失败 entity=" + i + ":" + ex3.Message));
				}
				try
				{
					if (reference.warningId != 0 && GameMain.data != null && GameMain.data.warningSystem != null)
					{
						GameMain.data.warningSystem.RemoveWarningData(reference.warningId);
						if (reference.combatStatId != 0 && factory.skillSystem != null && reference.combatStatId < factory.skillSystem.combatStats.capacity)
						{
							factory.skillSystem.combatStats.buffer[reference.combatStatId].warningId = 0;
						}
					}
				}
				catch (Exception ex4)
				{
					Plugin.Log.LogWarning((object)("[Starport] 移除站显示警告失败 entity=" + i + ":" + ex4.Message));
				}
				reference.colliderId = 0;
				reference.audioId = 0;
				reference.mmblockId = 0;
				reference.warningId = 0;
				if (!removeCombatStats || reference.combatStatId == 0)
				{
					continue;
				}
				SkillSystem skillSystem = factory.skillSystem;
				int combatStatId = reference.combatStatId;
				if (skillSystem != null && combatStatId > 0 && combatStatId < skillSystem.combatStats.capacity)
				{
					int num = 0;
					int num2 = 0;
					try
					{
						num = skillSystem.combatStats.buffer[combatStatId].warningId;
						num2 = skillSystem.combatStats.buffer[combatStatId].originAstroId;
						if (num != 0 && GameMain.data != null && GameMain.data.warningSystem != null)
						{
							GameMain.data.warningSystem.RemoveWarningData(num);
						}
					}
					catch (Exception ex5)
					{
						Plugin.Log.LogWarning((object)("[Starport] 移除站战斗警告失败 entity=" + i + ":" + ex5.Message));
					}
					try
					{
						skillSystem.OnRemovingSkillTarget(combatStatId, num2, (ETargetType)64);
					}
					catch (Exception ex6)
					{
						Plugin.Log.LogWarning((object)("[Starport] 注销站战斗目标失败 entity=" + i + ":" + ex6.Message));
					}
					try
					{
						skillSystem.combatStats.Remove(combatStatId);
					}
					catch (Exception ex7)
					{
						Plugin.Log.LogWarning((object)("[Starport] 移除站战斗状态失败 entity=" + i + ":" + ex7.Message));
					}
				}
				reference.combatStatId = 0;
			}
		}

		public static void RefreshStationRenderers(PlanetData planet)
		{
			if (planet == null || planet.factory == null)
			{
				return;
			}
			StarportPlanet starportPlanet = Find(planet);
			if (starportPlanet == null || starportPlanet.RenderVersion == gpuResetVersion)
			{
				return;
			}
			PlanetFactory factory = planet.factory;
			ClearStationModels(factory, removeCombatStats: false);
			int num = 0;
			for (int i = 1; i < factory.entityCursor; i++)
			{
				ref EntityData reference = ref factory.entityPool[i];
				if (reference.id != 0 && reference.modelIndex != 0)
				{
					try
					{
						factory.CreateEntityDisplayComponents(i);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("[Starport] 重建站显示失败 entity=" + i + ":" + ex.Message));
					}
					if (reference.modelId != 0)
					{
						num++;
					}
				}
			}
			try
			{
				CargoTraffic cargoTraffic = factory.cargoTraffic;
				if (cargoTraffic != null)
				{
					cargoTraffic.CreateRenderingBatches();
				}
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("[Starport] 重建站传送带渲染失败:" + ex2.Message));
			}
			try
			{
				PlanetPhysics physics = planet.physics;
				if (physics != null)
				{
					physics.RefreshColliders();
				}
			}
			catch (Exception ex3)
			{
				Plugin.Log.LogWarning((object)("[Starport] 刷新站碰撞体失败:" + ex3.Message));
			}
			starportPlanet.RenderVersion = gpuResetVersion;
			Plugin.Log.LogInfo((object)("[Starport] 重建站内模型实例 " + num + " 个 version=" + gpuResetVersion));
		}

		public void TeleportToStation()
		{
			TeleportToStation(GetSelectedOrFirst());
		}

		public void TeleportToStation(StarportPlanet station)
		{
			if (IsGateTransiting)
			{
				CancelGateTransit("手动传送中断了星门跃迁");
			}
			if (station == null)
			{
				Notify("还没有站,先建站");
				return;
			}
			PlanetData planet = station.Planet;
			if (GameMain.mainPlayer == null || planet == null)
			{
				RestoreGateTransitController();
			}
			else if (!planet.factoryLoaded)
			{
				if (!planet.factoryLoading)
				{
					Notify("正在加载站工厂,加载完成后自动传送…");
					planet.LoadFactory();
				}
				((MonoBehaviour)this).StartCoroutine(TeleportWhenFactoryReady(station));
			}
			else
			{
				DoTeleport(station);
			}
		}

		private IEnumerator TeleportWhenFactoryReady(StarportPlanet station)
		{
			PlanetData planet = station.Planet;
			float timeout = Time.realtimeSinceStartup + 15f;
			while (planet != null && !planet.factoryLoaded && Time.realtimeSinceStartup < timeout)
			{
				yield return null;
			}
			if (planet == null || !planet.factoryLoaded)
			{
				RestoreGateTransitController();
				Notify("站工厂加载超