Decompiled source of XL Scrap Api v0.2.0

XLScrapApi.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalModDataLib.Attributes;
using LethalModDataLib.Base;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using XLScrapApi.Models;
using XLScrapApi.NetcodePatcher;
using XLScrapApi.Util;
using XlScrapApi;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Henit3")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("API to add scrap too heavy for an employee to manage alone!")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+a07148bff75cd0b7114f4a517d257cc94d66572e")]
[assembly: AssemblyProduct("XL Scrap API")]
[assembly: AssemblyTitle("XLScrapApi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedINetworkSerializable<NetworkObjectReference>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<NetworkObjectReference>();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 XLScrapApi
{
	[BepInPlugin("XLScrapApi", "XL Scrap API", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigValues Config;

		internal static ManualLogSource Logger;

		private static readonly Harmony Harmony = new Harmony("XLScrapApi");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin XLScrapApi (0.2.0) is loading...");
			Config = new ConfigValues(((BaseUnityPlugin)this).Config);
			NetcodePatcher();
			Logger.LogInfo((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogInfo((object)"Patching complete!");
			Logger.LogInfo((object)"Plugin XLScrapApi (0.2.0) is loaded!");
		}

		private static void NetcodePatcher()
		{
			Type[] array;
			try
			{
				array = Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				array = ex.Types.Where((Type t) => t != null).ToArray();
			}
			Type[] array2 = array;
			foreach (Type type in array2)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array3 = methods;
				foreach (MethodInfo methodInfo in array3)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "XLScrapApi";

		public const string PLUGIN_NAME = "XL Scrap API";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace XLScrapApi.Util
{
	public static class ManualLogSourceExtensions
	{
		private class CodeInstructionFormatter
		{
			private int _instructionIndexPadLength = instructionCount.ToString().Length;

			public CodeInstructionFormatter(int instructionCount)
			{
			}

			public string Format(CodeInstruction instruction, int index)
			{
				return $"    IL_{index.ToString().PadLeft(_instructionIndexPadLength, '0')}: {instruction}";
			}
		}

		public static void LogDebugInstructionsFrom(this ManualLogSource source, CodeMatcher matcher)
		{
			string name = new StackTrace().GetFrame(1).GetMethod().Name;
			CodeInstructionFormatter @object = new CodeInstructionFormatter(matcher.Length);
			StringBuilder stringBuilder = new StringBuilder("'" + name + "' Matcher Instructions:\n").AppendLine(string.Join("\n", matcher.InstructionEnumeration().Select(@object.Format))).AppendLine("End of matcher instructions.");
			source.LogDebug((object)stringBuilder.ToString());
		}
	}
	public static class VectorExtensions
	{
		public static Vector3 Sum(this IEnumerable<Vector3> vectors)
		{
			//IL_0001: 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)
			return vectors.Aggregate(Vector3.zero, (Vector3 s, Vector3 v) => s + v);
		}

		public static Vector3 Average(this IEnumerable<Vector3> vectors)
		{
			//IL_0001: 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)
			return vectors.Sum() / (float)vectors.Count();
		}

		public static Vector3? FloorVector(this Vector3 vector, float maxRange = 5f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			return Physics.Raycast(vector, Vector3.down, ref val, maxRange, StartOfRound.Instance.walkableSurfacesMask) ? new Vector3?(((RaycastHit)(ref val)).point) : null;
		}
	}
	public static class XLPositionUtils
	{
		public static Vector3 GetPositionFromHolders(IList<Vector3> anchors, IList<Vector3> holdersPos)
		{
			//IL_0037: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			return (from i in Enumerable.Range(0, holdersPos.Count)
				select holdersPos[i] - anchors[i]).Average();
		}

		public static Vector3[] GetHolderPositionsAt(IList<Vector3> anchors, Vector3 destVector)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return anchors.Select((Vector3 x) => x + destVector).ToArray();
		}

		public static Vector3[] GetHoldersPositionsOnShift(IList<Vector3> holdersPos, Vector3 shiftVector)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return holdersPos?.Select((Vector3 x) => x + shiftVector).ToArray();
		}
	}
	public static class XLSpawner
	{
		private const float MaxSpawnDiff = 20f;

		private const int MaxFailedCorrectionAttempts = 3;

		private static int HolderLinecastMask => StartOfRound.Instance.collidersAndRoomMaskAndDefault ^ 0x800;

		public static bool CorrectToValidPosition(XLMainItem xlMain, Vector3? location = null)
		{
			//IL_0027: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			XLSimpleMainItem xlItem = new XLSimpleMainItem(xlMain);
			if (location.HasValue)
			{
				xlItem.Position = location.Value;
				xlItem.HolderPositions = XLPositionUtils.GetHolderPositionsAt(xlItem.Anchors, location.Value);
			}
			for (int i = 0; i < 3; i++)
			{
				List<Vector3> realAnchors = xlItem.Anchors.Select((Vector3 a) => a + xlItem.Position).ToList();
				if (CheckValidPosition(xlItem, realAnchors, out var correction))
				{
					xlMain.SetPositionWithHolders(xlItem.Position);
					Plugin.Logger.LogDebug((object)$"Valid position at {xlItem.Position}");
					return true;
				}
				Plugin.Logger.LogDebug((object)$"Invalid position at {xlItem.Position}: {correction}");
				switch (correction)
				{
				case CorrectionType.Wall:
					CorrectValidWallPosition(xlItem, realAnchors);
					break;
				case CorrectionType.Floor:
					CorrectValidFloorPosition(xlItem, realAnchors);
					break;
				default:
					Plugin.Logger.LogWarning((object)"Invalid position without correction type specified!");
					break;
				}
			}
			return false;
		}

		private static void CorrectValidWallPosition(XLSimpleMainItem xlItem, List<Vector3> realAnchors)
		{
			//IL_0003: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			bool flag = false;
			for (int i = 0; i < realAnchors.Count; i++)
			{
				for (int j = i + 1; j < realAnchors.Count; j++)
				{
					if (Physics.Linecast(realAnchors[i], realAnchors[j], ref val, HolderLinecastMask))
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
			if (!flag)
			{
				Plugin.Logger.LogDebug((object)"Correcting wall (NO WALL)");
				return;
			}
			float num = 0f;
			float num2 = 0f;
			for (int k = 0; k < realAnchors.Count; k++)
			{
				Vector3 val2 = ((RaycastHit)(ref val)).point - realAnchors[k];
				float num3 = Vector3.Dot(((RaycastHit)(ref val)).normal, val2);
				if (num3 > num)
				{
					num = num3;
				}
				if (num3 < num2)
				{
					num2 = num3;
				}
			}
			if (num == 0f && num2 == 0f)
			{
				Plugin.Logger.LogDebug((object)"Correcting wall (NO DISTANCES)");
				return;
			}
			float num4 = Math.Abs(num);
			float num5 = Math.Abs(num2);
			if (1 == 0)
			{
			}
			float num6 = ((num4 == 0f) ? ((num5 != 0f) ? num2 : 0f) : ((num5 != 0f) ? ((num4 > num5) ? num5 : num4) : num));
			if (1 == 0)
			{
			}
			float num7 = num6;
			Vector3 val3 = num7 * ((RaycastHit)(ref val)).normal;
			xlItem.Position += val3;
			xlItem.HolderPositions = XLPositionUtils.GetHoldersPositionsOnShift(xlItem.HolderPositions, val3);
		}

		private static void CorrectValidFloorPosition(XLSimpleMainItem xlItem, List<Vector3> realAnchors)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3?> list = realAnchors.Select((Vector3 x) => x.FloorVector()).ToList();
			if (list.All((Vector3? x) => !x.HasValue))
			{
				float num = xlItem.Anchors.Max((Vector3 a) => ((Vector3)(ref a)).magnitude);
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				Vector3 val = Vector2.op_Implicit(((Vector2)(ref insideUnitCircle)).normalized) * (num + 1f);
				xlItem.Position += val;
				xlItem.HolderPositions = XLPositionUtils.GetHoldersPositionsOnShift(xlItem.HolderPositions, val);
				Plugin.Logger.LogDebug((object)$"Correcting floor (RANDOM END): {xlItem.Position}");
				return;
			}
			Vector3 val2 = Vector3.zero;
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].HasValue)
				{
					val2 += xlItem.Anchors[i];
				}
			}
			((Vector3)(ref val2)).Normalize();
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			for (int j = 0; j < realAnchors.Count; j++)
			{
				Vector3 val3 = realAnchors[j];
				Vector3? val4 = list[j];
				Vector3 val5 = val3 - xlItem.Position;
				float num4 = Vector3.Dot(val2, val5);
				if (!val4.HasValue)
				{
					if (num4 < num2)
					{
						num2 = num4;
					}
				}
				else if (num4 < num3)
				{
					num3 = num4;
				}
			}
			if (num2 == float.MinValue)
			{
				num2 = 0f;
			}
			if (num3 == float.MaxValue)
			{
				num3 = 0f;
			}
			float num5 = Math.Abs(num2) + Math.Abs(num3);
			Vector3 val6 = val2 * num5;
			xlItem.Position += val6;
			xlItem.HolderPositions = XLPositionUtils.GetHoldersPositionsOnShift(xlItem.HolderPositions, val2 * num5);
		}

		private static bool CheckValidPosition(XLSimpleMainItem xlItem, List<Vector3> realAnchors, out CorrectionType? correction)
		{
			if (!CheckAnchorIntersections(xlItem, realAnchors, out correction) || !CheckFloorPositions(xlItem, realAnchors, out correction))
			{
				return false;
			}
			return true;
		}

		private static bool CheckAnchorIntersections(XLSimpleMainItem xlItem, List<Vector3> realAnchors, out CorrectionType? correction)
		{
			//IL_0016: 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_003d: 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)
			correction = null;
			for (int i = 0; i < realAnchors.Count; i++)
			{
				for (int j = i + 1; j < realAnchors.Count; j++)
				{
					if (Physics.Linecast(realAnchors[i], realAnchors[j], HolderLinecastMask))
					{
						Plugin.Logger.LogDebug((object)$"Wall between anchors: {realAnchors[i]}, {realAnchors[j]}");
						correction = CorrectionType.Wall;
						return false;
					}
				}
			}
			return true;
		}

		private static bool CheckFloorPositions(XLSimpleMainItem xlItem, List<Vector3> realAnchors, out CorrectionType? correction)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			correction = null;
			Vector3? val = xlItem.Position.FloorVector();
			if (!val.HasValue || Vector3.Distance(val.Value, xlItem.Position) > 20f)
			{
				Plugin.Logger.LogDebug((object)$"Main floor not good: {xlItem.Position} -> {val}");
				correction = CorrectionType.Floor;
				return false;
			}
			List<Vector3?> list = realAnchors.Select((Vector3 x) => x.FloorVector()).ToList();
			if (list.Any((Vector3? a) => !a.HasValue))
			{
				Plugin.Logger.LogDebug((object)("Anchor floor not good: " + string.Join(',', list)));
				correction = CorrectionType.Floor;
				return false;
			}
			List<Vector3> list2 = list.Select((Vector3? a) => a.Value).ToList();
			Vector3 positionFromHolders = XLPositionUtils.GetPositionFromHolders(xlItem.Anchors, list2);
			if (Vector3.Distance(positionFromHolders, xlItem.Position) > 20f)
			{
				Plugin.Logger.LogDebug((object)$"New position too far away: {xlItem.Position} -> {positionFromHolders}");
				correction = CorrectionType.Floor;
				return false;
			}
			for (int i = 0; i < list2.Count; i++)
			{
				float num = Vector3.Distance(positionFromHolders, list2[i]);
				if (num > ((Vector3)(ref xlItem.Anchors[i])).magnitude + Plugin.Config.MaxHolderRadius.Value / 2f)
				{
					Plugin.Logger.LogDebug((object)$"Floored anchor too far away ({num}): {positionFromHolders} <-> {list2[i]}");
					correction = CorrectionType.Floor;
					return false;
				}
			}
			return true;
		}
	}
}
namespace XLScrapApi.Patches.StartOfRoundPatch
{
	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	public class AwakePatch
	{
		[HarmonyPrefix]
		public static void Prefix(StartOfRound __instance)
		{
			ModSaveFile.Init();
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
	public class SyncShipUnlockablesClientPatch
	{
		private static bool IsNotHolder(Component component)
		{
			return ((Object)component).name != "Holder(Clone)";
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> StopHolderPosSync(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StartOfRound), "elevatorTransform"), (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
			});
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Ldloc_0, (object)null),
				new CodeInstruction(OpCodes.Ldloc_S, (object)7),
				new CodeInstruction(OpCodes.Ldelem_Ref, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SyncShipUnlockablesClientPatch), "IsNotHolder", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.And, (object)null)
			});
			return val.InstructionEnumeration();
		}
	}
}
namespace XLScrapApi.Patches.RoundManagerPatch
{
	[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
	public class SpawnScrapInLevelPatch
	{
		private const float MaxSpawnDiff = 20f;

		private static int _failedSpawnAttempts;

		private const int MaxFailedSpawnAttempts = 3;

		private const int Component1Ref = 18;

		private const int VRef = 17;

		private const int ArrayRef = 6;

		private const int RandomScrapSpawnRef = 7;

		private static bool HandleXlSpawn(GrabbableObject component)
		{
			if (!(component is XLMainItem xlMain))
			{
				return true;
			}
			if (!XLSpawner.CorrectToValidPosition(xlMain))
			{
				return InvalidateXlSpawn((Component)(object)component);
			}
			return true;
		}

		private static bool InvalidateXlSpawn(Component component)
		{
			Object.Destroy((Object)(object)component.gameObject);
			Plugin.Logger.LogWarning((object)$"XL Spawn failed! ({_failedSpawnAttempts})");
			return false;
		}

		private static void HandleFailedXlSpawn(RoundManager __instance, int i, List<Item> scrapToSpawn, int[] array, List<RandomScrapSpawn> usedSpawns, RandomScrapSpawn randomScrapSpawn)
		{
			if (++_failedSpawnAttempts >= 3)
			{
				_failedSpawnAttempts = 0;
				scrapToSpawn[i] = __instance.currentLevel.spawnableScrap[__instance.GetRandomWeightedIndex(array, (Random)null)].spawnableItem;
				Plugin.Logger.LogWarning((object)"XL Spawn failed too many times: Rerolling spawned item");
			}
			usedSpawns.Remove(randomScrapSpawn);
			randomScrapSpawn.spawnUsed = false;
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddXlSpawnLogic(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Expected O, but got Unknown
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Expected O, but got Unknown
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Expected O, but got Unknown
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Expected O, but got Unknown
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Expected O, but got Unknown
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Expected O, but got Unknown
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Expected O, but got Unknown
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Expected O, but got Unknown
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Expected O, but got Unknown
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Expected O, but got Unknown
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Expected O, but got Unknown
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.End();
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Blt, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null)
			});
			object operand = val.InstructionAt(1).operand;
			object operand2 = val.InstructionAt(2).operand;
			val.Advance(-1);
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null)
			});
			object operand3 = val.InstructionAt(1).operand;
			Label label;
			if ((label = val.Instruction.labels.FirstOrDefault()) == default(Label))
			{
				label = generator.DefineLabel();
				val.AddLabelsAt(val.Pos, (IEnumerable<Label>)new <>z__ReadOnlySingleElementList<Label>(label));
			}
			val.Start();
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldstr, (object)null, (string)null)
			});
			val.Advance(1);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldstr, (object)null, (string)null)
			});
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Br, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)null, (string)null)
			});
			object operand4 = val.Instruction.operand;
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_3, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null)
			});
			Label label2 = generator.DefineLabel();
			val.AddLabelsAt(val.Pos, (IEnumerable<Label>)new <>z__ReadOnlySingleElementList<Label>(label2));
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[17]
			{
				new CodeInstruction(OpCodes.Ldloc_S, (object)18),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SpawnScrapInLevelPatch), "HandleXlSpawn", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Brtrue, (object)label2),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldloc_S, (object)17),
				new CodeInstruction(OpCodes.Ldfld, operand3),
				new CodeInstruction(OpCodes.Ldloc_S, (object)17),
				new CodeInstruction(OpCodes.Ldfld, operand),
				new CodeInstruction(OpCodes.Ldfld, operand2),
				new CodeInstruction(OpCodes.Ldloc_S, (object)6),
				new CodeInstruction(OpCodes.Ldloc_S, (object)17),
				new CodeInstruction(OpCodes.Ldfld, operand),
				new CodeInstruction(OpCodes.Ldfld, operand4),
				new CodeInstruction(OpCodes.Ldloc_S, (object)7),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SpawnScrapInLevelPatch), "HandleFailedXlSpawn", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Pop, (object)null),
				new CodeInstruction(OpCodes.Br, (object)label)
			});
			return val.InstructionEnumeration();
		}
	}
}
namespace XLScrapApi.Patches.PlayerControllerBPatch
{
	[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
	public class BeginGrabObjectPatch : HolderTargetPatchBase
	{
		[HarmonyPrefix]
		public static bool Prefix(PlayerControllerB __instance, int ___interactableObjectsMask)
		{
			return !__instance.twoHanded && !((double)__instance.sinkingValue > 0.7300000190734863) && HolderTargetPatchBase.ShouldProcessAfterHolderCheck(__instance, ___interactableObjectsMask);
		}
	}
	public abstract class HolderTargetPatchBase
	{
		private const float XlGrabDistance = 2.5f;

		protected static bool ShouldProcessAfterHolderCheck(PlayerControllerB __instance, int ___interactableObjectsMask)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)__instance.gameplayCamera).transform.position, ((Component)__instance.gameplayCamera).transform.forward);
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, ref val2, __instance.grabDistance, ___interactableObjectsMask) || ((Component)((RaycastHit)(ref val2)).collider).gameObject.layer == 8 || ((Component)((RaycastHit)(ref val2)).collider).tag != "PhysicsProp")
			{
				return true;
			}
			GrabbableObject component = ((Component)((Component)((RaycastHit)(ref val2)).collider).transform).gameObject.GetComponent<GrabbableObject>();
			if (!(component is XLHolderItem xLHolderItem))
			{
				return true;
			}
			return Vector3.Distance(((Component)__instance.gameplayCamera).transform.position, ((Component)xLHolderItem).transform.position) <= 2.5f;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "SetHoverTipAndCurrentInteractTrigger")]
	public class SetHoverTipAndCurrentInteractTriggerPatch : HolderTargetPatchBase
	{
		[HarmonyPrefix]
		public static bool Prefix(PlayerControllerB __instance, int ___interactableObjectsMask)
		{
			return HolderTargetPatchBase.ShouldProcessAfterHolderCheck(__instance, ___interactableObjectsMask);
		}
	}
}
namespace XLScrapApi.Patches.HUDManagerPatch
{
	[HarmonyPatch(typeof(HUDManager), "ChangeControlTipMultiple")]
	public class ChangeControlTipMultiplePatch
	{
		[HarmonyPostfix]
		public static void Postfix(HUDManager __instance, Item itemProperties)
		{
			GrabbableObject currentlyHeldObjectServer = StartOfRound.Instance.localPlayerController.currentlyHeldObjectServer;
			if (currentlyHeldObjectServer is XLHolderItem xLHolderItem)
			{
				((TMP_Text)__instance.controlTipLines[0]).text = "Stop Holding " + ((GrabbableObject)xLHolderItem.MainItem).itemProperties.itemName + " : [G]";
			}
		}
	}
}
namespace XLScrapApi.Patches.GiftBoxItemPatch
{
	[HarmonyPatch(typeof(GiftBoxItem), "Start")]
	public class StartPatch
	{
		private const int GiftboxItemId = 152767;

