Decompiled source of EmployeeTweaks v1.0.7

EmployeeTweaks-IL2CPP.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using EmployeeTweaks;
using EmployeeTweaks.Helpers;
using EmployeeTweaks.Network;
using EmployeeTweaks.Patches.EmployeeArea;
using EmployeeTweaks.Patches.FilterItemApply;
using EmployeeTweaks.Patches.MoreEmployeeConfigItems;
using EmployeeTweaks.Patches.Unpackaging;
using EmployeeTweaks.Persistence;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppFishNet.Connection;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.Effects;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.EntityFramework;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Management;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Behaviour;
using Il2CppScheduleOne.ObjectScripts;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.Tiles;
using Il2CppScheduleOne.Tools;
using Il2CppScheduleOne.UI.Items;
using Il2CppScheduleOne.UI.Management;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Internal.Abstraction;
using S1API.Saveables;
using S1API.UI;
using S1API.Utils;
using Semver;
using SteamNetworkLib;
using SteamNetworkLib.Events;
using SteamNetworkLib.Models;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::EmployeeTweaks.EmployeeTweaks), "EmployeeTweaks", "1.0.7", "k073l", "https://github.com/k073l/s1-employeetweaks")]
[assembly: MelonColor(1, 217, 131, 36)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonOptionalDependencies(new string[] { "SteamNetworkLib" })]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EmployeeTweaks-IL2CPP")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyDescription("Various employee tweaks - unpackaging, sprinkler/pourer use and more")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+700441f409a80695300df63551bba49015f12b56")]
[assembly: AssemblyProduct("EmployeeTweaks-IL2CPP")]
[assembly: AssemblyTitle("EmployeeTweaks-IL2CPP")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EmployeeTweaks
{
	public static class BuildInfo
	{
		public const string Name = "EmployeeTweaks";

		public const string Description = "Various employee tweaks - unpackaging, sprinkler/pourer use and more";

		public const string Author = "k073l";

		public const string Version = "1.0.7";
	}
	public class EmployeeTweaks : MelonMod
	{
		private static Logger Logger;

		private DebugAreaDrawer debugAreaDrawer;

		private bool _lastShift;

		private bool _lastCtrl;

		internal SettingsRegistry SettingsRegistry;

		internal INetworkManager? NetworkManager;

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			CheckDependencies();
			MoveItemBehaviourPatches.ManualPatchDestinationValid(((MelonBase)this).HarmonyInstance);
			PropertyPatch.ManualPatchProperties(((MelonBase)this).HarmonyInstance);
		}

		public override void OnLateInitializeMelon()
		{
			SettingsRegistry = new SettingsRegistry();
			NetworkManager = NetworkLoader.Create();
			if (NetworkManager == null)
			{
				Logger.Warning("NetworkManager is null, multiplayer features will be unavailable.");
			}
			SettingsRegistry.InitializeCategories();
			NetworkManager?.RegisterLoggerSettings();
			debugAreaDrawer = new DebugAreaDrawer();
			DebugAreaDrawer.WireDebugAreaDrawer(debugAreaDrawer);
			Logger.Msg("EmployeeTweaks initialized");
		}

		public override void OnUpdate()
		{
			NetworkManager?.Update();
		}

		public override void OnLateUpdate()
		{
			TextMeshProUGUI applyItemAsFilterButtonText = FilterConfigPanelPatches.ApplyItemAsFilterButtonText;
			if (!((Object)(object)applyItemAsFilterButtonText == (Object)null))
			{
				bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
				bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
				if (flag != _lastShift || flag2 != _lastCtrl)
				{
					_lastShift = flag;
					_lastCtrl = flag2;
					FilterConfigPanelPatches.AllSlots = flag;
					FilterConfigPanelPatches.DenyListMode = flag2;
					((TMP_Text)applyItemAsFilterButtonText).text = (flag ? "Apply All As Filters" : "Apply Item As Filter");
				}
			}
		}

		public override void OnDeinitializeMelon()
		{
			NetworkManager?.Dispose();
		}

		private static void CheckDependencies()
		{
			DependenciesChecker dependenciesChecker = new DependenciesChecker
			{
				ShowMenuBanner = true,
				UnloadIfMissingRequired = true
			};
			dependenciesChecker.AddDependency(new DependencyInfo
			{
				Name = "S1API (Forked)",
				AssemblyName = "S1API",
				IsRequired = true,
				Version = "3.1.0",
				Urls = new List<DependencyUrl>(3)
				{
					new DependencyUrl
					{
						SourceName = "Thunderstore",
						Url = "https://thunderstore.io/c/schedule-i/p/ifBars/S1API_Forked/"
					},
					new DependencyUrl
					{
						SourceName = "NexusMods",
						Url = "https://www.nexusmods.com/schedule1/mods/1194"
					},
					new DependencyUrl
					{
						SourceName = "Github",
						Url = "https://github.com/ifBars/S1API/releases/"
					}
				}
			});
			dependenciesChecker.AddDependency(new DependencyInfo
			{
				Name = "SteamNetworkLib",
				AssemblyName = "SteamNetworkLib",
				IsRequired = false,
				Version = "1.2.1",
				Urls = new List<DependencyUrl>(4)
				{
					new DependencyUrl
					{
						SourceName = "Thunderstore Il2Cpp",
						Url = "https://thunderstore.io/c/schedule-i/p/ifBars/SteamNetworkLib_Il2Cpp/"
					},
					new DependencyUrl
					{
						SourceName = "Thunderstore Mono",
						Url = "https://thunderstore.io/c/schedule-i/p/ifBars/SteamNetworkLib_Mono/"
					},
					new DependencyUrl
					{
						SourceName = "NexusMods",
						Url = "https://www.nexusmods.com/schedule1/mods/1396"
					},
					new DependencyUrl
					{
						SourceName = "Github",
						Url = "https://github.com/ifBars/SteamNetworkLib/releases"
					}
				}
			});
			dependenciesChecker.ProcessAndAlert();
		}
	}
	internal class SettingsRegistry
	{
		internal MelonPreferences_Category EmployeeCapacityCategory;

		internal NetworkedMelonEntry<bool> EnableCapacityAndDebug;

		internal MelonPreferences_Entry<bool> DrawDebugArea;

		internal HashSet<NetworkedMelonEntry<int>> EmployeeCapacities = new HashSet<NetworkedMelonEntry<int>>();

		internal MelonPreferences_Category EmployeeAssignsCategory;

		internal NetworkedMelonEntry<bool> EnableAssigns;

		internal NetworkedMelonEntry<int> BotanistMaxPots;

		internal NetworkedMelonEntry<int> HandlerMaxStations;

		internal NetworkedMelonEntry<int> HandlerMaxRoutes;

		internal NetworkedMelonEntry<int> ChemistMaxStations;

		internal NetworkedMelonEntry<int> CleanerMaxBins;

		internal MelonPreferences_Category EmployeeTweaksDebugCategory;

		internal MelonPreferences_Entry<bool> EnableNetworkDebug;

		internal MelonPreferences_Entry<bool> EnableConfigItemsDebug;

		internal MelonPreferences_Entry<bool> EnableUnpackagingDebug;

		internal object? _boxedClient = null;

		internal object? _boxedOptions = null;

		public bool InitializeNetwork(object? client)
		{
			if (client == null)
			{
				return false;
			}
			_boxedClient = client;
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "SteamNetworkLib");
			if (assembly == null)
			{
				return false;
			}
			Type type = assembly.GetType("SteamNetworkLib.Sync.NetworkSyncOptions");
			if (type == null)
			{
				return false;
			}
			_boxedOptions = Activator.CreateInstance(type);
			if (_boxedOptions == null)
			{
				return false;
			}
			PropertyInfo property = type.GetProperty("KeyPrefix");
			if (property == null)
			{
				return false;
			}
			property.SetValue(_boxedOptions, Assembly.GetExecutingAssembly().GetName().Name + "_");
			return true;
		}

		public void InitializeCategories()
		{
			InitializeCapacityCategory();
			InitializeAssignsCategory();
			InitializeModDebugCategory();
		}

		private void InitializeCapacityCategory()
		{
			EmployeeCapacityCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeCapacity", "Employee Capacities");
			EnableCapacityAndDebug = EmployeeCapacityCategory.GetOrCreateNetworkedEntry("EmployeeTweaksEnableCapacityAndDebug", defaultValue: true, _boxedClient, _boxedOptions, announce: true, "Enable Category", "Enables employee capacity tweaks and drawing employee idle points area");
			DrawDebugArea = EmployeeCapacityCategory.CreateEntry<bool>("EmployeeTweaksDrawDebugArea", false, "Draw Debug Area", "Draws a debug area where employee idle points are contained", false, false, (ValueValidator)null, (string)null);
		}

		private void InitializeAssignsCategory()
		{
			EmployeeAssignsCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeAssignsCategory", "Employee Assigns Capacities");
			EnableAssigns = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksEnableAssigns", defaultValue: true, _boxedClient, _boxedOptions, announce: true, "Enable Category", "Enables employee assigns capacity modifications");
			BotanistMaxPots = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksBotanistMaxPots", 8, _boxedClient, _boxedOptions, announce: true, "Botanist Max Pots", $"Maximum number of pots a botanist can be assigned to (allowed values from {SettingsConstants.BotanistBoundsMaxPots.Item1} to {SettingsConstants.BotanistBoundsMaxPots.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.BotanistBoundsMaxPots.Item1, SettingsConstants.BotanistBoundsMaxPots.Item2));
			HandlerMaxStations = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksHandlerMaxStations", 3, _boxedClient, _boxedOptions, announce: true, "Handler Max Stations", $"Maximum number of stations a packager can be assigned to (allowed values from {SettingsConstants.HandlerBoundsMaxStations.Item1} to {SettingsConstants.HandlerBoundsMaxStations.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxStations.Item1, SettingsConstants.HandlerBoundsMaxStations.Item2));
			HandlerMaxRoutes = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksHandlerMaxRoutes", 5, _boxedClient, _boxedOptions, announce: true, "Handler Max Routes", $"Maximum number of routes a packager can be assigned to (allowed values from {SettingsConstants.HandlerBoundsMaxRoutes.Item1} to {SettingsConstants.HandlerBoundsMaxRoutes.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxRoutes.Item1, SettingsConstants.HandlerBoundsMaxRoutes.Item2));
			ChemistMaxStations = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksChemistMaxStations", 4, _boxedClient, _boxedOptions, announce: true, "Chemist Max Stations", $"Maximum number of stations a chemist can be assigned to (allowed values from {SettingsConstants.ChemistBoundsMaxStations.Item1} to {SettingsConstants.ChemistBoundsMaxStations.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.ChemistBoundsMaxStations.Item1, SettingsConstants.ChemistBoundsMaxStations.Item2));
			CleanerMaxBins = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksCleanerMaxBins", 6, _boxedClient, _boxedOptions, announce: true, "Cleaner Max Trash Cans", $"Maximum number of trash cans a cleaner can be assigned to (allowed values from {SettingsConstants.CleanerBoundsMaxBins.Item1} to {SettingsConstants.CleanerBoundsMaxBins.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.CleanerBoundsMaxBins.Item1, SettingsConstants.CleanerBoundsMaxBins.Item2));
		}

		private void InitializeModDebugCategory()
		{
			EmployeeTweaksDebugCategory = MelonPreferences.CreateCategory("EmployeeTweaksDebug", "Employee Tweaks Debug&Troubleshooting");
			EnableNetworkDebug = EmployeeTweaksDebugCategory.CreateEntry<bool>("EmployeeTweaksEnableNetworkDebug", false, "Enable Network Debug", "Enables debug logging for networked preferences", false, false, (ValueValidator)null, (string)null);
			EnableConfigItemsDebug = EmployeeTweaksDebugCategory.CreateEntry<bool>("EmployeeTweaksEnableConfigItemsDebug", false, "Enable Config Items Debug", "Enables debug logging for employee config items", false, false, (ValueValidator)null, (string)null);
			EnableUnpackagingDebug = EmployeeTweaksDebugCategory.CreateEntry<bool>("EmployeeTweaksEnableUnpackagingDebug", false, "Enable Unpackaging Debug", "Enables debug logging for unpackaging", false, false, (ValueValidator)null, (string)null);
		}

		private void PushLoggerSettings()
		{
			SetAndRegister(ClipboardUIHelper.Logger, EnableConfigItemsDebug);
			SetAndRegister(SharedClipboardPatches.Logger, EnableConfigItemsDebug);
			SetAndRegister(PackagingStationConfigPanelPatch.Logger, EnableUnpackagingDebug);
			SetAndRegister(MoveItemBehaviourPatches.Logger, EnableUnpackagingDebug);
			SetAndRegister(PackagerPatches.Logger, EnableUnpackagingDebug);
		}

		private void SetAndRegister(Logger logger, MelonPreferences_Entry<bool>? entry)
		{
			logger.RaiseDebug = entry?.Value ?? false;
			((MelonEventBase<LemonAction<bool, bool>>)(object)entry?.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate(bool _, bool newValue)
			{
				logger.RaiseDebug = newValue;
			}, 0, false);
		}
	}
	internal static class SettingsConstants
	{
		public const int BotanistDefaultMaxPots = 8;

		public static (int, int) BotanistBoundsMaxPots = (1, 32);

		public const int HandlerDefaultMaxStations = 3;

		public static (int, int) HandlerBoundsMaxStations = (1, 8);

		public const int HandlerDefaultMaxRoutes = 5;

		public static (int, int) HandlerBoundsMaxRoutes = (1, 16);

		public const int ChemistDefaultMaxStations = 4;

		public static (int, int) ChemistBoundsMaxStations = (1, 32);

		public const int CleanerDefaultMaxBins = 6;

		public static (int, int) CleanerBoundsMaxBins = (1, 32);
	}
}
namespace EmployeeTweaks.Persistence
{
	public class UnpackageSave : Saveable
	{
		[SaveableField("UnpackageStations")]
		public Dictionary<Guid, bool> UnpackageStations = new Dictionary<Guid, bool>();

		private static UnpackageSave _instance;

		public static UnpackageSave Instance => _instance ?? (_instance = new UnpackageSave());

		public UnpackageSave()
		{
			_instance = this;
		}

		protected override void OnLoaded()
		{
			INetworkManager? networkManager = Melon<EmployeeTweaks>.Instance.NetworkManager;
			if (networkManager == null || networkManager.IsSingleplayer)
			{
				return;
			}
			foreach (KeyValuePair<Guid, bool> unpackageStation in UnpackageStations)
			{
				Melon<EmployeeTweaks>.Instance.NetworkManager?.BroadcastStation(unpackageStation.Key.ToString(), unpackageStation.Value);
			}
		}

		public unsafe bool TryGetValue(Guid guid, out bool value)
		{
			Guid key = Guid.Parse(((object)(*(Guid*)(&guid))/*cast due to .constrained prefix*/).ToString());
			return UnpackageStations.TryGetValue(key, out value);
		}

