Decompiled source of SurtlingSkyfarer v0.1.5

BepInEx/plugins/Skyfarer/Wise.Skyfarer.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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.5.0")]
[assembly: AssemblyInformationalVersion("0.1.5")]
[assembly: AssemblyProduct("Wise.Skyfarer")]
[assembly: AssemblyTitle("Wise.Skyfarer")]
[assembly: AssemblyVersion("0.1.5.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;

		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 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_00da: 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);
				throttle = StoredThrottle();
				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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: 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_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: 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_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_072c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0701: Unknown result type (might be due to invalid IL or missing references)
			//IL_0711: Unknown result type (might be due to invalid IL or missing references)
			//IL_0716: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: 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_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Unknown result type (might be due to invalid IL or missing references)
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValid || !view.IsOwner())
			{
				wasOwner = false;
				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;
			Vector3 val2 = val * (throttle * 22f);
			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)
			{
				Vector3 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 = 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), "R  reverse on ground     •     Right mouse  brake     •     Space  leave seat", textStyle);
		}
	}
	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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00ec: 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)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: Unknown result type (might be due to invalid IL or missing references)
			//IL_068a: Unknown result type (might be due to invalid IL or missing references)
			//IL_069e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: Unknown result type (might be due to invalid IL or missing references)
			//IL_072f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0756: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: 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_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fa: 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_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: 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_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_083a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0855: Unknown result type (might be due to invalid IL or missing references)
			//IL_0870: Unknown result type (might be due to invalid IL or missing references)
			//IL_088e: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0902: Unknown result type (might be due to invalid IL or missing references)
			//IL_096b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0970: Unknown result type (might be due to invalid IL or missing references)
			//IL_0986: Unknown result type (might be due to invalid IL or missing references)
			//IL_098b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_09bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_09dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b6d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b81: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a61: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bdb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be2: Expected O, but got Unknown
			//IL_0c19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c1f: Expected O, but got Unknown
			//IL_0c2a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c30: Expected O, but got Unknown
			//IL_0c3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c41: Expected O, but got Unknown
			//IL_0c4b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c51: Expected O, but got Unknown
			//IL_0c58: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c62: Expected O, but got Unknown
			//IL_0c76: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c7c: Invalid comparison between Unknown and I4
			//IL_0ad8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0caa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0caf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cbf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cda: 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(wood)
			{
				name = "Skyfarer sailcloth"
			};
			cloth.mainTexture = ((Renderer)val2).sharedMaterial.mainTexture;
			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 i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).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_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 = 1800f;
			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 = true;
			val.GetComponent<ZSyncTransform>().m_syncBodyVelocity = true;
			Transform val3 = Child(val.transform, "Skyfarer airframe", Vector3.zero);
			for (int j = -1; j <= 1; j += 2)
			{
				for (int k = 0; k < 5; k++)
				{
					float num = 1.05f + (float)k * 1.12f;
					float x = num + 1.12f;
					Vector3 a = WingPoint(j, num, trailing: false);
					Vector3 val4 = WingPoint(j, x, trailing: false);
					Vector3 val5 = WingPoint(j, x, trailing: true);
					Vector3 val6 = WingPoint(j, num, trailing: true);
					Panel(val3, "Stitched wing " + j + " " + k, a, val4, val5, val6, (k == 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 (k == 4)
					{
						Beam(val3, "Wingtip rib", val4, val5, 0.07f, wood);
					}
				}
				Beam(val3, "Wing brace", new Vector3((float)j * 1.1f, 0.4f, 0.4f), WingPoint(j, 4.1f, trailing: false), 0.09f, wood);
				Beam(val3, "Aft wing brace", new Vector3((float)j * 1.05f, 0.4f, -1.5f), WingPoint(j, 4.1f, trailing: true), 0.075f, wood);
				((Component)Child(val3, "Wing collision", new Vector3((float)j * 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)j * 0.9f, 0.45f, 1.3f), new Vector3((float)j * 1.05f, 2.65f, 1.6f), 0.12f, wood);
				Panel(val3, "Tailplane", new Vector3(0f, 1.6f, -3.4f), new Vector3((float)j * 2.5f, 1.65f, -4.1f), new Vector3((float)j * 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)j * 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 i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			LODGroup[] componentsInChildren4 = val8.GetComponentsInChildren<LODGroup>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
			}
			Transform val9 = Child(val7, "Propeller", new Vector3(0f, 0f, 0.85f));
			for (int l = 0; l < 4; l++)
			{
				Transform obj3 = Child(val9, "Carved propeller blade", Vector3.zero);
				obj3.localRotation = Quaternion.Euler(0f, 0f, (float)(l * 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>();
			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 m = 0; m < array.Length; m++)
			{
				Transform val10 = Child(val.transform, (m == 0) ? "Pilot seat" : ("Passenger seat " + m), array[m]);
				SkySeat skySeat = ((Component)val10).gameObject.AddComponent<SkySeat>();
				skySeat.Index = m;
				skySeat.Aircraft = aircraft;
				skySeat.AttachPoint = Child(val10, "SkyfarerAttach" + m, 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 i = 0; i < componentsInChildren4.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
				}
				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[m] = 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 i = 0; i < seats.Length; i++)
			{
				SetLayer(((Component)seats[i]).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 num2 = (string.IsNullOrEmpty(environmentVariable) ? 128 : 1024);
				Sprite val12 = RenderManager.Instance.Render(new RenderRequest(val)
				{
					Width = num2,
					Height = num2,
					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_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_001b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_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_0050: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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[] array = (Vector3[])(object)new Vector3[5] { a, b, c, d, val };
			val2.vertices = array.Concat(array).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 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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 = (component2.m_distant = true);
			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>();
			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 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 type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || released)
			{
				return;
			}
			string text = view.GetZDO().GetString("skyfarer.cargoLink", "");
			if (text.Length == 0)
			{
				return;
			}
			ZDO val = CargoLinks.Find(text, cargo: false);
			if (val != null)
			{
				missingSince = -1f;
				GameObject val2 = ZNetScene.instance.FindInstance(val.m_uid);
				Quaternion val3 = (Object.op_Implicit((Object)(object)val2) ? val2.transform.rotation : val.GetRotation());
				Vector3 val4 = (Object.op_Implicit((Object)(object)val2) ? val2.transform.TransformPoint(CargoHold.Offset) : (val.GetPosition() + val3 * CargoHold.Offset));
				((Component)this).transform.SetPositionAndRotation(val4, val3);
				view.GetZDO().SetPosition(val4);
				if (view.IsOwner())
				{
					view.GetZDO().SetRotation(val3);
				}
			}
			else if (ZNet.instance.IsServer())
			{
				if (missingSince < 0f)
				{
					missingSince = Time.time;
				}
				if (Time.time - missingSince > 10f && view.IsOwner())
				{
					Release();
				}
			}
		}

		private void ParentDestroyed(ZDO data)
		{
			if (Object.op_Implicit((Object)(object)view) && view.IsValid() && data.GetPrefab() == StringExtensionMethods.GetStableHashCode("Wise_SurtlingSkyfarer") && data.GetString("skyfarer.cargoLink", "").Length > 0 && data.GetString("skyfarer.cargoLink", "") == view.GetZDO().GetString("skyfarer.cargoLink", "") && view.IsOwner())
			{
				Release();
			}
		}

		private void Release()
		{
			if (!released)
			{
				released = true;
				LoadContents(Container);
				DropContents(Container);
				view.Destroy();
			}
		}
	}
	internal static class CargoLinks
	{
		internal const string Key = "skyfarer.cargoLink";

		private static readonly FieldRef<ZDOMan, Dictionary<ZDOID, ZDO>> Records = AccessTools.FieldRefAccess<ZDOMan, Dictionary<ZDOID, ZDO>>("m_objectsByID");

		private static readonly Dictionary<string, ZDOID> Planes = new Dictionary<string, ZDOID>();

		private static readonly Dictionary<string, ZDOID> Chests = new Dictionary<string, ZDOID>();

		private static ZDOMan manager;

		private static float nextScan;

		private static void ResetSession()
		{
			if (manager != ZDOMan.instance)
			{
				manager = ZDOMan.instance;
				Planes.Clear();
				Chests.Clear();
				nextScan = 0f;
			}
		}

		internal static void Register(ZDO data)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			ResetSession();
			string text = data.GetString("skyfarer.cargoLink", "");
			if (text.Length != 0)
			{
				if (data.GetPrefab() == StringExtensionMethods.GetStableHashCode("Wise_SurtlingSkyfarer"))
				{
					Planes[text] = data.m_uid;
				}
				else if (data.GetPrefab() == StringExtensionMethods.GetStableHashCode("Wise_SkyfarerCargo"))
				{
					Chests[text] = data.m_uid;
				}
			}
		}

		internal static ZDO Find(string link, bool cargo)
		{
			ResetSession();
			if (manager == null || string.IsNullOrEmpty(link))
			{
				return null;
			}
			Dictionary<string, ZDOID> index = (cargo ? Chests : Planes);
			ZDO val = Lookup(index, link, cargo);
			if (val != null)
			{
				return val;
			}
			if (Time.time >= nextScan)
			{
				nextScan = Time.time + 2f;
				foreach (ZDO value in Records.Invoke(manager).Values)
				{
					Register(value);
				}
				val = Lookup(index, link, cargo);
			}
			return val;
		}

		private static ZDO Lookup(Dictionary<string, ZDOID> index, string link, bool cargo)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!index.TryGetValue(link, out var value))
			{
				return null;
			}
			ZDO zDO = manager.GetZDO(value);
			int stableHashCode = StringExtensionMethods.GetStableHashCode(cargo ? "Wise_SkyfarerCargo" : "Wise_SurtlingSkyfarer");
			if (zDO == null || !zDO.IsValid() || zDO.GetPrefab() != stableHashCode || !(zDO.GetString("skyfarer.cargoLink", "") == link))
			{
				return null;
			}
			return zDO;
		}
	}
	internal static class CargoSmoke
	{
		internal static void AddWood(Container container, int count, bool marker = false)
		{
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Wood");
			ItemData val = itemPrefab.GetComponent<ItemDrop>().m_itemData.Clone();
			val.m_dropPrefab = itemPrefab;
			val.m_stack = count;
			if (marker)
			{
				val.m_customData["skyfarer.smoke.cargo"] = "drop-test";
			}
			container.GetInventory().AddItem(val);
		}

		internal static IEnumerator Run(Aircraft plane, Player player, Action<bool, string> check)
		{
			CargoHold hold = ((Component)plane).GetComponent<CargoHold>();
			float deadline = Time.time + 5f;
			while (!Object.op_Implicit((Object)(object)hold.Cargo) && Time.time < deadline)
			{
				yield return null;
			}
			check(Object.op_Implicit((Object)(object)hold.Cargo), "Aircraft creates its persistent cargo chest");
			SkyCargo cargo = hold.Cargo;
			Container container = cargo.Container;
			Inventory inventory = container.GetInventory();
			ZNetView cargoView = ((Component)cargo).GetComponent<ZNetView>();
			ZNetView planeView = ((Component)plane).GetComponent<ZNetView>();
			Container component = PrefabManager.Instance.GetPrefab("piece_chest_wood").GetComponent<Container>();
			check(inventory.GetWidth() == component.m_width && inventory.GetHeight() == component.m_height && inventory.GetWidth() * inventory.GetHeight() == 10, "Cargo has a normal wooden chest's ten slots");
			check(cargoView.GetZDO().m_uid != planeView.GetZDO().m_uid && cargoView.GetZDO().GetString("skyfarer.cargoLink", "").Length == 32 && cargoView.GetZDO().GetString("skyfarer.cargoLink", "") == planeView.GetZDO().GetString("skyfarer.cargoLink", ""), "Cargo and aircraft have separate network IDs and share a stable saved link");
			Collider collider = ((Component)cargo).GetComponentsInChildren<Collider>().First();
			Physics.SyncTransforms();
			Bounds bounds = collider.bounds;
			check(Physics.RaycastAll(((Bounds)(ref bounds)).center + Vector3.right * 2f, Vector3.left, 3f, LayerMask.GetMask(new string[3] { "piece", "Default", "static_solid" })).Any((RaycastHit hit) => (Object)(object)((RaycastHit)(ref hit)).collider == (Object)(object)collider), "Cargo collider is reachable by the game's default interaction ray query");
			AddWood(container, 7);
			check(inventory.CountItems("$item_wood", -1, true) == 7 && cargoView.GetZDO().GetByteArray(ZDOVars.s_items, (byte[])null) != null, "Putting items in cargo writes its persistent inventory");
			Transform transform = ((Component)player).transform;
			Vector3 position = (((Component)player).GetComponent<Rigidbody>().position = ((Component)cargo).transform.position + Vector3.right);
			transform.position = position;
			((Component)player).GetComponent<Rigidbody>().linearVelocity = Vector3.zero;
			Physics.SyncTransforms();
			((Component)player).GetComponent<ZSyncTransform>().SyncNow();
			ZNet.instance.SetReferencePosition(((Component)player).transform.position);
			container.Interact((Humanoid)(object)player, false, false);
			Plugin.Log.LogInfo((object)string.Format("CARGO_UI_OPEN visible={0} inUse={1} open={2} owner={3} distance={4} active={5} cutscene={6} teleport={7} components={8}", InventoryGui.IsVisible(), container.IsInUse(), InventoryGui.instance.IsContainerOpen(), container.IsOwner(), Vector3.Distance(((Component)player).transform.position, ((Component)cargo).transform.position), ((Behaviour)InventoryGui.instance).isActiveAndEnabled, ((Character)player).InCutscene(), ((Character)player).IsTeleporting(), string.Join(",", from c in ((Component)cargo).GetComponents<Component>()
				select ((object)c).GetType().Name)));
			yield return (object)new WaitForSeconds(0.2f);
			Plugin.Log.LogInfo((object)$"CARGO_UI_AFTER visible={InventoryGui.IsVisible()} inUse={container.IsInUse()} open={InventoryGui.instance.IsContainerOpen()} owner={container.IsOwner()} distance={Vector3.Distance(((Component)player).transform.position, ((Component)cargo).transform.position)} active={((Behaviour)InventoryGui.instance).isActiveAndEnabled} cutscene={((Character)player).InCutscene()} teleport={((Character)player).IsTeleporting()}");
			check(InventoryGui.IsVisible() && container.IsInUse(), "Cargo opens in the normal chest inventory UI");
			InventoryGui.instance.Hide();
			container.SetInUse(false);
			long owner = planeView.GetZDO().GetOwner();
			long owner2 = cargoView.GetZDO().GetOwner();
			try
			{
				string[] array = new string[2] { "RPC_RequestOpen", "RPC_RequestStack" };
				foreach (string text in array)
				{
					cargoView.GetZDO().SetOwner(owner2);
					AccessTools.Method(typeof(Container), text, (Type[])null, (Type[])null).Invoke(container, new object[2]
					{
						owner + 789,
						player.GetPlayerID()
					});
					check(cargoView.GetZDO().GetOwner() == owner + 789 && planeView.GetZDO().GetOwner() == owner, text + " transfers only cargo ownership and leaves the pilot's aircraft ownership intact");
				}
			}
			finally
			{
				cargoView.GetZDO().SetOwner(owner2);
			}
			Aircraft doomed = Object.Instantiate<GameObject>(AircraftFactory.Prefab, ((Component)plane).transform.position + Vector3.right * 20f, Quaternion.identity).GetComponent<Aircraft>();
			doomed.Body.isKinematic = true;
			CargoHold doomedHold = ((Component)doomed).GetComponent<CargoHold>();
			deadline = Time.time + 5f;
			while (!Object.op_Implicit((Object)(object)doomedHold.Cargo) && Time.time < deadline)
			{
				yield return null;
			}
			check(Object.op_Implicit((Object)(object)doomedHold.Cargo), "Second aircraft receives a distinct cargo chest");
			SkyCargo droppedCargo = doomedHold.Cargo;
			AddWood(droppedCargo.Container, 3, marker: true);
			((Component)doomed).GetComponent<WearNTear>().Remove(false);
			yield return (object)new WaitForSeconds(1.5f);
			check(!Object.op_Implicit((Object)(object)doomed) && !Object.op_Implicit((Object)(object)droppedCargo) && Object.FindObjectsByType<ItemDrop>((FindObjectsSortMode)0).Any((ItemDrop drop) => drop.m_itemData.m_stack == 3 && drop.m_itemData.m_customData.ContainsKey("skyfarer.smoke.cargo")), "Hammer removal drops stored cargo and removes the linked chest");
		}

		internal static IEnumerator Reload(Aircraft plane, Action<bool, string> check)
		{
			CargoHold hold = ((Component)plane).GetComponent<CargoHold>();
			float deadline = Time.time + 8f;
			while ((!Object.op_Implicit((Object)(object)hold.Cargo) || hold.Cargo.Container.GetInventory().CountItems("$item_wood", -1, true) != 7) && Time.time < deadline)
			{
				yield return null;
			}
			check(Object.op_Implicit((Object)(object)hold.Cargo) && hold.Cargo.Container.GetInventory().CountItems("$item_wood", -1, true) == 7, "Cargo contents survive a full game restart and world reload");
			check(Object.FindObjectsByType<SkyCargo>((FindObjectsSortMode)0).Count((SkyCargo c) => ((Component)c).GetComponent<ZNetView>().GetZDO().GetString("skyfarer.cargoLink", "") == ((Component)plane).GetComponent<ZNetView>().GetZDO().GetString("skyfarer.cargoLink", "")) == 1, "Reload reconnects the existing cargo chest without creating a duplicate");
			check(Vector3.Distance(((Component)hold.Cargo).transform.position, ((Component)plane).transform.TransformPoint(CargoHold.Offset)) < 0.5f, "Reloaded cargo follows its aircraft after world object IDs change");
		}
	}
	internal static class Commands
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__0_0;

			public static ConsoleEvent <>9__0_1;

			internal void <Register>b__0_0(ConsoleEventArgs args)
			{
				args.Context.AddString("Surtling Skyfarer — one pilot + four passenger seats.\nHammer > Transport near a workbench: 80 fine wood, 30 iron, 20 deer hide, 8 Surtling cores.\nShift/Ctrl throttle, W/S nose down/up, A/D roll, Q/E rudder, R reverse on ground, right mouse wheel brakes, Space leave seat.\nHold W/S for loops and A/D for rolls; release to hold attitude. Only Space exits the helm.\nThrottle stays set when you release the keys or leave the helm.\nLocal testing: devcommands, confirmcheats (if requested), then skyfarer_spawn.");
			}

			internal void <Register>b__0_1(ConsoleEventArgs args)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: 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_0097: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: 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_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				Player localPlayer = Player.m_localPlayer;
				if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer() || ZNet.instance.GetPeers().Count != 0)
				{
					args.Context.AddString("Use this test command in a local single-player world.");
					return;
				}
				Vector3 val = Vector3.ProjectOnPlane(((Component)localPlayer).transform.forward, Vector3.up);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 val2 = ((Component)localPlayer).transform.position + normalized * 10f + Vector3.up * 2f;
				RaycastHit val3 = default(RaycastHit);
				if (Physics.Raycast(val2 + Vector3.up * 15f, Vector3.down, ref val3, 50f, LayerMask.GetMask(new string[3] { "terrain", "static_solid", "piece" }), (QueryTriggerInteraction)1))
				{
					val2.y = ((RaycastHit)(ref val3)).point.y + 1.7f;
				}
				Object.Instantiate<GameObject>(AircraftFactory.Prefab, val2, Quaternion.LookRotation(normalized)).GetComponent<Piece>().SetCreator(localPlayer.GetPlayerID(), ((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID);
				args.Context.AddString("Skyfarer spawned. Board using the port ladder; E on the front chair to pilot.\nHold Shift to increase throttle, then S to lift off. Ctrl reduces throttle; W lowers the nose. Four passenger seats sit behind the pilot.");
			}
		}

		internal static void Register()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_006c: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					args.Context.AddString("Surtling Skyfarer — one pilot + four passenger seats.\nHammer > Transport near a workbench: 80 fine wood, 30 iron, 20 deer hide, 8 Surtling cores.\nShift/Ctrl throttle, W/S nose down/up, A/D roll, Q/E rudder, R reverse on ground, right mouse wheel brakes, Space leave seat.\nHold W/S for loops and A/D for rolls; release to hold attitude. Only Space exits the helm.\nThrottle stays set when you release the keys or leave the helm.\nLocal testing: devcommands, confirmcheats (if requested), then skyfarer_spawn.");
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("skyfarer", "Show Skyfarer controls and test instructions", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				ConsoleEvent val2 = delegate(ConsoleEventArgs args)
				{
					//IL_004e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0053: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_0061: Unknown result type (might be due to invalid IL or missing references)
					//IL_0066: Unknown result type (might be due to invalid IL or missing references)
					//IL_006d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0072: Unknown result type (might be due to invalid IL or missing references)
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0082: 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_0097: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ac: Unkn