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 EnableCapacityAndDebug; internal MelonPreferences_Entry DrawDebugArea; internal HashSet> EmployeeCapacities = new HashSet>(); internal MelonPreferences_Category EmployeeAssignsCategory; internal MelonPreferences_Entry EnableAssigns; internal MelonPreferences_Entry BotanistMaxPots; internal MelonPreferences_Entry HandlerMaxStations; internal MelonPreferences_Entry HandlerMaxRoutes; internal MelonPreferences_Entry ChemistMaxStations; internal MelonPreferences_Entry CleanerMaxBins; public SettingsRegistry() { InitializeCapacityCategory(); InitializeAssignsCategory(); } private void InitializeCapacityCategory() { EmployeeCapacityCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeCapacity", "Employee Capacities"); EnableCapacityAndDebug = EmployeeCapacityCategory.CreateEntry("EmployeeTweaksEnableCapacityAndDebug", true, "Enable Category", "Enables employee capacity tweaks and drawing employee idle points area", false, false, (ValueValidator)null, (string)null); DrawDebugArea = EmployeeCapacityCategory.CreateEntry("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("EmployeeTweaksEnableAssigns", true, "Enable Category", "Enables employee assigns capacity modifications", false, false, (ValueValidator)null, (string)null); BotanistMaxPots = EmployeeAssignsCategory.CreateEntry("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(SettingsConstants.BotanistBoundsMaxPots.Item1, SettingsConstants.BotanistBoundsMaxPots.Item2), (string)null); HandlerMaxStations = EmployeeAssignsCategory.CreateEntry("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(SettingsConstants.HandlerBoundsMaxStations.Item1, SettingsConstants.HandlerBoundsMaxStations.Item2), (string)null); HandlerMaxRoutes = EmployeeAssignsCategory.CreateEntry("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(SettingsConstants.HandlerBoundsMaxRoutes.Item1, SettingsConstants.HandlerBoundsMaxRoutes.Item2), (string)null); ChemistMaxStations = EmployeeAssignsCategory.CreateEntry("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(SettingsConstants.ChemistBoundsMaxStations.Item1, SettingsConstants.ChemistBoundsMaxStations.Item2), (string)null); CleanerMaxBins = EmployeeAssignsCategory.CreateEntry("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(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 UnpackageStations = new Dictionary(); 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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = ((TransitRoute)__instance).Source; PackagingStation result2; bool flag2 = Utils.Is2((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 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 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 customGrabRunning = new Dictionary(); private static Dictionary customPlaceRunning = new Dictionary(); 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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = route.Source; PackagingStation result2; bool flag2 = Utils.Is2((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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = route.Source; PackagingStation result2; bool flag2 = Utils.Is2((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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2((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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2((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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = CS$<>8__locals0.__instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2((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.<g__Routine|0>d))] IEnumerator Routine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <>c__DisplayClass7_0.<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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2((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((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((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.<g__Routine|0>d))] IEnumerator Routine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <>c__DisplayClass9_0.<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((object)destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2((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((Delegate)new Func(__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 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((object)current, out result) && (Object)(object)result != (Object)null && UnpackageSave.Instance.TryGetValue(((BuildableItem)result).GUID, out value) && value) { List inputSlots = result.InputSlots; if (Utils.Is((object)current.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 = current; return false; } } } else { ItemSlot outputSlot = current.OutputSlot; if (Utils.Is((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((object)station.Configuration, out PackagingStationConfiguration config) || config == null) { return true; } ItemSlot val = station.InputSlots.AsEnumerable().FirstOrDefault((Func)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 UnpackageFields = new Dictionary(); 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 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 enumerator = configs.GetEnumerator(); while (enumerator.MoveNext()) { EntityConfiguration current = enumerator.Current; if (!Utils.Is((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 component = ((Component)__instance.DestinationUI).GetComponent(); val3.sizeDelta = new Vector2(400f, 50f); GameObject val4 = new GameObject("Title"); val4.transform.SetParent(val2.transform, false); RectTransform val5 = val4.AddComponent(); 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(); ((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(); 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(); ((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