Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SmartChest v1.0.0
plugins/SmartChest.dll
Decompiled 7 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; 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 BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using SmartChest.Catalog; using SmartChest.Chests; using SmartChest.Compat; using SmartChest.Storing; using SmartChest.UI; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("SmartChest")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+2f2c5105a5c93a6324ae1a4836ed76dd5a264343")] [assembly: AssemblyProduct("SmartChest")] [assembly: AssemblyTitle("SmartChest")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 SmartChest { [BepInPlugin("sashalorenc.SmartChest", "Smart Chest", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string ModGuid = "sashalorenc.SmartChest"; public const string ModName = "Smart Chest"; public const string ModVersion = "1.0.0"; public const string QuickStackStoreGuid = "goldenrevolver.quick_stack_store"; public static ConfigEntry<float> StoreRadius; public static ConfigEntry<KeyboardShortcut> StoreKey; public static ConfigEntry<KeyboardShortcut> EditItemKey; public static ConfigEntry<bool> SkipHotbar; public static ConfigEntry<bool> ShowCategoriesInTooltip; public static ConfigEntry<bool> QuickStackIntegration; public static ConfigEntry<bool> AutoStoreIntegration; public static ConfigEntry<ButtonPlacement> ButtonsPlacement; public static ConfigEntry<float> ButtonsOffsetX; public static ConfigEntry<float> ButtonsOffsetY; public static ConfigEntry<float> ButtonsWidth; public static ConfigEntry<ButtonPlacement> InventoryButtonsPlacement; public static ConfigEntry<float> InventoryButtonsOffsetX; public static ConfigEntry<float> InventoryButtonsOffsetY; public static ConfigEntry<float> SearchRadius; public static ConfigEntry<float> SearchDuration; public static ConfigEntry<bool> FullChestAlert; private Harmony _harmony; public static Plugin Instance { get; private set; } public static ManualLogSource Log { get; private set; } private void Awake() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; BindConfig(); CatalogManager.Load(); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new DumpCommand()); _harmony = new Harmony("sashalorenc.SmartChest"); _harmony.PatchAll(typeof(Plugin).Assembly); HoverTracker.Init(_harmony); QuickStackStoreCompat.TryInit(_harmony); AzuAutoStoreCompat.TryInit(_harmony); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Smart Chest 1.0.0 chargé."); } private void Start() { ModCompat.LogDetected(); } private void Update() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Player.m_localPlayer == (Object)null)) { KeyboardShortcut value = StoreKey.Value; if (((KeyboardShortcut)(ref value)).IsDown() && !IsTypingSomewhere()) { StoreService.StoreNearby(Player.m_localPlayer); } } } private static bool IsTypingSomewhere() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Invalid comparison between Unknown and I4 if (UiKit.IsTyping) { return true; } if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return true; } if (Console.IsVisible() || TextInput.IsVisible() || Menu.IsVisible()) { return true; } if ((Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2) { return true; } return false; } private void BindConfig() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Expected O, but got Unknown //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Expected O, but got Unknown //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Expected O, but got Unknown StoreRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Rangement", "Rayon", 10f, new ConfigDescription("Distance maximale (m) des coffres utilisés pour le rangement.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>())); StoreKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Touches", "RangerParCategorie", new KeyboardShortcut((KeyCode)108, Array.Empty<KeyCode>()), "Range l'inventaire dans les coffres catégorisés à portée."); EditItemKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Touches", "EditerObjet", new KeyboardShortcut((KeyCode)107, Array.Empty<KeyCode>()), "Sur un objet survolé dans l'inventaire : modifier ses catégories."); ShowCategoriesInTooltip = ((BaseUnityPlugin)this).Config.Bind<bool>("Affichage", "CategoriesDansInfobulle", true, "Affiche les catégories d'un objet dans son infobulle."); ButtonsPlacement = ((BaseUnityPlugin)this).Config.Bind<ButtonPlacement>("Interface", "PositionBoutons", ButtonPlacement.Dessous, "Où placer les boutons Catégories / Ranger ici autour du coffre ouvert : Dessus, Dessous, Gauche, Droite."); ButtonsOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "DecalageX", 0f, "Décalage horizontal des boutons en pixels (positif = vers la droite)."); ButtonsOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "DecalageY", 0f, "Décalage vertical des boutons en pixels (positif = vers le haut)."); ButtonsWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "LargeurBoutons", 150f, new ConfigDescription("Largeur de chaque bouton en pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(80f, 300f), Array.Empty<object>())); ButtonsPlacement.SettingChanged += delegate { ChestPanel.ResetButtons(); }; ButtonsOffsetX.SettingChanged += delegate { ChestPanel.ResetButtons(); }; ButtonsOffsetY.SettingChanged += delegate { ChestPanel.ResetButtons(); }; ButtonsWidth.SettingChanged += delegate { ChestPanel.ResetButtons(); InventoryButtons.Reset(); }; InventoryButtonsPlacement = ((BaseUnityPlugin)this).Config.Bind<ButtonPlacement>("Interface", "PositionBoutonsInventaire", ButtonPlacement.Dessus, "Où placer les boutons Ranger par catégorie / Rechercher autour de l'inventaire du joueur : Dessus, Dessous, Gauche, Droite."); InventoryButtonsOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "InventaireDecalageX", 0f, "Décalage horizontal des boutons de l'inventaire en pixels (positif = vers la droite)."); InventoryButtonsOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Interface", "InventaireDecalageY", 0f, "Décalage vertical des boutons de l'inventaire en pixels (positif = vers le haut)."); InventoryButtonsPlacement.SettingChanged += delegate { InventoryButtons.Reset(); }; InventoryButtonsOffsetX.SettingChanged += delegate { InventoryButtons.Reset(); }; InventoryButtonsOffsetY.SettingChanged += delegate { InventoryButtons.Reset(); }; SearchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Recherche", "Rayon", 30f, new ConfigDescription("Distance maximale (m) des coffres fouillés par la recherche.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>())); SearchDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Recherche", "Duree", 15f, new ConfigDescription("Durée (secondes) pendant laquelle les coffres trouvés brillent.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 60f), Array.Empty<object>())); FullChestAlert = ((BaseUnityPlugin)this).Config.Bind<bool>("Rangement", "AlerteCoffrePlein", true, "Prévient (en haut à gauche) quand un coffre catégorisé est plein et que des objets de sa catégorie n'ont pas pu être rangés."); QuickStackIntegration = ((BaseUnityPlugin)this).Config.Bind<bool>("Compatibilite", "QuickStackStore", true, "Avec Quick Stack Store Sort Trash Restock : le stockage rapide envoie aussi les objets vers les coffres de leur catégorie, et Tout stocker respecte les coffres en mode strict."); AutoStoreIntegration = ((BaseUnityPlugin)this).Config.Bind<bool>("Compatibilite", "AzuAutoStore", true, "Avec AzuAutoStore : les coffres catégorisés reçoivent les objets de leurs catégories, et en mode strict refusent les autres."); SkipHotbar = ((BaseUnityPlugin)this).Config.Bind<bool>("Rangement", "IgnorerBarreRaccourcis", true, "Ne jamais ranger les objets de la barre de raccourcis (1 à 8)."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace SmartChest.UI { public enum ButtonPlacement { Dessus, Dessous, Gauche, Droite } public static class CategoryManagerPanel { [CompilerGenerated] private static class <>O { public static UnityAction <0>__Back; } private const float RowHeight = 38f; private const float ColWidth = 380f; private const float PanelWidth = 800f; private static GameObject _panel; private static Container _returnTo; private static string _pendingDelete; public static bool IsOpen => (Object)(object)_panel != (Object)null; public static void Open(Container returnTo) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Expected O, but got Unknown //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Expected O, but got Unknown Panels.CloseAll(); _returnTo = returnTo; List<Category> list = new List<Category>(CatalogManager.Categories); int num = (list.Count + 1) / 2; float height = 80f + (float)num * 38f + 70f; _panel = UiKit.CreatePanel(800f, height); UiKit.AddText(_panel.transform, Localization.instance.Localize("$smartchest_manage_title"), 20f, 15f, 760f, 30f, 22, GUIManager.Instance.ValheimOrange); Color color = default(Color); for (int i = 0; i < list.Count; i++) { Category category = list[i]; string id = category.Id; float num2 = 20f + (float)(i % 2) * 380f; float y = 60f + (float)(i / 2) * 38f; Image component = UiKit.AddButton(_panel.transform, "", num2, y, 30f, 30f, (UnityAction)delegate { Category category2 = CatalogManager.GetCategory(id); if (category2 != null) { CatalogManager.UpdateCategory(id, null, UiKit.NextColor(category2.Color)); Refresh(); } }).GetComponent<Image>(); if ((Object)(object)component != (Object)null && ColorUtility.TryParseHtmlString("#" + category.Color, ref color)) { ((Graphic)component).color = color; } InputField val = UiKit.AddInput(_panel.transform, category.DisplayName, "", num2 + 36f, y, 210f, 30f); string original = category.DisplayName; ((UnityEvent<string>)(object)val.onEndEdit).AddListener((UnityAction<string>)delegate(string text) { string text2 = (text ?? "").Trim(); if (text2.Length != 0 && !(text2 == original)) { CatalogManager.UpdateCategory(id, text2, null); } }); if (category.Hidden) { Text textComponent = val.textComponent; if ((Object)(object)textComponent != (Object)null) { ((Graphic)textComponent).color = new Color(0.6f, 0.6f, 0.6f); } } UiKit.AddButton(label: (!category.IsDefault) ? ((_pendingDelete == id) ? "$smartchest_confirm" : "$smartchest_delete") : (category.Hidden ? "$smartchest_show" : "$smartchest_hide"), parent: _panel.transform, x: num2 + 252f, y: y, width: 110f, height: 30f, onClick: (UnityAction)delegate { Category category2 = CatalogManager.GetCategory(id); if (category2 != null) { if (category2.IsDefault) { CatalogManager.SetHidden(id, !category2.Hidden); } else if (_pendingDelete == id) { CatalogManager.RemoveCategory(id); _pendingDelete = null; } else { _pendingDelete = id; } Refresh(); } }); } float y2 = 60f + (float)num * 38f + 15f; Transform transform = _panel.transform; object obj = <>O.<0>__Back; if (obj == null) { UnityAction val2 = Back; <>O.<0>__Back = val2; obj = (object)val2; } UiKit.AddButton(transform, "$smartchest_back", 630f, y2, 150f, 34f, (UnityAction)obj); } private static void Refresh() { Container returnTo = _returnTo; string pendingDelete = _pendingDelete; Open(returnTo); _pendingDelete = pendingDelete; } private static void Back() { Container returnTo = _returnTo; _pendingDelete = null; Close(); if ((Object)(object)returnTo != (Object)null && (Object)(object)InventoryGui.instance != (Object)null && (Object)(object)InventoryGui.instance.m_currentContainer == (Object)(object)returnTo) { ChestPanel.Open(returnTo); } } public static void Close() { if ((Object)(object)_panel != (Object)null) { Object.Destroy((Object)(object)_panel); } _panel = null; _returnTo = null; } } public class ChestHighlight : MonoBehaviour { private WearNTear _wnt; private float _until; private GameObject _labelGo; private TextMesh _label; private Bounds _bounds; private bool _hasBounds; public static void Flash(Container container, float seconds, string text) { if (!((Object)(object)container == (Object)null)) { ChestHighlight chestHighlight = ((Component)container).gameObject.GetComponent<ChestHighlight>(); if ((Object)(object)chestHighlight == (Object)null) { chestHighlight = ((Component)container).gameObject.AddComponent<ChestHighlight>(); } chestHighlight._until = Time.time + seconds; chestHighlight.SetText(text); } } public static void ClearAll() { ChestHighlight[] array = Object.FindObjectsOfType<ChestHighlight>(); for (int i = 0; i < array.Length; i++) { array[i]._until = 0f; } } private void Awake() { _wnt = ((Component)this).GetComponent<WearNTear>(); if ((Object)(object)_wnt == (Object)null) { _wnt = ((Component)this).GetComponentInParent<WearNTear>(); } ComputeBounds(); } private void ComputeBounds() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { if (val is MeshRenderer || val is SkinnedMeshRenderer) { if (!_hasBounds) { _bounds = val.bounds; _hasBounds = true; } else { ((Bounds)(ref _bounds)).Encapsulate(val.bounds); } } } } private void SetText(string text) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(text)) { return; } if ((Object)(object)_labelGo == (Object)null) { _labelGo = new GameObject("SmartChestSearchLabel"); _labelGo.transform.SetParent(((Component)this).transform, false); _label = _labelGo.AddComponent<TextMesh>(); _label.richText = true; _label.fontSize = 40; _label.characterSize = 0.03f; _label.anchor = (TextAnchor)4; _label.alignment = (TextAlignment)1; _label.color = new Color(1f, 1f, 0.4f); Font val = ((GUIManager.Instance != null) ? GUIManager.Instance.AveriaSerifBold : null); if ((Object)(object)val != (Object)null) { _label.font = val; MeshRenderer component = _labelGo.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null) { ((Renderer)component).material = val.material; } } } _label.text = text; } private void Update() { if (Time.time > _until) { Object.Destroy((Object)(object)this); } else if ((Object)(object)_wnt != (Object)null) { _wnt.Highlight(); } } private void LateUpdate() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //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) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_labelGo == (Object)null) && !((Object)(object)GameCamera.instance == (Object)null)) { Transform transform = ((Component)GameCamera.instance).transform; Vector3 val = (_hasBounds ? ((Bounds)(ref _bounds)).center : (((Component)this).transform.position + Vector3.up * 0.5f)); Vector3 val2 = transform.position - val; val2.y = 0f; if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f) { val2 = -transform.forward; } Vector3 normalized = ((Vector3)(ref val2)).normalized; float num = 0.5f; float num2 = default(float); if (_hasBounds && ((Bounds)(ref _bounds)).IntersectRay(new Ray(val + normalized * 10f, -normalized), ref num2)) { num = 10f - num2; } _labelGo.transform.position = val + normalized * (num + 0.05f); _labelGo.transform.rotation = transform.rotation; } } private void OnDestroy() { if ((Object)(object)_labelGo != (Object)null) { Object.Destroy((Object)(object)_labelGo); } } } [HarmonyPatch(typeof(Container), "GetHoverText")] internal static class ChestHoverPatch { private static void Postfix(Container __instance, ref string __result) { if (__result != null) { string text = ChestDescription.Describe(__instance, extras: true); if (text.Length > 0) { __result = __result + "\n" + text; } } } } public static class ChestPanel { [CompilerGenerated] private static class <>O { public static UnityAction <0>__Close; public static UnityAction <1>__AddCategoryFromInput; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__11_0; public static UnityAction <>9__11_1; public static UnityAction <>9__11_2; public static Action<string, bool> <>9__12_0; public static UnityAction <>9__12_2; public static UnityAction <>9__12_3; internal void <CreateButtons>b__11_0() { if (IsOpen) { Close(); } else { Open(InventoryGui.instance.m_currentContainer); } } internal void <CreateButtons>b__11_1() { StoreService.StoreInto(Player.m_localPlayer, InventoryGui.instance.m_currentContainer); } internal void <CreateButtons>b__11_2() { SortService.SortChest(Player.m_localPlayer, InventoryGui.instance.m_currentContainer); } internal void <Open>b__12_0(string id, bool on) { ChestCategories.Toggle(_panelFor, id, on); } internal void <Open>b__12_2() { Container panelFor = _panelFor; Close(); CategoryManagerPanel.Open(panelFor); } internal void <Open>b__12_3() { } } private const float PanelWidth = 590f; private static GameObject _buttons; private static GameObject _panel; private static Container _panelFor; private static InputField _nameInput; private static Container _checkedContainer; private static bool _checkedEligible; public static bool IsOpen => (Object)(object)_panel != (Object)null; internal static void OnInventoryUpdate(InventoryGui gui) { Container val = (gui.IsContainerOpen() ? gui.m_currentContainer : null); if ((Object)(object)val != (Object)(object)_checkedContainer) { _checkedContainer = val; _checkedEligible = (Object)(object)val != (Object)null && ModCompat.IsEligibleChest(val); } bool flag = (Object)(object)val != (Object)null && _checkedEligible; if (flag && (Object)(object)_buttons == (Object)null) { CreateButtons(gui); } if ((Object)(object)_buttons != (Object)null && _buttons.activeSelf != flag) { _buttons.SetActive(flag); } if ((Object)(object)_panel != (Object)null && ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)_panelFor)) { Close(); } } public static void ResetButtons() { if ((Object)(object)_buttons != (Object)null) { Object.Destroy((Object)(object)_buttons); } _buttons = null; } private static void CreateButtons(InventoryGui gui) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown RectTransform container = gui.m_container; ButtonPlacement value = Plugin.ButtonsPlacement.Value; Vector2 offset = new Vector2(Plugin.ButtonsOffsetX.Value, Plugin.ButtonsOffsetY.Value); float value2 = Plugin.ButtonsWidth.Value; string[] labels = new string[3] { "$smartchest_categories", "$smartchest_store_here", "$smartchest_sort" }; UnityAction[] array = new UnityAction[3]; object obj = <>c.<>9__11_0; if (obj == null) { UnityAction val = delegate { if (IsOpen) { Close(); } else { Open(InventoryGui.instance.m_currentContainer); } }; <>c.<>9__11_0 = val; obj = (object)val; } array[0] = (UnityAction)obj; object obj2 = <>c.<>9__11_1; if (obj2 == null) { UnityAction val2 = delegate { StoreService.StoreInto(Player.m_localPlayer, InventoryGui.instance.m_currentContainer); }; <>c.<>9__11_1 = val2; obj2 = (object)val2; } array[1] = (UnityAction)obj2; object obj3 = <>c.<>9__11_2; if (obj3 == null) { UnityAction val3 = delegate { SortService.SortChest(Player.m_localPlayer, InventoryGui.instance.m_currentContainer); }; <>c.<>9__11_2 = val3; obj3 = (object)val3; } array[2] = (UnityAction)obj3; _buttons = UiKit.CreateButtonBar((Transform)(object)container, "SmartChestButtons", value, offset, value2, labels, (UnityAction[])(object)array); } public static void Open(Container container) { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Expected O, but got Unknown //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Expected O, but got Unknown //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Expected O, but got Unknown //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Expected O, but got Unknown Panels.CloseAll(); if ((Object)(object)container == (Object)null) { return; } _panelFor = container; float num = UiKit.CategoryGridHeight(); float height = 70f + num + 200f; _panel = UiKit.CreatePanel(590f, height); UiKit.AddText(_panel.transform, Localization.instance.Localize("$smartchest_categories") + " : " + Localization.instance.Localize(container.m_name), 20f, 15f, 550f, 30f, 22, GUIManager.Instance.ValheimOrange); UiKit.AddCategoryGrid(_panel.transform, 60f, ChestCategories.Get(container), delegate(string id, bool on) { ChestCategories.Toggle(_panelFor, id, on); }); float num2 = 60f + num + 15f; GameObject modeBtn = null; modeBtn = UiKit.AddButton(_panel.transform, ModeLabel(ChestCategories.GetMode(container)), 25f, num2, 260f, 34f, (UnityAction)delegate { ChestMode mode = ((ChestCategories.GetMode(_panelFor) == ChestMode.Strict) ? ChestMode.Overflow : ChestMode.Strict); ChestCategories.SetMode(_panelFor, mode); UiKit.SetButtonText(modeBtn, ModeLabel(mode)); }); Transform transform = _panel.transform; object obj = <>c.<>9__12_2; if (obj == null) { UnityAction val = delegate { Container panelFor = _panelFor; Close(); CategoryManagerPanel.Open(panelFor); }; <>c.<>9__12_2 = val; obj = (object)val; } UiKit.AddButton(transform, "$smartchest_manage", 295f, num2, 140f, 34f, (UnityAction)obj); Transform transform2 = _panel.transform; object obj2 = <>O.<0>__Close; if (obj2 == null) { UnityAction val2 = Close; <>O.<0>__Close = val2; obj2 = (object)val2; } UiKit.AddButton(transform2, "$smartchest_close", 445f, num2, 120f, 34f, (UnityAction)obj2); float num3 = num2 + 48f; Transform transform3 = _panel.transform; string label = PriorityLabel(ChestCategories.GetPriority(container)); object obj3 = <>c.<>9__12_3; if (obj3 == null) { UnityAction val3 = delegate { }; <>c.<>9__12_3 = val3; obj3 = (object)val3; } GameObject prioBtn = UiKit.AddButton(transform3, label, 25f, num3, 260f, 34f, (UnityAction)obj3); ((Selectable)prioBtn.GetComponent<Button>()).interactable = false; UiKit.AddButton(_panel.transform, "-", 295f, num3, 45f, 34f, (UnityAction)delegate { ChangePriority(prioBtn, -1); }); UiKit.AddButton(_panel.transform, "+", 345f, num3, 45f, 34f, (UnityAction)delegate { ChangePriority(prioBtn, 1); }); float y = num3 + 48f; _nameInput = UiKit.AddInput(_panel.transform, "", Localization.instance.Localize("$smartchest_new_category_placeholder"), 25f, y, 330f, 34f); Transform transform4 = _panel.transform; object obj4 = <>O.<1>__AddCategoryFromInput; if (obj4 == null) { UnityAction val4 = AddCategoryFromInput; <>O.<1>__AddCategoryFromInput = val4; obj4 = (object)val4; } UiKit.AddButton(transform4, "$smartchest_new_category", 365f, y, 200f, 34f, (UnityAction)obj4); } public static void Close() { if ((Object)(object)_panel != (Object)null) { Object.Destroy((Object)(object)_panel); } _panel = null; _panelFor = null; _nameInput = null; } private static void AddCategoryFromInput() { if (!((Object)(object)_nameInput == (Object)null) && !((Object)(object)_panelFor == (Object)null)) { string text = _nameInput.text.Trim(); if (text.Length != 0) { string color = UiKit.Palette[CatalogManager.Categories.Count % UiKit.Palette.Length]; Category category = CatalogManager.AddCustomCategory(text, color); ChestCategories.Toggle(_panelFor, category.Id, enabled: true); Open(_panelFor); } } } private static void ChangePriority(GameObject label, int delta) { ChestCategories.SetPriority(_panelFor, ChestCategories.GetPriority(_panelFor) + delta); UiKit.SetButtonText(label, PriorityLabel(ChestCategories.GetPriority(_panelFor))); } private static string PriorityLabel(int prio) { return Localization.instance.Localize("$smartchest_priority") + " : " + prio; } private static string ModeLabel(ChestMode mode) { return Localization.instance.Localize("$smartchest_mode") + " : " + Localization.instance.Localize((mode == ChestMode.Strict) ? "$smartchest_mode_strict" : "$smartchest_mode_overflow"); } } [HarmonyPatch(typeof(InventoryGui), "Update")] internal static class InventoryGuiUpdatePatch { private static bool Prefix() { return !UiKit.IsTyping; } private static void Postfix(InventoryGui __instance) { ChestPanel.OnInventoryUpdate(__instance); InventoryButtons.OnInventoryUpdate(__instance); ItemEditorPanel.OnInventoryUpdate(__instance); } } [HarmonyPatch(typeof(InventoryGui), "Hide")] internal static class InventoryGuiHidePatch { private static void Postfix() { Panels.CloseAll(); } } internal static class HoverTracker { internal static void Init(Harmony harmony) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown try { MethodInfo methodInfo = AccessTools.Method(typeof(UIInputHandler), "OnPointerEnter", new Type[1] { typeof(PointerEventData) }, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(UIInputHandler), "OnPointerExit", new Type[1] { typeof(PointerEventData) }, (Type[])null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(HoverTracker), "EnterPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(HoverTracker), "ExitPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (methodInfo == null || methodInfo2 == null) { Plugin.Log.LogWarning((object)"UIInputHandler.OnPointerEnter/Exit introuvable : la touche K ne pourra pas détecter l'objet survolé."); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Suivi du survol désactivé : " + ex.Message)); } } private static void EnterPostfix(UIInputHandler __instance) { ItemEditorPanel.SetHovered(((Component)__instance).gameObject); } private static void ExitPostfix(UIInputHandler __instance) { ItemEditorPanel.ClearHovered(((Component)__instance).gameObject); } } public static class InventoryButtons { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__1_0; public static UnityAction <>9__1_1; internal void <OnInventoryUpdate>b__1_0() { StoreService.StoreNearby(Player.m_localPlayer); } internal void <OnInventoryUpdate>b__1_1() { if (SearchPanel.IsOpen) { SearchPanel.Close(); } else { SearchPanel.Open(); } } } private static GameObject _bar; internal static void OnInventoryUpdate(InventoryGui gui) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown if ((Object)(object)_bar != (Object)null || (Object)(object)gui.m_player == (Object)null) { return; } RectTransform player = gui.m_player; ButtonPlacement value = Plugin.InventoryButtonsPlacement.Value; Vector2 offset = new Vector2(Plugin.InventoryButtonsOffsetX.Value, Plugin.InventoryButtonsOffsetY.Value); float w = Plugin.ButtonsWidth.Value + 30f; string[] labels = new string[2] { "$smartchest_store_by_category", "$smartchest_search" }; UnityAction[] array = new UnityAction[2]; object obj = <>c.<>9__1_0; if (obj == null) { UnityAction val = delegate { StoreService.StoreNearby(Player.m_localPlayer); }; <>c.<>9__1_0 = val; obj = (object)val; } array[0] = (UnityAction)obj; object obj2 = <>c.<>9__1_1; if (obj2 == null) { UnityAction val2 = delegate { if (SearchPanel.IsOpen) { SearchPanel.Close(); } else { SearchPanel.Open(); } }; <>c.<>9__1_1 = val2; obj2 = (object)val2; } array[1] = (UnityAction)obj2; _bar = UiKit.CreateButtonBar((Transform)(object)player, "SmartChestInventoryButtons", value, offset, w, labels, (UnityAction[])(object)array); } public static void Reset() { if ((Object)(object)_bar != (Object)null) { Object.Destroy((Object)(object)_bar); } _bar = null; } } public static class ItemEditorPanel { [CompilerGenerated] private static class <>O { public static Action<string, bool> <0>__SetCategory; public static UnityAction <1>__Close; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__10_0; internal void <Open>b__10_0() { ItemData item = _item; CatalogManager.ResetItemCategories(item); Open(item); } } private const float PanelWidth = 590f; private static GameObject _panel; private static ItemData _item; private static GameObject _hoveredSlot; public static bool IsOpen => (Object)(object)_panel != (Object)null; internal static void SetHovered(GameObject go) { _hoveredSlot = go; } internal static void ClearHovered(GameObject go) { if ((Object)(object)_hoveredSlot == (Object)(object)go) { _hoveredSlot = null; } } internal static void OnInventoryUpdate(InventoryGui gui) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) if (UiKit.IsTyping) { return; } KeyboardShortcut value = Plugin.EditItemKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { ItemData val = GetHoveredItem(gui.m_playerGrid, "joueur") ?? GetHoveredItem(gui.m_containerGrid, "coffre"); if (val == null) { Plugin.Log.LogInfo((object)("Touche K : aucun objet sous la souris (case survolée : " + (((Object)(object)_hoveredSlot != (Object)null) ? ((Object)_hoveredSlot).name : "aucune") + ").")); return; } Plugin.Log.LogInfo((object)("Touche K : édition de " + CatalogManager.GetPrefabName(val) + ".")); Open(val); } } private static ItemData GetHoveredItem(InventoryGrid grid, string label) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)grid == (Object)null || grid.GetInventory() == null || (Object)(object)_hoveredSlot == (Object)null) { return null; } try { Transform val = _hoveredSlot.transform; while ((Object)(object)val != (Object)null) { Vector2i buttonPos = grid.GetButtonPos(((Component)val).gameObject); if (buttonPos.x >= 0 && buttonPos.y >= 0) { ItemData itemAt = grid.GetInventory().GetItemAt(buttonPos.x, buttonPos.y); Plugin.Log.LogInfo((object)string.Format("Touche K : case ({0},{1}) de l'inventaire {2}, objet : {3}.", buttonPos.x, buttonPos.y, label, (itemAt != null) ? CatalogManager.GetPrefabName(itemAt) : "vide")); return itemAt; } val = val.parent; } } catch (Exception arg) { Plugin.Log.LogWarning((object)$"Touche K : erreur en lisant l'inventaire {label} : {arg}"); } return null; } public static void Open(ItemData item) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Expected O, but got Unknown Panels.CloseAll(); if (item == null) { return; } _item = item; float num = UiKit.CategoryGridHeight(); float height = 110f + num + 70f; _panel = UiKit.CreatePanel(590f, height); string text = Localization.instance.Localize(item.m_shared.m_name); UiKit.AddText(_panel.transform, Localization.instance.Localize("$smartchest_categories") + " : " + text, 20f, 15f, 550f, 30f, 22, GUIManager.Instance.ValheimOrange); string text2 = (CatalogManager.IsOverridden(item) ? "$smartchest_item_custom" : "$smartchest_item_default"); UiKit.AddText(_panel.transform, Localization.instance.Localize(text2), 20f, 48f, 550f, 26f, 16, new Color(0.8f, 0.8f, 0.8f)); UiKit.AddCategoryGrid(_panel.transform, 90f, CatalogManager.GetItemCategories(item), SetCategory); float y = 90f + num + 15f; Transform transform = _panel.transform; object obj = <>c.<>9__10_0; if (obj == null) { UnityAction val = delegate { ItemData item2 = _item; CatalogManager.ResetItemCategories(item2); Open(item2); }; <>c.<>9__10_0 = val; obj = (object)val; } UiKit.AddButton(transform, "$smartchest_reset_default", 25f, y, 260f, 34f, (UnityAction)obj); Transform transform2 = _panel.transform; object obj2 = <>O.<1>__Close; if (obj2 == null) { UnityAction val2 = Close; <>O.<1>__Close = val2; obj2 = (object)val2; } UiKit.AddButton(transform2, "$smartchest_close", 415f, y, 150f, 34f, (UnityAction)obj2); } private static void SetCategory(string id, bool on) { if (_item != null) { List<string> itemCategories = CatalogManager.GetItemCategories(_item); if (on && !itemCategories.Contains(id)) { itemCategories.Add(id); } if (!on) { itemCategories.Remove(id); } CatalogManager.SetItemCategories(_item, itemCategories); } } public static void Close() { if ((Object)(object)_panel != (Object)null) { Object.Destroy((Object)(object)_panel); } _panel = null; _item = null; } } internal static class Panels { internal static void CloseAll() { ChestPanel.Close(); ItemEditorPanel.Close(); CategoryManagerPanel.Close(); SearchPanel.Close(); } } public static class SearchPanel { [CompilerGenerated] private static class <>O { public static UnityAction <0>__Search; public static UnityAction <1>__Close; } private const float Width = 460f; private static GameObject _panel; private static InputField _input; private static string _lastQuery = ""; public static bool IsOpen => (Object)(object)_panel != (Object)null; public static void Open() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Expected O, but got Unknown Panels.CloseAll(); _panel = UiKit.CreatePanel(460f, 170f); UiKit.AddText(_panel.transform, Localization.instance.Localize("$smartchest_search_title"), 20f, 15f, 420f, 30f, 20, GUIManager.Instance.ValheimOrange); _input = UiKit.AddInput(_panel.transform, _lastQuery, Localization.instance.Localize("$smartchest_search_placeholder"), 25f, 60f, 410f, 34f); ((UnityEvent<string>)(object)_input.onEndEdit).AddListener((UnityAction<string>)delegate { if (Input.GetKey((KeyCode)13) || Input.GetKey((KeyCode)271)) { Search(); } }); Transform transform = _panel.transform; object obj = <>O.<0>__Search; if (obj == null) { UnityAction val = Search; <>O.<0>__Search = val; obj = (object)val; } UiKit.AddButton(transform, "$smartchest_search_go", 25f, 110f, 200f, 34f, (UnityAction)obj); Transform transform2 = _panel.transform; object obj2 = <>O.<1>__Close; if (obj2 == null) { UnityAction val2 = Close; <>O.<1>__Close = val2; obj2 = (object)val2; } UiKit.AddButton(transform2, "$smartchest_close", 285f, 110f, 150f, 34f, (UnityAction)obj2); _input.ActivateInputField(); } private static void Search() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_input == (Object)null) { return; } _lastQuery = _input.text.Trim(); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || _lastQuery.Length == 0) { return; } List<ChestSearch.Hit> list = ChestSearch.Find(((Component)localPlayer).transform.position, Plugin.SearchRadius.Value, _lastQuery); ChestHighlight.ClearAll(); float value = Plugin.SearchDuration.Value; foreach (ChestSearch.Hit item in list) { ChestHighlight.Flash(item.Container, value, $"{item.ItemName} x{item.Count}"); } string text = ((list.Count == 0) ? string.Format(Localization.instance.Localize("$smartchest_search_none"), _lastQuery) : string.Format(Localization.instance.Localize("$smartchest_search_found"), _lastQuery, list.Count)); ((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false); } public static void Close() { if ((Object)(object)_panel != (Object)null) { Object.Destroy((Object)(object)_panel); } _panel = null; _input = null; } } [HarmonyPatch] internal static class TooltipPatch { private const string Marker = "<!--sc-->"; private static IEnumerable<MethodBase> TargetMethods() { return from m in typeof(ItemData).GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) where m.Name == "GetTooltip" && m.ReturnType == typeof(string) && m.GetParameters().Length != 0 && m.GetParameters()[0].ParameterType == typeof(ItemData) select m; } private static void Postfix(ref string __result, ItemData __0) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.ShowCategoriesInTooltip.Value || __0 == null || __result == null || __result.Contains("<!--sc-->")) { return; } List<string> itemCategories = CatalogManager.GetItemCategories(__0); if (itemCategories.Count != 0) { StringBuilder stringBuilder = new StringBuilder(__result); stringBuilder.Append("\n").Append(Localization.instance.Localize("$smartchest_tooltip_categories")).Append(" : "); stringBuilder.Append(CatalogManager.ColoredNames(itemCategories)); if (CatalogManager.IsOverridden(__0)) { stringBuilder.Append(" *"); } stringBuilder.Append(string.Format("\n<color=#AAAAAA>[{0}] {1}</color>", Plugin.EditItemKey.Value, Localization.instance.Localize("$smartchest_tooltip_edit_hint"))); stringBuilder.Append("<!--sc-->"); __result = stringBuilder.ToString(); } } } internal static class UiKit { internal static readonly string[] Palette = new string[16] { "E67E22", "2ECC71", "3498DB", "9B59B6", "E91E63", "1ABC9C", "F1C40F", "E74C3C", "00BCD4", "8BC34A", "A0703C", "B5B5B5", "FFD700", "7F8C8D", "D9534F", "4CAF50" }; internal const float CategoryGridWidth = 590f; private const float GridRowHeight = 34f; private const float GridColWidth = 270f; internal static bool IsTyping { get { EventSystem current = EventSystem.current; if ((Object)(object)current == (Object)null || (Object)(object)current.currentSelectedGameObject == (Object)null) { return false; } InputField component = current.currentSelectedGameObject.GetComponent<InputField>(); if ((Object)(object)component != (Object)null) { return component.isFocused; } return false; } } internal static Transform PanelRoot { get { if (!((Object)(object)GUIManager.CustomGUIFront != (Object)null)) { return ((Component)InventoryGui.instance).transform; } return GUIManager.CustomGUIFront.transform; } } internal static float CategoryGridHeight() { return (float)((CatalogManager.VisibleCategories().Count + 1) / 2) * 34f; } internal static void AddCategoryGrid(Transform parent, float top, ICollection<string> selected, Action<string, bool> onToggle) { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) List<Category> list = CatalogManager.VisibleCategories(); for (int i = 0; i < list.Count; i++) { Category category = list[i]; string id = category.Id; float num = 25f + (float)(i % 2) * 270f; float y = top + (float)(i / 2) * 34f; AddToggle(parent, num, y, selected.Contains(id), delegate(bool on) { onToggle(id, on); }); AddText(parent, "<color=#" + category.Color + ">" + category.DisplayName + "</color>", num + 34f, y, 230f, 28f, 18, Color.white); } } internal static string NextColor(string current) { int num = Array.IndexOf(Palette, (current ?? "").ToUpperInvariant()); return Palette[(num + 1) % Palette.Length]; } internal static GameObject CreatePanel(float width, float height) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) return GUIManager.Instance.CreateWoodpanel(PanelRoot, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), new Vector2((0f - width) / 2f - 30f, 0f), width, height, true); } internal static Toggle AddToggle(Transform parent, float x, float y, bool isOn, UnityAction<bool> onChange) { GameObject obj = GUIManager.Instance.CreateToggle(parent, 26f, 26f); Place(obj, x, y, 26f, 26f); Toggle component = obj.GetComponent<Toggle>(); component.isOn = isOn; ((UnityEvent<bool>)(object)component.onValueChanged).AddListener(onChange); return component; } internal static InputField AddInput(Transform parent, string text, string placeholder, float x, float y, float width, float height) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GUIManager.Instance.CreateInputField(parent, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, (ContentType)0, placeholder, 18, width, height); Place(obj, x, y, width, height); InputField component = obj.GetComponent<InputField>(); component.characterLimit = 32; component.text = text ?? ""; return component; } internal static void Place(GameObject go, float x, float y, float width, float height) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)go.transform; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0f, 1f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0f, 1f); val.anchoredPosition = new Vector2(x, 0f - y); val.sizeDelta = new Vector2(width, height); } internal static GameObject AddButton(Transform parent, string label, float x, float y, float width, float height, UnityAction onClick) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GUIManager.Instance.CreateButton(Localization.instance.Localize(label), parent, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, width, height); Place(obj, x, y, width, height); ((UnityEvent)obj.GetComponent<Button>().onClick).AddListener(onClick); return obj; } internal static GameObject CreateButtonBar(Transform parent, string name, ButtonPlacement place, Vector2 offset, float w, string[] labels, UnityAction[] actions) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: 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_01db: Unknown result type (might be due to invalid IL or missing references) bool flag = place == ButtonPlacement.Gauche || place == ButtonPlacement.Droite; int num = labels.Length; GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(parent, false); val2.sizeDelta = (flag ? new Vector2(w, (float)num * 30f + (float)(num - 1) * 6f) : new Vector2((float)num * w + (float)(num - 1) * 6f, 30f)); Vector2 val3 = default(Vector2); switch (place) { case ButtonPlacement.Dessus: ((Vector2)(ref val3))..ctor(0f, 1f); val2.anchorMax = val3; val2.anchorMin = val3; val2.pivot = new Vector2(0f, 0f); val2.anchoredPosition = new Vector2(0f, 6f) + offset; break; case ButtonPlacement.Dessous: ((Vector2)(ref val3))..ctor(0f, 0f); val2.anchorMax = val3; val2.anchorMin = val3; val2.pivot = new Vector2(0f, 1f); val2.anchoredPosition = new Vector2(0f, -6f) + offset; break; case ButtonPlacement.Gauche: ((Vector2)(ref val3))..ctor(0f, 1f); val2.anchorMax = val3; val2.anchorMin = val3; val2.pivot = new Vector2(1f, 1f); val2.anchoredPosition = new Vector2(-6f, 0f) + offset; break; default: ((Vector2)(ref val3))..ctor(1f, 1f); val2.anchorMax = val3; val2.anchorMin = val3; val2.pivot = new Vector2(0f, 1f); val2.anchoredPosition = new Vector2(6f, 0f) + offset; break; } for (int i = 0; i < num; i++) { float x = (flag ? 0f : ((float)i * (w + 6f))); float y = (flag ? ((float)i * 36f) : 0f); AddButton(val.transform, labels[i], x, y, w, 30f, actions[i]); } return val; } internal static void SetButtonText(GameObject button, string text) { if (!((Object)(object)button == (Object)null)) { Text componentInChildren = button.GetComponentInChildren<Text>(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.text = text; } } } internal static void AddText(Transform parent, string text, float x, float y, float width, float height, int size, Color color) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GUIManager.Instance.CreateText(text, parent, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, size, color, true, Color.black, width, height, false); Place(obj, x, y, width, height); Text component = obj.GetComponent<Text>(); if ((Object)(object)component != (Object)null) { component.supportRichText = true; component.alignment = (TextAnchor)3; } } } } namespace SmartChest.Storing { public static class ChestSearch { public class Hit { public Container Container; public string ItemName; public int Count; } public static List<Hit> Find(Vector3 position, float radius, string query) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) List<Hit> list = new List<Hit>(); query = (query ?? "").Trim(); if (query.Length == 0) { return list; } foreach (Container item in ContainerRegistry.All()) { if (Vector3.Distance(position, ((Component)item).transform.position) > radius || !ModCompat.IsEligibleChest(item)) { continue; } Inventory inventory = item.GetInventory(); if (inventory == null) { continue; } Hit hit = null; foreach (ItemData item2 in inventory.m_inventory) { string text = Localization.instance.Localize(item2.m_shared.m_name); if (Contains(text, query) || Contains(CatalogManager.GetPrefabName(item2), query)) { if (hit == null) { hit = new Hit { Container = item, ItemName = text }; } hit.Count += item2.m_stack; } } if (hit != null) { list.Add(hit); } } return list; } private static bool Contains(string text, string query) { if (text != null) { return text.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0; } return false; } } public static class SortService { public static void SortChest(Player player, Container container) { //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || (Object)(object)container == (Object)null || (Object)(object)container.m_nview == (Object)null || !container.m_nview.IsValid()) { return; } if (!container.m_nview.IsOwner()) { ((Character)player).Message((MessageType)2, "$smartchest_msg_not_owner", 0, (Sprite)null, false); return; } Inventory inventory = container.GetInventory(); if (inventory == null) { return; } List<ItemData> list = new List<ItemData>(inventory.m_inventory); MergeStacks(list, inventory); Dictionary<ItemData, int> rank = new Dictionary<ItemData, int>(); Dictionary<ItemData, string> names = new Dictionary<ItemData, string>(); foreach (ItemData item in list) { rank[item] = CatalogManager.SortRank(item); names[item] = Localization.instance.Localize(item.m_shared.m_name); } list.Sort(delegate(ItemData a, ItemData b) { int num4 = rank[a].CompareTo(rank[b]); if (num4 != 0) { return num4; } num4 = string.Compare(names[a], names[b], StringComparison.CurrentCultureIgnoreCase); if (num4 != 0) { return num4; } num4 = b.m_quality.CompareTo(a.m_quality); return (num4 != 0) ? num4 : b.m_stack.CompareTo(a.m_stack); }); int num = 0; for (int num2 = 0; num2 < inventory.GetHeight(); num2++) { if (num >= list.Count) { break; } for (int num3 = 0; num3 < inventory.GetWidth(); num3++) { if (num >= list.Count) { break; } list[num++].m_gridPos = new Vector2i(num3, num2); } } inventory.Changed(false, false); ((Character)player).Message((MessageType)2, "$smartchest_msg_sorted", 0, (Sprite)null, false); } private static void MergeStacks(List<ItemData> items, Inventory inventory) { foreach (List<ItemData> item in (from i in items where i.m_stack < i.m_shared.m_maxStackSize && (i.m_customData == null || i.m_customData.Count == 0) group i by i.m_shared.m_name + "#" + i.m_quality into g select g.ToList()).ToList()) { if (item.Count <= 1) { continue; } int num = item.Sum((ItemData i) => i.m_stack); int maxStackSize = item[0].m_shared.m_maxStackSize; foreach (ItemData item2 in item) { if (num <= 0) { item2.m_stack = 0; inventory.RemoveItem(item2); items.Remove(item2); } else { item2.m_stack = Math.Min(maxStackSize, num); num -= item2.m_stack; } } } } } public static class StoreService { private class Target { public Container Container; public Inventory Inventory; public HashSet<string> Categories; public ChestMode Mode; public int Priority; public float Distance; public bool Remote; public bool Claimed; } private class Report { public int Moved; public readonly HashSet<Container> UsedChests = new HashSet<Container>(); public readonly List<Container> FullChests = new List<Container>(); } public static void StoreNearby(Player player) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null) { return; } Container val = (((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.m_currentContainer : null); Vector3 position = ((Component)player).transform.position; float value = Plugin.StoreRadius.Value; List<Target> list = new List<Target>(); foreach (Container item in ContainerRegistry.All()) { float num = Vector3.Distance(position, ((Component)item).transform.position); if (!(num > value)) { Target target = MakeTarget(item, player, num, (Object)(object)item == (Object)(object)val); if (target != null) { list.Add(target); } } } Run(player, list); } public static void StoreInto(Player player, Container container) { if (!((Object)(object)player == (Object)null) && !((Object)(object)container == (Object)null)) { Target target = MakeTarget(container, player, 0f, isOpenByMe: true); if (target == null) { ((Character)player).Message((MessageType)2, "$smartchest_msg_no_categories", 0, (Sprite)null, false); return; } Run(player, new List<Target> { target }); } } private static Target MakeTarget(Container c, Player player, float distance, bool isOpenByMe) { if (!ModCompat.IsEligibleChest(c)) { return null; } Inventory inventory = c.GetInventory(); if (inventory == null || inventory == ((Humanoid)player).GetInventory()) { return null; } List<string> list = ChestCategories.Get(c); ChestMode mode = ChestCategories.GetMode(c); if (list.Count == 0 && mode != ChestMode.Overflow) { return null; } if (!isOpenByMe && !ModCompat.CanAffectRemotely(c, player)) { return null; } return new Target { Container = c, Inventory = inventory, Categories = new HashSet<string>(list), Mode = mode, Priority = ChestCategories.GetPriority(c), Distance = distance, Remote = !isOpenByMe }; } private static void Run(Player player, List<Target> targets) { if (targets.Count == 0) { ((Character)player).Message((MessageType)2, "$smartchest_msg_no_chest", 0, (Sprite)null, false); return; } Inventory inventory = ((Humanoid)player).GetInventory(); Report report = new Report(); foreach (ItemData item in inventory.m_inventory.ToList()) { if (CanStore(player, inventory, item)) { StoreItem(inventory, item, targets, report); } } foreach (Target target in targets) { if (target.Remote && target.Claimed) { ModCompat.EndRemoteEdit(target.Container); } } ShowReport(player, report); } private static void StoreItem(Inventory playerInv, ItemData item, List<Target> targets, Report report) { List<Target> list = new List<Target>(); List<Target> list2 = new List<Target>(); foreach (Target target in targets) { if (CatalogManager.MatchesAny(item, target.Categories)) { list.Add(target); } else if (target.Mode == ChestMode.Overflow) { list2.Add(target); } } foreach (Target item2 in (from t in list orderby t.Priority descending, Contains(t.Inventory, item) descending, t.Distance select t).Concat(from t in list2 orderby t.Priority descending, t.Distance select t)) { int num = MoveInto(playerInv, item2, item); if (num > 0) { report.Moved += num; report.UsedChests.Add(item2.Container); } if (!playerInv.ContainsItem(item)) { return; } } foreach (Target item3 in list) { if (!report.FullChests.Contains(item3.Container) && ChestCategories.IsFull(item3.Container)) { report.FullChests.Add(item3.Container); } } } private static void ShowReport(Player player, Report report) { string text = ((report.Moved == 0) ? Localization.instance.Localize("$smartchest_msg_nothing") : string.Format(Localization.instance.Localize("$smartchest_stored_summary"), report.Moved, report.UsedChests.Count)); ((Character)player).Message((MessageType)2, text, 0, (Sprite)null, false); if (!Plugin.FullChestAlert.Value) { return; } string format = Localization.instance.Localize("$smartchest_msg_full"); foreach (Container fullChest in report.FullChests) { ((Character)player).Message((MessageType)1, string.Format(format, ChestDescription.Describe(fullChest, extras: false)), 0, (Sprite)null, false); } } private static bool CanStore(Player player, Inventory playerInv, ItemData item) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) if (item == null || item.m_equipped) { return false; } if (Plugin.SkipHotbar.Value && item.m_gridPos.y == 0) { return false; } if (QuickStackStoreCompat.IsFavorited(player, item)) { return false; } return !ModCompat.IsProtectedSlot(playerInv, item.m_gridPos); } private static bool Contains(Inventory inv, ItemData item) { foreach (ItemData item2 in inv.m_inventory) { if (item2.m_shared.m_name == item.m_shared.m_name) { return true; } } return false; } private static int MoveInto(Inventory from, Target t, ItemData item) { if (!t.Claimed) { if (t.Remote) { ModCompat.BeginRemoteEdit(t.Container); } else if (!t.Container.m_nview.IsOwner()) { t.Container.m_nview.ClaimOwnership(); } t.Claimed = true; } int stack = item.m_stack; t.Inventory.MoveItemToThis(from, item); int num = (from.ContainsItem(item) ? item.m_stack : 0); return stack - num; } } } namespace SmartChest.Compat { public static class AzuAutoStoreCompat { public static void TryInit(Harmony harmony) { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Expected O, but got Unknown if (!ModCompat.Has("Azumatt.AzuAutoStore")) { return; } try { Assembly assembly = ((object)Chainloader.PluginInfos["Azumatt.AzuAutoStore"].Instance).GetType().Assembly; List<MethodInfo> list = new List<MethodInfo>(); Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(assembly); for (int i = 0; i < typesFromAssembly.Length; i++) { MethodInfo[] methods = typesFromAssembly[i].GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (!(methodInfo.Name != "TryStore") && !(methodInfo.ReturnType != typeof(bool))) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length >= 2 && parameters[0].ParameterType == typeof(Container) && parameters[1].ParameterType == typeof(ItemData).MakeByRefType()) { list.Add(methodInfo); } } } } HarmonyMethod val = new HarmonyMethod(typeof(AzuAutoStoreCompat), "TryStorePrefix", (Type[])null); foreach (MethodInfo item in list) { harmony.Patch((MethodBase)item, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (list.Count > 0) { Plugin.Log.LogInfo((object)$"Intégration AzuAutoStore : active ({list.Count} méthode(s))."); } else { Plugin.Log.LogWarning((object)"AzuAutoStore : méthode TryStore introuvable, intégration inactive."); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Intégration AzuAutoStore désactivée : " + ex.Message)); } } private static bool TryStorePrefix(Container __0, ref ItemData __1, ref bool __result) { if (!Plugin.AutoStoreIntegration.Value || (Object)(object)__0 == (Object)null || __1 == null) { return true; } List<string> list = ChestCategories.Get(__0); if (list.Count == 0) { return true; } if (!CatalogManager.MatchesAny(__1, list)) { if (ChestCategories.GetMode(__0) == ChestMode.Overflow) { return true; } __result = false; return false; } __result = StoreCopy(__0, __1); return false; } private static bool StoreCopy(Container chest, ItemData item) { Inventory inventory = chest.GetInventory(); if (inventory == null || item.m_stack <= 0) { return false; } bool flag = false; while (item.m_stack > 0 && inventory.CanAddItem(item, 1)) { ItemData val = item.Clone(); val.m_stack = 1; if (!inventory.AddItem(val)) { break; } item.m_stack--; flag = true; } if (flag) { chest.Save(); } return flag; } } public static class ModCompat { public const string AedenEPI = "aedenthorn.ExtendedPlayerInventory"; public const string ComfyQuickSlots = "com.bruce.valheim.comfyquickslots"; public const string OdinsQoL = "com.odinplusqol.mod"; public const string OdinsExtendedInventory = "odinplusqol.OdinsExtendedInventory"; public const string RandyEquipmentQuickSlots = "randyknapp.mods.equipmentandquickslots"; public const string AzuEPI = "Azumatt.AzuExtendedPlayerInventory"; public const string BetterArchery = "ishid4.mods.betterarchery"; public const string MultiUserChest = "com.maxsch.valheim.MultiUserChest"; public const string DynamicStoragePiles = "com.maxsch.valheim.DynamicStoragePiles"; public const string AzuAutoStore = "Azumatt.AzuAutoStore"; public const string AdventureBackpacks = "vapok.mods.adventurebackpacks"; public const string Backpacks = "org.bepinex.plugins.backpacks"; public const string Jewelcrafting = "org.bepinex.plugins.jewelcrafting"; public const string CurrencyPocket = "Azumatt.CurrencyPocket"; public const string SmartContainers = "flueno.SmartContainers"; public const string Auga = "randyknapp.mods.auga"; private const string ZdoInUse = "InUse"; private static MethodInfo _isRestrictedContainer; private static bool _restrictedLookupFailed; private static MethodInfo _qssIsEquipOrQuickSlot; private static bool _qssLookupDone; private static MethodInfo _azuGetAddedRows; private static bool _azuFailed; private static MethodInfo _comfyIsArmorSlot; private static bool _comfyFailed; private static FieldInfo _baEnabled; private static FieldInfo _baRow; private static bool _baFailed; private static readonly Dictionary<string, Type> _typeCache = new Dictionary<string, Type>(); private static readonly Dictionary<string, FieldInfo> _fieldCache = new Dictionary<string, FieldInfo>(); public static bool Has(string guid) { return Chainloader.PluginInfos.ContainsKey(guid); } public static Type PluginType(string guid, string fullName) { try { if (!Chainloader.PluginInfos.TryGetValue(guid, out var value) || (Object)(object)value.Instance == (Object)null) { return null; } return ((object)value.Instance).GetType().Assembly.GetType(fullName, throwOnError: false); } catch { return null; } } public static void LogDetected() { string[] source = new string[17] { "goldenrevolver.quick_stack_store", "aedenthorn.ExtendedPlayerInventory", "com.bruce.valheim.comfyquickslots", "com.odinplusqol.mod", "odinplusqol.OdinsExtendedInventory", "randyknapp.mods.equipmentandquickslots", "Azumatt.AzuExtendedPlayerInventory", "ishid4.mods.betterarchery", "com.maxsch.valheim.MultiUserChest", "com.maxsch.valheim.DynamicStoragePiles", "Azumatt.AzuAutoStore", "vapok.mods.adventurebackpacks", "org.bepinex.plugins.backpacks", "org.bepinex.plugins.jewelcrafting", "Azumatt.CurrencyPocket", "flueno.SmartContainers", "randyknapp.mods.auga" }; string text = string.Join(", ", source.Where(Has)); Plugin.Log.LogInfo((object)("Mods compatibles détectés : " + ((text.Length > 0) ? text : "aucun"))); if (Has("randyknapp.mods.auga")) { Plugin.Log.LogWarning((object)"Project Auga remplace l'interface de l'inventaire : les boutons de Smart Chest peuvent ne pas apparaître. La touche de rangement fonctionne quand même."); } } public static bool IsEligibleChest(Container c) { if ((Object)(object)c == (Object)null || (Object)(object)c.m_nview == (Object)null || !c.m_nview.IsValid()) { return false; } if ((Object)(object)((Component)c).GetComponent<TombStone>() != (Object)null) { return false; } if ((Object)(object)((Component)c).GetComponentInParent<Player>() != (Object)null) { return false; } Piece val = (((Object)(object)c.m_piece != (Object)null) ? c.m_piece : ((Component)c).GetComponentInParent<Piece>()); if ((Object)(object)val == (Object)null || !val.IsPlacedByPlayer()) { return false; } if (IsRestrictedPile(c)) { return false; } return true; } public static bool IsTrueSingleplayer() { if (!ZNet.m_openServer && !ZNet.m_publicServer && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer() && !ZNet.instance.IsDedicated()) { return ZNet.instance.GetConnectedPeers().Count == 0; } return false; } public static bool IsInUse(Container c) { if (c.IsInUse()) { return true; } if ((Object)(object)c.m_wagon != (Object)null && c.m_wagon.InUse()) { return true; } ZDO zDO = c.m_nview.GetZDO(); if (zDO != null) { return zDO.GetInt("InUse", 0) == 1; } return false; } public static bool CanAffectRemotely(Container c, Player player) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (!c.CheckAccess(player.GetPlayerID())) { return false; } if (c.m_checkGuardStone && !PrivateArea.CheckAccess(((Component)c).transform.position, 0f, false, false)) { return false; } if (Has("com.maxsch.valheim.MultiUserChest")) { return true; } if (!IsTrueSingleplayer() && (Object)(object)((Component)((Component)c).transform.root).GetComponentInChildren<Ship>() != (Object)null) { return false; } return !IsInUse(c); } public static void BeginRemoteEdit(Container c) { if (!Has("com.maxsch.valheim.MultiUserChest")) { c.m_nview.ClaimOwnership(); SetInUse(c, inUse: true); } } public static void EndRemoteEdit(Container c) { if (!Has("com.maxsch.valheim.MultiUserChest")) { SetInUse(c, inUse: false); } } private static void SetInUse(Container c, bool inUse) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) c.m_inUse = inUse; ZDO zDO = c.m_nview.GetZDO(); if (zDO != null) { zDO.Set("InUse", inUse ? 1 : 0); ZDOMan.instance.ForceSendZDO(ZNet.GetUID(), zDO.m_uid); } } public static bool IsRestrictedPile(Container c) { if (!Has("com.maxsch.valheim.DynamicStoragePiles") || _restrictedLookupFailed) { return false; } try { if (_isRestrictedContainer == null) { _isRestrictedContainer = (PluginType("com.maxsch.valheim.DynamicStoragePiles", "DynamicStoragePiles.RestrictContainers") ?? FindType("DynamicStoragePiles", "RestrictContainers"))?.GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((MethodInfo m) => m.Name.Equals("IsRestrictedContainer", StringComparison.OrdinalIgnoreCase)); if (_isRestrictedContainer == null) { _restrictedLookupFailed = true; return false; } } object[] parameters = new object[2] { c.m_name, null }; object obj = _isRestrictedContainer.Invoke(null, parameters); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch (Exception ex) { _restrictedLookupFailed = true; Plugin.Log.LogWarning((object)("Dynamic Storage Piles : détection impossible (" + ex.Message + ")")); return false; } } public static bool IsProtectedSlot(Inventory inv, Vector2i pos) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) int height = inv.GetHeight(); int width = inv.GetWidth(); if (!_qssLookupDone) { _qssLookupDone = true; if (Has("goldenrevolver.quick_stack_store")) { Type type = PluginType("goldenrevolver.quick_stack_store", "QuickStackStore.CompatibilitySupport"); _qssIsEquipOrQuickSlot = ((type != null) ? AccessTools.Method(type, "IsEquipOrQuickSlot", new Type[3] { typeof(int), typeof(int), typeof(Vector2i) }, (Type[])null) : null); } } if (_qssIsEquipOrQuickSlot != null) { try { return (bool)_qssIsEquipOrQuickSlot.Invoke(null, new object[3] { height, width, pos }); } catch { } } if (!IsAedenLikeSlot(height, pos) && !IsAzuEpiSlot(height, width, pos) && !IsComfySlot(pos)) { return IsBetterArcherySlot(pos); } return true; } private static bool IsAedenLikeSlot(int height, Vector2i pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (pos.y != height - 1) { return false; } if ((!Has("aedenthorn.ExtendedPlayerInventory") || !BoolField("ExtendedPlayerInventory", "BepInExPlugin", "addEquipmentRow")) && (!Has("odinplusqol.OdinsExtendedInventory") || !BoolField("OdinsExtendedInventory", "OdinsExtendedInventoryPlugin", "addEquipmentRow"))) { if (Has("com.odinplusqol.mod")) { return BoolField("OdinQOL", "QuickAccessBar", "AddEquipmentRow"); } return false; } return true; } private static bool IsAzuEpiSlot(int height, int width, Vector2i pos) { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) if (!Has("Azumatt.AzuExtendedPlayerInventory") || _azuFailed) { return false; } try { if (_azuGetAddedRows == null) { Type type = PluginType("Azumatt.AzuExtendedPlayerInventory", "AzuExtendedPlayerInventory.API"); _azuGetAddedRows = ((type != null) ? AccessTools.Method(type, "GetAddedRows", new Type[1] { typeof(int) }, (Type[])null) : null); } int num = ((!(_azuGetAddedRows != null)) ? (ToggleField("AzuExtendedPlayerInventory", "AzuExtendedPlayerInventoryPlugin", "AddEquipmentRow") ? 1 : 0) : ((int)_azuGetAddedRows.Invoke(null, new object[1] { width }))); return num > 0 && pos.y >= height - num; } catch { _azuFailed = true; return pos.y == height - 1; } } private static bool IsComfySlot(Vector2i pos) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) if (!Has("com.bruce.valheim.comfyquickslots") || _comfyFailed) { return false; } try { if (_comfyIsArmorSlot == null) { _comfyIsArmorSlot = FindType("ComfyQuickSlots", "QuickSlotsManager")?.GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((MethodInfo m) => m.Name.Equals("IsArmorSlot", StringComparison.OrdinalIgnoreCase) && m.GetParameters().Length == 1); if (_comfyIsArmorSlot == null) { _comfyFailed = true; return false; } } return (bool)_comfyIsArmorSlot.Invoke(null, new object[1] { pos }) || (bool)_comfyIsArmorSlot.Invoke(null, new object[1] { (object)new Vector2i(pos.x - 3, pos.y) }); } catch { _comfyFailed = true; return false; } } private static bool IsBetterArcherySlot(Vector2i pos) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) if (!Has("ishid4.mods.betterarchery") || _baFailed) { return false; } try { if (_baEnabled == null || _baRow == null) { _baEnabled = StaticField("BetterArchery", "BetterArchery", "ConfigQuiverEnabled"); _baRow = StaticField("BetterArchery", "BetterArchery", "QuiverRowIndex"); if (_baEnabled == null || _baRow == null) { _baFailed = true; return false; } } if (!(_baEnabled.GetValue(null) is ConfigEntry<bool> val) || !val.Value) { return false; } if (!(_baRow.GetValue(null) is int num) || num == 0) { return false; } return pos.y == num || pos.y == num - 1; } catch { _baFailed = true; return false; } } private static Type FindType(string assemblyName, string className) { string key = assemblyName + "/" + className; if (_typeCache.TryGetValue(key, out var value)) { return value; } Type type = null; try { type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == assemblyName)?.GetTypes().FirstOrDefault((Type t) => t.IsClass && t.Name == className); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Lecture de " + assemblyName + " impossible : " + ex.Message)); } _typeCache[key] = type; return type; } private static FieldInfo StaticField(string assemblyName, string className, string fieldName) { string key = assemblyName + "/" + className + "/" + fieldName; if (_fieldCache.TryGetValue(key, out var value)) { return value; } FieldInfo fieldInfo = FindType(assemblyName, className)?.GetFields(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((FieldInfo x) => x.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase)); _fieldCache[key] = fieldInfo; return fieldInfo; } private static bool BoolField(string assemblyName, string className, string fieldName) { try { return StaticField(assemblyName, className, fieldName)?.GetValue(null) is ConfigEntry<bool> val && val.Value; } catch { return true; } } private static bool ToggleField(string assemblyName, string className, string fieldName) { try { object obj = StaticField(assemblyName, className, fieldName)?.GetValue(null); if (obj is ConfigEntry<bool> val) { return val.Value; } ConfigEntryBase val2 = (ConfigEntryBase)((obj is ConfigEntryBase) ? obj : null); if (val2 != null) { return Convert.ToInt32(val2.BoxedValue) != 0; } return false; } catch { return true; } } } public static class QuickStackStoreCompat { private static MethodInfo _getPlayerConfig; private static MethodInfo _isFavorited; private static object _cachedConfig; private static long _cachedPlayerId; private static int _cachedFrame = -1; public static bool Active { get; private set; } public static void TryInit(Harmony harmony) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown if (!Chainloader.PluginInfos.ContainsKey("goldenrevolver.quick_stack_store")) { return; } try { Type type = ModCompat.PluginType("goldenrevolver.quick_stack_store", "QuickStackStore.QuickStackModule"); Type type2 = ModCompat.PluginType("goldenrevolver.quick_stack_store", "QuickStackStore.StoreTakeAllModule"); Type type3 = ModCompat.PluginType("goldenrevolver.quick_stack_store", "QuickStackStore.UserConfig"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "QuickStackIntoThisContainer", (Type[])null, (Type[])null) : null); MethodInfo methodInfo2 = ((type2 != null) ? AccessTools.Method(type2, "ShouldStoreItem", (Type[])null, (Type[])null) : null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(QuickStackStoreCompat), "QuickStackPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { Plugin.Log.LogWarning((object)"Quick Stack Store : méthode QuickStackIntoThisContainer introuvable, stockage rapide non intégré."); } if (methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(QuickStackStoreCompat), "ShouldStorePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { Plugin.Log.LogWarning((object)"Quick Stack Store : méthode ShouldStoreItem introuvable, Tout stocker non intégré."); } if (type3 != null) { _getPlayerConfig = AccessTools.Method(type3, "GetPlayerConfig", new Type[1] { typeof(long) }, (Type[])null); _isFavorited = AccessTools.Method(type3, "IsItemNameOrSlotFavorited", new Type[1] { typeof(ItemData) }, (Type[])null); } Active = methodInfo != null || methodInfo2 != null; Plugin.Log.LogInfo((object)("Intégration Quick Stack Store : " + (Active ? "active" : "inactive") + ".")); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Intégration Quick Stack Store désactivée : " + ex.Message)); } } public static bool IsFavorited(Player player, ItemData item) { if (_getPlayerConfig == null || _isFavorited == null || (Object)(object)player == (Object)null) { return false; } try { long playerID = player.GetPlayerID(); if (_cachedFrame != Time.frameCount || _cachedPlayerId != playerID) { _cachedConfig = _getPlayerConfig.Invoke(null, new object[1] { playerID }); _cachedPlayerId = playerID; _cachedFrame = Time.frameCount; } return _cachedConfig != null && (bool)_isFavorited.Invoke(_cachedConfig, new object[1] { item }); } catch { return false; } } private static void QuickStackPostfix(List<ItemData> trophies, List<ItemData> nonTrophies, Inventory playerInventory, Inventory container, bool callPlayerInvChanged, ref int __result) { if (!Plugin.QuickStackIntegration.Value) { return; } Container val = ContainerRegistry.FromInventory(container); if ((Object)(object)val == (Object)null) { return; } HashSet<string> hashSet = new HashSet<string>(ChestCategories.Get(val)); if (hashSet.Count == 0) { return; } int num = MoveMatching(nonTrophies, hashSet, playerInventory, container) + MoveMatching(trophies, hashSet, playerInventory, container); if (num > 0) { __result += num; if (callPlayerInvChanged) { playerInventory.Changed(false, false); } } } private static int MoveMatching(List<ItemData> items, HashSet<string> chestCats, Inventory from, Inventory to) { if (items == null) { return 0; } int num = 0; for (int num2 = items.Count - 1; num2 >= 0; num2--) { ItemData val = items[num2]; if (CatalogManager.MatchesAny(val, chestCats) && to.AddItem(val)) { from.RemoveItem(val); items.RemoveAt(num2); num++; } } return num; } private static void ShouldStorePostfix(ItemData item, ref bool __result) { if (!__result || !Plugin.QuickStackIntegration.Value) { return; } Container val = (((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.m_currentContainer : null); if (!((Object)(object)val == (Object)null) && ChestCategories.GetMode(val) == ChestMode.Strict) { List<string> list = ChestCategories.Get(val); if (list.Count != 0 && !CatalogManager.MatchesAny(item, list)) { __result = false; } } } } } namespace SmartChest.Chests { public enum ChestMode { Strict, Overflow } public static class ChestCategories { public const string KeyCategories = "SmartChest_Cats"; public const string KeyMode = "SmartChest_Mode"; public const string KeyPriority = "SmartChest_Prio"; public const int MaxPriority = 9; private static ZDO GetZdo(Container container) { if ((Object)(object)container == (Object)null || (Object)(object)container.m_nview == (Object)null || !container.m_nview.IsValid()) { return null; } return container.m_nview.GetZDO(); } public static List<string> Get(Container container) { ZDO zdo = GetZdo(container); if (zdo == null) { return new List<string>(); } string text = zdo.GetString("SmartChest_Cats", ""); if (string.IsNullOrEmpty(text)) { return new List<string>(); } return (from id in text.Split(new char[1] { ';' }) where id.Length > 0 && CatalogManager.GetCategory(id) != null select id).Distinct().ToList(); } public static ChestMode GetMode(Container container) { ZDO zdo = GetZdo(container); if (zdo != null) { return (ChestMode)zdo.GetInt("SmartChest_Mode", 0); } return ChestMode.Strict; } public static int GetPriority(Container container) { ZDO zdo = GetZdo(container); if (zdo != null) { return Mathf.Clamp(zdo.GetInt("SmartChest_Prio", 0), 0, 9); } return 0; } public static bool SetPriority(Container container, int priority) { ZDO writableZdo = GetWritableZdo(container); if (writableZdo == null) { return false; } writableZdo.Set("SmartChest_Prio", Mathf.Clamp(priority, 0, 9)); return true; } public static bool IsFull(Container container) { Inventory val = (((Object)(object)container != (Object)null) ? container.GetInventory() : null); if (val != null) { return val.m_inventory.Count >= val.GetWidth() * val.GetHeight(); } return false; } public static bool Set(Container container, IEnumerable<string> categoryIds) { ZDO writableZdo = GetWritableZdo(container); if (writableZdo == null) { return false; } writableZdo.Set("SmartChest_Cats", string.Join(";", categoryIds.Distinct())); return true; } public static bool SetMode(Container container, ChestMode mode) { ZDO writableZdo = GetWritableZdo(container); if (writableZdo == null) { return false; } writableZdo.Set("SmartChest_Mode", (int)mode); return true; } public static bool Toggle(Container container, string categoryId, bool enabled) { List<string> list = Get(container); if (enabled && !list.Contains(categoryId)) { list.Add(categoryId); } if (!enabled) { list.Remove(categoryId); } return Set(container, list); } private static ZDO GetWritableZdo(Container container) { ZDO zdo = GetZdo(container); if (zdo == null) { return null; } if (!container.m_nview.IsOwner()) { container.m_nview.ClaimOwnership(); } return zdo; } } public static class ChestDescription { public static string Describe(Container container, bool extras) { List<string> list = ChestCategories.Get(container); string text = CatalogManager.ColoredNames(list); if (ChestCategories.GetMode(container) == ChestMode.Overflow) { string text2 = Localization.instance.Localize((list.Count == 0) ? "$smartchest_mode_overflow" : "$smartchest_label_rest"); text = text + ((text.Length > 0) ? " " : "") + "<color=#CCCCCC>" + text2 + "</color>"; } if (!extras || text.Length == 0) { return text; } int priority = ChestCategories.GetPriority(container); if (priority > 0) { text = text + " <color=#CCCCCC>(" + Localization.instance.Localize("$smartchest_priority") + " " + priority + ")</color>"; } if (ChestCategories.IsFull(container)) { text = text + " <color=#FF5050>" + Localization.instance.Localize("$smartchest_full").ToUpperInvariant() + "</color>"; } return text; } } public static class ContainerRegistry { [HarmonyPatch(typeof(Container), "Awake")] private static class AwakePatch { private static void Postfix(Container __instance) { Add(__instance); } } private static readonly HashSet<Container> _all = new HashSet<Container>(); private static readonly Dictionary<Inventory, Container> _byInventory = new Dictionary<Inventory, Container>(); public static List<Container> All() { _all.RemoveWhere((Container c) => (Object)(object)c == (Object)null); List<Inventory> list = new List<Inventory>(); foreach (KeyValuePair<Inventory, Container> item in _byInventory) { if ((Object)(object)item.Value == (Object)null) { list.Add(item.Key); } } foreach (Inventory item2 in list) { _byInventory.Remove(item2); } return new List<Container>(_all); } public static Container FromInventory(Inventory inv) { if (inv != null && _byInventory.TryGetValue(inv, out var value)) { if ((Object)(object)value != (Object)null) { return value; } _byInventory.Remove(inv); } return null; } internal static void Add(Container c) { if (!((Object)(object)c == (Object)null)) { _all.Add(c); Inventory inventory = c.GetInventory(); if (inventory != null) { _byInventory[inventory] = c; } } } } } namespace SmartChest.Catalog { public static class CatalogManager { private static CatalogData _data; private static readonly Dictionary<string, Category> _byId = new Dictionary<string, Category>(); private static readonly Dictionary<string, List<string>> _overrides = new Dictionary<string, List<string>>(); private static readonly Dictionary<string, List<string>> _defaultCache = new Dictionary<string, List<string>>(); private static readonly Dictionary<string, int> _rank = new Dictionary<string, int>(); public static string FilePath => Path.Combine(Paths.ConfigPath, "SmartChest", "catalog.json"); public static IReadOnlyList<Category> Categories => _data.Categories; public static void Load() { CatalogData catalogData = null; try { if (File.Exists(FilePath)) { catalogData = JsonUtility.FromJson<CatalogData>(File.ReadAllText(FilePath)); } } catch (Exception ex) { Plugin.Log.LogError((object)("catalog.json illisible, on repart des valeurs par défaut : " + ex.Message)); TryBackupBrokenFile(); } _data = catalogData ?? new CatalogData(); EnsureDefaultCategories(); RebuildIndex(); LoadOverrides(); Save(); Plugin.Log.LogInfo((object)$"Catalogue chargé : {_data.Categories.Count} catégories, {_data.ItemOverrides.Count} objets modifiés."); } public static void Save() { try { Directory.CreateDirectory(Path.GetDirectoryName(FilePath)); _data.ItemOverrides = (from kv in _overrides orderby kv.Key select new ItemOverride { Prefab = kv.Key, Categories = kv.Value.ToList() }).ToList(); File.WriteAllText(FilePath, JsonUtility.ToJson((object)_data, true)); } catch (Exception ex) { Plugin.Log.LogError((object)("Impossible d'écrire catalog.json : " + ex.Message)); } } public static Category GetCategory(string id) { if (id == null || !_byId.TryGetValue(id, out var value)) { return null; } return value; } public static string GetPrefabName(ItemData item) { string text = (((Object)(object)item?.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : (item?.m_shared?.m_name ?? "")); int num = text.IndexOf("(Clone)", StringComparison.Ordinal); if (num < 0) { return text; } return text.Substring(0, num).Trim(); } public static List<string> GetItemCategories(ItemData item) { List<string> list = new List<string>(); foreach (string item2 in RawCategories(item)) { if (_byId.ContainsKey(item2)) { list.Add(item2); } } return list; } public static bool MatchesAny(ItemData item, ICollection<string> categoryIds) { if (item == null || categoryIds == null || categoryIds.Count == 0) { return false; } foreach (string item2 in RawCategories(item)) { if (categoryIds.Contains(item2) && _byId.ContainsKey(item2)) { return true; } } return false; } public static int SortRank(ItemData item) { int num = int.MaxValue; foreach (string item2 in RawCategories(item)) { if (_rank.TryGetValue(ite