

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using EmployeeTweaks;
using EmployeeTweaks.Helpers;
using EmployeeTweaks.Patches.EmployeeArea;
using EmployeeTweaks.Patches.FilterItemApply;
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.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 Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Internal.Abstraction;
using S1API.Saveables;
using S1API.UI;
using Semver;
using UnityEngine;
using UnityEngine.Events;
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.3", "k073l", null)]
[assembly: MelonColor(1, 217, 131, 36)]
[assembly: MelonGame("TVGS", "Schedule I")]
[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.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+38262f090018ba0a7dce31ddadee40e3b352a080")]
[assembly: AssemblyProduct("EmployeeTweaks-IL2CPP")]
[assembly: AssemblyTitle("EmployeeTweaks-IL2CPP")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.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]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace 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.3";
}
public class EmployeeTweaks : MelonMod
{
private static Instance Logger;
private DebugAreaDrawer debugAreaDrawer;
private bool _lastShift;
private bool _lastCtrl;
internal SettingsRegistry SettingsRegistry;
public override void OnInitializeMelon()
{
Logger = ((MelonBase)this).LoggerInstance;
SettingsRegistry = new SettingsRegistry();
Logger.Msg("EmployeeTweaks initialized");
DependenciesChecker.PrintMissing();
MoveItemBehaviourPatches.ManualPatchDestinationValid(((MelonBase)this).HarmonyInstance);
debugAreaDrawer = new DebugAreaDrawer();
DebugAreaDrawer.WireDebugAreaDrawer(debugAreaDrawer);
}
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");
}
}
}
}
internal class SettingsRegistry
{
internal MelonPreferences_Category EmployeeCapacityCategory;
internal MelonPreferences_Entry<bool> EnableCapacityAndDebug;
internal MelonPreferences_Entry<bool> DrawDebugArea;
internal HashSet<MelonPreferences_Entry<int>> EmployeeCapacities = new HashSet<MelonPreferences_Entry<int>>();
internal MelonPreferences_Category EmployeeAssignsCategory;
internal MelonPreferences_Entry<bool> EnableAssigns;
internal MelonPreferences_Entry<int> BotanistMaxPots;
internal MelonPreferences_Entry<int> HandlerMaxStations;
internal MelonPreferences_Entry<int> HandlerMaxRoutes;
internal MelonPreferences_Entry<int> ChemistMaxStations;
internal MelonPreferences_Entry<int> CleanerMaxBins;
public SettingsRegistry()
{
InitializeCapacityCategory();
InitializeAssignsCategory();
}
private void InitializeCapacityCategory()
{
EmployeeCapacityCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeCapacity", "Employee Capacities");
EnableCapacityAndDebug = EmployeeCapacityCategory.CreateEntry<bool>("EmployeeTweaksEnableCapacityAndDebug", true, "Enable Category", "Enables employee capacity tweaks and drawing employee idle points area", false, false, (ValueValidator)null, (string)null);
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.CreateEntry<bool>("EmployeeTweaksEnableAssigns", true, "Enable Category", "Enables employee assigns capacity modifications", false, false, (ValueValidator)null, (string)null);
BotanistMaxPots = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksBotanistMaxPots", 8, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.BotanistBoundsMaxPots.Item1, SettingsConstants.BotanistBoundsMaxPots.Item2), (string)null);
HandlerMaxStations = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksHandlerMaxStations", 3, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxStations.Item1, SettingsConstants.HandlerBoundsMaxStations.Item2), (string)null);
HandlerMaxRoutes = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksHandlerMaxRoutes", 5, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxRoutes.Item1, SettingsConstants.HandlerBoundsMaxRoutes.Item2), (string)null);
ChemistMaxStations = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksChemistMaxStations", 4, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.ChemistBoundsMaxStations.Item1, SettingsConstants.ChemistBoundsMaxStations.Item2), (string)null);
CleanerMaxBins = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksCleanerMaxBins", 6, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.CleanerBoundsMaxBins.Item1, SettingsConstants.CleanerBoundsMaxBins.Item2), (string)null);
}
}
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;
}
public bool TryGetValue(Guid guid, out bool value)
{
Guid key = Guid.Parse(((object)(Guid)(ref guid)).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
{
[CompilerGenerated]
private sealed class <>c__DisplayClass7_0
{
public MoveItemBehaviour __instance;
}
[CompilerGenerated]
private sealed class <>c__DisplayClass9_0
{
public MoveItemBehaviour __instance;
public bool destIsStation;
public ITransitEntity dest;
}
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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: 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)
{
MelonLogger.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)
{
MelonLogger.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) ? 1 : 0));
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)
<>c__DisplayClass7_0 CS$<>8__locals0 = new <>c__DisplayClass7_0();
CS$<>8__locals0.__instance = __instance;
TransitRoute assignedRoute = CS$<>8__locals0.__instance.assignedRoute;
if (((assignedRoute != null) ? assignedRoute.Source : null) == null)
{
return true;
}
ITransitEntity destination = CS$<>8__locals0.__instance.assignedRoute.Destination;
PackagingStation result;
bool flag = Utils.Is2<PackagingStation>((object)destination, out result) && (Object)(object)result != (Object)null;
ITransitEntity source = CS$<>8__locals0.__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)CS$<>8__locals0.__instance).beh.DEBUG_MODE)
{
Console.Log(Object.op_Implicit("MoveItemBehaviour.GrabItem"), (Object)null);
}
CS$<>8__locals0.__instance.currentState = (EState)2;
CS$<>8__locals0.__instance.grabRoutine = null;
object value2 = MelonCoroutines.Start(Routine());
customGrabRunning[CS$<>8__locals0.__instance] = value2;
return false;
[IteratorStateMachine(typeof(<>c__DisplayClass7_0.<<GrabItem>g__Routine|0>d))]
IEnumerator Routine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <>c__DisplayClass7_0.<<GrabItem>g__Routine|0>d(0)
{
<>4__this = CS$<>8__locals0
};
}
}
[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)
{
Console.LogWarning(Object.op_Implicit("Amount to grab is 0!"), (Object)null);
return false;
}
ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0));
if (((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null) == null)
{
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)
<>c__DisplayClass9_0 CS$<>8__locals0 = new <>c__DisplayClass9_0();
CS$<>8__locals0.__instance = __instance;
TransitRoute assignedRoute = CS$<>8__locals0.__instance.assignedRoute;
if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
{
return true;
}
CS$<>8__locals0.dest = CS$<>8__locals0.__instance.assignedRoute.Destination;
CS$<>8__locals0.destIsStation = Utils.Is2<PackagingStation>((object)CS$<>8__locals0.dest, out PackagingStation result) && (Object)(object)result != (Object)null;
ITransitEntity source = CS$<>8__locals0.__instance.assignedRoute.Source;
PackagingStation result2;
bool flag = Utils.Is2<PackagingStation>((object)source, out result2) && (Object)(object)result2 != (Object)null;
if (!CS$<>8__locals0.destIsStation && !flag)
{
return true;
}
PackagingStation val = (CS$<>8__locals0.destIsStation ? result : result2);
UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
if (!value)
{
return true;
}
if (((Behaviour)CS$<>8__locals0.__instance).beh.DEBUG_MODE)
{
Console.Log(Object.op_Implicit("MoveItemBehaviour.PlaceItem"), (Object)null);
}
CS$<>8__locals0.__instance.currentState = (EState)4;
CS$<>8__locals0.__instance.placingRoutine = null;
object value2 = MelonCoroutines.Start(Routine());
customPlaceRunning[CS$<>8__locals0.__instance] = value2;
return false;
[IteratorStateMachine(typeof(<>c__DisplayClass9_0.<<PlaceItem>g__Routine|0>d))]
IEnumerator Routine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <>c__DisplayClass9_0.<<PlaceItem>g__Routine|0>d(0)
{
<>4__this = CS$<>8__locals0
};
}
}
[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 var value))
{
MelonCoroutines.Stop(value);
customPlaceRunning.Remove(__instance);
return false;
}
return true;
}
return true;
}
if (customGrabRunning.TryGetValue(__instance, out var value2))
{
MelonCoroutines.Stop(value2);
customGrabRunning.Remove(__instance);
return false;
}
return true;
}
[HarmonyPatch("OnActiveTick")]
[HarmonyPrefix]
private static bool OnActiveTick(MoveItemBehaviour __instance)
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Invalid comparison between Unknown and I4
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
if (!InstanceFinder.IsServer)
{
return false;
}
if (!__instance.assignedRoute.AreEntitiesNonNull())
{
Console.LogWarning(Object.op_Implicit("Transit route entities are null!"), (Object)null);
((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
return false;
}
if (((Behaviour)__instance).beh.DEBUG_MODE)
{
EState currentState = __instance.currentState;
Console.Log(Object.op_Implicit("State: " + ((object)(EState)(ref currentState)).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) : 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))
{
Console.LogWarning(Object.op_Implicit("Invalid transit route for move item behaviour by checking transit route!. Reason: " + text), (Object)null);
((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))
{
Console.LogWarning(Object.op_Implicit("Invalid transit route for move item behaviour by checking destination! Reason: " + text2), (Object)null);
((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
return false;
}
}
__instance.currentState = (EState)0;
return false;
}
}
[HarmonyPatch(typeof(Packager))]
internal static class 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)
{
Console.Log(Object.op_Implicit("[Unpacked] Rejected item " + ((BaseItemInstance)x.ItemInstance).ID + ": " + text), (Object)null);
}
return flag;
});
if (val == null)
{
return true;
}
Console.Log(Object.op_Implicit("[Unpacked] Starting moving items from " + ((Object)((Component)station).gameObject).name), (Object)null);
((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))
{
Console.LogError(Object.op_Implicit("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)
{
Console.Log(Object.op_Implicit($"MoveItemBehaviour initialized with route: {route.Source.Name} -> {route.Destination.Name} for item: {((BaseItemInstance)_itemToRetrieveTemplate).ID}"), (Object)null);
}
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;
}
}
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 gUID = ((BuildableItem)station).GUID;
Guid key = Guid.Parse(((object)(Guid)(ref 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
{
[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_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
//IL_0165: 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_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Expected O, but got Unknown
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_0315: 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)
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 gUID = ((BuildableItem)val.Station).GUID;
Guid stationGuid = Guid.Parse(((object)(Guid)(ref gUID)).ToString());
if (!PackagingStationConfigPatches.UnpackageFields.TryGetValue(stationGuid, out var _))
{
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>();
val3.sizeDelta = new Vector2(400f, 50f);
GameObject val4 = new GameObject("Title");
val4.transform.SetParent(val2.transform, false);
RectTransform val5 = val4.AddComponent<RectTransform>();
val5.anchorMin = new Vector2(0f, 0.5f);
val5.anchorMax = new Vector2(0f, 0.5f);
val5.pivot = new Vector2(0f, 0.5f);
val5.anchoredPosition = new Vector2(0f, 0f);
val5.sizeDelta = new Vector2(150f, 30f);
TextMeshProUGUI val6 = val4.AddComponent<TextMeshProUGUI>();
((TMP_Text)val6).fontSize = 24f;
((TMP_Text)val6).alignment = (TextAlignmentOptions)513;
((TMP_Text)val6).text = "Set Unpackage";
((Graphic)val6).color = Color.black;
GameObject val7 = new GameObject("Value");
val7.transform.SetParent(val2.transform, false);
RectTransform val8 = val7.AddComponent<RectTransform>();
val8.anchorMin = new Vector2(1f, 0.5f);
val8.anchorMax = new Vector2(1f, 0.5f);
val8.pivot = new Vector2(1f, 0.5f);
val8.anchoredPosition = new Vector2(0f, 0f);
val8.sizeDelta = new Vector2(80f, 30f);
TextMeshProUGUI valueTmpro = val7.AddComponent<TextMeshProUGUI>();
((TMP_Text)valueTmpro).fontSize = 24f;
((TMP_Text)valueTmpro).alignment = (TextAlignmentOptions)516;
UnpackageSave.Instance.TryGetValue(stationGuid, out var value2);
((TMP_Text)valueTmpro).text = (value2 ? "On" : "Off");
((Graphic)valueTmpro).color = (value2 ? Color.green : Color.gray);
Button val9 = val7.AddComponent<Button>();
((UnityEventBase)val9.onClick).RemoveAllListeners();
string s = "";
EventHelper.AddListener((Action)delegate
{
//IL_00b2: 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)
s = s;
MelonLogger.Msg("Button clicked");
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];
((TMP_Text)valueTmpro).text = (flag ? "On" : "Off");
((Graphic)valueTmpro).color = (flag ? Color.green : Color.gray);
}
}, (UnityEvent)(object)val9.onClick);
UIContentPanel component2 = ((Component)__instance).GetComponent<UIContentPanel>();
if ((Object)(object)component2 != (Object)null)
{
UISelectable val10 = val7.GetComponent<UISelectable>();
if ((Object)(object)val10 == (Object)null)
{
val10 = val7.AddComponent<UISelectable>();
}
((UIPanel)component2).AddSelectable(val10);
}
}
catch (Exception value3)
{
MelonLogger.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 Instance _logger = new Instance("EmployeeTweaks.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), "Awake")]
[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), "OnSpawnServer")]
[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), "OnSpawnServer")]
[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
{
private static readonly Instance Logger = new Instance("EmployeeTweaks.MoreEmployeeConfigItems");
public static ScrollRect MoveToScrollableList(RectTransform source, Transform parent)
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
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 val = default(ScrollRect);
RectTransform val2 = UIFactory.ScrollableVerticalList(((Object)source).name + "_Scroll", parent, ref val);
VerticalLayoutGroup component2 = ((Component)val2).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)val2, 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)val).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);
val2.sizeDelta = new Vector2(0f, val2.sizeDelta.y);
LayoutElement orAddComponent = ((Component)val2).gameObject.GetOrAddComponent<LayoutElement>();
orAddComponent.flexibleWidth = 1f;
ContentSizeFitter orAddComponent2 = ((Component)val2).gameObject.GetOrAddComponent<ContentSizeFitter>();
orAddComponent2.horizontalFit = (FitMode)0;
AddVerticalScrollbar(val, 8f, 8f, (ScrollbarVisibility)1);
Object.Destroy((Object)(object)((Component)source).gameObject);
LayoutRebuilder.ForceRebuildLayoutImmediate(val2);
return val;
}
public static Scrollbar AddVerticalScrollbar(ScrollRect scrollRect, float width = 12f, float spacing = -2f, ScrollbarVisibility visibility = 1)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
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), "OnSpawnServer")]
[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
{
[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)
{
MelonDebug.Msg($"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)
{
MelonDebug.Msg($"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 i = 0; i < num2; i++)
{
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());
MelonDebug.Msg($"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)
{
MelonDebug.Msg($"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)
{
MelonDebug.Msg($"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 Instance _logger = new Instance("EmployeeTweaks.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 Instance Logger = new Instance("EmployeeTweaks.DebugAreaDrawer");
private List<GameObject> _areas = new List<GameObject>();
internal void Draw()
{
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
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(typeof(Property))]
internal class PropertyPatch
{
private static Instance Logger = new Instance("EmployeeTweaks.PropertyPatch");
internal static Dictionary<Property, (Vector3, Vector3)> _propertyIdlePointRects = new Dictionary<Property, (Vector3, Vector3)>();
[HarmonyPatch("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 (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: 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_0097: Unknown result type (might be due to invalid IL or missing references)
if (!Melon<EmployeeTweaks>.Instance.SettingsRegistry.EnableCapacityAndDebug.Value)
{
return;
}
Il2CppReferenceArray<Transform> employeeIdlePoints = __instance.EmployeeIdlePoints;
if (employeeIdlePoints != null && ((Il2CppArrayBase<Transform>)(object)employeeIdlePoints).Length > 0)
{
var (val, val2) = MinMaxPoints(((IEnumerable<Transform>)employeeIdlePoints).AsEnumerable().ToList());
if (val == val2)
{
val2 = val + new Vector3(0.5f, 0f, 0.5f);
}
_propertyIdlePointRects[__instance] = (val, val2);
}
if (__instance.EmployeeCapacity <= 0)
{
return;
}
MelonPreferences_Entry<int> entry = Melon<EmployeeTweaks>.Instance.SettingsRegistry.EmployeeCapacityCategory.GetOrCreateEntry("EmployeeTweaks_" + __instance.propertyCode + "_EmpCap", __instance.EmployeeCapacity, __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_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0310: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Expected O, but got Unknown
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_034e: Unknown result type (might be due to invalid IL or missing references)
int num = prop.Employees?.AsEnumerable<Employee>().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
{
int num2 = ((Il2CppArrayBase<Transform>)(object)prop.EmployeeIdlePoints)?.Length ?? 0;
int num3 = target - num2;
if (num3 <= 0)
{
if (num2 <= 0)
{
entry.Value = prop.EmployeeCapacity;
}
else
{
List<Transform> list = ((IEnumerable<Transform>)prop.EmployeeIdlePoints).AsEnumerable().ToList();
list = list.GetRange(0, target);
prop.EmployeeIdlePoints = Il2CppReferenceArray<Transform>.op_Implicit(list.ToArray());
prop.EmployeeCapacity = list.Count;
}
}
else
{
List<Vector3> list2 = PoissonDiskSampler2D.SampleAdaptive(value.Item1, value.Item2, (((IEnumerable<Transform>)prop.EmployeeIdlePoints)?.AsEnumerable() ?? Array.Empty<Transform>()).ToList(), num3, 1f, 0.01f, prop.propertyCode.GetHashCode());
if (list2.Count + (((Il2CppArrayBase<Transform>)(object)prop.EmployeeIdlePoints)?.Length ?? 0) < target)
{
Logger.Warning($"Generated {list2.Count} new points for {prop.propertyName} but needed {num3}, cannot add capacity");
entry.Value = prop.EmployeeCapacity;
}
else
{
List<Transform> list3 = new List<Transform>();
Transform val3 = ((IEnumerable<Transform>)prop.EmployeeIdlePoints)?.FirstOrDefault();
if ((Object)(object)val3 == (Object)null)
{
Logger.Warning("Property " + prop.propertyName + " has no idle points, cannot add capacity");
entry.Value = prop.EmployeeCapacity;
}
else
{
foreach (Vector3 item in list2)
{
GameObject val4 = new GameObject(prop.propertyName + "_EmployeeIdlePoint");
val4.transform.SetParent(((Component)val3).transform.parent, false);
val4.transform.position = item;
val4.transform.rotation = ((Component)val3).transform.rotation;
list3.Add(val4.transform);
}
foreach (Transform item2 in (Il2CppArrayBase<Transform>)(object)prop.EmployeeIdlePoints)
{
list3.Add(item2);
}
prop.EmployeeIdlePoints = Il2CppReferenceArray<Transform>.op_Implicit(list3.ToArray());
prop.EmployeeCapacity = list3.Count;
}
}
}
}
}
}
private static (Vector3 min, Vector3 max) MinMaxPoints(List<Transform> transforms)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_003e: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if (transforms == null || transforms.Count == 0)
{
throw new ArgumentException("Empty list");
}
Vector3 position = transforms[0].position;
Vector3 val = position;
Vector3 val2 = position;
for (int i = 1; i < transforms.Count; i++)
{
Vector3 position2 = transforms[i].position;
val = Vector3.Min(val, position2);
val2 = Vector3.Max(val2, position2);
}
return (val, val2);
}
}
public static class PoissonDiskSampler2D
{
private static Random _rng;
public static List<Vector3> SampleAdaptive(Vector3 min, Vector3 max, List<Transform> blocked, int targetCount, float preferredRadius, float minRadius, int seed, int maxIterations = 5, int k = 30)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
_rng = new Random(seed);
float num = preferredRadius;
List<Vector3> list = new List<Vector3>();
for (int i = 0; i < maxIterations; i++)
{
List<Vector3> list2 = Sample(min, max, blocked, num, k);
if (list2.Count >= targetCount)
{
return list2.GetRange(0, targetCount);
}
if (list2.Count > list.Count)
{
list = list2;
}
num *= 0.7f;
if (num < minRadius)
{
break;
}
}
if (list.Count < targetCount)
{
list.AddRange(Fill(min, max, blocked, list, targetCount - list.Count, minRadius));
}
return list;
}
private static List<Vector3> Sample(Vector3 min, Vector3 max, List<Transform> blocked, float radius, int k)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: 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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
float num = radius / Mathf.Sqrt(2f);
int num2 = Mathf.CeilToInt((max.x - min.x) / num);
int num3 = Mathf.CeilToInt((max.z - min.z) / num);
Vector3?[,] grid = new Vector3?[num2, num3];
List<Vector3> list = new List<Vector3>();
List<Vector3> list2 = new List<Vector3>();
Vector3 val = RandomPoint(min, max);
list.Add(val);
list2.Add(val);
Set(grid, min, num, val);
while (list.Count > 0)
{
int index = _rng.Next(list.Count);
Vector3 p = list[index];
bool flag = false;
for (int i = 0; i < k; i++)
{
Vector3 val2 = GenerateAround(p, radius);
if (IsValid(val2, min, max, radius, grid, blocked, num))
{
list.Add(val2);
list2.Add(val2);
Set(grid, min, num, val2);
flag = true;
break;
}
}
if (!flag)
{
list.RemoveAt(index);
}
}
return list2;
}
private static List<Vector3> Fill(Vector3 min, Vector3 max, List<Transform> blocked, List<Vector3> current, int needed, float epsilon)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
List<Vector3> list = new List<Vector3>();
float epsSqr = epsilon * epsilon;
int num = 0;
int num2 = needed * 20;
while (list.Count < needed && num++ < num2)
{
Vector3 val = RandomPoint(min, max);
if (!TooClose(val, blocked, current, list, epsSqr))
{
list.Add(val);
}
}
return list;
}
private static Vector3 RandomPoint(Vector3 min, Vector3 max)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
return new Vector3(Lerp(min.x, max.x), min.y, Lerp(min.z, max.z));
}
private static Vector3 GenerateAround(Vector3 p, float radius)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
float num = (float)(_rng.NextDouble() * 3.1415927410125732 * 2.0);
float num2 = Lerp(radius, radius * 2f);
return new Vector3(p.x + Mathf.Cos(num) * num2, p.y, p.z + Mathf.Sin(num) * num2);
}
private static bool IsValid(Vector3 p, Vector3 min, Vector3 max, float radius, Vector3?[,] grid, List<Transform> blocked, float cellSize)
{
//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unusing System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using EmployeeTweaks;
using EmployeeTweaks.Helpers;
using EmployeeTweaks.Patches.EmployeeArea;
using EmployeeTweaks.Patches.FilterItemApply;
using EmployeeTweaks.Patches.Unpackaging;
using EmployeeTweaks.Persistence;
using FishNet;
using FishNet.Connection;
using FishNet.Object;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Internal.Abstraction;
using S1API.Saveables;
using S1API.UI;
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 TMPro;
using UnityEngine;
using UnityEngine.Events;
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.3", "k073l", null)]
[assembly: MelonColor(1, 217, 131, 36)]
[assembly: MelonGame("TVGS", "Schedule I")]
[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.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+38262f090018ba0a7dce31ddadee40e3b352a080")]
[assembly: AssemblyProduct("EmployeeTweaks-Mono")]
[assembly: AssemblyTitle("EmployeeTweaks-Mono")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.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]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace 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.3";
}
public class EmployeeTweaks : MelonMod
{
private static Instance Logger;
private DebugAreaDrawer debugAreaDrawer;
private bool _lastShift;
private bool _lastCtrl;
internal SettingsRegistry SettingsRegistry;
public override void OnInitializeMelon()
{
Logger = ((MelonBase)this).LoggerInstance;
SettingsRegistry = new SettingsRegistry();
Logger.Msg("EmployeeTweaks initialized");
DependenciesChecker.PrintMissing();
MoveItemBehaviourPatches.ManualPatchDestinationValid(((MelonBase)this).HarmonyInstance);
debugAreaDrawer = new DebugAreaDrawer();
DebugAreaDrawer.WireDebugAreaDrawer(debugAreaDrawer);
}
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");
}
}
}
}
internal class SettingsRegistry
{
internal MelonPreferences_Category EmployeeCapacityCategory;
internal MelonPreferences_Entry<bool> EnableCapacityAndDebug;
internal MelonPreferences_Entry<bool> DrawDebugArea;
internal HashSet<MelonPreferences_Entry<int>> EmployeeCapacities = new HashSet<MelonPreferences_Entry<int>>();
internal MelonPreferences_Category EmployeeAssignsCategory;
internal MelonPreferences_Entry<bool> EnableAssigns;
internal MelonPreferences_Entry<int> BotanistMaxPots;
internal MelonPreferences_Entry<int> HandlerMaxStations;
internal MelonPreferences_Entry<int> HandlerMaxRoutes;
internal MelonPreferences_Entry<int> ChemistMaxStations;
internal MelonPreferences_Entry<int> CleanerMaxBins;
public SettingsRegistry()
{
InitializeCapacityCategory();
InitializeAssignsCategory();
}
private void InitializeCapacityCategory()
{
EmployeeCapacityCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeCapacity", "Employee Capacities");
EnableCapacityAndDebug = EmployeeCapacityCategory.CreateEntry<bool>("EmployeeTweaksEnableCapacityAndDebug", true, "Enable Category", "Enables employee capacity tweaks and drawing employee idle points area", false, false, (ValueValidator)null, (string)null);
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.CreateEntry<bool>("EmployeeTweaksEnableAssigns", true, "Enable Category", "Enables employee assigns capacity modifications", false, false, (ValueValidator)null, (string)null);
BotanistMaxPots = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksBotanistMaxPots", 8, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.BotanistBoundsMaxPots.Item1, SettingsConstants.BotanistBoundsMaxPots.Item2), (string)null);
HandlerMaxStations = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksHandlerMaxStations", 3, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxStations.Item1, SettingsConstants.HandlerBoundsMaxStations.Item2), (string)null);
HandlerMaxRoutes = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksHandlerMaxRoutes", 5, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.HandlerBoundsMaxRoutes.Item1, SettingsConstants.HandlerBoundsMaxRoutes.Item2), (string)null);
ChemistMaxStations = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksChemistMaxStations", 4, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.ChemistBoundsMaxStations.Item1, SettingsConstants.ChemistBoundsMaxStations.Item2), (string)null);
CleanerMaxBins = EmployeeAssignsCategory.CreateEntry<int>("EmployeeTweaksCleanerMaxBins", 6, "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.", false, false, (ValueValidator)(object)new ValueRange<int>(SettingsConstants.CleanerBoundsMaxBins.Item1, SettingsConstants.CleanerBoundsMaxBins.Item2), (string)null);
}
}
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;
}
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
{
[CompilerGenerated]
private sealed class <>c__DisplayClass7_0
{
public MoveItemBehaviour __instance;
}
[CompilerGenerated]
private sealed class <>c__DisplayClass9_0
{
public MoveItemBehaviour __instance;
public bool destIsStation;
public ITransitEntity dest;
}
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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: 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)
{
MelonLogger.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)
{
MelonLogger.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) ? 1 : 0));
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)
<>c__DisplayClass7_0 CS$<>8__locals0 = new <>c__DisplayClass7_0();
CS$<>8__locals0.__instance = __instance;
TransitRoute assignedRoute = CS$<>8__locals0.__instance.assignedRoute;
if (((assignedRoute != null) ? assignedRoute.Source : null) == null)
{
return true;
}
ITransitEntity destination = CS$<>8__locals0.__instance.assignedRoute.Destination;
PackagingStation result;
bool flag = Utils.Is2<PackagingStation>(destination, out result) && (Object)(object)result != (Object)null;
ITransitEntity source = CS$<>8__locals0.__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)CS$<>8__locals0.__instance).beh.DEBUG_MODE)
{
Console.Log((object)"MoveItemBehaviour.GrabItem", (Object)null);
}
CS$<>8__locals0.__instance.currentState = (EState)2;
CS$<>8__locals0.__instance.grabRoutine = null;
object value2 = MelonCoroutines.Start(Routine());
customGrabRunning[CS$<>8__locals0.__instance] = value2;
return false;
[IteratorStateMachine(typeof(<>c__DisplayClass7_0.<<GrabItem>g__Routine|0>d))]
IEnumerator Routine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <>c__DisplayClass7_0.<<GrabItem>g__Routine|0>d(0)
{
<>4__this = CS$<>8__locals0
};
}
}
[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)
{
Console.LogWarning((object)"Amount to grab is 0!", (Object)null);
return false;
}
ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0));
if (((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null) == null)
{
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)
<>c__DisplayClass9_0 CS$<>8__locals0 = new <>c__DisplayClass9_0();
CS$<>8__locals0.__instance = __instance;
TransitRoute assignedRoute = CS$<>8__locals0.__instance.assignedRoute;
if (((assignedRoute != null) ? assignedRoute.Destination : null) == null)
{
return true;
}
CS$<>8__locals0.dest = CS$<>8__locals0.__instance.assignedRoute.Destination;
CS$<>8__locals0.destIsStation = Utils.Is2<PackagingStation>(CS$<>8__locals0.dest, out PackagingStation result) && (Object)(object)result != (Object)null;
ITransitEntity source = CS$<>8__locals0.__instance.assignedRoute.Source;
PackagingStation result2;
bool flag = Utils.Is2<PackagingStation>(source, out result2) && (Object)(object)result2 != (Object)null;
if (!CS$<>8__locals0.destIsStation && !flag)
{
return true;
}
PackagingStation val = (CS$<>8__locals0.destIsStation ? result : result2);
UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value);
if (!value)
{
return true;
}
if (((Behaviour)CS$<>8__locals0.__instance).beh.DEBUG_MODE)
{
Console.Log((object)"MoveItemBehaviour.PlaceItem", (Object)null);
}
CS$<>8__locals0.__instance.currentState = (EState)4;
CS$<>8__locals0.__instance.placingRoutine = null;
object value2 = MelonCoroutines.Start(Routine());
customPlaceRunning[CS$<>8__locals0.__instance] = value2;
return false;
[IteratorStateMachine(typeof(<>c__DisplayClass9_0.<<PlaceItem>g__Routine|0>d))]
IEnumerator Routine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <>c__DisplayClass9_0.<<PlaceItem>g__Routine|0>d(0)
{
<>4__this = CS$<>8__locals0
};
}
}
[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 var value))
{
MelonCoroutines.Stop(value);
customPlaceRunning.Remove(__instance);
return false;
}
return true;
}
return true;
}
if (customGrabRunning.TryGetValue(__instance, out var value2))
{
MelonCoroutines.Stop(value2);
customGrabRunning.Remove(__instance);
return false;
}
return true;
}
[HarmonyPatch("OnActiveTick")]
[HarmonyPrefix]
private static bool OnActiveTick(MoveItemBehaviour __instance)
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Invalid comparison between Unknown and I4
if (!InstanceFinder.IsServer)
{
return false;
}
if (!__instance.assignedRoute.AreEntitiesNonNull())
{
Console.LogWarning((object)"Transit route entities are null!", (Object)null);
((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
return false;
}
if (((Behaviour)__instance).beh.DEBUG_MODE)
{
Console.Log((object)("State: " + ((object)(EState)(ref __instance.currentState)).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_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Expected O, but got Unknown
//IL_0217: 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) : 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))
{
Console.LogWarning((object)("Invalid transit route for move item behaviour by checking transit route!. Reason: " + text), (Object)null);
((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))
{
Console.LogWarning((object)("Invalid transit route for move item behaviour by checking destination! Reason: " + text2), (Object)null);
((Behaviour)__instance).Disable_Networked((NetworkConnection)null);
return false;
}
}
__instance.currentState = (EState)0;
return false;
}
}
[HarmonyPatch(typeof(Packager))]
internal static class 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)
{
Console.Log((object)("[Unpacked] Rejected item " + ((BaseItemInstance)x.ItemInstance).ID + ": " + text), (Object)null);
}
return flag;
});
if (val == null)
{
return true;
}
Console.Log((object)("[Unpacked] Starting moving items from " + ((Object)((Component)station).gameObject).name), (Object)null);
((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))
{
Console.LogError((object)("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)
{
Console.Log((object)("MoveItemBehaviour initialized with route: " + route.Source.Name + " -> " + route.Destination.Name + " for item: " + ((BaseItemInstance)_itemToRetrieveTemplate).ID), (Object)null);
}
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;
}
}
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
{
[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_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Expected O, but got Unknown
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: 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_0226: Expected O, but got Unknown
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: 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)
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 var _))
{
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>();
val3.sizeDelta = new Vector2(400f, 50f);
GameObject val4 = new GameObject("Title");
val4.transform.SetParent(val2.transform, false);
RectTransform val5 = val4.AddComponent<RectTransform>();
val5.anchorMin = new Vector2(0f, 0.5f);
val5.anchorMax = new Vector2(0f, 0.5f);
val5.pivot = new Vector2(0f, 0.5f);
val5.anchoredPosition = new Vector2(0f, 0f);
val5.sizeDelta = new Vector2(150f, 30f);
TextMeshProUGUI val6 = val4.AddComponent<TextMeshProUGUI>();
((TMP_Text)val6).fontSize = 24f;
((TMP_Text)val6).alignment = (TextAlignmentOptions)513;
((TMP_Text)val6).text = "Set Unpackage";
((Graphic)val6).color = Color.black;
GameObject val7 = new GameObject("Value");
val7.transform.SetParent(val2.transform, false);
RectTransform val8 = val7.AddComponent<RectTransform>();
val8.anchorMin = new Vector2(1f, 0.5f);
val8.anchorMax = new Vector2(1f, 0.5f);
val8.pivot = new Vector2(1f, 0.5f);
val8.anchoredPosition = new Vector2(0f, 0f);
val8.sizeDelta = new Vector2(80f, 30f);
TextMeshProUGUI valueTmpro = val7.AddComponent<TextMeshProUGUI>();
((TMP_Text)valueTmpro).fontSize = 24f;
((TMP_Text)valueTmpro).alignment = (TextAlignmentOptions)516;
UnpackageSave.Instance.TryGetValue(stationGuid, out var value2);
((TMP_Text)valueTmpro).text = (value2 ? "On" : "Off");
((Graphic)valueTmpro).color = (value2 ? Color.green : Color.gray);
Button val9 = val7.AddComponent<Button>();
((UnityEventBase)val9.onClick).RemoveAllListeners();
string s = "";
EventHelper.AddListener((Action)delegate
{
//IL_00b2: 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)
s = s;
MelonLogger.Msg("Button clicked");
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];
((TMP_Text)valueTmpro).text = (flag ? "On" : "Off");
((Graphic)valueTmpro).color = (flag ? Color.green : Color.gray);
}
}, (UnityEvent)(object)val9.onClick);
UIContentPanel component2 = ((Component)__instance).GetComponent<UIContentPanel>();
if ((Object)(object)component2 != (Object)null)
{
UISelectable val10 = val7.GetComponent<UISelectable>();
if ((Object)(object)val10 == (Object)null)
{
val10 = val7.AddComponent<UISelectable>();
}
((UIPanel)component2).AddSelectable(val10);
}
}
catch (Exception arg)
{
MelonLogger.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 Instance _logger = new Instance("EmployeeTweaks.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), "Awake")]
[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), "OnSpawnServer")]
[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), "OnSpawnServer")]
[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
{
private static readonly Instance Logger = new Instance("EmployeeTweaks.MoreEmployeeConfigItems");
public static ScrollRect MoveToScrollableList(RectTransform source, Transform parent)
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
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 val = default(ScrollRect);
RectTransform val2 = UIFactory.ScrollableVerticalList(((Object)source).name + "_Scroll", parent, ref val);
VerticalLayoutGroup component2 = ((Component)val2).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)val2, 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)val).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);
val2.sizeDelta = new Vector2(0f, val2.sizeDelta.y);
LayoutElement orAddComponent = ((Component)val2).gameObject.GetOrAddComponent<LayoutElement>();
orAddComponent.flexibleWidth = 1f;
ContentSizeFitter orAddComponent2 = ((Component)val2).gameObject.GetOrAddComponent<ContentSizeFitter>();
orAddComponent2.horizontalFit = (FitMode)0;
AddVerticalScrollbar(val, 8f, 8f, (ScrollbarVisibility)1);
Object.Destroy((Object)(object)((Component)source).gameObject);
LayoutRebuilder.ForceRebuildLayoutImmediate(val2);
return val;
}
public static Scrollbar AddVerticalScrollbar(ScrollRect scrollRect, float width = 12f, float spacing = -2f, ScrollbarVisibility visibility = 1)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
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), "OnSpawnServer")]
[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
{
[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)
{
MelonDebug.Msg($"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)
{
MelonDebug.Msg($"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 j = 0; j < num3; j++)
{
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();
MelonDebug.Msg($"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)
{
MelonDebug.Msg($"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)
{
MelonDebug.Msg($"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 Instance _logger = new Instance("EmployeeTweaks.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_00a3: 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 Instance Logger = new Instance("EmployeeTweaks.DebugAreaDrawer");
private List<GameObject> _areas = new List<GameObject>();
internal void Draw()
{
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
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(typeof(Property))]
internal class PropertyPatch
{
private static Instance Logger = new Instance("EmployeeTweaks.PropertyPatch");
internal static Dictionary<Property, (Vector3, Vector3)> _propertyIdlePointRects = new Dictionary<Property, (Vector3, Vector3)>();
[HarmonyPatch("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;
}
MelonPreferences_Entry<int> entry = Melon<EmployeeTweaks>.Instance.SettingsRegistry.EmployeeCapacityCategory.GetOrCreateEntry("EmployeeTweaks_" + __instance.propertyCode + "_EmpCap", __instance.EmployeeCapacity, __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_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: 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_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Expected O, but got Unknown
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: 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> list = prop.EmployeeIdlePoints.AsEnumerable().ToList();
list = list.GetRange(0, target);
prop.EmployeeIdlePoints = list.ToArray();
prop.EmployeeCapacity = list.Count;
}
}
else
{
List<Vector3> list2 = PoissonDiskSampler2D.SampleAdaptive(value.Item1, value.Item2, (prop.EmployeeIdlePoints?.AsEnumerable() ?? Array.Empty<Transform>()).ToList(), num3, 1f, 0.01f, prop.propertyCode.GetHashCode());
int count = list2.Count;
Transform[] employeeIdlePoints3 = prop.EmployeeIdlePoints;
if (count + ((employeeIdlePoints3 != null) ? employeeIdlePoints3.Length : 0) < target)
{
Logger.Warning($"Generated {list2.Count} new points for {prop.propertyName} but needed {num3}, cannot add capacity");
entry.Value = prop.EmployeeCapacity;
}
else
{
List<Transform> list3 = new List<Transform>();
Transform val3 = prop.EmployeeIdlePoints?.FirstOrDefault();
if ((Object)(object)val3 == (Object)null)
{
Logger.Warning("Property " + prop.propertyName + " has no idle points, cannot add capacity");
entry.Value = prop.EmployeeCapacity;
}
else
{
foreach (Vector3 item2 in list2)
{
GameObject val4 = new GameObject(prop.propertyName + "_EmployeeIdlePoint");
val4.transform.SetParent(((Component)val3).transform.parent, false);
val4.transform.position = item2;
val4.transform.rotation = ((Component)val3).transform.rotation;
list3.Add(val4.transform);
}
Transform[] employeeIdlePoints4 = prop.EmployeeIdlePoints;
foreach (Transform item in employeeIdlePoints4)
{
list3.Add(item);
}
prop.EmployeeIdlePoints = list3.ToArray();
prop.EmployeeCapacity = list3.Count;
}
}
}
}
}
}
private static (Vector3 min, Vector3 max) MinMaxPoints(List<Transform> transforms)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_003e: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if (transforms == null || transforms.Count == 0)
{
throw new ArgumentException("Empty list");
}
Vector3 position = transforms[0].position;
Vector3 val = position;
Vector3 val2 = position;
for (int i = 1; i < transforms.Count; i++)
{
Vector3 position2 = transforms[i].position;
val = Vector3.Min(val, position2);
val2 = Vector3.Max(val2, position2);
}
return (val, val2);
}
}
public static class PoissonDiskSampler2D
{
private static Random _rng;
public static List<Vector3> SampleAdaptive(Vector3 min, Vector3 max, List<Transform> blocked, int targetCount, float preferredRadius, float minRadius, int seed, int maxIterations = 5, int k = 30)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
_rng = new Random(seed);
float num = preferredRadius;
List<Vector3> list = new List<Vector3>();
for (int i = 0; i < maxIterations; i++)
{
List<Vector3> list2 = Sample(min, max, blocked, num, k);
if (list2.Count >= targetCount)
{
return list2.GetRange(0, targetCount);
}
if (list2.Count > list.Count)
{
list = list2;
}
num *= 0.7f;
if (num < minRadius)
{
break;
}
}
if (list.Count < targetCount)
{
list.AddRange(Fill(min, max, blocked, list, targetCount - list.Count, minRadius));
}
return list;
}
private static List<Vector3> Sample(Vector3 min, Vector3 max, List<Transform> blocked, float radius, int k)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: 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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
float num = radius / Mathf.Sqrt(2f);
int num2 = Mathf.CeilToInt((max.x - min.x) / num);
int num3 = Mathf.CeilToInt((max.z - min.z) / num);
Vector3?[,] grid = new Vector3?[num2, num3];
List<Vector3> list = new List<Vector3>();
List<Vector3> list2 = new List<Vector3>();
Vector3 val = RandomPoint(min, max);
list.Add(val);
list2.Add(val);
Set(grid, min, num, val);
while (list.Count > 0)
{
int index = _rng.Next(list.Count);
Vector3 p = list[index];
bool flag = false;
for (int i = 0; i < k; i++)
{
Vector3 val2 = GenerateAround(p, radius);
if (IsValid(val2, min, max, radius, grid, blocked, num))
{
list.Add(val2);
list2.Add(val2);
Set(grid, min, num, val2);
flag = true;
break;
}
}
if (!flag)
{
list.RemoveAt(index);
}
}
return list2;
}
private static List<Vector3> Fill(Vector3 min, Vector3 max, List<Transform> blocked, List<Vector3> current, int needed, float epsilon)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
List<Vector3> list = new List<Vector3>();
float epsSqr = epsilon * epsilon;
int num = 0;
int num2 = needed * 20;
while (list.Count < needed && num++ < num2)
{
Vector3 val = RandomPoint(min, max);
if (!TooClose(val, blocked, current, list, epsSqr))
{
list.Add(val);
}
}
return list;
}
private static Vector3 RandomPoint(Vector3 min, Vector3 max)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
return new Vector3(Lerp(min.x, max.x), min.y, Lerp(min.z, max.z));
}
private static Vector3 GenerateAround(Vector3 p, float radius)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
float num = (float)(_rng.NextDouble() * 3.1415927410125732 * 2.0);
float num2 = Lerp(radius, radius * 2f);
return new Vector3(p.x + Mathf.Cos(num) * num2, p.y, p.z + Mathf.Sin(num) * num2);
}
private static bool IsValid(Vector3 p, Vector3 min, Vector3 max, float radius, Vector3?[,] grid, List<Transform> blocked, float cellSize)
{
//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
if (p.x < min.x || p.x > max.x || p.z < min.z || p.z > max.z)
{
return false;
}
float num = radius * radius;
if (TooClose(p, blocked, null, null, num))
{
return false;
}
int num2 = (int)((p.x - min.x) / cellSize);
int num3 = (int)((p.z - min.z) / cellSize);
for (int i = -2; i <= 2; i++)
{
for (int j = -2; j <= 2; j++)
{
int num4 = num2 + i;
int num5 = num3 + j;
if (num4 >= 0 && num5 >= 0 && num4 < grid.GetLength(0) && num5 < grid.GetLength(1) && grid[num4, num5].HasValue)
{
Vector3 val = grid[num4, num5].Value - p;
if (((Vector3)(ref val)).sqrMagnitude < num)
{
return false;
}
}
}
}
return true;
}
private static void Set(Vector3?[,] grid, Vector3 min, float cellSize, Vector3 p)
{
//IL_0001: 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_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
int num = (int)((p.x - min.x) / cellSize);
int num2 = (int)((p.z - min.z) / cellSize);
grid[num, num2] = p;
}
private static bool TooClose(Vector3 p, List<Transform> blocked, List<Vector3> a, List<Vector3> b, float epsSqr)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: 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_00c8: Unknown result type (might be due to invalid IL or missing references)