Decompiled source of FireSale v1.0.1

FireSale.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using FireSale.Configuration;
using FireSale.EntityHelpers;
using FireSale.HelperFunctions;
using FireSale.Networking;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FireSale")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("On scan within the ship, items in the ship will be organized.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a421de37c6795b65ba4eabf1c7393fb0dea4b858")]
[assembly: AssemblyProduct("FireSale")]
[assembly: AssemblyTitle("FireSale")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 FireSale
{
	[HarmonyPatch]
	internal class FireSaleFunctions
	{
		public static Vector3 GetDepositCounterLocation()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return GameObject.Find("/BellDinger").gameObject.transform.position;
		}

		public static bool OnCompanyPlanet()
		{
			return (Object)(object)GameObject.Find("/Environment/Map/CompanyPlanet") != (Object)null;
		}

		internal static void RetrieveAllLoot()
		{
			if (OnCompanyPlanet())
			{
				HangarShipHelper hangarShipHelper = new HangarShipHelper();
				if (Keybinds.localPlayerController.isInHangarShipRoom)
				{
					List<GrabbableObject> list = ScrapHelperFunctions.FindAllScrapOnMap();
					if (list.Where((GrabbableObject obj) => !obj.isInShipRoom).Any())
					{
						FireSale.Log("--------------- Move Items to Ship ----------");
						foreach (GrabbableObject item in list)
						{
							if (!item.isInShipRoom)
							{
								hangarShipHelper.MoveItemToShip(item);
							}
						}
					}
					FireSale.Log("--------------- Organize Ship Loot ----------");
					LootOrganizingFunctions.OrganizeShipLoot();
				}
				else
				{
					FireSale.Log("--------------- Move Items To Player ----------");
					MoveObjectsToDeskArea(hangarShipHelper);
				}
			}
			else
			{
				FireSale.Log("No actions allowed off company planet");
			}
		}

		private static void MoveObjectsToDeskArea(HangarShipHelper hsh)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			Vector3 depositCounterLocation = GetDepositCounterLocation();
			List<GrabbableObject> list = ScrapHelperFunctions.SortByValue(hsh.ObjectsInShip(), ascending: false);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(depositCounterLocation.x + 1f, depositCounterLocation.y, depositCounterLocation.z - 2f);
			int num = 0;
			float num2 = 1f;
			Vector3 placementPosition = default(Vector3);
			for (int i = 0; i < list.Count; i++)
			{
				GrabbableObject obj = list[i];
				int num3 = i / 10;
				((Vector3)(ref placementPosition))..ctor(val.x + num2, val.y, val.z + (float)num3);
				NetworkFunctions.NetworkingObjectManager.MakeObjectFallRpc(obj, placementPosition, shipParent: true);
				if (num3 != num)
				{
					num2 = 1f;
					num = num3;
				}
				else
				{
					num2 += 1f;
				}
				FireSale.Log($"XCounter: {num2} - tenPercentStep: {num3} - i: {i}");
			}
		}
	}
	[BepInPlugin("FireSale", "FireSale", "1.0.1")]
	internal class FireSale : BaseUnityPlugin
	{
		public static FireSale instance;

		private const string GUID = "FireSale";

		private const string NAME = "FireSale";

		private const string VERSION = "1.0.1";

		public static void Log(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
		}

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			ConfigSettings.BindConfigSettings();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin FireSale is loaded!");
			new Harmony("FireSale").PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FireSale";

		public const string PLUGIN_NAME = "FireSale";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace FireSale.Patchers
{
	internal class TerminalPatcher
	{
		[HarmonyPatch(typeof(Terminal), "Start")]
		private static class Patch
		{
			[HarmonyPrefix]
			private static void AddToTerminalObject(Terminal __instance)
			{
				((Component)__instance).gameObject.AddComponent<NetworkFunctions.NetworkingObjectManager>();
			}
		}
	}
}
namespace FireSale.Networking
{
	internal class NetworkFunctions
	{
		public class NetworkingObjectManager : NetworkBehaviour
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static HandleNamedMessageDelegate <>9__3_0;

				internal void <NetworkManagerInit>b__3_0(ulong senderClientId, FastBufferReader reader)
				{
					//IL_0013: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					//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_0057: Unknown result type (might be due to invalid IL or missing references)
					if (senderClientId != localPlayerController.playerClientId)
					{
						NetworkObjectReference val = default(NetworkObjectReference);
						((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref val, default(ForNetworkSerializable));
						Vector3 placementPosition = default(Vector3);
						((FastBufferReader)(ref reader)).ReadValueSafe(ref placementPosition);
						bool shipParent = default(bool);
						((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref shipParent, default(ForPrimitives));
						NetworkObject val2 = default(NetworkObject);
						if (((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null))
						{
							GrabbableObject component = ((Component)val2).GetComponent<GrabbableObject>();
							GetNetworkingObjectManager().MakeObjectFall(component, placementPosition, shipParent);
						}
					}
				}
			}

			public static PlayerControllerB localPlayerController;

			public static NetworkingObjectManager GetNetworkingObjectManager()
			{
				GameObject val = GameObject.Find("/Environment/HangarShip/Terminal");
				if ((Object)(object)val != (Object)null)
				{
					FireSale.Log("Terminal found " + ((Object)val).name);
					return val.GetComponentInChildren<NetworkingObjectManager>();
				}
				return null;
			}

			public static void MakeObjectFallRpc(GrabbableObject obj, Vector3 placementPosition, bool shipParent)
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				NetworkingObjectManager networkingObjectManager = GetNetworkingObjectManager();
				if ((Object)(object)networkingObjectManager != (Object)null)
				{
					FireSale.Log("NetworkingObjectManager - Network behavior found " + ((Object)networkingObjectManager).name);
					networkingObjectManager.RunClientRpc(NetworkObjectReference.op_Implicit(((NetworkBehaviour)obj).NetworkObject), placementPosition, shipParent);
				}
				else
				{
					FireSale.Log("NetworkingObjectManager not found ");
				}
			}

			public static void NetworkManagerInit()
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				FireSale.Log("Registering named message");
				CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
				object obj = <>c.<>9__3_0;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = delegate(ulong senderClientId, FastBufferReader reader)
					{
						//IL_0013: Unknown result type (might be due to invalid IL or missing references)
						//IL_0019: Unknown result type (might be due to invalid IL or missing references)
						//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_0057: Unknown result type (might be due to invalid IL or missing references)
						if (senderClientId != localPlayerController.playerClientId)
						{
							NetworkObjectReference val2 = default(NetworkObjectReference);
							((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref val2, default(ForNetworkSerializable));
							Vector3 placementPosition = default(Vector3);
							((FastBufferReader)(ref reader)).ReadValueSafe(ref placementPosition);
							bool shipParent = default(bool);
							((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref shipParent, default(ForPrimitives));
							NetworkObject val3 = default(NetworkObject);
							if (((NetworkObjectReference)(ref val2)).TryGet(ref val3, (NetworkManager)null))
							{
								GrabbableObject component = ((Component)val3).GetComponent<GrabbableObject>();
								GetNetworkingObjectManager().MakeObjectFall(component, placementPosition, shipParent);
							}
						}
					};
					<>c.<>9__3_0 = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("MakeObjectFallFireSale", (HandleNamedMessageDelegate)obj);
			}

			[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
			[HarmonyPostfix]
			public static void OnLocalPlayerConnect(PlayerControllerB __instance)
			{
				localPlayerController = __instance;
				if (((NetworkBehaviour)localPlayerController).IsClient)
				{
					NetworkManagerInit();
				}
			}

			public void MakeObjectFall(GrabbableObject obj, Vector3 placementPosition, bool shipParent)
			{
				//IL_001e: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: 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_0113: 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_0142: 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_015b: 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_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)
				GameObject val = GameObject.Find("/Environment/HangarShip");
				GameObject val2 = GameObject.Find("/Environment/HangarShip/StorageCloset");
				string empty = string.Empty;
				Vector3 val3 = default(Vector3);
				if (shipParent)
				{
					if ((Object)(object)((Component)obj).gameObject.transform.GetParent() == (Object)null || ((Object)((Component)obj).gameObject.transform.GetParent()).name != "HangarShip")
					{
						((Component)obj).gameObject.transform.SetParent(val.transform);
					}
					val3 = val.transform.position;
					empty = "ship";
				}
				else
				{
					if ((Object)(object)((Component)obj).gameObject.transform.GetParent() == (Object)null || ((Object)((Component)obj).gameObject.transform.GetParent()).name != "StorageCloset")
					{
						((Component)obj).gameObject.transform.SetParent(val2.transform);
					}
					val3 = val2.transform.position;
					empty = "storage";
				}
				FireSale.Log($"Request to make GrabbableObject {((Object)obj).name} fall to ground in {empty} - {val3.x},{val3.y},{val3.z}");
				((Component)obj).gameObject.transform.SetPositionAndRotation(placementPosition, ((Component)obj).transform.rotation);
				obj.hasHitGround = false;
				obj.startFallingPosition = placementPosition;
				if ((Object)(object)((Component)obj).transform.parent != (Object)null)
				{
					obj.startFallingPosition = ((Component)obj).transform.parent.InverseTransformPoint(obj.startFallingPosition);
				}
				obj.FallToGround(false);
			}

			[ClientRpc]
			public void MakeObjectFallClientRpc(NetworkObjectReference obj, Vector3 placementPosition, bool shipParent)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: 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_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
				if (networkManager == null || !networkManager.IsListening)
				{
					return;
				}
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(ref obj, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref placementPosition);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref shipParent, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("MakeObjectFallFireSale", val, (NetworkDelivery)2);
				NetworkObject val2 = default(NetworkObject);
				if (((NetworkObjectReference)(ref obj)).TryGet(ref val2, (NetworkManager)null))
				{
					GrabbableObject component = ((Component)val2).GetComponent<GrabbableObject>();
					if (!((NetworkBehaviour)this).IsOwner)
					{
						MakeObjectFall(component, placementPosition, shipParent);
					}
				}
			}

			[ServerRpc]
			public void MakeObjectFallServerRpc(NetworkObjectReference obj, Vector3 placementPosition, bool shipParent)
			{
				//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_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_0080: 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_0028: Invalid comparison between Unknown and I4
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
				if (networkManager == null || !networkManager.IsListening)
				{
					return;
				}
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(ref obj, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref placementPosition);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref shipParent, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("MakeObjectFallFireSale", val, (NetworkDelivery)2);
				NetworkObject val2 = default(NetworkObject);
				if (((NetworkObjectReference)(ref obj)).TryGet(ref val2, (NetworkManager)null))
				{
					GrabbableObject component = ((Component)val2).GetComponent<GrabbableObject>();
					if (!((NetworkBehaviour)this).IsOwner)
					{
						MakeObjectFall(component, placementPosition, shipParent);
					}
				}
			}

			[ClientRpc]
			public void RunClientRpc(NetworkObjectReference obj, Vector3 placementPosition, bool shipParent)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				MakeObjectFallServerRpc(obj, placementPosition, shipParent);
			}
		}
	}
}
namespace FireSale.HelperFunctions
{
	public class LootOrganizingFunctions
	{
		private static List<string> ItemsForStorageCloset = ConfigSettings.ClosetLocationOverride.GetStrings(ConfigSettings.ClosetLocationOverride.Key.Value);

		private static List<string> SortingBlacklist = ConfigSettings.SortingLocationBlacklist.GetStrings(ConfigSettings.SortingLocationBlacklist.Key.Value);

		public static void OrganizeShipLoot()
		{
			StorageClosetHelper storageClosetHelper = new StorageClosetHelper();
			List<GrabbableObject> list = new HangarShipHelper().ObjectsInShip();
			foreach (GrabbableObject item in storageClosetHelper.GetObjectsInStorageCloset())
			{
				if (list.Contains(item))
				{
					list.Remove(item);
				}
			}
			List<GrabbableObject> list2 = new List<GrabbableObject>();
			List<GrabbableObject> list3 = new List<GrabbableObject>();
			foreach (GrabbableObject item2 in list)
			{
				if (item2.itemProperties.twoHanded)
				{
					list2.Add(item2);
				}
				else
				{
					list3.Add(item2);
				}
			}
			OrganizeItems(storageClosetHelper, list3, twoHanded: false);
			OrganizeItems(storageClosetHelper, list2, twoHanded: true);
		}

		public static void OrganizeStorageCloset()
		{
			StorageClosetHelper storageClosetHelper = new StorageClosetHelper();
			List<GrabbableObject> objectsInStorageCloset = storageClosetHelper.GetObjectsInStorageCloset();
			List<string> list = new List<string>();
			foreach (GrabbableObject item in objectsInStorageCloset)
			{
				if (!list.Contains(((Object)item).name))
				{
					list.Add(((Object)item).name);
				}
			}
			foreach (string objectType in list)
			{
				List<GrabbableObject> list2 = objectsInStorageCloset.Where((GrabbableObject obj) => ((Object)obj).name.Contains(objectType)).ToList();
				if ((Object)(object)((IEnumerable<GrabbableObject>)list2).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject obj) => !obj.isHeld)) != (Object)null)
				{
					storageClosetHelper.PlaceStorageObjectOnShelve(list2);
				}
			}
		}

		private static float GetXOffsetFromScrapValue(GrabbableObject obj, float highestScrapValue, float maxXOffset)
		{
			return (float)(obj.scrapValue - 10) / highestScrapValue * maxXOffset;
		}

		private static void OrganizeItems(StorageClosetHelper sch, List<GrabbableObject> objects, bool twoHanded)
		{
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			HangarShipHelper hangarShipHelper = new HangarShipHelper();
			List<string> list = new List<string>();
			foreach (GrabbableObject @object in objects)
			{
				if (!list.Contains(((Object)@object).name))
				{
					list.Add(((Object)@object).name);
				}
			}
			float num = 0f;
			float num2 = 2.25f / (float)list.Count;
			float num3 = 0f;
			float num4 = 2.75f / (float)list.Count;
			float num5 = 7f;
			bool flag = false;
			float num6 = 0f;
			float num7 = 0f;
			if (twoHanded)
			{
				if (ConfigSettings.TwoHandedItemLocation.Key.Value == "Front")
				{
					num7 = num3;
					num6 = num2;
					flag = true;
				}
				else
				{
					num7 = num5;
					num6 = num4;
				}
			}
			else if (ConfigSettings.TwoHandedItemLocation.Key.Value == "Front")
			{
				num6 = num4;
				num7 = num5;
			}
			else
			{
				num7 = num3;
				num6 = num2;
				flag = true;
			}
			int num8 = 0;
			Vector3 val = default(Vector3);
			foreach (string objectType in list)
			{
				List<GrabbableObject> list2 = objects.Where((GrabbableObject obj) => ((Object)obj).name.Contains(objectType)).ToList();
				if (ItemsForStorageCloset.Where(objectType.Contains).Any())
				{
					sch.PlaceStorageObjectOnShelve(list2);
				}
				else
				{
					if (SortingBlacklist.Where(objectType.Contains).Any())
					{
						continue;
					}
					GrabbableObject? obj2 = ((IEnumerable<GrabbableObject>)list2).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject obj) => !obj.isHeld));
					List<float> list3 = new List<float>();
					if (ConfigSettings.OrganizationTechnique.Key.Value == "Stack")
					{
						Random random = new Random();
						num = (float)random.NextDouble() * (float)random.Next(-1, 2);
						if (ConfigSettings.ItemGrouping.Key.Value == "Loose")
						{
							num *= 2f;
						}
					}
					if (!((Object)(object)obj2 != (Object)null))
					{
						continue;
					}
					((Vector3)(ref val))..ctor(hangarShipHelper.GetShipCenterLocation().x, hangarShipHelper.GetShipCenterLocation().y, hangarShipHelper.GetShipCenterLocation().z);
					if (ConfigSettings.ItemGrouping.Key.Value == "Loose")
					{
						val.z -= num6 * (float)num8;
					}
					else
					{
						val.z -= num6 * (float)num8 * 0.1f + num6 * 0.9f * (float)list.Count;
					}
					if (!flag)
					{
						val.z += 0.5f;
					}
					foreach (GrabbableObject item in list2)
					{
						if (item.isHeld)
						{
							continue;
						}
						val.x = hangarShipHelper.GetShipCenterLocation().x + num7;
						if (ConfigSettings.OrganizationTechnique.Key.Value == "Value")
						{
							if (flag)
							{
								val.x += GetXOffsetFromScrapValue(item, ScrapHelperFunctions.CalculateHighestScrapValue(hangarShipHelper.ObjectsInShip()), 2.5f);
							}
							else
							{
								val.x += GetXOffsetFromScrapValue(item, ScrapHelperFunctions.CalculateHighestScrapValue(hangarShipHelper.ObjectsInShip()), 4f);
							}
							while (list3.Contains(val.x))
							{
								val.x += 0.1f;
							}
							list3.Add(val.x);
						}
						else
						{
							val.x += num;
						}
						if (!hangarShipHelper.IsPositionWithinShip(val))
						{
							val = hangarShipHelper.AdjustPositionWithinShip(val);
						}
						if (!PositionHelperFunctions.SameLocation(((Component)item).transform.position, val))
						{
							FireSale.Log($"Moving item to ship - {((Object)item).name} - {val.x},{val.y},{val.z}");
							NetworkFunctions.NetworkingObjectManager.MakeObjectFallRpc(item, val, shipParent: true);
							if (!hangarShipHelper.IsObjectWithinShip(item))
							{
								FireSale.Log("Found item outside of the ship - " + ((Object)item).name);
							}
						}
					}
					num8++;
				}
			}
			OrganizeStorageCloset();
		}
	}
	public static class PositionHelperFunctions
	{
		public static Vector3 AdjustPositionWithinBounds(Vector3 targetPosition, Vector3 min, Vector3 max)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			if (targetPosition.x > max.x)
			{
				targetPosition.x = max.x;
			}
			if (targetPosition.y > max.y)
			{
				targetPosition.y = max.y;
			}
			if (targetPosition.z > max.z)
			{
				targetPosition.z = max.z;
			}
			if (targetPosition.x < min.x)
			{
				targetPosition.x = min.x;
			}
			if (targetPosition.y < min.y)
			{
				targetPosition.y = min.y;
			}
			if (targetPosition.z < min.z)
			{
				targetPosition.z = min.z;
			}
			return targetPosition;
		}

		public static bool IsPositionWithinBounds(Vector3 testPosition, Vector3 boundingPositionMin, Vector3 boundingPositionMax)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (testPosition.x < boundingPositionMax.x && testPosition.y < boundingPositionMax.y && testPosition.z < boundingPositionMax.z && testPosition.x > boundingPositionMin.x && testPosition.y > boundingPositionMin.y)
			{
				return testPosition.z > boundingPositionMin.z;
			}
			return false;
		}

		public static bool NearLocation(float f1, float f2, float offset)
		{
			if (f1 < f2 + offset)
			{
				return f1 > f2 - offset;
			}
			return false;
		}

		public static bool SameLocation(Vector3 pos1, Vector3 pos2)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			if (NearLocation(pos1.x, pos2.x, 0.01f))
			{
				return NearLocation(pos1.z, pos2.z, 0.01f);
			}
			return false;
		}
	}
	public static class ScrapHelperFunctions
	{
		public static float CalculateHighestScrapValue(List<GrabbableObject> objects)
		{
			float num = 0f;
			foreach (GrabbableObject @object in objects)
			{
				if ((float)@object.scrapValue > num)
				{
					num = @object.scrapValue;
				}
			}
			return num;
		}

		public static void PlaceObjectAtPlayer(GrabbableObject obj)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)Keybinds.localPlayerController.gameplayCamera).transform.position;
			Vector3 placementPosition = default(Vector3);
			((Vector3)(ref placementPosition))..ctor(position.x - 1f, position.y + 0.2f, position.z);
			NetworkFunctions.NetworkingObjectManager.MakeObjectFallRpc(obj, placementPosition, shipParent: true);
		}

		public static List<GrabbableObject> SortByValue(List<GrabbableObject> objects, bool ascending)
		{
			if (ascending)
			{
				return objects.OrderBy((GrabbableObject obj) => obj.scrapValue).ToList();
			}
			return objects.OrderByDescending((GrabbableObject obj) => obj.scrapValue).ToList();
		}

		internal static List<GrabbableObject> FindAllScrapOnMap()
		{
			List<GrabbableObject> list = new List<GrabbableObject>();
			GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)0);
			foreach (GrabbableObject val in array)
			{
				if (!val.isInShipRoom)
				{
					list.Add(val);
					FireSale.Log("Found scrap: " + ((Object)val).name);
				}
			}
			return list;
		}
	}
}
namespace FireSale.EntityHelpers
{
	public class HangarShipHelper
	{
		public static Vector3 ShipCenterForPlacement;