		public bool TryGetValue(Guid guid, out bool value)
		{
			return UnpackageStations.TryGetValue(guid, out value);
		}
	}
}
namespace EmployeeTweaks.Patches.Unpackaging
{
	[HarmonyPatch(typeof(AdvancedTransitRoute))]
	internal static class AdvancedTransitRoutePatch
	{
		[HarmonyPatch("GetItemReadyToMove")]
		[HarmonyPrefix]
		private static bool GetItemReadyToMove(AdvancedTransitRoute __instance, ref ItemInstance __result)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if (((TransitRoute)__instance).Source == null || ((TransitRoute)__instance).Destination == null)
			{
				return true;
			}
			if (((TransitRoute)__instance).Destination == null)
			{
				return true;
			}
			ITransitEntity destination = ((TransitRoute)__instance).Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = ((TransitRoute)__instance).Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (flag)
			{
				Enumerator<ItemSlot> enumerator = ((TransitRoute)__instance).Source.OutputSlots.GetEnumerator();
				while (enumerator.MoveNext())
				{
					ItemSlot current = enumerator.Current;
					if (current.ItemInstance != null && __instance.Filter.DoesItemMeetFilter(current.ItemInstance))
					{
						int outputCapacityForItem = destination.GetOutputCapacityForItem(current.ItemInstance, (NPC)null);
						if (outputCapacityForItem > 0)
						{
							__result = current.ItemInstance.GetCopy(Mathf.Min(outputCapacityForItem, ((BaseItemInstance)current.ItemInstance).Quantity));
							return false;
						}
					}
				}
			}
			else
			{
				Enumerator<ItemSlot> enumerator2 = ((TransitRoute)__instance).Source.InputSlots.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					ItemSlot current2 = enumerator2.Current;
					if (current2.ItemInstance != null && __instance.Filter.DoesItemMeetFilter(current2.ItemInstance))
					{
						int inputCapacityForItem = destination.GetInputCapacityForItem(current2.ItemInstance, (NPC)null, true);
						if (inputCapacityForItem > 0)
						{
							__result = current2.ItemInstance.GetCopy(Mathf.Min(inputCapacityForItem, ((BaseItemInstance)current2.ItemInstance).Quantity));
							return false;
						}
					}
				}
			}
			__result = null;
			return false;
		}
	}
	[HarmonyPatch(typeof(MoveItemBehaviour))]
	internal static class MoveItemBehaviourPatches
	{
		internal static readonly Logger Logger = new Logger("MoveItemBehaviourPatches");

		private static Dictionary<MoveItemBehaviour, object> customGrabRunning = new Dictionary<MoveItemBehaviour, object>();

		private static Dictionary<MoveItemBehaviour, object> customPlaceRunning = new Dictionary<MoveItemBehaviour, object>();

		internal static void ManualPatchDestinationValid(Harmony harmony)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(MoveItemBehaviour), "IsDestinationValid", new Type[3]
			{
				typeof(TransitRoute),
				typeof(ItemInstance),
				typeof(string).MakeByRefType()
			}, (Type[])null);
			if (methodInfo == null)
			{
				Logger.Error("Failed to find IsDestinationValid method!");
				return;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MoveItemBehaviourPatches), "IsDestinationValid", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(MoveItemBehaviour), "IsTransitRouteValid", new Type[3]
			{
				typeof(TransitRoute),
				typeof(string),
				typeof(string).MakeByRefType()
			}, (Type[])null);
			if (methodInfo2 == null)
			{
				Logger.Error("Failed to find IsTransitRouteValid method!");
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(MoveItemBehaviourPatches), "IsTransitRouteValidID", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static bool IsDestinationValid(MoveItemBehaviour __instance, TransitRoute route, ItemInstance item, ref string invalidReason, ref bool __result)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			invalidReason = string.Empty;
			if (((route != null) ? route.Destination : null) == null)
			{
				__result = false;
				return true;
			}
			ITransitEntity destination = route.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = route.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				__result = false;
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				__result = false;
				return true;
			}
			if (!__instance.CanGetToDestination(route))
			{
				invalidReason = "Cannot get to destination!";
				__result = false;
				return false;
			}
			if (!__instance.CanGetToSource(route))
			{
				invalidReason = "Cannot get to source!";
				__result = false;
				return false;
			}
			if ((flag ? destination.GetOutputCapacityForItem(item, ((Behaviour)__instance).Npc) : destination.GetInputCapacityForItem(item, ((Behaviour)__instance).Npc, true)) == 0)
			{
				invalidReason = "Destination has no capacity for item!";
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}

		private static bool IsTransitRouteValidID(MoveItemBehaviour __instance, TransitRoute route, string itemID, ref string invalidReason, ref bool __result)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			invalidReason = string.Empty;
			if (((route != null) ? route.Destination : null) == null || route.Source == null)
			{
				__result = false;
				return true;
			}
			ITransitEntity destination = route.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = route.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				__result = false;
				return true;
			}
			if (!route.AreEntitiesNonNull())
			{
				invalidReason = "Entities are null!";
				__result = false;
				return false;
			}
			ItemSlot firstSlotContainingItem = source.GetFirstSlotContainingItem(itemID, (ESlotType)(!flag2));
			ItemInstance val2 = ((firstSlotContainingItem != null) ? firstSlotContainingItem.ItemInstance : null);
			if (val2 == null || ((BaseItemInstance)val2).Quantity <= 0)
			{
				invalidReason = "Item is null or quantity is 0!";
				__result = false;
				return false;
			}
			if (!__instance.IsDestinationValid(route, val2, ref invalidReason))
			{
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}

		[HarmonyPatch("IsNpcInventoryItemValid")]
		[HarmonyPrefix]
		private static bool CheckNpcInventoryItemValid(MoveItemBehaviour __instance, ItemInstance item, ref bool __result)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (flag)
			{
				if (destination.GetOutputCapacityForItem(item, ((Behaviour)__instance).Npc) == 0)
				{
					__result = false;
					return false;
				}
			}
			else if (destination.GetInputCapacityForItem(item, ((Behaviour)__instance).Npc, true) == 0)
			{
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}

		[HarmonyPatch("GetAmountToGrab")]
		[HarmonyPrefix]
		private static bool GetAmountToGrab(MoveItemBehaviour __instance, ref int __result)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0));
			ItemInstance val2 = ((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null);
			if (val2 == null)
			{
				__result = 0;
				return false;
			}
			int num = ((BaseItemInstance)val2).Quantity;
			if (__instance.maxMoveAmount > 0)
			{
				num = Mathf.Min(__instance.maxMoveAmount, num);
			}
			int num2 = (flag ? destination.GetOutputCapacityForItem(val2, ((Behaviour)__instance).Npc) : destination.GetInputCapacityForItem(val2, ((Behaviour)__instance).Npc, true));
			__result = Mathf.Min(num, num2);
			return false;
		}

		[HarmonyPatch("GrabItem")]
		[HarmonyPrefix]
		private static bool GrabItem(MoveItemBehaviour __instance)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Source : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (flag)
			{
				return true;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log(Object.op_Implicit("MoveItemBehaviour.GrabItem"), (Object)null);
			}
			__instance.currentState = (EState)2;
			__instance.grabRoutine = null;
			object value2 = MelonCoroutines.Start(Routine());
			customGrabRunning[__instance] = value2;
			return false;
			IEnumerator Routine()
			{
				Transform sourceAccessPoint = __instance.GetSourceAccessPoint(__instance.assignedRoute);
				if ((Object)(object)sourceAccessPoint == (Object)null)
				{
					LogWarning("Could not find source access point!");
					__instance.grabRoutine = null;
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
				}
				else
				{
					((Behaviour)__instance).Npc.Movement.FaceDirection(sourceAccessPoint.forward, 0.5f);
					((Behaviour)__instance).Npc.SetAnimationTrigger_Networked((NetworkConnection)null, "GrabItem");
					if (!Utils.Is<Employee>((object)((Behaviour)__instance).Npc, out Employee employee) || (Object)(object)employee == (Object)null)
					{
						Logger.Debug("Could not find employee!");
						yield break;
					}
					float seconds = TimeManager.TickDuration / employee.CurrentWorkSpeed;
					yield return (object)new WaitForSeconds(seconds);
					ItemInstance itemToRetrieveTemplate = __instance.itemToRetrieveTemplate;
					if (((itemToRetrieveTemplate != null) ? ((BaseItemInstance)itemToRetrieveTemplate).ID : null) == null)
					{
						Logger.Debug("Could not find item to retrieve template!");
						yield break;
					}
					string invalidReason = default(string);
					if (!__instance.IsTransitRouteValid(__instance.assignedRoute, ((BaseItemInstance)__instance.itemToRetrieveTemplate).ID, ref invalidReason))
					{
						LogWarning(((Behaviour)__instance).Npc.FullName + " transit route no longer valid! Reason: " + invalidReason);
						__instance.grabRoutine = null;
						((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					}
					else
					{
						__instance.TakeItem();
						yield return (object)new WaitForSeconds(TimeManager.TickDuration);
						__instance.grabRoutine = null;
						__instance.currentState = (EState)0;
					}
				}
				customGrabRunning.Remove(__instance);
			}
		}

		[HarmonyPatch("TakeItem")]
		[HarmonyPrefix]
		private static bool TakeItem(MoveItemBehaviour __instance)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log(Object.op_Implicit("MoveItemBehaviour.TakeItem"), (Object)null);
			}
			int amountToGrab = __instance.GetAmountToGrab();
			if (amountToGrab == 0)
			{
				LogWarning("Amount to grab is 0!");
				return false;
			}
			ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0));
			if (((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null) == null)
			{
				Logger.Debug("Could not find first slot containing item!");
				return false;
			}
			ItemInstance copy = firstSlotContainingTemplateItem.ItemInstance.GetCopy(amountToGrab);
			__instance.grabbedAmount = amountToGrab;
			firstSlotContainingTemplateItem.ChangeQuantity(-amountToGrab, false);
			((Behaviour)__instance).Npc.Inventory.InsertItem(copy, true);
			if (flag)
			{
				destination.ReserveOutputSlotsForItem(copy, ((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
			}
			else
			{
				destination.ReserveInputSlotsForItem(copy, ((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
			}
			return false;
		}

		[HarmonyPatch("PlaceItem")]
		[HarmonyPrefix]
		private static bool PlaceItem(MoveItemBehaviour __instance)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity dest = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool destIsStation = Utils.Is2<PackagingStation>((object)dest, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!destIsStation && !flag)
			{
				return true;
			}
			PackagingStation val = (destIsStation ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log(Object.op_Implicit("MoveItemBehaviour.PlaceItem"), (Object)null);
			}
			__instance.currentState = (EState)4;
			__instance.placingRoutine = null;
			object value2 = MelonCoroutines.Start(Routine());
			customPlaceRunning[__instance] = value2;
			return false;
			IEnumerator Routine()
			{
				if ((Object)(object)__instance.GetDestinationAccessPoint(__instance.assignedRoute) != (Object)null)
				{
					((Behaviour)__instance).Npc.Movement.FaceDirection(__instance.GetDestinationAccessPoint(__instance.assignedRoute).forward, 0.5f);
				}
				((Behaviour)__instance).Npc.SetAnimationTrigger_Networked((NetworkConnection)null, "GrabItem");
				if (!Utils.Is<Employee>((object)((Behaviour)__instance).Npc, out Employee employee) || (Object)(object)employee == (Object)null)
				{
					Logger.Debug("Could not find employee!");
					customPlaceRunning.Remove(__instance);
				}
				else
				{
					float seconds = TimeManager.TickDuration / employee.CurrentWorkSpeed;
					yield return (object)new WaitForSeconds(seconds);
					if (destIsStation)
					{
						dest.RemoveOutputSlotLocks(((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
					}
					else
					{
						dest.RemoveSlotLocks(((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
					}
					ItemInstance firstIdenticalItem = ((Behaviour)__instance).Npc.Inventory.GetFirstIdenticalItem(__instance.itemToRetrieveTemplate, (ItemFilter)null);
					if (firstIdenticalItem != null && __instance.grabbedAmount > 0)
					{
						ItemInstance copy = firstIdenticalItem.GetCopy(__instance.grabbedAmount);
						if (destIsStation)
						{
							if (dest.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount)
							{
								dest.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc);
							}
							else
							{
								LogWarning("Destination does not have enough capacity for item! Attempting to return item to source.");
								if (__instance.assignedRoute.Source.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount)
								{
									__instance.assignedRoute.Source.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc);
								}
								else
								{
									LogError("Source does not have enough capacity for item! Item will be lost.");
								}
							}
						}
						else if (dest.GetInputCapacityForItem(copy, ((Behaviour)__instance).Npc, true) >= __instance.grabbedAmount)
						{
							dest.InsertItemIntoInput(copy, ((Behaviour)__instance).Npc);
						}
						else
						{
							LogWarning("Destination does not have enough capacity for item! Attempting to return item to source.");
							if (__instance.assignedRoute.Source.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount)
							{
								__instance.assignedRoute.Source.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc);
							}
							else
							{
								LogError("Source does not have enough capacity for item! Item will be lost.");
							}
						}
						((BaseItemInstance)firstIdenticalItem).ChangeQuantity(-__instance.grabbedAmount);
					}
					else
					{
						LogWarning("Could not find carried item to place!");
					}
					yield return (object)new WaitForSeconds(TimeManager.TickDuration);
					__instance.placingRoutine = null;
					__instance.currentState = (EState)0;
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					customPlaceRunning.Remove(__instance);
				}
			}
		}

		[HarmonyPatch("StopCurrentActivity")]
		[HarmonyPrefix]
		private static bool StopCurrentActivity(MoveItemBehaviour __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			EState currentState = __instance.currentState;
			EState val = currentState;
			if ((int)val != 2)
			{
				if ((int)val == 4)
				{
					if (customPlaceRunning.TryGetValue(__instance, out object value))
					{
						MelonCoroutines.Stop(value);
						customPlaceRunning.Remove(__instance);
						return false;
					}
					return true;
				}
				return true;
			}
			if (customGrabRunning.TryGetValue(__instance, out object value2))
			{
				MelonCoroutines.Stop(value2);
				customGrabRunning.Remove(__instance);
				return false;
			}
			return true;
		}

		[HarmonyPatch("OnActiveTick")]
		[HarmonyPrefix]
		private static bool OnActiveTick(MoveItemBehaviour __instance)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			if (!__instance.assignedRoute.AreEntitiesNonNull())
			{
				LogWarning("Transit route entities are null!");
				((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
				return false;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log(Object.op_Implicit("State: " + ((object)__instance.currentState/*cast due to .constrained prefix*/).ToString()), (Object)null);
				Console.Log(Object.op_Implicit("Moving: " + ((Behaviour)__instance).Npc.Movement.IsMoving), (Object)null);
			}
			if ((int)__instance.currentState > 0)
			{
				return false;
			}
			if (((Behaviour)__instance).Npc.Inventory.GetIdenticalItemAmount(__instance.itemToRetrieveTemplate) > 0 && __instance.grabbedAmount > 0)
			{
				if (__instance.IsAtDestination())
				{
					__instance.PlaceItem();
				}
				else
				{
					__instance.WalkToDestination();
				}
			}
			else if (__instance.skipPickup)
			{
				__instance.TakeItem();
				__instance.skipPickup = false;
			}
			else if (__instance.IsAtSource())
			{
				__instance.GrabItem();
			}
			else
			{
				__instance.WalkToSource();
			}
			return false;
		}

		[HarmonyPatch("StartTransit")]
		[HarmonyPrefix]
		private static bool StartTransit(MoveItemBehaviour __instance)
		{
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(9, 4);
			defaultInterpolatedStringHandler.AppendFormatted(__instance.assignedRoute.Source.Name);
			defaultInterpolatedStringHandler.AppendLiteral(" ->  ");
			defaultInterpolatedStringHandler.AppendFormatted(__instance.assignedRoute.Destination.Name);
			defaultInterpolatedStringHandler.AppendLiteral(" (");
			ItemInstance itemToRetrieveTemplate = __instance.itemToRetrieveTemplate;
			defaultInterpolatedStringHandler.AppendFormatted((itemToRetrieveTemplate != null) ? ((BaseItemInstance)itemToRetrieveTemplate).ID : null);
			defaultInterpolatedStringHandler.AppendLiteral("x");
			ItemInstance itemToRetrieveTemplate2 = __instance.itemToRetrieveTemplate;
			defaultInterpolatedStringHandler.AppendFormatted((itemToRetrieveTemplate2 != null) ? new int?(((BaseItemInstance)itemToRetrieveTemplate2).Quantity) : ((int?)null));
			defaultInterpolatedStringHandler.AppendLiteral(")");
			Console.Log(Object.op_Implicit(defaultInterpolatedStringHandler.ToStringAndClear()), (Object)null);
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			if (((Behaviour)__instance).Npc.Inventory.GetIdenticalItemAmount(__instance.itemToRetrieveTemplate) == 0)
			{
				ItemInstance itemToRetrieveTemplate3 = __instance.itemToRetrieveTemplate;
				if (((itemToRetrieveTemplate3 != null) ? ((BaseItemInstance)itemToRetrieveTemplate3).ID : null) == null)
				{
					return false;
				}
				string text = default(string);
				if (!__instance.IsTransitRouteValid(__instance.assignedRoute, ((BaseItemInstance)__instance.itemToRetrieveTemplate).ID, ref text))
				{
					LogWarning("Invalid transit route for move item behaviour by checking transit route!. Reason: " + text);
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					return false;
				}
			}
			else
			{
				ItemFilter val = DelegateSupport.ConvertDelegate<ItemFilter>((Delegate)new Func<ItemInstance, bool>(__instance.IsNpcInventoryItemValid));
				ItemInstance firstIdenticalItem = ((Behaviour)__instance).Npc.Inventory.GetFirstIdenticalItem(__instance.itemToRetrieveTemplate, val);
				if (((Behaviour)__instance).Npc.Behaviour.DEBUG_MODE)
				{
					Console.Log(Object.op_Implicit("Moving item: " + (object)firstIdenticalItem), (Object)null);
				}
				string text2 = default(string);
				if (!__instance.IsDestinationValid(__instance.assignedRoute, firstIdenticalItem, ref text2))
				{
					LogWarning("Invalid transit route for move item behaviour by checking destination! Reason: " + text2);
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					return false;
				}
			}
			__instance.currentState = (EState)0;
			return false;
		}

		private static void LogWarning(string msg)
		{
			Console.LogWarning(Object.op_Implicit(msg), (Object)null);
			Logger.Debug(msg);
		}

		private static void LogError(string msg)
		{
			Console.LogError(Object.op_Implicit(msg), (Object)null);
			Logger.Debug(msg);
		}
	}
	[HarmonyPatch(typeof(Packager))]
	internal static class PackagerPatches
	{
		internal static readonly Logger Logger = new Logger("PackagerPatches");

		[HarmonyWrapSafe]
		[HarmonyPatch("GetStationMoveItems")]
		[HarmonyPrefix]
		private static bool GetStationMoveItems(Packager __instance, ref PackagingStation __result)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<PackagingStation> enumerator = __instance.configuration.AssignedStations.GetEnumerator();
			PackagingStation result = default(PackagingStation);
			bool value = default(bool);
			while (enumerator.MoveNext())
			{
				PackagingStation current = enumerator.Current;
				if ((Object)(object)current != (Object)null && Utils.Is<PackagingStation>((object)current, out result) && (Object)(object)result != (Object)null && UnpackageSave.Instance.TryGetValue(((BuildableItem)result).GUID, out value) && value)
				{
					List<ItemSlot> inputSlots = result.InputSlots;
					if (Utils.Is<PackagingStationConfiguration>((object)current.Configuration, out PackagingStationConfiguration config) && config != null)
					{
						bool flag = (from x in inputSlots.AsEnumerable<ItemSlot>()
							where x != null
							select x.ItemInstance into x
							where ((x != null) ? ((BaseItemInstance)x).ID : null) != null
							select x).Any((ItemInstance x) => ((Employee)__instance).MoveItemBehaviour.IsTransitRouteValid(config.DestinationRoute, ((BaseItemInstance)x).ID));
						if (inputSlots.AsEnumerable<ItemSlot>().Sum((ItemSlot x) => x.Quantity) != 0 && flag)
						{
							__result = current;
							return false;
						}
					}
				}
				else
				{
					ItemSlot outputSlot = current.OutputSlot;
					if (Utils.Is<PackagingStationConfiguration>((object)current.Configuration, out PackagingStationConfiguration result2) && result2 != null && outputSlot.Quantity != 0 && ((Employee)__instance).MoveItemBehaviour.IsTransitRouteValid(result2.DestinationRoute, ((BaseItemInstance)outputSlot.ItemInstance).ID))
					{
						__result = current;
						return false;
					}
				}
			}
			__result = null;
			return false;
		}

		[HarmonyPatch("StartMoveItem", new Type[] { typeof(PackagingStation) })]
		[HarmonyPrefix]
		private static bool StartMoveItem(Packager __instance, PackagingStation station)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			UnpackageSave.Instance.TryGetValue(((BuildableItem)station).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (!Utils.Is<PackagingStationConfiguration>((object)station.Configuration, out PackagingStationConfiguration config) || config == null)
			{
				return true;
			}
			ItemSlot val = station.InputSlots.AsEnumerable<ItemSlot>().FirstOrDefault((Func<ItemSlot, bool>)delegate(ItemSlot x)
			{
				if (x.ItemInstance == null)
				{
					return false;
				}
				string text = default(string);
				bool flag = ((Employee)__instance).MoveItemBehaviour.IsTransitRouteValid(config.DestinationRoute, ((BaseItemInstance)x.ItemInstance).ID, ref text);
				if (!flag)
				{
					Log("[Unpacked] Rejected item " + ((BaseItemInstance)x.ItemInstance).ID + ": " + text);
				}
				return flag;
			});
			if (val == null)
			{
				return true;
			}
			Log("[Unpacked] Starting moving items from " + ((Object)((Component)station).gameObject).name);
			((Employee)__instance).MoveItemBehaviour.InitializeMoveItemBehaviourWithID(config.DestinationRoute, val.ItemInstance);
			((Behaviour)((Employee)__instance).MoveItemBehaviour).Enable_Networked();
			return false;
		}

		private static void InitializeMoveItemBehaviourWithID(this MoveItemBehaviour moveItemBehaviour, TransitRoute route, ItemInstance _itemToRetrieveTemplate, int _maxMoveAmount = -1, bool _skipPickup = false)
		{
			if (((_itemToRetrieveTemplate != null) ? ((BaseItemInstance)_itemToRetrieveTemplate).ID : null) == null)
			{
				return;
			}
			string text = default(string);
			if (!moveItemBehaviour.IsTransitRouteValid(route, ((BaseItemInstance)_itemToRetrieveTemplate).ID, ref text))
			{
				LogError("Invalid transit route for move item behaviour! Reason: " + text, (Object?)(object)((Component)moveItemBehaviour).gameObject);
				return;
			}
			moveItemBehaviour.assignedRoute = route;
			moveItemBehaviour.itemToRetrieveTemplate = _itemToRetrieveTemplate;
			moveItemBehaviour.maxMoveAmount = _maxMoveAmount;
			if (((Behaviour)moveItemBehaviour).Npc.Behaviour.DEBUG_MODE)
			{
				Log($"MoveItemBehaviour initialized with route: {route.Source.Name} -> {route.Destination.Name} for item: {((BaseItemInstance)_itemToRetrieveTemplate).ID}");
			}
			moveItemBehaviour.skipPickup = _skipPickup;
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(Employee), "UpdateBehaviour")]
		private static void UpdateEmployeeBehaviour(Employee __instance)
		{
			throw new NotImplementedException();
		}

		[HarmonyPatch("UpdateBehaviour")]
		[HarmonyPrefix]
		private static bool UpdateBehaviour(Packager __instance)
		{
			UpdateEmployeeBehaviour((Employee)(object)__instance);
			if (((Behaviour)__instance.PackagingBehaviour).Active)
			{
				((Employee)__instance).MarkIsWorking();
			}
			else if (((Behaviour)((Employee)__instance).MoveItemBehaviour).Active)
			{
				((Employee)__instance).MarkIsWorking();
			}
			else
			{
				if (!InstanceFinder.IsServer)
				{
					return false;
				}
				if (((Employee)__instance).Fired)
				{
					((Employee)__instance).LeavePropertyAndDespawn();
				}
				else
				{
					if (!((Employee)__instance).CanWork())
					{
						return false;
					}
					if (__instance.configuration.AssignedStationCount + __instance.configuration.Routes.Routes.Count == 0)
					{
						((Employee)__instance).SubmitNoWorkReason("I haven't been assigned to any stations or routes.", "You can use your management clipboards to assign stations or routes to me.", 0);
						((Employee)__instance).SetIdle(true);
					}
					else
					{
						if (!InstanceFinder.IsServer)
						{
							return false;
						}
						PackagingStation stationToAttend = __instance.GetStationToAttend();
						if ((Object)(object)stationToAttend != (Object)null)
						{
							__instance.StartPackaging(stationToAttend);
							return false;
						}
						BrickPress brickPress = __instance.GetBrickPress();
						if ((Object)(object)brickPress != (Object)null)
						{
							__instance.StartPress(brickPress);
							return false;
						}
						PackagingStation stationMoveItems = __instance.GetStationMoveItems();
						if ((Object)(object)stationMoveItems != (Object)null)
						{
							__instance.StartMoveItem(stationMoveItems);
							return false;
						}
						BrickPress brickPressMoveItems = __instance.GetBrickPressMoveItems();
						if ((Object)(object)brickPressMoveItems != (Object)null)
						{
							__instance.StartMoveItem(brickPressMoveItems);
							return false;
						}
						ItemInstance val = default(ItemInstance);
						AdvancedTransitRoute transitRouteReady = __instance.GetTransitRouteReady(ref val);
						if (transitRouteReady != null)
						{
							((Employee)__instance).MoveItemBehaviour.Initialize((TransitRoute)(object)transitRouteReady, val, ((BaseItemInstance)val).Quantity, false);
							((Behaviour)((Employee)__instance).MoveItemBehaviour).Enable_Networked();
						}
						else
						{
							((Employee)__instance).SubmitNoWorkReason("There's nothing for me to do right now.", "I need one of my assigned stations to have enough product and packaging to get to work.", 0);
							((Employee)__instance).SetIdle(true);
						}
					}
				}
			}
			return false;
		}

		private static void Log(string message, Object? context = null)
		{
			Console.Log(Object.op_Implicit(message), context);
			Logger.Debug($"{message}, context: {context}");
		}

		private static void LogError(string message, Object? context = null)
		{
			Console.LogError(Object.op_Implicit(message), context);
			Logger.Debug($"{message}, context: {context}");
		}

		private static void LogWarning(string message, Object? context = null)
		{
			Console.LogWarning(Object.op_Implicit(message), context);
			Logger.Debug($"{message}, context: {context}");
		}
	}
	public static class PackagingStationConfigPatches
	{
		public static Dictionary<Guid, StringField> UnpackageFields = new Dictionary<Guid, StringField>();

		public static void InitializeField(PackagingStationConfiguration config, PackagingStation station)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Guid key = Guid.Parse(((object)((BuildableItem)station).GUID/*cast due to .constrained prefix*/).ToString());
			if (!UnpackageFields.ContainsKey(key))
			{
				StringField value = new StringField((EntityConfiguration)(object)config, "false");
				UnpackageFields[key] = value;
			}
			else
			{
				((EntityConfiguration)config).Fields.Add((ConfigField)(object)UnpackageFields[key]);
			}
		}
	}
	[HarmonyPatch(typeof(PackagingStationConfiguration))]
	public class PackagingStationConfigurationPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void ConstructorPostfix(PackagingStationConfiguration __instance, PackagingStation station)
		{
			if (__instance != null && !((Object)(object)station == (Object)null))
			{
				PackagingStationConfigPatches.InitializeField(__instance, station);
			}
		}
	}
	[HarmonyPatch(typeof(PackagingStationConfigPanel))]
	public class PackagingStationConfigPanelPatch
	{
		internal static readonly Logger Logger = new Logger("PackagingStationConfigPatches");

		[HarmonyPostfix]
		[HarmonyPatch("BindInternal")]
		public static void BindInternalPostfix(PackagingStationConfigPanel __instance, List<EntityConfiguration> configs)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_019a: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: 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_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Expected O, but got Unknown
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Expected O, but got Unknown
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.DestinationUI == (Object)null)
			{
				return;
			}
			try
			{
				PackagingStationConfiguration val = null;
				Enumerator<EntityConfiguration> enumerator = configs.GetEnumerator();
				while (enumerator.MoveNext())
				{
					EntityConfiguration current = enumerator.Current;
					if (!Utils.Is<PackagingStationConfiguration>((object)current, out PackagingStationConfiguration result) || result == null)
					{
						continue;
					}
					val = result;
					break;
				}
				if ((Object)(object)((val != null) ? val.Station : null) == (Object)null)
				{
					return;
				}
				Guid stationGuid = Guid.Parse(((object)((BuildableItem)val.Station).GUID/*cast due to .constrained prefix*/).ToString());
				if (!PackagingStationConfigPatches.UnpackageFields.TryGetValue(stationGuid, out StringField _))
				{
					PackagingStationConfigPatches.InitializeField(val, val.Station);
				}
				Transform parent = ((Component)__instance.DestinationUI).transform.parent;
				GameObject val2 = new GameObject("UnpackageToggle");
				val2.transform.SetParent(parent, false);
				RectTransform val3 = val2.AddComponent<RectTransform>();
				RectTransform component = ((Component)__instance.DestinationUI).GetComponent<RectTransform>();
				TextMeshProUGUI fieldLabel = __instance.DestinationUI.FieldLabel;
				Transform val4 = ((component != null) ? ((Transform)component).Find("Selection") : null);
				Image val5 = ((val4 != null) ? ((Component)val4).GetComponent<Image>() : null);
				if ((Object)(object)component == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)fieldLabel == (Object)null)
				{
					Logger.Error("Failed to find necessary UI components for unpackage toggle");
					return;
				}
				val3.sizeDelta = new Vector2(400f, 50f);
				val2.transform.localPosition = ((Transform)component).localPosition + new Vector3(0f, -120f, 0f);
				GameObject val6 = new GameObject("Title");
				val6.transform.SetParent(val2.transform, false);
				RectTransform val7 = val6.AddComponent<RectTransform>();
				val7.anchorMin = new Vector2(0f, 0.5f);
				val7.anchorMax = new Vector2(0f, 0.5f);
				val7.pivot = new Vector2(0f, 0.5f);
				val7.anchoredPosition = new Vector2(0f, 0f);
				val7.sizeDelta = new Vector2(200f, 30f);
				TextMeshProUGUI val8 = val6.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val8).fontSize = ((TMP_Text)fieldLabel).fontSize;
				((TMP_Text)val8).alignment = ((TMP_Text)fieldLabel).alignment;
				((TMP_Text)val8).text = "Set Unpackage";
				((Graphic)val8).color = ((Graphic)fieldLabel).color;
				((TMP_Text)val8).font = ((TMP_Text)fieldLabel).font;
				GameObject val9 = new GameObject("Value");
				RectTransform val10 = val9.AddComponent<RectTransform>();
				val9.transform.SetParent(val2.transform, false);
				val10.anchorMin = new Vector2(1f, 0.5f);
				val10.anchorMax = new Vector2(1f, 0.5f);
				val10.pivot = new Vector2(1f, 0.5f);
				val10.anchoredPosition = Vector2.zero;
				val10.sizeDelta = new Vector2(80f, 30f);
				Image val11 = val9.AddComponent<Image>();
				val11.sprite = val5.sprite;
				val11.overrideSprite = val5.overrideSprite;
				val11.type = val5.type;
				((Graphic)val11).material = ((Graphic)val5).material;
				((Graphic)val11).color = ((Graphic)val5).color;
				((Graphic)val11).raycastTarget = ((Graphic)val5).raycastTarget;
				val11.preserveAspect = val5.preserveAspect;
				val11.pixelsPerUnitMultiplier = val5.pixelsPerUnitMultiplier;
				GameObject val12 = new GameObject("Text");
				val12.transform.SetParent(val9.transform, false);
				RectTransform val13 = val12.AddComponent<RectTransform>();
				val13.anchorMin = new Vector2(1f, 0.5f);
				val13.anchorMax = new Vector2(1f, 0.5f);
				val13.pivot = new Vector2(1f, 0.5f);
				val13.anchoredPosition = new Vector2(0f, 0f);
				val13.sizeDelta = new Vector2(80f, 30f);
				TextMeshProUGUI valueTmpro = val12.AddComponent<TextMeshProUGUI>();
				((TMP_Text)valueTmpro).fontSize = 24f;
				((TMP_Text)valueTmpro).alignment = (TextAlignmentOptions)514;
				((TMP_Text)valueTmpro).font = ((TMP_Text)fieldLabel).font;
				UnpackageSave.Instance.TryGetValue(stationGuid, out var value2);
				((TMP_Text)valueTmpro).text = (value2 ? "On" : "Off");
				((Graphic)valueTmpro).color = (value2 ? Color.green : Color.gray);
				Button val14 = val9.AddComponent<Button>();
				((UnityEventBase)val14.onClick).RemoveAllListeners();
				string s = "";
				EventHelper.AddListener((Action)delegate
				{
					//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
					s = s;
					Logger.Msg("Toggled unpackaging setting for station " + stationGuid);
					UnpackageSave instance = UnpackageSave.Instance;
					if (instance?.UnpackageStations != null)
					{
						if (!instance.UnpackageStations.TryAdd(stationGuid, value: true))
						{
							instance.UnpackageStations[stationGuid] = !instance.UnpackageStations[stationGuid];
						}
						bool flag = instance.UnpackageStations[stationGuid];
						Melon<EmployeeTweaks>.Instance.NetworkManager?.BroadcastStation(stationGuid.ToString(), flag);
						((TMP_Text)valueTmpro).text = (flag ? "On" : "Off");
						((Graphic)valueTmpro).color = (flag ? Color.green : Color.gray);
					}
				}, (UnityEvent)(object)val14.onClick);
				((Selectable)val14).image = val11;
				((Selectable)val14).targetGraphic = (Graphic)(object)val11;
				UIContentPanel component2 = ((Component)__instance).GetComponent<UIContentPanel>();
				if ((Object)(object)component2 != (Object)null)
				{
					UISelectable val15 = val9.GetComponent<UISelectable>();
					if ((Object)(object)val15 == (Object)null)
					{
						val15 = val9.AddComponent<UISelectable>();
					}
					((UIPanel)component2).AddSelectable(val15);
				}
				Transform val16 = ((Transform)component).Find("Description");
				if (!((Object)(object)val16 == (Object)null))
				{
					GameObject val17 = Object.Instantiate<GameObject>(((Component)val16).gameObject);
					RectTransform component3 = val17.GetComponent<RectTransform>();
					((Transform)component3).SetParent(val2.transform, false);
					((Transform)component3).localPosition = Vector3.zero;
					component3.anchoredPosition += new Vector2(0f, -50f);
					TextMeshProUGUI component4 = val17.GetComponent<TextMeshProUGUI>();
					((TMP_Text)component4).text = "^The assigned packager will use this station for unpackaging product only";
				}
			}
			catch (Exception value3)
			{
				Logger.Error($"BindInternalPostfix failed: {value3}");
			}
		}
	}
	[HarmonyPatch(typeof(PackagingStation))]
	internal static class PackagingStationPatches
	{
		[HarmonyPatch("PackSingleInstance")]
		[HarmonyPrefix]
		private static bool UnpackIfConfigured(PackagingStation __instance)
		{
			//IL_0008: 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)
			if (__instance != null)
			{
				_ = ((BuildableItem)__instance).GUID;
				if (0 == 0)
				{
					UnpackageSave.Instance.TryGetValue(((BuildableItem)__instance).GUID, out var value);
					if (!value)
					{
						return true;
					}
					__instance.Unpack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PackagingStationBehaviour))]
	internal static class PackagingStationBehaviourPatches
	{
		[HarmonyPatch("IsStationReady")]
		[HarmonyPrefix]
		private static bool IsStationReady(PackagingStationBehaviour __instance, PackagingStation station, ref bool __result)
		{
			//IL_006d: 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_00a8: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			if ((Object)(object)station == (Object)null)
			{
				__result = false;
				return false;
			}
			NPC npc = ((Behaviour)__instance).Npc;
			Utils.Is2<IUsable>((object)station, out IUsable result);
			if (result != null && result.IsInUse && (Object)(object)station.NPCUserObject != (Object)(object)((NetworkBehaviour)npc).NetworkObject)
			{
				__result = false;
				return false;
			}
			if (!npc.Movement.CanGetTo(station.StandPoint.position, 1f))
			{
				__result = false;
				return false;
			}
			UnpackageSave.Instance.TryGetValue(((BuildableItem)station).GUID, out var value);
			EMode val = (EMode)(value ? 1 : 0);
			if ((int)station.GetState(val) > 0)
			{
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}
	}
	public static class TransitEntityExtensions
	{
		public static List<ItemSlot> ReserveOutputSlotsForItem(this ITransitEntity entity, ItemInstance item, NetworkObject locker)
		{
			List<ItemSlot> list = new List<ItemSlot>();
			int num = ((BaseItemInstance)item).Quantity;
			for (int i = 0; i < entity.OutputSlots.Count; i++)
			{
				int capacityForItem = entity.OutputSlots[i].GetCapacityForItem(item, false);
				if (capacityForItem != 0)
				{
					int num2 = Mathf.Min(capacityForItem, num);
					num -= num2;
					entity.OutputSlots[i].ApplyLock(locker, "Employee is about to place an item here", false);
					list.Add(entity.OutputSlots[i]);
					if (num <= 0)
					{
						break;
					}
				}
			}
			return list;
		}

		public static void RemoveOutputSlotLocks(this ITransitEntity entity, NetworkObject locker)
		{
			for (int i = 0; i < entity.OutputSlots.Count; i++)
			{
				if (entity.OutputSlots[i].ActiveLock != null && (Object)(object)entity.OutputSlots[i].ActiveLock.LockOwner == (Object)(object)locker)
				{
					entity.OutputSlots[i].RemoveLock(false);
				}
			}
		}
	}
}
namespace EmployeeTweaks.Patches.QualityEmployeeWorkSpeed
{
	[HarmonyPatch]
	internal static class EffectPatches
	{
		private static Logger _logger = new Logger("QualityEmployeeWorkSpeed");

		[HarmonyPatch(typeof(ProductItemInstance), "ApplyEffectsToNPC")]
		[HarmonyPrefix]
		private static bool ApplyEffectsToEmployee(ProductItemInstance __instance, NPC npc)
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((__instance != null) ? ((ItemInstance)__instance).Definition : null) == (Object)null)
			{
				return true;
			}
			if ((Object)(object)npc == (Object)null)
			{
				return true;
			}
			if (!Utils.Is<Employee>((object)npc, out Employee result) || (Object)(object)result == (Object)null)
			{
				return true;
			}
			if (!Utils.Is<ProductDefinition>((object)((ItemInstance)__instance).Definition, out ProductDefinition result2) || (Object)(object)result2 == (Object)null)
			{
				return true;
			}
			List<Effect> list = new List<Effect>();
			list.AddRange(((PropertyItemDefinition)result2).Properties.AsEnumerable<Effect>());
			list = list.OrderBy((Effect x) => x.Tier).ToList();
			StackEntry val = default(StackEntry);
			foreach (Effect item in list)
			{
				item.ApplyToEmployee(result);
				if (result.WorkSpeedController.TryGetEntry(item.Name, ref val))
				{
					float value = ApplyQuality(val.Value, GetQualityMult(((QualityItemInstance)__instance).Quality));
					_logger.Msg($"Applying quality transformation to {item.Name}: was {val.Value}, is {value}");
					val.Value = value;
					result.WorkSpeedController.Recalculate();
				}
			}
			return false;
		}

		private static float GetQualityMult(EQuality quality)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected I4, but got Unknown
			if (1 == 0)
			{
			}
			float result = (int)quality switch
			{
				0 => 0.4f, 
				1 => 0.7f, 
				2 => 1f, 
				3 => 1.2f, 
				4 => 1.5f, 
				_ => 1f, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		private static float ApplyQuality(float baseValue, float m)
		{
			float num = 1f + (m - 1f) * 1.2f;
			float num2 = baseValue * 0.9f;
			float num3 = baseValue * 1.2f;
			return Mathf.Lerp(num2, num3, Mathf.InverseLerp(0.4f, 1.5f, num));
		}
	}
}
namespace EmployeeTweaks.Patches.MoreEmployeeConfigItems
{
	[HarmonyPatch]
	internal static class BotanistMorePots
	{
		[HarmonyPatch(typeof(Botanist), "AssignProperty")]
		[HarmonyPrefix]
		private static void Awake(Botanist __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.MaxAssignedPots = Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.Value;
			}
		}

