Decompiled source of Void Crew Fleet v0.4.7

VoidCrewFleet.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CG;
using CG.Client;
using CG.Client.Audio;
using CG.Client.Player.HUD;
using CG.Client.Player.Input;
using CG.Client.Player.Interactions;
using CG.Client.Player.Interactions.Build;
using CG.Client.Quests.Behaviours;
using CG.Client.Quests.SectorTwists;
using CG.Client.Ship;
using CG.Client.Ship.Hull;
using CG.Client.Ship.Interactions;
using CG.Client.Ship.Modules.Mediators;
using CG.Client.UI;
using CG.Client.UserData;
using CG.Client.Utils;
using CG.Game;
using CG.Game.Missions;
using CG.Game.Player;
using CG.Game.Scenarios;
using CG.Game.Scenarios.Actions;
using CG.Game.SpaceObjects;
using CG.Game.SpaceObjects.Controllers;
using CG.GameLoopStateMachine;
using CG.GameLoopStateMachine.GameStates;
using CG.Graphics;
using CG.Input;
using CG.Network;
using CG.Objects;
using CG.Ship;
using CG.Ship.Hull;
using CG.Ship.Modules;
using CG.Ship.Modules.Weapons;
using CG.Ship.Object;
using CG.Ship.Repair;
using CG.Ship.Scanning;
using CG.Ship.Shield;
using CG.Ship.Status;
using CG.Ship.TargetLocking;
using CG.Ship.Tracking;
using CG.Space;
using CG.Space.Projectiles;
using CG.Utils;
using Cinemachine;
using Client.Player.Interactions;
using Client.Utils;
using Code.Gameplay;
using ExitGames.Client.Photon;
using Extensions;
using FMOD.Studio;
using Gameplay.Atmosphere;
using Gameplay.Carryables;
using Gameplay.Chat;
using Gameplay.CompositeWeapons;
using Gameplay.Damage;
using Gameplay.Defects;
using Gameplay.Enhancements;
using Gameplay.Factory;
using Gameplay.Helm;
using Gameplay.Hub;
using Gameplay.MissionDifficulty;
using Gameplay.NPC.AI;
using Gameplay.Power;
using Gameplay.Quests;
using Gameplay.Ship;
using Gameplay.Ship.VoidJump;
using Gameplay.SpacePlatforms;
using Gameplay.Utilities;
using HarmonyLib;
using Knife.HDRPOutline.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character.Identifiers;
using Photon.Pun;
using Photon.Realtime;
using PlatformAbstractionLayer;
using RSG;
using ResourceAssets;
using RuntimeAssets;
using Steamworks;
using ToolClasses;
using UI;
using UI.AstralMap;
using UI.Core;
using UI.Core.Audio;
using UI.LoadoutTerminal;
using UI.MainHUD;
using UI.ObjectMarker;
using UI.PilotHUD;
using UI.Settings;
using UI.ShipLoadoutTerminal;
using Unity.Services.Vivox;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Localization;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
using VFX;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Void Crew Fleet")]
[assembly: AssemblyDescription("BepInEx plugin for Void Crew: up to six player ships, up to 24 players, a fleet mission and a PvP mode")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CaptainChunck")]
[assembly: AssemblyProduct("VoidCrewFleet")]
[assembly: AssemblyCopyright("Copyright © CaptainChunck 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b7d3f2a9-4c1e-4f6b-8a25-3e9d0c7f1a64")]
[assembly: AssemblyFileVersion("0.4.7")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.4.7.0")]
namespace VoidCrewFleet;

internal static class ActionHint
{
	private struct Hint
	{
		public int Priority;

		public string Key;

		public bool Hold;

		public string Action;

		public float Progress;
	}

	public const int PunchPriority = 0;

	public const int HackPriority = 10;

	private static readonly PropertyInfo PromptKey = GameMember.Property(typeof(KeyBindVE), "Key");

	private static readonly Dictionary<string, Hint> Hints = new Dictionary<string, Hint>();

	private static readonly Dictionary<string, InputAction> KeyActions = new Dictionary<string, InputAction>();

	private static UIDocument _hud;

	private static VisualElement _hudRoot;

	private static KeyBindVE _prompt;

	private static Label _action;

	private static string _shownKey;

	private static bool _shownHold;

	private static float _shownProgress = -1f;

	private static float _nextPrepare;

	public static void Prepare()
	{
		if ((_prompt != null && ((VisualElement)_prompt).panel != null) || Time.unscaledTime < _nextPrepare)
		{
			return;
		}
		_nextPrepare = Time.unscaledTime + 1f;
		GameStateMachine instance = Singleton<GameStateMachine>.Instance;
		if ((Object)(object)instance == (Object)null || !(((AbstractStateMachine<GameStateMachine>)(object)instance).CurrentState is GSIngame))
		{
			return;
		}
		try
		{
			if (Ensure() && Hints.Count > 0)
			{
				Refresh();
			}
		}
		catch (Exception e)
		{
			Log.Failure("Putting the action prompt into the HUD", e);
		}
	}

	public static void Set(string source, int priority, string key, bool hold, string action, float progress = 0f)
	{
		Hint value;
		if (string.IsNullOrEmpty(action))
		{
			Clear(source);
		}
		else if (!Hints.TryGetValue(source, out value) || value.Priority != priority || !(value.Key == key) || value.Hold != hold || !(value.Action == action) || value.Progress != progress)
		{
			Hints[source] = new Hint
			{
				Priority = priority,
				Key = key,
				Hold = hold,
				Action = action,
				Progress = progress
			};
			Refresh();
		}
	}

	public static void Clear(string source)
	{
		if (Hints.Remove(source))
		{
			Refresh();
		}
	}

	private static void Refresh()
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Hint hint = default(Hint);
			bool flag = false;
			foreach (Hint value in Hints.Values)
			{
				if (!flag || value.Priority > hint.Priority)
				{
					hint = value;
					flag = true;
				}
			}
			if (!flag)
			{
				if (_prompt != null)
				{
					((VisualElement)_prompt).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
				}
			}
			else if (Ensure())
			{
				string text = hint.Key ?? "";
				if (text != _shownKey)
				{
					SetKey(text);
				}
				if (hint.Hold != _shownHold)
				{
					_shownHold = hint.Hold;
					((StateVE)_prompt).SetClassState("keybind-key-interaction", hint.Hold ? "hold" : "press");
				}
				if (_action != null && ((TextElement)_action).text != hint.Action)
				{
					((TextElement)_action).text = hint.Action;
				}
				if (hint.Progress != _shownProgress)
				{
					_shownProgress = hint.Progress;
					_prompt.SetProgress(hint.Progress);
				}
				((VisualElement)_prompt).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)0);
			}
		}
		catch (Exception e)
		{
			Log.Failure("Showing the action prompt", e);
		}
	}

	private static UIDocument MainHud()
	{
		MainHUDUI instance = Singleton<MainHUDUI>.Instance;
		if (!((Object)(object)instance != (Object)null))
		{
			return null;
		}
		return ((Component)instance).GetComponent<UIDocument>();
	}

	private static bool Ensure()
	{
		UIDocument val = MainHud();
		VisualElement val2 = (((Object)(object)val != (Object)null) ? val.rootVisualElement : null);
		if (val2 == null)
		{
			return false;
		}
		if (_prompt != null && (Object)(object)val == (Object)(object)_hud && val2 == _hudRoot && ((VisualElement)_prompt).panel != null)
		{
			return true;
		}
		if (_prompt != null)
		{
			((VisualElement)_prompt).RemoveFromHierarchy();
		}
		_prompt = null;
		_action = null;
		_hud = val;
		_hudRoot = val2;
		VisualElement val3 = UQueryExtensions.Q(val2, "InteractionInfoContainer", (string)null);
		if (val3 == null)
		{
			Log.WarnOnce("action prompt row", "The game's HUD has no row of key prompts (InteractionInfoContainer), so the punch and hacking prompts don't show.");
			return false;
		}
		MakePrompt(val3, "");
		return _prompt != null;
	}

	private static void MakePrompt(VisualElement row, string key)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		KeyBindVE val = new KeyBindVE("FleetActionHint", key, false)
		{
			pickingMode = (PickingMode)1
		};
		((VisualElement)val).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
		row.Add((VisualElement)(object)val);
		_prompt = val;
		_action = UQueryExtensions.Q<Label>((VisualElement)(object)val, "Action", (string)null);
		if (_action != null)
		{
			((TextElement)_action).enableRichText = false;
		}
		_shownKey = key;
		_shownHold = false;
		_shownProgress = -1f;
		((StateVE)_prompt).SetClassState("keybind-key-interaction", "press");
	}

	private static void SetKey(string key)
	{
		InputAction val = ((key.Length > 0) ? KeyAction(key, null) : null);
		if (!GiveKey(_prompt, key, val))
		{
			VisualElement parent = ((VisualElement)_prompt).parent;
			((VisualElement)_prompt).RemoveFromHierarchy();
			MakePrompt(parent, key);
			_prompt.Init((InteractionDescription)null, val);
		}
		_shownKey = key;
		_shownProgress = -1f;
	}

	internal static bool GiveKey(KeyBindVE prompt, string key, InputAction input)
	{
		if (PromptKey == null)
		{
			return false;
		}
		PromptKey.SetValue(prompt, key, null);
		prompt.Init((InteractionDescription)null, input);
		return true;
	}

	internal static InputAction KeyAction(string path, string padPath)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_0054: 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)
		string key = ((padPath == null) ? path : (path + "|" + padPath));
		if (KeyActions.TryGetValue(key, out var value))
		{
			return value;
		}
		value = new InputAction("Fleet prompt " + KeyActions.Count, (InputActionType)1, (string)null, "", (string)null, (string)null);
		InputActionSetupExtensions.AddBinding(value, path, (string)null, (string)null, (string)null);
		if (padPath != null)
		{
			InputActionSetupExtensions.AddBinding(value, padPath, (string)null, (string)null, (string)null);
		}
		KeyActions[key] = value;
		return value;
	}
}
internal static class Aim
{
	private const float FreshSeconds = 0.3f;

	private static Vector3 _eye;

	private static Vector3 _forward;

	private static float _time = -1f;

	[GamePatch("PvP boarding rules", "CG.Client.Player.Interactions.RaycastHandler", "FindInteractable", PatchKind.Postfix)]
	private static void FindInteractablePostfix(Transform ___cameraTransform)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)___cameraTransform == (Object)null)
		{
			return;
		}
		try
		{
			_eye = ___cameraTransform.position;
			_forward = ___cameraTransform.forward;
			_time = Time.unscaledTime;
		}
		catch (Exception e)
		{
			Log.Failure("Reading where the local player looks", e);
		}
	}

	public static bool Get(out Vector3 eye, out Vector3 forward)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//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_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//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)
		if (_time >= 0f && Time.unscaledTime - _time < 0.3f)
		{
			eye = _eye;
			forward = _forward;
			return true;
		}
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			eye = Vector3.zero;
			forward = Vector3.forward;
			return false;
		}
		eye = ((Component)main).transform.position;
		forward = ((Component)main).transform.forward;
		return true;
	}
}
internal static class AstralMapLink
{
	public const string Feature = "Ships jump together";

	private static readonly FieldInfo DisplayField = GameMember.Field(typeof(AstralMapController), "_sectorDisplay");

	private static readonly FieldInfo DisplayedField = GameMember.Field(typeof(ObjectiveDisplay), "_displayedSector");

	private static readonly FieldInfo DisplaySystemField = GameMember.Field(typeof(ObjectiveDisplay), "_voidJumpSystem");

	private static readonly MethodInfo DestinationObjective = GameMember.Method(typeof(AstralMapController), "GetDestinationPreviewObjective");

	private static readonly MethodInfo ActionClicked = GameMember.Method(typeof(ObjectiveDisplay), "ActionClicked");

	[GamePatch("Ships jump together", "UI.AstralMap.AstralMapController", "Start", PatchKind.Prefix, Optional = true)]
	private static void StartPrefix(AstralMapController __instance, out bool __state)
	{
		__state = false;
		PlayerControlledShip ship = null;
		try
		{
			if (FleetShips.Active)
			{
				ship = FleetShips.OwnerOf((Component)(object)__instance);
			}
		}
		catch (Exception e)
		{
			Log.Failure("Finding the ship of an astral map", e);
		}
		ShipRedirect.BeginOverride(ship);
		__state = true;
	}

	[GamePatch("Ships jump together", "UI.AstralMap.AstralMapController", "Start", PatchKind.Finalizer, Optional = true)]
	private static void StartFinalizer(bool __state)
	{
		if (__state)
		{
			ShipRedirect.EndOverride();
		}
	}