		public static Vector3 ShipBoundsCenter;

		public static Vector3 ShipBoundsExtents;

		public static Vector3 ShipBoundsMax;

		public static Vector3 ShipBoundsMin;

		public static Vector3 ShipCenter;

		public static Vector3 ShipCollider;

		public static Vector3 ShipExtends;

		public static GameObject ShipObject;

		public HangarShipHelper()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009c: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_00f6: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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)
			ShipObject = GameObject.Find("/Environment/HangarShip");
			ShipCenter = ShipObject.transform.position;
			MeshCollider componentInChildren = GameObject.Find("/Environment/HangarShip/ShipInside").GetComponentInChildren<MeshCollider>();
			ShipBoundsCenter = ((Collider)componentInChildren).bounds.m_Center;
			ShipBoundsExtents = ((Collider)componentInChildren).bounds.m_Extents;
			ShipCenterForPlacement = new Vector3(ShipCenter.z - 6.25f, ShipCenter.x - 5.25f, ShipCenter.y + 1.66f);
			Bounds bounds = ((Collider)componentInChildren).bounds;
			float num = ((Bounds)(ref bounds)).min.x + 1.75f;
			bounds = ((Collider)componentInChildren).bounds;
			float y = ((Bounds)(ref bounds)).min.y;
			bounds = ((Collider)componentInChildren).bounds;
			ShipBoundsMin = new Vector3(num, y, ((Bounds)(ref bounds)).min.z);
			bounds = ((Collider)componentInChildren).bounds;
			float num2 = ((Bounds)(ref bounds)).max.x - 7f;
			bounds = ((Collider)componentInChildren).bounds;
			float y2 = ((Bounds)(ref bounds)).max.y;
			bounds = ((Collider)componentInChildren).bounds;
			ShipBoundsMax = new Vector3(num2, y2, ((Bounds)(ref bounds)).max.z);
		}

		public List<GrabbableObject> FindAllScrapShip()
		{
			List<GrabbableObject> list = new List<GrabbableObject>();
			GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)0);
			foreach (GrabbableObject val in array)
			{
				if (val.isInShipRoom)
				{
					list.Add(val);
				}
			}
			return list;
		}

		public Vector3 AdjustPositionWithinShip(Vector3 targetPosition)
		{
			//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_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return PositionHelperFunctions.AdjustPositionWithinBounds(targetPosition, ShipBoundsMin, ShipBoundsMax);
		}

		public Vector3 GetShipCenterLocation()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = GameObject.Find("/Environment/HangarShip").transform.position;
			position.z += -6.25f;
			position.x += -5.25f;
			position.y += 1.66f;
			return position;
		}

		public bool IsObjectWithinShip(GrabbableObject obj)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return PositionHelperFunctions.IsPositionWithinBounds(((Component)obj).gameObject.transform.position, ShipBoundsMin, ShipBoundsMax);
		}

		public bool IsPositionWithinShip(Vector3 position)
		{
			//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_0006: Unknown result type (might be due to invalid IL or missing references)
			return PositionHelperFunctions.IsPositionWithinBounds(position, ShipBoundsMin, ShipBoundsMax);
		}

		public void MoveItemToShip(GrabbableObject obj)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			FireSale.Log("Moving Item To Ship Center - " + ((Object)obj).name);
			obj.hasBeenHeld = true;
			obj.isInFactory = false;
			obj.isInShipRoom = true;
			RoundManager instance = RoundManager.Instance;
			instance.scrapCollectedInLevel += obj.scrapValue;
			PlayerStats obj2 = StartOfRound.Instance.gameStats.allPlayerStats[Keybinds.localPlayerController.playerClientId];
			obj2.profitable += obj.scrapValue;
			RoundManager.Instance.CollectNewScrapForThisRound(obj);
			((Component)obj).transform.SetParent(ShipObject.transform);
			obj.OnBroughtToShip();
			NetworkFunctions.NetworkingObjectManager.MakeObjectFallRpc(obj, GetShipCenterLocation(), shipParent: true);
		}

		public List<GrabbableObject> ObjectsInShip()
		{
			return (from obj in ShipObject.GetComponentsInChildren<GrabbableObject>()
				where ((Object)obj).name != "ClipboardManual" && ((Object)obj).name != "StickyNoteItem"
				select obj).ToList();
		}
	}
	public class StorageClosetHelper
	{
		public static Vector3 ClosetBoundsMax;

		public static Vector3 ClosetBoundsMin;

		private const float StorageLocationDoorOffsetToShelve = 0.2f;

		private string LastItemPlaced = string.Empty;

		private Vector3 LeftDoor;

		private float placementLocationX;

		private Vector3 RightDoor;

		private int shelveToPlaceOn = 1;

		private List<Vector3> ShevleListCenter = new List<Vector3>();

		private GameObject StorageCloset;

		private float StorageLocationXEnd;

		private float StorageLocationXStart;

		private float StorageLocationXStepItem = 0.2f;

		private float StorageLocationXStepSize = 0.1f;

		private float StorageLocationZOffset = 0.6f;

		public StorageClosetHelper()
		{
			//IL_00c5: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: 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_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			StorageCloset = GameObject.Find("/Environment/HangarShip/StorageCloset");
			GameObject gameObject = ((Component)StorageCloset.GetComponentsInChildren<Transform>().First((Transform tf) => ((Object)tf.GetParent()).name == "Cube.000")).gameObject;
			GameObject gameObject2 = ((Component)StorageCloset.GetComponentsInChildren<Transform>().First((Transform tf) => ((Object)tf.GetParent()).name == "Cube.002")).gameObject;
			LeftDoor = gameObject.transform.position;
			RightDoor = gameObject2.transform.position;
			StorageLocationXStart = LeftDoor.x + 0.2f;
			StorageLocationXEnd = RightDoor.x - 0.2f;
			ShevleListCenter.Add(new Vector3((LeftDoor.x + RightDoor.x) / 2f, 0.75f, LeftDoor.z));
			ShevleListCenter.Add(new Vector3((LeftDoor.x + RightDoor.x) / 2f, 1.4f, LeftDoor.z));
			ShevleListCenter.Add(new Vector3((LeftDoor.x + RightDoor.x) / 2f, 2f, LeftDoor.z));
			ShevleListCenter.Add(new Vector3((LeftDoor.x + RightDoor.x) / 2f, 2.5f, LeftDoor.z));
			MeshCollider componentInChildren = GameObject.Find("/Environment/HangarShip/StorageCloset").GetComponentInChildren<MeshCollider>();
			Bounds bounds = ((Collider)componentInChildren).bounds;
			float num = ((Bounds)(ref bounds)).min.x + 0.3f;
			bounds = ((Collider)componentInChildren).bounds;
			float y = ((Bounds)(ref bounds)).min.y;
			bounds = ((Collider)componentInChildren).bounds;
			ClosetBoundsMin = new Vector3(num, y, ((Bounds)(ref bounds)).min.z);
			bounds = ((Collider)componentInChildren).bounds;
			float num2 = ((Bounds)(ref bounds)).max.x - 0.3f;
			bounds = ((Collider)componentInChildren).bounds;
			float y2 = ((Bounds)(ref bounds)).max.y;
			bounds = ((Collider)componentInChildren).bounds;
			ClosetBoundsMax = new Vector3(num2, y2, ((Bounds)(ref bounds)).max.z);
			placementLocationX = StorageLocationXStart;
		}

		public List<GrabbableObject> GetObjectsInStorageCloset()
		{
			return (from obj in StorageCloset.GetComponentsInChildren<GrabbableObject>()
				where ((Object)obj).name != "ClipboardManual" && ((Object)obj).name != "StickyNoteItem"
				select obj).ToList();
		}

		public bool IsObjectWithinCloset(GrabbableObject obj)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return PositionHelperFunctions.IsPositionWithinBounds(((Component)obj).gameObject.transform.position, ClosetBoundsMin, ClosetBoundsMax);
		}

		public bool IsPositionWithinCloset(Vector3 placementPosition)
		{
			//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_0006: Unknown result type (might be due to invalid IL or missing references)
			return PositionHelperFunctions.IsPositionWithinBounds(placementPosition, ClosetBoundsMin, ClosetBoundsMax);
		}

		public void PlaceStorageObjectOnShelve(List<GrabbableObject> objectsOfType)
		{
			//IL_0173: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01b5: 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)
			string name = ((Object)objectsOfType.First()).name;
			if (!(name == "Key(Clone)"))
			{
				if (name == "WhoopieCushion(Clone)")
				{
					StorageLocationXStepSize = 0.2f;
				}
				else
				{
					StorageLocationXStepSize = 0.1f;
				}
			}
			else
			{
				StorageLocationXStepSize = 0.05f;
			}
			if (((Object)objectsOfType.First()).name != LastItemPlaced && LastItemPlaced != string.Empty)
			{
				if (placementLocationX + StorageLocationXStepItem + StorageLocationXStepSize * (float)objectsOfType.Count > StorageLocationXEnd)
				{
					placementLocationX = StorageLocationXStart;
					if (shelveToPlaceOn < 4)
					{
						shelveToPlaceOn++;
					}
				}
				else
				{
					placementLocationX += StorageLocationXStepItem;
				}
				LastItemPlaced = ((Object)objectsOfType.First()).name;
			}
			else if (LastItemPlaced == string.Empty)
			{
				LastItemPlaced = ((Object)objectsOfType.First()).name;
			}
			int num = 2;
			bool flag = true;
			int num2 = 0;
			float num3 = 0.1f;
			float num4 = 0f;
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < objectsOfType.Count; i++)
			{
				GrabbableObject val = objectsOfType[i];
				if (flag)
				{
					if (num2 < num)
					{
						num2++;
					}
					else
					{
						flag = false;
					}
					num4 += num3;
				}
				else
				{
					if (num2 >= 0)
					{
						num2--;
					}
					else
					{
						flag = true;
					}
					num4 -= num3;
				}
				((Vector3)(ref val2))..ctor(placementLocationX, ShevleListCenter[shelveToPlaceOn - 1].y, ShevleListCenter[shelveToPlaceOn - 1].z + StorageLocationZOffset + num4);
				if (!IsPositionWithinCloset(val2))
				{
					val2 = PositionHelperFunctions.AdjustPositionWithinBounds(val2, ClosetBoundsMin, ClosetBoundsMax);
					FireSale.Log("Fixed object location out of closet " + ((Object)val).name);
				}
				FireSale.Log($"Placing {((Object)val).name} [{i + 1} of {objectsOfType.Count}] on shelve {shelveToPlaceOn} at {val2.x},{val2.y},{val2.z}");
				NetworkFunctions.NetworkingObjectManager.MakeObjectFallRpc(val, val2, shipParent: false);
				placementLocationX += StorageLocationXStepSize;
			}
			if (LastItemPlaced == "Key(Clone)")
			{
				StorageLocationXStepSize = 0.1f;
			}
			else
			{
				StorageLocationXStepSize = 0.1f;
			}
		}
	}
}
namespace FireSale.Configuration
{
	public static class ConfigSettings
	{
		public static ConfigSetupList ClosetLocationOverride = new ConfigSetupList
		{
			pluginName = "FireSale",
			SettingName = "ClosetLocationOverride",
			SettingValue = "Whoopie,Key,Flashlight,StunGrenade",
			SettingDescription = "List of items separated by comma that will be automatically placed in the storage container on ship cleanup."
		};