		private const int IndexRef = 4;

		private static bool IsXlAtIndex(List<SpawnableItemWithRarity> spawnChoices, int index)
		{
			GameObject spawnPrefab = spawnChoices[index].spawnableItem.spawnPrefab;
			if ((Object)(object)spawnPrefab == (Object)null)
			{
				return false;
			}
			GrabbableObject component = spawnPrefab.GetComponent<GrabbableObject>();
			return (component is XLMainItem || component is XLHolderItem) ? true : false;
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> ExcludeXlItems(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4, (object)152767, (string)null)
			});
			val.Advance(1);
			object operand = val.Instruction.operand;
			val.RemoveInstruction();
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[8]
			{
				new CodeInstruction(OpCodes.Ceq, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(RoundManager), "Instance")),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(RoundManager), "currentLevel")),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(SelectableLevel), "spawnableScrap")),
				new CodeInstruction(OpCodes.Ldloc_S, (object)4),
				new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(StartPatch), "IsXlAtIndex", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Or, (object)null),
				new CodeInstruction(OpCodes.Brfalse, operand)
			});
			return val.InstructionEnumeration();
		}
	}
}
namespace XLScrapApi.Patches.GameNetworkManagerPatch
{
	[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
	public class SaveItemsInShipPatch
	{
		[HarmonyPostfix]
		public static void Postfix(GameNetworkManager __instance)
		{
			if (__instance.isHostingGame && StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.isChallengeFile && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				ModSaveFile.Instance.SaveXlScrap(Object.FindObjectsByType<XLMainItem>((FindObjectsInactive)0, (FindObjectsSortMode)0));
			}
		}
	}
}
namespace XLScrapApi.Patches.EntranceTeleportPatch
{
	public class TeleportPlayerBase
	{
		protected static bool IsTeleportingWithXl(PlayerControllerB player, out XLMainItem xlItemOut)
		{
			xlItemOut = null;
			if (!((Object)(object)player.currentlyHeldObjectServer == (Object)null) && player.currentlyHeldObjectServer is XLHolderItem xLHolderItem)
			{
				XLMainItem mainItem = xLHolderItem.MainItem;
				if (mainItem != null && mainItem.HolderItems != null)
				{
					xlItemOut = mainItem;
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayerClientRpc")]
	public class TeleportPlayerClientPatch : TeleportPlayerBase
	{
		[HarmonyPrefix]
		public static bool Prefix(EntranceTeleport __instance, int playerObj)
		{
			PlayerControllerB player = __instance.playersManager.allPlayerScripts[playerObj];
			if (!TeleportPlayerBase.IsTeleportingWithXl(player, out var _))
			{
				return true;
			}
			Plugin.Logger.LogDebug((object)"Skipped teleport on ClientRpc (XL in hand)");
			return false;
		}
	}
	[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayer")]
	public class TeleportPlayerPatch : TeleportPlayerBase
	{
		private static bool HandleXlTeleport(EntranceTeleport instance, PlayerControllerB player)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!TeleportPlayerBase.IsTeleportingWithXl(player, out var xlItemOut))
			{
				return false;
			}
			xlItemOut.TeleportXlScrapServerRpc(NetworkObjectReference.op_Implicit(((Component)instance).GetComponent<NetworkObject>()), (int)player.playerClientId);
			return true;
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> StopEntranceTeleportWithXl(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)
			});
			val.Advance(1);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Stloc_1, (object)null, (string)null)
			});
			val.Advance(1);
			Label label = generator.DefineLabel();
			val.AddLabelsAt(val.Pos, (IEnumerable<Label>)new <>z__ReadOnlySingleElementList<Label>(label));
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[6]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(GameNetworkManager), "Instance")),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameNetworkManager), "localPlayerController")),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(TeleportPlayerPatch), "HandleXlTeleport", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Brfalse, (object)label),
				new CodeInstruction(OpCodes.Ret, (object)null)
			});
			return val.InstructionEnumeration();
		}
	}
}
namespace XLScrapApi.Patches.DepositItemsDeskPatch
{
	[HarmonyPatch(typeof(DepositItemsDesk), "AddObjectToDeskServerRpc")]
	public class AddObjectToDeskServerPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(DepositItemsDesk __instance, NetworkObjectReference grabbableObjectNetObject)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return true;
			}
			NetworkObject val = default(NetworkObject);
			if (!((NetworkObjectReference)(ref grabbableObjectNetObject)).TryGet(ref val, (NetworkManager)null) || !(((Component)val).GetComponentInChildren<GrabbableObject>() is XLHolderItem xLHolderItem))
			{
				return true;
			}
			XLHolderItem[] holderItems = xLHolderItem.MainItem.HolderItems;
			foreach (XLHolderItem xLHolderItem2 in holderItems)
			{
				((Component)xLHolderItem2).GetComponent<NetworkObject>().Despawn(true);
			}
			xLHolderItem.MainItem.HolderItems = null;
			__instance.AddObjectToDeskServerRpc(NetworkObjectReference.op_Implicit(((Component)xLHolderItem.MainItem).gameObject.GetComponent<NetworkObject>()));
			return false;
		}
	}
	[HarmonyPatch(typeof(DepositItemsDesk), "PlaceItemOnCounter")]
	public class PlaceItemOnCounterPatch
	{
		private static bool HandleSellXl(DepositItemsDesk desk, PlayerControllerB player, Vector3 counterPos)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (!(player.currentlyHeldObjectServer is XLHolderItem xLHolderItem) || (Object)(object)xLHolderItem.MainItem == (Object)null)
			{
				return false;
			}
			((Component)xLHolderItem.MainItem).transform.SetParent(((Component)desk.deskObjectsContainer).transform, true);
			xLHolderItem.MainItem.SetOnCounterServerRpc(counterPos);
			return true;
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddHandleSellXl(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.End();
			Label label = generator.DefineLabel();
			val.AddLabelsAt(val.Pos, (IEnumerable<Label>)new <>z__ReadOnlySingleElementList<Label>(label));
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null)
			});
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Ldloc_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlaceItemOnCounterPatch), "HandleSellXl", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Brtrue, (object)label)
			});
			return val.InstructionEnumeration();
		}
	}
}
namespace XLScrapApi.Models
{
	public enum CorrectionType
	{
		Wall,
		Floor
	}
	public class ModSaveFile : ModDataContainer
	{
		[ModDataIgnore(/*Could not decode attribute arguments.*/)]
		public static ModSaveFile Instance;