		[HarmonyPatch(typeof(BotanistConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollRect(BotanistConfigPanel __instance)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = ((__instance != null) ? __instance.PotsUI : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = ((IEnumerable<RectTransform>)val.Entries).AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform component = val2.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				Transform val3 = val2.transform.parent.Find("Hint");
				if (!((Object)(object)val3 == (Object)null) && Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.Value > 9)
				{
					val3.localPosition += new Vector3(10f, 0f);
				}
			}
		}
	}
	[HarmonyPatch]
	internal class ChemistMoreStations
	{
		[HarmonyPatch(typeof(Chemist), "AssignProperty")]
		[HarmonyPostfix]
		private static void AddStations(Chemist __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.configuration.Stations.MaxItems = Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.Value;
			}
		}

		[HarmonyPatch(typeof(ChemistConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollStationRect(ChemistConfigPanel __instance)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = ((__instance != null) ? __instance.StationsUI : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = ((IEnumerable<RectTransform>)val.Entries).AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform component = val2.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				Transform val3 = val2.transform.parent.Find("Hint");
				if (!((Object)(object)val3 == (Object)null) && Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.Value > 9)
				{
					val3.localPosition += new Vector3(10f, 0f);
				}
			}
		}
	}
	[HarmonyPatch]
	internal class CleanerMoreBins
	{
		[HarmonyPatch(typeof(Cleaner), "AssignProperty")]
		[HarmonyPostfix]
		private static void AddBins(Cleaner __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.configuration.Bins.MaxItems = Melon<EmployeeTweaks>.Instance.SettingsRegistry.CleanerMaxBins.Value;
			}
		}

		[HarmonyPatch(typeof(CleanerConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollStationRect(CleanerConfigPanel __instance)
		{
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.CleanerMaxBins.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.CleanerMaxBins.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = ((__instance != null) ? __instance.BinsUI : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = ((IEnumerable<RectTransform>)val.Entries).AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if (!((Object)(object)val2 == (Object)null))
			{
				RectTransform component = val2.GetComponent<RectTransform>();
				if (!((Object)(object)component == (Object)null))
				{
					ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				}
			}
		}
	}
	public static class ClipboardUIHelper
	{
		internal static readonly Logger Logger = new Logger("MoreEmployeeConfigItems");

		public static ScrollRect MoveToScrollableList(RectTransform source, Transform parent)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				Logger.Error("Source is null");
				return null;
			}
			VerticalLayoutGroup component = ((Component)source).GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.Error("Source does not have VerticalLayoutGroup");
				return null;
			}
			ScrollRect val2 = default(ScrollRect);
			RectTransform val = UIFactory.ScrollableVerticalList(((Object)source).name + "_Scroll", parent, ref val2);
			VerticalLayoutGroup component2 = ((Component)val).GetComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component2).spacing = ((HorizontalOrVerticalLayoutGroup)component).spacing;
			((LayoutGroup)component2).padding = new RectOffset(((LayoutGroup)component).padding.left, ((LayoutGroup)component).padding.right, 8, ((LayoutGroup)component).padding.bottom);
			((LayoutGroup)component2).childAlignment = ((LayoutGroup)component).childAlignment;
			((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = ((HorizontalOrVerticalLayoutGroup)component).childControlHeight;
			((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight;
			((HorizontalOrVerticalLayoutGroup)component2).childScaleWidth = ((HorizontalOrVerticalLayoutGroup)component).childScaleWidth;
			((HorizontalOrVerticalLayoutGroup)component2).childScaleHeight = ((HorizontalOrVerticalLayoutGroup)component).childScaleHeight;
			while (((Transform)source).childCount > 0)
			{
				Transform child = ((Transform)source).GetChild(0);
				child.SetParent((Transform)(object)val, false);
				if (Utils.Is<RectTransform>((object)child, out RectTransform result) && !((Object)(object)result == (Object)null))
				{
					result.anchorMin = new Vector2(result.anchorMin.x, 1f);
					result.anchorMax = new Vector2(result.anchorMax.x, 1f);
					result.pivot = new Vector2(result.pivot.x, 1f);
				}
			}
			RectTransform component3 = ((Component)val2).gameObject.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 1f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.pivot = new Vector2(0.5f, 1f);
			component3.anchoredPosition = source.anchoredPosition + new Vector2(0f, 150f);
			component3.sizeDelta = new Vector2(0f, source.sizeDelta.y);
			val.sizeDelta = new Vector2(0f, val.sizeDelta.y);
			LayoutElement orAddComponent = ((Component)val).gameObject.GetOrAddComponent<LayoutElement>();
			orAddComponent.flexibleWidth = 1f;
			ContentSizeFitter orAddComponent2 = ((Component)val).gameObject.GetOrAddComponent<ContentSizeFitter>();
			orAddComponent2.horizontalFit = (FitMode)0;
			AddVerticalScrollbar(val2, 8f, 8f, (ScrollbarVisibility)1);
			Object.Destroy((Object)(object)((Component)source).gameObject);
			LayoutRebuilder.ForceRebuildLayoutImmediate(val);
			return val2;
		}

		public static Scrollbar AddVerticalScrollbar(ScrollRect scrollRect, float width = 12f, float spacing = -2f, ScrollbarVisibility visibility = (ScrollbarVisibility)1)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: 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)
			if ((Object)(object)scrollRect == (Object)null)
			{
				Logger.Error("AddVerticalScrollbar: scrollRect is null");
				return null;
			}
			RectTransform component = ((Component)scrollRect).GetComponent<RectTransform>();
			if ((Object)(object)scrollRect.verticalScrollbar != (Object)null)
			{
				GameObject gameObject = ((Component)scrollRect.verticalScrollbar).gameObject;
				scrollRect.verticalScrollbar = null;
				Object.Destroy((Object)(object)gameObject);
			}
			GameObject val = new GameObject("Scrollbar");
			val.GetOrAddComponent<RectTransform>();
			val.transform.SetParent((Transform)(object)component, false);
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(1f, 0f);
			component2.anchorMax = new Vector2(1f, 1f);
			component2.pivot = new Vector2(1f, 1f);
			component2.sizeDelta = new Vector2(width, 0f);
			component2.anchoredPosition = Vector2.zero;
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = new Color(63f / 85f, 63f / 85f, 0.7490196f, 0.25f);
			((Graphic)val2).raycastTarget = true;
			GameObject val3 = new GameObject("Handle");
			val3.GetOrAddComponent<RectTransform>();
			val3.transform.SetParent(val.transform, false);
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 0f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.pivot = new Vector2(0.5f, 0.5f);
			component3.sizeDelta = Vector2.zero;
			Image val4 = val3.AddComponent<Image>();
			((Graphic)val4).color = new Color(0.6745098f, 0.6745098f, 0.6784314f, 0.65f);
			((Graphic)val4).raycastTarget = true;
			Scrollbar val5 = val.AddComponent<Scrollbar>();
			val5.direction = (Direction)2;
			val5.handleRect = component3;
			((Selectable)val5).targetGraphic = (Graphic)(object)val4;
			scrollRect.vertical = true;
			scrollRect.horizontal = false;
			scrollRect.verticalScrollbar = val5;
			scrollRect.verticalScrollbarVisibility = visibility;
			scrollRect.verticalScrollbarSpacing = spacing;
			RectTransform content = scrollRect.content;
			if ((Object)(object)content != (Object)null)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(content);
			}
			Canvas.ForceUpdateCanvases();
			return val5;
		}
	}
	[HarmonyPatch]
	internal static class HandlerPatches
	{
		[HarmonyPatch(typeof(Packager), "AssignProperty")]
		[HarmonyPostfix]
		private static void AddRoutes(Packager __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.configuration.Routes.MaxRoutes = Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxRoutes.Value;
				__instance.MaxAssignedStations = Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.Value;
				__instance.configuration.Stations.MaxItems = Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.Value;
			}
		}

		[HarmonyPatch(typeof(PackagerConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollStationRect(PackagerConfigPanel __instance)
		{
			//IL_00f3: 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)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = ((__instance != null) ? __instance.StationsUI : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = ((IEnumerable<RectTransform>)val.Entries).AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform component = val2.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ScrollRect val3 = ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				RectTransform component2 = ((Component)val3).gameObject.GetComponent<RectTransform>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.sizeDelta = new Vector2(0f, 165f);
					component2.offsetMin = new Vector2(0f, -165f);
					Canvas.ForceUpdateCanvases();
					LayoutRebuilder.ForceRebuildLayoutImmediate(val3.content);
				}
			}
		}

		[HarmonyPatch(typeof(PackagerConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollRouteRect(PackagerConfigPanel __instance)
		{
			//IL_00f2: 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)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxRoutes.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxRoutes.DefaultValue)
			{
				return;
			}
			RouteListFieldUI routesUI = __instance.RoutesUI;
			object obj;
			if (routesUI == null)
			{
				obj = null;
			}
			else
			{
				RouteEntryUI? obj2 = ((IEnumerable<RouteEntryUI>)routesUI.RouteEntries).AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Component)obj2).transform.parent).gameObject : null);
			}
			GameObject val = (GameObject)obj;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			RectTransform component = val.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ScrollRect val2 = ClipboardUIHelper.MoveToScrollableList(component, val.transform.parent);
				RectTransform component2 = ((Component)val2).gameObject.GetComponent<RectTransform>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.anchoredPosition = new Vector2(0f, -55f);
					component2.sizeDelta = new Vector2(0f, 165f);
					Canvas.ForceUpdateCanvases();
					LayoutRebuilder.ForceRebuildLayoutImmediate(val2.content);
				}
			}
		}
	}
	[HarmonyPatch]
	public class SharedClipboardPatches
	{
		internal static readonly Logger Logger = new Logger("SharedClipboardPatches");

		[HarmonyPatch(typeof(ObjectListFieldUI), "Bind")]
		[HarmonyPrefix]
		private static void AddMissing(ObjectListFieldUI __instance, List<ObjectListField> field)
		{
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				return;
			}
			int num = field.AsEnumerable<ObjectListField>().Max((ObjectListField olf) => olf.MaxItems);
			int length = ((Il2CppArrayBase<RectTransform>)(object)__instance.Entries).Length;
			if (num <= length)
			{
				Logger.D($"Not adding, current: {length}, maxFieldsNeeded: {num}");
				return;
			}
			int num2 = num - length;
			RectTransform val = ((IEnumerable<RectTransform>)__instance.Entries).AsEnumerable().FirstOrDefault();
			if ((Object)(object)val == (Object)null || num2 <= 0)
			{
				Logger.D($"Not adding, template: {val} or todo {num2}");
				return;
			}
			List<RectTransform> list = new List<RectTransform>();
			foreach (RectTransform item in (Il2CppArrayBase<RectTransform>)(object)__instance.Entries)
			{
				list.Add(item);
			}
			for (int num3 = 0; num3 < num2; num3++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject);
				val2.transform.SetParent(((Component)val).transform.parent, false);
				val2.transform.SetAsLastSibling();
				list.Add(val2.GetComponent<RectTransform>());
			}
			__instance.Entries = Il2CppReferenceArray<RectTransform>.op_Implicit(list.ToArray());
			Logger.D($"Ensured {((Il2CppArrayBase<RectTransform>)(object)__instance.Entries).Length} instances");
		}

		[HarmonyPatch(typeof(RouteListFieldUI), "Bind")]
		[HarmonyPrefix]
		private static void AddMissing(RouteListFieldUI __instance)
		{
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				return;
			}
			int item = SettingsConstants.HandlerBoundsMaxRoutes.Item2;
			int length = ((Il2CppArrayBase<RouteEntryUI>)(object)__instance.RouteEntries).Length;
			if (item <= length)
			{
				Logger.D($"Not adding, current: {length}, maxFieldsNeeded: {item}");
				return;
			}
			int num = item - length;
			RouteEntryUI? obj = ((IEnumerable<RouteEntryUI>)__instance.RouteEntries).AsEnumerable().FirstOrDefault();
			GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)val == (Object)null || num <= 0)
			{
				Logger.D($"Not adding, template: {val} or todo {num}");
				return;
			}
			List<RouteEntryUI> list = new List<RouteEntryUI>();
			foreach (RouteEntryUI item2 in (Il2CppArrayBase<RouteEntryUI>)(object)__instance.RouteEntries)
			{
				list.Add(item2);
			}
			for (int i = 0; i < num; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(val.gameObject);
				val2.transform.SetParent(val.transform.parent, false);
				val2.transform.SetSiblingIndex(val.transform.parent.childCount - 2);
				val2.SetActive(false);
				RouteEntryUI component = val2.GetComponent<RouteEntryUI>();
				if (!((Object)(object)component == (Object)null))
				{
					list.Add(component);
				}
			}
			__instance.RouteEntries = Il2CppReferenceArray<RouteEntryUI>.op_Implicit(list.ToArray());
		}
	}
}
namespace EmployeeTweaks.Patches.FilterItemApply
{
	[HarmonyPatch(typeof(FilterConfigPanel))]
	internal class FilterConfigPanelPatches
	{
		private static Logger _logger = new Logger("FilterItemApply");