		public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>();

		public static ConfigSetupInputAction FireSaleInputAction = new ConfigSetupInputAction
		{
			pluginName = "FireSale",
			ActionName = "FireSaleKey",
			KeyboardMapping = "<Keyboard>/k",
			ActionDescription = "Activate fire sale keybind."
		};

		public static ConfigSetupString ItemGrouping = new ConfigSetupString
		{
			pluginName = "FireSale",
			SettingName = "ItemGrouping",
			SettingValue = "Tight",
			SettingDescription = "[Loose] Spread items accross the ship from left to right -or- [Tight] Pack the items to the side of the ship with the suit rack."
		};

		public static ConfigSetupString OrganizationTechnique = new ConfigSetupString
		{
			pluginName = "FireSale",
			SettingName = "OrganizationMethod",
			SettingValue = "Value",
			SettingDescription = "Choose organization method, spread items of a type by [Value] or [Stack] perfectly by item type."
		};

		public static ConfigSetupList SortingLocationBlacklist = new ConfigSetupList
		{
			pluginName = "FireSale",
			SettingName = "SortingDisabledList",
			SettingValue = "",
			SettingDescription = "List of items separated by comma that will be ignored on sorting."
		};

		public static ConfigSetupString TwoHandedItemLocation = new ConfigSetupString
		{
			pluginName = "FireSale",
			SettingName = "TwoHandedItemLocation",
			SettingValue = "Front",
			SettingDescription = "Choose location for two handed objects, [Front] of ship, or [Back] of ship. The opposite location will have the single handed items"
		};