		[ModDataIgnore(/*Could not decode attribute arguments.*/)]
		public HashSet<int> SpawnedKeys;

		public Dictionary<Vector3, List<(Vector3, Vector3)>> XlHolderLocations;

		public static void Init()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				Instance = new ModSaveFile();
				Instance.LoadXlScrap();
			}
		}

		public ModSaveFile()
		{
			XlHolderLocations = new Dictionary<Vector3, List<(Vector3, Vector3)>>();
			SpawnedKeys = new HashSet<int>();
		}

		public void Reset()
		{
			XlHolderLocations = new Dictionary<Vector3, List<(Vector3, Vector3)>>();
			SpawnedKeys = new HashSet<int>();
		}

		public void SaveXlScrap(IList<XLMainItem> xlMains)
		{
			XlHolderLocations = xlMains.Where((XLMainItem m) => m.HolderItems?.Any() ?? false).ToDictionary((XLMainItem m) => ((Component)m).transform.position, (XLMainItem m) => m.HolderItems.Select((XLHolderItem h) => (((Component)h).transform.position, ((Component)h).transform.localPosition)).ToList());
			((ModDataContainer)this).Save();
		}

		public void LoadXlScrap(bool force = false)
		{
			if (!force)
			{
				Dictionary<Vector3, List<(Vector3, Vector3)>> xlHolderLocations = XlHolderLocations;
				if (xlHolderLocations != null && xlHolderLocations.Any())
				{
					return;
				}
			}
			((ModDataContainer)this).Load();
		}
	}
	[DefaultExecutionOrder(101)]
	public class XLHolderItem : PhysicsProp
	{
		public const float MaxRadius = 1.2f;

		public int Id { get; set; }

		public bool MainItemAssigned { get; set; }

		public XLMainItem MainItem { get; private set; }

		public Vector3 GetAnchor()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return MainItem.GetAnchor(Id);
		}

		public void SetMainItem(XLMainItem newMainItem)
		{
			MainItem = newMainItem;
			if (!((Object)(object)MainItem == (Object)null))
			{
				MainItemAssigned = true;
				((GrabbableObject)this).itemProperties.weight = 1f + (((GrabbableObject)MainItem).itemProperties.weight - 1f) / (float)MainItem.HolderItems.Length;
				((GrabbableObject)this).customGrabTooltip = "Hold " + ((GrabbableObject)MainItem).itemProperties.itemName;
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
		}

		public override void Update()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_011c: 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_013d: 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_0143: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if ((Object)(object)MainItem == (Object)null || MainItem.HolderItems == null || !MainItem.HolderItems.Any() || MainItem.HolderItems.Any((XLHolderItem x) => (Object)(object)x == (Object)null))
			{
				return;
			}
			Vector3 anchor = GetAnchor();
			Vector3 val = ((Component)this).transform.position - anchor;
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null))
			{
				Vector3 val2 = ((Component)((GrabbableObject)this).playerHeldBy).transform.position - ((Component)this).transform.position;
				Vector3 val3 = ((GrabbableObject)this).playerHeldBy.serverPlayerPosition - ((Component)this).transform.position;
				if (((Vector3)(ref val)).magnitude > Plugin.Config.MaxHolderRadius.Value)
				{
					((Component)this).transform.position = anchor + ((Vector3)(ref val)).normalized * Plugin.Config.MaxHolderRadius.Value;
					((Component)((GrabbableObject)this).playerHeldBy).transform.position = ((Component)this).transform.position + val2;
					((GrabbableObject)this).playerHeldBy.serverPlayerPosition = ((Component)this).transform.position + val3;
				}
			}
		}

		public override void OnBroughtToShip()
		{
			((GrabbableObject)this).OnBroughtToShip();
			if (!((Object)(object)MainItem == (Object)null))
			{
				MainItem.HolderOnShipGround(this, value: true);
			}
		}

		public override void OnDestroy()
		{
			DropOnClient(isDeleted: true);
			((NetworkBehaviour)this).OnDestroy();
		}

		public override void EquipItem()
		{
			((PhysicsProp)this).EquipItem();
			if (!((Object)(object)MainItem == (Object)null) && !((GrabbableObject)MainItem).hasBeenHeld)
			{
				((GrabbableObject)MainItem).hasBeenHeld = true;
				if (!((GrabbableObject)this).isInShipRoom && !StartOfRound.Instance.inShipPhase && StartOfRound.Instance.currentLevel.spawnEnemiesAndScrap)
				{
					RoundManager instance = RoundManager.Instance;
					instance.valueOfFoundScrapItems += ((GrabbableObject)MainItem).scrapValue;
				}
			}
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			if (!((Object)(object)MainItem == (Object)null))
			{
				MainItem.HolderOnShipGround(this, value: false);
			}
		}

		public void DropOnClient(bool isDeleted = false)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null))
			{
				AccessTools.Method(typeof(PlayerControllerB), "SetSpecialGrabAnimationBool", (Type[])null, (Type[])null).Invoke(((GrabbableObject)this).playerHeldBy, new object[2] { false, this });
				((GrabbableObject)this).playerHeldBy.playerBodyAnimator.SetBool("cancelHolding", true);
				((GrabbableObject)this).playerHeldBy.playerBodyAnimator.SetTrigger("Throw");
				if ((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)(object)StartOfRound.Instance.localPlayerController)
				{
					((Behaviour)HUDManager.Instance.itemSlotIcons[((GrabbableObject)this).playerHeldBy.currentItemSlot]).enabled = false;
					((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
				}
				int num = (int)((Component)((GrabbableObject)this).playerHeldBy).transform.localEulerAngles.y;
				if ((Object)(object)this != (Object)null && !isDeleted)
				{
					((GrabbableObject)this).playerHeldBy.SetObjectAsNoLongerHeld(false, false, ((GrabbableObject)this).targetFloorPosition, (GrabbableObject)(object)this, num);
				}
				else
				{
					((GrabbableObject)this).playerHeldBy.twoHanded = false;
					((GrabbableObject)this).playerHeldBy.twoHandedAnimation = false;
					((GrabbableObject)this).playerHeldBy.carryWeight = Mathf.Clamp(((GrabbableObject)this).playerHeldBy.carryWeight - (((GrabbableObject)this).itemProperties.weight - 1f), 1f, 10f);
					((GrabbableObject)this).playerHeldBy.isHoldingObject = false;
					Traverse.Create((object)((GrabbableObject)this).playerHeldBy).Field("hasThrownObject").SetValue((object)true);
				}
				((GrabbableObject)this).playerHeldBy.currentlyHeldObjectServer = null;
				if (((NetworkBehaviour)this).IsOwner)
				{
					((GrabbableObject)this).DiscardItem();
				}
			}
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "XLHolderItem";
		}
	}
	[DefaultExecutionOrder(100)]
	public class XLMainItem : PhysicsProp
	{
		public const int ExecutionOrder = 100;

		private static Item _holderItemPrefab;

		private NetworkList<NetworkObjectReference> holderNetRefs = new NetworkList<NetworkObjectReference>();

		public Vector3[] Anchors;

		private bool[] groundedInShip;

		private bool first = true;

		private static Item HolderItemPrefab
		{
			get
			{
				if ((Object)(object)_holderItemPrefab != (Object)null)
				{
					return _holderItemPrefab;
				}
				_holderItemPrefab = ((IEnumerable<Item>)StartOfRound.Instance.allItemsList.itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i.spawnPrefab != (Object)null && (Object)(object)i.spawnPrefab.GetComponent<XLHolderItem>() != (Object)null));
				return _holderItemPrefab;
			}
		}

		public XLHolderItem[] HolderItems { get; set; }

		public bool IsTeleporting { get; private set; }

		public override void Start()
		{
			((GrabbableObject)this).Start();
			EnsureRequiredXlPropsSet();
			if (!((NetworkBehaviour)this).IsSpawned)
			{
				return;
			}
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
			{
				if (HolderItems != null)
				{
					InitialiseHoldersClient();
				}
			}
			else if (!LoadHoldersFromSaveServer())
			{
				InitialiseHoldersServer();
			}
		}

		public Vector3 GetAnchor(int id)
		{
			//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)
			return ((Component)this).transform.position + Anchors[id];
		}

		private void EnsureRequiredXlPropsSet()
		{
			((GrabbableObject)this).grabbable = false;
			((GrabbableObject)this).grabbableToEnemies = false;
			((Component)this).gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
			if (!Plugin.Config.XlItemCollision.Value)
			{
				SetCollision(value: false);
			}
		}

		private void SetCollision(bool value)
		{
			Collider[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Collider>();
			if (componentsInChildren != null)
			{
				Collider[] array = componentsInChildren;
				foreach (Collider val in array)
				{
					val.enabled = value;
				}
			}
		}

		private void InitialiseHoldersServer()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0057: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < Anchors.Length; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(HolderItemPrefab.spawnPrefab, ((Component)this).transform.position + Anchors[i], Quaternion.identity, StartOfRound.Instance.propsContainer);
				NetworkObject component = val.GetComponent<NetworkObject>();
				component.Spawn(false);
				holderNetRefs.Add(NetworkObjectReference.op_Implicit(component));
			}
			InitialiseHoldersClientRpc();
		}

		private bool LoadHoldersFromSaveServer()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
			{
				return false;
			}
			if (!StartOfRound.Instance.inShipPhase)
			{
				Plugin.Logger.LogDebug((object)"LoadHoldersFromSaveServer called from outside orbit");
				return false;
			}
			if (!(ModSaveFile.Instance?.XlHolderLocations?.Any()).GetValueOrDefault())
			{
				Plugin.Logger.LogDebug((object)"LoadHoldersFromSaveServer called with empty save data");
				return false;
			}
			int num = -1;
			int num2 = -1;
			Vector3? val = null;
			float num3 = 0f;
			foreach (KeyValuePair<Vector3, List<(Vector3, Vector3)>> xlHolderLocation in ModSaveFile.Instance.XlHolderLocations)
			{
				xlHolderLocation.Deconstruct(out var key, out var _);
				Vector3 val2 = key;
				num++;
				if (!ModSaveFile.Instance.SpawnedKeys.Contains(num))
				{
					float num4 = Vector3.Distance(((Component)this).transform.position, val2);
					if (!val.HasValue || num4 < num3)
					{
						val = val2;
						num3 = num4;
						num2 = num;
					}
				}
			}
			if (!val.HasValue || num2 == -1)
			{
				Plugin.Logger.LogDebug((object)"LoadHoldersFromSaveServer couldn't find matching info in save data");
				return false;
			}
			ModSaveFile.Instance.SpawnedKeys.Add(num2);
			(Vector3, Vector3)[] array = ModSaveFile.Instance.XlHolderLocations[val.Value].ToArray();
			List<XLHolderItem> list = (from x in Object.FindObjectsOfType<XLHolderItem>()
				where (Object)(object)x.MainItem == (Object)null && !x.MainItemAssigned
				select x).ToList();
			if (list.Count < Anchors.Length)
			{
				Plugin.Logger.LogWarning((object)"LoadHoldersFromSaveServer couldn't find enough holders to load in a XL main item");
				ModSaveFile.Instance.SpawnedKeys.Remove(num2);
				return false;
			}
			List<XLHolderItem> list2 = new List<XLHolderItem>();
			(Vector3, Vector3)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				(Vector3, Vector3) holderPosition = array2[i];
				XLHolderItem xLHolderItem = list.Aggregate((XLHolderItem h1, XLHolderItem h2) => (Vector3.Distance(holderPosition.Item1, ((Component)h1).transform.position) < Vector3.Distance(holderPosition.Item1, ((Component)h2).transform.position)) ? h1 : h2);
				list.Remove(xLHolderItem);
				list2.Add(xLHolderItem);
				xLHolderItem.MainItemAssigned = true;
			}
			holderNetRefs.Clear();
			foreach (XLHolderItem item in list2)
			{
				holderNetRefs.Add(NetworkObjectReference.op_Implicit(((Component)item).GetComponent<NetworkObject>()));
			}
			InitialiseHoldersClientRpc();
			return true;
		}

		[ClientRpc]
		private void InitialiseHoldersClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3364911113u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3364911113u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					InitialiseHoldersClient();
				}
			}
		}

		private void InitialiseHoldersClient()
		{
			//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_010f: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsSpawned || holderNetRefs == null || holderNetRefs.Count == 0)
			{
				return;
			}
			HolderItems = new XLHolderItem[holderNetRefs.Count];
			groundedInShip = new bool[holderNetRefs.Count];
			NetworkObject val2 = default(NetworkObject);
			for (int i = 0; i < holderNetRefs.Count; i++)
			{
				NetworkObjectReference val = holderNetRefs[i];
				if (((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null))
				{
					XLHolderItem component = ((Component)val2).gameObject.GetComponent<XLHolderItem>();
					component.SetMainItem(this);
					component.Id = i;
					HolderItems[i] = component;
				}
			}
			((Component)this).transform.position = XLPositionUtils.GetPositionFromHolders(Anchors, HolderItems.Select((XLHolderItem x) => ((Component)x).transform.position).ToArray());
			Quaternion rotation = Quaternion.FromToRotation(Anchors[0], ((Component)HolderItems[0]).transform.position - ((Component)this).transform.position);
			RotateAnchors(rotation);
			Quaternion anchorRotationOffset = GetAnchorRotationOffset();
			RotateBase(anchorRotationOffset);
		}

		public override void Update()
		{
			//IL_00d9: 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_00ea: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if (HolderItems == null || HolderItems.Length == 0)
			{
				if (holderNetRefs.Count == 0 || NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
				{
					return;
				}
				InitialiseHoldersClient();
			}
			if (!HolderItems.Any((XLHolderItem x) => (Object)(object)x == (Object)null) && !IsTeleporting)
			{
				((Component)this).transform.position = GetPositionOffsetFromPoints(Anchors, HolderItems.Select((XLHolderItem x) => ((Component)x).transform.position).ToArray());
				Quaternion anchorRotationOffset = GetAnchorRotationOffset();
				RotateBase(anchorRotationOffset);
				if (first)
				{
					anchorRotationOffset = GetAnchorRotationOffset();
					first = false;
				}
				RotateAnchors(anchorRotationOffset);
			}
		}

		public void HolderOnShipGround(XLHolderItem holder, bool value)
		{
			groundedInShip[holder.Id] = value;
			if (!groundedInShip.Any((bool x) => !x))
			{
				PlayerControllerB playerHeldBy = ((GrabbableObject)holder).playerHeldBy;
				playerHeldBy.SetItemInElevator(playerHeldBy.isInHangarShipRoom, playerHeldBy.isInElevator, (GrabbableObject)(object)this);
			}
		}

		private Quaternion GetAnchorRotationOffset()
		{
			//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)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)HolderItems[0]).transform.position;
			Vector3 val = ((Component)this).transform.position - position;
			return Quaternion.FromToRotation(((Component)this).transform.forward, val);
		}

		private void RotateBase(Quaternion rotation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.forward = rotation * ((Component)this).transform.forward;
		}

		private void RotateAnchors(Quaternion rotation)
		{
			//IL_000d: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < Anchors.Length; i++)
			{
				Anchors[i] = rotation * Anchors[i];
			}
		}

		public Vector3 GetPositionOffsetFromPoints(IList<Vector3> anchors, IList<Vector3> points)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)this).transform.position + (from i in Enumerable.Range(0, anchors.Count())
				select points[i] - (((Component)this).transform.position + anchors[i])).Average();
		}

		public void SetPositionWithHolders(Vector3 destVector)
		{
			//IL_0007: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.position = destVector;
			if (HolderItems != null)
			{
				Vector3[] holderPositionsAt = XLPositionUtils.GetHolderPositionsAt(Anchors, destVector);
				for (int i = 0; i < HolderItems.Length; i++)
				{
					((Component)HolderItems[i]).transform.position = holderPositionsAt[i];
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SetOnCounterServerRpc(Vector3 counterPos)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2748708732u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref counterPos);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2748708732u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					SetOnCounterClientRpc(counterPos);
				}
			}
		}

		[ClientRpc]
		public void SetOnCounterClientRpc(Vector3 counterPos)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1391903525u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref counterPos);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1391903525u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				DepositItemsDesk val3 = Object.FindFirstObjectByType<DepositItemsDesk>();
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)this).transform.SetParent(((Component)val3.deskObjectsContainer).transform, true);
				}
				((Component)this).transform.localPosition = counterPos;
				((GrabbableObject)this).targetFloorPosition = counterPos;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void TeleportXlScrapServerRpc(NetworkObjectReference teleportNetRef, int playerObj)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_013b: 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_0144: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_0215: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2378562987u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref teleportNetRef, default(ForNetworkSerializable));
				BytePacker.WriteValueBitPacked(val2, playerObj);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2378562987u, val, (RpcDelivery)0);
			}
			NetworkObject val3 = default(NetworkObject);
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || !((NetworkObjectReference)(ref teleportNetRef)).TryGet(ref val3, (NetworkManager)null))
			{
				return;
			}
			EntranceTeleport component = ((Component)val3).gameObject.GetComponent<EntranceTeleport>();
			IsTeleporting = true;
			Plugin.Logger.LogDebug((object)$"Attempting to teleport XL Scrap: {((Component)this).transform.position}");
			Vector3 forward = component.exitPoint.forward;
			Vector3 val4 = ((Vector3)(ref forward)).normalized;
			if (component.isEntranceToBuilding && component.entranceId > 0)
			{
				val4 *= -1f;
			}
			Vector3 value = component.exitPoint.position + new Vector3(0f, 2f, 0f) + val4 * (Anchors.Max((Vector3 x) => ((Vector3)(ref x)).magnitude) + 1f);
			if (!XLSpawner.CorrectToValidPosition(this, value))
			{
				IsTeleporting = false;
				Plugin.Logger.LogWarning((object)"Failed to teleport XL Scrap:");
				NotifyTeleportFailClientRpc(playerObj);
			}
			else
			{
				TeleportWithXlScrapClientRpc(playerObj, teleportNetRef, ((Component)this).transform.position, HolderItems.Select((XLHolderItem x) => ((Component)x).transform.position).ToArray());
			}
		}

		[ClientRpc]
		public void TeleportWithXlScrapClientRpc(int playerObj, NetworkObjectReference teleportNetRef, Vector3 xlMainPos, Vector3[] xlHoldersPos)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3049506443u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerObj);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref teleportNetRef, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref xlMainPos);
				bool flag = xlHoldersPos != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(xlHoldersPos);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3049506443u, val, (RpcDelivery)0);
			}
			NetworkObject val3 = default(NetworkObject);
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost) || !((NetworkObjectReference)(ref teleportNetRef)).TryGet(ref val3, (NetworkManager)null))
			{
				return;
			}
			EntranceTeleport component = ((Component)val3).gameObject.GetComponent<EntranceTeleport>();
			((Component)this).transform.position = xlMainPos;
			((GrabbableObject)this).isInFactory = component.isEntranceToBuilding;
			if (HolderItems == null || HolderItems.Length < xlHoldersPos.Length)
			{
				return;
			}
			for (int i = 0; i < HolderItems.Length; i++)
			{
				XLHolderItem xLHolderItem = HolderItems[i];
				xLHolderItem.DropOnClient();
				((Component)xLHolderItem).transform.position = xlHoldersPos[i];
				((GrabbableObject)xLHolderItem).isInFactory = component.isEntranceToBuilding;
				((GrabbableObject)xLHolderItem).startFallingPosition = ((Component)xLHolderItem).transform.localPosition;
				((GrabbableObject)xLHolderItem).FallToGround(false);
			}
			((GrabbableObject)this).EnableItemMeshes(true);
			StartOfRound.Instance.allPlayerScripts[playerObj].TeleportPlayer(((Component)component.exitPoint).transform.position, true, component.exitPoint.eulerAngles.y, false, true);
			IsTeleporting = false;
			if (playerObj != (int)GameNetworkManager.Instance.localPlayerController.playerClientId)
			{
				return;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			localPlayerController.isInElevator = false;
			localPlayerController.isInHangarShipRoom = false;
			localPlayerController.isInsideFactory = component.isEntranceToBuilding;
			GrabbableObject[] itemSlots = localPlayerController.ItemSlots;
			foreach (GrabbableObject val4 in itemSlots)
			{
				if (!((Object)(object)val4 == (Object)null))
				{
					val4.isInFactory = component.isEntranceToBuilding;
				}
			}
		}

		[ClientRpc]
		public void NotifyTeleportFailClientRpc(int playerObj)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(260694087u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerObj);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 260694087u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && playerObj == (int)GameNetworkManager.Instance.localPlayerController.playerClientId)
				{
					HUDManager.Instance.DisplayStatusEffect("Insufficient space detected for XL Scrap on other side");
				}
			}
		}

		protected override void __initializeVariables()
		{
			if (holderNetRefs == null)
			{
				throw new Exception("XLMainItem.holderNetRefs cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)holderNetRefs).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)holderNetRefs, "holderNetRefs");
			((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)holderNetRefs);
			((PhysicsProp)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_XLMainItem()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3364911113u, new RpcReceiveHandler(__rpc_handler_3364911113));
			NetworkManager.__rpc_func_table.Add(2748708732u, new RpcReceiveHandler(__rpc_handler_2748708732));
			NetworkManager.__rpc_func_table.Add(1391903525u, new RpcReceiveHandler(__rpc_handler_1391903525));
			NetworkManager.__rpc_func_table.Add(2378562987u, new RpcReceiveHandler(__rpc_handler_2378562987));
			NetworkManager.__rpc_func_table.Add(3049506443u, new RpcReceiveHandler(__rpc_handler_3049506443));
			NetworkManager.__rpc_func_table.Add(260694087u, new RpcReceiveHandler(__rpc_handler_260694087));
		}

		private static void __rpc_handler_3364911113(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((XLMainItem)(object)target).InitialiseHoldersClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2748708732(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 onCounterServerRpc = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref onCounterServerRpc);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((XLMainItem)(object)target).SetOnCounterServerRpc(onCounterServerRpc);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1391903525(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 onCounterClientRpc = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref onCounterClientRpc);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((XLMainItem)(object)target).SetOnCounterClientRpc(onCounterClientRpc);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2378562987(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: 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_003e: 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_005c: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkObjectReference teleportNetRef = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref teleportNetRef, default(ForNetworkSerializable));
				int playerObj = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerObj);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((XLMainItem)(object)target).TeleportXlScrapServerRpc(teleportNetRef, playerObj);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3049506443(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerObj = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerObj);
				NetworkObjectReference teleportNetRef = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref teleportNetRef, default(ForNetworkSerializable));
				Vector3 xlMainPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref xlMainPos);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				Vector3[] xlHoldersPos = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref xlHoldersPos);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((XLMainItem)(object)target).TeleportWithXlScrapClientRpc(playerObj, teleportNetRef, xlMainPos, xlHoldersPos);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_260694087(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerObj = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerObj);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((XLMainItem)(object)target).NotifyTeleportFailClientRpc(playerObj);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "XLMainItem";
		}
	}
	public struct XLSimpleMainItem
	{
		public Vector3 Position { get; set; }

		public Vector3[] Anchors { get; set; }

		public Vector3[] HolderPositions { get; set; }

		public XLSimpleMainItem(XLMainItem xlMain)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Position = ((Component)xlMain).transform.position;
			Anchors = xlMain.Anchors.ToArray();
			HolderPositions = ((xlMain.HolderItems == null) ? null : xlMain.HolderItems.Select((XLHolderItem x) => ((Component)x).transform.position).ToArray());
		}
	}
}
namespace XlScrapApi
{
	public class ConfigValues
	{
		public ConfigEntry<float> MaxHolderRadius { get; private set; }