		internal const string Filter1 = "Apply Item As Filter";

		internal const string Filter2 = "Apply All As Filters";

		internal static bool AllSlots;

		internal static bool DenyListMode;

		internal static TextMeshProUGUI ApplyItemAsFilterButtonText;

		private static Button _applyItemAsFilterButton;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AddButton(FilterConfigPanel __instance)
		{
			Button applyToSiblingsButton = __instance.ApplyToSiblingsButton;
			if ((Object)(object)applyToSiblingsButton == (Object)null)
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)applyToSiblingsButton).gameObject, ((Component)applyToSiblingsButton).transform.parent);
			_applyItemAsFilterButton = val.GetComponent<Button>();
			ApplyItemAsFilterButtonText = ((Component)_applyItemAsFilterButton).GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)ApplyItemAsFilterButtonText).text = "Apply Item As Filter";
			((UnityEventBase)_applyItemAsFilterButton.onClick).RemoveAllListeners();
			string s = "";
			EventHelper.AddListener((Action)delegate
			{
				s = s;
				if (AllSlots)
				{
					ApplyItemsAsFilters(__instance.OpenSlot);
				}
				else
				{
					ApplyItemAsFilter(__instance.OpenSlot);
				}
			}, (UnityEvent)(object)_applyItemAsFilterButton.onClick);
		}

		private static void ApplyItemAsFilter(ItemSlot itemSlot)
		{
			if (!AllSlots)
			{
				_logger.Msg("Applying item as filter");
			}
			ItemInstance itemInstance = itemSlot.ItemInstance;
			if (((itemInstance != null) ? ((BaseItemInstance)itemInstance).ID : null) == null)
			{
				_logger.Warning("No item in slot to apply as filter.");
				return;
			}
			SlotFilter playerFilter = itemSlot.PlayerFilter;
			if (((playerFilter != null) ? playerFilter.ItemIDs : null) == null)
			{
				_logger.Warning("Player filter is null or does not have an ItemIDs list.");
				return;
			}
			playerFilter.ItemIDs.Clear();
			playerFilter.ItemIDs.Add(((BaseItemInstance)itemInstance).ID);
			playerFilter.Type = (EType)((!DenyListMode) ? 1 : 2);
			itemSlot.SetPlayerFilter(playerFilter, false);
		}

		private static void ApplyItemsAsFilters(ItemSlot itemSlot)
		{
			_logger.Msg("Applying all items in sibling slots as filters.");
			Enumerator<ItemSlot> enumerator = itemSlot.SiblingSet.Slots.GetEnumerator();
			while (enumerator.MoveNext())
			{
				ItemSlot current = enumerator.Current;
				ApplyItemAsFilter(current);
			}
		}
	}
}
namespace EmployeeTweaks.Patches.EmployeeArea
{
	internal class DebugAreaDrawer
	{
		private Logger Logger = new Logger("DebugAreaDrawer");

		private List<GameObject> _areas = new List<GameObject>();

