Decompiled source of UtilityDrone v0.2.7

UtilityDrone/utilitydrone.dll

Decompiled 12 hours 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.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using DigitalRuby.ThunderAndLightning;
using Dissonance;
using Dissonance.Audio.Capture;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NAudio.Wave;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UtilityDrone")]
[assembly: AssemblyProduct("UtilityDrone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.7.0")]
[assembly: AssemblyInformationalVersion("0.2.7")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 UtilityDrone
{
	[HarmonyPatch(typeof(GrabbableObject), "LoadItemSaveData")]
	internal static class BatteryLoadPatch
	{
		[HarmonyPostfix]
		private static void Postfix(GrabbableObject __instance, int saveData)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			DroneMarker component = ((Component)__instance).GetComponent<DroneMarker>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.StoredCharge = Mathf.Clamp01(ShotgunRules.Charge(saveData));
				__instance.insertedBattery = new Battery(component.StoredCharge <= 0f, component.StoredCharge);
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject), "GetItemDataToSave")]
	internal static class BatterySavePatch
	{
		[HarmonyPostfix]
		private static void Postfix(GrabbableObject __instance, ref int __result)
		{
			if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<DroneMarker>()))
			{
				__result = ShotgunRules.Save(__instance.insertedBattery?.charge ?? 1f, 0);
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject), "Start")]
	internal static class BatteryStartPatch
	{
		[HarmonyPostfix]
		private static void Postfix(GrabbableObject __instance)
		{
			DroneItem.InitializeBattery(__instance);
		}
	}
	internal sealed class BatteryWarning
	{
		private bool wasLow;

		private double next;

		internal static bool Low(bool powered, float charge)
		{
			if (powered && Rules.Finite(charge) && charge > 0f)
			{
				return charge <= 0.1f;
			}
			return false;
		}

		internal bool Due(bool powered, float charge, double now)
		{
			if (!Low(powered, charge))
			{
				Reset();
				return false;
			}
			if (wasLow && now < next)
			{
				return false;
			}
			wasLow = true;
			next = now + 5.0;
			return true;
		}

		internal void Reset()
		{
			wasLow = false;
			next = 0.0;
		}
	}
	internal static class CargoMass
	{
		internal static float Total(IEnumerable<ulong> roots, Func<ulong, float> pounds, Func<ulong, IEnumerable<ulong>> contents)
		{
			HashSet<ulong> hashSet = new HashSet<ulong>();
			Stack<ulong> stack = new Stack<ulong>(roots);
			float num = 0f;
			while (stack.Count > 0)
			{
				ulong num2 = stack.Pop();
				if (!hashSet.Add(num2))
				{
					continue;
				}
				num = Math.Min(100000f, num + pounds(num2));
				foreach (ulong item in contents(num2))
				{
					stack.Push(item);
				}
			}
			return num;
		}
	}
	internal sealed class CargoViewers
	{
		private readonly Dictionary<(ulong drone, ulong client), double> viewers = new Dictionary<(ulong, ulong), double>();

		internal void Set(ulong drone, ulong client, bool open, double now)
		{
			if (open)
			{
				viewers[(drone, client)] = now + 2.0;
			}
			else
			{
				viewers.Remove((drone, client));
			}
		}

		internal bool IsOpen(ulong drone, double now)
		{
			return viewers.Any((KeyValuePair<(ulong drone, ulong client), double> v) => v.Key.drone == drone && v.Value > now);
		}

		internal void Prune(double now, Func<ulong, ulong, bool> valid)
		{
			(ulong, ulong)[] array = (from v in viewers
				where v.Value <= now || !valid(v.Key.drone, v.Key.client)
				select v.Key).ToArray();
			foreach ((ulong, ulong) key in array)
			{
				viewers.Remove(key);
			}
		}

		internal void Disconnect(ulong client)
		{
			(ulong, ulong)[] array = viewers.Keys.Where(((ulong drone, ulong client) k) => k.client == client).ToArray();
			foreach ((ulong, ulong) key in array)
			{
				viewers.Remove(key);
			}
		}

		internal void Clear()
		{
			viewers.Clear();
		}
	}
	internal sealed class CargoVisuals
	{
		private sealed class Saved
		{
			internal GrabbableObject Item;

			internal bool Grabbable;

			internal bool Enemies;

			internal (Rigidbody body, bool kinematic, bool gravity)[] Bodies = Array.Empty<(Rigidbody, bool, bool)>();

			internal (Renderer renderer, bool on)[] Renderers = Array.Empty<(Renderer, bool)>();

			internal (Collider collider, bool on)[] Colliders = Array.Empty<(Collider, bool)>();
		}

		private readonly Dictionary<ulong, Saved> hidden = new Dictionary<ulong, Saved>();

		internal void Refresh(IEnumerable<ulong> ids, Func<ulong, GrabbableObject?> find)
		{
			HashSet<ulong> wanted = new HashSet<ulong>(ids);
			foreach (Saved value in hidden.Values)
			{
				if (Object.op_Implicit((Object)(object)value.Item))
				{
					value.Item.grabbable = (value.Item.grabbableToEnemies = false);
				}
				(Renderer, bool)[] renderers = value.Renderers;
				for (int i = 0; i < renderers.Length; i++)
				{
					(Renderer, bool) tuple = renderers[i];
					if (Object.op_Implicit((Object)(object)tuple.Item1))
					{
						tuple.Item1.enabled = false;
					}
				}
				(Collider, bool)[] colliders = value.Colliders;
				for (int j = 0; j < colliders.Length; j++)
				{
					(Collider, bool) tuple2 = colliders[j];
					if (Object.op_Implicit((Object)(object)tuple2.Item1))
					{
						tuple2.Item1.enabled = false;
					}
				}
			}
			ulong[] array = hidden.Keys.Where((ulong item) => !wanted.Contains(item)).ToArray();
			foreach (ulong id in array)
			{
				Restore(id);
			}
			foreach (ulong item in wanted)
			{
				if (hidden.ContainsKey(item))
				{
					continue;
				}
				GrabbableObject val = find(item);
				if (Object.op_Implicit((Object)(object)val))
				{
					Saved saved = new Saved
					{
						Item = val,
						Grabbable = val.grabbable,
						Enemies = val.grabbableToEnemies,
						Bodies = (from b in ((Component)val).GetComponentsInChildren<Rigidbody>(true)
							select (b: b, isKinematic: b.isKinematic, useGravity: b.useGravity)).ToArray(),
						Renderers = (from r in ((Component)val).GetComponentsInChildren<Renderer>(true)
							select (r: r, enabled: r.enabled)).ToArray(),
						Colliders = (from c in ((Component)val).GetComponentsInChildren<Collider>(true)
							select (c: c, enabled: c.enabled)).ToArray()
					};
					hidden[item] = saved;
					val.grabbable = (val.grabbableToEnemies = false);
					(Rigidbody, bool, bool)[] bodies = saved.Bodies;
					for (int num2 = 0; num2 < bodies.Length; num2++)
					{
						(Rigidbody, bool, bool) tuple3 = bodies[num2];
						tuple3.Item1.isKinematic = true;
						tuple3.Item1.useGravity = false;
					}
					(Renderer, bool)[] renderers2 = saved.Renderers;
					for (int num3 = 0; num3 < renderers2.Length; num3++)
					{
						renderers2[num3].Item1.enabled = false;
					}
					(Collider, bool)[] colliders2 = saved.Colliders;
					for (int num4 = 0; num4 < colliders2.Length; num4++)
					{
						colliders2[num4].Item1.enabled = false;
					}
				}
			}
		}

		internal void Restore(ulong id)
		{
			if (!hidden.TryGetValue(id, out Saved value))
			{
				return;
			}
			hidden.Remove(id);
			if (Object.op_Implicit((Object)(object)value.Item))
			{
				value.Item.grabbable = value.Grabbable;
				value.Item.grabbableToEnemies = value.Enemies;
			}
			(Rigidbody, bool, bool)[] bodies = value.Bodies;
			for (int i = 0; i < bodies.Length; i++)
			{
				(Rigidbody, bool, bool) tuple = bodies[i];
				if (Object.op_Implicit((Object)(object)tuple.Item1))
				{
					tuple.Item1.isKinematic = tuple.Item2;
					tuple.Item1.useGravity = tuple.Item3;
				}
			}
			(Renderer, bool)[] renderers = value.Renderers;
			for (int j = 0; j < renderers.Length; j++)
			{
				(Renderer, bool) tuple2 = renderers[j];
				if (Object.op_Implicit((Object)(object)tuple2.Item1))
				{
					tuple2.Item1.enabled = tuple2.Item2;
				}
			}
			(Collider, bool)[] colliders = value.Colliders;
			for (int k = 0; k < colliders.Length; k++)
			{
				(Collider, bool) tuple3 = colliders[k];
				if (Object.op_Implicit((Object)(object)tuple3.Item1))
				{
					tuple3.Item1.enabled = tuple3.Item2;
				}
			}
		}

		internal void Clear()
		{
			ulong[] array = hidden.Keys.ToArray();
			foreach (ulong id in array)
			{
				Restore(id);
			}
		}
	}
	[Serializable]
	internal sealed class Command
	{
		public int Op;

		public int Mode;

		public uint Modules;

		public ulong Drone;

		public ulong Item;

		public uint Seq;

		public uint Token;

		public float X;

		public float Y;

		public float Z;

		public float Yaw;

		public float Pitch;

		public bool Fire;

		public bool Lamp;

		public bool Boost;
	}
	[HarmonyPatch(typeof(GrabbableObject), "UseItemOnClient")]
	internal static class DeployPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(GrabbableObject __instance, bool buttonDown)
		{
			if (Plugin.Instance.Storage.Active || Plugin.Instance.DockUI.Active)
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<DroneMarker>()))
			{
				return true;
			}
			return false;
		}
	}
	internal static class DockingRules
	{
		internal const float ChargePerSecond = 0.01f;

		internal const float ReturnHeight = 13.716001f;

		internal const float ReturnSpeed = 3f;

		internal const float LocalRecallRange = 5f;

		internal const float ReturnDescentSpeed = 1.5f;

		internal const float DockTurnSpeed = 45f;

		internal const float LandingSpeed = 0.125f;

		internal static int LocalReturnLeg(bool inShip, bool inFacility, float distanceToShip)
		{
			if (!inFacility)
			{
				if (!inShip)
				{
					if (!Rules.Finite(distanceToShip) || !(distanceToShip >= 0f) || !(distanceToShip <= 5f))
					{
						return -1;
					}
					return 0;
				}
				return 2;
			}
			return -1;
		}

		internal static float Recharge(float charge, float elapsed)
		{
			return Math.Min(1f, Rules.MeterFraction(charge) + (Rules.Finite(elapsed) ? Math.Max(0f, elapsed) : 0f) * 0.01f);
		}

		internal static bool FinishedCharging(float before, float after)
		{
			if (Rules.Finite(before) && Rules.Finite(after) && before >= 0f && before < 1f)
			{
				return after >= 1f;
			}
			return false;
		}

		internal static bool CanLaunch(bool docked, bool returning, float charge)
		{
			if (docked && !returning && Rules.Finite(charge))
			{
				return charge >= 1f;
			}
			return false;
		}

		internal static int ChargeSecondsLeft(float charge)
		{
			return (int)Math.Ceiling((1.0 - (double)Rules.MeterFraction(charge)) / 0.009999999776482582 - 1E-05);
		}
	}
	internal sealed class DockingSystem
	{
		private StartOfRound? round;

		private DroneStationMarker? station;

		private DroneStationMarker? groundedStation;

		private float readyAt;

		private float nextEnsure;

		private float nextRepair;

		private float nextError;

		private bool migrationChecked;

		private ulong stationId = ulong.MaxValue;

		private Vector3 stationOffset;

		private Vector3 stationRotation;

		private ulong appliedStation = ulong.MaxValue;

		private Vector3 appliedOffset;

		private Vector3 appliedRotation;

		private readonly Dictionary<ulong, int> returnLegs = new Dictionary<ulong, int>();

		internal bool Available
		{
			get
			{
				if (Object.op_Implicit((Object)(object)station) && !DroneStation.Item.inStorage)
				{
					return !DroneStation.IsBeingMoved(((Component)station).GetComponent<PlaceableShipObject>());
				}
				return false;
			}
		}

		internal ulong StationId
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)station))
				{
					return ulong.MaxValue;
				}
				return ((Component)station).GetComponent<NetworkObject>().NetworkObjectId;
			}
		}

		internal Vector3 Offset
		{
			get
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)station))
				{
					return Vector3.zero;
				}
				return ((Component)station).GetComponent<AutoParentToShip>().positionOffset;
			}
		}

		internal Vector3 Rotation
		{
			get
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)station))
				{
					return Vector3.zero;
				}
				return ((Component)station).GetComponent<AutoParentToShip>().rotationOffset;
			}
		}

		internal Vector3 DockPosition
		{
			get
			{
				//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_000d: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)station))
				{
					return Vector3.zero;
				}
				return ((Component)station).transform.TransformPoint(StationModel.DockOffset);
			}
		}

		internal Vector3 LaunchPosition
		{
			get
			{
				//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_0012: 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_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				Vector3 dockPosition = DockPosition;
				Bounds bounds = round.shipInnerRoomBounds.bounds;
				float num = ((Bounds)(ref bounds)).max.y - 0.05f - dockPosition.y - DroneModel.TopHeight;
				return dockPosition + Vector3.up * Mathf.Clamp(num, 0f, 0.3f);
			}
		}

		internal float DockYaw
		{
			get
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)station))
				{
					return 0f;
				}
				return ((Component)station).transform.eulerAngles.y;
			}
		}

		internal void ItemsLoaded()
		{
			round = StartOfRound.Instance;
			readyAt = Time.unscaledTime + 1f;
		}

		internal void Receive(ulong id, Vector3 offset, Vector3 rotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			stationId = id;
			stationOffset = offset;
			stationRotation = rotation;
		}

		internal void Tick(Plugin plugin)
		{
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Expected O, but got Unknown
			StartOfRound instance = StartOfRound.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.elevatorTransform) || !Object.op_Implicit((Object)(object)instance.shipInnerRoomBounds) || !Object.op_Implicit((Object)(object)NetworkManager.Singleton))
			{
				return;
			}
			if ((Object)(object)round != (Object)(object)instance)
			{
				round = instance;
				station = null;
				groundedStation = null;
				appliedStation = ulong.MaxValue;
				migrationChecked = false;
				readyAt = Time.unscaledTime + 4f;
				nextEnsure = (nextRepair = 0f);
			}
			try
			{
				if (Time.unscaledTime < nextEnsure)
				{
					return;
				}
				nextEnsure = Time.unscaledTime + 0.25f;
				DroneStation.ApplyPrice(plugin.StorePrice);
				DroneStationMarker droneStationMarker = (plugin.Server ? DroneStation.Find() : ((stationId != ulong.MaxValue) ? DroneStation.Find(stationId) : null));
				station = droneStationMarker;
				if (Object.op_Implicit((Object)(object)station))
				{
					station.UpdateConsole(plugin);
					DroneState droneState = plugin.Fleet.Values.OrderBy((DroneState s) => s.Id).FirstOrDefault();
					if (droneState != null)
					{
						station.UpdateBatteryMeter(droneState.Charge);
					}
				}
				if (!plugin.Server)
				{
					if (Object.op_Implicit((Object)(object)station))
					{
						AutoParentToShip component = ((Component)station).GetComponent<AutoParentToShip>();
						if (!DroneStation.IsBeingMoved(((Component)station).GetComponent<PlaceableShipObject>()) && (appliedStation != stationId || appliedOffset != stationOffset || appliedRotation != stationRotation))
						{
							component.overrideOffset = true;
							component.positionOffset = stationOffset;
							component.rotationOffset = stationRotation;
							component.disableObject = false;
							component.MoveToOffset();
							appliedStation = stationId;
							appliedOffset = stationOffset;
							appliedRotation = stationRotation;
						}
						DroneStation.Item.inStorage = false;
						DroneStation.RestoreVisibleReplica(station);
					}
				}
				else
				{
					if (Time.unscaledTime < readyAt || !Object.op_Implicit((Object)(object)GameNetworkManager.Instance) || !Object.op_Implicit((Object)(object)plugin.Local))
					{
						return;
					}
					plugin.Appearance.Load(plugin);
					NetworkObject[] array = (from n in NetworkManager.Singleton.SpawnManager.SpawnedObjects.Values
						where Object.op_Implicit((Object)(object)n) && n.IsSpawned && Object.op_Implicit((Object)(object)((Component)n).GetComponent<DroneMarker>())
						orderby n.NetworkObjectId
						select n).ToArray();
					if (!migrationChecked && DroneStation.ResolveItem() >= 0)
					{
						string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
						if (!ES3.Load<bool>("UtilityDrone.StationMigrationV1", currentSaveFileName, false))
						{
							if (array.Length != 0 && !DroneStation.IsOwned)
							{
								DroneStation.Item.hasBeenUnlockedByPlayer = true;
								Plugin.Tip("Existing utility drone converted to a drone station upgrade.");
							}
							ES3.Save<bool>("UtilityDrone.StationMigrationV1", true, currentSaveFileName);
						}
						migrationChecked = true;
					}
					if (!DroneStation.IsOwned)
					{
						return;
					}
					if (!Object.op_Implicit((Object)(object)station))
					{
						if (!(Time.unscaledTime >= nextRepair))
						{
							return;
						}
						nextRepair = Time.unscaledTime + 3f;
						DroneStation.Configure();
						int num = DroneStation.ResolveItem();
						if (num >= 0)
						{
							if (instance.SpawnedShipUnlockables.TryGetValue(num, out var value) && !Object.op_Implicit((Object)(object)value))
							{
								instance.SpawnedShipUnlockables.Remove(num);
							}
							AccessTools.Method(typeof(StartOfRound), "SpawnUnlockable", (Type[])null, (Type[])null).Invoke(instance, new object[2] { num, true });
						}
						return;
					}
					DroneStation.RestoreVisibleReplica(station);
					if ((Object)(object)groundedStation != (Object)(object)station && GroundLegacyStation(plugin))
					{
						groundedStation = station;
					}
					if (array.Length != 0)
					{
						foreach (NetworkObject item in array.Skip(1))
						{
							plugin.ReleaseDuplicateCargo(item.NetworkObjectId);
							item.Despawn(true);
						}
						return;
					}
					GameObject obj = Object.Instantiate<GameObject>(DroneItem.Prefab, DockPosition, Quaternion.Euler(0f, DockYaw, 0f), instance.propsContainer);
					obj.SetActive(true);
					GrabbableObject component2 = obj.GetComponent<GrabbableObject>();
					component2.grabbable = (component2.grabbableToEnemies = false);
					component2.isInShipRoom = (component2.isInElevator = true);
					component2.insertedBattery = new Battery(false, 1f);
					obj.GetComponent<NetworkObject>().Spawn(false);
				}
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime >= nextError)
				{
					nextError = Time.unscaledTime + 10f;
					plugin.Report("Drone station initialization failed; retrying", ex);
				}
			}
		}

		private bool GroundLegacyStation(Plugin plugin)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			ShipBuildModeManager instance = ShipBuildModeManager.Instance;
			if (!Object.op_Implicit((Object)(object)station) || !Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)plugin.Local) || round.shipIsLeaving || (!round.inShipPhase && !round.shipHasLanded))
			{
				return false;
			}
			PlaceableShipObject component = ((Component)station).GetComponent<PlaceableShipObject>();
			if (component.inUse || instance.InBuildMode)
			{
				return false;
			}
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(((Component)station).transform.position + Vector3.up * 0.3f, Vector3.down, ref val, 4f, LayerMask.GetMask(new string[2] { "Room", "Colliders" }), (QueryTriggerInteraction)1))
			{
				return false;
			}
			float num = ((Component)station).transform.position.y - ((RaycastHit)(ref val)).point.y;
			if (num >= -0.02f && num <= 0.15f)
			{
				Vector3 val2 = ((Component)station).transform.position + ((Component)station).transform.rotation * StationModel.ModelOrigin;
				val2.y = ((RaycastHit)(ref val)).point.y + StationModel.FloorOffset;
				Vector3 eulerAngles = ((Component)station).transform.eulerAngles;
				instance.PlaceShipObject(val2, eulerAngles, component, false);
				instance.PlaceShipObjectServerRpc(val2, eulerAngles, new NetworkObjectReference(((Component)station).GetComponent<NetworkObject>()), (int)plugin.Local.playerClientId);
			}
			return true;
		}

		internal void AddToSnapshot(Fleet snapshot)
		{
			//IL_000e: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			snapshot.StationId = StationId;
			snapshot.StationOffset = Offset;
			snapshot.StationRotation = Rotation;
		}

		internal void StartReturn(DroneState state)
		{
			state.Docked = false;
			state.Returning = true;
			state.Deployed = true;
			state.Pitch = 0f;
			state.Epoch++;
			returnLegs[state.Id] = -1;
			if (Available)
			{
				InitializeReturnRoute(state);
			}
		}

		private int InitializeReturnRoute(DroneState state)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = round.shipInnerRoomBounds.bounds;
			int num = DockingRules.LocalReturnLeg(((Bounds)(ref bounds)).Contains(state.Position), state.Inside, Vector3.Distance(state.Position, ((Bounds)(ref bounds)).ClosestPoint(state.Position)));
			if (num < 0)
			{
				state.Position = RecallSpawnPoint();
				num = 0;
			}
			state.Inside = false;
			returnLegs[state.Id] = num;
			return num;
		}

		private Vector3 RecallSpawnPoint()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Vector3 result = EntrancePoint(inside: false);
			Bounds bounds = round.shipInnerRoomBounds.bounds;
			result.y = ((Bounds)(ref bounds)).max.y + 13.716001f;
			return result;
		}

		private Vector3 EntrancePoint(bool inside)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0035: 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_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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = round.shipInnerRoomBounds.bounds;
			Vector3 val = (Object.op_Implicit((Object)(object)round.shipDoorNode) ? round.shipDoorNode.position : (((Bounds)(ref bounds)).center - round.elevatorTransform.forward * ((Bounds)(ref bounds)).extents.z));
			Vector3 val2 = ((Bounds)(ref bounds)).center - val;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
			{
				val2 = round.elevatorTransform.forward;
			}
			((Vector3)(ref val2)).Normalize();
			Vector3 result = val + val2 * (inside ? 1.4f : (-2f));
			result.y = Mathf.Clamp(DockPosition.y + 0.2f, ((Bounds)(ref bounds)).min.y + 0.7f, ((Bounds)(ref bounds)).max.y - 0.4f);
			return result;
		}

		internal void StepReturn(DroneState state, float dt)
		{
			//IL_0063: 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_0069: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_00a0: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			if (!Available)
			{
				return;
			}
			int value;
			int num = (returnLegs.TryGetValue(state.Id, out value) ? value : (-1));
			if (num < 0)
			{
				num = InitializeReturnRoute(state);
				state.Epoch++;
			}
			Vector3 val = ((num == 0) ? EntrancePoint(inside: false) : ((num == 1) ? EntrancePoint(inside: true) : ((num < 4) ? LaunchPosition : DockPosition)));
			Vector3 val2 = val - state.Position;
			if (num >= 3)
			{
				state.Yaw = Mathf.MoveTowardsAngle(state.Yaw, DockYaw, dt * 45f);
			}
			else
			{
				Vector2 val3 = new Vector2(val2.x, val2.z);
				if (((Vector2)(ref val3)).sqrMagnitude > 0.01f)
				{
					state.Yaw = Mathf.MoveTowardsAngle(state.Yaw, Mathf.Atan2(val2.x, val2.z) * 57.29578f, dt * 120f);
				}
			}
			state.Position = Vector3.MoveTowards(state.Position, val, num switch
			{
				0 => 1.5f, 
				4 => 0.125f, 
				_ => 3f, 
			} * dt);
			state.Inside = false;
			Vector3 val4 = state.Position - val;
			if (!(((Vector3)(ref val4)).sqrMagnitude <= 1E-06f))
			{
				return;
			}
			if (num == 3)
			{
				if (Mathf.Abs(Mathf.DeltaAngle(state.Yaw, DockYaw)) <= 0.01f)
				{
					returnLegs[state.Id] = 4;
				}
			}
			else if (num < 4)
			{
				returnLegs[state.Id] = num + 1;
			}
			else if (Mathf.Abs(Mathf.DeltaAngle(state.Yaw, DockYaw)) <= 0.01f)
			{
				Dock(state);
			}
		}

		internal void Dock(DroneState state)
		{
			//IL_0048: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)round))
			{
				bool num = state.Returning && Available;
				Vector3 position;
				if (!Object.op_Implicit((Object)(object)station))
				{
					Bounds bounds = round.shipInnerRoomBounds.bounds;
					position = ((Bounds)(ref bounds)).center;
				}
				else
				{
					position = DockPosition;
				}
				state.Position = position;
				state.Yaw = DockYaw;
				state.Pitch = 0f;
				state.Docked = true;
				state.Returning = false;
				state.Deployed = false;
				state.Inside = false;
				state.Epoch++;
				returnLegs.Remove(state.Id);
				if (num)
				{
					Plugin.Instance.NotifyDocked(StationId);
				}
			}
		}

		internal void StepCharge(DroneState state, float dt)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_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)
			if (!Object.op_Implicit((Object)(object)round))
			{
				return;
			}
			Vector3 position;
			if (!Object.op_Implicit((Object)(object)station))
			{
				Bounds bounds = round.shipInnerRoomBounds.bounds;
				position = ((Bounds)(ref bounds)).center;
			}
			else
			{
				position = DockPosition;
			}
			state.Position = position;
			state.Yaw = DockYaw;
			state.Pitch = 0f;
			state.Inside = false;
			if (Available)
			{
				float charge = state.Charge;
				state.Charge = DockingRules.Recharge(state.Charge, dt);
				if (DockingRules.FinishedCharging(charge, state.Charge))
				{
					Plugin.Instance.NotifyCharged(StationId);
				}
			}
		}

		internal void Reset()
		{
			round = null;
			station = null;
			groundedStation = null;
			stationId = ulong.MaxValue;
			migrationChecked = false;
			appliedStation = ulong.MaxValue;
			returnLegs.Clear();
			nextEnsure = (nextRepair = (readyAt = 0f));
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
	internal static class DroneStationItemsLoadedPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			Plugin.Instance.Docking.ItemsLoaded();
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
	internal static class DroneDepartureDockPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static void Prefix()
		{
			Plugin.Instance.DockForDeparture();
		}
	}
	internal sealed class DockManagementUI
	{
		private readonly Plugin plugin;

		private DroneStationMarker? station;

		private bool opened;

		private PlayerControllerB? player;

		private readonly Dictionary<string, bool> flags = new Dictionary<string, bool>();

		private CursorLockMode cursorLock;

		private bool cursorVisible;

		private uint draftBody = 16777216u;

		private uint draftChassis = 16777216u;

		private uint draftModules;

		private bool pending;

		private float pendingUntil;

		private float nextApply;

		private float nextRecall;

		private string paintStatus = "";

		private static readonly uint[] Presets = new uint[8] { 3689003u, 921871u, 7567995u, 13093306u, 9387057u, 3562892u, 12089136u, 7494021u };

		private Font? font;

		private GUIStyle? heading;

		private GUIStyle? text;

		private GUIStyle? small;

		private GUIStyle? button;

		private GUIStyle? dockWarning;

		private static readonly Color Green = new Color(0.66f, 0.88f, 0.66f);

		private static readonly Color Dim = new Color(0.38f, 0.49f, 0.39f);

		private static readonly Color Line = new Color(0.24f, 0.36f, 0.27f);

		private static readonly Color Amber = new Color(0.88f, 0.62f, 0.29f);

		internal bool Active => opened;

		internal DockManagementUI(Plugin plugin)
		{
			this.plugin = plugin;
		}

		internal bool CanOpen(DroneStationMarker target, PlayerControllerB? local)
		{
			ShipBuildModeManager instance = ShipBuildModeManager.Instance;
			if (Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)local) && (Object)(object)local == (Object)(object)plugin.Local && !local.isPlayerDead && !local.inTerminalMenu && !local.isTypingChat && !local.quickMenuManager.isMenuOpen && !plugin.View.Active && !plugin.Storage.Active && !Active && (!Object.op_Implicit((Object)(object)instance) || !instance.InBuildMode))
			{
				return !DroneStation.IsBeingMoved(((Component)target).GetComponent<PlaceableShipObject>());
			}
			return false;
		}

		internal void Open(DroneStationMarker target, PlayerControllerB local)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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)
			if (!CanOpen(target, local))
			{
				return;
			}
			BoxCollider component = ((Component)target).GetComponent<BoxCollider>();
			if (Vector3.Distance(((Component)local.gameplayCamera).transform.position, ((Collider)component).ClosestPoint(((Component)local.gameplayCamera).transform.position)) > 3f)
			{
				return;
			}
			station = target;
			player = local;
			opened = true;
			draftBody = plugin.Appearance.Body;
			draftChassis = plugin.Appearance.Chassis;
			draftModules = plugin.Appearance.Modules;
			pending = false;
			paintStatus = "Choose modules and colors, then apply to save.";
			cursorLock = Cursor.lockState;
			cursorVisible = Cursor.visible;
			string[] array = new string[2] { "disableMoveInput", "disableLookInput" };
			foreach (string text in array)
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerControllerB), text);
				if (!(fieldInfo == null))
				{
					flags[text] = (bool)fieldInfo.GetValue(local);
					fieldInfo.SetValue(local, true);
				}
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		internal void Tick()
		{
			//IL_00ce: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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)
			if (!Active)
			{
				return;
			}
			ShipBuildModeManager instance = ShipBuildModeManager.Instance;
			bool flag = !Object.op_Implicit((Object)(object)station) || !((Component)station).gameObject.activeInHierarchy || !Object.op_Implicit((Object)(object)player) || (Object)(object)player != (Object)(object)plugin.Local || player.isPlayerDead || player.inTerminalMenu || plugin.View.Active || player.quickMenuManager.isMenuOpen || (Object.op_Implicit((Object)(object)instance) && instance.InBuildMode) || DroneStation.IsBeingMoved(((Component)station).GetComponent<PlaceableShipObject>());
			if (!flag)
			{
				Vector3 position = ((Component)player.gameplayCamera).transform.position;
				flag = Vector3.Distance(position, ((Collider)((Component)station).GetComponent<BoxCollider>()).ClosestPoint(position)) > 4f;
			}
			if (!flag)
			{
				Keyboard current = Keyboard.current;
				if (current == null || !((ButtonControl)current.escapeKey).wasPressedThisFrame)
				{
					if (pending && plugin.Appearance.Body == draftBody && plugin.Appearance.Chassis == draftChassis && plugin.Appearance.Modules == draftModules)
					{
						pending = false;
						paintStatus = "Configuration saved for this ship.";
					}
					else if (pending && Time.unscaledTime > pendingUntil)
					{
						pending = false;
						paintStatus = "Not applied. Dock the drone and retry.";
					}
					foreach (KeyValuePair<string, bool> flag2 in flags)
					{
						AccessTools.Field(typeof(PlayerControllerB), flag2.Key)?.SetValue(player, true);
					}
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
					return;
				}
			}
			Close();
		}

		internal void Close()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				return;
			}
			foreach (KeyValuePair<string, bool> flag in flags)
			{
				if (Object.op_Implicit((Object)(object)player))
				{
					AccessTools.Field(typeof(PlayerControllerB), flag.Key)?.SetValue(player, flag.Value);
				}
			}
			flags.Clear();
			station = null;
			player = null;
			opened = false;
			Cursor.lockState = cursorLock;
			Cursor.visible = cursorVisible;
		}

		private void Styles()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			if (heading == null)
			{
				font = Font.CreateDynamicFontFromOSFont(new string[3] { "Consolas", "Lucida Console", "Courier New" }, 18);
				heading = Style(24, Green, (FontStyle)1);
				text = Style(16, Green, (FontStyle)0);
				small = Style(13, Dim, (FontStyle)0);
				dockWarning = Style(22, new Color(1f, 0.24f, 0.2f), (FontStyle)1);
				dockWarning.alignment = (TextAnchor)4;
				button = new GUIStyle(GUI.skin.button)
				{
					font = font,
					fontSize = 14
				};
				button.normal.textColor = Green;
				button.hover.textColor = Color.white;
			}
			GUIStyle Style(int size, Color color, FontStyle weight = (FontStyle)0)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: 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_004e: 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_005b: Expected O, but got Unknown
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					font = (Font)(Object.op_Implicit((Object)(object)font) ? ((object)font) : ((object)GUI.skin.label.font)),
					fontSize = size,
					fontStyle = weight,
					wordWrap = false
				};
				val.normal.textColor = color;
				return val;
			}
		}

		private static void Fill(Rect r, Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color = GUI.color;
			GUI.color = c;
			GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
		}

		private static void Frame(Rect r, Color c)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, 1f), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 1f, ((Rect)(ref r)).width, 1f), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, 1f, ((Rect)(ref r)).height), c);
			Fill(new Rect(((Rect)(ref r)).xMax - 1f, ((Rect)(ref r)).y, 1f, ((Rect)(ref r)).height), c);
		}

		private void Label(float x, float y, float w, string value, GUIStyle? style = null)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(x, y, w, 28f), value, style ?? text);
		}

		private void ColorControls(float y, string label, ref uint draft, bool body)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			uint num = PaintRules.Resolve(draft, body);
			Label(562f, y, 290f, label + "   #" + num.ToString("X6"), small);
			for (int i = 0; i < Presets.Length; i++)
			{
				Rect val = new Rect((float)(563 + i * 38), y + 27f, 29f, 20f);
				Fill(val, DroneAppearance.Color(Presets[i], body));
				Frame(val, (num == Presets[i]) ? Green : Line);
				if (GUI.Button(val, "", GUIStyle.none))
				{
					draft = Presets[i];
					pending = false;
					paintStatus = "Unapplied color changes.";
				}
			}
			num = PaintRules.Resolve(draft, body);
			int num2 = (int)((num >> 16) & 0xFF);
			int num3 = (int)((num >> 8) & 0xFF);
			int num4 = (int)(num & 0xFF);
			int[] array = new int[3] { num2, num3, num4 };
			string[] array2 = new string[3] { "R", "G", "B" };
			for (int j = 0; j < 3; j++)
			{
				float num5 = y + 51f + (float)(j * 17);
				Label(563f, num5 - 3f, 22f, array2[j], small);
				int num6 = Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(589f, num5 + 3f, 216f, 14f), (float)array[j], 0f, 255f));
				Label(817f, num5 - 3f, 46f, num6.ToString(), small);
				array[j] = num6;
			}
			uint num7 = (uint)((array[0] << 16) | (array[1] << 8) | array[2]);
			if (num7 != num)
			{
				draft = num7;
				pending = false;
				paintStatus = "Unapplied color changes.";
			}
		}

		private void ApplyColors()
		{
			if (!(Time.unscaledTime < nextApply) && DroneAppearance.CanCustomize(plugin) && ModuleRules.Valid(draftModules))
			{
				DroneState droneState = plugin.Fleet.Values.OrderBy((DroneState s) => s.Id).FirstOrDefault();
				if (droneState == null)
				{
					paintStatus = "Drone unavailable.";
					return;
				}
				nextApply = Time.unscaledTime + 0.5f;
				pending = true;
				pendingUntil = Time.unscaledTime + 5f;
				paintStatus = "Saving configuration...";
				plugin.Submit(new Command
				{
					Op = 12,
					Drone = droneState.Id,
					Item = PaintRules.Pack(draftBody, draftChassis),
					Modules = draftModules
				});
			}
		}

		private void RecallDrone()
		{
			DroneState droneState = plugin.Fleet.Values.OrderBy((DroneState s) => s.Id).FirstOrDefault();
			if (droneState != null && !droneState.Docked && !droneState.Returning && !(Time.unscaledTime < nextRecall))
			{
				nextRecall = Time.unscaledTime + 0.75f;
				plugin.Submit(new Command
				{
					Op = 10,
					Drone = droneState.Id
				});
			}
		}

		internal void Draw()
		{
			//IL_07c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cb: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_006b: 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_00e6: 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_00f0: 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)
			//IL_00fc: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: 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_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0641: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_069f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0783: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				return;
			}
			Styles();
			bool flag = DroneAppearance.CanCustomize(plugin);
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			int depth = GUI.depth;
			bool enabled = GUI.enabled;
			try
			{
				GUI.depth = -100;
				GUI.enabled = true;
				GUI.color = Color.white;
				GUI.matrix = Matrix4x4.identity;
				Fill(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), new Color(0f, 0f, 0f, 0.72f));
				float num = Mathf.Min(1.3f, Mathf.Min((float)Screen.width / 1000f, (float)Screen.height / 660f));
				GUI.matrix = Matrix4x4.TRS(new Vector3(((float)Screen.width - 900f * num) * 0.5f, ((float)Screen.height - 560f * num) * 0.5f, 0f), Quaternion.identity, Vector3.one * num);
				Fill(new Rect(0f, 0f, 900f, 560f), new Color(0.025f, 0.035f, 0.028f, 0.99f));
				Frame(new Rect(0f, 0f, 900f, 560f), Green);
				Fill(new Rect(1f, 1f, 898f, 5f), Amber);
				Label(26f, 20f, 670f, "UTILITY DRONE // MANAGEMENT", heading);
				Label(27f, 55f, 660f, "COMPANY EQUIPMENT DIVISION   /   DOCK CONSOLE 01", small);
				if (GUI.Button(new Rect(785f, 26f, 88f, 30f), "CLOSE", button))
				{
					Close();
					return;
				}
				Fill(new Rect(26f, 92f, 848f, 1f), Line);
				if (!flag)
				{
					Rect val = new Rect(26f, 100f, 848f, 36f);
					Fill(val, new Color(0.18f, 0.035f, 0.025f));
					Frame(val, new Color(1f, 0.24f, 0.2f));
					GUI.Label(val, "DRONE MUST BE DOCKED TO CUSTOMIZE", dockWarning);
				}
				else
				{
					Label(27f, 107f, 610f, "CONFIGURATION WORKSPACE", this.text);
					Rect val2 = new Rect(680f, 110f, 200f, 24f);
					GUIStyle val3 = new GUIStyle(small);
					val3.normal.textColor = Amber;
					GUI.Label(val2, "BODY / CHASSIS PAINT", val3);
				}
				Frame(new Rect(26f, 150f, 500f, 310f), Line);
				Label(44f, 163f, 350f, "MODULE LOADOUT");
				Label(410f, 166f, 100f, ModuleRules.Count(draftModules) + "/4 BAYS", small);
				GUI.enabled = flag && !pending;
				string[] array = new string[5] { "ZAP GUN", "DEFIBRILLATOR", "LOCKPICKER", "SPRAY PAINT", "SHOTGUN" };
				string[] array2 = new string[5] { "DG-2", "DB4", "LP", "SP", "SG-2" };
				for (int i = 0; i < 5; i++)
				{
					float num2 = 202 + i * 43;
					Fill(new Rect(43f, num2, 466f, 39f), new Color(0.055f, 0.075f, 0.057f));
					Frame(new Rect(43f, num2, 466f, 39f), Line);
					Label(55f, num2 + 3f, 60f, array2[i], small);
					Label(124f, num2 + 2f, 230f, array[i]);
					bool flag2 = ModuleRules.Has(draftModules, i);
					bool enabled2 = GUI.enabled;
					GUI.enabled = enabled2 && (flag2 || ModuleRules.CanInstall(draftModules, i));
					if (GUI.Button(new Rect(372f, num2 + 3f, 126f, 27f), flag2 ? "REMOVE" : "INSTALL", button))
					{
						draftModules ^= (uint)(1 << i);
						paintStatus = "Unapplied module changes.";
					}
					GUI.enabled = enabled2;
				}
				Label(45f, 432f, 460f, "SELECT UP TO FOUR MODULES", small);
				Frame(new Rect(544f, 150f, 330f, 310f), Line);
				Label(562f, 163f, 290f, "APPEARANCE");
				ColorControls(193f, "BODY", ref draftBody, body: true);
				ColorControls(306f, "CHASSIS", ref draftChassis, body: false);
				if (GUI.Button(new Rect(560f, 427f, 90f, 26f), "APPLY", button))
				{
					ApplyColors();
				}
				if (GUI.Button(new Rect(662f, 427f, 86f, 26f), "SWAP", button))
				{
					uint num3 = PaintRules.Resolve(draftBody, body: true);
					draftBody = PaintRules.Resolve(draftChassis, body: false);
					draftChassis = num3;
					pending = false;
					paintStatus = "Colors swapped. Apply to save.";
				}
				if (GUI.Button(new Rect(760f, 427f, 100f, 26f), "FACTORY", button))
				{
					draftBody = (draftChassis = 16777216u);
					pending = false;
					paintStatus = "Factory colors selected. Apply to save.";
				}
				GUI.enabled = true;
				Fill(new Rect(26f, 485f, 848f, 1f), Line);
				Label(27f, 499f, 640f, flag ? paintStatus : "DRONE AWAY // Dock the drone to customize.", small);
				DroneState droneState = plugin.Fleet.Values.OrderBy((DroneState s) => s.Id).FirstOrDefault();
				GUI.enabled = droneState != null && !droneState.Docked && !droneState.Returning && Time.unscaledTime >= nextRecall;
				string text = ((droneState == null) ? "DRONE UNAVAILABLE" : (droneState.Docked ? "DRONE DOCKED" : (droneState.Returning ? "RETURNING..." : "RECALL DRONE")));
				if (GUI.Button(new Rect(682f, 496f, 192f, 30f), text, button))
				{
					RecallDrone();
				}
				GUI.enabled = true;
				Label(27f, 526f, 835f, "[ESC] CLOSE   //   APPLY SAVES MODULES AND COLORS   //   v0.2.7", small);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
				GUI.depth = depth;
				GUI.enabled = enabled;
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")]
	internal static class DockManagementEscapePatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			DockManagementUI dockManagementUI = Plugin.Instance?.DockUI;
			if (dockManagementUI == null || !dockManagementUI.Active)
			{
				return true;
			}
			dockManagementUI.Close();
			return false;
		}
	}
	internal sealed class DroneAppearance
	{
		internal uint Modules;

		internal uint Body = 16777216u;

		internal uint Chassis = 16777216u;

		private StartOfRound? loadedRound;

		private string? loadedFile;

		private readonly Dictionary<ulong, float> nextChange = new Dictionary<ulong, float>();

		private const string SaveKey = "UtilityDrone.PaintV1";

		internal void Load(Plugin plugin)
		{
			if (!plugin.Server || !Object.op_Implicit((Object)(object)StartOfRound.Instance) || !Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
			{
				return;
			}
			string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
			if ((Object)(object)loadedRound == (Object)(object)StartOfRound.Instance && loadedFile == currentSaveFileName)
			{
				return;
			}
			Body = (Chassis = 16777216u);
			Modules = 0u;
			nextChange.Clear();
			loadedRound = StartOfRound.Instance;
			loadedFile = currentSaveFileName;
			try
			{
				uint[] array = ES3.Load<uint[]>("UtilityDrone.PaintV1", currentSaveFileName, new uint[2] { 16777216u, 16777216u });
				if (array != null && array.Length == 2 && PaintRules.Valid(array[0]) && PaintRules.Valid(array[1]))
				{
					Body = array[0];
					Chassis = array[1];
				}
				uint[] array2 = ES3.Load<uint[]>("UtilityDrone.ConfigurationV1", currentSaveFileName, new uint[3] { Body, Chassis, 0u });
				if (array2 == null || array2.Length != 3 || !PaintRules.Valid(array2[0]) || !PaintRules.Valid(array2[1]))
				{
					return;
				}
				Body = array2[0];
				Chassis = array2[1];
				Modules = ModuleRules.FromSaved(array2[2]);
				if (Modules != array2[2])
				{
					try
					{
						ES3.Save<uint[]>("UtilityDrone.ConfigurationV1", new uint[3] { Body, Chassis, Modules }, currentSaveFileName);
						return;
					}
					catch (Exception ex)
					{
						plugin.Report("Unable to save migrated drone loadout", ex);
						return;
					}
				}
			}
			catch (Exception ex2)
			{
				plugin.Report("Unable to load drone configuration; using defaults", ex2);
			}
		}

		internal bool Apply(Plugin plugin, ulong sender, PlayerControllerB player, ulong packed, uint? modules = null)
		{
			//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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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)
			Load(plugin);
			uint num = PaintRules.Body(packed);
			uint num2 = PaintRules.Chassis(packed);
			if (!plugin.Server || !PaintRules.Valid(num) || !PaintRules.Valid(num2))
			{
				return false;
			}
			uint num3 = modules ?? Modules;
			if (!ModuleRules.Valid(num3) || !CanCustomize(plugin))
			{
				return false;
			}
			DroneStationMarker droneStationMarker = DroneStation.Find();
			ShipBuildModeManager instance = ShipBuildModeManager.Instance;
			if (!Object.op_Implicit((Object)(object)droneStationMarker) || !Object.op_Implicit((Object)(object)player) || player.isPlayerDead || !DroneStation.IsOwned || (Object.op_Implicit((Object)(object)instance) && instance.InBuildMode) || DroneStation.IsBeingMoved(((Component)droneStationMarker).GetComponent<PlaceableShipObject>()))
			{
				return false;
			}
			Vector3 val = ((Component)player).transform.position + Vector3.up * 1.5f;
			Vector3 val2 = ((Collider)((Component)droneStationMarker).GetComponent<BoxCollider>()).ClosestPoint(val) - val;
			if (((Vector3)(ref val2)).magnitude > 3.25f)
			{
				return false;
			}
			int mask = LayerMask.GetMask(new string[4] { "Room", "Colliders", "Default", "PlaceableShipObjects" });
			RaycastHit val3 = default(RaycastHit);
			if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f && Physics.Raycast(val, ((Vector3)(ref val2)).normalized, ref val3, ((Vector3)(ref val2)).magnitude + 0.01f, mask, (QueryTriggerInteraction)1) && (Object)(object)((Component)((RaycastHit)(ref val3)).collider).transform != (Object)(object)((Component)droneStationMarker).transform && !((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(((Component)droneStationMarker).transform))
			{
				return false;
			}
			if (nextChange.TryGetValue(sender, out var value) && Time.unscaledTime < value)
			{
				return false;
			}
			nextChange[sender] = Time.unscaledTime + 0.4f;
			if (Body == num && Chassis == num2 && Modules == num3)
			{
				return true;
			}
			try
			{
				ES3.Save<uint[]>("UtilityDrone.ConfigurationV1", new uint[3] { num, num2, num3 }, loadedFile);
				Body = num;
				Chassis = num2;
				Modules = num3;
				return true;
			}
			catch (Exception ex)
			{
				plugin.Report("Unable to save drone configuration", ex);
				return false;
			}
		}

		internal static bool CanCustomize(Plugin plugin)
		{
			if (!plugin.Docking.Available || plugin.Fleet.Count != 1)
			{
				return false;
			}
			foreach (DroneState value in plugin.Fleet.Values)
			{
				if (!ModuleRules.Customizable(value.Docked, value.Deployed, value.Returning))
				{
					return false;
				}
			}
			return true;
		}

		internal void Receive(uint body, uint chassis, uint modules)
		{
			if (PaintRules.Valid(body) && PaintRules.Valid(chassis) && ModuleRules.Valid(modules))
			{
				Body = body;
				Chassis = chassis;
				Modules = modules;
			}
		}

		internal void Reset()
		{
			Modules = 0u;
			Body = (Chassis = 16777216u);
			loadedRound = null;
			loadedFile = null;
			nextChange.Clear();
		}

		internal static Color Color(uint rgb, bool body)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			rgb = PaintRules.Resolve(rgb, body);
			return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f, 1f);
		}
	}
	internal static class DroneAudio
	{
		private static AudioClip? clip;

		private static AudioClip? warning;

		private static AudioClip? chargeup;

		private static AudioClip? defib;

		private static AudioClip? dockChime;

		private static AudioClip? finishedChime;

		internal static AudioClip FinishedChime()
		{
			if (!Object.op_Implicit((Object)(object)finishedChime))
			{
				finishedChime = LoadPcm("UtilityDrone.finished-chime.pcm", "Drone charging complete");
			}
			return finishedChime;
		}

		internal static AudioClip DockChime()
		{
			if (!Object.op_Implicit((Object)(object)dockChime))
			{
				dockChime = LoadPcm("UtilityDrone.chime.pcm", "Drone docking complete");
			}
			return dockChime;
		}

		internal static AudioClip Chargeup()
		{
			if (!Object.op_Implicit((Object)(object)chargeup))
			{
				return chargeup = LoadPcm("UtilityDrone.chargeup.pcm", "Drone defibrillator charging");
			}
			return chargeup;
		}

		internal static AudioClip Defib()
		{
			if (!Object.op_Implicit((Object)(object)defib))
			{
				return defib = LoadPcm("UtilityDrone.defib.pcm", "Drone revival successful");
			}
			return defib;
		}

		internal static AudioClip Load()
		{
			if (Object.op_Implicit((Object)(object)clip))
			{
				return clip;
			}
			return clip = LoadPcm("UtilityDrone.motor.pcm", "Utility drone motor");
		}

		internal static AudioClip Warning()
		{
			if (Object.op_Implicit((Object)(object)warning))
			{
				return warning;
			}
			return warning = LoadPcm("UtilityDrone.warning.pcm", "Utility drone low battery warning");
		}

		private static AudioClip LoadPcm(string resource, string name)
		{
			using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(resource) ?? throw new InvalidOperationException("Drone sound resource missing.");
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num == 0)
				{
					throw new InvalidOperationException("Incomplete drone sound resource.");
				}
			}
			if (array.Length == 0 || array.Length % 2 != 0)
			{
				throw new InvalidOperationException("Invalid drone PCM sound.");
			}
			float[] array2 = new float[array.Length / 2];
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j] = (float)(short)(array[j * 2] | (array[j * 2 + 1] << 8)) / 32768f;
			}
			AudioClip obj = AudioClip.Create(name, array2.Length, 1, 24000, false);
			if (!obj.SetData(array2, 0))
			{
				throw new InvalidOperationException("Could not initialize drone sound.");
			}
			return obj;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")]
	internal static class DroneCargoTapPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static bool Prefix(PlayerControllerB __instance)
		{
			StorageView storage = Plugin.Instance.Storage;
			if (!storage.OwnsCargoInput(__instance))
			{
				return true;
			}
			storage.CancelCargoHold(__instance);
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "ClickHoldInteraction")]
	internal static class DroneCargoHoldPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static bool Prefix(PlayerControllerB __instance)
		{
			StorageView storage = Plugin.Instance.Storage;
			if (!storage.OwnsCargoInput(__instance))
			{
				return true;
			}
			storage.CancelCargoHold(__instance);
			return false;
		}
	}
	internal sealed class DroneCargoUI : IDisposable
	{
		private readonly Plugin plugin;

		private readonly Action store;

		private readonly Action close;

		private readonly Action<ulong> take;

		private readonly GameObject root;

		private readonly GameObject panel;

		private readonly Image[] icons = (Image[])(object)new Image[4];

		private readonly GameObject[] slots = (GameObject[])(object)new GameObject[4];

		private readonly Image? draggingIcon;

		private readonly int createdFrame;

		private ulong[] items = Array.Empty<ulong>();

		private TMP_Text? capacityText;

		private ulong dragging = ulong.MaxValue;

		private Vector2 dragStart;

		internal DroneCargoUI(Plugin plugin, Action store, Action<ulong> take, Action close)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Expected O, but got Unknown
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: 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_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0915: Unknown result type (might be due to invalid IL or missing references)
			//IL_092a: Unknown result type (might be due to invalid IL or missing references)
			//IL_093f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0954: Unknown result type (might be due to invalid IL or missing references)
			//IL_0968: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_066f: Expected O, but got Unknown
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: 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_070b: Unknown result type (might be due to invalid IL or missing references)
			//IL_070d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0710: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_071a: Unknown result type (might be due to invalid IL or missing references)
			//IL_071c: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0727: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_0773: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Expected O, but got Unknown
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0796: Expected O, but got Unknown
			//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0800: Unknown result type (might be due to invalid IL or missing references)
			//IL_0802: Unknown result type (might be due to invalid IL or missing references)
			//IL_0809: Expected O, but got Unknown
			this.plugin = plugin;
			this.store = store;
			this.take = take;
			this.close = close;
			BeltBagInventoryUI val = ((IEnumerable<BeltBagInventoryUI>)Object.FindObjectsOfType<BeltBagInventoryUI>(true)).FirstOrDefault((Func<BeltBagInventoryUI, bool>)((BeltBagInventoryUI u) => Object.op_Implicit((Object)(object)u) && Object.op_Implicit((Object)(object)u.panel)));
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("Native belt bag UI is unavailable.");
			}
			root = new GameObject("Drone cargo native bag UI", new Type[1] { typeof(RectTransform) });
			root.SetActive(false);
			Canvas componentInParent = val.panel.GetComponentInParent<Canvas>(true);
			root.transform.SetParent(Object.op_Implicit((Object)(object)componentInParent) ? ((Component)componentInParent).transform : val.panel.transform.parent, false);
			RectTransform val2 = (RectTransform)root.transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.sizeDelta = Vector2.zero;
			try
			{
				panel = Object.Instantiate<GameObject>(val.panel, root.transform, false);
				panel.SetActive(true);
				panel.transform.localScale = Vector3.one;
				CanvasGroup[] componentsInChildren = panel.GetComponentsInChildren<CanvasGroup>(true);
				foreach (CanvasGroup obj in componentsInChildren)
				{
					obj.alpha = 1f;
					obj.interactable = true;
					obj.blocksRaycasts = true;
				}
				BeltBagInventoryUI[] componentsInChildren2 = panel.GetComponentsInChildren<BeltBagInventoryUI>(true);
				foreach (BeltBagInventoryUI obj2 in componentsInChildren2)
				{
					((Behaviour)obj2).enabled = false;
					Object.Destroy((Object)(object)obj2);
				}
				Button[] componentsInChildren3 = panel.GetComponentsInChildren<Button>(true);
				Button[] array = componentsInChildren3;
				foreach (Button obj3 in array)
				{
					obj3.onClick = new ButtonClickedEvent();
					((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
					{
						this.close();
					});
				}
				EventTrigger[] componentsInChildren4 = panel.GetComponentsInChildren<EventTrigger>(true);
				for (int num2 = 0; num2 < componentsInChildren4.Length; num2++)
				{
					componentsInChildren4[num2].triggers.Clear();
				}
				GameObject[] inventorySlots = val.inventorySlots;
				foreach (GameObject val3 in inventorySlots)
				{
					if (Object.op_Implicit((Object)(object)val3))
					{
						Transform val4 = CopyOf(val3.transform, val.panel.transform, panel.transform);
						if (Object.op_Implicit((Object)(object)val4) && (Object)(object)val4 != (Object)(object)panel.transform)
						{
							((Component)val4).gameObject.SetActive(false);
						}
					}
				}
				Image[] inventorySlotIcons = val.inventorySlotIcons;
				foreach (Image val5 in inventorySlotIcons)
				{
					if (Object.op_Implicit((Object)(object)val5))
					{
						Transform val6 = CopyOf(((Component)val5).transform, val.panel.transform, panel.transform);
						if (Object.op_Implicit((Object)(object)val6) && (Object)(object)val6 != (Object)(object)panel.transform)
						{
							((Component)val6).gameObject.SetActive(false);
						}
					}
				}
				GameObject val7 = ((IEnumerable<GameObject>)val.inventorySlots).FirstOrDefault((Func<GameObject, bool>)((GameObject slot) => Object.op_Implicit((Object)(object)slot)));
				Image val8 = ((IEnumerable<Image>)val.inventorySlotIcons).FirstOrDefault((Func<Image, bool>)((Image icon) => Object.op_Implicit((Object)(object)icon)));
				if (!Object.op_Implicit((Object)(object)val7) || !Object.op_Implicit((Object)(object)val8))
				{
					throw new InvalidOperationException("Native bag has no slot visual templates.");
				}
				GameObject val9 = new GameObject("Four drone cargo slots", new Type[3]
				{
					typeof(RectTransform),
					typeof(GridLayoutGroup),
					typeof(LayoutElement)
				});
				val9.transform.SetParent(panel.transform, false);
				val9.GetComponent<LayoutElement>().ignoreLayout = true;
				GridLayoutGroup component = val9.GetComponent<GridLayoutGroup>();
				RectTransform component2 = val7.GetComponent<RectTransform>();
				float num3;
				Rect rect;
				if (!Object.op_Implicit((Object)(object)component2))
				{
					num3 = 64f;
				}
				else
				{
					rect = component2.rect;
					num3 = Mathf.Clamp(((Rect)(ref rect)).width, 48f, 90f);
				}
				float num4 = num3;
				float num5;
				if (!Object.op_Implicit((Object)(object)component2))
				{
					num5 = 64f;
				}
				else
				{
					rect = component2.rect;
					num5 = Mathf.Clamp(((Rect)(ref rect)).height, 48f, 90f);
				}
				float num6 = num5;
				component.cellSize = new Vector2(num4, num6);
				component.spacing = new Vector2(8f, 8f);
				component.constraint = (Constraint)1;
				component.constraintCount = 4;
				((LayoutGroup)component).childAlignment = (TextAnchor)4;
				RectTransform val10 = (RectTransform)val9.transform;
				Vector2 val11 = (val10.pivot = new Vector2(0.5f, 0.5f));
				Vector2 val13 = val11;
				val11 = (val10.anchorMax = val13);
				Vector2 anchorMin = val11;
				val10.anchorMin = anchorMin;
				val10.anchoredPosition = Vector2.zero;
				val10.sizeDelta = new Vector2(num4 * 4f + 24f, num6);
				for (int num7 = 0; num7 < 4; num7++)
				{
					GameObject val15 = ((num7 < val.inventorySlots.Length && Object.op_Implicit((Object)(object)val.inventorySlots[num7])) ? val.inventorySlots[num7] : val7);
					Image val16 = ((num7 < val.inventorySlotIcons.Length && Object.op_Implicit((Object)(object)val.inventorySlotIcons[num7])) ? val.inventorySlotIcons[num7] : val8);
					GameObject val17 = Object.Instantiate<GameObject>(val15, val9.transform, false);
					val17.SetActive(true);
					val17.transform.localScale = Vector3.one;
					slots[num7] = val17;
					componentsInChildren = val17.GetComponentsInChildren<CanvasGroup>(true);
					foreach (CanvasGroup obj4 in componentsInChildren)
					{
						obj4.alpha = 1f;
						obj4.interactable = true;
						obj4.blocksRaycasts = true;
					}
					componentsInChildren2 = val17.GetComponentsInChildren<BeltBagInventoryUI>(true);
					foreach (BeltBagInventoryUI obj5 in componentsInChildren2)
					{
						((Behaviour)obj5).enabled = false;
						Object.Destroy((Object)(object)obj5);
					}
					componentsInChildren4 = val17.GetComponentsInChildren<EventTrigger>(true);
					for (int num8 = 0; num8 < componentsInChildren4.Length; num8++)
					{
						componentsInChildren4[num8].triggers.Clear();
					}
					componentsInChildren3 = val17.GetComponentsInChildren<Button>(true);
					for (int num9 = 0; num9 < componentsInChildren3.Length; num9++)
					{
						componentsInChildren3[num9].onClick = new ButtonClickedEvent();
					}
					Transform val18 = CopyOf(((Component)val16).transform, val15.transform, val17.transform);
					icons[num7] = (Object.op_Implicit((Object)(object)val18) ? ((Component)val18).GetComponent<Image>() : Object.Instantiate<Image>(val16, val17.transform, false));
					((Component)icons[num7]).gameObject.SetActive(true);
					((Graphic)icons[num7]).raycastTarget = false;
					RectTransform rectTransform = ((Graphic)icons[num7]).rectTransform;
					val11 = (rectTransform.pivot = new Vector2(0.5f, 0.5f));
					val13 = val11;
					val11 = (rectTransform.anchorMax = val13);
					anchorMin = val11;
					rectTransform.anchorMin = anchorMin;
					rectTransform.anchoredPosition = Vector2.zero;
					rectTransform.sizeDelta = new Vector2(num4 * 0.8f, num6 * 0.8f);
					int index = num7;
					Button val21 = val17.GetComponentInChildren<Button>(true) ?? val17.AddComponent<Button>();
					((Selectable)val21).interactable = true;
					val21.onClick = new ButtonClickedEvent();
					((UnityEvent)val21.onClick).AddListener((UnityAction)delegate
					{
						Click(index);
					});
					Image val22 = val17.GetComponent<Image>() ?? val17.GetComponentInChildren<Image>(true);
					if (Object.op_Implicit((Object)(object)val22))
					{
						((Behaviour)val22).enabled = true;
						((Graphic)val22).raycastTarget = true;
						((Selectable)val21).targetGraphic = (Graphic)(object)val22;
					}
					AddSlotBorder(val17.transform);
					EventTrigger obj6 = ((Component)val21).GetComponent<EventTrigger>() ?? ((Component)val21).gameObject.AddComponent<EventTrigger>();
					obj6.triggers = new List<Entry>();
					Entry val23 = new Entry
					{
						eventID = (EventTriggerType)2
					};
					((UnityEvent<BaseEventData>)(object)val23.callback).AddListener((UnityAction<BaseEventData>)delegate
					{
						BeginDrag(index);
					});
					obj6.triggers.Add(val23);
				}
				TMP_Text[] componentsInChildren5 = panel.GetComponentsInChildren<TMP_Text>(true);
				foreach (TMP_Text val24 in componentsInChildren5)
				{
					if (val24.text.IndexOf("belt", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						val24.text = "Drone cargo";
					}
					if (val24.text.IndexOf("scrap", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						val24.text = "Scrap and equipment allowed";
					}
				}
				TextMeshProUGUI val25 = panel.GetComponentsInChildren<TextMeshProUGUI>(true).FirstOrDefault();
				if (Object.op_Implicit((Object)(object)val25))
				{
					TextMeshProUGUI val26 = Object.Instantiate<TextMeshProUGUI>(val25, panel.transform, false);
					((Component)val26).gameObject.SetActive(true);
					((Graphic)val26).raycastTarget = false;
					capacityText = (TMP_Text?)(object)val26;
					((TMP_Text)val26).text = "Click an empty slot to store the held item. Click or drag an item out to retrieve it. [E/Esc] Close";
					RectTransform rectTransform2 = ((TMP_Text)val26).rectTransform;
					rectTransform2.anchorMin = new Vector2(0.05f, 0f);
					rectTransform2.anchorMax = new Vector2(0.95f, 0f);
					rectTransform2.pivot = new Vector2(0.5f, 1f);
					rectTransform2.anchoredPosition = new Vector2(0f, -12f);
					rectTransform2.sizeDelta = new Vector2(0f, 65f);
					((TMP_Text)val26).enableAutoSizing = true;
					((TMP_Text)val26).fontSizeMin = 12f;
					((TMP_Text)val26).fontSizeMax = 20f;
				}
				if (Object.op_Implicit((Object)(object)val.cursorGrabbingObjectImage))
				{
					Transform val27 = CopyOf(((Component)val.cursorGrabbingObjectImage).transform, val.panel.transform, panel.transform);
					draggingIcon = (Object.op_Implicit((Object)(object)val27) ? ((Component)val27).GetComponent<Image>() : Object.Instantiate<Image>(val.cursorGrabbingObjectImage, root.transform, false));
					((Graphic)draggingIcon).raycastTarget = false;
					((Component)draggingIcon).gameObject.SetActive(false);
				}
				createdFrame = Time.frameCount;
			}
			catch
			{
				Object.Destroy((Object)(object)root);
				throw;
			}
		}

		private static void AddSlotBorder(Transform slot)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0089: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			Edge("Blue cargo border top", new Vector2(0f, 1f), Vector2.one, new Vector2(0.5f, 1f), new Vector2(0f, 4f));
			Edge("Blue cargo border bottom", Vector2.zero, new Vector2(1f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 4f));
			Edge("Blue cargo border left", Vector2.zero, new Vector2(0f, 1f), new Vector2(0f, 0.5f), new Vector2(4f, 0f));
			Edge("Blue cargo border right", new Vector2(1f, 0f), Vector2.one, new Vector2(1f, 0.5f), new Vector2(4f, 0f));
			void Edge(string name, Vector2 min, Vector2 max, Vector2 pivot, Vector2 size)
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: 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_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: 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)
				GameObject val = new GameObject(name, new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(LayoutElement)
				});
				val.transform.SetParent(slot, false);
				val.GetComponent<LayoutElement>().ignoreLayout = true;
				Image component = val.GetComponent<Image>();
				((Graphic)component).raycastTarget = false;
				((Graphic)component).color = new Color(0.04f, 0.55f, 1f, 1f);
				RectTransform rectTransform = ((Graphic)component).rectTransform;
				rectTransform.anchorMin = min;
				rectTransform.anchorMax = max;
				rectTransform.pivot = pivot;
				rectTransform.anchoredPosition = Vector2.zero;
				rectTransform.sizeDelta = size;
			}
		}

		private static Transform? CopyOf(Transform source, Transform sourceRoot, Transform cloneRoot)
		{
			Stack<int> stack = new Stack<int>();
			Transform val = source;
			while ((Object)(object)val != (Object)(object)sourceRoot)
			{
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.parent))
				{
					return null;
				}
				stack.Push(val.GetSiblingIndex());
				val = val.parent;
			}
			Transform val2 = cloneRoot;
			while (stack.Count > 0)
			{
				int num = stack.Pop();
				if (num >= val2.childCount)
				{
					return null;
				}
				val2 = val2.GetChild(num);
			}
			return val2;
		}

		private void Click(int index)
		{
			dragging = ulong.MaxValue;
			if (Object.op_Implicit((Object)(object)draggingIcon))
			{
				((Component)draggingIcon).gameObject.SetActive(false);
			}
			if (index < items.Length)
			{
				take(items[index]);
			}
			else
			{
				store();
			}
		}

		private void BeginDrag(int index)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (index < items.Length && Mouse.current != null)
			{
				dragging = items[index];
				dragStart = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
				if (Object.op_Implicit((Object)(object)draggingIcon))
				{
					draggingIcon.sprite = icons[index].sprite;
					((Component)draggingIcon).gameObject.SetActive(true);
				}
			}
		}

		internal void Tick(DroneState state)
		{
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			items = state.Cargo.ToArray();
			if (Object.op_Implicit((Object)(object)capacityText))
			{
				capacityText.text = $"CARGO {items.Length}/4 | {state.CargoWeight:0}/50 lb\nClick an empty slot to store. Click or drag to retrieve. [E/Esc] Close";
			}
			if (Time.frameCount > createdFrame)
			{
				root.SetActive(true);
			}
			for (int i = 0; i < icons.Length; i++)
			{
				GrabbableObject val = ((i < items.Length) ? plugin.Item(items[i]) : null);
				((Component)icons[i]).gameObject.SetActive(true);
				((Behaviour)icons[i]).enabled = Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.itemProperties.itemIcon);
				icons[i].sprite = (Object.op_Implicit((Object)(object)val) ? val.itemProperties.itemIcon : null);
			}
			if (dragging == ulong.MaxValue || Mouse.current == null)
			{
				return;
			}
			Vector2 val2 = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
			Canvas componentInParent = panel.GetComponentInParent<Canvas>();
			Camera val3 = ((Object.op_Implicit((Object)(object)componentInParent) && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
			if (Object.op_Implicit((Object)(object)draggingIcon))
			{
				Transform parent = ((Component)draggingIcon).transform.parent;
				RectTransform val4 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				Vector2 val5 = default(Vector2);
				if (val4 != null && RectTransformUtility.ScreenPointToLocalPointInRectangle(val4, val2, val3, ref val5))
				{
					((Transform)((Graphic)draggingIcon).rectTransform).localPosition = new Vector3(val5.x, val5.y, 0f);
				}
			}
			if (Mouse.current.leftButton.wasReleasedThisFrame)
			{
				bool num = !RectTransformUtility.RectangleContainsScreenPoint((RectTransform)panel.transform, val2, val3);
				ulong obj = dragging;
				dragging = ulong.MaxValue;
				if (Object.op_Implicit((Object)(object)draggingIcon))
				{
					((Component)draggingIcon).gameObject.SetActive(false);
				}
				if (num || Vector2.Distance(val2, dragStart) < 5f)
				{
					take(obj);
				}
			}
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)root))
			{
				root.SetActive(false);
				Object.Destroy((Object)(object)root);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
	internal static class DroneGrabPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static bool Prefix(PlayerControllerB __instance)
		{
			return !Plugin.Instance.Storage.BlockNativeGrab(__instance);
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "GrabObjectServerRpc")]
	internal static class DroneServerGrabPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static bool Prefix(NetworkObjectReference __0)
		{
			NetworkObject val = default(NetworkObject);
			if (((NetworkObjectReference)(ref __0)).TryGet(ref val, (NetworkManager)null))
			{
				return !Object.op_Implicit((Object)(object)((Component)val).GetComponent<DroneMarker>());
			}
			return true;
		}
	}
	internal static class DroneHud
	{
		private static GUIStyle? paintLabel;

		private static GUIStyle? shotgunReloadLabel;

		private static GUIStyle? targetLabel;

		private static GUIStyle? small;

		private static GUIStyle? title;

		private static GUIStyle? number;

		private static GUIStyle? module;

		private static GUIStyle? body;

		private static GUIStyle? cargo;

		private static readonly Color Ink = new Color(0.025f, 0.045f, 0.055f, 0.5f);

		private static readonly Color Muted = new Color(0.55f, 0.68f, 0.71f);

		private static readonly Color White = new Color(0.92f, 0.98f, 1f);

		private static readonly Vector2[] Bolt = (Vector2[])(object)new Vector2[6]
		{
			new Vector2(39f, 7f),
			new Vector2(19f, 34f),
			new Vector2(30f, 34f),
			new Vector2(24f, 57f),
			new Vector2(47f, 25f),
			new Vector2(35f, 25f)
		};

		internal static void DrawShotgunAim(Camera camera, bool armed, float reloadRemaining)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0057: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_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_00ab: 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_00b7: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			/