		public ConfigEntry<bool> XlItemCollision { get; private set; }

		public ConfigValues(ConfigFile configFile)
		{
			MaxHolderRadius = configFile.Bind<float>("Experimental", "Max Holder Radius", 1.2f, "Maximum radius that holders can be from their anchor points. May be moved to be item-specific in the future.");
			XlItemCollision = configFile.Bind<bool>("Experimental", "XL Item Collision", false, "Whether players have collision with XL Items. Note that enabling this can lead to buggy behaviour like clipping.");
			ClearUnusedEntries(configFile);
		}

		private void ClearUnusedEntries(ConfigFile configFile)
		{
			PropertyInfo property = ((object)configFile).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(configFile, null);
			dictionary.Clear();
			configFile.Save();
		}
	}
}
internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T>
	{
		object IEnumerator.Current => _item;

		T IEnumerator<T>.Current => _item;

		public Enumerator(T item)
		{
			_item = item;
		}

		bool IEnumerator.MoveNext()
		{
			return !_moveNextCalled && (_moveNextCalled = true);
		}

		void IEnumerator.Reset()
		{
			_moveNextCalled = false;
		}

		void IDisposable.Dispose()
		{
		}
	}

	int ICollection.Count => 1;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => 1;

	T IReadOnlyList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
	}

	int ICollection<T>.Count => 1;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlySingleElementList(T item)
	{
		_item = item;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection.CopyTo(Array array, int index)
	{
		array.SetValue(_item, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return EqualityComparer<T>.Default.Equals(_item, (T)value);
	}

	int IList.IndexOf(object value)
	{
		return (!EqualityComparer<T>.Default.Equals(_item, (T)value)) ? (-1) : 0;
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return EqualityComparer<T>.Default.Equals(_item, item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		array[arrayIndex] = _item;
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return (!EqualityComparer<T>.Default.Equals(_item, item)) ? (-1) : 0;
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
namespace XLScrapApi.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}