		internal void Draw()
		{
			//IL_00f4: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject area in _areas)
			{
				if ((Object)(object)area != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)area);
				}
			}
			_areas.Clear();
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableCapacityAndDebug.Value || !Melon<EmployeeTweaks>.Instance.SettingsRegistry.DrawDebugArea.Value)
			{
				return;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, 0.1f, 0f);
			foreach (var value in PropertyPatch._propertyIdlePointRects.Values)
			{
				Logger.Msg($"Drawing Employee Area at {value.Item1 + val}, {value.Item2 + val}");
				GameObject item = DrawDebugArea(value.Item1 + val, value.Item2 + val, new Color(1f, 0f, 0f, 0.2f));
				_areas.Add(item);
			}
		}

		private static GameObject DrawDebugArea(Vector3 a, Vector3 b, Color color)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: 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_002a: 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_0030: 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_003c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0107: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)5);
			((Object)val).name = "DebugArea";
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			Vector3 val2 = Vector3.Min(a, b);
			Vector3 val3 = Vector3.Max(a, b);
			Vector3 val4 = (val2 + val3) * 0.5f;
			Vector3 val5 = val3 - val2;
			val.transform.position = val4 + Vector3.up * 0.01f;
			val.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
			val.transform.localScale = new Vector3(val5.x, val5.z, 1f);
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			Shader val6 = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)val6 == (Object)null)
			{
				return val;
			}
			Material val7 = new Material(val6);
			if (val7.HasProperty("_Surface"))
			{
				val7.SetFloat("_Surface", 1f);
			}
			if (color.a <= 0f)
			{
				color.a = 0.2f;
			}
			if (val7.HasProperty("_BaseColor"))
			{
				val7.SetColor("_BaseColor", color);
			}
			if (val7.HasProperty("_EmissionColor"))
			{
				val7.EnableKeyword("_EMISSION");
				val7.SetColor("_EmissionColor", new Color(color.r, color.g, color.b) * 1.5f);
			}
			val7.SetInt("_ZWrite", 0);
			val7.renderQueue = 3000;
			((Renderer)component).material = val7;
			return val;
		}

		internal static void WireDebugAreaDrawer(DebugAreaDrawer debugAreaDrawer)
		{
			Player.LocalPlayerSpawned += delegate
			{
				debugAreaDrawer.Draw();
			};
			((MelonEventBase<LemonAction<bool, bool>>)(object)Melon<EmployeeTweaks>.Instance.SettingsRegistry.DrawDebugArea.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate
			{
				debugAreaDrawer.Draw();
			}, 0, false);
		}
	}
	[HarmonyPatch]
	internal class PropertyPatch
	{
		private static Logger Logger = new Logger("PropertyPatch");

		internal static Dictionary<Property, (Vector3, Vector3)> _propertyIdlePointRects = new Dictionary<Property, (Vector3, Vector3)>();

		[HarmonyPatch(typeof(Property), "NetworkInitialize___Early")]
		[HarmonyPriority(-100)]
		[HarmonyPrefix]
		private static void StorePointRectAndAddCapacity(Property __instance)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (mig

EmployeeTweaks-Mono.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using EmployeeTweaks;
using EmployeeTweaks.Helpers;
using EmployeeTweaks.Network;
using EmployeeTweaks.Patches.EmployeeArea;
using EmployeeTweaks.Patches.FilterItemApply;
using EmployeeTweaks.Patches.MoreEmployeeConfigItems;
using EmployeeTweaks.Patches.Unpackaging;
using EmployeeTweaks.Persistence;
using FishNet;
using FishNet.Connection;
using FishNet.Object;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Internal.Abstraction;
using S1API.Saveables;
using S1API.UI;
using S1API.Utils;
using ScheduleOne;
using ScheduleOne.Core.Items.Framework;
using ScheduleOne.Effects;
using ScheduleOne.Employees;
using ScheduleOne.EntityFramework;
using ScheduleOne.Growing;
using ScheduleOne.ItemFramework;
using ScheduleOne.Management;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.Behaviour;
using ScheduleOne.ObjectScripts;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Product;
using ScheduleOne.Property;
using ScheduleOne.Tiles;
using ScheduleOne.Tools;
using ScheduleOne.UI.Items;
using ScheduleOne.UI.Management;
using Semver;
using SteamNetworkLib;
using SteamNetworkLib.Events;
using SteamNetworkLib.Models;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::EmployeeTweaks.EmployeeTweaks), "EmployeeTweaks", "1.0.7", "k073l", "https://github.com/k073l/s1-employeetweaks")]
[assembly: MelonColor(1, 217, 131, 36)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonOptionalDependencies(new string[] { "SteamNetworkLib" })]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("EmployeeTweaks-Mono")]
[assembly: AssemblyConfiguration("Mono")]
[assembly: AssemblyDescription("Various employee tweaks - unpackaging, sprinkler/pourer use and more")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+700441f409a80695300df63551bba49015f12b56")]
[assembly: AssemblyProduct("EmployeeTweaks-Mono")]
[assembly: AssemblyTitle("EmployeeTweaks-Mono")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EmployeeTweaks
{
	public static class BuildInfo
	{
		public const string Name = "EmployeeTweaks";

		public const string Description = "Various employee tweaks - unpackaging, sprinkler/pourer use and more";

		public const string Author = "k073l";

		public const string Version = "1.0.7";
	}
	public class EmployeeTweaks : MelonMod
	{
		private static Logger Logger;

		private DebugAreaDrawer debugAreaDrawer;

		private bool _lastShift;

		private bool _lastCtrl;

		internal SettingsRegistry SettingsRegistry;

		internal INetworkManager? NetworkManager;

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			CheckDependencies();
			MoveItemBehaviourPatches.ManualPatchDestinationValid(((MelonBase)this).HarmonyInstance);
			PropertyPatch.ManualPatchProperties(((MelonBase)this).HarmonyInstance);
		}

		public override void OnLateInitializeMelon()
		{
			SettingsRegistry = new SettingsRegistry();
			NetworkManager = NetworkLoader.Create();
			if (NetworkManager == null)
			{
				Logger.Warning("NetworkManager is null, multiplayer features will be unavailable.");
			}
			SettingsRegistry.InitializeCategories();
			NetworkManager?.RegisterLoggerSettings();
			debugAreaDrawer = new DebugAreaDrawer();
			DebugAreaDrawer.WireDebugAreaDrawer(debugAreaDrawer);
			Logger.Msg("EmployeeTweaks initialized");
		}

		public override void OnUpdate()
		{
			NetworkManager?.Update();
		}

		public override void OnLateUpdate()
		{
			TextMeshProUGUI applyItemAsFilterButtonText = FilterConfigPanelPatches.ApplyItemAsFilterButtonText;
			if (!((Object)(object)applyItemAsFilterButtonText == (Object)null))
			{
				bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
				bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
				if (flag != _lastShift || flag2 != _lastCtrl)
				{
					_lastShift = flag;
					_lastCtrl = flag2;
					FilterConfigPanelPatches.AllSlots = flag;
					FilterConfigPanelPatches.DenyListMode = flag2;
					((TMP_Text)applyItemAsFilterButtonText).text = (flag ? "Apply All As Filters" : "Apply Item As Filter");
				}
			}
		}

		public override void OnDeinitializeMelon()
		{
			NetworkManager?.Dispose();
		}

		private static void CheckDependencies()
		{
			DependenciesChecker dependenciesChecker = new DependenciesChecker
			{
				ShowMenuBanner = true,
				UnloadIfMissingRequired = true
			};
			dependenciesChecker.AddDependency(new DependencyInfo
			{
				Name = "S1API (Forked)",
				AssemblyName = "S1API",
				IsRequired = true,
				Version = "3.1.0",
				Urls = new List<DependencyUrl>(3)
				{
					new DependencyUrl
					{
						SourceName = "Thunderstore",
						Url = "https://thunderstore.io/c/schedule-i/p/ifBars/S1API_Forked/"
					},
					new DependencyUrl
					{
						SourceName = "NexusMods",
						Url = "https://www.nexusmods.com/schedule1/mods/1194"
					},
					new DependencyUrl
					{
						SourceName = "Github",
						Url = "https://github.com/ifBars/S1API/releases/"
					}
				}
			});
			dependenciesChecker.AddDependency(new DependencyInfo
			{
				Name = "SteamNetworkLib",
				AssemblyName = "SteamNetworkLib",
				IsRequired = false,
				Version = "1.2.1",
				Urls = new List<DependencyUrl>(4)
				{
					new DependencyUrl
					{
						SourceName = "Thunderstore Il2Cpp",
						Url = "https://thunderstore.io/c/schedule-i/p/ifBars/SteamNetworkLib_Il2Cpp/"
					},
					new DependencyUrl
					{
						SourceName = "Thunderstore Mono",
						Url = "https://thunderstore.io/c/schedule-i/p/ifBars/SteamNetworkLib_Mono/"
					},
					new DependencyUrl
					{
						SourceName = "NexusMods",
						Url = "https://www.nexusmods.com/schedule1/mods/1396"
					},
					new DependencyUrl
					{
						SourceName = "Github",
						Url = "https://github.com/ifBars/SteamNetworkLib/releases"
					}
				}
			});
			dependenciesChecker.ProcessAndAlert();
		}
	}
	internal class SettingsRegistry
	{
		internal MelonPreferences_Category EmployeeCapacityCategory;

		internal NetworkedMelonEntry<bool> EnableCapacityAndDebug;

		internal MelonPreferences_Entry<bool> DrawDebugArea;

		internal HashSet<NetworkedMelonEntry<int>> EmployeeCapacities = new HashSet<NetworkedMelonEntry<int>>();

		internal MelonPreferences_Category EmployeeAssignsCategory;

		internal NetworkedMelonEntry<bool> EnableAssigns;

		internal NetworkedMelonEntry<int> BotanistMaxPots;

		internal NetworkedMelonEntry<int> HandlerMaxStations;

		internal NetworkedMelonEntry<int> HandlerMaxRoutes;

		internal NetworkedMelonEntry<int> ChemistMaxStations;

		internal NetworkedMelonEntry<int> CleanerMaxBins;

		internal MelonPreferences_Category EmployeeTweaksDebugCategory;

		internal MelonPreferences_Entry<bool> EnableNetworkDebug;

		internal MelonPreferences_Entry<bool> EnableConfigItemsDebug;

		internal MelonPreferences_Entry<bool> EnableUnpackagingDebug;

		internal object? _boxedClient = null;

		internal object? _boxedOptions = null;

		public bool InitializeNetwork(object? client)
		{
			if (client == null)
			{
				return false;
			}
			_boxedClient = client;
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "SteamNetworkLib");
			if (assembly == null)
			{
				return false;
			}
			Type type = assembly.GetType("SteamNetworkLib.Sync.NetworkSyncOptions");
			if (type == null)
			{
				return false;
			}
			_boxedOptions = Activator.CreateInstance(type);
			if (_boxedOptions == null)
			{
				return false;
			}
			PropertyInfo property = type.GetProperty("KeyPrefix");
			if (property == null)
			{
				return false;
			}
			property.SetValue(_boxedOptions, Assembly.GetExecutingAssembly().GetName().Name + "_");
			return true;
		}

		public void InitializeCategories()
		{
			InitializeCapacityCategory();
			InitializeAssignsCategory();
			InitializeModDebugCategory();
		}

		private void InitializeCapacityCategory()
		{
			EmployeeCapacityCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeCapacity", "Employee Capacities");
			EnableCapacityAndDebug = EmployeeCapacityCategory.GetOrCreateNetworkedEntry("EmployeeTweaksEnableCapacityAndDebug", defaultValue: true, _boxedClient, _boxedOptions, announce: true, "Enable Category", "Enables employee capacity tweaks and drawing employee idle points area");
			DrawDebugArea = EmployeeCapacityCategory.CreateEntry<bool>("EmployeeTweaksDrawDebugArea", false, "Draw Debug Area", "Draws a debug area where employee idle points are contained", false, false, (ValueValidator)null, (string)null);
		}

		private void InitializeAssignsCategory()
		{
			EmployeeAssignsCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeAssignsCategory", "Employee Assigns Capacities");
			EnableAssigns = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksEnableAssigns", defaultValue: true, _boxedClient, _boxedOptions, announce: true, "Enable Category", "Enables employee assigns capacity modifications");
			BotanistMaxPots = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksBotanistMaxPots", 8, _boxedClient, _boxedOptions, announce: true, "Botanist Max Pots", $"Maximum number of pots a botanist can be assigned to (allowed values from {SettingsConstants.BotanistBoundsMaxPots.Item1} to {SettingsConstants.BotanistBoundsMaxPots.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.BotanistBoundsMaxPots.Item1, SettingsConstants.BotanistBoundsMaxPots.Item2));
			HandlerMaxStations = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksHandlerMaxStations", 3, _boxedClient, _boxedOptions, announce: true, "Handler Max Stations", $"Maximum number of stations a packager can be assigned to (allowed values from {SettingsConstants.HandlerBoundsMaxStations.Item1} to {SettingsConstants.HandlerBoundsMaxStations.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxStations.Item1, SettingsConstants.HandlerBoundsMaxStations.Item2));
			HandlerMaxRoutes = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksHandlerMaxRoutes", 5, _boxedClient, _boxedOptions, announce: true, "Handler Max Routes", $"Maximum number of routes a packager can be assigned to (allowed values from {SettingsConstants.HandlerBoundsMaxRoutes.Item1} to {SettingsConstants.HandlerBoundsMaxRoutes.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxRoutes.Item1, SettingsConstants.HandlerBoundsMaxRoutes.Item2));
			ChemistMaxStations = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksChemistMaxStations", 4, _boxedClient, _boxedOptions, announce: true, "Chemist Max Stations", $"Maximum number of stations a chemist can be assigned to (allowed values from {SettingsConstants.ChemistBoundsMaxStations.Item1} to {SettingsConstants.ChemistBoundsMaxStations.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.ChemistBoundsMaxStations.Item1, SettingsConstants.ChemistBoundsMaxStations.Item2));
			CleanerMaxBins = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksCleanerMaxBins", 6, _boxedClient, _boxedOptions, announce: true, "Cleaner Max Trash Cans", $"Maximum number of trash cans a cleaner can be assigned to (allowed values from {SettingsConstants.CleanerBoundsMaxBins.Item1} to {SettingsConstants.CleanerBoundsMaxBins.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(SettingsConstants.CleanerBoundsMaxBins.Item1, SettingsConstants.CleanerBoundsMaxBins.Item2));
		}

		private void InitializeModDebugCategory()
		{
			EmployeeTweaksDebugCategory = MelonPreferences.CreateCategory("EmployeeTweaksDebug", "Employee Tweaks Debug&Troubleshooting");
			EnableNetworkDebug = EmployeeTweaksDebugCategory.CreateEntry<bool>("EmployeeTweaksEnableNetworkDebug", false, "Enable Network Debug", "Enables debug logging for networked preferences", false, false, (ValueValidator)null, (string)null);
			EnableConfigItemsDebug = EmployeeTweaksDebugCategory.CreateEntry<bool>("EmployeeTweaksEnableConfigItemsDebug", false, "Enable Config Items Debug", "Enables debug logging for employee config items", false, false, (ValueValidator)null, (string)null);
			EnableUnpackagingDebug = EmployeeTweaksDebugCategory.CreateEntry<bool>("EmployeeTweaksEnableUnpackagingDebug", false, "Enable Unpackaging Debug", "Enables debug logging for unpackaging", false, false, (ValueValidator)null, (string)null);
		}

		private void PushLoggerSettings()
		{
			SetAndRegister(ClipboardUIHelper.Logger, EnableConfigItemsDebug);
			SetAndRegister(SharedClipboardPatches.Logger, EnableConfigItemsDebug);
			SetAndRegister(PackagingStationConfigPanelPatch.Logger, EnableUnpackagingDebug);
			SetAndRegister(MoveItemBehaviourPatches.Logger, EnableUnpackagingDebug);
			SetAndRegister(PackagerPatches.Logger, EnableUnpackagingDebug);
		}

		private void SetAndRegister(Logger logger, MelonPreferences_Entry<bool>? entry)
		{
			logger.RaiseDebug = entry?.Value ?? false;
			((MelonEventBase<LemonAction<bool, bool>>)(object)entry?.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate(bool _, bool newValue)
			{
				logger.RaiseDebug = newValue;
			}, 0, false);
		}
	}
	internal static class SettingsConstants
	{
		public const int BotanistDefaultMaxPots = 8;

		public static (int, int) BotanistBoundsMaxPots = (1, 32);

		public const int HandlerDefaultMaxStations = 3;

		public static (int, int) HandlerBoundsMaxStations = (1, 8);

		public const int HandlerDefaultMaxRoutes = 5;

		public static (int, int) HandlerBoundsMaxRoutes = (1, 16);

		public const int ChemistDefaultMaxStations = 4;

		public static (int, int) ChemistBoundsMaxStations = (1, 32);

		public const int CleanerDefaultMaxBins = 6;

		public static (int, int) CleanerBoundsMaxBins = (1, 32);
	}
}
namespace EmployeeTweaks.Persistence
{
	public class UnpackageSave : Saveable
	{
		[SaveableField("UnpackageStations")]
		public Dictionary<Guid, bool> UnpackageStations = new Dictionary<Guid, bool>();

		private static UnpackageSave _instance;

		public static UnpackageSave Instance => _instance ?? (_instance = new UnpackageSave());

		public UnpackageSave()
		{
			_instance = this;
		}

		protected override void OnLoaded()
		{
			INetworkManager? networkManager = Melon<EmployeeTweaks>.Instance.NetworkManager;
			if (networkManager == null || networkManager.IsSingleplayer)
			{
				return;
			}
			foreach (KeyValuePair<Guid, bool> unpackageStation in UnpackageStations)
			{
				Melon<EmployeeTweaks>.Instance.NetworkManager?.BroadcastStation(unpackageStation.Key.ToString(), unpackageStation.Value);
			}
		}

		public bool TryGetValue(Guid guid, out bool value)
		{
			return UnpackageStations.TryGetValue(guid, out value);
		}
	}
}
namespace EmployeeTweaks.Patches.Unpackaging
{
	[HarmonyPatch(typeof(AdvancedTransitRoute))]
	internal static class AdvancedTransitRoutePatch
	{
		[HarmonyPatch("GetItemReadyToMove")]
		[HarmonyPrefix]
		private static bool GetItemReadyToMove(AdvancedTransitRoute __instance, ref ItemInstance __result)
		{
			if (((TransitRoute)__instance).Source == null || ((TransitRoute)__instance).Destination == null)
			{
				return true;
			}
			if (((TransitRoute)__instance).Destination == null)
			{
				return true;
			}
			ITransitEntity destination = ((TransitRoute)__instance).Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = ((TransitRoute)__instance).Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (flag)
			{
				foreach (ItemSlot outputSlot in ((TransitRoute)__instance).Source.OutputSlots)
				{
					if (outputSlot.ItemInstance != null && __instance.Filter.DoesItemMeetFilter(outputSlot.ItemInstance))
					{
						int outputCapacityForItem = destination.GetOutputCapacityForItem(outputSlot.ItemInstance, (NPC)null);
						if (outputCapacityForItem > 0)
						{
							__result = outputSlot.ItemInstance.GetCopy(Mathf.Min(outputCapacityForItem, ((BaseItemInstance)outputSlot.ItemInstance).Quantity));
							return false;
						}
					}
				}
			}
			else
			{
				foreach (ItemSlot inputSlot in ((TransitRoute)__instance).Source.InputSlots)
				{
					if (inputSlot.ItemInstance != null && __instance.Filter.DoesItemMeetFilter(inputSlot.ItemInstance))
					{
						int inputCapacityForItem = destination.GetInputCapacityForItem(inputSlot.ItemInstance, (NPC)null, true);
						if (inputCapacityForItem > 0)
						{
							__result = inputSlot.ItemInstance.GetCopy(Mathf.Min(inputCapacityForItem, ((BaseItemInstance)inputSlot.ItemInstance).Quantity));
							return false;
						}
					}
				}
			}
			__result = null;
			return false;
		}
	}
	[HarmonyPatch(typeof(MoveItemBehaviour))]
	internal static class MoveItemBehaviourPatches
	{
		internal static readonly Logger Logger = new Logger("MoveItemBehaviourPatches");

		private static Dictionary<MoveItemBehaviour, object> customGrabRunning = new Dictionary<MoveItemBehaviour, object>();

		private static Dictionary<MoveItemBehaviour, object> customPlaceRunning = new Dictionary<MoveItemBehaviour, object>();

		internal static void ManualPatchDestinationValid(Harmony harmony)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(MoveItemBehaviour), "IsDestinationValid", new Type[3]
			{
				typeof(TransitRoute),
				typeof(ItemInstance),
				typeof(string).MakeByRefType()
			}, (Type[])null);
			if (methodInfo == null)
			{
				Logger.Error("Failed to find IsDestinationValid method!");
				return;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MoveItemBehaviourPatches), "IsDestinationValid", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(MoveItemBehaviour), "IsTransitRouteValid", new Type[3]
			{
				typeof(TransitRoute),
				typeof(string),
				typeof(string).MakeByRefType()
			}, (Type[])null);
			if (methodInfo2 == null)
			{
				Logger.Error("Failed to find IsTransitRouteValid method!");
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(MoveItemBehaviourPatches), "IsTransitRouteValidID", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static bool IsDestinationValid(MoveItemBehaviour __instance, TransitRoute route, ItemInstance item, ref string invalidReason, ref bool __result)
		{
			invalidReason = string.Empty;
			if (((route != null) ? route.Destination : null) == null)
			{
				__result = false;
				return true;
			}
			ITransitEntity destination = route.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = route.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				__result = false;
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				__result = false;
				return true;
			}
			if (!__instance.CanGetToDestination(route))
			{
				invalidReason = "Cannot get to destination!";
				__result = false;
				return false;
			}
			if (!__instance.CanGetToSource(route))
			{
				invalidReason = "Cannot get to source!";
				__result = false;
				return false;
			}
			if ((flag ? destination.GetOutputCapacityForItem(item, ((Behaviour)__instance).Npc) : destination.GetInputCapacityForItem(item, ((Behaviour)__instance).Npc, true)) == 0)
			{
				invalidReason = "Destination has no capacity for item!";
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}

		private static bool IsTransitRouteValidID(MoveItemBehaviour __instance, TransitRoute route, string itemID, ref string invalidReason, ref bool __result)
		{
			invalidReason = string.Empty;
			if (((route != null) ? route.Destination : null) == null || route.Source == null)
			{
				__result = false;
				return true;
			}
			ITransitEntity destination = route.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = route.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				__result = false;
				return true;
			}
			if (!route.AreEntitiesNonNull())
			{
				invalidReason = "Entities are null!";
				__result = false;
				return false;
			}
			ItemSlot firstSlotContainingItem = source.GetFirstSlotContainingItem(itemID, (ESlotType)(!flag2));
			ItemInstance val2 = ((firstSlotContainingItem != null) ? firstSlotContainingItem.ItemInstance : null);
			if (val2 == null || ((BaseItemInstance)val2).Quantity <= 0)
			{
				invalidReason = "Item is null or quantity is 0!";
				__result = false;
				return false;
			}
			if (!__instance.IsDestinationValid(route, val2, ref invalidReason))
			{
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}

		[HarmonyPatch("IsNpcInventoryItemValid")]
		[HarmonyPrefix]
		private static bool CheckNpcInventoryItemValid(MoveItemBehaviour __instance, ItemInstance item, ref bool __result)
		{
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (flag)
			{
				if (destination.GetOutputCapacityForItem(item, ((Behaviour)__instance).Npc) == 0)
				{
					__result = false;
					return false;
				}
			}
			else if (destination.GetInputCapacityForItem(item, ((Behaviour)__instance).Npc, true) == 0)
			{
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}

		[HarmonyPatch("GetAmountToGrab")]
		[HarmonyPrefix]
		private static bool GetAmountToGrab(MoveItemBehaviour __instance, ref int __result)
		{
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0));
			ItemInstance val2 = ((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null);
			if (val2 == null)
			{
				__result = 0;
				return false;
			}
			int num = ((BaseItemInstance)val2).Quantity;
			if (__instance.maxMoveAmount > 0)
			{
				num = Mathf.Min(__instance.maxMoveAmount, num);
			}
			int num2 = (flag ? destination.GetOutputCapacityForItem(val2, ((Behaviour)__instance).Npc) : destination.GetInputCapacityForItem(val2, ((Behaviour)__instance).Npc, true));
			__result = Mathf.Min(num, num2);
			return false;
		}

		[HarmonyPatch("GrabItem")]
		[HarmonyPrefix]
		private static bool GrabItem(MoveItemBehaviour __instance)
		{
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Source : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (flag)
			{
				return true;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log((object)"MoveItemBehaviour.GrabItem", (Object)null);
			}
			__instance.currentState = (EState)2;
			__instance.grabRoutine = null;
			object value2 = MelonCoroutines.Start(Routine());
			customGrabRunning[__instance] = value2;
			return false;
			IEnumerator Routine()
			{
				Transform sourceAccessPoint = __instance.GetSourceAccessPoint(__instance.assignedRoute);
				if ((Object)(object)sourceAccessPoint == (Object)null)
				{
					LogWarning("Could not find source access point!");
					__instance.grabRoutine = null;
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
				}
				else
				{
					((Behaviour)__instance).Npc.Movement.FaceDirection(sourceAccessPoint.forward, 0.5f);
					((Behaviour)__instance).Npc.SetAnimationTrigger_Networked((NetworkConnection)null, "GrabItem");
					if (!Utils.Is<Employee>(((Behaviour)__instance).Npc, out Employee employee) || (Object)(object)employee == (Object)null)
					{
						Logger.Debug("Could not find employee!");
						yield break;
					}
					float seconds = 0.5f / employee.CurrentWorkSpeed;
					yield return (object)new WaitForSeconds(seconds);
					ItemInstance itemToRetrieveTemplate = __instance.itemToRetrieveTemplate;
					if (((itemToRetrieveTemplate != null) ? ((BaseItemInstance)itemToRetrieveTemplate).ID : null) == null)
					{
						Logger.Debug("Could not find item to retrieve template!");
						yield break;
					}
					string invalidReason = default(string);
					if (!__instance.IsTransitRouteValid(__instance.assignedRoute, ((BaseItemInstance)__instance.itemToRetrieveTemplate).ID, ref invalidReason))
					{
						LogWarning(((Behaviour)__instance).Npc.FullName + " transit route no longer valid! Reason: " + invalidReason);
						__instance.grabRoutine = null;
						((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					}
					else
					{
						__instance.TakeItem();
						yield return (object)new WaitForSeconds(0.5f);
						__instance.grabRoutine = null;
						__instance.currentState = (EState)0;
					}
				}
				customGrabRunning.Remove(__instance);
			}
		}

		[HarmonyPatch("TakeItem")]
		[HarmonyPrefix]
		private static bool TakeItem(MoveItemBehaviour __instance)
		{
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			PackagingStation val = (flag ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log((object)"MoveItemBehaviour.TakeItem", (Object)null);
			}
			int amountToGrab = __instance.GetAmountToGrab();
			if (amountToGrab == 0)
			{
				LogWarning("Amount to grab is 0!");
				return false;
			}
			ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0));
			if (((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null) == null)
			{
				Logger.Debug("Could not find first slot containing item!");
				return false;
			}
			ItemInstance copy = firstSlotContainingTemplateItem.ItemInstance.GetCopy(amountToGrab);
			__instance.grabbedAmount = amountToGrab;
			firstSlotContainingTemplateItem.ChangeQuantity(-amountToGrab, false);
			((Behaviour)__instance).Npc.Inventory.InsertItem(copy, true);
			if (flag)
			{
				destination.ReserveOutputSlotsForItem(copy, ((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
			}
			else
			{
				destination.ReserveInputSlotsForItem(copy, ((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
			}
			return false;
		}

		[HarmonyPatch("PlaceItem")]
		[HarmonyPrefix]
		private static bool PlaceItem(MoveItemBehaviour __instance)
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute assignedRoute = __instance.assignedRoute;
			if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity dest = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool destIsStation = Utils.Is2<PackagingStation>(dest, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!destIsStation && !flag)
			{
				return true;
			}
			PackagingStation val = (destIsStation ? result : result2);
			UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log((object)"MoveItemBehaviour.PlaceItem", (Object)null);
			}
			__instance.currentState = (EState)4;
			__instance.placingRoutine = null;
			object value2 = MelonCoroutines.Start(Routine());
			customPlaceRunning[__instance] = value2;
			return false;
			IEnumerator Routine()
			{
				if ((Object)(object)__instance.GetDestinationAccessPoint(__instance.assignedRoute) != (Object)null)
				{
					((Behaviour)__instance).Npc.Movement.FaceDirection(__instance.GetDestinationAccessPoint(__instance.assignedRoute).forward, 0.5f);
				}
				((Behaviour)__instance).Npc.SetAnimationTrigger_Networked((NetworkConnection)null, "GrabItem");
				if (!Utils.Is<Employee>(((Behaviour)__instance).Npc, out Employee employee) || (Object)(object)employee == (Object)null)
				{
					Logger.Debug("Could not find employee!");
					customPlaceRunning.Remove(__instance);
				}
				else
				{
					float seconds = 0.5f / employee.CurrentWorkSpeed;
					yield return (object)new WaitForSeconds(seconds);
					if (destIsStation)
					{
						dest.RemoveOutputSlotLocks(((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
					}
					else
					{
						dest.RemoveSlotLocks(((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject);
					}
					ItemInstance firstIdenticalItem = ((Behaviour)__instance).Npc.Inventory.GetFirstIdenticalItem(__instance.itemToRetrieveTemplate, (ItemFilter)null);
					if (firstIdenticalItem != null && __instance.grabbedAmount > 0)
					{
						ItemInstance copy = firstIdenticalItem.GetCopy(__instance.grabbedAmount);
						if (destIsStation)
						{
							if (dest.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount)
							{
								dest.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc);
							}
							else
							{
								LogWarning("Destination does not have enough capacity for item! Attempting to return item to source.");
								if (__instance.assignedRoute.Source.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount)
								{
									__instance.assignedRoute.Source.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc);
								}
								else
								{
									LogError("Source does not have enough capacity for item! Item will be lost.");
								}
							}
						}
						else if (dest.GetInputCapacityForItem(copy, ((Behaviour)__instance).Npc, true) >= __instance.grabbedAmount)
						{
							dest.InsertItemIntoInput(copy, ((Behaviour)__instance).Npc);
						}
						else
						{
							LogWarning("Destination does not have enough capacity for item! Attempting to return item to source.");
							if (__instance.assignedRoute.Source.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount)
							{
								__instance.assignedRoute.Source.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc);
							}
							else
							{
								LogError("Source does not have enough capacity for item! Item will be lost.");
							}
						}
						((BaseItemInstance)firstIdenticalItem).ChangeQuantity(-__instance.grabbedAmount);
					}
					else
					{
						LogWarning("Could not find carried item to place!");
					}
					yield return (object)new WaitForSeconds(0.5f);
					__instance.placingRoutine = null;
					__instance.currentState = (EState)0;
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					customPlaceRunning.Remove(__instance);
				}
			}
		}

		[HarmonyPatch("StopCurrentActivity")]
		[HarmonyPrefix]
		private static bool StopCurrentActivity(MoveItemBehaviour __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			EState currentState = __instance.currentState;
			EState val = currentState;
			if ((int)val != 2)
			{
				if ((int)val == 4)
				{
					if (customPlaceRunning.TryGetValue(__instance, out object value))
					{
						MelonCoroutines.Stop(value);
						customPlaceRunning.Remove(__instance);
						return false;
					}
					return true;
				}
				return true;
			}
			if (customGrabRunning.TryGetValue(__instance, out object value2))
			{
				MelonCoroutines.Stop(value2);
				customGrabRunning.Remove(__instance);
				return false;
			}
			return true;
		}

		[HarmonyPatch("OnActiveTick")]
		[HarmonyPrefix]
		private static bool OnActiveTick(MoveItemBehaviour __instance)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Invalid comparison between Unknown and I4
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			if (!__instance.assignedRoute.AreEntitiesNonNull())
			{
				LogWarning("Transit route entities are null!");
				((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
				return false;
			}
			if (((Behaviour)__instance).beh.DEBUG_MODE)
			{
				Console.Log((object)("State: " + ((object)Unsafe.As<EState, EState>(ref __instance.currentState)/*cast due to .constrained prefix*/).ToString()), (Object)null);
				Console.Log((object)("Moving: " + ((Behaviour)__instance).Npc.Movement.IsMoving), (Object)null);
			}
			if ((int)__instance.currentState > 0)
			{
				return false;
			}
			if (((Behaviour)__instance).Npc.Inventory.GetIdenticalItemAmount(__instance.itemToRetrieveTemplate) > 0 && __instance.grabbedAmount > 0)
			{
				if (__instance.IsAtDestination())
				{
					__instance.PlaceItem();
				}
				else
				{
					__instance.WalkToDestination();
				}
			}
			else if (__instance.skipPickup)
			{
				__instance.TakeItem();
				__instance.skipPickup = false;
			}
			else if (__instance.IsAtSource())
			{
				__instance.GrabItem();
			}
			else
			{
				__instance.WalkToSource();
			}
			return false;
		}

		[HarmonyPatch("StartTransit")]
		[HarmonyPrefix]
		private static bool StartTransit(MoveItemBehaviour __instance)
		{
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			ITransitEntity destination = __instance.assignedRoute.Destination;
			PackagingStation result;
			bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
			ITransitEntity source = __instance.assignedRoute.Source;
			PackagingStation result2;
			bool flag2 = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
			if (!flag && !flag2)
			{
				return true;
			}
			object[] obj = new object[4]
			{
				__instance.assignedRoute.Source.Name,
				__instance.assignedRoute.Destination.Name,
				null,
				null
			};
			ItemInstance itemToRetrieveTemplate = __instance.itemToRetrieveTemplate;
			obj[2] = ((itemToRetrieveTemplate != null) ? ((BaseItemInstance)itemToRetrieveTemplate).ID : null);
			ItemInstance itemToRetrieveTemplate2 = __instance.itemToRetrieveTemplate;
			obj[3] = ((itemToRetrieveTemplate2 != null) ? new int?(((BaseItemInstance)itemToRetrieveTemplate2).Quantity) : ((int?)null));
			Console.Log((object)string.Format("{0} ->  {1} ({2}x{3})", obj), (Object)null);
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			if (((Behaviour)__instance).Npc.Inventory.GetIdenticalItemAmount(__instance.itemToRetrieveTemplate) == 0)
			{
				ItemInstance itemToRetrieveTemplate3 = __instance.itemToRetrieveTemplate;
				if (((itemToRetrieveTemplate3 != null) ? ((BaseItemInstance)itemToRetrieveTemplate3).ID : null) == null)
				{
					return false;
				}
				string text = default(string);
				if (!__instance.IsTransitRouteValid(__instance.assignedRoute, ((BaseItemInstance)__instance.itemToRetrieveTemplate).ID, ref text))
				{
					LogWarning("Invalid transit route for move item behaviour by checking transit route!. Reason: " + text);
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					return false;
				}
			}
			else
			{
				ItemInstance firstIdenticalItem = ((Behaviour)__instance).Npc.Inventory.GetFirstIdenticalItem(__instance.itemToRetrieveTemplate, new ItemFilter(__instance.IsNpcInventoryItemValid));
				if (((Behaviour)__instance).Npc.Behaviour.DEBUG_MODE)
				{
					Console.Log((object)("Moving item: " + (object)firstIdenticalItem), (Object)null);
				}
				string text2 = default(string);
				if (!__instance.IsDestinationValid(__instance.assignedRoute, firstIdenticalItem, ref text2))
				{
					LogWarning("Invalid transit route for move item behaviour by checking destination! Reason: " + text2);
					((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
					return false;
				}
			}
			__instance.currentState = (EState)0;
			return false;
		}

		private static void LogWarning(string msg)
		{
			Console.LogWarning((object)msg, (Object)null);
			Logger.Debug(msg);
		}

		private static void LogError(string msg)
		{
			Console.LogError((object)msg, (Object)null);
			Logger.Debug(msg);
		}
	}
	[HarmonyPatch(typeof(Packager))]
	internal static class PackagerPatches
	{
		internal static readonly Logger Logger = new Logger("PackagerPatches");

		[HarmonyWrapSafe]
		[HarmonyPatch("GetStationMoveItems")]
		[HarmonyPrefix]
		private static bool GetStationMoveItems(Packager __instance, ref PackagingStation __result)
		{
			PackagingStation result = default(PackagingStation);
			bool value = default(bool);
			foreach (PackagingStation assignedStation in __instance.configuration.AssignedStations)
			{
				if ((Object)(object)assignedStation != (Object)null && Utils.Is<PackagingStation>(assignedStation, out result) && (Object)(object)result != (Object)null && UnpackageSave.Instance.TryGetValue(((BuildableItem)result).GUID, out value) && value)
				{
					List<ItemSlot> inputSlots = result.InputSlots;
					if (Utils.Is<PackagingStationConfiguration>(assignedStation.Configuration, out PackagingStationConfiguration config) && config != null)
					{
						bool flag = (from x in inputSlots.AsEnumerable()
							where x != null
							select x.ItemInstance into x
							where ((x != null) ? ((BaseItemInstance)x).ID : null) != null
							select x).Any((ItemInstance x) => ((Employee)__instance).MoveItemBehaviour.IsTransitRouteValid(config.DestinationRoute, ((BaseItemInstance)x).ID));
						if (inputSlots.AsEnumerable().Sum((ItemSlot x) => x.Quantity) != 0 && flag)
						{
							__result = assignedStation;
							return false;
						}
					}
				}
				else
				{
					ItemSlot outputSlot = assignedStation.OutputSlot;
					if (Utils.Is<PackagingStationConfiguration>(assignedStation.Configuration, out PackagingStationConfiguration result2) && result2 != null && outputSlot.Quantity != 0 && ((Employee)__instance).MoveItemBehaviour.IsTransitRouteValid(result2.DestinationRoute, ((BaseItemInstance)outputSlot.ItemInstance).ID))
					{
						__result = assignedStation;
						return false;
					}
				}
			}
			__result = null;
			return false;
		}

		[HarmonyPatch("StartMoveItem", new Type[] { typeof(PackagingStation) })]
		[HarmonyPrefix]
		private static bool StartMoveItem(Packager __instance, PackagingStation station)
		{
			UnpackageSave.Instance.TryGetValue(((BuildableItem)station).GUID, out var value);
			if (!value)
			{
				return true;
			}
			if (!Utils.Is<PackagingStationConfiguration>(station.Configuration, out PackagingStationConfiguration config) || config == null)
			{
				return true;
			}
			ItemSlot val = station.InputSlots.AsEnumerable().FirstOrDefault((Func<ItemSlot, bool>)delegate(ItemSlot x)
			{
				if (x.ItemInstance == null)
				{
					return false;
				}
				string text = default(string);
				bool flag = ((Employee)__instance).MoveItemBehaviour.IsTransitRouteValid(config.DestinationRoute, ((BaseItemInstance)x.ItemInstance).ID, ref text);
				if (!flag)
				{
					Log("[Unpacked] Rejected item " + ((BaseItemInstance)x.ItemInstance).ID + ": " + text);
				}
				return flag;
			});
			if (val == null)
			{
				return true;
			}
			Log("[Unpacked] Starting moving items from " + ((Object)((Component)station).gameObject).name);
			((Employee)__instance).MoveItemBehaviour.InitializeMoveItemBehaviourWithID(config.DestinationRoute, val.ItemInstance);
			((Behaviour)((Employee)__instance).MoveItemBehaviour).Enable_Networked();
			return false;
		}

		private static void InitializeMoveItemBehaviourWithID(this MoveItemBehaviour moveItemBehaviour, TransitRoute route, ItemInstance _itemToRetrieveTemplate, int _maxMoveAmount = -1, bool _skipPickup = false)
		{
			if (((_itemToRetrieveTemplate != null) ? ((BaseItemInstance)_itemToRetrieveTemplate).ID : null) == null)
			{
				return;
			}
			string text = default(string);
			if (!moveItemBehaviour.IsTransitRouteValid(route, ((BaseItemInstance)_itemToRetrieveTemplate).ID, ref text))
			{
				LogError("Invalid transit route for move item behaviour! Reason: " + text, (Object?)(object)((Component)moveItemBehaviour).gameObject);
				return;
			}
			moveItemBehaviour.assignedRoute = route;
			moveItemBehaviour.itemToRetrieveTemplate = _itemToRetrieveTemplate;
			moveItemBehaviour.maxMoveAmount = _maxMoveAmount;
			if (((Behaviour)moveItemBehaviour).Npc.Behaviour.DEBUG_MODE)
			{
				Log("MoveItemBehaviour initialized with route: " + route.Source.Name + " -> " + route.Destination.Name + " for item: " + ((BaseItemInstance)_itemToRetrieveTemplate).ID);
			}
			moveItemBehaviour.skipPickup = _skipPickup;
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(Employee), "UpdateBehaviour")]
		private static void UpdateEmployeeBehaviour(Employee __instance)
		{
			throw new NotImplementedException();
		}

		[HarmonyPatch("UpdateBehaviour")]
		[HarmonyPrefix]
		private static bool UpdateBehaviour(Packager __instance)
		{
			UpdateEmployeeBehaviour((Employee)(object)__instance);
			if (((Behaviour)__instance.PackagingBehaviour).Active)
			{
				((Employee)__instance).MarkIsWorking();
			}
			else if (((Behaviour)((Employee)__instance).MoveItemBehaviour).Active)
			{
				((Employee)__instance).MarkIsWorking();
			}
			else
			{
				if (!InstanceFinder.IsServer)
				{
					return false;
				}
				if (((Employee)__instance).Fired)
				{
					((Employee)__instance).LeavePropertyAndDespawn();
				}
				else
				{
					if (!((Employee)__instance).CanWork())
					{
						return false;
					}
					if (__instance.configuration.AssignedStationCount + __instance.configuration.Routes.Routes.Count == 0)
					{
						((Employee)__instance).SubmitNoWorkReason("I haven't been assigned to any stations or routes.", "You can use your management clipboards to assign stations or routes to me.", 0);
						((Employee)__instance).SetIdle(true);
					}
					else
					{
						if (!InstanceFinder.IsServer)
						{
							return false;
						}
						PackagingStation stationToAttend = __instance.GetStationToAttend();
						if ((Object)(object)stationToAttend != (Object)null)
						{
							__instance.StartPackaging(stationToAttend);
							return false;
						}
						BrickPress brickPress = __instance.GetBrickPress();
						if ((Object)(object)brickPress != (Object)null)
						{
							__instance.StartPress(brickPress);
							return false;
						}
						PackagingStation stationMoveItems = __instance.GetStationMoveItems();
						if ((Object)(object)stationMoveItems != (Object)null)
						{
							__instance.StartMoveItem(stationMoveItems);
							return false;
						}
						BrickPress brickPressMoveItems = __instance.GetBrickPressMoveItems();
						if ((Object)(object)brickPressMoveItems != (Object)null)
						{
							__instance.StartMoveItem(brickPressMoveItems);
							return false;
						}
						ItemInstance val = default(ItemInstance);
						AdvancedTransitRoute transitRouteReady = __instance.GetTransitRouteReady(ref val);
						if (transitRouteReady != null)
						{
							((Employee)__instance).MoveItemBehaviour.Initialize((TransitRoute)(object)transitRouteReady, val, ((BaseItemInstance)val).Quantity, false);
							((Behaviour)((Employee)__instance).MoveItemBehaviour).Enable_Networked();
						}
						else
						{
							((Employee)__instance).SubmitNoWorkReason("There's nothing for me to do right now.", "I need one of my assigned stations to have enough product and packaging to get to work.", 0);
							((Employee)__instance).SetIdle(true);
						}
					}
				}
			}
			return false;
		}

		private static void Log(string message, Object? context = null)
		{
			Console.Log((object)message, context);
			Logger.Debug($"{message}, context: {context}");
		}

		private static void LogError(string message, Object? context = null)
		{
			Console.LogError((object)message, context);
			Logger.Debug($"{message}, context: {context}");
		}

		private static void LogWarning(string message, Object? context = null)
		{
			Console.LogWarning((object)message, context);
			Logger.Debug($"{message}, context: {context}");
		}
	}
	public static class PackagingStationConfigPatches
	{
		public static Dictionary<Guid, StringField> UnpackageFields = new Dictionary<Guid, StringField>();

		public static void InitializeField(PackagingStationConfiguration config, PackagingStation station)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Guid key = Guid.Parse(((BuildableItem)station).GUID.ToString());
			if (!UnpackageFields.ContainsKey(key))
			{
				StringField value = new StringField((EntityConfiguration)(object)config, "false");
				UnpackageFields[key] = value;
			}
			else
			{
				((EntityConfiguration)config).Fields.Add((ConfigField)(object)UnpackageFields[key]);
			}
		}
	}
	[HarmonyPatch(typeof(PackagingStationConfiguration))]
	public class PackagingStationConfigurationPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void ConstructorPostfix(PackagingStationConfiguration __instance, PackagingStation station)
		{
			if (__instance != null && !((Object)(object)station == (Object)null))
			{
				PackagingStationConfigPatches.InitializeField(__instance, station);
			}
		}
	}
	[HarmonyPatch(typeof(PackagingStationConfigPanel))]
	public class PackagingStationConfigPanelPatch
	{
		internal static readonly Logger Logger = new Logger("PackagingStationConfigPatches");

		[HarmonyPostfix]
		[HarmonyPatch("BindInternal")]
		public static void BindInternalPostfix(PackagingStationConfigPanel __instance, List<EntityConfiguration> configs)
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_01ab: 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_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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: 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_025e: 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_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: 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_02de: Expected O, but got Unknown
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Expected O, but got Unknown
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.DestinationUI == (Object)null)
			{
				return;
			}
			try
			{
				PackagingStationConfiguration val = null;
				foreach (EntityConfiguration config in configs)
				{
					if (!Utils.Is<PackagingStationConfiguration>(config, out PackagingStationConfiguration result) || result == null)
					{
						continue;
					}
					val = result;
					break;
				}
				if ((Object)(object)((val != null) ? val.Station : null) == (Object)null)
				{
					return;
				}
				Guid stationGuid = Guid.Parse(((BuildableItem)val.Station).GUID.ToString());
				if (!PackagingStationConfigPatches.UnpackageFields.TryGetValue(stationGuid, out StringField _))
				{
					PackagingStationConfigPatches.InitializeField(val, val.Station);
				}
				Transform parent = ((Component)__instance.DestinationUI).transform.parent;
				GameObject val2 = new GameObject("UnpackageToggle");
				val2.transform.SetParent(parent, false);
				RectTransform val3 = val2.AddComponent<RectTransform>();
				RectTransform component = ((Component)__instance.DestinationUI).GetComponent<RectTransform>();
				TextMeshProUGUI fieldLabel = __instance.DestinationUI.FieldLabel;
				Transform val4 = ((component != null) ? ((Transform)component).Find("Selection") : null);
				Image val5 = ((val4 != null) ? ((Component)val4).GetComponent<Image>() : null);
				if ((Object)(object)component == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)fieldLabel == (Object)null)
				{
					Logger.Error("Failed to find necessary UI components for unpackage toggle");
					return;
				}
				val3.sizeDelta = new Vector2(400f, 50f);
				val2.transform.localPosition = ((Transform)component).localPosition + new Vector3(0f, -120f, 0f);
				GameObject val6 = new GameObject("Title");
				val6.transform.SetParent(val2.transform, false);
				RectTransform val7 = val6.AddComponent<RectTransform>();
				val7.anchorMin = new Vector2(0f, 0.5f);
				val7.anchorMax = new Vector2(0f, 0.5f);
				val7.pivot = new Vector2(0f, 0.5f);
				val7.anchoredPosition = new Vector2(0f, 0f);
				val7.sizeDelta = new Vector2(200f, 30f);
				TextMeshProUGUI val8 = val6.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val8).fontSize = ((TMP_Text)fieldLabel).fontSize;
				((TMP_Text)val8).alignment = ((TMP_Text)fieldLabel).alignment;
				((TMP_Text)val8).text = "Set Unpackage";
				((Graphic)val8).color = ((Graphic)fieldLabel).color;
				((TMP_Text)val8).font = ((TMP_Text)fieldLabel).font;
				GameObject val9 = new GameObject("Value");
				RectTransform val10 = val9.AddComponent<RectTransform>();
				val9.transform.SetParent(val2.transform, false);
				val10.anchorMin = new Vector2(1f, 0.5f);
				val10.anchorMax = new Vector2(1f, 0.5f);
				val10.pivot = new Vector2(1f, 0.5f);
				val10.anchoredPosition = Vector2.zero;
				val10.sizeDelta = new Vector2(80f, 30f);
				Image val11 = val9.AddComponent<Image>();
				val11.sprite = val5.sprite;
				val11.overrideSprite = val5.overrideSprite;
				val11.type = val5.type;
				((Graphic)val11).material = ((Graphic)val5).material;
				((Graphic)val11).color = ((Graphic)val5).color;
				((Graphic)val11).raycastTarget = ((Graphic)val5).raycastTarget;
				val11.preserveAspect = val5.preserveAspect;
				val11.pixelsPerUnitMultiplier = val5.pixelsPerUnitMultiplier;
				GameObject val12 = new GameObject("Text");
				val12.transform.SetParent(val9.transform, false);
				RectTransform val13 = val12.AddComponent<RectTransform>();
				val13.anchorMin = new Vector2(1f, 0.5f);
				val13.anchorMax = new Vector2(1f, 0.5f);
				val13.pivot = new Vector2(1f, 0.5f);
				val13.anchoredPosition = new Vector2(0f, 0f);
				val13.sizeDelta = new Vector2(80f, 30f);
				TextMeshProUGUI valueTmpro = val12.AddComponent<TextMeshProUGUI>();
				((TMP_Text)valueTmpro).fontSize = 24f;
				((TMP_Text)valueTmpro).alignment = (TextAlignmentOptions)514;
				((TMP_Text)valueTmpro).font = ((TMP_Text)fieldLabel).font;
				UnpackageSave.Instance.TryGetValue(stationGuid, out var value2);
				((TMP_Text)valueTmpro).text = (value2 ? "On" : "Off");
				((Graphic)valueTmpro).color = (value2 ? Color.green : Color.gray);
				Button val14 = val9.AddComponent<Button>();
				((UnityEventBase)val14.onClick).RemoveAllListeners();
				string s = "";
				EventHelper.AddListener((Action)delegate
				{
					//IL_0103: 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)
					s = s;
					Logger logger = Logger;
					object[] array = new object[1];
					Guid guid = stationGuid;
					array[0] = "Toggled unpackaging setting for station " + guid;
					logger.Msg(array);
					UnpackageSave instance = UnpackageSave.Instance;
					if (instance?.UnpackageStations != null)
					{
						if (!instance.UnpackageStations.TryAdd(stationGuid, value: true))
						{
							instance.UnpackageStations[stationGuid] = !instance.UnpackageStations[stationGuid];
						}
						bool flag = instance.UnpackageStations[stationGuid];
						Melon<EmployeeTweaks>.Instance.NetworkManager?.BroadcastStation(stationGuid.ToString(), flag);
						((TMP_Text)valueTmpro).text = (flag ? "On" : "Off");
						((Graphic)valueTmpro).color = (flag ? Color.green : Color.gray);
					}
				}, (UnityEvent)(object)val14.onClick);
				((Selectable)val14).image = val11;
				((Selectable)val14).targetGraphic = (Graphic)(object)val11;
				UIContentPanel component2 = ((Component)__instance).GetComponent<UIContentPanel>();
				if ((Object)(object)component2 != (Object)null)
				{
					UISelectable val15 = val9.GetComponent<UISelectable>();
					if ((Object)(object)val15 == (Object)null)
					{
						val15 = val9.AddComponent<UISelectable>();
					}
					((UIPanel)component2).AddSelectable(val15);
				}
				Transform val16 = ((Transform)component).Find("Description");
				if (!((Object)(object)val16 == (Object)null))
				{
					GameObject val17 = Object.Instantiate<GameObject>(((Component)val16).gameObject);
					RectTransform component3 = val17.GetComponent<RectTransform>();
					((Transform)component3).SetParent(val2.transform, false);
					((Transform)component3).localPosition = Vector3.zero;
					component3.anchoredPosition += new Vector2(0f, -50f);
					TextMeshProUGUI component4 = val17.GetComponent<TextMeshProUGUI>();
					((TMP_Text)component4).text = "^The assigned packager will use this station for unpackaging product only";
				}
			}
			catch (Exception arg)
			{
				Logger.Error($"BindInternalPostfix failed: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(PackagingStation))]
	internal static class PackagingStationPatches
	{
		[HarmonyPatch("PackSingleInstance")]
		[HarmonyPrefix]
		private static bool UnpackIfConfigured(PackagingStation __instance)
		{
			if (__instance != null)
			{
				_ = ((BuildableItem)__instance).GUID;
				if (0 == 0)
				{
					UnpackageSave.Instance.TryGetValue(((BuildableItem)__instance).GUID, out var value);
					if (!value)
					{
						return true;
					}
					__instance.Unpack();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PackagingStationBehaviour))]
	internal static class PackagingStationBehaviourPatches
	{
		[HarmonyPatch("IsStationReady")]
		[HarmonyPrefix]
		private static bool IsStationReady(PackagingStationBehaviour __instance, PackagingStation station, ref bool __result)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			if ((Object)(object)station == (Object)null)
			{
				__result = false;
				return false;
			}
			NPC npc = ((Behaviour)__instance).Npc;
			Utils.Is2<IUsable>(station, out IUsable result);
			if (result != null && result.IsInUse && (Object)(object)station.NPCUserObject != (Object)(object)((NetworkBehaviour)npc).NetworkObject)
			{
				__result = false;
				return false;
			}
			if (!npc.Movement.CanGetTo(station.StandPoint.position, 1f))
			{
				__result = false;
				return false;
			}
			UnpackageSave.Instance.TryGetValue(((BuildableItem)station).GUID, out var value);
			EMode val = (EMode)(value ? 1 : 0);
			if ((int)station.GetState(val) > 0)
			{
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}
	}
	public static class TransitEntityExtensions
	{
		public static List<ItemSlot> ReserveOutputSlotsForItem(this ITransitEntity entity, ItemInstance item, NetworkObject locker)
		{
			List<ItemSlot> list = new List<ItemSlot>();
			int num = ((BaseItemInstance)item).Quantity;
			for (int i = 0; i < entity.OutputSlots.Count; i++)
			{
				int capacityForItem = entity.OutputSlots[i].GetCapacityForItem(item, false);
				if (capacityForItem != 0)
				{
					int num2 = Mathf.Min(capacityForItem, num);
					num -= num2;
					entity.OutputSlots[i].ApplyLock(locker, "Employee is about to place an item here", false);
					list.Add(entity.OutputSlots[i]);
					if (num <= 0)
					{
						break;
					}
				}
			}
			return list;
		}

		public static void RemoveOutputSlotLocks(this ITransitEntity entity, NetworkObject locker)
		{
			for (int i = 0; i < entity.OutputSlots.Count; i++)
			{
				if (entity.OutputSlots[i].ActiveLock != null && (Object)(object)entity.OutputSlots[i].ActiveLock.LockOwner == (Object)(object)locker)
				{
					entity.OutputSlots[i].RemoveLock(false);
				}
			}
		}
	}
}
namespace EmployeeTweaks.Patches.QualityEmployeeWorkSpeed
{
	[HarmonyPatch]
	internal static class EffectPatches
	{
		private static Logger _logger = new Logger("QualityEmployeeWorkSpeed");

		[HarmonyPatch(typeof(ProductItemInstance), "ApplyEffectsToNPC")]
		[HarmonyPrefix]
		private static bool ApplyEffectsToEmployee(ProductItemInstance __instance, NPC npc)
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((__instance != null) ? ((ItemInstance)__instance).Definition : null) == (Object)null)
			{
				return true;
			}
			if ((Object)(object)npc == (Object)null)
			{
				return true;
			}
			if (!Utils.Is<Employee>(npc, out Employee result) || (Object)(object)result == (Object)null)
			{
				return true;
			}
			if (!Utils.Is<ProductDefinition>(((ItemInstance)__instance).Definition, out ProductDefinition result2) || (Object)(object)result2 == (Object)null)
			{
				return true;
			}
			List<Effect> list = new List<Effect>();
			list.AddRange(((PropertyItemDefinition)result2).Properties.AsEnumerable());
			list = list.OrderBy((Effect x) => x.Tier).ToList();
			StackEntry val = default(StackEntry);
			foreach (Effect item in list)
			{
				item.ApplyToEmployee(result);
				if (result.WorkSpeedController.TryGetEntry(item.Name, ref val))
				{
					float num = ApplyQuality(val.Value, GetQualityMult(((QualityItemInstance)__instance).Quality));
					_logger.Msg($"Applying quality transformation to {item.Name}: was {val.Value}, is {num}");
					val.Value = num;
					result.WorkSpeedController.Recalculate();
				}
			}
			return false;
		}

		private static float GetQualityMult(EQuality quality)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected I4, but got Unknown
			if (1 == 0)
			{
			}
			float result = (int)quality switch
			{
				0 => 0.4f, 
				1 => 0.7f, 
				2 => 1f, 
				3 => 1.2f, 
				4 => 1.5f, 
				_ => 1f, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		private static float ApplyQuality(float baseValue, float m)
		{
			float num = 1f + (m - 1f) * 1.2f;
			float num2 = baseValue * 0.9f;
			float num3 = baseValue * 1.2f;
			return Mathf.Lerp(num2, num3, Mathf.InverseLerp(0.4f, 1.5f, num));
		}
	}
}
namespace EmployeeTweaks.Patches.MoreEmployeeConfigItems
{
	[HarmonyPatch]
	internal static class BotanistMorePots
	{
		[HarmonyPatch(typeof(Botanist), "AssignProperty")]
		[HarmonyPrefix]
		private static void Awake(Botanist __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.MaxAssignedPots = Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.Value;
			}
		}

		[HarmonyPatch(typeof(BotanistConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollRect(BotanistConfigPanel __instance)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = __instance?.PotsUI;
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = val.Entries.AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform component = val2.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				Transform val3 = val2.transform.parent.Find("Hint");
				if (!((Object)(object)val3 == (Object)null) && Melon<EmployeeTweaks>.Instance.SettingsRegistry.BotanistMaxPots.Value > 9)
				{
					val3.localPosition += new Vector3(10f, 0f);
				}
			}
		}
	}
	[HarmonyPatch]
	internal class ChemistMoreStations
	{
		[HarmonyPatch(typeof(Chemist), "AssignProperty")]
		[HarmonyPostfix]
		private static void AddStations(Chemist __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.configuration.Stations.MaxItems = Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.Value;
			}
		}

		[HarmonyPatch(typeof(ChemistConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollStationRect(ChemistConfigPanel __instance)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = __instance?.StationsUI;
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = val.Entries.AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform component = val2.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				Transform val3 = val2.transform.parent.Find("Hint");
				if (!((Object)(object)val3 == (Object)null) && Melon<EmployeeTweaks>.Instance.SettingsRegistry.ChemistMaxStations.Value > 9)
				{
					val3.localPosition += new Vector3(10f, 0f);
				}
			}
		}
	}
	[HarmonyPatch]
	internal class CleanerMoreBins
	{
		[HarmonyPatch(typeof(Cleaner), "AssignProperty")]
		[HarmonyPostfix]
		private static void AddBins(Cleaner __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.configuration.Bins.MaxItems = Melon<EmployeeTweaks>.Instance.SettingsRegistry.CleanerMaxBins.Value;
			}
		}

		[HarmonyPatch(typeof(CleanerConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollStationRect(CleanerConfigPanel __instance)
		{
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.CleanerMaxBins.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.CleanerMaxBins.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = __instance?.BinsUI;
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = val.Entries.AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if (!((Object)(object)val2 == (Object)null))
			{
				RectTransform component = val2.GetComponent<RectTransform>();
				if (!((Object)(object)component == (Object)null))
				{
					ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				}
			}
		}
	}
	public static class ClipboardUIHelper
	{
		internal static readonly Logger Logger = new Logger("MoreEmployeeConfigItems");

		public static ScrollRect MoveToScrollableList(RectTransform source, Transform parent)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				Logger.Error("Source is null");
				return null;
			}
			VerticalLayoutGroup component = ((Component)source).GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.Error("Source does not have VerticalLayoutGroup");
				return null;
			}
			ScrollRect val2 = default(ScrollRect);
			RectTransform val = UIFactory.ScrollableVerticalList(((Object)source).name + "_Scroll", parent, ref val2);
			VerticalLayoutGroup component2 = ((Component)val).GetComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component2).spacing = ((HorizontalOrVerticalLayoutGroup)component).spacing;
			((LayoutGroup)component2).padding = new RectOffset(((LayoutGroup)component).padding.left, ((LayoutGroup)component).padding.right, 8, ((LayoutGroup)component).padding.bottom);
			((LayoutGroup)component2).childAlignment = ((LayoutGroup)component).childAlignment;
			((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = ((HorizontalOrVerticalLayoutGroup)component).childControlHeight;
			((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight;
			((HorizontalOrVerticalLayoutGroup)component2).childScaleWidth = ((HorizontalOrVerticalLayoutGroup)component).childScaleWidth;
			((HorizontalOrVerticalLayoutGroup)component2).childScaleHeight = ((HorizontalOrVerticalLayoutGroup)component).childScaleHeight;
			while (((Transform)source).childCount > 0)
			{
				Transform child = ((Transform)source).GetChild(0);
				child.SetParent((Transform)(object)val, false);
				if (Utils.Is<RectTransform>(child, out RectTransform result) && !((Object)(object)result == (Object)null))
				{
					result.anchorMin = new Vector2(result.anchorMin.x, 1f);
					result.anchorMax = new Vector2(result.anchorMax.x, 1f);
					result.pivot = new Vector2(result.pivot.x, 1f);
				}
			}
			RectTransform component3 = ((Component)val2).gameObject.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 1f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.pivot = new Vector2(0.5f, 1f);
			component3.anchoredPosition = source.anchoredPosition + new Vector2(0f, 150f);
			component3.sizeDelta = new Vector2(0f, source.sizeDelta.y);
			val.sizeDelta = new Vector2(0f, val.sizeDelta.y);
			LayoutElement orAddComponent = ((Component)val).gameObject.GetOrAddComponent<LayoutElement>();
			orAddComponent.flexibleWidth = 1f;
			ContentSizeFitter orAddComponent2 = ((Component)val).gameObject.GetOrAddComponent<ContentSizeFitter>();
			orAddComponent2.horizontalFit = (FitMode)0;
			AddVerticalScrollbar(val2, 8f, 8f, (ScrollbarVisibility)1);
			Object.Destroy((Object)(object)((Component)source).gameObject);
			LayoutRebuilder.ForceRebuildLayoutImmediate(val);
			return val2;
		}

		public static Scrollbar AddVerticalScrollbar(ScrollRect scrollRect, float width = 12f, float spacing = -2f, ScrollbarVisibility visibility = (ScrollbarVisibility)1)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: 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)
			if ((Object)(object)scrollRect == (Object)null)
			{
				Logger.Error("AddVerticalScrollbar: scrollRect is null");
				return null;
			}
			RectTransform component = ((Component)scrollRect).GetComponent<RectTransform>();
			if ((Object)(object)scrollRect.verticalScrollbar != (Object)null)
			{
				GameObject gameObject = ((Component)scrollRect.verticalScrollbar).gameObject;
				scrollRect.verticalScrollbar = null;
				Object.Destroy((Object)(object)gameObject);
			}
			GameObject val = new GameObject("Scrollbar");
			val.GetOrAddComponent<RectTransform>();
			val.transform.SetParent((Transform)(object)component, false);
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(1f, 0f);
			component2.anchorMax = new Vector2(1f, 1f);
			component2.pivot = new Vector2(1f, 1f);
			component2.sizeDelta = new Vector2(width, 0f);
			component2.anchoredPosition = Vector2.zero;
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = new Color(63f / 85f, 63f / 85f, 0.7490196f, 0.25f);
			((Graphic)val2).raycastTarget = true;
			GameObject val3 = new GameObject("Handle");
			val3.GetOrAddComponent<RectTransform>();
			val3.transform.SetParent(val.transform, false);
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 0f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.pivot = new Vector2(0.5f, 0.5f);
			component3.sizeDelta = Vector2.zero;
			Image val4 = val3.AddComponent<Image>();
			((Graphic)val4).color = new Color(0.6745098f, 0.6745098f, 0.6784314f, 0.65f);
			((Graphic)val4).raycastTarget = true;
			Scrollbar val5 = val.AddComponent<Scrollbar>();
			val5.direction = (Direction)2;
			val5.handleRect = component3;
			((Selectable)val5).targetGraphic = (Graphic)(object)val4;
			scrollRect.vertical = true;
			scrollRect.horizontal = false;
			scrollRect.verticalScrollbar = val5;
			scrollRect.verticalScrollbarVisibility = visibility;
			scrollRect.verticalScrollbarSpacing = spacing;
			RectTransform content = scrollRect.content;
			if ((Object)(object)content != (Object)null)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(content);
			}
			Canvas.ForceUpdateCanvases();
			return val5;
		}
	}
	[HarmonyPatch]
	internal static class HandlerPatches
	{
		[HarmonyPatch(typeof(Packager), "AssignProperty")]
		[HarmonyPostfix]
		private static void AddRoutes(Packager __instance)
		{
			if (Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				__instance.configuration.Routes.MaxRoutes = Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxRoutes.Value;
				__instance.MaxAssignedStations = Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.Value;
				__instance.configuration.Stations.MaxItems = Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.Value;
			}
		}

		[HarmonyPatch(typeof(PackagerConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollStationRect(PackagerConfigPanel __instance)
		{
			//IL_00f3: 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)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxStations.DefaultValue)
			{
				return;
			}
			ObjectListFieldUI val = __instance?.StationsUI;
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				RectTransform? obj2 = val.Entries.AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Transform)obj2).parent).gameObject : null);
			}
			GameObject val2 = (GameObject)obj;
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform component = val2.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ScrollRect val3 = ClipboardUIHelper.MoveToScrollableList(component, val2.transform.parent);
				RectTransform component2 = ((Component)val3).gameObject.GetComponent<RectTransform>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.sizeDelta = new Vector2(0f, 165f);
					component2.offsetMin = new Vector2(0f, -165f);
					Canvas.ForceUpdateCanvases();
					LayoutRebuilder.ForceRebuildLayoutImmediate(val3.content);
				}
			}
		}

		[HarmonyPatch(typeof(PackagerConfigPanel), "BindInternal")]
		[HarmonyPostfix]
		private static void AddScrollRouteRect(PackagerConfigPanel __instance)
		{
			//IL_00f2: 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)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value || Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxRoutes.Value <= Melon<EmployeeTweaks>.Instance.SettingsRegistry.HandlerMaxRoutes.DefaultValue)
			{
				return;
			}
			RouteListFieldUI routesUI = __instance.RoutesUI;
			object obj;
			if (routesUI == null)
			{
				obj = null;
			}
			else
			{
				RouteEntryUI? obj2 = routesUI.RouteEntries.AsEnumerable().FirstOrDefault();
				obj = ((obj2 != null) ? ((Component)((Component)obj2).transform.parent).gameObject : null);
			}
			GameObject val = (GameObject)obj;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			RectTransform component = val.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				ScrollRect val2 = ClipboardUIHelper.MoveToScrollableList(component, val.transform.parent);
				RectTransform component2 = ((Component)val2).gameObject.GetComponent<RectTransform>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.anchoredPosition = new Vector2(0f, -55f);
					component2.sizeDelta = new Vector2(0f, 165f);
					Canvas.ForceUpdateCanvases();
					LayoutRebuilder.ForceRebuildLayoutImmediate(val2.content);
				}
			}
		}
	}
	[HarmonyPatch]
	public class SharedClipboardPatches
	{
		internal static readonly Logger Logger = new Logger("SharedClipboardPatches");

		[HarmonyPatch(typeof(ObjectListFieldUI), "Bind")]
		[HarmonyPrefix]
		private static void AddMissing(ObjectListFieldUI __instance, List<ObjectListField> field)
		{
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				return;
			}
			int num = field.AsEnumerable().Max((ObjectListField olf) => olf.MaxItems);
			int num2 = __instance.Entries.Length;
			if (num <= num2)
			{
				Logger.D($"Not adding, current: {num2}, maxFieldsNeeded: {num}");
				return;
			}
			int num3 = num - num2;
			RectTransform val = __instance.Entries.AsEnumerable().FirstOrDefault();
			if ((Object)(object)val == (Object)null || num3 <= 0)
			{
				Logger.D($"Not adding, template: {val} or todo {num3}");
				return;
			}
			List<RectTransform> list = new List<RectTransform>();
			RectTransform[] entries = __instance.Entries;
			foreach (RectTransform item in entries)
			{
				list.Add(item);
			}
			for (int num5 = 0; num5 < num3; num5++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject);
				val2.transform.SetParent(((Component)val).transform.parent, false);
				val2.transform.SetAsLastSibling();
				list.Add(val2.GetComponent<RectTransform>());
			}
			__instance.Entries = list.ToArray();
			Logger.D($"Ensured {__instance.Entries.Length} instances");
		}

		[HarmonyPatch(typeof(RouteListFieldUI), "Bind")]
		[HarmonyPrefix]
		private static void AddMissing(RouteListFieldUI __instance)
		{
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableAssigns.Value)
			{
				return;
			}
			int item = SettingsConstants.HandlerBoundsMaxRoutes.Item2;
			int num = __instance.RouteEntries.Length;
			if (item <= num)
			{
				Logger.D($"Not adding, current: {num}, maxFieldsNeeded: {item}");
				return;
			}
			int num2 = item - num;
			RouteEntryUI? obj = __instance.RouteEntries.AsEnumerable().FirstOrDefault();
			GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)val == (Object)null || num2 <= 0)
			{
				Logger.D($"Not adding, template: {val} or todo {num2}");
				return;
			}
			List<RouteEntryUI> list = new List<RouteEntryUI>();
			RouteEntryUI[] routeEntries = __instance.RouteEntries;
			foreach (RouteEntryUI item2 in routeEntries)
			{
				list.Add(item2);
			}
			for (int j = 0; j < num2; j++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(val.gameObject);
				val2.transform.SetParent(val.transform.parent, false);
				val2.transform.SetSiblingIndex(val.transform.parent.childCount - 2);
				val2.SetActive(false);
				RouteEntryUI component = val2.GetComponent<RouteEntryUI>();
				if (!((Object)(object)component == (Object)null))
				{
					list.Add(component);
				}
			}
			__instance.RouteEntries = list.ToArray();
		}
	}
}
namespace EmployeeTweaks.Patches.FilterItemApply
{
	[HarmonyPatch(typeof(FilterConfigPanel))]
	internal class FilterConfigPanelPatches
	{
		private static Logger _logger = new Logger("FilterItemApply");