		public static void BindConfigSettings()
		{
			FireSale.Log("BindingConfigs");
			currentConfigEntries = FireSaleInputAction.Bind(currentConfigEntries);
			currentConfigEntries = OrganizationTechnique.Bind(currentConfigEntries);
			currentConfigEntries = TwoHandedItemLocation.Bind(currentConfigEntries);
			currentConfigEntries = ItemGrouping.Bind(currentConfigEntries);
			currentConfigEntries = ClosetLocationOverride.Bind(currentConfigEntries);
			currentConfigEntries = SortingLocationBlacklist.Bind(currentConfigEntries);
			TryRemoveOldConfigSettings();
		}

		public static void TryRemoveOldConfigSettings()
		{
			HashSet<string> hashSet = new HashSet<string>();
			HashSet<string> hashSet2 = new HashSet<string>();
			foreach (ConfigEntryBase value in currentConfigEntries.Values)
			{
				hashSet.Add(value.Definition.Section);
				hashSet2.Add(value.Definition.Key);
			}
			try
			{
				FireSale.Log("Cleaning old config entries");
				ConfigFile config = ((BaseUnityPlugin)FireSale.instance).Config;
				string configFilePath = config.ConfigFilePath;
				if (!File.Exists(configFilePath))
				{
					return;
				}
				string text = File.ReadAllText(configFilePath);
				string[] array = File.ReadAllLines(configFilePath);
				string text2 = "";
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = array[i].Replace("\n", "");
					if (array[i].Length <= 0)
					{
						continue;
					}
					if (array[i].StartsWith("["))
					{
						if (text2 != "" && !hashSet.Contains(text2))
						{
							text2 = "[" + text2 + "]";
							int num = text.IndexOf(text2);
							int num2 = text.IndexOf(array[i]);
							text = text.Remove(num, num2 - num);
						}
						text2 = array[i].Replace("[", "").Replace("]", "").Trim();
					}
					else
					{
						if (!(text2 != ""))
						{
							continue;
						}
						if (i <= array.Length - 4 && array[i].StartsWith("##"))
						{
							int j;
							for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++)
							{
							}
							if (hashSet.Contains(text2))
							{
								int num3 = array[i + j - 1].IndexOf("=");
								string item = array[i + j - 1].Substring(0, num3 - 1);
								if (!hashSet2.Contains(item))
								{
									int num4 = text.IndexOf(array[i]);
									int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length;
									text = text.Remove(num4, num5 - num4);
								}
							}
							i += j - 1;
						}
						else if (array[i].Length > 3)
						{
							text = text.Replace(array[i], "");
						}
					}
				}
				if (!hashSet.Contains(text2))
				{
					text2 = "[" + text2 + "]";
					int num6 = text.IndexOf(text2);
					text = text.Remove(num6, text.Length - num6);
				}
				while (text.Contains("\n\n\n"))
				{
					text = text.Replace("\n\n\n", "\n\n");
				}
				File.WriteAllText(configFilePath, text);
				config.Reload();
			}
			catch
			{
			}
		}
	}
	public class ConfigSetupInputAction
	{
		public string ActionDescription;

		public string ActionName;

		public ConfigEntry<string> Key;

		public string KeyboardMapping;

		public string KeyDisplayName;

		public string pluginName;

		public static ConfigEntry<string> CreateKey(ConfigSetupInputAction c)
		{
			return ((BaseUnityPlugin)FireSale.instance).Config.Bind<string>(c.pluginName, c.ActionName, c.KeyboardMapping, c.ActionDescription);
		}

		public static string GetDisplayName(string key)
		{
			key = key.Replace("<Keyboard>/", "");
			key = key.Replace("<Mouse>/", "");
			return key.Replace("leftAlt", "Alt").Replace("rightAlt", "Alt").Replace("leftCtrl", "Ctrl")
				.Replace("rightCtrl", "Ctrl")
				.Replace("leftShift", "Shift")
				.Replace("rightShift", "Shift")
				.Replace("leftButton", "LMB")
				.Replace("rightButton", "RMB")
				.Replace("middleButton", "MMB");
		}

		public void Bind()
		{
			Key = CreateKey(this);
			KeyDisplayName = GetDisplayName(Key.Value);
		}

		public Dictionary<string, ConfigEntryBase> Bind(Dictionary<string, ConfigEntryBase> toDictionary)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Key = CreateKey(this);
			toDictionary.Add(((ConfigEntryBase)Key).Definition.Key, (ConfigEntryBase)Key);
			return toDictionary;
		}
	}
	public class ConfigSetupList
	{
		public ConfigEntry<string> Key;

		public string KeyDisplayName;

		public string pluginName;

		public string SettingDescription;

		public string SettingName;

		public string SettingValue;

		public static ConfigEntry<string> CreateKey(ConfigSetupList c)
		{
			return ((BaseUnityPlugin)FireSale.instance).Config.Bind<string>(c.pluginName, c.SettingName, c.SettingValue, c.SettingDescription);
		}

		public Dictionary<string, ConfigEntryBase> Bind(Dictionary<string, ConfigEntryBase> toDictionary)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Key = CreateKey(this);
			toDictionary.Add(((ConfigEntryBase)Key).Definition.Key, (ConfigEntryBase)Key);
			return toDictionary;
		}

		public List<string> GetStrings(string configSetting)
		{
			List<string> list = new List<string>();
			foreach (Match item in new Regex("((?<item>[A-Za-z]+)[,]*)").Matches(configSetting))
			{
				string text = item.Groups["item"].ToString();
				list.Add(item.Groups["item"].ToString());
				FireSale.Log("Got configuration item " + text);
			}
			return list;
		}
	}
	public class ConfigSetupString
	{
		public string pluginName;

		public string SettingName;

		public string SettingValue;

		public string SettingDescription;

		public ConfigEntry<string> Key;

		public string KeyDisplayName;

		public Dictionary<string, ConfigEntryBase> Bind(Dictionary<string, ConfigEntryBase> toDictionary)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Key = CreateKey(this);
			toDictionary.Add(((ConfigEntryBase)Key).Definition.Key, (ConfigEntryBase)Key);
			return toDictionary;
		}

		public static ConfigEntry<string> CreateKey(ConfigSetupString c)
		{
			return ((BaseUnityPlugin)FireSale.instance).Config.Bind<string>(c.pluginName, c.SettingName, c.SettingValue, c.SettingDescription);
		}
	}
	[HarmonyPatch]
	internal static class Keybinds
	{
		public static PlayerControllerB localPlayerController;

		private static InputAction FireSaleGrabLoot;

		[HarmonyPatch(typeof(PlayerControllerB), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable(PlayerControllerB __instance)
		{
			//IL_0008: 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_001c: Expected O, but got Unknown
			//IL_001c: Expected O, but got Unknown
			if (FireSaleGrabLoot != null && !((Object)__instance != (Object)localPlayerController))
			{
				FireSaleGrabLoot.performed -= OnFireSaleCalled;
				FireSaleGrabLoot.Disable();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable(PlayerControllerB __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0015: Expected O, but got Unknown
			if ((Object)__instance == (Object)localPlayerController)
			{
				SubscribeToEvents();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void OnLocalPlayerConnect(PlayerControllerB __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			localPlayerController = __instance;
			FireSaleGrabLoot = new InputAction((string)null, (InputActionType)0, ConfigSettings.FireSaleInputAction.Key.Value, "Press", (string)null, (string)null);
			if (((Component)localPlayerController).gameObject.activeSelf)
			{
				SubscribeToEvents();
			}
		}

		private static void OnFireSaleCalled(CallbackContext context)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if (!((Object)localPlayerController == (Object)null) && localPlayerController.isPlayerControlled && !localPlayerController.inTerminalMenu && (!((NetworkBehaviour)localPlayerController).IsServer || localPlayerController.isHostPlayerObject))
			{
				FireSale.Log("Get all loot");
				FireSaleFunctions.RetrieveAllLoot();
			}
		}

		private static void SubscribeToEvents()
		{
			if (FireSaleGrabLoot != null)
			{
				FireSaleGrabLoot.Enable();
				FireSaleGrabLoot.performed += OnFireSaleCalled;
			}
		}
	}
}