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 ComfyQuickSlots v1.10.3
ComfyQuickSlots.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ComfyLib; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ComfyQuickSlots")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ComfyQuickSlots")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("08d30e30-98ba-4364-8410-f0d2534129ba")] [assembly: AssemblyFileVersion("1.10.3")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.10.3.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 ComfyQuickSlots { [BepInPlugin("com.bruce.valheim.comfyquickslots", "ComfyQuickSlots", "1.10.3")] public sealed class ComfyQuickSlots : BaseUnityPlugin { public const string PluginGuid = "com.bruce.valheim.comfyquickslots"; public const string PluginName = "ComfyQuickSlots"; public const string PluginVersion = "1.10.3"; private static ManualLogSource _logger; private void Awake() { _logger = ((BaseUnityPlugin)this).Logger; PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.bruce.valheim.comfyquickslots"); } public static void LogInfo(object obj) { _logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } private void Update() { //IL_002a: 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_008e: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && PluginConfig.EnableQuickslots.Value && ((Character)localPlayer).TakeInput()) { ItemData val = null; if (ZInput.GetKeyDown(PluginConfig.QuickSlot1.Value, true)) { val = ((Humanoid)localPlayer).GetInventory().GetItemAt(QuickSlotsManager.QuickSlot1.x, QuickSlotsManager.QuickSlot1.y); } if (ZInput.GetKeyDown(PluginConfig.QuickSlot2.Value, true)) { val = ((Humanoid)localPlayer).GetInventory().GetItemAt(QuickSlotsManager.QuickSlot2.x, QuickSlotsManager.QuickSlot2.y); } if (ZInput.GetKeyDown(PluginConfig.QuickSlot3.Value, true)) { val = ((Humanoid)localPlayer).GetInventory().GetItemAt(QuickSlotsManager.QuickSlot3.x, QuickSlotsManager.QuickSlot3.y); } if (val != null && !localPlayer.IsEquipActionQueued(val)) { ((Humanoid)localPlayer).UseItem((Inventory)null, val, false); } } } } public sealed class PluginConfig { public static ConfigEntry<bool> IsModEnabled { get; private set; } public static ConfigEntry<bool> EnableQuickslots { get; private set; } public static ConfigEntry<KeyCode> QuickSlot1 { get; private set; } public static ConfigEntry<KeyCode> QuickSlot2 { get; private set; } public static ConfigEntry<KeyCode> QuickSlot3 { get; private set; } public static ConfigEntry<TextAnchor> QuickSlotsAnchor { get; private set; } public static ConfigEntry<Vector2> QuickSlotsPosition { get; private set; } public static ConfigEntry<Vector2> ContainerInventoryGridAnchoredPosition { get; private set; } public static ConfigEntry<string> LogFilesPath { get; private set; } public static void BindConfig(ConfigFile config) { //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); EnableQuickslots = config.BindInOrder("QuickSlotToggles", "quickSlotEnable", defaultValue: true, "Enables or disables quickslots."); QuickSlot1 = config.BindInOrder<KeyCode>("QuickSlotBinding", "quickSlot1Use", (KeyCode)122, "Hot key for item use in quick slot 1"); QuickSlot1.OnSettingChanged<KeyCode>(QuickSlotsManager.RefreshBindings); QuickSlot2 = config.BindInOrder<KeyCode>("QuickSlotBinding", "quickSlot2Use", (KeyCode)118, "Hot key for item use in quick slot 2"); QuickSlot2.OnSettingChanged<KeyCode>(QuickSlotsManager.RefreshBindings); QuickSlot3 = config.BindInOrder<KeyCode>("QuickSlotBinding", "quickSlot3Use", (KeyCode)98, "Hot key for item use in quick slot 3"); QuickSlot3.OnSettingChanged<KeyCode>(QuickSlotsManager.RefreshBindings); QuickSlotsAnchor = config.BindInOrder<TextAnchor>("QuickSlotsAnchor", "quickSlotsAnchor", (TextAnchor)6, "The point on the HUD to anchor the Quick Slots bar.\nChanging this also changes the pivot of the Quick Slots to that corner."); QuickSlotsPosition = config.BindInOrder<Vector2>("QuickSlotsOffset", "quickSlotsOffset", new Vector2(216f, 150f), "The position offset from the Quick Slots Anchor at which to place the QuickSlots."); ContainerInventoryGridAnchoredPosition = config.BindInOrder<Vector2>("Container", "anchoredPosition", new Vector2(0f, -25f), "The anchoredPosition for the the Container.InventoryGrid panel."); LogFilesPath = config.BindInOrder("Logging", "logFilesPath", "ItemsOnDeath/", "Path to where logging of items on death are saved."); Directory.CreateDirectory(LogFilesPath.Value); } } public sealed class ConfigPositionedElement : MonoBehaviour { public ConfigEntry<TextAnchor> AnchorConfig; public ConfigEntry<Vector2> PositionConfig; private RectTransform _rt; private TextAnchor _currentAnchor; private void Awake() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown _rt = (RectTransform)((Component)this).transform; EnsureCorrectPosition(); } private void Update() { EnsureCorrectPosition(); } public void EnsureCorrectPosition() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected I4, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: 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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0167: 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_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: 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_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) if (AnchorConfig != null && PositionConfig != null && (_currentAnchor != AnchorConfig.Value || !(_rt.anchoredPosition == PositionConfig.Value))) { _currentAnchor = AnchorConfig.Value; TextAnchor currentAnchor = _currentAnchor; Vector2 val = default(Vector2); switch ((int)currentAnchor) { case 0: { RectTransform rt25 = _rt; RectTransform rt26 = _rt; RectTransform rt27 = _rt; ((Vector2)(ref val))..ctor(0f, 1f); rt27.anchorMax = val; Vector2 pivot = (rt26.anchorMin = val); rt25.pivot = pivot; break; } case 1: { RectTransform rt22 = _rt; RectTransform rt23 = _rt; RectTransform rt24 = _rt; ((Vector2)(ref val))..ctor(0.5f, 1f); rt24.anchorMax = val; Vector2 pivot = (rt23.anchorMin = val); rt22.pivot = pivot; break; } case 2: { RectTransform rt19 = _rt; RectTransform rt20 = _rt; RectTransform rt21 = _rt; ((Vector2)(ref val))..ctor(1f, 1f); rt21.anchorMax = val; Vector2 pivot = (rt20.anchorMin = val); rt19.pivot = pivot; break; } case 3: { RectTransform rt16 = _rt; RectTransform rt17 = _rt; RectTransform rt18 = _rt; ((Vector2)(ref val))..ctor(0f, 0.5f); rt18.anchorMax = val; Vector2 pivot = (rt17.anchorMin = val); rt16.pivot = pivot; break; } case 4: { RectTransform rt13 = _rt; RectTransform rt14 = _rt; RectTransform rt15 = _rt; ((Vector2)(ref val))..ctor(0.5f, 0.5f); rt15.anchorMax = val; Vector2 pivot = (rt14.anchorMin = val); rt13.pivot = pivot; break; } case 5: { RectTransform rt10 = _rt; RectTransform rt11 = _rt; RectTransform rt12 = _rt; ((Vector2)(ref val))..ctor(1f, 0.5f); rt12.anchorMax = val; Vector2 pivot = (rt11.anchorMin = val); rt10.pivot = pivot; break; } case 6: { RectTransform rt7 = _rt; RectTransform rt8 = _rt; RectTransform rt9 = _rt; ((Vector2)(ref val))..ctor(0f, 0f); rt9.anchorMax = val; Vector2 pivot = (rt8.anchorMin = val); rt7.pivot = pivot; break; } case 7: { RectTransform rt4 = _rt; RectTransform rt5 = _rt; RectTransform rt6 = _rt; ((Vector2)(ref val))..ctor(0.5f, 0f); rt6.anchorMax = val; Vector2 pivot = (rt5.anchorMin = val); rt4.pivot = pivot; break; } case 8: { RectTransform rt = _rt; RectTransform rt2 = _rt; RectTransform rt3 = _rt; ((Vector2)(ref val))..ctor(1f, 0f); rt3.anchorMax = val; Vector2 pivot = (rt2.anchorMin = val); rt.pivot = pivot; break; } } _rt.anchoredPosition = PositionConfig.Value; } } } internal static class HotkeyBarManager { public const string QuickSlotsHotKeyBarName = "QuickSlotsHotkeyBar"; public static HotkeyBar QuickSlotsHotkeyBar; public static GameObject QuickSlotsHotkeyBarGameObject; public static bool ShouldRefreshQuickSlots = false; public static string[] HotkeyTexts = new string[3] { PluginConfig.QuickSlot1.Value.ToShortString(), PluginConfig.QuickSlot2.Value.ToShortString(), PluginConfig.QuickSlot3.Value.ToShortString() }; public static void ResetItems(HotkeyBar hkb, Player player) { //IL_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) hkb.m_items.Clear(); foreach (Vector2i quickSlot in QuickSlotsManager.QuickSlots) { ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(quickSlot.x, quickSlot.y); if (itemAt != null) { hkb.m_items.Add(itemAt); } } } public static void CreateHotkeyBarGameObject(Hud hud) { QuickSlotsHotkeyBarGameObject = Object.Instantiate<GameObject>(((Component)QuickSlotsHotkeyBar).gameObject, hud.m_rootObject.transform, true); ((Object)QuickSlotsHotkeyBarGameObject).name = "QuickSlotsHotkeyBar"; QuickSlotsHotkeyBar.m_selected = -1; ConfigPositionedElement configPositionedElement = QuickSlotsHotkeyBarGameObject.AddComponent<ConfigPositionedElement>(); configPositionedElement.PositionConfig = PluginConfig.QuickSlotsPosition; configPositionedElement.AnchorConfig = PluginConfig.QuickSlotsAnchor; configPositionedElement.EnsureCorrectPosition(); RemoveElements(QuickSlotsHotkeyBar); } public static bool HaveItemsChanged(HotkeyBar hkb, Player player) { foreach (ItemData item in new List<ItemData> { ((Humanoid)player).GetInventory().GetItemAt(QuickSlotsManager.QuickSlot1.x, QuickSlotsManager.QuickSlot1.y), ((Humanoid)player).GetInventory().GetItemAt(QuickSlotsManager.QuickSlot2.x, QuickSlotsManager.QuickSlot2.y), ((Humanoid)player).GetInventory().GetItemAt(QuickSlotsManager.QuickSlot3.x, QuickSlotsManager.QuickSlot3.y) }) { if (!hkb.m_items.Contains(item)) { return true; } } return false; } public static void RemoveElements(HotkeyBar hkb) { hkb.m_items.Clear(); foreach (ElementData element in hkb.m_elements) { Object.Destroy((Object)(object)element.m_go); } hkb.m_elements.Clear(); } public static void ResetHotkeyTexts() { //IL_000d: 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_0031: Unknown result type (might be due to invalid IL or missing references) HotkeyTexts = new string[3] { PluginConfig.QuickSlot1.Value.ToShortString(), PluginConfig.QuickSlot2.Value.ToShortString(), PluginConfig.QuickSlot3.Value.ToShortString() }; } } public static class QuickSlotsManager { public const string PlayerDataKey = "ComfyQuickSlotsInventory"; public const string PlayerInventoryName = "ComfyQuickSlotsInventory"; public const int Columns = 8; private static int _rows = 5; public const int QuickSlotsCount = 3; public static readonly List<ItemType> ArmorSlotTypes = new List<ItemType>(5) { (ItemType)6, (ItemType)7, (ItemType)11, (ItemType)17, (ItemType)18 }; public static bool FirstLoad = false; public static Vector2i HelmetSlot = new Vector2i(0, 4); public static Vector2i ChestSlot = new Vector2i(1, 4); public static Vector2i LegsSlot = new Vector2i(2, 4); public static Vector2i ShoulderSlot = new Vector2i(3, 4); public static Vector2i UtilitySlot = new Vector2i(4, 4); public static Vector2i QuickSlot1 = new Vector2i(5, 4); public static Vector2i QuickSlot2 = new Vector2i(6, 4); public static Vector2i QuickSlot3 = new Vector2i(7, 4); public static List<Vector2i> ArmorSlots = new List<Vector2i>(5) { HelmetSlot, ChestSlot, LegsSlot, ShoulderSlot, UtilitySlot }; public static List<Vector2i> QuickSlots = new List<Vector2i>(3) { QuickSlot1, QuickSlot2, QuickSlot3 }; public static bool OnMenuLoad = false; public static bool IsPurchasingItem = false; public static bool ShouldRefreshPlayerGrid { get; set; } public static void SetupPlayerInventory(Player player) { ((Humanoid)player).m_inventory.m_name = "ComfyQuickSlotsInventory"; ((Humanoid)player).m_inventory.m_width = 8; string s = default(string); if (player.TryGetUniqueKeyValue("invrows", ref s) && int.TryParse(s, out var result)) { SetRows(result + 1); } ((Humanoid)player).m_inventory.m_height = _rows; } public static void RefreshBindings() { ShouldRefreshPlayerGrid = true; } public static void EquipArmorInArmorSlots(Player player) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) foreach (Vector2i armorSlot in ArmorSlots) { ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(armorSlot.x, armorSlot.y); if (itemAt != null) { ((Humanoid)player).EquipItem(itemAt, true); } } } public static void EquipItem(Humanoid humanoid, ItemData item) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Invalid comparison between Unknown and I4 if (item != null) { if ((int)item.m_shared.m_itemType == 6) { humanoid.m_helmetItem = item; } else if ((int)item.m_shared.m_itemType == 7) { humanoid.m_chestItem = item; } else if ((int)item.m_shared.m_itemType == 11) { humanoid.m_legItem = item; } else if ((int)item.m_shared.m_itemType == 17) { humanoid.m_shoulderItem = item; } else if ((int)item.m_shared.m_itemType == 18) { humanoid.m_utilityItem = item; } item.m_equipped = true; humanoid.SetupEquipment(); humanoid.TriggerEquipEffect(item); } } public static ItemData GetArmorItemToSwap(Humanoid humanoid, ItemData item) { //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_000e: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType <= 7) { if ((int)itemType == 6) { return humanoid.m_helmetItem; } if ((int)itemType == 7) { return humanoid.m_chestItem; } } else { if ((int)itemType == 11) { return humanoid.m_legItem; } if ((int)itemType == 17) { return humanoid.m_shoulderItem; } if ((int)itemType == 18) { return humanoid.m_utilityItem; } } return null; } public static Vector2i GetArmorSlot(ItemData item) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return ArmorSlots[GetArmorTypeIndex(item)]; } public static int GetArmorSlotIndex(Vector2i loc) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return ArmorSlots.IndexOf(loc); } public static int GetArmorTypeIndex(ItemData item) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return ArmorSlotTypes.IndexOf(item.m_shared.m_itemType); } public static Vector2i GetEmptyInventorySlot(Inventory inventory, bool topFirst) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (topFirst) { Vector2i val = default(Vector2i); for (int i = 0; i < _rows; i++) { for (int j = 0; j < 8; j++) { ((Vector2i)(ref val))..ctor(j, i); if (inventory.GetItemAt(j, i) == null && !IsArmorSlot(val)) { return val; } } } } Vector2i val2 = default(Vector2i); for (int num = _rows - 1; num >= 0; num--) { for (int k = 0; k < 8; k++) { ((Vector2i)(ref val2))..ctor(k, num); if (inventory.GetItemAt(k, num) == null && !IsArmorSlot(val2)) { return val2; } } } return new Vector2i(-1, -1); } public static List<ItemData> GetItemsInExtendedSlots(Inventory inventory) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_006f: Unknown result type (might be due to invalid IL or missing references) List<ItemData> list = new List<ItemData>(); foreach (Vector2i armorSlot in ArmorSlots) { ItemData itemAt = inventory.GetItemAt(armorSlot.x, armorSlot.y); if (itemAt != null) { list.Add(itemAt); } } foreach (Vector2i quickSlot in QuickSlots) { ItemData itemAt2 = inventory.GetItemAt(quickSlot.x, quickSlot.y); if (itemAt2 != null) { list.Add(itemAt2); } } return list; } public static bool IsArmor(ItemData item) { //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_000e: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType <= 7) { if ((int)itemType == 6) { return true; } if ((int)itemType == 7) { return true; } } else { if ((int)itemType == 11) { return true; } if ((int)itemType == 17) { return true; } if ((int)itemType == 18) { return true; } } return false; } public static bool IsArmorSlot(Vector2i loc) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (ArmorSlots.Contains(loc)) { return true; } return false; } public static bool IsArmorTypeEquipped(Humanoid humanoid, ItemData item) { //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_000e: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; if ((int)itemType <= 7) { if ((int)itemType == 6) { return humanoid.m_helmetItem != null; } if ((int)itemType == 7) { return humanoid.m_chestItem != null; } } else { if ((int)itemType == 11) { return humanoid.m_legItem != null; } if ((int)itemType == 17) { return humanoid.m_shoulderItem != null; } if ((int)itemType == 18) { return humanoid.m_utilityItem != null; } } return false; } public static int ItemCountInInventory(Inventory inventory, ItemData item) { string name = item.m_shared.m_name; int num = 0; for (int i = 0; i < _rows; i++) { for (int j = 0; j < 8; j++) { ItemData itemAt = inventory.GetItemAt(j, i); if (itemAt != null && itemAt.m_shared.m_name == name) { num++; } } } return num; } public static void LoadSavedData(Player player) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown foreach (ItemData item in ((Humanoid)player).GetInventory().m_inventory) { if (item.IsEquipable() && !IsArmor(item) && item.m_equipped) { ((Humanoid)player).EquipItem(item, true); } } if (player.m_knownTexts.ContainsKey("ComfyQuickSlotsInventory")) { ((Humanoid)player).m_helmetItem = null; ((Humanoid)player).m_chestItem = null; ((Humanoid)player).m_legItem = null; ((Humanoid)player).m_shoulderItem = null; ((Humanoid)player).m_utilityItem = null; ((Humanoid)player).m_rightItem = null; ((Humanoid)player).m_leftItem = null; ((Humanoid)player).m_ammoItem = null; ((Humanoid)player).m_trinketItem = null; ((Humanoid)player).GetInventory().Load(new ZPackage(player.m_knownTexts["ComfyQuickSlotsInventory"])); EquipArmorInArmorSlots(player); foreach (ItemData item2 in ((Humanoid)player).GetInventory().m_inventory) { if (item2.IsEquipable() && !IsArmor(item2) && item2.m_equipped) { ((Humanoid)player).EquipItem(item2, true); } } ((Humanoid)player).GetInventory().Changed(false, false); return; } FirstLoad = true; foreach (ItemData item3 in ((Humanoid)player).m_inventory.m_inventory.Where((ItemData x) => x.m_equipped && IsArmor(x)).ToList()) { ((Humanoid)player).EquipItem(item3, true); } MoveEquippedArmorToArmorSlots(); ((Humanoid)player).GetInventory().Changed(false, false); } public static void MoveArmorItemToSlot(Humanoid humanoid, ItemData item, int x, int y) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (item == null) { return; } ItemData itemAt = humanoid.GetInventory().GetItemAt(x, y); if (itemAt != null && !((object)itemAt).Equals((object?)item)) { SwapArmorItems(humanoid, item, itemAt, x, y); return; } item.m_gridPos = new Vector2i(x, y); if (!humanoid.GetInventory().m_inventory.Contains(item)) { humanoid.GetInventory().AddItem(item); humanoid.GetInventory().Changed(false, false); } } public static void MoveEquippedArmorToArmorSlots() { if (!((Object)(object)Player.m_localPlayer == (Object)null)) { MoveArmorItemToSlot((Humanoid)(object)Player.m_localPlayer, ((Humanoid)Player.m_localPlayer).m_helmetItem, HelmetSlot.x, HelmetSlot.y); MoveArmorItemToSlot((Humanoid)(object)Player.m_localPlayer, ((Humanoid)Player.m_localPlayer).m_chestItem, ChestSlot.x, ChestSlot.y); MoveArmorItemToSlot((Humanoid)(object)Player.m_localPlayer, ((Humanoid)Player.m_localPlayer).m_legItem, LegsSlot.x, LegsSlot.y); MoveArmorItemToSlot((Humanoid)(object)Player.m_localPlayer, ((Humanoid)Player.m_localPlayer).m_shoulderItem, ShoulderSlot.x, ShoulderSlot.y); MoveArmorItemToSlot((Humanoid)(object)Player.m_localPlayer, ((Humanoid)Player.m_localPlayer).m_utilityItem, UtilitySlot.x, UtilitySlot.y); } } public static void MoveQuickSlotItems(Player player) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || ((Humanoid)player).GetInventory() == null) { return; } foreach (Vector2i quickSlot in QuickSlots) { ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(quickSlot.x, quickSlot.y - 1); if (itemAt != null) { itemAt.m_gridPos = quickSlot; } } ((Humanoid)player).GetInventory().Changed(false, false); } public static bool Save(Player player) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); val.Write(110); val.Write((ushort)((Humanoid)player).GetInventory().m_inventory.Count); foreach (ItemData item in ((Humanoid)player).GetInventory().m_inventory) { item.Save(val); } if (player.m_knownTexts.ContainsKey("ComfyQuickSlotsInventory")) { player.m_knownTexts["ComfyQuickSlotsInventory"] = val.GetBase64(); } else { player.m_knownTexts.Add("ComfyQuickSlotsInventory", val.GetBase64()); } return true; } public static bool SwapArmorItems(Humanoid humanoid, ItemData itemToMove, ItemData itemInArmorSlot, int armorSlotX, int armorSlotY) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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) Vector2i gridPos = itemToMove.m_gridPos; itemToMove.m_gridPos = new Vector2i(armorSlotX, armorSlotY); itemInArmorSlot.m_gridPos = gridPos; humanoid.GetInventory().Changed(false, false); return false; } public static bool UnequipAllArmor(Player player) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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) Inventory inventory = ((Humanoid)player).GetInventory(); foreach (Vector2i armorSlot in ArmorSlots) { ItemData itemAt = inventory.GetItemAt(armorSlot.x, armorSlot.y); if (itemAt != null) { UnequipItem((Humanoid)(object)player, itemAt); } } return true; } public static bool UnequipItem(Humanoid player, ItemData item) { if (player.m_helmetItem == item) { player.m_helmetItem = null; item.m_equipped = false; player.SetupEquipment(); player.TriggerEquipEffect(item); return true; } if (player.m_chestItem == item) { player.m_chestItem = null; item.m_equipped = false; player.SetupEquipment(); player.TriggerEquipEffect(item); return true; } if (player.m_legItem == item) { player.m_legItem = null; item.m_equipped = false; player.SetupEquipment(); player.TriggerEquipEffect(item); return true; } if (player.m_shoulderItem == item) { player.m_shoulderItem = null; item.m_equipped = false; player.SetupEquipment(); player.TriggerEquipEffect(item); return true; } if (player.m_utilityItem == item) { player.m_utilityItem = null; item.m_equipped = false; player.SetupEquipment(); player.TriggerEquipEffect(item); return true; } return false; } public static bool CanAddItem(Inventory inventory, ItemData item, int stack) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) int num = inventory.m_width * inventory.m_height - 5; int num2 = 0; string name = item.m_shared.m_name; int worldLevel = item.m_worldLevel; foreach (ItemData item2 in inventory.m_inventory) { if (!IsArmorSlot(item2.m_gridPos)) { num--; if (item2.m_shared.m_name == name && item2.m_worldLevel == worldLevel) { num2 += item2.m_shared.m_maxStackSize - item2.m_stack; } } } if (stack <= 0) { stack = item.m_stack; } if (num <= 0) { return num2 + num * item.m_shared.m_maxStackSize >= stack; } return true; } public static bool HasEmptyNonEquipmentSlot(Inventory inventory) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) int num = inventory.m_width * inventory.m_height - 5; foreach (ItemData item in inventory.m_inventory) { if (!IsArmorSlot(item.m_gridPos)) { num--; } } return num > 0; } public static int FindFreeNonEquipmentStackSpace(Inventory inventory, string itemName, int worldLevel) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) int num = 0; foreach (ItemData item in inventory.m_inventory) { if (!IsArmorSlot(item.m_gridPos) && item.m_shared.m_name == itemName && item.m_worldLevel == worldLevel) { num += item.m_shared.m_maxStackSize - item.m_stack; } } return num; } public static int GetEmptyInventorySlots(Inventory inventory) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) int num = inventory.m_width * inventory.m_height - 5; foreach (ItemData item in inventory.m_inventory) { if (!IsArmorSlot(item.m_gridPos)) { num--; } } return num; } public static int GetRows() { return _rows; } public static int GetRowIndex() { return _rows - 1; } public static void SetRows(int rows) { _rows = rows; PositionQuickslots(); } public static void PositionQuickslots() { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) HelmetSlot = new Vector2i(0, GetRowIndex()); ChestSlot = new Vector2i(1, GetRowIndex()); LegsSlot = new Vector2i(2, GetRowIndex()); ShoulderSlot = new Vector2i(3, GetRowIndex()); UtilitySlot = new Vector2i(4, GetRowIndex()); QuickSlot1 = new Vector2i(5, GetRowIndex()); QuickSlot2 = new Vector2i(6, GetRowIndex()); QuickSlot3 = new Vector2i(7, GetRowIndex()); ArmorSlots = new List<Vector2i>(5) { HelmetSlot, ChestSlot, LegsSlot, ShoulderSlot, UtilitySlot }; QuickSlots = new List<Vector2i>(3) { QuickSlot1, QuickSlot2, QuickSlot3 }; } } public static class InventoryLogger { public static readonly string InventoryCsvHeaderRow = string.Join(",", "name", "crafterId", "crafterName", "gridpos.x", "gridpos.y", "quality", "stack", "variant"); public static void LogInventoryToFile(Inventory inventory, string filename) { using StreamWriter streamWriter = File.CreateText(filename); streamWriter.AutoFlush = true; streamWriter.WriteLine(InventoryCsvHeaderRow); foreach (ItemData item in inventory.m_inventory) { streamWriter.WriteLine(ItemToCsvRow(item)); } } private static string ItemToCsvRow(ItemData item) { return string.Join(",", EscapeCsvField(item.m_shared.m_name), item.m_crafterID, EscapeCsvField(item.m_crafterName), item.m_gridPos.x, item.m_gridPos.y, item.m_quality, item.m_stack, item.m_variant); } private static string EscapeCsvField(string valueToEscape) { if (valueToEscape.Contains(",")) { return "\"" + valueToEscape + "\""; } return valueToEscape; } } public static class KeyCodeUtils { public static readonly Dictionary<KeyCode, string> KeyCodeToShortText = new Dictionary<KeyCode, string> { { (KeyCode)97, "A" }, { (KeyCode)98, "B" }, { (KeyCode)99, "C" }, { (KeyCode)100, "D" }, { (KeyCode)101, "E" }, { (KeyCode)102, "F" }, { (KeyCode)103, "G" }, { (KeyCode)104, "H" }, { (KeyCode)105, "I" }, { (KeyCode)106, "J" }, { (KeyCode)107, "K" }, { (KeyCode)108, "L" }, { (KeyCode)109, "M" }, { (KeyCode)110, "N" }, { (KeyCode)111, "O" }, { (KeyCode)112, "P" }, { (KeyCode)113, "Q" }, { (KeyCode)114, "R" }, { (KeyCode)115, "S" }, { (KeyCode)116, "T" }, { (KeyCode)117, "U" }, { (KeyCode)118, "V" }, { (KeyCode)119, "W" }, { (KeyCode)120, "X" }, { (KeyCode)121, "Y" }, { (KeyCode)122, "Z" }, { (KeyCode)257, "kp1" }, { (KeyCode)258, "kp2" }, { (KeyCode)259, "kp3" }, { (KeyCode)260, "kp4" }, { (KeyCode)261, "kp5" }, { (KeyCode)262, "kp6" }, { (KeyCode)263, "kp7" }, { (KeyCode)264, "kp8" }, { (KeyCode)265, "kp9" }, { (KeyCode)256, "kp10" }, { (KeyCode)33, "!" }, { (KeyCode)34, "\"" }, { (KeyCode)35, "#" }, { (KeyCode)36, "$" }, { (KeyCode)38, "&" }, { (KeyCode)39, "'" }, { (KeyCode)40, "(" }, { (KeyCode)41, ")" }, { (KeyCode)42, "*" }, { (KeyCode)43, "+" }, { (KeyCode)44, "," }, { (KeyCode)45, "-" }, { (KeyCode)46, "." }, { (KeyCode)47, "/" }, { (KeyCode)58, ":" }, { (KeyCode)59, ";" }, { (KeyCode)60, "<" }, { (KeyCode)61, "=" }, { (KeyCode)62, ">" }, { (KeyCode)63, "?" }, { (KeyCode)64, "@" }, { (KeyCode)91, "[" }, { (KeyCode)92, "\\" }, { (KeyCode)93, "]" }, { (KeyCode)94, "^" }, { (KeyCode)95, "_" }, { (KeyCode)96, "`" }, { (KeyCode)49, "1" }, { (KeyCode)50, "2" }, { (KeyCode)51, "3" }, { (KeyCode)52, "4" }, { (KeyCode)53, "5" }, { (KeyCode)54, "6" }, { (KeyCode)55, "7" }, { (KeyCode)56, "8" }, { (KeyCode)57, "9" }, { (KeyCode)48, "0" }, { (KeyCode)266, "kp ." }, { (KeyCode)267, "kp //" }, { (KeyCode)268, "kp *" }, { (KeyCode)269, "kp -" }, { (KeyCode)270, "kp +" }, { (KeyCode)272, "kp =" } }; public unsafe static string ToShortString(this KeyCode keyCode) { //IL_0005: 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) if (!KeyCodeToShortText.ContainsKey(keyCode)) { return ((object)(*(KeyCode*)(&keyCode))/*cast due to .constrained prefix*/).ToString(); } return KeyCodeToShortText[keyCode]; } public static string ToShortString(this KeyboardShortcut keyboardShortcut) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) return string.Join(" + ", ((KeyboardShortcut)(ref keyboardShortcut)).Modifiers.Concat(Enumerable.Repeat<KeyCode>(((KeyboardShortcut)(ref keyboardShortcut)).MainKey, 1)).Select(ToShortString)); } } [HarmonyPatch(typeof(FejdStartup))] internal static class FejdStartupPatch { [HarmonyPrefix] [HarmonyPatch("SetupCharacterPreview")] private static void SetupCharacterPreviewPrefix() { QuickSlotsManager.FirstLoad = false; } } [HarmonyPatch(typeof(HotkeyBar))] internal static class HotkeyBarPatch { [HarmonyPrefix] [HarmonyPatch("UpdateIcons")] private static bool HotkeyBarPrefix(HotkeyBar __instance, Player player) { //IL_005e: 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_007b: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) if (((Object)__instance).name != "QuickSlotsHotkeyBar") { return true; } if (__instance.m_elements == null) { return false; } HotkeyBarManager.ResetHotkeyTexts(); if ((Object)(object)player == (Object)null || ((Character)player).IsDead() || !PluginConfig.EnableQuickslots.Value || __instance.m_items == null) { return false; } HotkeyBarManager.RemoveElements(__instance); HotkeyBarManager.ResetItems(__instance, player); for (int i = 0; i < 3; i++) { ElementData val = new ElementData { m_go = Object.Instantiate<GameObject>(__instance.m_elementPrefab, ((Component)__instance).transform) }; val.m_go.transform.localPosition = new Vector3((float)i * __instance.m_elementSpace, 0f, 0f); val.m_icon = ((Component)((Component)val.m_go.transform).transform.Find("icon")).GetComponent<Image>(); val.m_durability = ((Component)val.m_go.transform.Find("durability")).GetComponent<GuiBar>(); val.m_amount = ((Component)val.m_go.transform.Find("amount")).GetComponent<TMP_Text>(); val.m_equiped = ((Component)val.m_go.transform.Find("equiped")).gameObject; val.m_queued = ((Component)val.m_go.transform.Find("queued")).gameObject; val.m_selection = ((Component)val.m_go.transform.Find("selected")).gameObject; TMP_Text component = ((Component)val.m_go.transform.Find("binding")).GetComponent<TMP_Text>(); ((Behaviour)component).enabled = true; component.text = HotkeyBarManager.HotkeyTexts[i]; __instance.m_elements.Add(val); } foreach (ElementData element in __instance.m_elements) { element.m_used = false; } bool flag = ZInput.IsGamepadActive(); foreach (ItemData item in __instance.m_items) { ElementData val2 = __instance.m_elements[item.m_gridPos.x - 5]; val2.m_used = true; ((Component)val2.m_icon).gameObject.SetActive(true); val2.m_icon.sprite = item.GetIcon(); ((Component)val2.m_durability).gameObject.SetActive(item.m_shared.m_useDurability); if (item.m_shared.m_useDurability) { if ((double)item.m_durability <= 0.0) { val2.m_durability.SetValue(1f); val2.m_durability.SetColor((Color)(((double)Mathf.Sin(Time.time * 10f) > 0.0) ? Color.red : new Color(0f, 0f, 0f, 0f))); } else { val2.m_durability.SetValue(item.GetDurabilityPercentage()); val2.m_durability.ResetColor(); } } val2.m_equiped.SetActive(item.m_equipped); val2.m_queued.SetActive(player.IsEquipActionQueued(item)); if (item.m_shared.m_maxStackSize > 1) { ((Component)val2.m_amount).gameObject.SetActive(true); val2.m_amount.text = item.m_stack + "/" + item.m_shared.m_maxStackSize; } else { ((Component)val2.m_amount).gameObject.SetActive(false); } } for (int j = 0; j < __instance.m_elements.Count; j++) { ElementData val3 = __instance.m_elements[j]; val3.m_selection.SetActive(flag && j == __instance.m_selected); if (!val3.m_used) { ((Component)val3.m_icon).gameObject.SetActive(false); ((Component)val3.m_durability).gameObject.SetActive(false); val3.m_equiped.SetActive(false); val3.m_queued.SetActive(false); ((Component)val3.m_amount).gameObject.SetActive(false); } } return false; } } [HarmonyPatch(typeof(Hud))] internal static class HudPatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(Hud __instance) { HotkeyBarManager.QuickSlotsHotkeyBar = ((Component)__instance).GetComponentInChildren<HotkeyBar>(); } [HarmonyPostfix] [HarmonyPatch("Update")] private static void UpdatePostfix(Hud __instance) { if (PluginConfig.IsModEnabled.Value && PluginConfig.EnableQuickslots.Value && !Object.op_Implicit((Object)(object)HotkeyBarManager.QuickSlotsHotkeyBarGameObject)) { HotkeyBarManager.CreateHotkeyBarGameObject(__instance); } } } [HarmonyPatch(typeof(Humanoid))] internal static class HumanoidPatch { [HarmonyPrefix] [HarmonyPatch("EquipItem")] private static bool EquipItemPrefix(Humanoid __instance, ref bool __result, ItemData item) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0033: 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) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) if (!QuickSlotsManager.IsArmor(item)) { return true; } Vector2i armorSlot = QuickSlotsManager.GetArmorSlot(item); if (QuickSlotsManager.IsArmorTypeEquipped(__instance, item)) { ItemData armorItemToSwap = QuickSlotsManager.GetArmorItemToSwap(__instance, item); QuickSlotsManager.UnequipItem(__instance, armorItemToSwap); QuickSlotsManager.EquipItem(__instance, item); QuickSlotsManager.MoveArmorItemToSlot(__instance, item, armorSlot.x, armorSlot.y); __result = true; return false; } QuickSlotsManager.EquipItem(__instance, item); if (item.m_gridPos.x != armorSlot.x || item.m_gridPos.y != armorSlot.y) { QuickSlotsManager.MoveArmorItemToSlot(__instance, item, armorSlot.x, armorSlot.y); } __result = true; return false; } [HarmonyPostfix] [HarmonyPatch("EquipItem")] private static void EquipItemPostfix(Humanoid __instance, ItemData item) { if ((Object)(object)__instance != (Object)null && item != null) { __instance.GetInventory().Changed(false, false); } } [HarmonyPrefix] [HarmonyPatch("UnequipItem")] private static bool UnequipItemPrefix(Humanoid __instance, ItemData item, bool triggerEquipEffects) { //IL_0042: 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_004a: 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) if (item == null) { return true; } if (QuickSlotsManager.IsArmor(item) && item.m_equipped) { if (!QuickSlotsManager.HasEmptyNonEquipmentSlot(__instance.GetInventory())) { ((Character)__instance).Message((MessageType)2, "Inventory full. Item not unequipped.", 0, (Sprite)null, false); return false; } QuickSlotsManager.UnequipItem(__instance, item); Vector2i emptyInventorySlot = QuickSlotsManager.GetEmptyInventorySlot(__instance.GetInventory(), topFirst: true); QuickSlotsManager.MoveArmorItemToSlot(__instance, item, emptyInventorySlot.x, emptyInventorySlot.y); return false; } return true; } } [HarmonyPatch(typeof(InventoryGrid))] internal static class InventoryGridPatch { [HarmonyPostfix] [HarmonyPatch("UpdateInventory")] private static void UpdateInventoryPostfix(InventoryGrid __instance) { if ((Object)(object)__instance == (Object)(object)InventoryGui.m_instance.m_playerGrid && QuickSlotsManager.ShouldRefreshPlayerGrid) { UpdatePlayerGrid(__instance); } } private static void UpdatePlayerGrid(InventoryGrid inventoryGrid) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) if (inventoryGrid.m_elements.Count >= QuickSlotsManager.GetRowIndex() * 8 + 2) { QuickSlotsManager.ShouldRefreshPlayerGrid = false; SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8], "Head"); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 1], "Chest"); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 2], "Legs"); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 3], "Cape"); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 4], "Util"); if (PluginConfig.EnableQuickslots.Value) { SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 5], PluginConfig.QuickSlot1.Value.ToShortString()); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 6], PluginConfig.QuickSlot2.Value.ToShortString()); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 7], PluginConfig.QuickSlot3.Value.ToShortString()); } else { SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 5], string.Empty, enabled: false); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 6], string.Empty, enabled: false); SetupBindingLabel(inventoryGrid.m_elements[QuickSlotsManager.GetRowIndex() * 8 + 7], string.Empty, enabled: false); } } } private static void SetupBindingLabel(InventoryElement element, string text, bool enabled = true) { Transform val = ((Component)element).gameObject.transform.Find("binding"); TMP_Text val2 = default(TMP_Text); if (Object.op_Implicit((Object)(object)val) && ((Component)val).TryGetComponent<TMP_Text>(ref val2)) { val2.text = text; ((Behaviour)val2).enabled = enabled; val2.fontSize = 12f; val2.alignment = (TextAlignmentOptions)257; val2.overflowMode = (TextOverflowModes)0; val2.textWrappingMode = (TextWrappingModes)0; } } } [HarmonyPatch(typeof(InventoryGui))] internal static class InventoryGuiPatch { [HarmonyPostfix] [HarmonyPatch("Show")] private static void ShowPostfix(InventoryGui __instance) { if (Object.op_Implicit((Object)(object)__instance.m_currentContainer)) { SetContainerGridAnchoredPosition(__instance); } QuickSlotsManager.RefreshBindings(); } [HarmonyPostfix] [HarmonyPatch("SetInventorySize")] private static void SetInventorySize(InventoryGui __instance, int rows) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) QuickSlotsManager.SetRows(rows + 1); ((Humanoid)Player.m_localPlayer).m_inventory.m_height = QuickSlotsManager.GetRows(); __instance.m_player.sizeDelta = new Vector2(__instance.m_player.sizeDelta.x, __instance.m_playerHeight + (float)(QuickSlotsManager.GetRows() - 4) * __instance.m_invGridHeight); } private static void SetContainerGridAnchoredPosition(InventoryGui inventoryGui) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) RectTransform val = default(RectTransform); if (((Component)((Component)inventoryGui.m_containerGrid).transform.parent).TryGetComponent<RectTransform>(ref val)) { val.anchoredPosition = PluginConfig.ContainerInventoryGridAnchoredPosition.Value; } } [HarmonyPrefix] [HarmonyPatch("OnSelectedItem")] private static bool OnSelectedItemPrefix(InventoryGrid grid, ItemData item, Vector2i pos) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (grid.m_inventory.m_name != "ComfyQuickSlotsInventory") { return true; } if (QuickSlotsManager.IsArmorSlot(pos) || Player.m_localPlayer.IsEquipActionQueued(item)) { return false; } return true; } [HarmonyPrefix] [HarmonyPatch("OnCraftPressed")] private static bool OnCraftPressedPrefix(InventoryGui __instance) { ItemData itemData = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).ItemData; if (itemData != null && itemData.m_equipped && !QuickSlotsManager.HasEmptyNonEquipmentSlot(((Humanoid)Player.m_localPlayer).GetInventory()) && QuickSlotsManager.ItemCountInInventory(((Humanoid)Player.m_localPlayer).GetInventory(), itemData) >= 1) { ((Character)Player.m_localPlayer).Message((MessageType)2, "Inventory full. Make room to upgrade equipped item.", 0, (Sprite)null, false); return false; } return true; } } [HarmonyPatch(typeof(Inventory))] internal static class InventoryPatch { [HarmonyPrefix] [HarmonyPatch("AddItem", new Type[] { typeof(ItemData), typeof(int), typeof(int), typeof(int), typeof(bool) })] private static bool AddItemPrefix(Inventory __instance, ItemData item, int amount, int x, int y, bool skipValidPositionCheck) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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) //IL_006b: Unknown result type (might be due to invalid IL or missing references) if (item == null || __instance.m_name != "ComfyQuickSlotsInventory") { return true; } if (QuickSlotsManager.FirstLoad && QuickSlotsManager.IsArmor(item) && item.m_equipped) { return true; } if (item.m_equipped && QuickSlotsManager.IsArmor(item) && (Object)(object)Player.m_localPlayer != (Object)null) { QuickSlotsManager.UnequipItem((Humanoid)(object)Player.m_localPlayer, item); Vector2i armorSlot = QuickSlotsManager.GetArmorSlot(item); if (x == armorSlot.x && y == armorSlot.y) { return true; } return false; } if ((Object)(object)Player.m_localPlayer == (Object)null) { return true; } if (QuickSlotsManager.IsArmorSlot(new Vector2i(x, y))) { return false; } return true; } [HarmonyPrefix] [HarmonyPatch("AddItem", new Type[] { typeof(string), typeof(int), typeof(int), typeof(int), typeof(long), typeof(string), typeof(Vector2i), typeof(bool), typeof(bool), typeof(bool) })] private static void AddItemStringIntIntIntLongStringVector2iBoolPrefix(Inventory __instance, ref Vector2i position) { //IL_0013: 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_0028: Unknown result type (might be due to invalid IL or missing references) if (!(__instance.m_name != "ComfyQuickSlotsInventory") && QuickSlotsManager.IsArmorSlot(position)) { position = new Vector2i(-1, -1); } } [HarmonyPrefix] [HarmonyPatch("MoveItemToThis", new Type[] { typeof(Inventory), typeof(ItemData), typeof(int), typeof(int), typeof(int) })] private static bool MoveItemToThisPrefix(Inventory __instance, ref bool __result, int x, int y) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (__instance.m_name != "ComfyQuickSlotsInventory" || !QuickSlotsManager.IsArmorSlot(new Vector2i(x, y))) { return true; } return false; } [HarmonyPrefix] [HarmonyPatch("FindEmptySlot")] private static bool FindEmptySlotPrefix(Inventory __instance, ref Vector2i __result, bool topFirst) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (__instance.m_name == "ComfyQuickSlotsInventory") { __result = QuickSlotsManager.GetEmptyInventorySlot(__instance, topFirst); return false; } return true; } [HarmonyPrefix] [HarmonyPatch("HaveEmptySlot")] private static bool HaveEmptySlotPrefix(Inventory __instance, ref bool __result) { if (__instance.m_name == "ComfyQuickSlotsInventory") { __result = QuickSlotsManager.HasEmptyNonEquipmentSlot(__instance); return false; } return true; } [HarmonyPrefix] [HarmonyPatch("CanAddItem", new Type[] { typeof(ItemData), typeof(int) })] private static bool CanAddItemPrefix(Inventory __instance, ItemData item, int stack, ref bool __result) { if (__instance == ((Humanoid)Player.m_localPlayer).m_inventory) { __result = QuickSlotsManager.CanAddItem(__instance, item, stack); return false; } return true; } [HarmonyPrefix] [HarmonyPatch("GetEmptySlots")] private static bool GetEmptySlotsPrefix(Inventory __instance, ref int __result) { if (__instance != ((Humanoid)Player.m_localPlayer).m_inventory) { return true; } __result = QuickSlotsManager.GetEmptyInventorySlots(__instance); return false; } [HarmonyPrefix] [HarmonyPatch("FindFreeStackSpace")] private static bool FindFreeStackSpacePrefix(Inventory __instance, string name, float worldLevel, ref int __result) { if (__instance == ((Humanoid)Player.m_localPlayer).m_inventory) { __result = QuickSlotsManager.FindFreeNonEquipmentStackSpace(__instance, name, Mathf.RoundToInt(worldLevel)); return false; } return true; } } [HarmonyPatch(typeof(Player))] internal static class PlayerPatch { [HarmonyPrefix] [HarmonyPatch("Awake")] private static void AwakePrefix(Player __instance) { ComfyQuickSlots.LogInfo("Setting up player inventory for CQS."); QuickSlotsManager.SetupPlayerInventory(__instance); } [HarmonyPostfix] [HarmonyPatch("Load")] private static void LoadPostFix(Player __instance, ZPackage pkg) { QuickSlotsManager.SetupPlayerInventory(__instance); QuickSlotsManager.LoadSavedData(__instance); } [HarmonyPrefix] [HarmonyPatch("Save")] private static bool SavePrefix(Player __instance) { QuickSlotsManager.FirstLoad = false; return QuickSlotsManager.Save(__instance); } [HarmonyPostfix] [HarmonyPatch("SetInventorySize")] private static void SetInventorySizePostfix(Player __instance, int rows) { QuickSlotsManager.MoveEquippedArmorToArmorSlots(); QuickSlotsManager.ShouldRefreshPlayerGrid = true; if (QuickSlotsManager.IsPurchasingItem) { QuickSlotsManager.MoveQuickSlotItems(__instance); } } [HarmonyPrefix] [HarmonyPatch("UseHotbarItem")] private static bool UseHotbarItemPrefix(Player __instance, int index) { ItemData itemAt = ((Humanoid)__instance).m_inventory.GetItemAt(index - 1, 0); if (__instance.IsEquipActionQueued(itemAt)) { return false; } return true; } [HarmonyPrefix] [HarmonyPatch("CreateTombStone")] private static void CreateTombStonePrefix(Player __instance) { if (!ZoneSystem.instance.GetGlobalKey((GlobalKeys)19) && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)21)) { QuickSlotsManager.UnequipAllArmor(__instance); } } [HarmonyTranspiler] [HarmonyPatch("Save")] private static IEnumerable<CodeInstruction> SaveTranspiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Humanoid), "m_inventory"), (string)null) }).ThrowIfInvalid("Could not patch Player.Save()! (set inventory contents)") .Advance(1) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerPatch), "GetReducedInventory", (Type[])null, (Type[])null)) }) .InstructionEnumeration(); } private static Inventory GetReducedInventory(Inventory inventory) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_003e: 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) if (!PluginConfig.IsModEnabled.Value) { return inventory; } Inventory val = new Inventory("Inventory", (Sprite)null, 8, QuickSlotsManager.GetRows() - 1); foreach (ItemData item in val.m_inventory) { if (!QuickSlotsManager.ArmorSlots.Contains(item.m_gridPos) && !QuickSlotsManager.QuickSlots.Contains(item.m_gridPos)) { val.AddItem(item.Clone()); } } return val; } } [HarmonyPatch(typeof(StoreGui))] internal static class StoreGuiPatch { [HarmonyPrefix] [HarmonyPatch("BuySelectedItem")] private static void BuySelectedItemPrefix() { QuickSlotsManager.IsPurchasingItem = true; } [HarmonyPostfix] [HarmonyPatch("BuySelectedItem")] private static void BuySelectedItemPostfix(StoreGui __instance) { QuickSlotsManager.IsPurchasingItem = false; } } } namespace ComfyLib { public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = null, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = customDrawer, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry<T>)(object)((SettingChangedEventArgs)eventArgs).ChangedSetting); }; } } }