		internal const string Filter1 = "Apply Item As Filter";

		internal const string Filter2 = "Apply All As Filters";

		internal static bool AllSlots;

		internal static bool DenyListMode;

		internal static TextMeshProUGUI ApplyItemAsFilterButtonText;

		private static Button _applyItemAsFilterButton;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AddButton(FilterConfigPanel __instance)
		{
			Button applyToSiblingsButton = __instance.ApplyToSiblingsButton;
			if ((Object)(object)applyToSiblingsButton == (Object)null)
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)applyToSiblingsButton).gameObject, ((Component)applyToSiblingsButton).transform.parent);
			_applyItemAsFilterButton = val.GetComponent<Button>();
			ApplyItemAsFilterButtonText = ((Component)_applyItemAsFilterButton).GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)ApplyItemAsFilterButtonText).text = "Apply Item As Filter";
			((UnityEventBase)_applyItemAsFilterButton.onClick).RemoveAllListeners();
			string s = "";
			EventHelper.AddListener((Action)delegate
			{
				s = s;
				if (AllSlots)
				{
					ApplyItemsAsFilters(__instance.OpenSlot);
				}
				else
				{
					ApplyItemAsFilter(__instance.OpenSlot);
				}
			}, (UnityEvent)(object)_applyItemAsFilterButton.onClick);
		}

		private static void ApplyItemAsFilter(ItemSlot itemSlot)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if (!AllSlots)
			{
				_logger.Msg("Applying item as filter");
			}
			ItemInstance itemInstance = itemSlot.ItemInstance;
			if (((itemInstance != null) ? ((BaseItemInstance)itemInstance).ID : null) == null)
			{
				_logger.Warning("No item in slot to apply as filter.");
				return;
			}
			SlotFilter playerFilter = itemSlot.PlayerFilter;
			if (playerFilter?.ItemIDs == null)
			{
				_logger.Warning("Player filter is null or does not have an ItemIDs list.");
				return;
			}
			playerFilter.ItemIDs.Clear();
			playerFilter.ItemIDs.Add(((BaseItemInstance)itemInstance).ID);
			playerFilter.Type = (EType)((!DenyListMode) ? 1 : 2);
			itemSlot.SetPlayerFilter(playerFilter, false);
		}

		private static void ApplyItemsAsFilters(ItemSlot itemSlot)
		{
			_logger.Msg("Applying all items in sibling slots as filters.");
			foreach (ItemSlot slot in itemSlot.SiblingSet.Slots)
			{
				ApplyItemAsFilter(slot);
			}
		}
	}
}
namespace EmployeeTweaks.Patches.EmployeeArea
{
	internal class DebugAreaDrawer
	{
		private Logger Logger = new Logger("DebugAreaDrawer");