	[GamePatch("Ships jump together", "UI.AstralMap.AstralMapController", "SectorSet", PatchKind.Postfix, Optional = true)]
	private static void DestinationPostfix(AstralMapController __instance, GameSessionSector obj, ObjectiveDisplay ____sectorDisplay, bool ____toggled, bool ____mapReady)
	{
		if (____sectorDisplay == null || !VoidJumpLink.Linked || GameSessionManager.ActiveSector != (GameSessionSector)null)
		{
			return;
		}
		try
		{
			____sectorDisplay.VectorOrDestinationSelected = obj != (GameSessionSector)null;
			if (obj == (GameSessionSector)null)
			{
				return;
			}
			____sectorDisplay.SetGlowAnimation(false);
			GameSessionSector val = ((GameSessionManager.ActiveSession != null) ? GameSessionManager.ActiveSession.InterdictionSector : null);
			if (____toggled && ____mapReady && !(DestinationObjective == null) && (!(val != (GameSessionSector)null) || obj.Id != val.Id))
			{
				object? obj2 = DestinationObjective.Invoke(__instance, null);
				UIObjective val2 = (UIObjective)((obj2 is UIObjective) ? obj2 : null);
				if (val2 != null && GameMember.Read<UIObjective>(DisplayedField, ____sectorDisplay, null) != val2)
				{
					__instance.Focus(val2, true);
				}
			}
		}
		catch (Exception e)
		{
			Log.Failure("Showing the fleet's destination on a ship's astral map", e);
		}
	}

	public static AstralMapController MapOf(PlayerControlledShip ship)
	{
		if ((Object)(object)ship == (Object)null)
		{
			return null;
		}
		AstralMapController[] array = Object.FindObjectsOfType<AstralMapController>();
		foreach (AstralMapController val in array)
		{
			if ((Object)(object)val != (Object)null && (Object)(object)FleetShips.OwnerOf((Component)(object)val) == (Object)(object)ship)
			{
				return val;
			}
		}
		return null;
	}

	private static ObjectiveDisplay DisplayOf(AstralMapController map)
	{
		if (!((Object)(object)map != (Object)null))
		{
			return null;
		}
		return GameMember.Read<ObjectiveDisplay>(DisplayField, map, null);
	}

	public static string DescribeForTest()
	{
		List<string> list = new List<string>();
		foreach (PlayerControlledShip item in FleetShips.All)
		{
			ObjectiveDisplay val = DisplayOf(MapOf(item));
			if (val == null)
			{
				list.Add(FleetShips.Describe(item) + ": no astral map");
				continue;
			}
			VoidJumpSystem val2 = GameMember.Read<VoidJumpSystem>(DisplaySystemField, val, null);
			UIObjective val3 = GameMember.Read<UIObjective>(DisplayedField, val, null);
			list.Add(FleetShips.Describe(item) + "'s map: works with " + (((Object)(object)val2 != (Object)null) ? FleetShips.Describe(val2.PlayerShip) : "no ship") + (((Object)(object)val2 != (Object)null && (Object)(object)val2.PlayerShip == (Object)(object)item) ? " (its own)" : " (NOT its own)") + ", picked " + val.VectorOrDestinationSelected + ", showing " + ((val3 != null && val3.Sector != (GameSessionSector)null) ? (val3.Sector.Name + " (" + val3.Sector.Id + ")") : "nothing"));
		}
		GameSessionSector val4 = (((Object)(object)GameSessionSectorManager.Instance != (Object)null) ? GameSessionSectorManager.Instance.DestinationSector : null);
		return string.Join("; ", list.ToArray()) + "; destination " + ((val4 != (GameSessionSector)null) ? (val4.Name + " (" + val4.Id + ")") : "none");
	}

	public static GameSessionSector PickableForTest(PlayerControlledShip ship)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		AstralMapController val = MapOf(ship);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		foreach (UIObjective uIObjective in val.UIObjectives)
		{
			if (uIObjective != null && !(uIObjective.Sector == (GameSessionSector)null) && !uIObjective.isExiting && !uIObjective.isStarting && !uIObjective.IsInterdiction && (int)uIObjective.SectorState.Value == 0)
			{
				return uIObjective.Sector;
			}
		}
		return null;
	}

	public static bool PressForTest(PlayerControlledShip ship, GameSessionSector pick)
	{
		AstralMapController val = MapOf(ship);
		ObjectiveDisplay val2 = DisplayOf(val);
		if (val2 == null || ActionClicked == null)
		{
			return false;
		}
		try
		{
			if (pick != (GameSessionSector)null)
			{
				UIObjective val3 = null;
				foreach (UIObjective uIObjective in val.UIObjectives)
				{
					if (uIObjective != null && uIObjective.Sector == pick && !uIObjective.isExiting)
					{
						val3 = uIObjective;
					}
				}
				if (val3 == null)
				{
					return false;
				}
				val.Focus(val3, true);
			}
			ActionClicked.Invoke(val2, null);
			return true;
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] Pressing a button on " + FleetShips.Describe(ship) + "'s astral map", e);
			return false;
		}
	}
}
internal enum AutoTestMode
{
	Off,
	TwoShips,
	FleetPilgrimage,
	PvP
}
internal static class AutoTest
{
	private enum Step
	{
		WaitMenu,
		Hosting,
		WaitHub,
		Starting,
		WaitMission,
		Report,
		Tour,
		Fists,
		Respawning,
		Cruisers,
		Deconstructing,
		Destroying,
		Returning,
		Jumping,
		Done
	}

	private static Step _step = Step.WaitMenu;

	private static float _stepStarted;

	private static float _lastReport;

	private static int _reports;

	private static int _shots;

	private static int _destroyed;

	private static bool _sequenceDone;

	private static Step _done = Step.WaitMenu;

	private static float _teamScreenSeen = -1f;

	private static bool _teamJoined;

	private const string CruiserProfile = "617c51d5b70105d46956fb25c40603f4";

	private const string CruiserTag = "1424f8c92ce67d142b620e2203ae8a11";

	private static bool _leverJump;

	private static readonly FieldInfo ChatPanelField = typeof(TextChat).GetField("_chatUI", BindingFlags.Instance | BindingFlags.NonPublic);

	private static bool _hubPreviewStarted;

	private static float Since => Time.unscaledTime - _stepStarted;

	private static int TestShips => Mathf.Clamp(Settings.AutoTestShips.Value, 1, 3);

	private static void Go(Step step)
	{
		_step = step;
		_stepStarted = Time.unscaledTime;
		Log.Info("[autotest] " + step);
	}

