Decompiled source of XL Scrap Api v0.1.1

XLScrapApi.dll

Decompiled 3 days 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.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+023968e3e57d966b850da18a4aece9cc2cc3cdee")]
[assembly: AssemblyProduct("XL Scrap API")]
[assembly: AssemblyTitle("XLScrapApi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.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.1.1")]
	[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.1.1) 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.1.1) 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.1.1";
	}
}
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;
		}
	}
}
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 xLMainItem))
			{
				return true;
			}
			if (!xLMainItem.CorrectToValidPosition())
			{
				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.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
{
	[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayerClientRpc")]
	public class TeleportPlayerClientPatch
	{
		private static bool ShouldSkipTeleport(int playerObj)
		{
			GrabbableObject currentlyHeldObjectServer = StartOfRound.Instance.allPlayerScripts[playerObj].currentlyHeldObjectServer;
			return currentlyHeldObjectServer is XLHolderItem;
		}

		[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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlayerControllerB), "TeleportPlayer", (Type[])null, (Type[])null), (string)null)
			});
			val.Advance(1);
			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.Ldelem_Ref, (object)null, (string)null)
			});
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)
			});
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(TeleportPlayerClientPatch), "ShouldSkipTeleport", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Brtrue, (object)label)
			});
			return val.InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayerServerRpc")]
	public class TeleportPlayerServerPatch
	{
		[HarmonyPrefix]
		public static void Prefix(EntranceTeleport __instance, int playerObj)
		{
			PlayerControllerB val = __instance.playersManager.allPlayerScripts[playerObj];
			if (!((Object)(object)val.currentlyHeldObjectServer == (Object)null) && val.currentlyHeldObjectServer is XLHolderItem xLHolderItem)
			{
				XLMainItem mainItem = xLHolderItem.MainItem;
				if (mainItem != null && mainItem.HolderItems != null)
				{
					mainItem.TeleportXlScrapServer(__instance, playerObj);
					return;
				}
			}
			Plugin.Logger.LogDebug((object)"TeleportXlScrap Initial Invalid");
		}
	}
}
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 const float MaxSpawnDiff = 20f;

		private const int MaxFailedCorrectionAttempts = 3;

		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; }

		private static int HolderLinecastMask => StartOfRound.Instance.collidersAndRoomMaskAndDefault;

		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_010a: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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 = GetPositionFromHolders(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();
		}

		private void ShiftPositionWithHolders(Vector3 shiftVector)
		{
			//IL_0008: 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)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)this).transform;
			transform.position += shiftVector;
			if (HolderItems != null)
			{
				XLHolderItem[] holderItems = HolderItems;
				foreach (XLHolderItem xLHolderItem in holderItems)
				{
					Transform transform2 = ((Component)xLHolderItem).transform;
					transform2.position += shiftVector;
				}
			}
		}

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

		public Vector3 GetPositionFromHolders(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 void TeleportXlScrapServer(EntranceTeleport teleport, int playerObj)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			IsTeleporting = true;
			Plugin.Logger.LogDebug((object)$"Attempting to teleport XL Scrap: {((Component)this).transform.position}");
			Vector3 position = ((Component)this).transform.position;
			Vector3 forward = teleport.exitPoint.forward;
			Vector3 val = ((Vector3)(ref forward)).normalized;
			if (teleport.isEntranceToBuilding && teleport.entranceId > 0)
			{
				val *= -1f;
			}
			SetPositionWithHolders(teleport.exitPoint.position + new Vector3(0f, 2f, 0f) + val * (Anchors.Max((Vector3 x) => ((Vector3)(ref x)).magnitude) + 1f));
			if (!CorrectToValidPosition())
			{
				Plugin.Logger.LogDebug((object)$"Failed to teleport XL Scrap: {((Component)this).transform.position}");
				SetPositionWithHolders(position);
				Plugin.Logger.LogDebug((object)$"Reset to: {((Component)this).transform.position}");
				IsTeleporting = false;
			}
			else
			{
				TeleportWithXlScrapClientRpc(playerObj, ((Component)teleport.exitPoint).transform.position, teleport.exitPoint.eulerAngles.y, ((Component)this).transform.position, HolderItems.Select((XLHolderItem x) => ((Component)x).transform.position).ToArray());
			}
		}

		[ClientRpc]
		public void TeleportWithXlScrapClientRpc(int playerObj, Vector3 teleportPos, float teleportRot, 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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(3216282151u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerObj);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref teleportPos);
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref teleportRot, default(ForPrimitives));
				((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, 3216282151u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			((Component)this).transform.position = xlMainPos;
			if (HolderItems != null && HolderItems.Length >= xlHoldersPos.Length)
			{
				for (int i = 0; i < HolderItems.Length; i++)
				{
					XLHolderItem xLHolderItem = HolderItems[i];
					xLHolderItem.DropOnClient();
					((Component)xLHolderItem).transform.position = xlHoldersPos[i];
					((GrabbableObject)xLHolderItem).startFallingPosition = ((Component)xLHolderItem).transform.localPosition;
					((GrabbableObject)xLHolderItem).FallToGround(false);
				}
				StartOfRound.Instance.allPlayerScripts[playerObj].TeleportPlayer(teleportPos, true, teleportRot, false, true);
				IsTeleporting = false;
			}
		}

		public bool CorrectToValidPosition()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			for (int i = 0; i < 3; i++)
			{
				List<Vector3> realAnchors = Anchors.Select((Vector3 a) => a + ((Component)this).transform.position).ToList();
				if (CheckValidPosition(realAnchors, out var correction))
				{
					Plugin.Logger.LogDebug((object)$"Valid position at {((Component)this).transform.position}");
					return true;
				}
				Plugin.Logger.LogDebug((object)$"Invalid position at {((Component)this).transform.position}: {correction}");
				switch (correction)
				{
				case CorrectionType.Wall:
					CorrectValidWallPosition(realAnchors);
					break;
				case CorrectionType.Floor:
					CorrectValidFloorPosition(realAnchors);
					break;
				default:
					Plugin.Logger.LogWarning((object)"Invalid position without correction type specified!");
					break;
				}
			}
			SetPositionWithHolders(position);
			return false;
		}

		private void CorrectValidWallPosition(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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: 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;
			ShiftPositionWithHolders(num7 * ((RaycastHit)(ref val)).normal);
		}

		private void CorrectValidFloorPosition(List<Vector3> realAnchors)
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_0157: 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)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3?> list = realAnchors.Select((Vector3 x) => x.FloorVector()).ToList();
			Plugin.Logger.LogDebug((object)("Correcting floor (FLOORED): [" + string.Join(",", list) + "]"));
			if (list.All((Vector3? x) => !x.HasValue))
			{
				float num = Anchors.Max((Vector3 a) => ((Vector3)(ref a)).magnitude);
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				ShiftPositionWithHolders(Vector2.op_Implicit(((Vector2)(ref insideUnitCircle)).normalized) * (num + 1f));
				Plugin.Logger.LogDebug((object)$"Correcting floor (RANDOM END): {((Component)this).transform.position}");
				return;
			}
			Vector3 val = Vector3.zero;
			for (int i = 0; i < list.Count; i++)
			{
				Vector3? val2 = list[i];
				Plugin.Logger.LogDebug((object)$"Correcting floor (ADD DIRECTION): {val2}, {Anchors[i]} on {val2}");
				if (val2.HasValue)
				{
					val += Anchors[i];
				}
			}
			((Vector3)(ref val)).Normalize();
			Plugin.Logger.LogDebug((object)$"Correcting floor (DIRECTION): {val}");
			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 - ((Component)this).transform.position;
				float num4 = Vector3.Dot(val, 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);
			Plugin.Logger.LogDebug((object)$"Correcting floor (MAGNITUDE): {num5}");
			ShiftPositionWithHolders(val * num5);
			Plugin.Logger.LogDebug((object)$"Correcting floor (END): {((Component)this).transform.position}");
		}

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

		private bool CheckAnchorIntersections(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 bool CheckFloorPositions(List<Vector3> realAnchors, out CorrectionType? correction)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			correction = null;
			Vector3? val = ((Component)this).transform.position.FloorVector();
			if (!val.HasValue || Vector3.Distance(val.Value, ((Component)this).transform.position) > 20f)
			{
				Plugin.Logger.LogDebug((object)$"Main floor not good: {((Component)this).transform.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 = GetPositionFromHolders(list2);
			if (Vector3.Distance(positionFromHolders, ((Component)this).transform.position) > 20f)
			{
				Plugin.Logger.LogDebug((object)$"New position too far away: {((Component)this).transform.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 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;
		}

		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
			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(3216282151u, new RpcReceiveHandler(__rpc_handler_3216282151));
		}

		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_3216282151(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_004f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00cc: 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);
				Vector3 teleportPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref teleportPos);
				float teleportRot = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref teleportRot, default(ForPrimitives));
				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, teleportPos, teleportRot, xlMainPos, xlHoldersPos);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "XLMainItem";
		}
	}
}
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
	{
	}
}