Decompiled source of SurtlingSkyfarer v0.1.8

BepInEx/plugins/Skyfarer/Wise.Skyfarer.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using SoftReferenceableAssets.SceneManagement;
using Splatform;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Wise.Skyfarer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.8.0")]
[assembly: AssemblyInformationalVersion("0.1.8")]
[assembly: AssemblyProduct("Wise.Skyfarer")]
[assembly: AssemblyTitle("Wise.Skyfarer")]
[assembly: AssemblyVersion("0.1.8.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Wise.Skyfarer
{
	internal static class AcrobaticSmoke
	{
		internal static IEnumerator Run(Aircraft plane, Player player, Action<bool, string> check)
		{
			Vector3 center = plane.Body.position + Vector3.up * 140f;
			float power = plane.Throttle;
			yield return Rotations(plane, player, center, Vector3.back, Vector3.left, "S backloops", pitch: true, check);
			yield return Rotations(plane, player, center, Vector3.forward, Vector3.right, "W forward loops", pitch: true, check);
			yield return Rotations(plane, player, center, Vector3.left, Vector3.forward, "A left rolls", pitch: false, check);
			yield return Rotations(plane, player, center, Vector3.right, Vector3.back, "D right rolls", pitch: false, check);
			int[] array = new int[2] { -1, 1 };
			foreach (int direction in array)
			{
				Reset(plane, player, center);
				yield return ControlSmoke.Drive(plane, Vector3.zero, up: false, down: false, 1f, brake: false, direction);
				Quaternion rotation = plane.Body.rotation;
				float num = Mathf.DeltaAngle(0f, ((Quaternion)(ref rotation)).eulerAngles.y);
				check(num * (float)direction > 15f && Vector3.Dot(((Component)plane).transform.up, Vector3.up) > 0.99f, ((direction < 0) ? "Q" : "E") + " rudder turns independently without rolling or ejecting the pilot");
			}
			Reset(plane, player, center);
			yield return ControlSmoke.Drive(plane, new Vector3(0.7f, 0f, -0.7f), up: false, down: false, 2f, brake: false, 0.4f);
			check(Quaternion.Angle(Quaternion.identity, plane.Body.rotation) > 80f && ((Character)player).IsAttached(), "Combined pitch, roll and rudder can perform a compound maneuver");
			Reset(plane, player, center);
			yield return ControlSmoke.Drive(plane, Vector3.zero, up: false, down: false, 1f, brake: false, 0f, reverse: true);
			check(Vector3.Dot(plane.Body.linearVelocity, ((Component)plane).transform.forward) > 12f && plane.Gear.GroundedCount == 0, "Ground reverse does not reverse thrust in flight");
			check(Mathf.Abs(plane.Throttle - power) < 0.001f, "Aerobatics and reverse input preserve the selected throttle");
			yield return ControlSmoke.Drive(plane, Vector3.zero, up: false, down: false, 0.2f);
		}

		private static IEnumerator Rotations(Aircraft plane, Player player, Vector3 center, Vector3 input, Vector3 axis, string label, bool pitch, Action<bool, string> check)
		{
			//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)
			//IL_0023: 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)
			Reset(plane, player, center);
			Quaternion previous = plane.Body.rotation;
			float total = 0f;
			float minY = center.y;
			float maxY = center.y;
			float maxSeatDistance = 0f;
			float maxSeatAngle = 0f;
			bool inverted = false;
			bool vertical = false;
			float deadline = Time.time + 24f;
			float num = default(float);
			Vector3 val2 = default(Vector3);
			while (total < 730f && Time.time < deadline)
			{
				plane.LocalInput(input, throttleUp: false, throttleDown: false);
				yield return (object)new WaitForFixedUpdate();
				Quaternion rotation = plane.Body.rotation;
				Quaternion val = Quaternion.Inverse(previous) * rotation;
				((Quaternion)(ref val)).ToAngleAxis(ref num, ref val2);
				if (num > 180f)
				{
					num -= 360f;
				}
				if (num > 0.0001f)
				{
					total += Vector3.Dot(val2, axis) * num;
				}
				previous = rotation;
				minY = Mathf.Min(minY, plane.Body.position.y);
				maxY = Mathf.Max(maxY, plane.Body.position.y);
				inverted |= Vector3.Dot(rotation * Vector3.up, Vector3.up) < -0.95f;
				vertical |= Mathf.Abs((rotation * Vector3.forward).y) > 0.98f;
				maxSeatDistance = Mathf.Max(maxSeatDistance, Vector3.Distance(((Component)player).transform.position, plane.Seats[0].AttachPoint.position));
				maxSeatAngle = Mathf.Max(maxSeatAngle, Quaternion.Angle(((Component)player).transform.rotation, plane.Seats[0].AttachPoint.rotation));
			}
			Plugin.Log.LogInfo((object)$"ACRO {label}: rotation={total:F1} altitudeSpan={maxY - minY:F1} seatDistance={maxSeatDistance:F2} seatAngle={maxSeatAngle:F2}");
			check(total >= 720f && inverted && (!pitch || vertical), label + " complete two continuous rotations through inverted flight");
			check(((Character)player).IsAttached() && plane.Occupant(0) == player.GetPlayerID() && maxSeatDistance < 0.8f && maxSeatAngle < 6f, label + " keep the pilot attached and aligned with the seat");
			if (pitch)
			{
				check(maxY - minY > 15f, label + " bend the flight path into a loop");
			}
			else
			{
				check(Vector3.Dot(((Component)plane).transform.forward, Vector3.forward) > 0.99f, label + " do not change heading");
			}
			yield return ControlSmoke.Drive(plane, Vector3.zero, up: false, down: false, 0.2f);
			Quaternion held = plane.Body.rotation;
			yield return ControlSmoke.Drive(plane, Vector3.zero, up: false, down: false, 0.7f);
			check(Quaternion.Angle(held, plane.Body.rotation) < 2f, label + " stop rotating when released and hold attitude");
		}

		private static void Reset(Aircraft plane, Player player, Vector3 position)
		{
			//IL_0006: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			((Component)plane).transform.SetPositionAndRotation(position, Quaternion.identity);
			plane.Body.position = position;
			plane.Body.rotation = Quaternion.identity;
			plane.Body.linearVelocity = Vector3.forward * (plane.Throttle * 22f);
			plane.Body.angularVelocity = Vector3.zero;
			((Component)player).transform.SetPositionAndRotation(plane.Seats[0].AttachPoint.position, plane.Seats[0].AttachPoint.rotation);
			Physics.SyncTransforms();
		}
	}
	public class Aircraft : MonoBehaviour
	{
		public SkySeat[] Seats;

		public Transform Propeller;

		public Light EngineLight;

		public LandingGear Gear;

		internal static readonly int[] SeatKeys = new int[5]
		{
			StringExtensionMethods.GetStableHashCode("skyfarer.pilot"),
			StringExtensionMethods.GetStableHashCode("skyfarer.passenger1"),
			StringExtensionMethods.GetStableHashCode("skyfarer.passenger2"),
			StringExtensionMethods.GetStableHashCode("skyfarer.passenger3"),
			StringExtensionMethods.GetStableHashCode("skyfarer.passenger4")
		};

		private static readonly int ThrottleKey = StringExtensionMethods.GetStableHashCode("skyfarer.throttle");

		private ZNetView view;

		private Rigidbody body;

		private Ship ship;

		private WaterVolume water;

		private readonly float[] lastHeartbeat = new float[5];

		private float throttle;

		private float roll;

		private float climb;

		private float rudder;

		private float lastInput;

		private float localThrottle;

		private float inputTime;

		private float heartbeatTime;

		private float auditTime;

		private float pendingUntil;

		private int pendingSeat = -1;

		private int pendingRequest;

		private long pendingOwner;

		private float emptySince = -1f;

		private bool wasOwner;

		private bool brake;

		private bool reverse;

		private float clearance = 100f;

		private readonly RaycastHit[] groundHits = (RaycastHit[])(object)new RaycastHit[24];

		private GUIStyle titleStyle;

		private GUIStyle textStyle;

		internal bool SmokeDrive;

		internal Vector3 SmokeInput = new Vector3(1f, 0f, 1f);

		internal float SmokeRudder;

		internal bool SmokeReverse;

		internal int SmokeContacts;

		private bool suspended;

		private bool wasKinematic;

		private float unstuckTime = -100f;

		internal float Rudder => rudder;

		public bool IsValid
		{
			get
			{
				if (Object.op_Implicit((Object)(object)view))
				{
					return view.IsValid();
				}
				return false;
			}
		}

		internal float Throttle => throttle;

		internal Vector3 ControlState => new Vector3(throttle, roll, climb);

		internal float Clearance => clearance;

		internal Rigidbody Body => body;

		internal bool StreamingSuspended => suspended;

		internal bool StartPlaytestCruise()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!IsValid || !view.IsOwner() || !Object.op_Implicit((Object)(object)localPlayer) || Occupant(0) != localPlayer.GetPlayerID() || !(localPlayer.GetDoodadController() is SkySeat skySeat) || (Object)(object)skySeat.Aircraft != (Object)(object)this || skySeat.Index != 0 || !((Character)localPlayer).IsAttached())
			{
				return false;
			}
			localThrottle = (throttle = 1f);
			view.GetZDO().Set(ThrottleKey, throttle);
			roll = (climb = (rudder = 0f));
			lastInput = Time.time;
			inputTime = 0f;
			Rigidbody obj = body;
			Vector3 val = Vector3.ProjectOnPlane(((Component)this).transform.forward, Vector3.up);
			obj.linearVelocity = ((Vector3)(ref val)).normalized * 22f;
			body.angularVelocity = Vector3.zero;
			return true;
		}

		private void Awake()
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			view = ((Component)this).GetComponent<ZNetView>();
			body = ((Component)this).GetComponent<Rigidbody>();
			ship = ((Component)this).GetComponent<Ship>();
			if (IsValid)
			{
				view.Register<long, int, int>("Skyfarer.SeatRequest", (Action<long, long, int, int>)RPC_SeatRequest);
				view.Register<int, int, bool, float>("Skyfarer.SeatReply", (Method<int, int, bool, float>)RPC_SeatReply);
				view.Register<long, int>("Skyfarer.SeatRelease", (Action<long, long, int>)RPC_SeatRelease);
				view.Register<long, int>("Skyfarer.Heartbeat", (Action<long, long, int>)RPC_Heartbeat);
				view.Register<long, Vector3, float, bool, bool>("Skyfarer.Input", (Method<long, Vector3, float, bool, bool>)RPC_Input);
				RegisterUtilityRpcs();
				throttle = StoredThrottle();
				AircraftDurability.Apply(this);
				body.centerOfMass = new Vector3(0f, -0.2f, 0f);
			}
		}

		public long Occupant(int index)
		{
			if (!IsValid || index < 0 || index >= 5)
			{
				return 0L;
			}
			return view.GetZDO().GetLong(SeatKeys[index], 0L);
		}

		internal void RequestSeat(int index)
		{
			if (IsValid && Object.op_Implicit((Object)(object)Player.m_localPlayer) && index >= 0 && index < 5 && (pendingSeat < 0 || !(Time.time <= pendingUntil)))
			{
				pendingSeat = index;
				pendingUntil = Time.time + 4f;
				pendingOwner = view.GetZDO().GetOwner();
				pendingRequest++;
				view.InvokeRPC(pendingOwner, "Skyfarer.SeatRequest", new object[3]
				{
					Player.m_localPlayer.GetPlayerID(),
					index,
					pendingRequest
				});
			}
		}

		private Player AuthenticatedPlayer(long sender, long id)
		{
			Player player = Player.GetPlayer(id);
			if (!Object.op_Implicit((Object)(object)player) || ((Character)player).GetOwner() != sender || ((Character)player).IsDead())
			{
				return null;
			}
			return player;
		}

		private void RPC_SeatRequest(long sender, long id, int index, int request)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValid || !view.IsOwner() || index < 0 || index >= 5)
			{
				return;
			}
			Player val = AuthenticatedPlayer(sender, id);
			if (!Object.op_Implicit((Object)(object)val) || Vector3.Distance(((Component)val).transform.position, Seats[index].AttachPoint.position) > 4f)
			{
				return;
			}
			bool flag = Occupant(index) == 0L || Occupant(index) == id;
			for (int i = 0; i < 5; i++)
			{
				if (i != index && Occupant(i) == id)
				{
					flag = false;
				}
			}
			if (flag)
			{
				view.GetZDO().Set(SeatKeys[index], id);
				lastHeartbeat[index] = Time.time;
				if (index == 0 && view.GetZDO().GetOwner() != sender)
				{
					((Component)this).GetComponent<ZSyncTransform>().SyncNow();
					view.GetZDO().SetOwner(sender);
					wasOwner = false;
					ZDOMan.instance.ForceSendZDO(view.GetZDO().m_uid);
				}
			}
			view.InvokeRPC(sender, "Skyfarer.SeatReply", new object[4]
			{
				index,
				request,
				flag,
				StoredThrottle()
			});
		}

		private void RPC_SeatReply(long sender, int index, int request, bool granted, float currentThrottle)
		{
			if (!IsValid || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || index < 0 || index >= 5 || sender != pendingOwner || index != pendingSeat || request != pendingRequest)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			pendingSeat = -1;
			if (Time.time > pendingUntil || ((Character)localPlayer).IsAttached() || ((Character)localPlayer).IsDead())
			{
				if (granted)
				{
					ReleaseSeat(index, localPlayer.GetPlayerID());
				}
			}
			else if (granted)
			{
				localThrottle = (Finite(currentThrottle) ? Mathf.Clamp01(currentThrottle) : StoredThrottle());
				inputTime = 0f;
				Seats[index].Attach(localPlayer);
			}
			else
			{
				((Character)localPlayer).Message((MessageType)2, "That seat is occupied.", 0, (Sprite)null, false);
			}
		}

		internal void ReleaseSeat(int index, long id)
		{
			if (IsValid)
			{
				view.InvokeRPC("Skyfarer.SeatRelease", new object[2] { id, index });
			}
		}

		private void RPC_SeatRelease(long sender, long id, int index)
		{
			if (IsValid && view.IsOwner() && index >= 0 && index < 5 && Occupant(index) == id)
			{
				Player player = Player.GetPlayer(id);
				if (Object.op_Implicit((Object)(object)player) && ((Character)player).GetOwner() == sender)
				{
					ClearSeat(index);
				}
			}
		}

		private void ClearSeat(int index)
		{
			view.GetZDO().Set(SeatKeys[index], 0L);
			if (index == 0)
			{
				roll = (climb = (rudder = 0f));
				brake = (reverse = false);
			}
		}

		private void RPC_Heartbeat(long sender, long id, int index)
		{
			if (IsValid && view.IsOwner() && index >= 0 && index < 5 && Occupant(index) == id && Object.op_Implicit((Object)(object)AuthenticatedPlayer(sender, id)))
			{
				lastHeartbeat[index] = Time.time;
			}
		}

		private float StoredThrottle()
		{
			float num = (IsValid ? view.GetZDO().GetFloat(ThrottleKey, 0f) : 0f);
			if (!Finite(num))
			{
				return 0f;
			}
			return Mathf.Clamp01(num);
		}

		internal void LocalInput(Vector3 move, bool throttleUp, bool throttleDown, bool wheelBrake = false, float rudderInput = 0f, bool wheelReverse = false)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && IsValid && Occupant(0) == Player.m_localPlayer.GetPlayerID())
			{
				float num = (throttleUp ? 1 : 0) - (throttleDown ? 1 : 0);
				localThrottle = Mathf.Clamp01(localThrottle + num * Time.fixedDeltaTime * 0.38f);
				if (!(Time.time < inputTime))
				{
					inputTime = Time.time + 0.05f;
					Vector3 val = default(Vector3);
					((Vector3)(ref val))..ctor(localThrottle, Mathf.Clamp(move.x, -1f, 1f), Mathf.Clamp(0f - move.z, -1f, 1f));
					view.InvokeRPC("Skyfarer.Input", new object[5]
					{
						Player.m_localPlayer.GetPlayerID(),
						val,
						rudderInput,
						wheelBrake,
						wheelReverse
					});
				}
			}
		}

		private void RPC_Input(long sender, long id, Vector3 input, float rudderInput, bool wheelBrake, bool wheelReverse)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (IsValid && view.IsOwner() && Occupant(0) == id && Object.op_Implicit((Object)(object)AuthenticatedPlayer(sender, id)) && Finite(input.x) && Finite(input.y) && Finite(input.z) && Finite(rudderInput))
			{
				throttle = Mathf.Clamp01(input.x);
				roll = Mathf.Clamp(input.y, -1f, 1f);
				rudder = Mathf.Clamp(rudderInput, -1f, 1f);
				climb = Mathf.Clamp(input.z, -1f, 1f);
				brake = wheelBrake;
				reverse = wheelReverse;
				view.GetZDO().Set(ThrottleKey, throttle);
				lastInput = Time.time;
			}
		}

		private static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}

		internal bool HasRiders()
		{
			for (int i = 0; i < 5; i++)
			{
				if (Occupant(i) != 0L)
				{
					return true;
				}
			}
			foreach (Player allPlayer in Player.GetAllPlayers())
			{
				if (Object.op_Implicit((Object)(object)allPlayer) && !((Character)allPlayer).IsDead() && ((Character)allPlayer).GetOwner() != 0L && ship.IsPlayerInBoat(allPlayer))
				{
					return true;
				}
			}
			return false;
		}

		private void Update()
		{
			if (!IsValid)
			{
				return;
			}
			float num = (view.IsOwner() ? throttle : view.GetZDO().GetFloat(ThrottleKey, 0f));
			if (Object.op_Implicit((Object)(object)Propeller))
			{
				Propeller.Rotate(0f, 0f, (50f + num * 1200f) * Time.deltaTime, (Space)1);
			}
			if (Object.op_Implicit((Object)(object)EngineLight))
			{
				EngineLight.intensity = 0.7f + num * 1.8f;
			}
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer) && localPlayer.GetDoodadController() is SkySeat skySeat && (Object)(object)skySeat.Aircraft == (Object)(object)this)
			{
				if (Time.time >= heartbeatTime)
				{
					heartbeatTime = Time.time + 1f;
					view.InvokeRPC("Skyfarer.Heartbeat", new object[2]
					{
						localPlayer.GetPlayerID(),
						skySeat.Index
					});
				}
				if (!((Character)localPlayer).IsAttached() || ((Character)localPlayer).IsDead())
				{
					localPlayer.StopDoodadControl();
				}
			}
		}

		private void FixedUpdate()
		{
			PhysicsStep(Time.fixedDeltaTime);
		}

		private void OnCollisionEnter(Collision collision)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (SmokeDrive)
			{
				SmokeContacts++;
				Plugin.Log.LogInfo((object)("FLIGHT_CONTACT " + ((Object)collision.gameObject).name + " velocity=" + ((object)collision.relativeVelocity/*cast due to .constrained prefix*/).ToString()));
			}
		}

		internal void PhysicsStep(float dt)
		{
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_055d: Unknown result type (might be due to invalid IL or missing references)
			//IL_055f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0643: Unknown result type (might be due to invalid IL or missing references)
			//IL_065c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0612: Unknown result type (might be due to invalid IL or missing references)
			//IL_066d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_067f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_0688: Unknown result type (might be due to invalid IL or missing references)
			//IL_0628: Unknown result type (might be due to invalid IL or missing references)
			//IL_0794: Unknown result type (might be due to invalid IL or missing references)
			//IL_079b: Unknown result type (might be due to invalid IL or missing references)
			//IL_081d: 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_069b: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_0735: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Unknown result type (might be due to invalid IL or missing references)
			//IL_074e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0753: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0802: Unknown result type (might be due to invalid IL or missing references)
			//IL_0807: Unknown result type (might be due to invalid IL or missing references)
			//IL_080c: Unknown result type (might be due to invalid IL or missing references)
			if (IsValid && view.IsOwner() && view.GetZDO().GetFloat(AircraftDurability.MaxHealthKey, 0f) != (float)SkyfarerSettings.MaxHealth.Value)
			{
				AircraftDurability.Apply(this);
			}
			if (!IsValid || !view.IsOwner())
			{
				wasOwner = false;
			}
			else
			{
				if (SuspendForStreaming())
				{
					return;
				}
				if (!wasOwner)
				{
					((Component)this).GetComponent<ZSyncTransform>().SyncNow();
					wasOwner = true;
					emptySince = -1f;
					for (int i = 0; i < 5; i++)
					{
						lastHeartbeat[i] = Time.time;
					}
					throttle = StoredThrottle();
					roll = (climb = (rudder = 0f));
					brake = (reverse = false);
				}
				if (Time.time >= auditTime)
				{
					auditTime = Time.time + 0.5f;
					for (int j = 0; j < 5; j++)
					{
						if (Occupant(j) != 0L)
						{
							Player player = Player.GetPlayer(Occupant(j));
							if ((Object.op_Implicit((Object)(object)player) && ((Character)player).IsDead()) || Time.time - lastHeartbeat[j] > 6f)
							{
								ClearSeat(j);
							}
						}
					}
				}
				if (SmokeDrive)
				{
					throttle = SmokeInput.x;
					roll = SmokeInput.y;
					climb = SmokeInput.z;
					rudder = SmokeRudder;
					brake = false;
					reverse = SmokeReverse;
				}
				else if (Occupant(0) == 0L || Time.time - lastInput > 1.5f)
				{
					roll = (climb = (rudder = 0f));
					brake = (reverse = false);
				}
				if (HasRiders())
				{
					emptySince = -1f;
				}
				else
				{
					if (emptySince < 0f)
					{
						emptySince = Time.time;
					}
					if (Time.time - emptySince >= 0.5f)
					{
						throttle = (localThrottle = (roll = (climb = (rudder = 0f))));
						brake = (reverse = false);
					}
				}
				view.GetZDO().Set(ThrottleKey, throttle);
				if (body.isKinematic)
				{
					return;
				}
				Gear.Step(Mathf.Clamp(roll + rudder, -1f, 1f), throttle, brake, reverse);
				bool flag = Gear.GroundedCount > 0 && Vector3.Dot(((Component)this).transform.up, Gear.GroundNormal) > 0.5f;
				Vector3 position = body.position;
				Vector3 linearVelocity = body.linearVelocity;
				float waterLevel = Floating.GetWaterLevel(position, ref water);
				float num = waterLevel;
				int num2 = Physics.RaycastNonAlloc(position + Vector3.up * 0.2f, Vector3.down, groundHits, 220f, LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" }), (QueryTriggerInteraction)1);
				for (int k = 0; k < num2; k++)
				{
					if ((Object)(object)((RaycastHit)(ref groundHits[k])).collider.attachedRigidbody != (Object)(object)body && ((RaycastHit)(ref groundHits[k])).point.y <= position.y + 0.15f)
					{
						num = Mathf.Max(num, ((RaycastHit)(ref groundHits[k])).point.y);
					}
				}
				clearance = Mathf.Max(0f, position.y - num - 1f);
				Vector3 val = body.rotation * Vector3.forward;
				float magnitude = ((Vector3)(ref linearVelocity)).magnitude;
				float num3 = Mathf.Clamp01(magnitude / 7f);
				float num4 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(3f, 8f, magnitude));
				if (flag && (climb <= 0f || reverse))
				{
					num4 = 0f;
				}
				float num5 = Mathf.Max(0.1f, 0f - Physics.gravity.y);
				float num6 = num5 * num4;
				bool flag2 = !flag && position.y < waterLevel + 0.9f;
				Vector3 val2 = val * (throttle * SkyfarerSettings.TopSpeed);
				Vector3 val3;
				if (flag2)
				{
					val3 = Vector3.ProjectOnPlane(val, Vector3.up);
					val2 = ((Vector3)(ref val3)).normalized * (brake ? 0f : (reverse ? (-4f) : (throttle * SkyfarerSettings.TopSpeed)));
				}
				if (throttle < 0.15f)
				{
					val2 += Vector3.down * 2.5f;
				}
				if (!flag)
				{
					body.AddForce(Vector3.ClampMagnitude((val2 - linearVelocity) * 2.5f, 40f), (ForceMode)5);
				}
				else if (climb > 0f && !reverse)
				{
					num6 += climb * 6f * num3;
				}
				float num7 = waterLevel + 0.45f - position.y;
				if (num7 > 0f)
				{
					num6 = Mathf.Max(num6, num5 + num7 * 12f - linearVelocity.y * 4f);
				}
				if (throttle < 0.15f && linearVelocity.y < -8f)
				{
					num6 = Mathf.Max(num6, num5 + (-8f - linearVelocity.y) * 2f);
				}
				body.AddForce(Vector3.up * Mathf.Clamp(num6, -5f, num5 + 18f), (ForceMode)5);
				if (flag)
				{
					val3 = Vector3.ProjectOnPlane(val, Gear.GroundNormal);
					Vector3 normalized = ((Vector3)(ref val3)).normalized;
					if (((Vector3)(ref normalized)).sqrMagnitude > 0.01f)
					{
						Quaternion val4 = Quaternion.LookRotation(normalized, Gear.GroundNormal) * Quaternion.Euler((0f - Mathf.Max(0f, climb)) * 4f * num3, 0f, 0f);
						float num8 = Mathf.Clamp(Vector3.Dot(linearVelocity, normalized) / 4.8f * Mathf.Tan(Gear.Wheels[0].steerAngle * ((float)Math.PI / 180f)) * 57.29578f, -30f, 30f);
						body.MoveRotation(Quaternion.AngleAxis(num8 * dt, Gear.GroundNormal) * Quaternion.Slerp(body.rotation, val4, 3.5f * dt));
					}
				}
				else
				{
					Vector3 val5 = ((flag2 && reverse) ? (new Vector3(0f, (0f - (rudder + roll)) * 28f, 0f) * Mathf.Max(0.3f, num3)) : (new Vector3((0f - climb) * 45f, rudder * 28f, (0f - roll) * 85f) * num3));
					if (((Vector3)(ref val5)).sqrMagnitude > 0.0001f)
					{
						body.MoveRotation(body.rotation * Quaternion.AngleAxis(((Vector3)(ref val5)).magnitude * dt, ((Vector3)(ref val5)).normalized));
					}
				}
				Rigidbody obj = body;
				obj.angularVelocity *= Mathf.Clamp01(1f - 5f * dt);
			}
		}

		private void OnGUI()
		{
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || !(localPlayer.GetDoodadController() is SkySeat skySeat) || (Object)(object)skySeat.Aircraft != (Object)(object)this || !IsValid)
			{
				return;
			}
			if (titleStyle == null)
			{
				titleStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 19,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				titleStyle.normal.textColor = new Color(1f, 0.79f, 0.43f);
				textStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14,
					alignment = (TextAnchor)4
				};
				textStyle.normal.textColor = new Color(0.96f, 0.91f, 0.8f);
			}
			float num = (float)(Screen.width - 690) / 2f;
			float num2 = Screen.height - 180;
			GUI.Box(new Rect(num, num2, 690f, 140f), GUIContent.none);
			GUI.Label(new Rect(num, num2 + 5f, 690f, 27f), "SURTLING SKYFARER", titleStyle);
			int num3 = 0;
			for (int i = 1; i < 5; i++)
			{
				if (Occupant(i) != 0L)
				{
					num3++;
				}
			}
			float num4 = (view.IsOwner() ? throttle : view.GetZDO().GetFloat(ThrottleKey, 0f));
			Rect val = new Rect(num, num2 + 33f, 690f, 24f);
			object[] obj = new object[4]
			{
				(skySeat.Index == 0) ? "PILOT" : "PASSENGER",
				num4,
				null,
				null
			};
			Vector3 linearVelocity = body.linearVelocity;
			obj[2] = ((Vector3)(ref linearVelocity)).magnitude;
			obj[3] = num3;
			GUI.Label(val, string.Format("{0}   •   Throttle {1:P0}   •   Speed {2:F0} m/s   •   Passengers {3}/4", obj), textStyle);
			GUI.Label(new Rect(num, num2 + 59f, 690f, 23f), (skySeat.Index == 0) ? "Shift / Ctrl  throttle     W / S  nose down / up     A / D  roll" : "Throttle stays set while someone remains aboard.", textStyle);
			GUI.Label(new Rect(num, num2 + 82f, 690f, 22f), (Gear.GroundedCount > 0) ? "A / D or Q / E  wheel steering     •     S  lift off" : "Q / E  rudder     •     Hold pitch / roll for full rotations", textStyle);
			GUI.Label(new Rect(num, num2 + 105f, 690f, 22f), "Right mouse  brakes     •     R  land/water reverse     •     Space  leave seat", textStyle);
		}

		private void RegisterUtilityRpcs()
		{
			view.Register<long>("Skyfarer.Unstuck", (Action<long, long>)RPC_Unstuck);
			view.Register<string>("Skyfarer.UtilityReply", (Action<long, string>)delegate(long sender, string message)
			{
				if (sender == view.GetZDO().GetOwner() && Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, message, 0, (Sprite)null, false);
				}
			});
		}

		internal bool SuspendForStreaming()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValid || !view.IsOwner() || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return false;
			}
			if (!ZoneSystem.instance.IsZoneLoaded(ZoneSystem.GetZone(body.position)))
			{
				if (!suspended)
				{
					wasKinematic = body.isKinematic;
					if (!wasKinematic)
					{
						body.linearVelocity = Vector3.zero;
						body.angularVelocity = Vector3.zero;
					}
					body.isKinematic = true;
					suspended = true;
				}
				return true;
			}
			if (suspended)
			{
				body.isKinematic = wasKinematic;
				suspended = false;
			}
			return false;
		}

		internal void RequestUnstuck()
		{
			if (IsValid && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				view.InvokeRPC("Skyfarer.Unstuck", new object[1] { Player.m_localPlayer.GetPlayerID() });
			}
		}

		private void RPC_Unstuck(long sender, long id)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (IsValid && view.IsOwner())
			{
				Player val = AuthenticatedPlayer(sender, id);
				if (Object.op_Implicit((Object)(object)val) && !(Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) > 10f) && ServiceAccess.Allowed(((Component)this).transform.position, id))
				{
					view.InvokeRPC(sender, "Skyfarer.UtilityReply", new object[1] { TryUnstuck() });
				}
			}
		}

		internal string TryUnstuck()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValid || !view.IsOwner())
			{
				return "Aircraft is unavailable.";
			}
			if (!HasRiders())
			{
				Vector3 val = body.linearVelocity;
				if (!(((Vector3)(ref val)).magnitude > 2f) && !(throttle > 0.01f))
				{
					if (Time.time - unstuckTime < 10f)
					{
						return "Wait a few seconds before trying again.";
					}
					if (!ZNetScene.instance.IsAreaReady(((Component)this).transform.position))
					{
						return "Wait for the nearby terrain to load.";
					}
					val = Vector3.ProjectOnPlane(((Component)this).transform.forward, Vector3.up);
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					Quaternion val2 = Quaternion.LookRotation((((Vector3)(ref normalized)).sqrMagnitude > 0.01f) ? normalized : Vector3.forward, Vector3.up);
					int mask = LayerMask.GetMask(new string[8] { "Default", "static_solid", "Default_small", "piece", "terrain", "character", "character_net", "character_noenv" });
					for (float num = 2.5f; num <= 8f; num += 0.5f)
					{
						Vector3 val3 = ((Component)this).transform.position + Vector3.up * num;
						bool flag = false;
						Collider[] array = Physics.OverlapBox(val3 + Vector3.up * 1.1f, new Vector3(6.9f, 2.6f, 5.6f), val2, mask, (QueryTriggerInteraction)1);
						for (int i = 0; i < array.Length; i++)
						{
							if (!((Component)array[i]).transform.IsChildOf(((Component)this).transform))
							{
								flag = true;
								break;
							}
						}
						if (!flag)
						{
							body.position = val3;
							body.rotation = val2;
							((Component)this).transform.SetPositionAndRotation(val3, val2);
							if (!body.isKinematic)
							{
								body.linearVelocity = Vector3.zero;
								body.angularVelocity = Vector3.zero;
							}
							Physics.SyncTransforms();
							((Component)this).GetComponent<ZSyncTransform>().SyncNow();
							((Component)this).GetComponent<CargoHold>().SyncCargo();
							unstuckTime = Time.time;
							return "Aircraft lifted and levelled.";
						}
					}
					return "No clear space above the plane within 8 metres. Clear the obstruction and try again.";
				}
			}
			return "Park, stop the engine and have everyone step off first.";
		}
	}
	internal static class AircraftDurability
	{
		internal const float LegacyMaxHealth = 1800f;

		internal static readonly int MaxHealthKey = StringExtensionMethods.GetStableHashCode("skyfarer.maxHealth");

		internal static void Apply(Aircraft aircraft)
		{
			WearNTear component = ((Component)aircraft).GetComponent<WearNTear>();
			float num = SkyfarerSettings.MaxHealth.Value;
			bool value = SkyfarerSettings.DurabilityEnabled.Value;
			component.m_health = num;
			component.m_noSupportWear = (component.m_noRoofWear = false);
			component.m_burnable = value;
			component.m_ashDamageImmune = (component.m_snowDamageImmune = !value);
			ImpactEffect[] componentsInChildren = ((Component)aircraft).GetComponentsInChildren<ImpactEffect>(true);
			foreach (ImpactEffect obj in componentsInChildren)
			{
				obj.m_damageToSelf = value;
				obj.m_hitDestroyChance = 0f;
			}
			ZNetView component2 = ((Component)aircraft).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)component2) || !component2.IsValid() || !component2.IsOwner())
			{
				return;
			}
			ZDO zDO = component2.GetZDO();
			float num2 = zDO.GetFloat(MaxHealthKey, 1800f);
			if (zDO.GetFloat(MaxHealthKey, 0f) != num)
			{
				if (float.IsNaN(num2) || float.IsInfinity(num2) || num2 <= 0f)
				{
					num2 = 1800f;
				}
				float num3 = zDO.GetFloat(ZDOVars.s_health, num2);
				if (float.IsNaN(num3) || float.IsInfinity(num3))
				{
					num3 = num2;
				}
				float num4 = Mathf.Clamp01(num3 / num2) * num;
				zDO.Set(MaxHealthKey, num);
				zDO.Set(ZDOVars.s_health, num4);
				component2.InvokeRPC(ZNetView.Everybody, "RPC_HealthChanged", new object[1] { num4 });
			}
		}

		internal static void ApplyAll()
		{
			if (Object.op_Implicit((Object)(object)AircraftFactory.Prefab))
			{
				AircraftFactory.Prefab.GetComponent<WearNTear>().m_health = SkyfarerSettings.MaxHealth.Value;
			}
			Aircraft[] array = Object.FindObjectsByType<Aircraft>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				Apply(array[i]);
			}
		}
	}
	internal static class AircraftFactory
	{
		internal const string PrefabName = "Wise_SurtlingSkyfarer";

		internal static GameObject Prefab;

		private static Material wood;

		private static Material iron;

		private static Material cloth;

		private static Material redCloth;

		internal static void Register()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_073f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0753: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0791: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_084f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0859: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_0631: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_065d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0687: Unknown result type (might be due to invalid IL or missing references)
			//IL_069f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_091b: Unknown result type (might be due to invalid IL or missing references)
			//IL_092f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0943: Unknown result type (might be due to invalid IL or missing references)
			//IL_0957: Unknown result type (might be due to invalid IL or missing references)
			//IL_0980: Unknown result type (might be due to invalid IL or missing references)
			//IL_0985: Unknown result type (might be due to invalid IL or missing references)
			//IL_098f: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a04: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a35: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a50: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a55: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a6b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a70: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c01: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c6f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c76: Expected O, but got Unknown
			//IL_0cad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb3: Expected O, but got Unknown
			//IL_0cbe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc4: Expected O, but got Unknown
			//IL_0ccf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd5: Expected O, but got Unknown
			//IL_0cdf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce5: Expected O, but got Unknown
			//IL_0cec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf6: Expected O, but got Unknown
			//IL_0d0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d10: Invalid comparison between Unknown and I4
			//IL_0b6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b85: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d3e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d4b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d53: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d54: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d5e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d6e: Expected O, but got Unknown
			PrefabManager instance = PrefabManager.Instance;
			CargoHold.Register();
			GameObject prefab = instance.GetPrefab("Karve");
			GameObject val = instance.CreateClonedPrefab("Wise_SurtlingSkyfarer", prefab);
			val.SetActive(false);
			Prefab = val;
			wood = ((Component)instance.GetPrefab("wood_beam").transform.Find("new")).GetComponent<Renderer>().sharedMaterial;
			iron = new Material(wood)
			{
				name = "Skyfarer forged fittings"
			};
			iron.SetColor("_Color", new Color(0.23f, 0.24f, 0.23f));
			SkinnedMeshRenderer val2 = prefab.GetComponentsInChildren<SkinnedMeshRenderer>(true).First();
			cloth = new Material(((Renderer)instance.GetPrefab("DeerHide").GetComponentsInChildren<MeshRenderer>(true).First((MeshRenderer r) => Object.op_Implicit((Object)(object)((Renderer)r).sharedMaterial) && !((Object)((Renderer)r).sharedMaterial.shader).name.Contains("Particle"))).sharedMaterial)
			{
				name = "Skyfarer sailcloth"
			};
			cloth.mainTexture = ((Renderer)val2).sharedMaterial.mainTexture;
			if (cloth.HasProperty("_Glossiness"))
			{
				cloth.SetFloat("_Glossiness", 0f);
			}
			if (cloth.HasProperty("_Metallic"))
			{
				cloth.SetFloat("_Metallic", 0f);
			}
			cloth.SetColor("_Color", new Color(0.91f, 0.82f, 0.64f));
			redCloth = new Material(cloth)
			{
				name = "Skyfarer oxblood cloth"
			};
			redCloth.SetColor("_Color", new Color(0.51f, 0.13f, 0.09f));
			Object.DestroyImmediate((Object)(object)val.GetComponent<LODGroup>());
			Disable(val, "ship/mast", "ship/ropes", "SurfaceEffects", "ashdamageeffects", "piece_chest");
			Chair[] componentsInChildren = val.GetComponentsInChildren<Chair>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				((Component)componentsInChildren[num]).gameObject.SetActive(false);
			}
			Ship component = val.GetComponent<Ship>();
			((Behaviour)component).enabled = true;
			((Component)component.m_shipControlls).gameObject.SetActive(false);
			component.m_hasSail = false;
			((Collider)component.m_floatCollider).enabled = false;
			Transform obj = val.transform.Find("OnboardTrigger");
			obj.localPosition = new Vector3(0f, 1.1f, 0f);
			obj.localScale = new Vector3(3.4f, 3.8f, 9f);
			Piece component2 = val.GetComponent<Piece>();
			component2.m_name = "Surtling Skyfarer";
			component2.m_description = "A core-fired skyboat with woven wings. One pilot and four passengers.";
			component2.m_canBeRemoved = true;
			component2.m_waterPiece = false;
			component2.m_groundOnly = false;
			component2.m_noInWater = false;
			component2.m_notOnTiltingSurface = true;
			component2.m_usage = (UsageTagFlags)2048;
			WearNTear component3 = val.GetComponent<WearNTear>();
			component3.m_health = SkyfarerSettings.MaxHealth.Value;
			component3.m_noRoofWear = false;
			component3.m_noSupportWear = false;
			component3.m_ashDamageImmune = true;
			component3.m_snowDamageImmune = true;
			component3.m_burnable = false;
			component3.m_staticPosition = false;
			component3.m_supports = false;
			ImpactEffect[] componentsInChildren2 = val.GetComponentsInChildren<ImpactEffect>(true);
			foreach (ImpactEffect obj2 in componentsInChildren2)
			{
				obj2.m_damageToSelf = false;
				obj2.m_hitDestroyChance = 0f;
			}
			Rigidbody component4 = val.GetComponent<Rigidbody>();
			component4.mass = 700f;
			component4.centerOfMass = new Vector3(0f, -0.2f, 0f);
			component4.linearDamping = 0.02f;
			component4.angularDamping = 3f;
			component4.interpolation = (RigidbodyInterpolation)1;
			component4.collisionDetectionMode = (CollisionDetectionMode)2;
			ZNetView component5 = val.GetComponent<ZNetView>();
			component5.m_persistent = true;
			component5.m_distant = false;
			val.GetComponent<ZSyncTransform>().m_syncBodyVelocity = true;
			Transform val3 = Child(val.transform, "Skyfarer airframe", Vector3.zero);
			for (int num2 = -1; num2 <= 1; num2 += 2)
			{
				for (int num3 = 0; num3 < 5; num3++)
				{
					float num4 = 1.05f + (float)num3 * 1.12f;
					float x = num4 + 1.12f;
					Vector3 a = WingPoint(num2, num4, trailing: false);
					Vector3 val4 = WingPoint(num2, x, trailing: false);
					Vector3 val5 = WingPoint(num2, x, trailing: true);
					Vector3 val6 = WingPoint(num2, num4, trailing: true);
					Panel(val3, "Stitched wing " + num2 + " " + num3, a, val4, val5, val6, (num3 == 3) ? redCloth : cloth, 0.1f);
					Beam(val3, "Leading spar", a, val4, 0.11f, wood);
					Beam(val3, "Trailing spar", val6, val5, 0.08f, wood);
					Beam(val3, "Wing rib", a, val6, 0.065f, wood);
					if (num3 == 4)
					{
						Beam(val3, "Wingtip rib", val4, val5, 0.07f, wood);
					}
				}
				Beam(val3, "Wing brace", new Vector3((float)num2 * 1.1f, 0.4f, 0.4f), WingPoint(num2, 4.1f, trailing: false), 0.09f, wood);
				Beam(val3, "Aft wing brace", new Vector3((float)num2 * 1.05f, 0.4f, -1.5f), WingPoint(num2, 4.1f, trailing: true), 0.075f, wood);
				((Component)Child(val3, "Wing collision", new Vector3((float)num2 * 3.7f, 2.85f, -0.25f))).gameObject.AddComponent<BoxCollider>().size = new Vector3(5.1f, 0.14f, 2.1f);
				Beam(val3, "Cabane strut", new Vector3((float)num2 * 0.9f, 0.45f, 1.3f), new Vector3((float)num2 * 1.05f, 2.65f, 1.6f), 0.12f, wood);
				Panel(val3, "Tailplane", new Vector3(0f, 1.6f, -3.4f), new Vector3((float)num2 * 2.5f, 1.65f, -4.1f), new Vector3((float)num2 * 2.2f, 1.65f, -5f), new Vector3(0f, 1.6f, -4.8f), redCloth, 0.02f);
				Beam(val3, "Tail spar", new Vector3(0f, 1.6f, -3.4f), new Vector3((float)num2 * 2.5f, 1.65f, -4.1f), 0.09f, wood);
			}
			Beam(val3, "Tail spine", new Vector3(0f, 0.6f, -2.8f), new Vector3(0f, 1.6f, -5f), 0.18f, wood);
			Panel(val3, "Raven tail fin", new Vector3(0f, 1.6f, -3.5f), new Vector3(0f, 3.25f, -4.4f), new Vector3(0f, 2.7f, -5.1f), new Vector3(0f, 1.6f, -5f), cloth, 0f);
			Beam(val3, "Fin spar", new Vector3(0f, 1.6f, -3.5f), new Vector3(0f, 3.25f, -4.4f), 0.1f, wood);
			Transform val7 = Child(val3, "Surtling engine", new Vector3(0f, 1.2f, 3.6f));
			Cube(val7, "Core housing", Vector3.zero, new Vector3(0.82f, 0.82f, 1.3f), iron, collision: false);
			GameObject val8 = Object.Instantiate<GameObject>(((Component)instance.GetPrefab("SurtlingCore").transform.Find("attach")).gameObject, val7, false);
			((Object)val8).name = "Bound Surtling core";
			val8.transform.localPosition = new Vector3(0f, 0.53f, 0f);
			val8.transform.localScale = Vector3.one * 2.3f;
			Collider[] componentsInChildren3 = val8.GetComponentsInChildren<Collider>(true);
			for (int num = 0; num < componentsInChildren3.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[num]);
			}
			LODGroup[] componentsInChildren4 = val8.GetComponentsInChildren<LODGroup>(true);
			for (int num = 0; num < componentsInChildren4.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[num]);
			}
			Transform val9 = Child(val7, "Propeller", new Vector3(0f, 0f, 0.85f));
			for (int num5 = 0; num5 < 4; num5++)
			{
				Transform obj3 = Child(val9, "Carved propeller blade", Vector3.zero);
				obj3.localRotation = Quaternion.Euler(0f, 0f, (float)(num5 * 90));
				Panel(obj3, "Blade", new Vector3(-0.12f, 0.18f, 0f), new Vector3(0.09f, 1.35f, 0.04f), new Vector3(0.32f, 1.25f, 0.04f), new Vector3(0.14f, 0.18f, 0f), wood, 0f);
			}
			Cube(val9, "Iron hub", Vector3.zero, Vector3.one * 0.3f, iron, collision: false);
			Aircraft aircraft = val.AddComponent<Aircraft>();
			val.AddComponent<CargoHold>();
			val.AddComponent<AircraftServices>();
			aircraft.Gear = AddWagonWheels(val, val3);
			aircraft.Propeller = val9;
			aircraft.EngineLight = val8.GetComponentInChildren<Light>();
			aircraft.Seats = new SkySeat[5];
			Vector3[] array = (Vector3[])(object)new Vector3[5]
			{
				new Vector3(0f, 0.15f, 2.1f),
				new Vector3(-0.62f, 0.1f, 0.55f),
				new Vector3(0.62f, 0.1f, 0.55f),
				new Vector3(-0.62f, 0.1f, -1.25f),
				new Vector3(0.62f, 0.1f, -1.25f)
			};
			for (int num6 = 0; num6 < array.Length; num6++)
			{
				Transform val10 = Child(val.transform, (num6 == 0) ? "Pilot seat" : ("Passenger seat " + num6), array[num6]);
				SkySeat skySeat = ((Component)val10).gameObject.AddComponent<SkySeat>();
				skySeat.Index = num6;
				skySeat.Aircraft = aircraft;
				skySeat.AttachPoint = Child(val10, "SkyfarerAttach" + num6, new Vector3(0f, 0.1f, 0f));
				componentsInChildren4 = Object.Instantiate<GameObject>(((Component)instance.GetPrefab("piece_chair").transform.Find("New")).gameObject, val10, false).GetComponentsInChildren<LODGroup>(true);
				for (int num = 0; num < componentsInChildren4.Length; num++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren4[num]);
				}
				BoxCollider obj4 = ((Component)val10).gameObject.AddComponent<BoxCollider>();
				obj4.center = new Vector3(0f, 0.42f, 0f);
				obj4.size = new Vector3(0.55f, 0.8f, 0.55f);
				aircraft.Seats[num6] = skySeat;
			}
			Beam(val3, "Pilot tiller", new Vector3(0f, 0.45f, 2.7f), new Vector3(0f, 1f, 2.55f), 0.08f, iron);
			Beam(val3, "Pilot tiller grip", new Vector3(-0.3f, 1f, 2.55f), new Vector3(0.3f, 1f, 2.55f), 0.09f, wood);
			SetLayer(val3, val.layer);
			SkySeat[] seats = aircraft.Seats;
			for (int num = 0; num < seats.Length; num++)
			{
				SetLayer(((Component)seats[num]).transform, val.layer);
			}
			PieceManager instance2 = PieceManager.Instance;
			PieceConfig val11 = new PieceConfig();
			val11.PieceTable = "Hammer";
			val11.Category = "Misc";
			val11.CraftingStation = "piece_workbench";
			val11.Requirements = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				new RequirementConfig("FineWood", 80, 0, true),
				new RequirementConfig("Copper", 25, 0, true),
				new RequirementConfig("DeerHide", 20, 0, true),
				new RequirementConfig("SurtlingCore", 8, 0, true)
			};
			if (!instance2.AddPiece(new CustomPiece(val, false, val11)))
			{
				throw new InvalidOperationException("Could not register Skyfarer build piece.");
			}
			val.SetActive(true);
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				string environmentVariable = Environment.GetEnvironmentVariable("SKYFARER_PREVIEW");
				int num7 = (string.IsNullOrEmpty(environmentVariable) ? 128 : 1024);
				Sprite val12 = RenderManager.Instance.Render(new RenderRequest(val)
				{
					Width = num7,
					Height = num7,
					Rotation = RenderManager.IsometricRotation,
					ParticleSimulationTime = -1f
				});
				if (Object.op_Implicit((Object)(object)val12))
				{
					component2.m_icon = val12;
					if (!string.IsNullOrEmpty(environmentVariable))
					{
						File.WriteAllBytes(environmentVariable, ImageConversion.EncodeToPNG(val12.texture));
					}
				}
			}
			Plugin.Log.LogInfo((object)"Skyfarer registered: 1 pilot, 4 passenger seats, 13.3 m wingspan.");
		}

		private static Vector3 WingPoint(int side, float x, bool trailing)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			float num = (x - 1.05f) / 5.6f;
			return new Vector3((float)side * x, 2.65f + num * 0.4f, (trailing ? (-1.4f) : 1.6f) - num * (trailing ? 0.2f : 1.15f));
		}

		private static LandingGear AddWagonWheels(GameObject root, Transform frame)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			LandingGear landingGear = root.AddComponent<LandingGear>();
			landingGear.Wheels = (WheelCollider[])(object)new WheelCollider[4];
			landingGear.Visuals = (Transform[])(object)new Transform[4];
			Vector3 val4 = default(Vector3);
			for (int i = 0; i < 2; i++)
			{
				float num = ((i == 0) ? 2.3f : (-2.5f));
				Beam(frame, "Wagon axle", new Vector3(-1.6f, -0.67f, num), new Vector3(1.6f, -0.67f, num), 0.18f, iron);
				for (int j = 0; j < 2; j++)
				{
					int num2 = i * 2 + j;
					float num3 = ((j == 0) ? (-1.6f) : 1.6f);
					Beam(frame, "Axle support", new Vector3(num3 * 0.6f, 0.1f, num), new Vector3(num3 * 0.85f, -0.65f, num), 0.15f, wood);
					for (int k = 0; k < 3; k++)
					{
						Cube(frame, "Laminated spring", new Vector3(num3 * 0.83f, -0.36f - (float)k * 0.06f, num), new Vector3(0.15f, 0.05f, 1.1f - (float)k * 0.2f), iron, collision: false);
					}
					WheelCollider val = ((Component)Child(frame, "Wheel suspension " + num2, new Vector3(num3, -0.5f, num))).gameObject.AddComponent<WheelCollider>();
					val.radius = 0.72f;
					val.mass = 25f;
					val.suspensionDistance = 0.32f;
					val.suspensionSpring = new JointSpring
					{
						spring = 40000f,
						damper = 4200f,
						targetPosition = 0.5f
					};
					val.forceAppPointDistance = 0.45f;
					val.wheelDampingRate = 0.1f;
					WheelFrictionCurve val2 = default(WheelFrictionCurve);
					((WheelFrictionCurve)(ref val2)).extremumSlip = 0.4f;
					((WheelFrictionCurve)(ref val2)).extremumValue = 1f;
					((WheelFrictionCurve)(ref val2)).asymptoteSlip = 0.8f;
					((WheelFrictionCurve)(ref val2)).asymptoteValue = 0.5f;
					((WheelFrictionCurve)(ref val2)).stiffness = 1f;
					val.forwardFriction = val2;
					val2 = default(WheelFrictionCurve);
					((WheelFrictionCurve)(ref val2)).extremumSlip = 0.2f;
					((WheelFrictionCurve)(ref val2)).extremumValue = 1f;
					((WheelFrictionCurve)(ref val2)).asymptoteSlip = 0.5f;
					((WheelFrictionCurve)(ref val2)).asymptoteValue = 0.75f;
					((WheelFrictionCurve)(ref val2)).stiffness = 1.1f;
					val.sidewaysFriction = val2;
					landingGear.Wheels[num2] = val;
					Transform val3 = Child(frame, ((i == 0) ? "Front" : "Rear") + " wagon wheel " + j, new Vector3(num3, -0.66f, num));
					Ring(val3, "Wooden felloe", 0.57f, 0.69f, 0.26f, wood);
					Ring(val3, "Forged iron tire", 0.685f, 0.72f, 0.28f, iron);
					for (int l = 0; l < 10; l++)
					{
						float num4 = (float)l * (float)Math.PI * 2f / 10f;
						((Vector3)(ref val4))..ctor(0f, Mathf.Cos(num4), Mathf.Sin(num4));
						Beam(val3, "Oak spoke", val4 * 0.12f, val4 * 0.6f, 0.07f, wood);
					}
					Cylinder(val3, "Wooden hub", Vector3.zero, new Vector3(0.29f, 0.22f, 0.29f), wood);
					for (int m = -1; m <= 1; m += 2)
					{
						Cylinder(val3, "Iron hub cap", new Vector3((float)m * 0.22f, 0f, 0f), new Vector3(0.32f, 0.025f, 0.32f), iron);
					}
					landingGear.Visuals[num2] = val3;
				}
			}
			return landingGear;
		}

		private static void Cylinder(Transform parent, string name, Vector3 position, Vector3 scale, Material material)
		{
			//IL_0020: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)2);
			obj.transform.SetParent(parent, false);
			((Object)obj).name = name;
			obj.transform.localPosition = position;
			obj.transform.localRotation = Quaternion.Euler(0f, 0f, 90f);
			obj.transform.localScale = scale;
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			obj.GetComponent<Renderer>().sharedMaterial = material;
		}

		private static void Ring(Transform parent, string name, float inner, float outer, float width, Material material)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> vertices = new List<Vector3>();
			List<Vector2> uv = new List<Vector2>();
			List<int> triangles = new List<int>();
			for (int i = 0; i < 32; i++)
			{
				float theta = (float)i * (float)Math.PI * 2f / 32f;
				float theta2 = (float)(i + 1) * (float)Math.PI * 2f / 32f;
				float num = width / 2f;
				Quad(Point(0f - num, outer, theta), Point(0f - num, outer, theta2), Point(num, outer, theta2), Point(num, outer, theta));
				Quad(Point(num, inner, theta), Point(num, inner, theta2), Point(0f - num, inner, theta2), Point(0f - num, inner, theta));
				Quad(Point(num, inner, theta), Point(num, outer, theta), Point(num, outer, theta2), Point(num, inner, theta2));
				Quad(Point(0f - num, inner, theta2), Point(0f - num, outer, theta2), Point(0f - num, outer, theta), Point(0f - num, inner, theta));
			}
			Mesh val = new Mesh
			{
				name = name
			};
			val.SetVertices(vertices);
			val.SetUVs(0, uv);
			val.SetTriangles(triangles, 0);
			val.colors = Enumerable.Repeat<Color>(Color.white, vertices.Count).ToArray();
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject gameObject = ((Component)Child(parent, name, Vector3.zero)).gameObject;
			gameObject.AddComponent<MeshFilter>().sharedMesh = val;
			((Renderer)gameObject.AddComponent<MeshRenderer>()).sharedMaterial = material;
			static Vector3 Point(float x, float r, float num2)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3(x, Mathf.Cos(num2) * r, Mathf.Sin(num2) * r);
			}
			void Quad(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
			{
				//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)
				//IL_0024: 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_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: 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_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				int count = vertices.Count;
				vertices.AddRange((IEnumerable<Vector3>)(object)new Vector3[4] { p0, p1, p2, p3 });
				uv.AddRange((IEnumerable<Vector2>)(object)new Vector2[4]
				{
					new Vector2(0f, 0f),
					new Vector2(1f, 0f),
					new Vector2(1f, 1f),
					new Vector2(0f, 1f)
				});
				triangles.AddRange(new int[6]
				{
					count,
					count + 1,
					count + 2,
					count,
					count + 2,
					count + 3
				});
			}
		}

		internal static Transform Child(Transform parent, string name, Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = pos;
			return val.transform;
		}

		private static void Disable(GameObject root, params string[] paths)
		{
			foreach (string text in paths)
			{
				Transform obj = root.transform.Find(text);
				if (obj != null)
				{
					((Component)obj).gameObject.SetActive(false);
				}
			}
		}

		private static void Cube(Transform parent, string name, Vector3 position, Vector3 size, Material material, bool collision)
		{
			//IL_0021: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = name;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = position;
			val.transform.localScale = size;
			val.GetComponent<Renderer>().sharedMaterial = material;
			if (!collision)
			{
				Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
				return;
			}
			val.GetComponent<Collider>().sharedMaterial = new PhysicsMaterial("Skyfarer skid")
			{
				dynamicFriction = 0.1f,
				staticFriction = 0.12f,
				frictionCombine = (PhysicsMaterialCombine)2,
				bounciness = 0f,
				bounceCombine = (PhysicsMaterialCombine)2
			};
		}

		private static void Beam(Transform parent, string name, Vector3 a, Vector3 b, float width, Material material, bool collision = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = Child(parent, name, (a + b) * 0.5f);
			obj.localRotation = Quaternion.FromToRotation(Vector3.up, b - a);
			Vector3 zero = Vector3.zero;
			Vector3 val = b - a;
			Cube(obj, "Timber", zero, new Vector3(width, ((Vector3)(ref val)).magnitude, width), material, collision);
		}

		private static void Panel(Transform parent, string name, Vector3 a, Vector3 b, Vector3 c, Vector3 d, Material material, float camber)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)Child(parent, name, Vector3.zero)).gameObject;
			Vector3 val = (a + b + c + d) / 4f + Vector3.up * camber;
			Mesh val2 = new Mesh
			{
				name = name
			};
			Vector3[] source = (Vector3[])(object)new Vector3[5] { a, b, c, d, val };
			Vector3 val3 = Vector3.Cross(b - a, d - a);
			Vector3 normal = ((Vector3)(ref val3)).normalized;
			val2.vertices = source.Select((Vector3 p) => p + normal * 0.006f).Concat(source.Select((Vector3 p) => p - normal * 0.006f)).ToArray();
			val2.uv = (Vector2[])(object)new Vector2[10]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f),
				new Vector2(0.5f, 0.5f),
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f),
				new Vector2(0.5f, 0.5f)
			};
			val2.triangles = new int[24]
			{
				0, 1, 4, 1, 2, 4, 2, 3, 4, 3,
				0, 4, 5, 9, 6, 6, 9, 7, 7, 9,
				8, 8, 9, 5
			};
			val2.colors = Enumerable.Repeat<Color>(Color.white, 10).ToArray();
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			gameObject.AddComponent<MeshFilter>().sharedMesh = val2;
			((Renderer)gameObject.AddComponent<MeshRenderer>()).sharedMaterial = material;
		}

		private static void SetLayer(Transform t, int layer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			((Component)t).gameObject.layer = layer;
			foreach (Transform item in t)
			{
				SetLayer(item, layer);
			}
		}
	}
	internal class AircraftServices : MonoBehaviour
	{
		internal const float MistRadius = 35f;

		internal static readonly Vector3 MistOffset = new Vector3(0f, 0f, 8.2f);

		private Aircraft plane;

		private bool menu;

		private static AircraftServices active;

		private GameObject wisp;

		internal static bool IsOpen
		{
			get
			{
				if (Object.op_Implicit((Object)(object)active))
				{
					return active.menu;
				}
				return false;
			}
		}

		internal Demister Mist { get; private set; }

		private void Awake()
		{
			plane = ((Component)this).GetComponent<Aircraft>();
		}

		internal void Open()
		{
			if (Object.op_Implicit((Object)(object)active) && (Object)(object)active != (Object)(object)this)
			{
				active.menu = false;
			}
			menu = !menu;
			active = this;
		}

		private void Update()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			if (menu && ZInput.GetKeyDown((KeyCode)27, true))
			{
				menu = false;
			}
			Player localPlayer = Player.m_localPlayer;
			if (menu && (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsAttached() || Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position) > 10f))
			{
				menu = false;
			}
			if (!Object.op_Implicit((Object)(object)plane) || !plane.IsValid)
			{
				return;
			}
			ZDO val = CargoLinks.Find(((Component)this).GetComponent<ZNetView>().GetZDO().GetString("skyfarer.cargoLink", ""), cargo: true);
			if (val == null || !val.GetBool("skyfarer.wisp", false) || Object.op_Implicit((Object)(object)wisp))
			{
				return;
			}
			wisp = new GameObject("Bound Skyfarer wisp");
			wisp.transform.SetParent(((Component)this).transform, false);
			wisp.transform.localPosition = new Vector3(0f, 3.6f, 2.4f);
			GameObject prefab = PrefabManager.Instance.GetPrefab("piece_groundtorch_mist");
			Demister val2 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponentInChildren<Demister>(true) : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, wisp.transform, false);
				val3.transform.localPosition = MistOffset;
				val3.SetActive(true);
				Mist = val3.GetComponent<Demister>();
				Mist.m_forceField.endRange = 35f;
				Light obj = wisp.AddComponent<Light>();
				obj.color = new Color(0.25f, 0.7f, 1f);
				obj.intensity = 2f;
				obj.range = 12f;
				GameObject prefab2 = PrefabManager.Instance.GetPrefab("Wisp");
				Transform val4 = (Object.op_Implicit((Object)(object)prefab2) ? prefab2.transform.Find("attach") : null);
				if (Object.op_Implicit((Object)(object)val4))
				{
					GameObject obj2 = Object.Instantiate<GameObject>(((Component)val4).gameObject, wisp.transform, false);
					obj2.transform.localPosition = Vector3.zero;
					Collider[] componentsInChildren = obj2.GetComponentsInChildren<Collider>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						Object.Destroy((Object)(object)componentsInChildren[i]);
					}
				}
			}
			else
			{
				Plugin.Log.LogError((object)"Native wisp torch mist volume was not found.");
				Object.Destroy((Object)(object)wisp);
			}
		}

		private void OnGUI()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (menu)
			{
				float num = (float)(Screen.width - 460) / 2f;
				float num2 = (float)(Screen.height - 260) / 2f;
				GUI.Box(new Rect(num, num2, 460f, 260f), "Skyfarer services");
				GUI.Label(new Rect(num + 20f, num2 + 30f, 420f, 40f), "Place upgrade materials in cargo, then close the chest.\nEach cargo expansion costs 20 Fine wood + 10 Copper.");
				SkyCargo cargo = ((Component)this).GetComponent<CargoHold>().Cargo;
				if (GUI.Button(new Rect(num + 20f, num2 + 80f, 420f, 32f), "Expand cargo: 10 → 20 → 30 slots") && cargo != null)
				{
					((Component)cargo).GetComponent<CargoUpgrades>().Request(wisp: false);
				}
				if (GUI.Button(new Rect(num + 20f, num2 + 120f, 420f, 32f), "Bind 1 Wisp: clear nearby Mistlands mist") && cargo != null)
				{
					((Component)cargo).GetComponent<CargoUpgrades>().Request(wisp: true);
				}
				if (GUI.Button(new Rect(num + 20f, num2 + 160f, 420f, 32f), "Unstuck: lift and level the parked aircraft"))
				{
					plane.RequestUnstuck();
					menu = false;
				}
				if (GUI.Button(new Rect(num + 20f, num2 + 210f, 420f, 30f), "Close"))
				{
					menu = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	internal static class ServiceMenuInput
	{
		private static bool Prefix(ref bool __result)
		{
			if (!AircraftServices.IsOpen)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	internal static class ServiceMenuCursor
	{
		private static void Postfix()
		{
			if (AircraftServices.IsOpen)
			{
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
			}
		}
	}
	internal class CargoHold : MonoBehaviour
	{
		internal const string PrefabName = "Wise_SkyfarerCargo";

		internal static readonly Vector3 Offset = new Vector3(0f, 0.12f, -2.65f);

		private static GameObject prefab;

		private ZNetView view;

		internal SkyCargo Cargo;

		internal static void Register()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			PrefabManager instance = PrefabManager.Instance;
			prefab = instance.CreateClonedPrefab("Wise_SkyfarerCargo", "piece_chest_wood");
			prefab.SetActive(false);
			Object.DestroyImmediate((Object)(object)prefab.GetComponent<WearNTear>());
			Object.DestroyImmediate((Object)(object)prefab.GetComponent<Piece>());
			ZSyncTransform component = prefab.GetComponent<ZSyncTransform>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			ZNetView component2 = prefab.GetComponent<ZNetView>();
			component2.m_persistent = true;
			component2.m_distant = false;
			Container component3 = prefab.GetComponent<Container>();
			component3.m_name = "Skyfarer cargo";
			component3.m_checkGuardStone = false;
			component3.m_privacy = (PrivacySetting)2;
			component3.m_rootObjectOverride = null;
			component3.m_autoDestroyEmpty = false;
			prefab.transform.localScale = Vector3.one * 0.65f;
			Collider[] componentsInChildren = prefab.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].isTrigger = true;
			}
			prefab.AddComponent<SkyCargo>();
			prefab.AddComponent<CargoUpgrades>();
			instance.AddPrefab(new CustomPrefab(prefab, false));
			prefab.SetActive(true);
		}

		private void Awake()
		{
			view = ((Component)this).GetComponent<ZNetView>();
		}

		private void Start()
		{
			((MonoBehaviour)this).InvokeRepeating("EnsureCargo", 0f, 0.5f);
		}

		private void EnsureCargo()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)view) && view.IsValid() && !Object.op_Implicit((Object)(object)Cargo))
			{
				string text = view.GetZDO().GetString("skyfarer.cargoLink", "");
				if (text.Length > 0)
				{
					SyncCargo();
				}
				else if (view.IsOwner())
				{
					GameObject val = Object.Instantiate<GameObject>(prefab, ((Component)this).transform.TransformPoint(Offset), ((Component)this).transform.rotation);
					Cargo = val.GetComponent<SkyCargo>();
					ZNetView component = val.GetComponent<ZNetView>();
					text = Guid.NewGuid().ToString("N");
					component.GetZDO().Set("skyfarer.cargoLink", text);
					view.GetZDO().Set("skyfarer.cargoLink", text);
					CargoLinks.Register(component.GetZDO());
					CargoLinks.Register(view.GetZDO());
					ZDOMan.instance.ForceSendZDO(component.GetZDO().m_uid);
					ZDOMan.instance.ForceSendZDO(view.GetZDO().m_uid);
				}
			}
		}

		private void FixedUpdate()
		{
			SyncCargo();
		}

		private void LateUpdate()
		{
			SyncCargo();
		}

		internal void SyncCargo()
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid())
			{
				return;
			}
			ZDO val = CargoLinks.Find(view.GetZDO().GetString("skyfarer.cargoLink", ""), cargo: true);
			if (val == null)
			{
				return;
			}
			Vector3 val2 = ((Component)this).transform.TransformPoint(Offset);
			val.SetPosition(val2);
			if (val.IsOwner())
			{
				val.SetRotation(((Component)this).transform.rotation);
			}
			if (!Object.op_Implicit((Object)(object)Cargo))
			{
				GameObject val3 = ZNetScene.instance.FindInstance(val.m_uid);
				if (Object.op_Implicit((Object)(object)val3))
				{
					Cargo = val3.GetComponent<SkyCargo>();
				}
			}
			if (Object.op_Implicit((Object)(object)Cargo))
			{
				((Component)Cargo).transform.SetPositionAndRotation(val2, ((Component)this).transform.rotation);
			}
		}
	}
	internal class SkyCargo : MonoBehaviour
	{
		private static readonly Action<Container> DropContents = AccessTools.MethodDelegate<Action<Container>>(AccessTools.Method(typeof(Container), "OnDestroyed", (Type[])null, (Type[])null), (object)null, true);

		private static readonly Func<Container, bool> LoadContents = AccessTools.MethodDelegate<Func<Container, bool>>(AccessTools.Method(typeof(Container), "Load", (Type[])null, (Type[])null), (object)null, true);

		private ZNetView view;

		private ZDOMan manager;

		private bool released;

		private float missingSince = -1f;

		internal Container Container { get; private set; }

		private void Awake()
		{
			view = ((Component)this).GetComponent<ZNetView>();
			Container = ((Component)this).GetComponent<Container>();
			if (view.IsValid())
			{
				manager = ZDOMan.instance;
				ZDOMan obj = manager;
				obj.m_onZDODestroyed = (Action<ZDO>)Delegate.Combine(obj.m_onZDODestroyed, new Action<ZDO>(ParentDestroyed));
			}
		}

		private void OnDestroy()
		{
			if (manager != null)
			{
				ZDOMan obj = manager;
				obj.m_onZDODestroyed = (Action<ZDO>)Delegate.Remove(obj.m_onZDODestroyed, new Action<ZDO>(ParentDestroyed));
			}
		}

		private void LateUpdate()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result