	public static void Tick()
	{
		if (Settings.AutoTest == null || Settings.AutoTest.Value == AutoTestMode.Off || _step == Step.Done)
		{
			return;
		}
		try
		{
			Run();
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] step " + _step, e);
		}
	}

	private static string StateName()
	{
		GameStateMachine instance = Singleton<GameStateMachine>.Instance;
		if (!((Object)(object)instance != (Object)null) || ((AbstractStateMachine<GameStateMachine>)(object)instance).CurrentState == null)
		{
			return "";
		}
		return ((object)((AbstractStateMachine<GameStateMachine>)(object)instance).CurrentState).GetType().Name;
	}

	private static void Run()
	{
		//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_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Invalid comparison between Unknown and I4
		//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04af: Invalid comparison between Unknown and I4
		switch (_step)
		{
		case Step.WaitMenu:
			if (Time.unscaledTime - _lastReport >= 15f)
			{
				_lastReport = Time.unscaledTime;
				Log.Info("[autotest] Waiting for the main menu: state " + StateName() + ", Photon " + ((object)PhotonNetwork.NetworkClientState/*cast due to .constrained prefix*/).ToString() + ", in a room " + PhotonNetwork.InRoom + ".");
			}
			if (!(StateName() != "GSMainMenu") && PhotonNetwork.IsConnectedAndReady && !PhotonNetwork.InRoom && !(Since < 3f))
			{
				Host();
				Go(Step.Hosting);
			}
			break;
		case Step.Hosting:
			if (PhotonNetwork.InRoom && GameSessionManager.InHub && (Object)(object)HubQuestManager.Instance != (Object)null)
			{
				Go(Step.WaitHub);
			}
			else if (Since > 90f)
			{
				Fail("the hub never loaded");
			}
			break;
		case Step.WaitHub:
			if (!(Since < 8f))
			{
				if (!_hubPreviewStarted)
				{
					_hubPreviewStarted = true;
					_sequenceDone = false;
					((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(HubCrewListSequence());
				}
				else if (_sequenceDone || !(Since < 40f))
				{
					StartMission();
					Go(Step.Starting);
				}
			}
			break;
		case Step.Starting:
			if (!GameSessionManager.InHub && StateName() == "GSIngame" && (Object)(object)LocalPlayer.Instance != (Object)null)
			{
				Go(Step.WaitMission);
			}
			else if (PvpTeams.Choosing && PvpTeamScreen.Visible)
			{
				PickTeams();
			}
			else if (Since > 180f)
			{
				Fail("the mission never started");
			}
			break;
		case Step.WaitMission:
			if (!(Since < 10f))
			{
				Go(Step.Report);
			}
			break;
		case Step.Report:
			if (Time.unscaledTime - _lastReport < 5f)
			{
				break;
			}
			_lastReport = Time.unscaledTime;
			Report("mission");
			if (_reports == 0)
			{
				CrewListPreview(show: true);
			}
			else if (_reports == 2)
			{
				CrewListPreview(show: false);
			}
			Screenshot((_reports == 1) ? "crew-list" : "mission");
			if (FleetSession.IsPvP && _reports == 0)
			{
				StartHackTest();
			}
			if (++_reports >= (FleetSession.IsPvP ? 10 : 3))
			{
				if (Settings.AutoTestTour.Value && FleetSession.IsPvP && Step.Tour > _done)
				{
					_done = Step.Tour;
					Go(Step.Tour);
					_sequenceDone = false;
					((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(TourSequence());
				}
				else if (Settings.AutoTestFists.Value && FleetSession.IsPvP && Step.Fists > _done)
				{
					_done = Step.Fists;
					Go(Step.Fists);
					_sequenceDone = false;
					((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(FistSequence());
				}
				else if (Settings.AutoTestRespawn.Value)
				{
					Go(Step.Respawning);
					_sequenceDone = false;
					((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(RespawnSequence());
				}
				else
				{
					AfterRespawn();
				}
			}
			break;
		case Step.Tour:
			if (_sequenceDone || !(Since < 300f))
			{
				if (!_sequenceDone)
				{
					Log.Warn("[autotest] The camera tour didn't finish in 300 s.");
				}
				Go(Step.Report);
			}
			break;
		case Step.Fists:
			if (_sequenceDone || !(Since < 60f))
			{
				if (!_sequenceDone)
				{
					Log.Warn("[autotest] The fist test didn't finish in 60 s.");
				}
				Go(Step.Report);
			}
			break;
		case Step.Respawning:
			if (_sequenceDone || !(Since < 90f))
			{
				if (!_sequenceDone)
				{
					Log.Warn("[autotest] The respawn test didn't finish in 90 s.");
				}
				AfterRespawn();
			}
			break;
		case Step.Cruisers:
			if (_sequenceDone || !(Since < 240f))
			{
				if (!_sequenceDone)
				{
					Log.Warn("[autotest] The cruiser test didn't finish in 240 s.");
				}
				AfterCruisers();
			}
			break;
		case Step.Deconstructing:
			if (_sequenceDone || !(Since < 240f))
			{
				if (!_sequenceDone)
				{
					Log.Warn("[autotest] The deconstruct test didn't finish in 240 s.");
				}
				Go(Step.Destroying);
			}
			break;
		case Step.Destroying:
			if (!(Since < 20f))
			{
				if (_destroyed > 0)
				{
					Report("after destroying ship " + DestroyList()[_destroyed - 1]);
					Screenshot("destroyed");
				}
				if (_destroyed < DestroyList().Length && ((Object)(object)ClientGame.Current == (Object)null || (int)ClientGame.Current.GameState != 3))
				{
					DestroyShip(DestroyList()[_destroyed++]);
					Go(Step.Destroying);
				}
				else if (Settings.AutoTestReturn.Value && (Object)(object)ClientGame.Current != (Object)null && (int)ClientGame.Current.GameState != 3)
				{
					Go(Step.Returning);
					_sequenceDone = false;
					((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(ReturnSequence());
				}
				else if (Settings.AutoTestJump.Value && FleetSession.Mode == FleetMode.Coop && FleetShips.Active)
				{
					StartJump();
				}
				else
				{
					Finish();
				}
			}
			break;
		case Step.Returning:
			if (_sequenceDone || !(Since < 180f))
			{
				if (!_sequenceDone)
				{
					Fail("never got back to the hub after RETURN TO HUB");
				}
				else
				{
					Finish();
				}
			}
			break;
		case Step.Jumping:
			{
				if (Time.unscaledTime - _lastReport < (_leverJump ? 10f : 3f))
				{
					break;
				}
				_lastReport = Time.unscaledTime;
				Report("jump");
				if (_shots < 12)
				{
					Screenshot("jump");
				}
				bool num;
				if (!_leverJump)
				{
					num = Since > 75f;
				}
				else
				{
					if (_sequenceDone)
					{
						goto IL_0597;
					}
					num = Since > 240f;
				}
				if (!num)
				{
					break;
				}
				goto IL_0597;
			}
			IL_0597:
			if (_leverJump && !_sequenceDone)
			{
				Log.Warn("[autotest] The lever jump didn't finish in 240 s.");
			}
			Finish();
			break;
		}
	}

	private static void Host()
	{
		Log.Info("[autotest] Hosting a private test room.");
		PunSingleton<PhotonService>.I.CreateRoom(false, false).Then((Action)delegate
		{
			PAL.Matchmaking.CreateLobby(false);
		}).Then((Action)delegate
		{
			PunSingleton<PhotonService>.I.SetCurrentRoomPlayerLimit(1);
		})
			.Then((Action)delegate
			{
				PunSingleton<PhotonService>.I.SetCurrentRoomName("Fleet autotest");
			})
			.Then((Action)delegate
			{
				GameSessionManager.Instance.SetNextGameSession(GameSessionLoadPromise.LoadLobbyData());
				((AbstractStateMachine<GameStateMachine>)(object)Singleton<GameStateMachine>.Instance).ChangeState<GSLoadingGame>();
			})
			.Catch((Action<Exception>)delegate(Exception e)
			{
				Fail("hosting failed: " + e.Message);
			});
	}

	private static void StartMission()
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		AutoTestMode value = Settings.AutoTest.Value;
		Log.Info("[autotest] Starting a mission: " + value.ToString() + ", " + TestShips + ((value == AutoTestMode.PvP) ? " ships per team." : " ships."));
		switch (value)
		{
		case AutoTestMode.FleetPilgrimage:
			HubFleet.RequestVariant(HubVariant.FleetPilgrimage);
			break;
		case AutoTestMode.PvP:
			HubFleet.RequestVariant(HubVariant.FleetBattle);
			break;
		default:
			HubQuestManager.Instance.SelectQuest(((ResourceAssetRef)DataTable<QuestTable>.Instance.EndlessQuest).AssetGuid);
			break;
		}
		((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(StartSoon(value));
	}

	private static GUIDUnion[] LoadoutChoices()
	{
		//IL_006a: 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)
		string text = ((Settings.AutoTestLoadouts.Value != null) ? Settings.AutoTestLoadouts.Value.Trim() : "");
		string[] array = ((text.Length == 0) ? new string[0] : text.Split(new char[1] { ',' }));
		GUIDUnion[] array2 = (GUIDUnion[])(object)new GUIDUnion[array.Length];
		for (int i = 0; i < array.Length; i++)
		{
			string text2 = array[i].Trim();
			if (text2.Length != 0)
			{
				try
				{
					array2[i] = new GUIDUnion(text2);
				}
				catch
				{
					Log.Warn("[autotest] AutoTestLoadouts entry " + (i + 2) + " is not a loadout GUID: " + text2);
				}
			}
		}
		return array2;
	}

	private static int[] DestroyList()
	{
		int result;
		return (from t in ((Settings.AutoTestDestroy.Value != null) ? Settings.AutoTestDestroy.Value : "").Split(new char[1] { ',' })
			select t.Trim() into t
			where t.Length > 0
			select int.TryParse(t, out result) ? result : 0 into n
			where n >= 1 && n <= 6
			select n).ToArray();
	}

	private static void ChooseLoadouts()
	{
		//IL_001b: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		GUIDUnion[] array = LoadoutChoices();
		for (int i = 0; i < array.Length; i++)
		{
			if (!((GUIDUnion)(ref array[i])).IsNull && HubFleet.ChosenLoadout(i + 1) != array[i])
			{
				HubFleet.RequestLoadout(i + 1, array[i]);
			}
		}
	}

	private static IEnumerator StartSoon(AutoTestMode mode)
	{
		yield return (object)new WaitForSeconds(1.5f);
		if (mode == AutoTestMode.PvP)
		{
			HubFleet.RequestShipsPerTeam(TestShips);
		}
		else
		{
			HubFleet.RequestShipCount(Mathf.Max(2, TestShips));
		}
		yield return (object)new WaitForSeconds(1.5f);
		ChooseLoadouts();
		yield return (object)new WaitForSeconds(1.5f);
		ChooseLoadouts();
		yield return (object)new WaitForSeconds(1.5f);
		GUIDUnion[] array = LoadoutChoices();
		for (int i = 0; i < array.Length; i++)
		{
			if (!((GUIDUnion)(ref array[i])).IsNull && HubFleet.ChosenLoadout(i + 1) != array[i])
			{
				Log.Warn("[autotest] Ship " + (i + 2) + "'s loadout was not taken: " + ((GUIDUnion)(ref array[i])).AsHex() + ".");
			}
		}
		HubQuestManager hub = HubQuestManager.Instance;
		if ((Object)(object)hub == (Object)null || (ResourceAssetRef)(object)hub.SelectedQuest == (ResourceAssetRef)null)
		{
			Fail("no mission is selected");
			yield break;
		}
		if (mode == AutoTestMode.PvP)
		{
			Log.Info("[autotest] Hub lobby showing: " + PvpTeamScreen.Visible + ", picking: " + PvpTeams.HubChoosing + ", ships " + HubFleet.PlannedShips + ", check: " + (PvpTeams.CheckTeams() ?? "ok") + ".");
			Screenshot("hub-teams");
			PvpTeams.Join(0);
			yield return (object)new WaitForSeconds(1.5f);
			Screenshot("hub-teams-picked");
			PvpTeams.ForceConfirm();
			yield return (object)new WaitForSeconds(1.5f);
			Log.Info("[autotest] Hub teams locked: " + PvpTeams.Locked + ", local team " + FleetShips.TeamOfActor(FleetShips.LocalActor) + ", ship " + (FleetShips.CrewSlot(FleetShips.LocalActor) + 1) + ", can edit ships " + string.Join(",", (from n in Enumerable.Range(1, HubFleet.PlannedShips)
				select n + ":" + FleetApi.CanEditShip(FleetShips.LocalActor, n)).ToArray()) + ".");
		}
		else if (HubFleet.PlannedShips > 1)
		{
			int slot = Mathf.Clamp(Settings.AutoTestCrewShip.Value, 1, HubFleet.PlannedShips) - 1;
			Log.Info("[autotest] Crews screen showing: " + PvpTeamScreen.Visible + ", picking: " + PvpTeams.HubChoosing + ", check: " + (PvpTeams.CheckPicks() ?? "ok") + ".");
			Screenshot("hub-crews");
			PvpTeams.Join(slot);
			yield return (object)new WaitForSeconds(1.5f);
			Screenshot("hub-crews-picked");
			Log.Info("[autotest] Local pick " + (FleetShips.CrewSlot(FleetShips.LocalActor) + 1) + ", check: " + (PvpTeams.CheckPicks() ?? "ok") + ".");
			PvpTeams.Confirm();
			yield return (object)new WaitForSeconds(1.5f);
			Log.Info("[autotest] Crews locked: " + PvpTeams.Locked + ", screen showing " + PvpTeamScreen.Visible + ".");
		}
		Screenshot("hub");
		yield return (object)new WaitForSeconds(0.5f);
		StringBuilder stringBuilder = new StringBuilder();
		for (int num = 0; num < HubFleet.PlannedShips; num++)
		{
			StringBuilder stringBuilder2 = stringBuilder.Append((num == 0) ? "" : "; ").Append(HubFleet.ShipLabel(num)).Append(" = ")
				.Append(HubFleet.ShipDescription(num));
			GUIDUnion val = HubFleet.ForcedType(num);
			stringBuilder2.Append(((GUIDUnion)(ref val)).IsNull ? "" : (" (type " + FleetSlots.TypeName(HubFleet.ForcedType(num)) + ")"));
		}
		Log.Info("[autotest] Planned: " + HubFleet.PlannedMode.ToString() + ", " + HubFleet.PlannedShips + " ships: " + stringBuilder?.ToString() + ".");
		hub.StartQuest(hub.SelectedQuest, (SessionStartType)1, hub.QuestSeed, hub.ChallengeSeed);
	}

	private static void DestroyShip(int number)
	{
		PlayerControlledShip val = FleetShips.BySlot(number - 1);
		if ((Object)(object)val == (Object)null || !PhotonNetwork.IsMasterClient)
		{
			Log.Warn("[autotest] Ship " + number + " isn't there to destroy.");
			return;
		}
		Log.Info("[autotest] Destroying " + FleetShips.Describe(val) + ".");
		((OrbitObject)val).Kill();
	}

	private static void PickTeams()
	{
		if (_teamScreenSeen < 0f)
		{
			_teamScreenSeen = Time.unscaledTime;
			Log.Info("[autotest] The PvP team screen is showing; spawning is on hold until the teams are confirmed.");
			return;
		}
		float num = Time.unscaledTime - _teamScreenSeen;
		if (!_teamJoined && num > 3f)
		{
			Screenshot("teams-empty");
			PvpTeams.Join(0);
			_teamJoined = true;
		}
		else if (_teamJoined && num > 6f && PhotonNetwork.IsMasterClient)
		{
			Screenshot("teams-picked");
			Log.Info("[autotest] Confirming the teams (local player crew slot " + FleetShips.CrewSlot(FleetShips.LocalActor) + ").");
			PvpTeams.ForceConfirm();
			_teamScreenSeen = float.MaxValue;
		}
	}

	private static void StartHackTest()
	{
		//IL_0028: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			LocalPlayer instance = LocalPlayer.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)PrefabSpawnerSync.Instance != (Object)null && HackTerminal.Registered)
			{
				PrefabSpawnerSync.Instance.SpawnCloneStarObject(HackTerminal.Guid, ((Component)instance).transform.position + ((Component)instance).transform.forward * 1.2f + ((Component)instance).transform.up, Quaternion.identity);
				Log.Info("[autotest] Spawned a hacking terminal in front of the player.");
			}
			Log.Info("[autotest] Hack: " + PvpHack.DebugAccess(FleetShips.BySlot(1), 0, 30f) + ".");
			Log.Info("[autotest] Cockpits: " + string.Join(", ", FleetShips.All.Select((PlayerControlledShip s) => FleetShips.Describe(s) + " " + ((Object)(object)PvpHack.CockpitRoom(s) != (Object)null)).ToArray()) + ".");
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] hack test", e);
		}
	}

	private static string DescribeTerminals()
	{
		int num = 0;
		CarryableObject[] array = Object.FindObjectsOfType<CarryableObject>();
		for (int i = 0; i < array.Length; i++)
		{
			if (HackTerminal.Is(array[i]))
			{
				num++;
			}
		}
		return num + " hacking terminal item(s) in the world";
	}

	private static IEnumerator RespawnSequence()
	{
		LocalPlayer instance = LocalPlayer.Instance;
		PlayerControlledShip own = FleetShips.LocalShip;
		if ((Object)(object)instance == (Object)null || (Object)(object)own == (Object)null)
		{
			Log.Warn("[autotest] Respawn test skipped: no character or no ship of their own.");
			_sequenceDone = true;
			yield break;
		}
		Log.Info("[autotest] Killing the local player aboard " + FleetShips.Describe(FleetShips.AboardShip((Player)(object)instance)) + "; they should be re-cloned on " + FleetShips.Describe(own) + ".");
		((Player)instance).Die((DeathCause)4);
		yield return (object)new WaitForSeconds(4f);
		Report("dead");
		Screenshot("dead");
		instance = LocalPlayer.Instance;
		ClonetubeRespawn val = (((Object)(object)instance != (Object)null && (Object)(object)((Player)instance).Locomotion != (Object)null) ? ((UltimateCharacterLocomotion)((Player)instance).Locomotion).GetAbility<ClonetubeRespawn>(-1) : null);
		Log.Info("[autotest] Asking to be re-cloned: " + (val != null && ((Ability)val).StartAbility()) + ".");
		float until = Time.unscaledTime + 40f;
		while (Time.unscaledTime < until && ((Object)(object)LocalPlayer.Instance == (Object)null || ((Player)LocalPlayer.Instance).IsDead))
		{
			yield return (object)new WaitForSeconds(0.5f);
		}
		yield return (object)new WaitForSeconds(4f);
		instance = LocalPlayer.Instance;
		PlayerControlledShip val2 = FleetShips.AboardShip((Player)(object)instance);
		Log.Info("[autotest] Re-cloned: " + ((Object)(object)instance != (Object)null && !((Player)instance).IsDead) + ", aboard " + FleetShips.Describe(val2) + " (should be " + FleetShips.Describe(own) + "): " + (((Object)(object)val2 == (Object)(object)own) ? "RIGHT SHIP" : "WRONG SHIP") + ".");
		Report("re-cloned");
		Screenshot("recloned");
		_sequenceDone = true;
	}

	private static void AfterRespawn()
	{
		if (Settings.AutoTestCruisers.Value && FleetSession.Mode == FleetMode.Coop)
		{
			Go(Step.Cruisers);
			_sequenceDone = false;
			((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(CruiserSequence());
		}
		else
		{
			AfterCruisers();
		}
	}

	private static void AfterCruisers()
	{
		if (Settings.AutoTestDeconstruct.Value && FleetSession.Mode == FleetMode.Coop && FleetShips.Active)
		{
			Go(Step.Deconstructing);
			_sequenceDone = false;
			((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(DeconstructSequence());
		}
		else
		{
			Go(Step.Destroying);
		}
	}

	private static IEnumerator DeconstructSequence()
	{
		BuildProcessController builder = (((Object)(object)ClientGame.Current != (Object)null) ? ((Component)ClientGame.Current).GetComponent<BuildProcessController>() : null);
		PlayerControlledShip val = FleetShips.LocalShip ?? FleetShips.BySlot(0);
		if (!PhotonNetwork.IsMasterClient || (Object)(object)builder == (Object)null || (Object)(object)val == (Object)null)
		{
			Log.Warn("[autotest] Deconstruct: skipped (host " + PhotonNetwork.IsMasterClient + ", build controller " + ((Object)(object)builder != (Object)null) + ", own ship " + ((Object)(object)val != (Object)null) + ").");
			_sequenceDone = true;
			yield break;
		}
		List<PlayerControlledShip> list = new List<PlayerControlledShip> { val };
		foreach (int item in FleetShips.AliveSlots())
		{
			PlayerControlledShip val2 = FleetShips.BySlot(item);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)val)
			{
				list.Add(val2);
			}
		}
		float wait = ClientGame.Current.SharedConfiguration.DeconstructDuration + 20f;
		int passed = 0;
		int failed = 0;
		foreach (PlayerControlledShip ship in list)
		{
			string passedOver;
			BuildSocket socket = TakeApartCandidate(ship, out passedOver);
			if ((Object)(object)socket == (Object)null)
			{
				Log.Warn("[autotest] Deconstruct: nothing on " + FleetShips.Describe(ship) + " can be taken apart; skipped (" + passedOver + ").");
				continue;
			}
			CellModule module = socket.InstalledModule;
			string name = ((AbstractCloneStarObject)module).DisplayName;
			if (!module.BuildingConstraints.AllowDeconstruction)
			{
				module.BuildingConstraints.AllowDeconstruction = true;
				Log.Info("[autotest] Deconstruct: " + name + " came with the ship; made removable here, as if built in this mission.");
			}
			int num = 0;
			foreach (CarryablesSocket connectedSocket in module.ConnectedSockets)
			{
				CarryableObject val3 = (((Object)(object)connectedSocket != (Object)null) ? connectedSocket.Payload : null);
				if (!((Object)(object)val3 == (Object)null) && !((AbstractCloneStarObject)val3).DestroyRequested)
				{
					((OrbitObject)val3).Kill();
					num++;
				}
			}
			if (num > 0)
			{
				Log.Info("[autotest] Deconstruct: emptied " + num + " item slot(s) of " + name + " first.");
				yield return (object)new WaitForSeconds(2f);
			}
			Log.Info("[autotest] Deconstruct: taking apart " + name + " on " + FleetShips.Describe(ship) + " (socket " + socket.Index + ").");
			bool asked = false;
			try
			{
				asked = builder.TryDeconstructModule(module);
			}
			catch (Exception e)
			{
				Log.Failure("[autotest] asking to take apart " + name, e);
			}
			float started = Time.unscaledTime;
			while (Time.unscaledTime - started < wait && StillIn(socket, module))
			{
				yield return (object)new WaitForSeconds(1f);
			}
			if (StillIn(socket, module))
			{
				failed++;
				Log.Error("[autotest] Deconstruct: FAILED on " + FleetShips.Describe(ship) + ", " + name + " is still in its slot after " + wait.ToString("0") + " s (asked " + asked + ", marked as being taken apart " + ((Object)(object)module != (Object)null && module.IsBeingDeconstructed) + ").");
				continue;
			}
			Log.Info("[autotest] Deconstruct: " + name + " came out of its slot on " + FleetShips.Describe(ship) + " in " + (Time.unscaledTime - started).ToString("0") + " s.");
			started = Time.unscaledTime;
			while (Time.unscaledTime - started < 15f && builder.IsWorkingOnSocket(socket))
			{
				yield return (object)new WaitForSeconds(0.5f);
			}
			CarryableObject payload = ((CarryablesSocket)socket).Payload;
			BuildBox box = (BuildBox)(object)((payload is BuildBox) ? payload : null);
			bool rebuilding = false;
			for (int attempt = 0; attempt < 3; attempt++)
			{
				if (!((Object)(object)box != (Object)null))
				{
					break;
				}
				if (rebuilding)
				{
					break;
				}
				if (attempt > 0)
				{
					yield return (object)new WaitForSeconds(2f);
				}
				try
				{
					rebuilding = builder.TryConstructModule(box, -1);
				}
				catch (Exception e2)
				{
					Log.Failure("[autotest] building " + name + " again", e2);
				}
			}
			started = Time.unscaledTime;
			while (rebuilding && Time.unscaledTime - started < wait && (Object)(object)socket.InstalledModule == (Object)null)
			{
				yield return (object)new WaitForSeconds(1f);
			}
			if ((Object)(object)socket.InstalledModule != (Object)null)
			{
				passed++;
				Log.Info("[autotest] Deconstruct: PASSED on " + FleetShips.Describe(ship) + ", " + ((AbstractCloneStarObject)socket.InstalledModule).DisplayName + " is built in that slot again.");
			}
			else
			{
				failed++;
				Log.Error("[autotest] Deconstruct: FAILED on " + FleetShips.Describe(ship) + ", the slot didn't take " + name + " back (build box " + ((Object)(object)box != (Object)null) + ", building " + rebuilding + ").");
			}
		}
		Log.Info("[autotest] Deconstruct: " + passed + " passed, " + failed + " failed.");
		_sequenceDone = true;
	}

	private static bool StillIn(BuildSocket socket, CellModule module)
	{
		if (socket.InstalledModule == module)
		{
			return (Object)(object)module != (Object)null;
		}
		return false;
	}

	private static BuildSocket TakeApartCandidate(PlayerControlledShip ship, out string passedOver)
	{
		passedOver = "no sockets";
		BuildSocketController val = (((Object)(object)ship != (Object)null) ? ((Component)ship).GetComponent<BuildSocketController>() : null);
		if ((Object)(object)val == (Object)null || val.Sockets == null)
		{
			return null;
		}
		BuildSocket val2 = null;
		BuildSocket val3 = null;
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		foreach (BuildSocket socket in val.Sockets)
		{
			CellModule val4 = (((Object)(object)socket != (Object)null) ? socket.InstalledModule : null);
			if ((Object)(object)val4 == (Object)null)
			{
				num++;
				continue;
			}
			if (val4 is VoidDriveModule || val4.BuildingConstraints == null || (ResourceAssetRef)(object)val4.BuildBoxRef == (ResourceAssetRef)null || ((ResourceAssetRef)val4.BuildBoxRef).IsNull)
			{
				num2++;
				continue;
			}
			if (val4.IsInUse || val4.IsBeingDeconstructed)
			{
				num3++;
				continue;
			}
			if ((Object)(object)val4.DefectSystem != (Object)null && val4.DefectSystem.ActiveDefectAmount > 0)
			{
				num4++;
				continue;
			}
			bool flag = val4 is CompositeWeaponModule;
			if (val4.BuildingConstraints.AllowDeconstruction)
			{
				if (flag)
				{
					return socket;
				}
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = socket;
				}
			}
			else if ((Object)(object)val3 == (Object)null || (flag && !(val3.InstalledModule is CompositeWeaponModule)))
			{
				val3 = socket;
			}
		}
		passedOver = val.Sockets.Count + " sockets: " + num + " empty, " + num2 + " can't be taken apart, " + num3 + " in use, " + num4 + " damaged";
		return val2 ?? val3;
	}

	private static IEnumerator CruiserSequence()
	{
		AIDirector director = Singleton<AIDirector>.I;
		FieldInfo countField = GameMember.Field(typeof(Spawner), "currentIntensity");
		FieldInfo unitsField = GameMember.Field(typeof(Spawner), "trackedUnits");
		ScriptableObjectRef tag = new ScriptableObjectRef(new GUIDUnion("1424f8c92ce67d142b620e2203ae8a11"));
		GUIDUnion val = default(GUIDUnion);
		((GUIDUnion)(ref val))..ctor("617c51d5b70105d46956fb25c40603f4");
		SpawnerProfile val2 = null;
		try
		{
			if (((ResourceAssetContainer<ScriptableObjectContainer, ScriptableObject, ScriptableObjectDef>)(object)ResourceAssetContainer<ScriptableObjectContainer, ScriptableObject, ScriptableObjectDef>.Instance).HasItem(val))
			{
				Object asset = ((ResourceAssetContainer<ScriptableObjectContainer, ScriptableObject, ScriptableObjectDef>)(object)ResourceAssetContainer<ScriptableObjectContainer, ScriptableObject, ScriptableObjectDef>.Instance).GetItem(val).Asset;
				val2 = (SpawnerProfile)(object)((asset is SpawnerProfile) ? asset : null);
			}
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] finding the Fleet Battle cruiser spawner", e);
		}
		PlayerControlledShip near = FleetShips.LocalShip ?? FleetShips.BySlot(0);
		if (!PhotonNetwork.IsMasterClient || (Object)(object)director == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)near == (Object)null || GameSessionManager.ActiveSector == (GameSessionSector)null || countField == null || unitsField == null)
		{
			Log.Warn("[autotest] Cruisers: skipped (host " + PhotonNetwork.IsMasterClient + ", AI Director " + ((Object)(object)director != (Object)null) + ", spawner profile " + ((Object)(object)val2 != (Object)null) + ", a ship to send them to " + ((Object)(object)near != (Object)null) + ", the spawner's fields " + (countField != null && unitsField != null) + ").");
			_sequenceDone = true;
			yield break;
		}
		if ((Object)(object)director.GetSpawner(tag, true) != (Object)null)
		{
			Log.Warn("[autotest] Cruisers: skipped, this sector already has the Fleet Battle cruiser spawner.");
			_sequenceDone = true;
			yield break;
		}
		FleetPlan current = FleetSession.Current;
		Log.Info("[autotest] Cruisers: Fleet Pilgrimage enemy scaling is " + ((current != null && current.ScaleEnemies) ? "on" : "OFF, so this only shows the game's own spawner") + "; bringing in the Fleet Battle cruiser spawner.");
		director.CreateSpawner(val2);
		Spawner spawner = null;
		float until = Time.unscaledTime + 10f;
		while ((Object)(object)spawner == (Object)null && Time.unscaledTime < until)
		{
			yield return (object)new WaitForSeconds(0.5f);
			spawner = director.GetSpawner(tag, true);
		}
		if ((Object)(object)spawner == (Object)null)
		{
			Log.Error("[autotest] Cruisers: FAILED, the spawner didn't start.");
			_sequenceDone = true;
			yield break;
		}
		Vector3 val3 = ((AbstractCloneStarObject)near).WorldPosition + ((Component)near).transform.forward * 1500f;
		director.SetSpawnerSpawnHandle(tag, new SpawnHandle(GameSessionManager.ActiveSector, val3, Quaternion.identity, (OrbitObject)null, (Dictionary<byte, object>)null, (DistributionSettings)null, (Object)null, false, false));
		Log.Info("[autotest] Cruisers: the spawner is up (budget " + spawner.TargetIntensity + " of " + spawner.MaxIntensity + ", counts " + SpawnerCount(countField, spawner).ToString("R") + "); its cruisers jump in 1.5 km ahead of " + FleetShips.Describe(near) + ".");
		OrbitObject first = null;
		until = Time.unscaledTime + 45f;
		while ((Object)(object)first == (Object)null && Time.unscaledTime < until)
		{
			yield return (object)new WaitForSeconds(1f);
			first = SpawnerUnit(unitsField, spawner, null);
		}
		if ((Object)(object)first == (Object)null)
		{
			Log.Error("[autotest] Cruisers: FAILED, the spawner sent no cruiser in 45 s (it counts " + SpawnerCount(countField, spawner).ToString("R") + ").");
			EndCruiserTest(director, tag, unitsField, spawner);
			_sequenceDone = true;
			yield break;
		}
		Log.Info("[autotest] Cruisers: the first cruiser is " + ((Object)first).name + " (the spawner counts " + SpawnerCount(countField, spawner).ToString("R") + ").");
		until = Time.unscaledTime + 40f;
		while ((Object)(object)first != (Object)null && !((AbstractCloneStarObject)first).IsDestroyed && first.Sector != GameSessionManager.ActiveSector && Time.unscaledTime < until)
		{
			yield return (object)new WaitForSeconds(1f);
		}
		bool flag = (Object)(object)first == (Object)null || ((AbstractCloneStarObject)first).IsDestroyed;
		bool flag2 = !flag && first.Sector == GameSessionManager.ActiveSector;
		Log.Info("[autotest] Cruisers: it " + (flag ? "was destroyed already." : ((flag2 ? ("arrived, " + Vector3.Distance(((AbstractCloneStarObject)first).WorldPosition, ((AbstractCloneStarObject)near).WorldPosition).ToString("0") + " m from " + FleetShips.Describe(near)) : "did not arrive in 40 s") + "; destroying it.")));
		if (!flag && !((AbstractCloneStarObject)first).DestroyRequested)
		{
			first.Kill();
		}
		float died = Time.unscaledTime;
		yield return (object)new WaitForSeconds(1f);
		float num = SpawnerCount(countField, spawner);
		Log.Info("[autotest] Cruisers: with it gone the spawner counts " + num.ToString("R") + ((num == 0f) ? " (nothing, right)." : " (should be 0: that's room taken from the next one)."));
		OrbitObject val4 = null;
		until = Time.unscaledTime + 75f;
		while ((Object)(object)val4 == (Object)null && Time.unscaledTime < until)
		{
			yield return (object)new WaitForSeconds(1f);
			val4 = SpawnerUnit(unitsField, spawner, first);
		}
		if ((Object)(object)val4 != (Object)null)
		{
			Log.Info("[autotest] Cruisers: PASSED, the next cruiser came " + (Time.unscaledTime - died).ToString("0") + " s after the first one died.");
		}
		else
		{
			Log.Error("[autotest] Cruisers: FAILED, no next cruiser in 75 s; the spawner counts " + SpawnerCount(countField, spawner).ToString("R") + " of its budget " + spawner.TargetIntensity + ".");
		}
		EndCruiserTest(director, tag, unitsField, spawner);
		_sequenceDone = true;
	}

	private static float SpawnerCount(FieldInfo countField, Spawner spawner)
	{
		return GameMember.Read(countField, spawner, float.NaN);
	}

	private static OrbitObject SpawnerUnit(FieldInfo unitsField, Spawner spawner, OrbitObject except)
	{
		List<OrbitObject> list = GameMember.Read<List<OrbitObject>>(unitsField, spawner, null);
		if (list == null)
		{
			return null;
		}
		foreach (OrbitObject item in list)
		{
			if ((Object)(object)item != (Object)null && !((AbstractCloneStarObject)item).IsDestroyed && !((AbstractCloneStarObject)item).DestroyRequested && item != except)
			{
				return item;
			}
		}
		return null;
	}

	private static void EndCruiserTest(AIDirector director, ScriptableObjectRef tag, FieldInfo unitsField, Spawner spawner)
	{
		try
		{
			List<OrbitObject> list = GameMember.Read<List<OrbitObject>>(unitsField, spawner, null);
			if (list != null)
			{
				foreach (OrbitObject item in new List<OrbitObject>(list))
				{
					if ((Object)(object)item != (Object)null && !((AbstractCloneStarObject)item).IsDestroyed && !((AbstractCloneStarObject)item).DestroyRequested)
					{
						item.Kill();
					}
				}
			}
			director.DestroySpawner(tag);
			Log.Info("[autotest] Cruisers: the test's spawner and its cruisers are gone.");
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] removing the cruiser test's spawner", e);
		}
	}

	private static IEnumerator FistSequence()
	{
		LocalPlayer instance = LocalPlayer.Instance;
		InClonetube val = (((Object)(object)instance != (Object)null && (Object)(object)((Player)instance).Locomotion != (Object)null) ? ((UltimateCharacterLocomotion)((Player)instance).Locomotion).GetAbility<InClonetube>(-1) : null);
		if (val != null && (Object)(object)val.ActiveClonetube != (Object)null && (instance.InteractionState.ActiveModes & 0x100000) != 0)
		{
			val.ActiveClonetube.RequestOpenDoorFromInside();
			float until = Time.unscaledTime + 15f;
			while (Time.unscaledTime < until && (Object)(object)LocalPlayer.Instance != (Object)null && (LocalPlayer.Instance.InteractionState.ActiveModes & 0x100000) != 0)
			{
				yield return (object)new WaitForSeconds(0.25f);
			}
			yield return (object)new WaitForSeconds(1f);
			Log.Info("[autotest] Out of the clone tube: " + ((Object)(object)LocalPlayer.Instance != (Object)null && (LocalPlayer.Instance.InteractionState.ActiveModes & 0x100000) == 0) + ".");
		}
		PvpPunch.ForceStanceForTest(up: true);
		yield return (object)new WaitForSeconds(1.5f);
		Log.Info("[autotest] Fists up: stance " + PvpPunch.LocalStanceUp + ", " + FistPose.Describe() + ".");
		Screenshot("fists-eyes");
		GameObject rig = null;
		LocalPlayer instance2 = LocalPlayer.Instance;
		if ((Object)(object)instance2 != (Object)null)
		{
			rig = new GameObject("__FleetAutotestCamera");
			((CinemachineVirtualCameraBase)rig.AddComponent<CinemachineVirtualCamera>()).Priority = 200;
			Transform transform = ((Component)instance2).transform;
			Vector3 val2 = transform.position + transform.up * 1.45f;
			rig.transform.SetPositionAndRotation(val2 + transform.forward * 1.6f + transform.right * 0.5f, Quaternion.LookRotation(val2 - (val2 + transform.forward * 1.6f + transform.right * 0.5f), transform.up));
		}
		yield return (object)new WaitForSeconds(1f);
		Screenshot("fists-front");
		PvpPunch.PunchForTest();
		yield return (object)new WaitForSeconds(0.1f);
		Screenshot("punch-left");
		Log.Info("[autotest] Left punch: " + FistPose.Describe() + ".");
		yield return (object)new WaitForSeconds(0.8f);
		PvpPunch.PunchForTest();
		yield return (object)new WaitForSeconds(0.1f);
		Screenshot("punch-right");
		yield return (object)new WaitForSeconds(0.8f);
		if ((Object)(object)rig != (Object)null)
		{
			Object.Destroy((Object)(object)rig);
		}
		yield return (object)new WaitForSeconds(0.5f);
		Screenshot("punch-eyes-before");
		PvpPunch.PunchForTest();
		yield return (object)new WaitForSeconds(0.1f);
		Screenshot("punch-eyes");
		yield return (object)new WaitForSeconds(0.8f);
		PvpPunch.ForceStanceForTest(up: false);
		yield return (object)new WaitForSeconds(1.5f);
		Log.Info("[autotest] Fists down: stance " + PvpPunch.LocalStanceUp + ", " + FistPose.Describe() + ".");
		Screenshot("fists-down");
		_sequenceDone = true;
	}

	private static IEnumerator TourSequence()
	{
		List<PvpArena.TourSpot> spots = new List<PvpArena.TourSpot>();
		Vector3 centre;
		Vector3 axis;
		Vector3 drop;
		string text = PvpArena.TourArena(out centre, out axis, out drop, spots);
		if (text == null)
		{
			Log.Warn("[autotest] Tour: this match has no PvP arena.");
			_sequenceDone = true;
			yield break;
		}
		Log.Info("[autotest] Tour of " + text + ": centre " + ((Vector3)(ref centre)).ToString("0") + ", BLUE to RED along " + ((Vector3)(ref axis)).ToString("0.00") + ".");
		PvpArena.DropNowForTest();
		Dictionary<VisualElement, StyleEnum<DisplayStyle>> screens = new Dictionary<VisualElement, StyleEnum<DisplayStyle>>();
		HideScreens(screens);
		Spectator.ShowShipsFromSpace();
		GameObject rig = new GameObject("__FleetTourCamera");
		CinemachineVirtualCamera obj = rig.AddComponent<CinemachineVirtualCamera>();
		LensSettings lens = obj.m_Lens;
		lens.FieldOfView = 60f;
		lens.NearClipPlane = 1f;
		lens.FarClipPlane = 60000f;
		obj.m_Lens = lens;
		((CinemachineVirtualCameraBase)obj).Priority = 300;
		rig.AddComponent<RoomPoint>();
		Transform view = rig.transform;
		Vector3 val = Vector3.Cross(Vector3.up, axis);
		Vector3 side = ((Vector3)(ref val)).normalized;
		Vector3 blue = centre - axis * 1800f;
		Vector3 red = centre + axis * 1800f;
		PlaceView(view, centre + Vector3.up * 5200f, centre, axis);
		yield return (object)new WaitForSeconds(3f);
		yield return TourShot(view, centre + Vector3.up * 5200f, centre, axis, screens, "tour-above", "the whole arena from 5.2 km straight above: BLUE's start at the bottom, RED's at the top");
		yield return TourShot(view, centre + side * 4500f + Vector3.up * 1500f, centre, Vector3.up, screens, "tour-side", "the arena from the side, 4.5 km out: BLUE's start on one side of the centre, RED's on the other");
		Vector3 val2 = centre;
		val = side - axis;
		yield return TourShot(view, val2 + ((Vector3)(ref val)).normalized * 3500f + Vector3.up * 2500f, centre, Vector3.up, screens, "tour-diagonal", "the arena from high above BLUE's side, looking across to RED's");
		yield return TourShot(view, blue - axis * 500f + Vector3.up * 120f, centre, Vector3.up, screens, "tour-behind-blue", "from behind BLUE's start, looking towards the centre and RED");
		yield return TourShot(view, red + axis * 500f + Vector3.up * 120f, centre, Vector3.up, screens, "tour-behind-red", "from behind RED's start, looking towards the centre and BLUE");
		yield return TourShot(view, centre + Vector3.up * 60f, blue, Vector3.up, screens, "tour-centre-to-blue", "from the centre of the arena, looking towards BLUE's start");
		yield return TourShot(view, centre + Vector3.up * 60f, red, Vector3.up, screens, "tour-centre-to-red", "from the centre of the arena, looking towards RED's start");
		foreach (PlayerControlledShip item in FleetShips.All.ToList())
		{
			if (!((Object)(object)item == (Object)null))
			{
				Bounds bounds;
				Vector3 val3 = (Extent(((Component)item).gameObject, out bounds) ? ((Bounds)(ref bounds)).center : ((Component)item).transform.position);
				val = ((Component)item).transform.forward * 0.75f + ((Component)item).transform.right * 0.55f + Vector3.up * 0.35f;
				Vector3 val4 = val3 + ((Vector3)(ref val)).normalized * 170f;
				string text2 = FleetShips.Describe(item);
				yield return TourShot(view, val4, val3, Vector3.up, screens, "tour-ship-" + text2.Replace(' ', '-'), text2 + " from ahead and above");
			}
		}
		foreach (PvpArena.TourSpot item2 in spots)
		{
			GameObject val5 = NearestSpawned(item2.Prefab, item2.Position, 1500f);
			Bounds bounds2 = default(Bounds);
			if (!((Object)(object)val5 != (Object)null) || !Extent(val5, out bounds2))
			{
				((Bounds)(ref bounds2))..ctor(((Object)(object)val5 != (Object)null) ? val5.transform.position : item2.Position, Vector3.one * 60f);
			}
			val = ((Bounds)(ref bounds2)).size;
			float num = Mathf.Clamp(((Vector3)(ref val)).magnitude, 25f, 900f);
			Vector3 val6 = ((item2.Team == 0) ? blue : red) - ((Bounds)(ref bounds2)).center;
			val6.y = 0f;
			Vector3 center = ((Bounds)(ref bounds2)).center;
			val = ((Vector3)(ref val6)).normalized * 0.85f + Vector3.up * 0.5f;
			Vector3 val7 = center + ((Vector3)(ref val)).normalized * Mathf.Clamp(num * 1.2f, 40f, 420f);
			yield return TourShot(view, val7, ((Bounds)(ref bounds2)).center, Vector3.up, screens, "tour-" + item2.Label.Replace(' ', '-'), item2.Label + (((Object)(object)val5 != (Object)null) ? "" : " (not found: its planned spot)") + ", seen from its team's side (about " + num.ToString("0") + " m across)");
		}
		GUIDUnion package = ((ResourceAssetRef)DataTable<DefaultAssetTable>.Instance.DefaultCarePackageAsset).AssetGuid;
		float until = Time.unscaledTime + 60f;
		GameObject val8 = NearestSpawned(package, drop, 600f);
		while ((Object)(object)val8 == (Object)null && Time.unscaledTime < until)
		{
			yield return (object)new WaitForSeconds(1f);
			val8 = NearestSpawned(package, drop, 600f);
		}
		yield return (object)new WaitForSeconds(6f);
		val8 = NearestSpawned(package, drop, 2000f);
		Vector3 dropAt = (((Object)(object)val8 != (Object)null) ? val8.transform.position : drop);
		Vector3 val9 = blue - dropAt;
		val9.y = 0f;
		val = ((Vector3)(ref val9)).normalized * 0.8f + Vector3.up * 0.6f;
		yield return TourShot(view, dropAt + ((Vector3)(ref val)).normalized * 120f, dropAt, Vector3.up, screens, "tour-supply-drop", ((Object)(object)val8 != (Object)null) ? "the supply drop, arrived between the teams" : "the supply drop's spot (no drop arrived within a minute)");
		yield return TourShot(view, dropAt + side * 900f + Vector3.up * 300f, dropAt, Vector3.up, screens, "tour-supply-drop-wide", "the supply drop's spot from further out");
		Object.Destroy((Object)(object)rig);
		foreach (KeyValuePair<VisualElement, StyleEnum<DisplayStyle>> item3 in screens)
		{
			item3.Key.style.display = item3.Value;
		}
		Log.Info("[autotest] Tour done: " + _shots + " screenshots so far.");
		_sequenceDone = true;
	}

	private static IEnumerator TourShot(Transform view, Vector3 from, Vector3 at, Vector3 up, Dictionary<VisualElement, StyleEnum<DisplayStyle>> screens, string label, string what)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		PlaceView(view, from, at, up);
		yield return (object)new WaitForSeconds(1.5f);
		HideScreens(screens);
		yield return null;
		Screenshot(label);
		Log.Info("[autotest] Tour " + _shots.ToString("00") + ": " + what + "; camera at " + ((Vector3)(ref from)).ToString("0") + ", looking at " + ((Vector3)(ref at)).ToString("0") + ".");
		yield return (object)new WaitForSeconds(0.3f);
	}

	private static void PlaceView(Transform view, Vector3 from, Vector3 at, Vector3 up)
	{
		//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)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = at - from;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			val = Vector3.forward;
		}
		view.SetPositionAndRotation(from, Quaternion.LookRotation(((Vector3)(ref val)).normalized, up));
	}

	private static void HideScreens(Dictionary<VisualElement, StyleEnum<DisplayStyle>> screens)
	{
		//IL_0053: 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)
		UIDocument[] array = Object.FindObjectsOfType<UIDocument>();
		foreach (UIDocument val in array)
		{
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.panelSettings == (Object)null) && !((Object)(object)val.panelSettings.targetTexture != (Object)null))
			{
				VisualElement rootVisualElement = val.rootVisualElement;
				if (rootVisualElement != null && !screens.ContainsKey(rootVisualElement))
				{
					screens[rootVisualElement] = rootVisualElement.style.display;
					rootVisualElement.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
				}
			}
		}
	}

	private static bool Extent(GameObject thing, out Bounds bounds)
	{
		//IL_0001: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		bounds = default(Bounds);
		bool flag = false;
		Renderer[] componentsInChildren = thing.GetComponentsInChildren<Renderer>();
		foreach (Renderer val in componentsInChildren)
		{
			if (val is MeshRenderer || val is SkinnedMeshRenderer)
			{
				if (!flag)
				{
					bounds = val.bounds;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val.bounds);
				}
				flag = true;
			}
		}
		return flag;
	}

	private static GameObject NearestSpawned(GUIDUnion prefab, Vector3 near, float within)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		GameObject result = null;
		float num = within;
		AbstractCloneStarObject[] array = Object.FindObjectsOfType<AbstractCloneStarObject>();
		foreach (AbstractCloneStarObject val in array)
		{
			if (!((Object)(object)val == (Object)null) && !(val.assetGuid != prefab))
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, near);
				if (!(num2 >= num))
				{
					result = ((Component)val).gameObject;
					num = num2;
				}
			}
		}
		return result;
	}

	private static IEnumerator ReturnSequence()
	{
		Log.Info("[autotest] RETURN TO HUB available: " + FleetReturn.Available + ".");
		try
		{
			MenuScreenController.Instance.Open<EscapeMenu>();
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] opening the escape menu", e);
		}
		yield return (object)new WaitForSeconds(2f);
		Log.Info("[autotest] Escape menu open: " + MenuScreenController.IsOpen() + ", RETURN TO HUB shown: " + FleetReturn.ButtonShown + ".");
		Screenshot("escape-menu");
		FleetReturn.AskForTest();
		yield return (object)new WaitForSeconds(2f);
		Screenshot("return-popup");
		try
		{
			while (MenuScreenController.IsOpen())
			{
				MenuScreenController.Instance.CloseTop(true);
			}
		}
		catch (Exception e2)
		{
			Log.Failure("[autotest] closing the menus", e2);
		}
		yield return (object)new WaitForSeconds(1f);
		FleetReturn.ReturnNow();
		float until = Time.unscaledTime + 170f;
		bool tallied = false;
		while (Time.unscaledTime < until && !GameSessionManager.InHub)
		{
			if (!tallied && StateName() == "GSTallyScreen")
			{
				tallied = true;
				yield return (object)new WaitForSeconds(3f);
				Screenshot("tally");
				PhotonNetwork.RaiseEvent((byte)10, (object)new string[0], new RaiseEventOptions
				{
					CachingOption = (EventCaching)5,
					Receivers = (ReceiverGroup)1
				}, SendOptions.SendReliable);
			}
			yield return (object)new WaitForSeconds(1f);
		}
		if (GameSessionManager.InHub)
		{
			yield return (object)new WaitForSeconds(10f);
			Log.Info("[autotest] Back in the hub (state " + StateName() + "), crews " + string.Join(", ", FleetShips.Crews().Values.Select((CrewEntry crewEntry) => crewEntry.ToString()).ToArray()) + ".");
			Screenshot("hub-again");
			_sequenceDone = true;
		}
	}

	private static void StartJump()
	{
		_leverJump = Settings.AutoTestLeverJump.Value;
		_sequenceDone = false;
		Go(Step.Jumping);
		((MonoBehaviour)FleetRuntime.Instance).StartCoroutine(_leverJump ? LeverJumpSequence() : JumpSequence());
	}

	private static IEnumerator JumpSequence()
	{
		List<int> list = FleetShips.AliveSlots();
		PlayerControlledShip last = ((list.Count > 0) ? FleetShips.BySlot(list[list.Count - 1]) : null);
		VoidJumpSystem val = (((Object)(object)last != (Object)null) ? ((Component)last).GetComponentInChildren<VoidJumpSystem>() : null);
		VoidDriveModule lastDrive = (((Object)(object)last != (Object)null) ? last.GetModule<VoidDriveModule>() : null);
		if ((Object)(object)val == (Object)null || (Object)(object)lastDrive == (Object)null)
		{
			Fail("the last ship has no void jump system");
			yield break;
		}
		Log.Info("[autotest] Setting the escape vector on " + FleetShips.Describe(last) + "'s system; every ship should take it.");
		val.ExitVectorSet(true);
		yield return (object)new WaitForSeconds(2f);
		Report("escape vector");
		foreach (PlayerControlledShip item in FleetShips.All)
		{
			VoidDriveModule module = item.GetModule<VoidDriveModule>();
			if ((Object)(object)module != (Object)null)
			{
				module.JumpCharge = 0f;
			}
		}
		Log.Info("[autotest] Pulling " + FleetShips.Describe(last) + "'s lever with uncharged drives: it should be refused.");
		lastDrive.TryStartImpulseJump();
		yield return (object)new WaitForSeconds(2f);
		foreach (PlayerControlledShip item2 in FleetShips.All)
		{
			VoidDriveModule module2 = item2.GetModule<VoidDriveModule>();
			if ((Object)(object)module2 != (Object)null)
			{
				module2.JumpCharge = 1f;
			}
		}
		int leadBefore = VoidJumpLink.LeaderSlot;
		Log.Info("[autotest] Pulling " + FleetShips.Describe(last) + "'s lever with every drive charged: it leads only if the game starts the jump (escape vector, power and a powered helm), otherwise the lead stays.");
		lastDrive.TryStartImpulseJump();
		yield return (object)new WaitForSeconds(2f);
		VoidJumpSystem componentInChildren = ((Component)last).GetComponentInChildren<VoidJumpSystem>();
		bool flag = (Object)(object)componentInChildren != (Object)null && componentInChildren.ActiveState != null && !(componentInChildren.ActiveState is VoidJumpInactive) && !(componentInChildren.ActiveState is VoidJumpExitVectorSet);
		Log.Info("[autotest] Lead ship now " + (VoidJumpLink.LeaderSlot + 1) + " (expected " + ((flag ? FleetShips.Slot(last) : leadBefore) + 1) + ": the jump " + (flag ? "started" : "didn't start") + ").");
		Report("lever");
		PlayerControlledShip val2 = FleetShips.BySlot(VoidJumpLink.LeaderSlot);
		VoidJumpSystem val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentInChildren<VoidJumpSystem>() : null);
		if ((Object)(object)val3 == (Object)null)
		{
			Fail("the lead ship has no void jump system");
			yield break;
		}
		Log.Info("[autotest] Making " + FleetShips.Describe(val2) + " jump (debug charge + travel); the other ships should follow.");
		val3.DebugTransitionToRotatingState();
	}

	private static IEnumerator LeverJumpSequence()
	{
		MethodInfo pull = GameMember.Method(typeof(VoidDriveModule), "OnJumpLeverPulled");
		List<int> list = FleetShips.AliveSlots();
		PlayerControlledShip last = ((list.Count > 1) ? FleetShips.BySlot(list[list.Count - 1]) : null);
		PlayerControlledShip own = FleetShips.LocalShip ?? ((list.Count > 0) ? FleetShips.BySlot(list[0]) : null);
		VoidDriveModule lastDrive = (((Object)(object)last != (Object)null) ? last.GetModule<VoidDriveModule>() : null);
		VoidDriveModule ownDrive = (((Object)(object)own != (Object)null) ? own.GetModule<VoidDriveModule>() : null);
		VoidJumpSystem lastSystem = (((Object)(object)last != (Object)null) ? ((Component)last).GetComponentInChildren<VoidJumpSystem>() : null);
		if (pull == null || (Object)(object)lastDrive == (Object)null || (Object)(object)ownDrive == (Object)null || (Object)(object)lastSystem == (Object)null)
		{
			Fail("the lever jump needs two living ships with void drives");
			yield break;
		}
		Log.Info("[autotest] Lever jump led by " + FleetShips.Describe(last) + ". Astral maps: " + AstralMapLink.DescribeForTest() + ".");
		foreach (PlayerControlledShip item in FleetShips.All.ToList())
		{
			ForShip(item, "Powering", delegate
			{
				DebugInput.PowerShip();
				DebugInput.PowerAllModules();
			});
		}
		yield return (object)new WaitForSeconds(3f);
		foreach (PlayerControlledShip item2 in FleetShips.All.ToList())
		{
			ForShip(item2, "Charging", (Action)DebugInput.ChargeEnginesOnce);
		}
		yield return (object)new WaitForSeconds(2f);
		Log.Info("[autotest] Powered and charged: " + DescribeDrives() + ".");
		Log.Info("[autotest] Pressing PLOT VECTOR on " + FleetShips.Describe(last) + "'s astral map: " + AstralMapLink.PressForTest(last, null) + ".");
		yield return (object)new WaitForSeconds(2f);
		Log.Info("[autotest] Escape vector on every ship: " + EveryShipIn<VoidJumpExitVectorSet>() + " (" + DescribeDrives() + "); astral maps: " + AstralMapLink.DescribeForTest() + ".");
		if (!EveryShipIn<VoidJumpExitVectorSet>())
		{
			Log.Warn("[autotest] The map didn't set the escape vector everywhere; setting it on " + FleetShips.Describe(last) + "'s jump system.");
			lastSystem.ExitVectorSet(true);
			yield return (object)new WaitForSeconds(2f);
		}
		ownDrive.JumpCharge = 0.9f;
		Log.Info("[autotest] Pulling " + FleetShips.Describe(last) + "'s lever with " + FleetShips.Describe(own) + "'s drive at 90 %: it should be refused, naming " + FleetShips.Describe(own) + ".");
		pull.Invoke(lastDrive, null);
		yield return (object)new WaitForSeconds(0.3f);
		Screenshot("lever-refused");
		float until = Time.unscaledTime + 15f;
		while (Time.unscaledTime < until && !ownDrive.IsFullyCharged)
		{
			yield return (object)new WaitForSeconds(0.25f);
		}
		Log.Info("[autotest] " + FleetShips.Describe(own) + "'s drive full again: " + ownDrive.IsFullyCharged + "; the jump didn't start: " + EveryShipIn<VoidJumpExitVectorSet>() + ".");
		yield return (object)new WaitForSeconds(3.5f);
		int leadBefore = VoidJumpLink.LeaderSlot;
		Log.Info("[autotest] Pulling " + FleetShips.Describe(last) + "'s lever with every drive charged: the jump should start, led by it.");
		pull.Invoke(lastDrive, null);
		yield return (object)new WaitForSeconds(2f);
		bool flag = !(lastSystem.ActiveState is VoidJumpInactive) && !(lastSystem.ActiveState is VoidJumpExitVectorSet);
		Log.Info("[autotest] Jump started: " + flag + "; lead ship " + (VoidJumpLink.LeaderSlot + 1) + " (expected " + ((flag ? FleetShips.Slot(last) : leadBefore) + 1) + "); " + DescribeDrives() + ".");
		if (!flag)
		{
			Log.Warn("[autotest] The lever didn't start the jump; making " + FleetShips.Describe(last) + " jump the debug way instead.");
			lastSystem.DebugTransitionToRotatingState();
		}
		until = Time.unscaledTime + 60f;
		while (Time.unscaledTime < until && !EveryShipTravelling())
		{
			yield return (object)new WaitForSeconds(0.5f);
		}
		Log.Info("[autotest] Every ship in the void: " + EveryShipTravelling() + " (" + DescribeDrives() + ").");
		Report("in the void");
		Screenshot("void");
		yield return (object)new WaitForSeconds(4f);
		GameSessionSector pick = AstralMapLink.PickableForTest(last);
		bool flag2 = pick != (GameSessionSector)null && AstralMapLink.PressForTest(last, pick);
		Log.Info("[autotest] Picking " + ((pick != (GameSessionSector)null) ? (pick.Name + " (" + pick.Id + ")") : "a mission (none on the map)") + " on " + FleetShips.Describe(last) + "'s astral map: " + flag2 + ".");
		yield return (object)new WaitForSeconds(2f);
		Log.Info("[autotest] Astral maps after the pick: " + AstralMapLink.DescribeForTest() + ".");
		if ((Object)(object)GameSessionSectorManager.Instance == (Object)null || GameSessionSectorManager.Instance.DestinationSector == (GameSessionSector)null)
		{
			Log.Warn("[autotest] No destination was picked, so the ships stay in the void.");
			_sequenceDone = true;
			yield break;
		}
		Log.Info("[autotest] Pulling " + FleetShips.Describe(last) + "'s lever again: every ship should arrive at the destination.");
		pull.Invoke(lastDrive, null);
		until = Time.unscaledTime + 60f;
		while (Time.unscaledTime < until && (!(GameSessionManager.ActiveSector != (GameSessionSector)null) || !EveryShipIn<VoidJumpInactive>()))
		{
			yield return (object)new WaitForSeconds(0.5f);
		}
		yield return (object)new WaitForSeconds(4f);
		Log.Info("[autotest] Arrived: " + (GameSessionManager.ActiveSector != (GameSessionSector)null && EveryShipIn<VoidJumpInactive>()) + ", in sector " + ((GameSessionManager.ActiveSector != (GameSessionSector)null) ? (GameSessionManager.ActiveSector.Name + " (" + GameSessionManager.ActiveSector.Id + ")") : "none") + " (picked " + pick.Id + ").");
		Report("arrived");
		Screenshot("arrived");
		_sequenceDone = true;
	}

	private static void ForShip(PlayerControlledShip ship, string what, Action action)
	{
		ShipRedirect.BeginOverride(ship);
		try
		{
			action();
		}
		catch (Exception ex)
		{
			Log.Warn("[autotest] " + what + " " + FleetShips.Describe(ship) + " failed: " + ex.GetType().Name + ": " + ex.Message);
		}
		finally
		{
			ShipRedirect.EndOverride();
		}
	}

	private static bool EveryShipIn<T>() where T : VoidJumpState
	{
		foreach (PlayerControlledShip item in FleetShips.All)
		{
			if (!((Object)(object)item == (Object)null) && !item.StartedDeath)
			{
				VoidJumpSystem componentInChildren = ((Component)item).GetComponentInChildren<VoidJumpSystem>();
				if ((Object)(object)componentInChildren == (Object)null || !(componentInChildren.ActiveState is T))
				{
					return false;
				}
			}
		}
		return true;
	}

	private static bool EveryShipTravelling()
	{
		foreach (PlayerControlledShip item in FleetShips.All)
		{
			if (!((Object)(object)item == (Object)null) && !item.StartedDeath)
			{
				VoidJumpSystem componentInChildren = ((Component)item).GetComponentInChildren<VoidJumpSystem>();
				if ((Object)(object)componentInChildren == (Object)null || (!(componentInChildren.ActiveState is VoidJumpTravellingStable) && !(componentInChildren.ActiveState is VoidJumpTravellingUnstable)))
				{
					return false;
				}
			}
		}
		return true;
	}

	private static string DescribeDrives()
	{
		List<string> list = new List<string>();
		foreach (PlayerControlledShip item in FleetShips.All)
		{
			try
			{
				VoidDriveModule module = item.GetModule<VoidDriveModule>();
				ShipEngine module2 = item.GetModule<ShipEngine>();
				Helm module3 = item.GetModule<Helm>();
				VoidJumpSystem componentInChildren = ((Component)item).GetComponentInChildren<VoidJumpSystem>();
				list.Add(FleetShips.Describe(item) + ": drive " + (((Object)(object)module != (Object)null) ? ((module.JumpCharge * 100f).ToString("0.0") + " %") : "none") + ", powered drive/engine/helm " + ((Object)(object)module != (Object)null && ((CellModule)module).IsPowered) + "/" + ((Object)(object)module2 != (Object)null && ((CellModule)module2).IsPowered) + "/" + ((Object)(object)module3 != (Object)null && ((CellModule)module3).IsPowered) + ", jump " + (((Object)(object)componentInChildren != (Object)null && componentInChildren.ActiveState != null) ? ((object)componentInChildren.ActiveState).GetType().Name : "?"));
			}
			catch (Exception ex)
			{
				list.Add(FleetShips.Describe(item) + ": can't be described (" + ex.GetType().Name + ")");
			}
		}
		return string.Join("; ", list.ToArray());
	}

	private static void Finish()
	{
		try
		{
			Report("final");
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] the final report", e);
		}
		Screenshot("final");
		Log.Info("[autotest] DONE. Leave the game running to look around, or close it.");
		Go(Step.Done);
	}

	private static void Fail(string why)
	{
		Log.Error("[autotest] FAILED: " + why);
		Go(Step.Done);
	}

	public unsafe static void Report(string label)
	{
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_082f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0834: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("[autotest] ---- report (" + label + ") ----");
		stringBuilder.AppendLine("  mode " + FleetSession.Mode.ToString() + ", plan " + ((FleetSession.Current != null) ? FleetSession.Current.ToString() : "none") + ", ships registered " + FleetShips.All.Count + ", active " + FleetShips.Active);
		Vector3 position;
		foreach (PlayerControlledShip item in FleetShips.All)
		{
			try
			{
				VoidJumpSystem componentInChildren = ((Component)item).GetComponentInChildren<VoidJumpSystem>();
				CloneTubeModule module = item.GetModule<CloneTubeModule>();
				string[] obj = new string[21]
				{
					"  ",
					FleetShips.Describe(item),
					": view ",
					FleetShips.ViewId(item).ToString(),
					", pos ",
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null
				};
				position = item.Platform.Position;
				obj[5] = ((object)(*(Vector3*)(&position))/*cast due to .constrained prefix*/).ToString();
				obj[6] = ", sector ";
				obj[7] = ((((OrbitObject)item).Sector != (GameSessionSector)null) ? ((OrbitObject)item).Sector.Id.ToString() : "none");
				obj[8] = ", jump ";
				obj[9] = (((Object)(object)componentInChildren != (Object)null && componentInChildren.ActiveState != null) ? ((object)componentInChildren.ActiveState).GetType().Name : "?");
				obj[10] = ", hp ";
				obj[11] = ((OrbitObject)item).HitPoints.ToString("0");
				obj[12] = ", clone tubes ";
				obj[13] = (((Object)(object)module != (Object)null) ? string.Join(",", module.CloneTubes.Select((CloneTube t) => t.Index.ToString()).ToArray()) : "none");
				obj[14] = ", crew ";
				obj[15] = FleetShips.CrewCount(FleetShips.Slot(item)).ToString();
				obj[16] = ", team ";
				obj[17] = FleetShips.TeamOfSlot(FleetShips.Slot(item)).ToString();
				obj[18] = ", faction ";
				obj[19] = ((OrbitObject)item).faction.ToString();
				obj[20] = (item.StartedDeath ? ", DYING" : "");
				stringBuilder.AppendLine(string.Concat(obj));
			}
			catch (Exception ex)
			{
				stringBuilder.AppendLine("  " + FleetShips.Describe(item) + ": can't be described here (" + ex.GetType().Name + ")");
			}
		}
		stringBuilder.AppendLine("  crews: " + string.Join(", ", FleetShips.Crews().Values.Select((CrewEntry e) => e.ToString()).ToArray()) + "; lead ship " + (VoidJumpLink.LeaderSlot + 1) + "; roster: " + string.Join(", ", (PvpRoster.Seats() ?? new List<RosterSeat>()).Select((RosterSeat r) => r.ToString()).ToArray()));
		if (FleetShips.Active)
		{
			stringBuilder.AppendLine("  resources: " + ShipResources.Describe() + (ShipResources.Active ? "" : " (per-ship resources off)"));
		}
		if (FleetSession.IsPvP)
		{
			stringBuilder.AppendLine("  PvP: teams locked " + PvpTeams.Locked + ", choosing " + PvpTeams.Choosing + ", team screen " + PvpTeamScreen.Visible + ", local team " + FleetShips.TeamOfActor(FleetShips.LocalActor) + ", spectator " + FleetShips.IsSpectator(FleetShips.LocalActor) + ", watching " + FleetShips.Describe(FleetShips.Watched) + ", loser " + PvpMatch.LoserTeam + ", local player faction " + (((Object)(object)LocalPlayer.Instance != (Object)null) ? ((OrbitObject)LocalPlayer.Instance).faction.ToString() : "-"));
			foreach (PlayerControlledShip item2 in FleetShips.All)
			{
				foreach (PlayerControlledShip item3 in FleetShips.All)
				{
					if (!((Object)(object)item2 == (Object)(object)item3) && FleetShips.Slot(item2) <= FleetShips.Slot(item3))
					{
						stringBuilder.AppendLine("  PvP: " + FleetShips.Describe(item2) + " / " + FleetShips.Describe(item3) + ": hostile " + ((SpaceCraft)item2).IsHostile((OrbitObject)(object)item3) + "/" + ((SpaceCraft)item3).IsHostile((OrbitObject)(object)item2) + ", " + Vector3.Distance(((Component)item2).transform.position, ((Component)item3).transform.position).ToString("0") + " m");
					}
				}
				stringBuilder.AppendLine("  PvP: " + FleetShips.Describe(item2) + " parts " + FactionCounts(item2) + "; turrets " + PvpTurrets.DescribeShip(item2));
			}
			PlayerControlledShip val = FleetShips.BySlot(1);
			stringBuilder.AppendLine("  PvP arena: " + PvpArena.Describe());
			if ((Object)(object)val != (Object)null)
			{
				stringBuilder.AppendLine("  PvP hack: BLUE door access to RED 1 " + PvpHack.HasAccess(0, val) + "; " + PvpBoarding.DescribeAccess(val) + "; " + DescribeTerminals());
			}
		}
		if (FleetSession.Mode == FleetMode.Coop)
		{
			stringBuilder.AppendLine("  co-op: local ship " + (FleetShips.CrewSlot(FleetShips.LocalActor) + 1) + ", spectator " + FleetShips.IsSpectator(FleetShips.LocalActor) + ", watching " + FleetShips.Describe(FleetShips.Watched) + ", RETURN TO HUB " + (FleetReturn.Available ? "available" : "not available"));
			if (FleetShips.Active)
			{
				stringBuilder.AppendLine("  astral maps: " + AstralMapLink.DescribeForTest());
			}
		}
		PlayerControlledShip ship = (((Object)(object)ClientGame.Current != (Object)null) ? ClientGame.Current.PlayerShip : null);
		LocalPlayer instance = LocalPlayer.Instance;
		string[] obj2 = new string[12]
		{
			"  game's player ship = ",
			FleetShips.Describe(ship),
			", local crew ship = ",
			FleetShips.Describe(FleetShips.LocalShip),
			", aboard = ",
			FleetShips.Describe(FleetShips.AboardShip((Player)(object)instance)),
			", local character ",
			null,
			null,
			null,
			null,
			null
		};
		object obj4;
		if (!((Object)(object)instance == (Object)null))
		{
			string obj3 = (((Player)instance).IsDead ? "dead" : "alive");
			position = ((Component)instance).transform.position;
			obj4 = obj3 + " at " + ((Vector3)(ref position)).ToString("0");
		}
		else
		{
			obj4 = "none";
		}
		obj2[7] = (string)obj4;
		obj2[8] = ", spectating ";
		obj2[9] = Spectator.Active.ToString();
		obj2[10] = ", game state ";
		obj2[11] = StateName();
		stringBuilder.AppendLine(string.Concat(obj2));
		stringBuilder.AppendLine("  active sector " + ((GameSessionManager.ActiveSector != (GameSessionSector)null) ? GameSessionManager.ActiveSector.Id.ToString() : "none") + ", room players " + PhotonNetwork.PlayerList.Length + "/" + ((PhotonNetwork.CurrentRoom != null) ? PhotonNetwork.CurrentRoom.MaxPlayers : 0));
		stringBuilder.AppendLine("  crew row: " + CrewBadge.Describe());
		stringBuilder.AppendLine("  crew list: " + CrewList.Describe());
		stringBuilder.AppendLine("  chat: " + DescribeChat());
		Log.Info(stringBuilder.ToString());
	}

	private static string FactionCounts(PlayerControlledShip ship)
	{
		SortedDictionary<int, int> sortedDictionary = new SortedDictionary<int, int>();
		List<OrbitObject> list = new List<OrbitObject>(((Component)ship).GetComponentsInChildren<OrbitObject>(true));
		if ((Object)(object)ship.Hull != (Object)null)
		{
			list.AddRange(((Component)ship.Hull).GetComponentsInChildren<OrbitObject>(true));
		}
		foreach (OrbitObject item in list)
		{
			sortedDictionary.TryGetValue(item.faction, out var value);
			sortedDictionary[item.faction] = value + 1;
		}
		return string.Join(", ", sortedDictionary.Select((KeyValuePair<int, int> p) => "faction " + p.Key + " x" + p.Value).ToArray());
	}

	private static string DescribeChat()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			TextChat instance = TextChat.Instance;
			VisualElement val = (VisualElement)(((Object)(object)instance != (Object)null && ChatPanelField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			string text = ((val == null) ? "no panel" : (((int)val.resolvedStyle.display == 0 && val.panel != null) ? "shown" : "hidden"));
			return (((Object)(object)instance != (Object)null) ? ("chat " + text) : "no chat") + ", UI toggle " + MainHUDUI.UIToggleState + ", spectating " + Spectator.Active;
		}
		catch (Exception ex)
		{
			return "unknown (" + ex.Message + ")";
		}
	}

	private static IEnumerator HubCrewListSequence()
	{
		CrewList.PreviewForTest("everyone");
		yield return (object)new WaitForSeconds(1f);
		Log.Info("[autotest] crew list: " + CrewList.Describe());
		Screenshot("hub-crew-list");
		yield return (object)new WaitForSeconds(0.5f);
		CrewList.PreviewForTest("teams");
		yield return (object)new WaitForSeconds(1f);
		Log.Info("[autotest] crew list: " + CrewList.Describe());
		Screenshot("hub-team-lists");
		yield return (object)new WaitForSeconds(0.5f);
		PlayerListPanel.OpenPreview(PlayerListPanel.Kind.Blue, 12);
		yield return (object)new WaitForSeconds(1f);
		Screenshot("player-list");
		yield return (object)new WaitForSeconds(0.5f);
		PlayerListPanel.Close();
		CrewList.PreviewForTest(null);
		_sequenceDone = true;
	}

	private static void CrewListPreview(bool show)
	{
		CrewList.PreviewForTest(show ? "own" : null);
		ShipCards.HeadsForTest = (show ? 5 : 0);
		ShipCards.EnemiesInRangeForTest = show && FleetSession.IsPvP;
	}

	private static void Screenshot(string label)
	{
		try
		{
			string text = Path.Combine(Paths.BepInExRootPath, "fleet-autotest");
			Directory.CreateDirectory(text);
			int num = ++_shots;
			string text2 = Path.Combine(text, num.ToString("00") + "-" + label + ".png");
			ScreenCapture.CaptureScreenshot(text2);
			Log.Info("[autotest] screenshot " + text2);
		}
		catch (Exception e)
		{
			Log.Failure("[autotest] screenshot", e);
		}
	}
}
internal static class CharacterShips
{
	public const string Feature = "Several player ships";

