using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ValheimChestSort")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ValheimChestSort")] [assembly: AssemblyTitle("ValheimChestSort")] [assembly: AssemblyVersion("1.0.0.0")] namespace ValheimChestSort; [BepInPlugin("SuperVikingDepartment.ValheimChestSort", "ValheimChestSort", "1.0.0")] public class ChestSortPlugin : BaseUnityPlugin { public const string PluginGuid = "SuperVikingDepartment.ValheimChestSort"; public const string PluginName = "ValheimChestSort"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; internal static ConfigEntry SortKeyName; internal static ConfigEntry SortModeName; internal static ConfigEntry MergeStacks; internal static ConfigEntry AddButton; internal static ConfigEntry ButtonLabel; internal static ConfigEntry DebugLogging; internal static KeyCode SortKey = (KeyCode)114; private static readonly FieldInfo FItems = AccessTools.Field(typeof(Inventory), "m_inventory"); private static readonly MethodInfo MChanged = AccessTools.Method(typeof(Inventory), "Changed", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null); private static readonly FieldInfo FCurrentContainer = AccessTools.Field(typeof(InventoryGui), "m_currentContainer"); private static readonly FieldInfo FDragItem = AccessTools.Field(typeof(InventoryGui), "m_dragItem"); private static GameObject _sortButtonGo; private static TMP_Text _sortLabel; private static readonly Dictionary CategoryRank = new Dictionary { { (ItemType)1, 10 }, { (ItemType)2, 20 }, { (ItemType)9, 30 }, { (ItemType)23, 31 }, { (ItemType)3, 40 }, { (ItemType)14, 41 }, { (ItemType)22, 42 }, { (ItemType)4, 43 }, { (ItemType)20, 44 }, { (ItemType)5, 50 }, { (ItemType)15, 51 }, { (ItemType)6, 60 }, { (ItemType)7, 61 }, { (ItemType)11, 62 }, { (ItemType)12, 63 }, { (ItemType)17, 64 }, { (ItemType)18, 70 }, { (ItemType)19, 71 }, { (ItemType)24, 72 }, { (ItemType)21, 73 }, { (ItemType)13, 74 }, { (ItemType)10, 75 }, { (ItemType)16, 80 }, { (ItemType)0, 90 } }; private void Awake() { //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; SortKeyName = ((BaseUnityPlugin)this).Config.Bind("General", "SortKey", "R", "整理当前打开箱子的快捷键(按钮之外的备用入口)。填 KeyCode 名称,如 R / T / B / LeftAlt / Mouse3。改完需重启游戏。"); SortModeName = ((BaseUnityPlugin)this).Config.Bind("General", "SortMode", "Category", "排序方式:Category = 先按类别(材料/消耗品/武器/护甲/工具…)再按名称;Name = 直接按名称。"); MergeStacks = ((BaseUnityPlugin)this).Config.Bind("General", "MergeStacks", true, "整理时是否合并同种物品的零散堆叠(补满已有堆叠),默认开启。"); AddButton = ((BaseUnityPlugin)this).Config.Bind("General", "AddButton", true, "是否在箱子界面「物品堆叠」按钮左边添加一个「整理」按钮。关闭后只能靠快捷键整理。改完需重启游戏。"); ButtonLabel = ((BaseUnityPlugin)this).Config.Bind("General", "ButtonLabel", "", "「整理」按钮上显示的文字。留空 = 自动:中文界面显示「整理」,其他语言显示「Sort」。"); DebugLogging = ((BaseUnityPlugin)this).Config.Bind("Diagnostics", "DebugLogging", false, "输出整理细节日志,用于排查问题。正常游玩建议关闭。"); SortKey = ParseKey(SortKeyName.Value, (KeyCode)114); LogReflectionStatus(); Localization.OnLanguageChange = (Action)Delegate.Combine(Localization.OnLanguageChange, new Action(ApplyLabel)); Log.LogInfo((object)"ValheimChestSort loaded (v1.0.0)"); Log.LogInfo((object)($"[ChestSort] 快捷键 = {SortKey},排序方式 = {SortModeName.Value}," + $"合并堆叠 = {MergeStacks.Value},界面按钮 = {AddButton.Value}")); } private static KeyCode ParseKey(string raw, KeyCode fallback) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(raw) && Enum.TryParse(raw.Trim(), ignoreCase: true, out KeyCode result)) { return result; } ManualLogSource log = Log; if (log != null) { log.LogWarning((object)$"[ChestSort] 无法识别按键 \"{raw}\",回退为 {fallback}"); } return fallback; } private static void LogReflectionStatus() { if (FItems == null) { Log.LogError((object)"[ChestSort][diag] Inventory.m_inventory 未找到!"); } if (MChanged == null) { Log.LogError((object)"[ChestSort][diag] Inventory.Changed 未找到!"); } if (FCurrentContainer == null) { Log.LogError((object)"[ChestSort][diag] InventoryGui.m_currentContainer 未找到!"); } if (FDragItem == null) { Log.LogWarning((object)"[ChestSort][diag] InventoryGui.m_dragItem 未找到(拖拽保护将失效)"); } } private void OnDestroy() { Localization.OnLanguageChange = (Action)Delegate.Remove(Localization.OnLanguageChange, new Action(ApplyLabel)); } private void Update() { //IL_0089: Unknown result type (might be due to invalid IL or missing references) InventoryGui instance = InventoryGui.instance; if (!((Object)(object)instance == (Object)null)) { if (AddButton.Value && (Object)(object)_sortButtonGo == (Object)null) { EnsureSortButton(instance); } if ((Object)(object)_sortButtonGo != (Object)null && _sortButtonGo.activeSelf != instance.IsContainerOpen()) { _sortButtonGo.SetActive(instance.IsContainerOpen()); } if (instance.IsContainerOpen() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && ZInput.GetKeyDown(SortKey, false)) { TrySortOpenedContainer(); } } } private static void EnsureSortButton(InventoryGui gui) { //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Expected O, but got Unknown if ((Object)(object)gui.m_stackAllButton == (Object)null) { return; } Transform transform = ((Component)gui.m_stackAllButton).transform; Transform parent = transform.parent; if ((Object)(object)parent == (Object)null) { return; } Transform val = parent.Find("ChestSortButton"); if ((Object)(object)val != (Object)null) { _sortButtonGo = ((Component)val).gameObject; _sortLabel = ((Component)val).GetComponentInChildren(true) ?? ((Component)transform).GetComponentInChildren(true); ApplyLabel(); return; } GameObject val2; try { val2 = Object.Instantiate(((Component)transform).gameObject, parent); } catch (Exception ex) { Log.LogError((object)("[ChestSort] 创建界面按钮失败:" + ex)); return; } ((Object)val2).name = "ChestSortButton"; val2.transform.SetSiblingIndex(transform.GetSiblingIndex()); Button component = val2.GetComponent