using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ExpeditionReady_ChestSort")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ExpeditionReady_ChestSort")] [assembly: AssemblyCopyright("Copyright © Goldenrevolver 2022, modifications © LEGIOmods 2026")] [assembly: AssemblyTrademark("")] [assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially created with the assistance of Generative AI for code changes, localization, documentation, and package preparation.")] [assembly: AssemblyMetadata("AI_Model_Vendor", "OpenAI")] [assembly: AssemblyMetadata("AI_Agent", "OpenAI Codex")] [assembly: ComVisible(false)] [assembly: Guid("beeb50d8-ebd2-4791-9866-4bbf2d810422")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace ExpeditionReadyChestSort; [BepInPlugin("legiomods.expeditionreadychestsort", "ExpeditionReady_ChestSort", "1.0.0")] public class ExpeditionReadyChestSortPlugin : BaseUnityPlugin { public const string GUID = "legiomods.expeditionreadychestsort"; public const string NAME = "ExpeditionReady_ChestSort"; public const string VERSION = "1.0.0"; private static readonly FieldInfo HumanoidInventoryField = AccessTools.Field(typeof(Humanoid), "m_inventory"); private static readonly FieldInfo InventoryItemsField = AccessTools.Field(typeof(Inventory), "m_inventory"); private static readonly FieldInfo ContainerInventoryField = AccessTools.Field(typeof(Container), "m_inventory"); private static readonly FieldInfo CurrentContainerField = AccessTools.Field(typeof(InventoryGui), "m_currentContainer"); private static readonly FieldInfo PlayerGridField = AccessTools.Field(typeof(InventoryGui), "m_playerGrid"); private static readonly MethodInfo InventoryChangedMethod = AccessTools.Method(typeof(Inventory), "Changed", (Type[])null, (Type[])null); private ConfigEntry modEnabled; private ConfigEntry nearbyRange; private ConfigEntry includeHotbar; private ConfigEntry mergeStacksBeforeSort; private Button restockButton; private Button readyButton; private Button sortButton; private void Awake() { modEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Enable ExpeditionReady_ChestSort."); nearbyRange = ((BaseUnityPlugin)this).Config.Bind("Restock", "NearbyChestRange", 15f, "Range in meters for nearby chest restock."); includeHotbar = ((BaseUnityPlugin)this).Config.Bind("Restock", "IncludeHotbar", true, "Restock stacks in the hotbar."); mergeStacksBeforeSort = ((BaseUnityPlugin)this).Config.Bind("Sort", "MergeStacksBeforeSort", true, "Merge equal item stacks before sorting a chest."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ExpeditionReady_ChestSort 1.0.0 loaded by BepInEx. GUID=legiomods.expeditionreadychestsort"); } private void Update() { if (modEnabled.Value && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)InventoryGui.instance == (Object)null) && InventoryGui.IsVisible()) { EnsureButtons(); } } private void EnsureButtons() { EnsureRestockButton(); EnsurePortalButton(); EnsureSortButton(); if ((Object)(object)sortButton != (Object)null) { ((Component)sortButton).gameObject.SetActive((Object)(object)GetCurrentContainer() != (Object)null); } } private void EnsureRestockButton() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown Button takeAllButton = InventoryGui.instance.m_takeAllButton; if ((Object)(object)takeAllButton == (Object)null) { return; } if ((Object)(object)restockButton == (Object)null) { restockButton = CreateButton(takeAllButton, "ExpeditionReadyChestSort_RestockButton", Text("Restock", "Auffüllen"), (UnityAction)delegate { Restock(Player.m_localPlayer); }); } SetButtonLabel(restockButton, Text("Restock", "Auffüllen")); ((Component)restockButton).gameObject.SetActive(true); PositionPlayerSideButton(restockButton, takeAllButton, 0); } private void EnsurePortalButton() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown Button takeAllButton = InventoryGui.instance.m_takeAllButton; if ((Object)(object)takeAllButton == (Object)null) { return; } if ((Object)(object)readyButton == (Object)null) { readyButton = CreateButton(takeAllButton, "ExpeditionReadyChestSort_PortalButton", Text("Portal ✓", "Portal ✓"), (UnityAction)delegate { PortalAuffuellen(Player.m_localPlayer); }); } SetButtonLabel(readyButton, Text("Portal ✓", "Portal ✓")); ((Component)readyButton).gameObject.SetActive(true); PositionPlayerSideButton(readyButton, takeAllButton, 1); } private void EnsureSortButton() { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown InventoryGui instance = InventoryGui.instance; Button takeAllButton = instance.m_takeAllButton; RectTransform stackAllButtonRectTransform = GetStackAllButtonRectTransform(instance); if (!((Object)(object)takeAllButton == (Object)null)) { if ((Object)(object)sortButton == (Object)null) { sortButton = CreateButton(takeAllButton, "ExpeditionReadyChestSort_SortButton", Text("Sort", "Sortieren"), new UnityAction(SortOpenChest)); } SetButtonLabel(sortButton, Text("Sort", "Sortieren")); PositionSortButton(sortButton, stackAllButtonRectTransform ?? ((Component)takeAllButton).GetComponent()); } } private static Button CreateButton(Button template, string objectName, string label, UnityAction onClick) { GameObject obj = Object.Instantiate(((Component)template).gameObject, ((Component)template).transform.parent); ((Object)obj).name = objectName; obj.SetActive(true); Button component = obj.GetComponent