using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using EmployeeTweaks; using EmployeeTweaks.Helpers; using EmployeeTweaks.Network; using EmployeeTweaks.Patches.EmployeeArea; using EmployeeTweaks.Patches.FilterItemApply; using EmployeeTweaks.Patches.Unpackaging; using EmployeeTweaks.Persistence; using FishNet; using FishNet.Connection; using FishNet.Object; using HarmonyLib; using MelonLoader; using MelonLoader.Preferences; using MelonLoader.Utils; using Microsoft.CodeAnalysis; using S1API.Entities; using S1API.Internal.Abstraction; using S1API.Saveables; using S1API.UI; using ScheduleOne; using ScheduleOne.Core.Items.Framework; using ScheduleOne.Effects; using ScheduleOne.Employees; using ScheduleOne.EntityFramework; using ScheduleOne.Growing; using ScheduleOne.ItemFramework; using ScheduleOne.Management; using ScheduleOne.NPCs; using ScheduleOne.NPCs.Behaviour; using ScheduleOne.ObjectScripts; using ScheduleOne.PlayerScripts; using ScheduleOne.Product; using ScheduleOne.Property; using ScheduleOne.Tiles; using ScheduleOne.Tools; using ScheduleOne.UI.Items; using ScheduleOne.UI.Management; using Semver; using SteamNetworkLib; using SteamNetworkLib.Events; using SteamNetworkLib.Models; using Steamworks; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: MelonInfo(typeof(global::EmployeeTweaks.EmployeeTweaks), "EmployeeTweaks", "1.0.5", "k073l", null)] [assembly: MelonColor(1, 217, 131, 36)] [assembly: MelonGame("TVGS", "Schedule I")] [assembly: MelonOptionalDependencies(new string[] { "SteamNetworkLib" })] [assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("EmployeeTweaks-Mono")] [assembly: AssemblyConfiguration("Mono")] [assembly: AssemblyDescription("Various employee tweaks - unpackaging, sprinkler/pourer use and more")] [assembly: AssemblyFileVersion("1.0.5.0")] [assembly: AssemblyInformationalVersion("1.0.5+849dbbb6d27c6c028f7583f6aca013d2bcbac764")] [assembly: AssemblyProduct("EmployeeTweaks-Mono")] [assembly: AssemblyTitle("EmployeeTweaks-Mono")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.5.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EmployeeTweaks { public static class BuildInfo { public const string Name = "EmployeeTweaks"; public const string Description = "Various employee tweaks - unpackaging, sprinkler/pourer use and more"; public const string Author = "k073l"; public const string Version = "1.0.5"; } public class EmployeeTweaks : MelonMod { private static Instance Logger; private DebugAreaDrawer debugAreaDrawer; private bool _lastShift; private bool _lastCtrl; internal SettingsRegistry SettingsRegistry; internal INetworkManager? NetworkManager; public override void OnInitializeMelon() { Logger = ((MelonBase)this).LoggerInstance; CheckDependencies(); MoveItemBehaviourPatches.ManualPatchDestinationValid(((MelonBase)this).HarmonyInstance); } public override void OnLateInitializeMelon() { SettingsRegistry = new SettingsRegistry(); NetworkManager = NetworkLoader.Create(); if (NetworkManager == null) { Logger.Warning("NetworkManager is null, multiplayer features will be unavailable."); } SettingsRegistry.InitializeCategories(); debugAreaDrawer = new DebugAreaDrawer(); DebugAreaDrawer.WireDebugAreaDrawer(debugAreaDrawer); Logger.Msg("EmployeeTweaks initialized"); } public override void OnUpdate() { NetworkManager?.Update(); } public override void OnLateUpdate() { TextMeshProUGUI applyItemAsFilterButtonText = FilterConfigPanelPatches.ApplyItemAsFilterButtonText; if (!((Object)(object)applyItemAsFilterButtonText == (Object)null)) { bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303); bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305); if (flag != _lastShift || flag2 != _lastCtrl) { _lastShift = flag; _lastCtrl = flag2; FilterConfigPanelPatches.AllSlots = flag; FilterConfigPanelPatches.DenyListMode = flag2; ((TMP_Text)applyItemAsFilterButtonText).text = (flag ? "Apply All As Filters" : "Apply Item As Filter"); } } } public override void OnDeinitializeMelon() { NetworkManager?.Dispose(); } private static void CheckDependencies() { DependenciesChecker dependenciesChecker = new DependenciesChecker { ShowMenuBanner = true, UnloadIfMissingRequired = true }; dependenciesChecker.AddDependency(new DependencyInfo { Name = "S1API (Forked)", AssemblyName = "S1API", IsRequired = true, Version = "3.0.2", Urls = new List(3) { new DependencyUrl { SourceName = "Thunderstore", Url = "https://thunderstore.io/c/schedule-i/p/ifBars/S1API_Forked/" }, new DependencyUrl { SourceName = "NexusMods", Url = "https://www.nexusmods.com/schedule1/mods/1194" }, new DependencyUrl { SourceName = "Github", Url = "https://github.com/ifBars/S1API/releases/" } } }); dependenciesChecker.AddDependency(new DependencyInfo { Name = "SteamNetworkLib", AssemblyName = "SteamNetworkLib", IsRequired = false, Version = "1.2.1", Urls = new List(4) { new DependencyUrl { SourceName = "Thunderstore Il2Cpp", Url = "https://thunderstore.io/c/schedule-i/p/ifBars/SteamNetworkLib_Il2Cpp/" }, new DependencyUrl { SourceName = "Thunderstore Mono", Url = "https://thunderstore.io/c/schedule-i/p/ifBars/SteamNetworkLib_Mono/" }, new DependencyUrl { SourceName = "NexusMods", Url = "https://www.nexusmods.com/schedule1/mods/1396" }, new DependencyUrl { SourceName = "Github", Url = "https://github.com/ifBars/SteamNetworkLib/releases" } } }); dependenciesChecker.ProcessAndAlert(); } } internal class SettingsRegistry { internal MelonPreferences_Category EmployeeCapacityCategory; internal NetworkedMelonEntry EnableCapacityAndDebug; internal MelonPreferences_Entry DrawDebugArea; internal HashSet> EmployeeCapacities = new HashSet>(); internal MelonPreferences_Category EmployeeAssignsCategory; internal NetworkedMelonEntry EnableAssigns; internal NetworkedMelonEntry BotanistMaxPots; internal NetworkedMelonEntry HandlerMaxStations; internal NetworkedMelonEntry HandlerMaxRoutes; internal NetworkedMelonEntry ChemistMaxStations; internal NetworkedMelonEntry CleanerMaxBins; internal object? _boxedClient = null; internal object? _boxedOptions = null; public bool InitializeNetwork(object? client) { if (client == null) { return false; } _boxedClient = client; Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "SteamNetworkLib"); if (assembly == null) { return false; } Type type = assembly.GetType("SteamNetworkLib.Sync.NetworkSyncOptions"); if (type == null) { return false; } _boxedOptions = Activator.CreateInstance(type); if (_boxedOptions == null) { return false; } PropertyInfo property = type.GetProperty("KeyPrefix"); if (property == null) { return false; } property.SetValue(_boxedOptions, Assembly.GetExecutingAssembly().GetName().Name + "_"); return true; } public void InitializeCategories() { InitializeCapacityCategory(); InitializeAssignsCategory(); } private void InitializeCapacityCategory() { EmployeeCapacityCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeCapacity", "Employee Capacities"); EnableCapacityAndDebug = EmployeeCapacityCategory.GetOrCreateNetworkedEntry("EmployeeTweaksEnableCapacityAndDebug", defaultValue: true, _boxedClient, _boxedOptions, announce: true, "Enable Category", "Enables employee capacity tweaks and drawing employee idle points area"); DrawDebugArea = EmployeeCapacityCategory.CreateEntry("EmployeeTweaksDrawDebugArea", false, "Draw Debug Area", "Draws a debug area where employee idle points are contained", false, false, (ValueValidator)null, (string)null); } private void InitializeAssignsCategory() { EmployeeAssignsCategory = MelonPreferences.CreateCategory("EmployeeTweaksEmployeeAssignsCategory", "Employee Assigns Capacities"); EnableAssigns = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksEnableAssigns", defaultValue: true, _boxedClient, _boxedOptions, announce: true, "Enable Category", "Enables employee assigns capacity modifications"); BotanistMaxPots = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksBotanistMaxPots", 8, _boxedClient, _boxedOptions, announce: true, "Botanist Max Pots", $"Maximum number of pots a botanist can be assigned to (allowed values from {SettingsConstants.BotanistBoundsMaxPots.Item1} to {SettingsConstants.BotanistBoundsMaxPots.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange(SettingsConstants.BotanistBoundsMaxPots.Item1, SettingsConstants.BotanistBoundsMaxPots.Item2)); HandlerMaxStations = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksHandlerMaxStations", 3, _boxedClient, _boxedOptions, announce: true, "Handler Max Stations", $"Maximum number of stations a packager can be assigned to (allowed values from {SettingsConstants.HandlerBoundsMaxStations.Item1} to {SettingsConstants.HandlerBoundsMaxStations.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange(SettingsConstants.HandlerBoundsMaxStations.Item1, SettingsConstants.HandlerBoundsMaxStations.Item2)); HandlerMaxRoutes = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksHandlerMaxRoutes", 5, _boxedClient, _boxedOptions, announce: true, "Handler Max Routes", $"Maximum number of routes a packager can be assigned to (allowed values from {SettingsConstants.HandlerBoundsMaxRoutes.Item1} to {SettingsConstants.HandlerBoundsMaxRoutes.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange(SettingsConstants.HandlerBoundsMaxRoutes.Item1, SettingsConstants.HandlerBoundsMaxRoutes.Item2)); ChemistMaxStations = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksChemistMaxStations", 4, _boxedClient, _boxedOptions, announce: true, "Chemist Max Stations", $"Maximum number of stations a chemist can be assigned to (allowed values from {SettingsConstants.ChemistBoundsMaxStations.Item1} to {SettingsConstants.ChemistBoundsMaxStations.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange(SettingsConstants.ChemistBoundsMaxStations.Item1, SettingsConstants.ChemistBoundsMaxStations.Item2)); CleanerMaxBins = EmployeeAssignsCategory.GetOrCreateNetworkedEntry("EmployeeTweaksCleanerMaxBins", 6, _boxedClient, _boxedOptions, announce: true, "Cleaner Max Trash Cans", $"Maximum number of trash cans a cleaner can be assigned to (allowed values from {SettingsConstants.CleanerBoundsMaxBins.Item1} to {SettingsConstants.CleanerBoundsMaxBins.Item2}). Changes require a restart.", isHidden: false, dontSaveDefault: false, (ValueValidator?)(object)new ValueRange(SettingsConstants.CleanerBoundsMaxBins.Item1, SettingsConstants.CleanerBoundsMaxBins.Item2)); } } 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; } protected override void OnLoaded() { INetworkManager? networkManager = Melon.Instance.NetworkManager; if (networkManager == null || networkManager.IsSingleplayer) { return; } foreach (KeyValuePair unpackageStation in UnpackageStations) { Melon.Instance.NetworkManager?.BroadcastStation(unpackageStation.Key.ToString(), unpackageStation.Value); } } public bool TryGetValue(Guid guid, out bool value) { return UnpackageStations.TryGetValue(guid, out value); } } } namespace EmployeeTweaks.Patches.Unpackaging { [HarmonyPatch(typeof(AdvancedTransitRoute))] internal static class AdvancedTransitRoutePatch { [HarmonyPatch("GetItemReadyToMove")] [HarmonyPrefix] private static bool GetItemReadyToMove(AdvancedTransitRoute __instance, ref ItemInstance __result) { if (((TransitRoute)__instance).Source == null || ((TransitRoute)__instance).Destination == null) { return true; } if (((TransitRoute)__instance).Destination == null) { return true; } ITransitEntity destination = ((TransitRoute)__instance).Destination; PackagingStation result; bool flag = Utils.Is2(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = ((TransitRoute)__instance).Source; PackagingStation result2; bool flag2 = Utils.Is2(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 { 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) { invalidReason = string.Empty; if (((route != null) ? route.Destination : null) == null) { __result = false; return true; } ITransitEntity destination = route.Destination; PackagingStation result; bool flag = Utils.Is2(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = route.Source; PackagingStation result2; bool flag2 = Utils.Is2(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(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = route.Source; PackagingStation result2; bool flag2 = Utils.Is2(source, out result2) && (Object)(object)result2 != (Object)null; if (!flag && !flag2) { return true; } PackagingStation val = (flag ? result : result2); UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value); if (!value) { __result = false; return true; } if (!route.AreEntitiesNonNull()) { invalidReason = "Entities are null!"; __result = false; return false; } ItemSlot firstSlotContainingItem = source.GetFirstSlotContainingItem(itemID, (ESlotType)(!flag2)); ItemInstance val2 = ((firstSlotContainingItem != null) ? firstSlotContainingItem.ItemInstance : null); if (val2 == null || ((BaseItemInstance)val2).Quantity <= 0) { invalidReason = "Item is null or quantity is 0!"; __result = false; return false; } if (!__instance.IsDestinationValid(route, val2, ref invalidReason)) { __result = false; return false; } __result = true; return false; } [HarmonyPatch("IsNpcInventoryItemValid")] [HarmonyPrefix] private static bool CheckNpcInventoryItemValid(MoveItemBehaviour __instance, ItemInstance item, ref bool __result) { TransitRoute assignedRoute = __instance.assignedRoute; if (((assignedRoute != null) ? assignedRoute.Destination : null) == null) { return true; } ITransitEntity destination = __instance.assignedRoute.Destination; PackagingStation result; bool flag = Utils.Is2(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2(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(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2(source, out result2) && (Object)(object)result2 != (Object)null; if (!flag && !flag2) { return true; } PackagingStation val = (flag ? result : result2); UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value); if (!value) { return true; } ItemSlot firstSlotContainingTemplateItem = __instance.assignedRoute.Source.GetFirstSlotContainingTemplateItem(__instance.itemToRetrieveTemplate, (ESlotType)(flag ? 1 : 0)); ItemInstance val2 = ((firstSlotContainingTemplateItem != null) ? firstSlotContainingTemplateItem.ItemInstance : null); if (val2 == null) { __result = 0; return false; } int num = ((BaseItemInstance)val2).Quantity; if (__instance.maxMoveAmount > 0) { num = Mathf.Min(__instance.maxMoveAmount, num); } int num2 = (flag ? destination.GetOutputCapacityForItem(val2, ((Behaviour)__instance).Npc) : destination.GetInputCapacityForItem(val2, ((Behaviour)__instance).Npc, true)); __result = Mathf.Min(num, num2); return false; } [HarmonyPatch("GrabItem")] [HarmonyPrefix] private static bool GrabItem(MoveItemBehaviour __instance) { //IL_0102: Unknown result type (might be due to invalid IL or missing references) TransitRoute assignedRoute = __instance.assignedRoute; if (((assignedRoute != null) ? assignedRoute.Source : null) == null) { return true; } ITransitEntity destination = __instance.assignedRoute.Destination; PackagingStation result; bool flag = Utils.Is2(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2(source, out result2) && (Object)(object)result2 != (Object)null; if (!flag && !flag2) { return true; } PackagingStation val = (flag ? result : result2); UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value); if (!value) { return true; } if (flag) { return true; } if (((Behaviour)__instance).beh.DEBUG_MODE) { Console.Log((object)"MoveItemBehaviour.GrabItem", (Object)null); } __instance.currentState = (EState)2; __instance.grabRoutine = null; object value2 = MelonCoroutines.Start(Routine()); customGrabRunning[__instance] = value2; return false; IEnumerator Routine() { Transform sourceAccessPoint = __instance.GetSourceAccessPoint(__instance.assignedRoute); if ((Object)(object)sourceAccessPoint == (Object)null) { Console.LogWarning((object)"Could not find source access point!", (Object)null); __instance.grabRoutine = null; ((Behaviour)__instance).Disable_Networked((NetworkConnection)null); object coro = customGrabRunning[__instance]; customGrabRunning.Remove(__instance); MelonCoroutines.Stop(coro); } else { ((Behaviour)__instance).Npc.Movement.FaceDirection(sourceAccessPoint.forward, 0.5f); ((Behaviour)__instance).Npc.SetAnimationTrigger_Networked((NetworkConnection)null, "GrabItem"); if (Utils.Is(((Behaviour)__instance).Npc, out Employee employee) && !((Object)(object)employee == (Object)null)) { float seconds = 0.5f / employee.CurrentWorkSpeed; yield return (object)new WaitForSeconds(seconds); ItemInstance itemToRetrieveTemplate = __instance.itemToRetrieveTemplate; if (((itemToRetrieveTemplate != null) ? ((BaseItemInstance)itemToRetrieveTemplate).ID : null) != null) { string invalidReason = default(string); if (!__instance.IsTransitRouteValid(__instance.assignedRoute, ((BaseItemInstance)__instance.itemToRetrieveTemplate).ID, ref invalidReason)) { Console.LogWarning((object)(((Behaviour)__instance).Npc.fullName + " transit route no longer valid! Reason: " + invalidReason), (Object)null); __instance.grabRoutine = null; ((Behaviour)__instance).Disable_Networked((NetworkConnection)null); object coro2 = customGrabRunning[__instance]; customGrabRunning.Remove(__instance); MelonCoroutines.Stop(coro2); } else { __instance.TakeItem(); yield return (object)new WaitForSeconds(0.5f); __instance.grabRoutine = null; __instance.currentState = (EState)0; object coro3 = customGrabRunning[__instance]; customGrabRunning.Remove(__instance); MelonCoroutines.Stop(coro3); } } } } } } [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(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2(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) TransitRoute assignedRoute = __instance.assignedRoute; if (((assignedRoute != null) ? assignedRoute.Destination : null) == null) { return true; } ITransitEntity dest = __instance.assignedRoute.Destination; PackagingStation result; bool destIsStation = Utils.Is2(dest, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag = Utils.Is2(source, out result2) && (Object)(object)result2 != (Object)null; if (!destIsStation && !flag) { return true; } PackagingStation val = (destIsStation ? result : result2); UnpackageSave.Instance.TryGetValue(((BuildableItem)val).GUID, out var value); if (!value) { return true; } if (((Behaviour)__instance).beh.DEBUG_MODE) { Console.Log((object)"MoveItemBehaviour.PlaceItem", (Object)null); } __instance.currentState = (EState)4; __instance.placingRoutine = null; object value2 = MelonCoroutines.Start(Routine()); customPlaceRunning[__instance] = value2; return false; IEnumerator Routine() { if ((Object)(object)__instance.GetDestinationAccessPoint(__instance.assignedRoute) != (Object)null) { ((Behaviour)__instance).Npc.Movement.FaceDirection(__instance.GetDestinationAccessPoint(__instance.assignedRoute).forward, 0.5f); } ((Behaviour)__instance).Npc.SetAnimationTrigger_Networked((NetworkConnection)null, "GrabItem"); if (!Utils.Is(((Behaviour)__instance).Npc, out Employee employee) || (Object)(object)employee == (Object)null) { customPlaceRunning.Remove(__instance); } else { float seconds = 0.5f / employee.CurrentWorkSpeed; yield return (object)new WaitForSeconds(seconds); if (destIsStation) { dest.RemoveOutputSlotLocks(((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject); } else { dest.RemoveSlotLocks(((NetworkBehaviour)((Behaviour)__instance).Npc).NetworkObject); } ItemInstance firstIdenticalItem = ((Behaviour)__instance).Npc.Inventory.GetFirstIdenticalItem(__instance.itemToRetrieveTemplate, (ItemFilter)null); if (firstIdenticalItem != null && __instance.grabbedAmount > 0) { ItemInstance copy = firstIdenticalItem.GetCopy(__instance.grabbedAmount); if (destIsStation) { if (dest.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount) { dest.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc); } else { Console.LogWarning((object)"Destination does not have enough capacity for item! Attempting to return item to source.", (Object)null); if (__instance.assignedRoute.Source.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount) { __instance.assignedRoute.Source.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc); } else { Console.LogError((object)"Source does not have enough capacity for item! Item will be lost.", (Object)null); } } } else if (dest.GetInputCapacityForItem(copy, ((Behaviour)__instance).Npc, true) >= __instance.grabbedAmount) { dest.InsertItemIntoInput(copy, ((Behaviour)__instance).Npc); } else { Console.LogWarning((object)"Destination does not have enough capacity for item! Attempting to return item to source.", (Object)null); if (__instance.assignedRoute.Source.GetOutputCapacityForItem(copy, ((Behaviour)__instance).Npc) >= __instance.grabbedAmount) { __instance.assignedRoute.Source.InsertItemIntoOutput(copy, ((Behaviour)__instance).Npc); } else { Console.LogError((object)"Source does not have enough capacity for item! Item will be lost.", (Object)null); } } ((BaseItemInstance)firstIdenticalItem).ChangeQuantity(-__instance.grabbedAmount); } else { Console.LogWarning((object)"Could not find carried item to place!", (Object)null); } yield return (object)new WaitForSeconds(0.5f); __instance.placingRoutine = null; __instance.currentState = (EState)0; ((Behaviour)__instance).Disable_Networked((NetworkConnection)null); object coro = customPlaceRunning[__instance]; customPlaceRunning.Remove(__instance); MelonCoroutines.Stop(coro); } } } [HarmonyPatch("StopCurrentActivity")] [HarmonyPrefix] private static bool StopCurrentActivity(MoveItemBehaviour __instance) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 EState currentState = __instance.currentState; EState val = currentState; if ((int)val != 2) { if ((int)val == 4) { if (customPlaceRunning.TryGetValue(__instance, out object value)) { MelonCoroutines.Stop(value); customPlaceRunning.Remove(__instance); return false; } return true; } return true; } if (customGrabRunning.TryGetValue(__instance, out object value2)) { MelonCoroutines.Stop(value2); customGrabRunning.Remove(__instance); return false; } return true; } [HarmonyPatch("OnActiveTick")] [HarmonyPrefix] private static bool OnActiveTick(MoveItemBehaviour __instance) { //IL_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)Unsafe.As(ref __instance.currentState)/*cast due to .constrained prefix*/).ToString()), (Object)null); Console.Log((object)("Moving: " + ((Behaviour)__instance).Npc.Movement.IsMoving), (Object)null); } if ((int)__instance.currentState > 0) { return false; } if (((Behaviour)__instance).Npc.Inventory.GetIdenticalItemAmount(__instance.itemToRetrieveTemplate) > 0 && __instance.grabbedAmount > 0) { if (__instance.IsAtDestination()) { __instance.PlaceItem(); } else { __instance.WalkToDestination(); } } else if (__instance.skipPickup) { __instance.TakeItem(); __instance.skipPickup = false; } else if (__instance.IsAtSource()) { __instance.GrabItem(); } else { __instance.WalkToSource(); } return false; } [HarmonyPatch("StartTransit")] [HarmonyPrefix] private static bool StartTransit(MoveItemBehaviour __instance) { //IL_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(destination, out result) && (Object)(object)result != (Object)null; ITransitEntity source = __instance.assignedRoute.Source; PackagingStation result2; bool flag2 = Utils.Is2(source, out result2) && (Object)(object)result2 != (Object)null; if (!flag && !flag2) { return true; } object[] obj = new object[4] { __instance.assignedRoute.Source.Name, __instance.assignedRoute.Destination.Name, null, null }; ItemInstance itemToRetrieveTemplate = __instance.itemToRetrieveTemplate; obj[2] = ((itemToRetrieveTemplate != null) ? ((BaseItemInstance)itemToRetrieveTemplate).ID : null); ItemInstance itemToRetrieveTemplate2 = __instance.itemToRetrieveTemplate; obj[3] = ((itemToRetrieveTemplate2 != null) ? new int?(((BaseItemInstance)itemToRetrieveTemplate2).Quantity) : ((int?)null)); Console.Log((object)string.Format("{0} -> {1} ({2}x{3})", obj), (Object)null); if (!InstanceFinder.IsServer) { return false; } if (((Behaviour)__instance).Npc.Inventory.GetIdenticalItemAmount(__instance.itemToRetrieveTemplate) == 0) { ItemInstance itemToRetrieveTemplate3 = __instance.itemToRetrieveTemplate; if (((itemToRetrieveTemplate3 != null) ? ((BaseItemInstance)itemToRetrieveTemplate3).ID : null) == null) { return false; } string text = default(string); if (!__instance.IsTransitRouteValid(__instance.assignedRoute, ((BaseItemInstance)__instance.itemToRetrieveTemplate).ID, ref text)) { 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(assignedStation, out result) && (Object)(object)result != (Object)null && UnpackageSave.Instance.TryGetValue(((BuildableItem)result).GUID, out value) && value) { List inputSlots = result.InputSlots; if (Utils.Is(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(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(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)("[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 UnpackageFields = new Dictionary(); 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 configs) { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //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_028e: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Expected O, but got Unknown //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03dd: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Expected O, but got Unknown //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_046a: Unknown result type (might be due to invalid IL or missing references) //IL_04f7: Unknown result type (might be due to invalid IL or missing references) //IL_04f0: Unknown result type (might be due to invalid IL or missing references) //IL_05dc: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05f9: Unknown result type (might be due to invalid IL or missing references) //IL_05fe: 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(config, out PackagingStationConfiguration result) || result == null) { continue; } val = result; break; } if ((Object)(object)((val != null) ? val.Station : null) == (Object)null) { return; } Guid stationGuid = Guid.Parse(((BuildableItem)val.Station).GUID.ToString()); if (!PackagingStationConfigPatches.UnpackageFields.TryGetValue(stationGuid, out StringField _)) { PackagingStationConfigPatches.InitializeField(val, val.Station); } Transform parent = ((Component)__instance.DestinationUI).transform.parent; GameObject val2 = new GameObject("UnpackageToggle"); val2.transform.SetParent(parent, false); RectTransform val3 = val2.AddComponent(); RectTransform component = ((Component)__instance.DestinationUI).GetComponent(); TextMeshProUGUI fieldLabel = __instance.DestinationUI.FieldLabel; Transform val4 = ((component != null) ? ((Transform)component).Find("Selection") : null); Image val5 = ((val4 != null) ? ((Component)val4).GetComponent() : null); if ((Object)(object)component == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)fieldLabel == (Object)null) { MelonLogger.Error("Failed to find necessary UI components for unpackage toggle"); return; } val3.sizeDelta = new Vector2(400f, 50f); val2.transform.localPosition = ((Transform)component).localPosition + new Vector3(0f, -120f, 0f); GameObject val6 = new GameObject("Title"); val6.transform.SetParent(val2.transform, false); RectTransform val7 = val6.AddComponent(); val7.anchorMin = new Vector2(0f, 0.5f); val7.anchorMax = new Vector2(0f, 0.5f); val7.pivot = new Vector2(0f, 0.5f); val7.anchoredPosition = new Vector2(0f, 0f); val7.sizeDelta = new Vector2(200f, 30f); TextMeshProUGUI val8 = val6.AddComponent(); ((TMP_Text)val8).fontSize = ((TMP_Text)fieldLabel).fontSize; ((TMP_Text)val8).alignment = ((TMP_Text)fieldLabel).alignment; ((TMP_Text)val8).text = "Set Unpackage"; ((Graphic)val8).color = ((Graphic)fieldLabel).color; ((TMP_Text)val8).font = ((TMP_Text)fieldLabel).font; GameObject val9 = new GameObject("Value"); RectTransform val10 = val9.AddComponent(); val9.transform.SetParent(val2.transform, false); val10.anchorMin = new Vector2(1f, 0.5f); val10.anchorMax = new Vector2(1f, 0.5f); val10.pivot = new Vector2(1f, 0.5f); val10.anchoredPosition = Vector2.zero; val10.sizeDelta = new Vector2(80f, 30f); Image val11 = val9.AddComponent(); val11.sprite = val5.sprite; val11.overrideSprite = val5.overrideSprite; val11.type = val5.type; ((Graphic)val11).material = ((Graphic)val5).material; ((Graphic)val11).color = ((Graphic)val5).color; ((Graphic)val11).raycastTarget = ((Graphic)val5).raycastTarget; val11.preserveAspect = val5.preserveAspect; val11.pixelsPerUnitMultiplier = val5.pixelsPerUnitMultiplier; GameObject val12 = new GameObject("Text"); val12.transform.SetParent(val9.transform, false); RectTransform val13 = val12.AddComponent(); val13.anchorMin = new Vector2(1f, 0.5f); val13.anchorMax = new Vector2(1f, 0.5f); val13.pivot = new Vector2(1f, 0.5f); val13.anchoredPosition = new Vector2(0f, 0f); val13.sizeDelta = new Vector2(80f, 30f); TextMeshProUGUI valueTmpro = val12.AddComponent(); ((TMP_Text)valueTmpro).fontSize = 24f; ((TMP_Text)valueTmpro).alignment = (TextAlignmentOptions)514; ((TMP_Text)valueTmpro).font = ((TMP_Text)fieldLabel).font; UnpackageSave.Instance.TryGetValue(stationGuid, out var value2); ((TMP_Text)valueTmpro).text = (value2 ? "On" : "Off"); ((Graphic)valueTmpro).color = (value2 ? Color.green : Color.gray); Button val14 = val9.AddComponent