	private static readonly Collider[] Hits = (Collider[])(object)new Collider[16];

	[GamePatch("Several player ships", "CharacterAtmosphericDataTracker", "CheckForInertiaZones", PatchKind.Prefix)]
	private static bool InertiaZonePrefix(CharacterAtmosphericDataTracker __instance, Vector3? overridePosition, int ___gravityZoneMask, ref bool __result)
	{
		//IL_002a: 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_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_00c0: 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_00c6: 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)
		if (!FleetShips.Active)
		{
			return true;
		}
		try
		{
			Vector3 val = (Vector3)(((??)overridePosition) ?? ((Component)__instance.CollectionPoint).transform.position);
			int num = Physics.OverlapSphereNonAlloc(val, __instance.InInertiaZone ? 1f : 0.01f, Hits, ___gravityZoneMask);
			if (num == 0)
			{
				__result = false;
				return false;
			}
			MovingSpacePlatform val2 = null;
			float num2 = float.MaxValue;
			for (int i = 0; i < num; i++)
			{
				Collider val3 = Hits[i];
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				MovingPlatformInertiaZone componentInParent = ((Component)val3).GetComponentInParent<MovingPlatformInertiaZone>();
				MovingSpacePlatform val4 = (((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.ConnectedPlatform != (Object)null) ? componentInParent.ConnectedPlatform : ((Component)val3).GetComponentInParent<MovingSpacePlatform>());
				if (!((Object)(object)val4 == (Object)null))
				{
					Vector3 val5 = val3.ClosestPoint(val) - val;
					float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
					if (sqrMagnitude < num2)
					{
						num2 = sqrMagnitude;
						val2 = val4;
					}
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				PlayerControlledShip viewShip = FleetShips.ViewShip;
				if ((Object)(object)viewShip == (Object)null)
				{
					return true;
				}
				val2 = viewShip.Platform;
			}
			__instance.InInertiaZone = true;
			__instance.ConnectedSpacePlatform = (SpacePlatform)(object)val2;
			__result = true;
			return false;
		}
		catch (Exception e)
		{
			Log.Failure("Finding which ship's inertia zone a player is in", e);
			return true;
		}
	}

	[GamePatch("Several player ships", "CG.Game.Player.LocalPlayer", "IsOnPlayerShip", PatchKind.Prefix)]
	private static bool OnPlayerShipPrefix(LocalPlayer __instance, ref bool __result)
	{
		if (!FleetShips.Active)
		{
			return true;
		}
		try
		{
			__result = IsShipPlatform(((Player)__instance).ZonedPlatform) && !((Player)__instance).Locomotion.AtmosphereTracker.InInertiaZone;
			return false;
		}
		catch (Exception e)
		{
			Log.Failure("Checking whether the local player is aboard a ship", e);
			return true;
		}
	}

	private static bool IsShipPlatform(SpacePlatform platform)
	{
		if ((Object)(object)platform == (Object)null)
		{
			return false;
		}
		List<PlayerControlledShip> all = FleetShips.All;
		for (int i = 0; i < all.Count; i++)
		{
			PlayerControlledShip val = all[i];
			if (val != null && (object)val.Platform == platform)
			{
				return true;
			}
		}
		return false;
	}
}
internal static class CloneTubes
{
	private sealed class ShipTubes
	{
		public PlayerControlledShip Ship;

		public int ShipView;

		public CloneTubeModule Module;

		public List<CloneTube> Tubes;
	}

	public const string Feature = "Several player ships";

	private const int SlotStride = 100;

	private static readonly MethodInfo ListGetItem = GameMember.Property(typeof(List<CloneTube>), "Item")?.GetGetMethod(nonPublic: true);

	private static readonly MethodInfo TubeAtMethod = new Func<List<CloneTube>, int, CloneTube>(TubeAt).Method;

	private static readonly MethodInfo SpawnTubeAtMethod = new Func<List<CloneTube>, int, CloneTube>(SpawnTubeAt).Method;

	private static readonly List<ShipTubes> Registered = new List<ShipTubes>();

	private static CloneTubeModule _disabling;

	private static Player _spawning;

	private static int _refused;

	public static Func<bool> HoldSpawns;

	private static bool FleetMission
	{
		get
		{
			if (FleetSession.ShipCount > 1)
			{
				return FleetShips.PublishedCount > 1;
			}
			return false;
		}
	}

	[GamePatch("Several player ships", "CloneTubeHealing", "OnEnter", PatchKind.Finalizer)]
	private static Exception HealingEnterFinalizer(Exception __exception, CloneTube cloneTube)
	{
		if (!(__exception is NullReferenceException) || (Object)(object)cloneTube == (Object)null)
		{
			return __exception;
		}
		try
		{
			if ((Object)(object)cloneTube.GetOccupant() != (Object)null)
			{
				return __exception;
			}
		}
		catch
		{
			return __exception;
		}
		Log.WarnOnce("tube occupant", "A clone tube's occupant hadn't loaded yet on this client; skipped its healing set-up.");
		return null;
	}

	[GamePatch("Several player ships", "CG.Game.Player.SpawnSystem", "RegisterCloneTubes", PatchKind.Prefix)]
	private static bool RegisterPrefix(List<CloneTube> cts, ref List<CloneTube> ___clonetubes)
	{
		try
		{
			if (cts == null || cts.Count == 0 || (Object)(object)cts[0] == (Object)null)
			{
				return true;
			}
			CloneTubeModule module = ((Component)cts[0]).GetComponentInParent<CloneTubeModule>();
			PlayerControlledShip ship = FleetShips.OwnerOf((Component)(object)cts[0]);
			Registered.RemoveAll((ShipTubes r) => (Object)(object)r.Module == (Object)null || ((Object)(object)module != (Object)null && (Object)(object)r.Module == (Object)(object)module));
			Registered.Add(new ShipTubes
			{
				Ship = ship,
				ShipView = FleetShips.ViewId(ship),
				Module = module,
				Tubes = new List<CloneTube>(cts)
			});
			___clonetubes = Rebuild();
			return false;
		}
		catch (Exception e)
		{
			Log.Failure("Registering a ship's clone tubes", e);
			return true;
		}
	}

	[GamePatch("Several player ships", "CG.Ship.Modules.CloneTubeModule", "OnDisable", PatchKind.Prefix)]
	private static void ModuleDisablePrefix(CloneTubeModule __instance)
	{
		_disabling = __instance;
	}

	[GamePatch("Several player ships", "CG.Ship.Modules.CloneTubeModule", "OnDisable", PatchKind.Finalizer)]
	private static void ModuleDisableFinalizer()
	{
		_disabling = null;
	}

	[GamePatch("Several player ships", "CG.Game.Player.SpawnSystem", "ClearCloneTubes", PatchKind.Prefix)]
	private static bool ClearPrefix(ref List<CloneTube> ___clonetubes)
	{
		try
		{
			if ((Object)(object)_disabling != (Object)null)
			{
				CloneTubeModule module = _disabling;
				Registered.RemoveAll((ShipTubes r) => (Object)(object)r.Module == (Object)null || (Object)(object)r.Module == (Object)(object)module);
			}
			else
			{
				Registered.Clear();
			}
			___clonetubes = Rebuild();
			return false;
		}
		catch (Exception e)
		{
			Log.Failure("Removing a ship's clone tubes", e);
			return true;
		}
	}

	public static List<CloneTube> RegisteredTubes()
	{
		if (Registered.Count == 0)
		{
			return null;
		}
		List<CloneTube> list = new List<CloneTube>();
		foreach (ShipTubes item in Registered)
		{
			foreach (CloneTube tube in item.Tubes)
			{
				if ((Object)(object)tube != (Object)null)
				{
					list.Add(tube);
				}
			}
		}
		return list;
	}

	private static List<CloneTube> Rebuild()
	{
		List<CloneTube> list = new List<CloneTube>();
		foreach (ShipTubes item in Registered.OrderBy((ShipTubes r) => r.ShipView))
		{
			int num = (((Object)(object)item.Ship != (Object)null) ? FleetShips.Slot(item.Ship) : (-1));
			for (int num2 = 0; num2 < item.Tubes.Count; num2++)
			{
				CloneTube val = item.Tubes[num2];
				if (!((Object)(object)val == (Object)null))
				{
					val.Index = ((num >= 0) ? (num * 100 + num2) : list.Count);
					list.Add(val);
				}
			}
		}
		return list;
	}

	public static void Recode()
	{
		try
		{
			if (Registered.Count < 2)
			{
				return;
			}
			foreach (ShipTubes item in Registered)
			{
				if ((Object)(object)item.Ship == (Object)null && (Object)(object)item.Module != (Object)null)
				{
					item.Ship = FleetShips.OwnerOf((Component)(object)item.Module);
					if ((Object)(object)item.Ship != (Object)null)
					{
						item.ShipView = FleetShips.ViewId(item.Ship);
					}
				}
				int num = (((Object)(object)item.Ship != (Object)null) ? FleetShips.Slot(item.Ship) : (-1));
				if (num < 0)
				{
					continue;
				}
				for (int i = 0; i < item.Tubes.Count; i++)
				{
					CloneTube val = item.Tubes[i];
					if ((Object)(object)val != (Object)null)
					{
						val.Index = num * 100 + i;
					}
				}
			}
		}
		catch (Exception e)
		{
			Log.Failure("Numbering the clone tubes", e);
		}
	}

	public static CloneTube TubeAt(List<CloneTube> list, int index)
	{
		if (list == null)
		{
			return null;
		}
		foreach (CloneTube item in list)
		{
			if ((Object)(object)item != (Object)null && item.Index == index)
			{
				return item;
			}
		}
		if (FleetMission)
		{
			return null;
		}
		if (index < 0 || index >= list.Count)
		{
			return null;
		}
		return list[index];
	}

	public static CloneTube SpawnTubeAt(List<CloneTube> list, int index)
	{
		CloneTube val = TubeAt(list, index);
		if ((Object)(object)val != (Object)null || !FleetMission)
		{
			return val;
		}
		try
		{
			PlayerControlledShip localShip = FleetShips.LocalShip;
			val = (((Object)(object)localShip != (Object)null) ? FreeTubeOf(localShip, orAny: true) : null);
			if ((Object)(object)val == (Object)null && list != null)
			{
				foreach (CloneTube item in list)
				{
					if (!((Object)(object)item == (Object)null))
					{
						if (item.IsAvailable())
						{
							val = item;
							break;
						}
						if ((Object)(object)val == (Object)null)
						{
							val = item;
						}
					}
				}
			}
			Log.Warn("The host sent clone tube " + index + " for this player's first spawn, which this client doesn't know; they start in tube " + (((Object)(object)val != (Object)null) ? (val.Index + " of " + FleetShips.Describe(FleetShips.OwnerOf((Component)(object)val))) : "none") + " instead.");
		}
		catch (Exception e)
		{
			Log.Failure("Choosing a clone tube for a new character", e);
		}
		return val;
	}

	[GamePatch("Several player ships", "CG.Game.Player.SpawnSystem", "RespawnPlayer", PatchKind.Transpiler)]
	private static IEnumerable<CodeInstruction> TubeLookupTranspiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
	{
		return ReplaceTubeLookup(instructions, original, TubeAtMethod);
	}

	[GamePatch("Several player ships", "CG.Game.Player.SpawnSystem", "InitializeCharacter", PatchKind.Transpiler)]
	private static IEnumerable<CodeInstruction> SpawnTubeLookupTranspiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
	{
		return ReplaceTubeLookup(instructions, original, SpawnTubeAtMethod);
	}

	private static IEnumerable<CodeInstruction> ReplaceTubeLookup(IEnumerable<CodeInstruction> instructio