		private List<GameObject> _areas = new List<GameObject>();

		internal void Draw()
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject area in _areas)
			{
				if ((Object)(object)area != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)area);
				}
			}
			_areas.Clear();
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableCapacityAndDebug.Value || !Melon<EmployeeTweaks>.Instance.SettingsRegistry.DrawDebugArea.Value)
			{
				return;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, 0.1f, 0f);
			foreach (var value in PropertyPatch._propertyIdlePointRects.Values)
			{
				Logger.Msg($"Drawing Employee Area at {value.Item1 + val}, {value.Item2 + val}");
				GameObject item = DrawDebugArea(value.Item1 + val, value.Item2 + val, new Color(1f, 0f, 0f, 0.2f));
				_areas.Add(item);
			}
		}

		private static GameObject DrawDebugArea(Vector3 a, Vector3 b, Color color)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: 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_002a: 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_0030: 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_003c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0107: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)5);
			((Object)val).name = "DebugArea";
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			Vector3 val2 = Vector3.Min(a, b);
			Vector3 val3 = Vector3.Max(a, b);
			Vector3 val4 = (val2 + val3) * 0.5f;
			Vector3 val5 = val3 - val2;
			val.transform.position = val4 + Vector3.up * 0.01f;
			val.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
			val.transform.localScale = new Vector3(val5.x, val5.z, 1f);
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			Shader val6 = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)val6 == (Object)null)
			{
				return val;
			}
			Material val7 = new Material(val6);
			if (val7.HasProperty("_Surface"))
			{
				val7.SetFloat("_Surface", 1f);
			}
			if (color.a <= 0f)
			{
				color.a = 0.2f;
			}
			if (val7.HasProperty("_BaseColor"))
			{
				val7.SetColor("_BaseColor", color);
			}
			if (val7.HasProperty("_EmissionColor"))
			{
				val7.EnableKeyword("_EMISSION");
				val7.SetColor("_EmissionColor", new Color(color.r, color.g, color.b) * 1.5f);
			}
			val7.SetInt("_ZWrite", 0);
			val7.renderQueue = 3000;
			((Renderer)component).material = val7;
			return val;
		}

		internal static void WireDebugAreaDrawer(DebugAreaDrawer debugAreaDrawer)
		{
			Player.LocalPlayerSpawned += delegate
			{
				debugAreaDrawer.Draw();
			};
			((MelonEventBase<LemonAction<bool, bool>>)(object)Melon<EmployeeTweaks>.Instance.SettingsRegistry.DrawDebugArea.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate
			{
				debugAreaDrawer.Draw();
			}, 0, false);
		}
	}
	[HarmonyPatch]
	internal class PropertyPatch
	{
		private static Logger Logger = new Logger("PropertyPatch");

		internal static Dictionary<Property, (Vector3, Vector3)> _propertyIdlePointRects = new Dictionary<Property, (Vector3, Vector3)>();

		[HarmonyPatch(typeof(Property), "NetworkInitialize___Early")]
		[HarmonyPriority(-100)]
		[HarmonyPrefix]
		private static void StorePointRectAndAddCapacity(Property __instance)
		{
			//IL_005c: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableCapacityAndDebug.Value)
			{
				return;
			}
			Transform[] employeeIdlePoints = __instance.EmployeeIdlePoints;
			if (employeeIdlePoints != null && employeeIdlePoints.Length > 0)
			{
				var (val, val2) = MinMaxPoints(employeeIdlePoints.AsEnumerable().ToList());
				if (val == val2)
				{
					val2 = val + new Vector3(0.5f, 0f, 0.5f);
				}
				_propertyIdlePointRects[__instance] = (val, val2);
			}
			if (__instance.EmployeeCapacity <= 0)
			{
				return;
			}
			NetworkedMelonEntry<int> entry = Melon<EmployeeTweaks>.Instance.SettingsRegistry.EmployeeCapacityCategory.GetOrCreateNetworkedEntry("EmployeeTweaks_" + __instance.propertyCode + "_EmpCap", __instance.EmployeeCapacity, Melon<EmployeeTweaks>.Instance.SettingsRegistry._boxedClient, Melon<EmployeeTweaks>.Instance.SettingsRegistry._boxedOptions, announce: true, __instance.propertyName + " Employee Capacity", "Max amount of employees you can hire for this property", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange<int>(1, Mathf.CeilToInt((float)__instance.EmployeeCapacity * 1.5f) + 1));
			Melon<EmployeeTweaks>.Instance.SettingsRegistry.EmployeeCapacities.Add(entry);
			((MelonEventBase<LemonAction<int, int>>)(object)entry.OnEntryValueChanged).Subscribe((LemonAction<int, int>)delegate(int oldVal, int newVal)
			{
				if (oldVal != newVal)
				{
					AddCapacity(__instance, newVal);
				}
			}, 0, false);
			AddCapacity(__instance, entry.Value);
			void AddCapacity(Property prop, int target)
			{
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				//IL_027c: Unknown result type (might be due to invalid IL or missing references)
				//IL_028f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0296: Expected O, but got Unknown
				//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
				int num = prop.Employees?.AsEnumerable().Count() ?? 0;
				(Vector3, Vector3) value;
				if (target < num)
				{
					Logger.Warning($"Cannot set capacity of {prop.propertyName} to {target} because it currently has {num} employees");
					entry.Value = prop.EmployeeCapacity;
				}
				else if (!_propertyIdlePointRects.TryGetValue(prop, out value))
				{
					Logger.Warning("Could not find idle point rect for " + prop.propertyName + ", cannot add capacity");
					entry.Value = prop.EmployeeCapacity;
				}
				else
				{
					Transform[] employeeIdlePoints2 = prop.EmployeeIdlePoints;
					int num2 = ((employeeIdlePoints2 != null) ? employeeIdlePoints2.Length : 0);
					int num3 = target - num2;
					if (num3 <= 0)
					{
						if (num2 <= 0)
						{
							entry.Value = prop.EmployeeCapacity;
						}
						else
						{
							List<Transform> l