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 EquipmentSheet v0.9.1
EquipmentSheet.dll
Decompiled 15 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Equipment Sheet")] [assembly: AssemblyFileVersion("0.9.1")] [assembly: AssemblyCompany("R4V9N1")] [assembly: AssemblyDescription("Created by R4V9N1")] [assembly: AssemblyProduct("Equipment Sheet")] [assembly: AssemblyCopyright("Created by R4V9N1")] [assembly: AssemblyMetadata("Creator", "Created by R4V9N1")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.9.1.0")] namespace EquipmentSheet; [BepInPlugin("r4v9n1.equipmentsheet", "Equipment Sheet", "0.9.1")] public sealed class EquipmentSheetPlugin : BaseUnityPlugin { private enum SlotKind { Equipment, Food } private sealed class SlotDef { public readonly string Label; public readonly ItemType Type; public readonly SlotKind Kind; public SlotDef(string label, ItemType type) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Label = label; Type = type; Kind = SlotKind.Equipment; } public SlotDef(string label) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) Label = label; Type = (ItemType)0; Kind = SlotKind.Food; } } private sealed class SheetUpgradeTransaction { public Player Player; public Inventory PlayerInventory; public ItemData OriginalItem; public Vector2i SheetPosition; public bool OriginalRemoved; public ItemData ReplacementItem; } public const string PluginGuid = "r4v9n1.equipmentsheet"; public const string PluginName = "Equipment Sheet"; public const string PluginVersion = "0.9.1"; public const string CreatorCredit = "Created by R4V9N1"; private const string CustomDataKey = "is.codex.valheim.equipmentsheet.inventory.v1"; private const string PendingTransferKey = "is.codex.valheim.equipmentsheet.pending-transfer.v1"; private const int SheetColumns = 3; private const int SheetRows = 3; private const int EquipmentSlotCount = 6; private static readonly SlotDef[] Slots = new SlotDef[9] { new SlotDef("Helm", (ItemType)6), new SlotDef("Chest", (ItemType)7), new SlotDef("Legs", (ItemType)11), new SlotDef("Trinket", (ItemType)24), new SlotDef("Back", (ItemType)17), new SlotDef("Belt", (ItemType)18), new SlotDef("Food 1"), new SlotDef("Food 2"), new SlotDef("Food 3") }; private static ConfigEntry<bool> _enabled; private static ConfigEntry<float> _panelGap; private static ConfigEntry<float> _panelExtraRightOffset; private static ManualLogSource _log; private static RectTransform _panel; private static InventoryGrid _grid; private static Inventory _equipmentInventory; private static Image[] _slotFrames; private static Image[] _slotIcons; private static Text[] _slotLabels; private static Text[] _slotAmounts; private static Text[] _slotQualities; private static Image[] _slotDurabilityBacks; private static Image[] _slotDurabilityBars; private static UIInputHandler[] _slotHitboxes; private static UITooltip[] _slotTooltips; private static Vector2 _cellSize = new Vector2(50f, 50f); private static Vector2[] _slotPositions; private static FieldInfo _customDataField; private static FieldInfo _onChangedField; private static FieldInfo _inventoryItemsField; private static FieldInfo _dragGoField; private static FieldInfo _dragItemField; private static FieldInfo _dragInventoryField; private static FieldInfo _dragAmountField; private static FieldInfo _itemEquippedField; private static FieldInfo _gridWidthField; private static FieldInfo _gridHeightField; private static FieldInfo _humanoidChestField; private static FieldInfo _humanoidLegField; private static FieldInfo _humanoidHelmetField; private static FieldInfo _humanoidShoulderField; private static FieldInfo _humanoidUtilityField; private static FieldInfo _humanoidTrinketField; private static FieldInfo _currentContainerField; private static FieldInfo _craftUpgradeItemField; private static MethodInfo _inventoryChangedMethod; private static MethodInfo _setupDragItemMethod; private static MethodInfo _setupEquipmentMethod; private static MethodInfo _createItemTooltipMethod; private static Player _loadedPlayer; private static bool _loadingInventory; private static int _upgradeRecipeScanDepth; private static SheetUpgradeTransaction _sheetUpgradeTransaction; private static readonly List<ItemData> PendingAutoRouteItems = new List<ItemData>(); private static ItemData _manualSheetDragItem; private static float _lastWrongTypeMessageTime = float.NegativeInfinity; private Harmony _harmony; private void Awake() { //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Expected O, but got Unknown _log = ((BaseUnityPlugin)this).Logger; _enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the equipment sheet panel next to the player inventory."); _panelGap = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelGap", 20f, "Horizontal gap (UI units) between the vanilla inventory grid and the equipment panel."); _panelExtraRightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelExtraRightOffset", 60f, "Extra horizontal offset added after PanelGap. Useful when another UI overlaps the equipment panel."); _customDataField = AccessTools.Field(typeof(Player), "m_customData"); _onChangedField = AccessTools.Field(typeof(Inventory), "m_onChanged"); _inventoryItemsField = AccessTools.Field(typeof(Inventory), "m_inventory"); _dragGoField = AccessTools.Field(typeof(InventoryGui), "m_dragGo"); _dragItemField = AccessTools.Field(typeof(InventoryGui), "m_dragItem"); _dragInventoryField = AccessTools.Field(typeof(InventoryGui), "m_dragInventory"); _dragAmountField = AccessTools.Field(typeof(InventoryGui), "m_dragAmount"); _itemEquippedField = AccessTools.Field(typeof(ItemData), "m_equipped"); _gridWidthField = AccessTools.Field(typeof(InventoryGrid), "m_width"); _gridHeightField = AccessTools.Field(typeof(InventoryGrid), "m_height"); _humanoidChestField = AccessTools.Field(typeof(Humanoid), "m_chestItem"); _humanoidLegField = AccessTools.Field(typeof(Humanoid), "m_legItem"); _humanoidHelmetField = AccessTools.Field(typeof(Humanoid), "m_helmetItem"); _humanoidShoulderField = AccessTools.Field(typeof(Humanoid), "m_shoulderItem"); _humanoidUtilityField = AccessTools.Field(typeof(Humanoid), "m_utilityItem"); _humanoidTrinketField = AccessTools.Field(typeof(Humanoid), "m_trinketItem"); _currentContainerField = AccessTools.Field(typeof(InventoryGui), "m_currentContainer"); _craftUpgradeItemField = AccessTools.Field(typeof(InventoryGui), "m_craftUpgradeItem"); _inventoryChangedMethod = AccessTools.Method(typeof(Inventory), "Changed", (Type[])null, (Type[])null); _setupDragItemMethod = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", new Type[3] { typeof(ItemData), typeof(Inventory), typeof(int) }, (Type[])null); _setupEquipmentMethod = AccessTools.Method(typeof(Humanoid), "SetupEquipment", (Type[])null, (Type[])null); _createItemTooltipMethod = AccessTools.Method(typeof(InventoryGrid), "CreateItemTooltip", new Type[2] { typeof(ItemData), typeof(UITooltip) }, (Type[])null); EnsureEquipmentInventory(); _harmony = new Harmony("r4v9n1.equipmentsheet"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Equipment Sheet 0.9.1 loaded."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Created by R4V9N1."); } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); _harmony = null; } } private void Update() { InventoryGui instance = InventoryGui.instance; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer != (Object)(object)_loadedPlayer) { LoadEquipmentInventory(localPlayer); RestorePendingTransfer(localPlayer); _loadedPlayer = localPlayer; } if (_manualSheetDragItem != null && ((Object)(object)instance == (Object)null || _dragItemField == null || _dragItemField.GetValue(instance) != _manualSheetDragItem)) { _manualSheetDragItem = null; } ProcessPendingAutoRouteItems(localPlayer); if (!((Object)(object)_panel == (Object)null) && !((Object)(object)instance == (Object)null) && !((Object)(object)localPlayer == (Object)null)) { bool flag = _enabled != null && _enabled.Value && (Object)(object)instance.m_player != (Object)null && ((Component)instance.m_player).gameObject.activeInHierarchy; if (((Component)_panel).gameObject.activeSelf != flag) { ((Component)_panel).gameObject.SetActive(flag); } if (flag) { UpdateEquipmentGrid(instance, localPlayer); } } } internal static void SetupPanel(InventoryGui gui) { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00b1: 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_00c9: 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_0109: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0518: Unknown result type (might be due to invalid IL or missing references) //IL_051d: Unknown result type (might be due to invalid IL or missing references) //IL_0551: Unknown result type (might be due to invalid IL or missing references) //IL_0556: Unknown result type (might be due to invalid IL or missing references) //IL_0564: Unknown result type (might be due to invalid IL or missing references) //IL_0575: Unknown result type (might be due to invalid IL or missing references) //IL_058a: Unknown result type (might be due to invalid IL or missing references) //IL_059f: Unknown result type (might be due to invalid IL or missing references) //IL_05b1: Unknown result type (might be due to invalid IL or missing references) //IL_05bb: Unknown result type (might be due to invalid IL or missing references) //IL_05e2: Unknown result type (might be due to invalid IL or missing references) //IL_062d: Unknown result type (might be due to invalid IL or missing references) //IL_0632: Unknown result type (might be due to invalid IL or missing references) //IL_0640: Unknown result type (might be due to invalid IL or missing references) //IL_0651: Unknown result type (might be due to invalid IL or missing references) //IL_0666: Unknown result type (might be due to invalid IL or missing references) //IL_067b: Unknown result type (might be due to invalid IL or missing references) //IL_068d: Unknown result type (might be due to invalid IL or missing references) //IL_069c: Unknown result type (might be due to invalid IL or missing references) //IL_06a1: Unknown result type (might be due to invalid IL or missing references) //IL_06ab: Unknown result type (might be due to invalid IL or missing references) //IL_06ba: Unknown result type (might be due to invalid IL or missing references) //IL_06bf: Unknown result type (might be due to invalid IL or missing references) //IL_06d2: Unknown result type (might be due to invalid IL or missing references) //IL_0725: Unknown result type (might be due to invalid IL or missing references) //IL_072a: Unknown result type (might be due to invalid IL or missing references) //IL_0738: Unknown result type (might be due to invalid IL or missing references) //IL_0743: Unknown result type (might be due to invalid IL or missing references) //IL_0754: Unknown result type (might be due to invalid IL or missing references) //IL_0769: Unknown result type (might be due to invalid IL or missing references) //IL_077e: Unknown result type (might be due to invalid IL or missing references) //IL_0790: Unknown result type (might be due to invalid IL or missing references) //IL_079a: Unknown result type (might be due to invalid IL or missing references) //IL_07a4: Unknown result type (might be due to invalid IL or missing references) //IL_07f0: Unknown result type (might be due to invalid IL or missing references) //IL_082c: Unknown result type (might be due to invalid IL or missing references) //IL_0840: Unknown result type (might be due to invalid IL or missing references) //IL_0882: Unknown result type (might be due to invalid IL or missing references) //IL_089d: Unknown result type (might be due to invalid IL or missing references) //IL_08a2: Unknown result type (might be due to invalid IL or missing references) //IL_08dc: Unknown result type (might be due to invalid IL or missing references) //IL_08f6: Unknown result type (might be due to invalid IL or missing references) //IL_08fb: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_panel != (Object)null) && !((Object)(object)gui == (Object)null) && !((Object)(object)gui.m_player == (Object)null) && !((Object)(object)gui.m_playerGrid == (Object)null) && !((Object)(object)gui.m_playerGrid.m_elementPrefab == (Object)null)) { EnsureEquipmentInventory(); RectTransform player = gui.m_player; GameObject val = new GameObject("EquipmentSheetPanel", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(((Transform)player).parent, false); RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = player.anchorMin; component.anchorMax = player.anchorMax; component.pivot = player.pivot; RectTransform component2 = gui.m_playerGrid.m_elementPrefab.GetComponent<RectTransform>(); if ((Object)(object)component2 != (Object)null && component2.sizeDelta.x > 0f && component2.sizeDelta.y > 0f) { _cellSize = component2.sizeDelta; } float num = 3f * _cellSize.x + 8f + 24f; float num2 = 3f * _cellSize.y + 8f + 24f; float num3 = ((_panelGap == null) ? 20f : _panelGap.Value) + ((_panelExtraRightOffset == null) ? 60f : _panelExtraRightOffset.Value); component.sizeDelta = new Vector2(num, num2); Vector2 anchoredPosition = player.anchoredPosition; Rect rect = player.rect; component.anchoredPosition = anchoredPosition + new Vector2(((Rect)(ref rect)).width + num3, 0f); Image val2 = val.AddComponent<Image>(); Image component3 = ((Component)player).GetComponent<Image>(); if ((Object)(object)component3 != (Object)null) { val2.sprite = component3.sprite; val2.type = component3.type; ((Graphic)val2).color = ((Graphic)component3).color; ((Graphic)val2).material = ((Graphic)component3).material; } else { ((Graphic)val2).color = new Color(0f, 0f, 0f, 0.6f); } GameObject val3 = new GameObject("EquipmentSheetGridRoot", new Type[1] { typeof(RectTransform) }); val3.transform.SetParent((Transform)(object)component, false); RectTransform component4 = val3.GetComponent<RectTransform>(); component4.anchorMin = new Vector2(0f, 1f); component4.anchorMax = new Vector2(0f, 1f); component4.pivot = new Vector2(0f, 1f); component4.anchoredPosition = new Vector2(12f, -12f); component4.sizeDelta = new Vector2(3f * _cellSize.x + 8f, 3f * _cellSize.y + 8f); _grid = val3.AddComponent<InventoryGrid>(); _grid.m_elementPrefab = gui.m_playerGrid.m_elementPrefab; _grid.m_gridRoot = component4; if (_gridWidthField != null) { _gridWidthField.SetValue(_grid, 3); } if (_gridHeightField != null) { _gridHeightField.SetValue(_grid, 3); } _grid.m_elementSpace = 4f; _grid.m_tooltipAnchor = gui.m_playerGrid.m_tooltipAnchor; _grid.m_onSelected = delegate(InventoryGrid grid, ItemData item, Vector2i pos, Modifier mod) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) HandleEquipmentGridSelected(gui, grid, item, pos, mod); }; _grid.m_onRightClick = delegate(InventoryGrid grid, ItemData item, Vector2i pos) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) HandleEquipmentGridSelected(gui, grid, item, pos, (Modifier)0); }; _grid.OnMoveToLowerInventoryGrid = gui.m_playerGrid.OnMoveToLowerInventoryGrid; _grid.OnMoveToUpperInventoryGrid = gui.m_playerGrid.OnMoveToUpperInventoryGrid; _grid.m_uiGroup = gui.m_playerGrid.m_uiGroup; _slotPositions = (Vector2[])(object)new Vector2[Slots.Length]; _slotFrames = (Image[])(object)new Image[Slots.Length]; _slotIcons = (Image[])(object)new Image[Slots.Length]; _slotLabels = (Text[])(object)new Text[Slots.Length]; _slotAmounts = (Text[])(object)new Text[Slots.Length]; _slotQualities = (Text[])(object)new Text[Slots.Length]; _slotDurabilityBacks = (Image[])(object)new Image[Slots.Length]; _slotDurabilityBars = (Image[])(object)new Image[Slots.Length]; _slotHitboxes = (UIInputHandler[])(object)new UIInputHandler[Slots.Length]; _slotTooltips = (UITooltip[])(object)new UITooltip[Slots.Length]; Font builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf"); for (int num4 = 0; num4 < Slots.Length; num4++) { int num5 = num4 % 3; int num6 = num4 / 3; _slotPositions[num4] = new Vector2((float)num5 * (_cellSize.x + 4f), (float)(-num6) * (_cellSize.y + 4f)); GameObject val4 = new GameObject("EquipmentSheet_" + Slots[num4].Label + "_Frame", new Type[1] { typeof(RectTransform) }); val4.transform.SetParent((Transform)(object)component4, false); RectTransform component5 = val4.GetComponent<RectTransform>(); component5.anchorMin = new Vector2(0f, 1f); component5.anchorMax = new Vector2(0f, 1f); component5.pivot = new Vector2(0f, 1f); component5.anchoredPosition = _slotPositions[num4]; component5.sizeDelta = _cellSize; Image val5 = val4.AddComponent<Image>(); ((Graphic)val5).color = new Color(0f, 0f, 0f, 0.45f); ((Graphic)val5).raycastTarget = false; _slotFrames[num4] = val5; GameObject val6 = new GameObject("EquipmentSheet_" + Slots[num4].Label + "_Icon", new Type[1] { typeof(RectTransform) }); val6.transform.SetParent((Transform)(object)component4, false); RectTransform component6 = val6.GetComponent<RectTransform>(); component6.anchorMin = new Vector2(0f, 1f); component6.anchorMax = new Vector2(0f, 1f); component6.pivot = new Vector2(0f, 1f); component6.anchoredPosition = _slotPositions[num4] + new Vector2(4f, -4f); component6.sizeDelta = _cellSize - new Vector2(8f, 8f); Image val7 = val6.AddComponent<Image>(); ((Graphic)val7).color = Color.white; val7.preserveAspect = true; ((Graphic)val7).raycastTarget = false; _slotIcons[num4] = val7; GameObject val8 = new GameObject("EquipmentSheet_" + Slots[num4].Label + "_Label", new Type[1] { typeof(RectTransform) }); val8.transform.SetParent((Transform)(object)component4, false); val8.transform.SetAsLastSibling(); RectTransform component7 = val8.GetComponent<RectTransform>(); component7.anchorMin = new Vector2(0f, 1f); component7.anchorMax = new Vector2(0f, 1f); component7.pivot = new Vector2(0f, 1f); component7.anchoredPosition = _slotPositions[num4]; component7.sizeDelta = _cellSize; Text val9 = val8.AddComponent<Text>(); val9.text = Slots[num4].Label; val9.font = builtinResource; val9.fontSize = 12; val9.alignment = (TextAnchor)4; ((Graphic)val9).color = new Color(1f, 1f, 1f, 0.95f); ((Graphic)val9).raycastTarget = false; val9.horizontalOverflow = (HorizontalWrapMode)0; val9.verticalOverflow = (VerticalWrapMode)1; Outline obj = val8.AddComponent<Outline>(); ((Shadow)obj).effectColor = new Color(0f, 0f, 0f, 0.85f); ((Shadow)obj).effectDistance = new Vector2(1f, -1f); _slotLabels[num4] = val9; _slotAmounts[num4] = CreateSlotCornerText(component4, builtinResource, "EquipmentSheet_" + Slots[num4].Label + "_Amount", _slotPositions[num4] + new Vector2(2f, 0f - _cellSize.y + 16f), (TextAnchor)3); _slotQualities[num4] = CreateSlotCornerText(component4, builtinResource, "EquipmentSheet_" + Slots[num4].Label + "_Quality", _slotPositions[num4] + new Vector2(_cellSize.x - 18f, -2f), (TextAnchor)5); CreateSlotDurabilityBar(component4, num4); } CreateSlotHitboxes(component4); _panel = component; val.SetActive(false); if (_log != null) { _log.LogInfo((object)"Equipment Sheet: created persistent equipment inventory panel."); } } } private static void EnsureEquipmentInventory() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown if (_equipmentInventory == null) { _equipmentInventory = new Inventory("Equipment Sheet", (Sprite)null, 3, 3); HookEquipmentInventoryChanged(); } } private static void HookEquipmentInventoryChanged() { if (_equipmentInventory == null || _onChangedField == null) { return; } Action action = _onChangedField.GetValue(_equipmentInventory) as Action; Action action2 = ValidateEquipmentInventory; bool flag = false; if (action != null) { Delegate[] invocationList = action.GetInvocationList(); for (int i = 0; i < invocationList.Length; i++) { if (invocationList[i] == action2) { flag = true; break; } } } if (!flag) { _onChangedField.SetValue(_equipmentInventory, (Action)Delegate.Combine(action, action2)); } } private static void UpdateEquipmentGrid(InventoryGui gui, Player player) { if (!((Object)(object)_grid == (Object)null) && _equipmentInventory != null) { UpdateSlotVisuals(); } } private static Text CreateSlotCornerText(RectTransform parent, Font font, string name, Vector2 position, TextAnchor anchor) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0038: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_00a5: 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) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent((Transform)(object)parent, false); RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(0f, 1f); component.pivot = new Vector2(0f, 1f); component.anchoredPosition = position; component.sizeDelta = new Vector2(16f, 14f); Text obj = val.AddComponent<Text>(); obj.font = font; obj.fontSize = 10; obj.alignment = anchor; ((Graphic)obj).color = Color.white; ((Graphic)obj).raycastTarget = false; Outline obj2 = val.AddComponent<Outline>(); ((Shadow)obj2).effectColor = new Color(0f, 0f, 0f, 0.85f); ((Shadow)obj2).effectDistance = new Vector2(1f, -1f); return obj; } private static void CreateSlotDurabilityBar(RectTransform parent, int slot) { //IL_002e: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0157: 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_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019e: 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_01ba: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("EquipmentSheet_" + Slots[slot].Label + "_DurabilityBack", new Type[1] { typeof(RectTransform) }); val.transform.SetParent((Transform)(object)parent, false); RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(0f, 1f); component.pivot = new Vector2(0f, 1f); component.anchoredPosition = _slotPositions[slot] + new Vector2(4f, 0f - _cellSize.y + 7f); component.sizeDelta = new Vector2(_cellSize.x - 8f, 4f); Image val2 = val.AddComponent<Image>(); ((Graphic)val2).color = new Color(0f, 0f, 0f, 0.8f); ((Graphic)val2).raycastTarget = false; ((Component)val2).gameObject.SetActive(false); _slotDurabilityBacks[slot] = val2; GameObject val3 = new GameObject("EquipmentSheet_" + Slots[slot].Label + "_DurabilityBar", new Type[1] { typeof(RectTransform) }); val3.transform.SetParent((Transform)(object)parent, false); RectTransform component2 = val3.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0f, 1f); component2.anchorMax = new Vector2(0f, 1f); component2.pivot = new Vector2(0f, 1f); component2.anchoredPosition = component.anchoredPosition; component2.sizeDelta = component.sizeDelta; Image val4 = val3.AddComponent<Image>(); ((Graphic)val4).color = Color.green; ((Graphic)val4).raycastTarget = false; ((Component)val4).gameObject.SetActive(false); _slotDurabilityBars[slot] = val4; } private static void UpdateSlotVisuals() { //IL_003a: 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) //IL_0260: Unknown result type (might be due to invalid IL or missing references) if (_slotLabels == null) { return; } Vector2i val = default(Vector2i); for (int i = 0; i < _slotLabels.Length; i++) { if ((Object)(object)_slotLabels[i] == (Object)null) { continue; } ((Vector2i)(ref val))..ctor(i % 3, i / 3); ItemData val2 = ((_equipmentInventory == null) ? null : _equipmentInventory.GetItemAt(val.x, val.y)); bool flag = val2 != null && val2.m_shared != null; _slotLabels[i].text = Slots[i].Label; ((Component)_slotLabels[i]).gameObject.SetActive(!flag); ((Component)_slotLabels[i]).transform.SetAsLastSibling(); if (_slotIcons != null && i < _slotIcons.Length && (Object)(object)_slotIcons[i] != (Object)null) { _slotIcons[i].sprite = (flag ? val2.GetIcon() : null); ((Component)_slotIcons[i]).gameObject.SetActive(flag); ((Component)_slotIcons[i]).transform.SetAsLastSibling(); } if (_slotAmounts != null && i < _slotAmounts.Length && (Object)(object)_slotAmounts[i] != (Object)null) { _slotAmounts[i].text = ((flag && val2.m_stack > 1) ? val2.m_stack.ToString() : ""); ((Component)_slotAmounts[i]).gameObject.SetActive(flag && val2.m_stack > 1); ((Component)_slotAmounts[i]).transform.SetAsLastSibling(); } if (_slotQualities != null && i < _slotQualities.Length && (Object)(object)_slotQualities[i] != (Object)null) { _slotQualities[i].text = ((flag && val2.m_quality > 1) ? val2.m_quality.ToString() : ""); ((Component)_slotQualities[i]).gameObject.SetActive(flag && val2.m_quality > 1); ((Component)_slotQualities[i]).transform.SetAsLastSibling(); } UpdateSlotDurability(i, val2, flag); if (_slotTooltips != null && i < _slotTooltips.Length && (Object)(object)_slotTooltips[i] != (Object)null) { if (flag && (Object)(object)_grid != (Object)null) { SetSlotTooltip(val2, _slotTooltips[i]); } else { _slotTooltips[i].Set("", "", ((Object)(object)_grid == (Object)null) ? null : _grid.m_tooltipAnchor, Vector2.zero); } } if (_slotHitboxes != null && i < _slotHitboxes.Length && (Object)(object)_slotHitboxes[i] != (Object)null) { ((Component)_slotHitboxes[i]).transform.SetAsLastSibling(); } } } private static void UpdateSlotDurability(int slot, ItemData item, bool hasItem) { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0120: 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) bool flag = hasItem && item.m_shared != null && item.m_shared.m_useDurability && item.GetMaxDurability() > 0f; if (_slotDurabilityBacks != null && slot < _slotDurabilityBacks.Length && (Object)(object)_slotDurabilityBacks[slot] != (Object)null) { ((Component)_slotDurabilityBacks[slot]).gameObject.SetActive(flag); ((Component)_slotDurabilityBacks[slot]).transform.SetAsLastSibling(); } if (_slotDurabilityBars != null && slot < _slotDurabilityBars.Length && !((Object)(object)_slotDurabilityBars[slot] == (Object)null)) { Image val = _slotDurabilityBars[slot]; ((Component)val).gameObject.SetActive(flag); ((Component)val).transform.SetAsLastSibling(); if (flag) { float num = Mathf.Clamp01(item.m_durability / item.GetMaxDurability()); ((Graphic)val).rectTransform.sizeDelta = new Vector2((_cellSize.x - 8f) * num, 4f); ((Graphic)val).color = ((num > 0.5f) ? Color.Lerp(new Color(1f, 0.75f, 0.1f, 1f), new Color(0.1f, 0.85f, 0.15f, 1f), (num - 0.5f) * 2f) : Color.Lerp(new Color(0.85f, 0.1f, 0.05f, 1f), new Color(1f, 0.75f, 0.1f, 1f), num * 2f)); } } } private static void CreateSlotHitboxes(RectTransform gridRoot) { //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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)gridRoot == (Object)null || _slotPositions == null) { return; } for (int i = 0; i < Slots.Length; i++) { int slotIndex = i; GameObject val = new GameObject("EquipmentSheet_" + Slots[i].Label + "_Hitbox", new Type[1] { typeof(RectTransform) }); val.transform.SetParent((Transform)(object)gridRoot, false); val.transform.SetAsLastSibling(); RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(0f, 1f); component.pivot = new Vector2(0f, 1f); component.anchoredPosition = _slotPositions[i]; component.sizeDelta = _cellSize; Image obj = val.AddComponent<Image>(); ((Graphic)obj).color = new Color(0f, 0f, 0f, 0f); ((Graphic)obj).raycastTarget = true; UIInputHandler val2 = val.AddComponent<UIInputHandler>(); val2.m_onLeftDown = delegate { HandleSheetSlotClicked(slotIndex, rightClick: false); }; val2.m_onRightDown = delegate { HandleSheetSlotClicked(slotIndex, rightClick: true); }; _slotHitboxes[i] = val2; UITooltip val3 = val.AddComponent<UITooltip>(); ConfigureSlotTooltip(val3); _slotTooltips[i] = val3; } } private static void ConfigureSlotTooltip(UITooltip tooltip) { if (!((Object)(object)tooltip == (Object)null)) { InventoryGui instance = InventoryGui.instance; UITooltip val = (((Object)(object)instance != (Object)null && (Object)(object)instance.m_playerGrid != (Object)null && (Object)(object)instance.m_playerGrid.m_elementPrefab != (Object)null) ? instance.m_playerGrid.m_elementPrefab.GetComponentInChildren<UITooltip>(true) : null); if ((Object)(object)val != (Object)null) { tooltip.m_tooltipPrefab = val.m_tooltipPrefab; tooltip.m_gamepadFocusObject = val.m_gamepadFocusObject; } } } private static void SetSlotTooltip(ItemData item, UITooltip tooltip) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) if (item != null && !((Object)(object)tooltip == (Object)null)) { if (_createItemTooltipMethod != null && (Object)(object)_grid != (Object)null) { _createItemTooltipMethod.Invoke(_grid, new object[2] { item, tooltip }); } else { string text = ((item.m_shared == null) ? "" : item.m_shared.m_name); tooltip.Set(text, item.GetTooltip(-1), ((Object)(object)_grid == (Object)null) ? null : _grid.m_tooltipAnchor, Vector2.zero); } } } private static void HandleSheetSlotClicked(int slotIndex, bool rightClick) { //IL_0038: 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_0096: Unknown result type (might be due to invalid IL or missing references) if (slotIndex < 0 || slotIndex >= Slots.Length || _equipmentInventory == null) { return; } InventoryGui instance = InventoryGui.instance; if (!((Object)(object)instance == (Object)null)) { Vector2i val = default(Vector2i); ((Vector2i)(ref val))..ctor(slotIndex % 3, slotIndex / 3); ItemData itemAt = _equipmentInventory.GetItemAt(val.x, val.y); if (IsFoodSlot(slotIndex) && itemAt != null && rightClick && !HasActiveDrag(instance)) { TryConsumeFoodSlot(slotIndex, itemAt); } else if (IsEquipmentSlot(slotIndex) && itemAt != null && rightClick && !HasActiveDrag(instance)) { MoveEquipmentItemToPlayerBag(itemAt); } else { HandleEquipmentGridSelected(instance, _grid, itemAt, val, (Modifier)0); } } } private static bool HasActiveDrag(InventoryGui gui) { if ((Object)(object)gui != (Object)null && _dragItemField != null) { return _dragItemField.GetValue(gui) is ItemData; } return false; } private static void TryConsumeFoodSlot(int slotIndex, ItemData item) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && _equipmentInventory != null && IsFoodSlot(slotIndex) && MatchesSlot(item, slotIndex)) { ((Humanoid)localPlayer).UseItem(_equipmentInventory, item, true); RefreshEquipmentInventory(); SaveEquipmentInventory(localPlayer); } } private static void ValidateEquipmentInventory() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (_loadingInventory || _equipmentInventory == null) { return; } bool flag = false; List<ItemData> list = new List<ItemData>(_equipmentInventory.GetAllItems()); for (int i = 0; i < list.Count; i++) { ItemData val = list[i]; if (val != null && val.m_shared != null) { int slotIndex = GetSlotIndex(val.m_gridPos); if (slotIndex >= 0 && MatchesSlot(val, slotIndex)) { SetEquippedFlag(val, IsEquipmentSlot(slotIndex)); continue; } MoveItemBackToPlayerBag(val); flag = true; } } if (flag) { RefreshEquipmentInventory(); ShowWrongItemTypeMessage(); } SyncCharacterEquipment(Player.m_localPlayer); SaveEquipmentInventory(Player.m_localPlayer); } internal static void QueueAutoRouteEquippedItem(Humanoid humanoid, ItemData item, bool equipped) { Player val = (Player)(object)((humanoid is Player) ? humanoid : null); if (equipped && !((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && item != null) { Inventory inventory = ((Humanoid)val).GetInventory(); if (item == _manualSheetDragItem && inventory != null && inventory.ContainsItem(item)) { _manualSheetDragItem = null; PendingAutoRouteItems.Remove(item); ((Humanoid)val).UnequipItem(item, false); } else if (!((Object)(object)val != (Object)(object)_loadedPlayer) && _enabled != null && _enabled.Value && GetEquipmentSlotForItem(item) >= 0 && inventory != null && inventory.ContainsItem(item) && ((Humanoid)val).IsItemEquiped(item) && !PendingAutoRouteItems.Contains(item)) { PendingAutoRouteItems.Add(item); } } } private static void ProcessPendingAutoRouteItems(Player player) { if (PendingAutoRouteItems.Count != 0) { List<ItemData> list = new List<ItemData>(PendingAutoRouteItems); PendingAutoRouteItems.Clear(); for (int i = 0; i < list.Count; i++) { MoveEquippedBagItemToSheet(player, list[i]); } } } private static void MoveEquippedBagItemToSheet(Player player, ItemData item) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: 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_00ba: 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_010c: 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) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || item == null || _equipmentInventory == null || !((Humanoid)player).IsItemEquiped(item)) { return; } int equipmentSlotForItem = GetEquipmentSlotForItem(item); Inventory inventory = ((Humanoid)player).GetInventory(); List<ItemData> inventoryItems = GetInventoryItems(inventory); List<ItemData> inventoryItems2 = GetInventoryItems(_equipmentInventory); if (equipmentSlotForItem < 0 || inventory == null || inventoryItems == null || inventoryItems2 == null || !inventoryItems.Contains(item)) { return; } Vector2i val = default(Vector2i); ((Vector2i)(ref val))..ctor(equipmentSlotForItem % 3, equipmentSlotForItem / 3); Vector2i gridPos = item.m_gridPos; if (inventory.GetItemAt(gridPos.x, gridPos.y) != item) { return; } ItemData itemAt = _equipmentInventory.GetItemAt(val.x, val.y); if (itemAt == item) { return; } inventoryItems.Remove(item); if (itemAt != null) { inventoryItems2.Remove(itemAt); itemAt.m_gridPos = gridPos; SetEquippedFlag(itemAt, equipped: false); inventoryItems.Add(itemAt); } item.m_gridPos = val; SetEquippedFlag(item, equipped: true); inventoryItems2.Add(item); if (_equipmentInventory.GetItemAt(val.x, val.y) != item || (itemAt != null && inventory.GetItemAt(gridPos.x, gridPos.y) != itemAt)) { inventoryItems2.Remove(item); item.m_gridPos = gridPos; SetEquippedFlag(item, equipped: true); inventoryItems.Add(item); if (itemAt != null) { inventoryItems.Remove(itemAt); itemAt.m_gridPos = val; SetEquippedFlag(itemAt, equipped: true); inventoryItems2.Add(itemAt); } } else { RefreshEquipmentInventory(); if (_inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(inventory, null); } SaveEquipmentInventory(player); } } private static void MoveEquipmentItemToPlayerBag(ItemData item) { //IL_004b: 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) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Inventory val = (((Object)(object)localPlayer == (Object)null) ? null : ((Humanoid)localPlayer).GetInventory()); List<ItemData> inventoryItems = GetInventoryItems(val); List<ItemData> inventoryItems2 = GetInventoryItems(_equipmentInventory); if ((Object)(object)localPlayer == (Object)null || item == null || val == null || inventoryItems == null || inventoryItems2 == null || !inventoryItems2.Contains(item)) { return; } Vector2i val2 = FindFirstEmptyPosition(val); if (val2.x < 0) { ((Character)localPlayer).Message((MessageType)2, "$inventory_full", 0, (Sprite)null); return; } Vector2i gridPos = item.m_gridPos; SavePendingTransfer(localPlayer, item); ((Humanoid)localPlayer).UnequipItem(item, false); inventoryItems2.Remove(item); item.m_gridPos = val2; SetEquippedFlag(item, equipped: false); inventoryItems.Add(item); if (val.GetItemAt(val2.x, val2.y) != item || _equipmentInventory.ContainsItem(item)) { inventoryItems.Remove(item); item.m_gridPos = gridPos; SetEquippedFlag(item, equipped: true); inventoryItems2.Add(item); SyncCharacterEquipment(localPlayer); ClearPendingTransfer(localPlayer); } else { RefreshEquipmentInventory(); if (_inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(val, null); } SaveEquipmentInventory(localPlayer); ClearPendingTransfer(localPlayer); } } private static Vector2i FindFirstEmptyPosition(Inventory inventory) { //IL_0005: 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_002d: Unknown result type (might be due to invalid IL or missing references) if (inventory == null) { return new Vector2i(-1, -1); } int width = inventory.GetWidth(); int height = inventory.GetHeight(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (inventory.GetItemAt(j, i) == null) { return new Vector2i(j, i); } } } return new Vector2i(-1, -1); } private static int GetEquipmentSlotForItem(ItemData item) { for (int i = 0; i < 6; i++) { if (MatchesSlot(item, i)) { return i; } } return -1; } private static FieldInfo GetHumanoidFieldForType(ItemType type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if ((int)type <= 11) { if ((int)type == 6) { return _humanoidHelmetField; } if ((int)type == 7) { return _humanoidChestField; } if ((int)type == 11) { return _humanoidLegField; } } else { if ((int)type == 17) { return _humanoidShoulderField; } if ((int)type == 18) { return _humanoidUtilityField; } if ((int)type == 24) { return _humanoidTrinketField; } } return null; } private static void SyncCharacterEquipment(Player player) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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) if ((Object)(object)player == (Object)null || _equipmentInventory == null || _setupEquipmentMethod == null) { return; } bool flag = false; Vector2i val = default(Vector2i); for (int i = 0; i < 6; i++) { FieldInfo humanoidFieldForType = GetHumanoidFieldForType(Slots[i].Type); if (humanoidFieldForType == null) { continue; } ((Vector2i)(ref val))..ctor(i % 3, i / 3); ItemData val2 = _equipmentInventory.GetItemAt(val.x, val.y); if (val2 != null && (val2.m_shared == null || !MatchesSlot(val2, i))) { val2 = null; } object? value = humanoidFieldForType.GetValue(player); ItemData val3 = (ItemData)((value is ItemData) ? value : null); if (val3 == val2) { continue; } bool flag2 = val3 != null && _equipmentInventory.ContainsItem(val3); if (val2 != null || flag2) { if (val3 != null) { ((Humanoid)player).UnequipItem(val3, false); } if (val2 != null) { humanoidFieldForType.SetValue(player, val2); SetEquippedFlag(val2, equipped: true); } flag = true; } } if (flag) { _setupEquipmentMethod.Invoke(player, null); } } internal static bool IsEquipmentGrid(InventoryGrid grid) { if ((Object)(object)grid != (Object)null && (Object)(object)_grid != (Object)null) { return (Object)(object)grid == (Object)(object)_grid; } return false; } internal static bool BeginContainerUpdateGuard(InventoryGui gui) { if ((Object)(object)gui == (Object)null || _dragInventoryField == null || _currentContainerField == null) { return false; } object? value = _dragInventoryField.GetValue(gui); Inventory val = (Inventory)((value is Inventory) ? value : null); if (val == null || val != _equipmentInventory) { return false; } object? value2 = _currentContainerField.GetValue(gui); if ((Object)((value2 is Container) ? value2 : null) != (Object)null) { return false; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return false; } _dragInventoryField.SetValue(gui, ((Humanoid)localPlayer).GetInventory()); return true; } internal static void EndContainerUpdateGuard(InventoryGui gui, bool didSwap) { if (didSwap && !((Object)(object)gui == (Object)null) && !(_dragInventoryField == null)) { _dragInventoryField.SetValue(gui, _equipmentInventory); } } internal static bool TryDropIntoEquipmentSlot(Inventory fromInventory, ItemData item, int amount, Vector2i pos) { //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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_00aa: 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_00ff: 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_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) if (_equipmentInventory == null || fromInventory == null || item == null || item.m_shared == null) { return false; } if (_equipmentInventory.GetItemAt(pos.x, pos.y) == item) { return true; } int slotIndex = GetSlotIndex(pos); if (slotIndex < 0 || !MatchesSlot(item, slotIndex)) { ShowWrongItemTypeMessage(); return false; } if (IsFoodSlot(slotIndex)) { return TryDropIntoFoodSlot(fromInventory, item, amount, pos); } if (_equipmentInventory.GetItemAt(pos.x, pos.y) != null) { return false; } if (Mathf.Clamp((amount <= 0) ? item.m_stack : amount, 1, item.m_stack) != item.m_stack) { ShowWrongItemTypeMessage(); return false; } if (fromInventory == _equipmentInventory) { item.m_gridPos = pos; SetEquippedFlag(item, equipped: true); RefreshEquipmentInventory(); SaveEquipmentInventory(Player.m_localPlayer); return true; } Player localPlayer = Player.m_localPlayer; SavePendingTransfer(localPlayer, item); List<ItemData> inventoryItems = GetInventoryItems(fromInventory); List<ItemData> inventoryItems2 = GetInventoryItems(_equipmentInventory); if (inventoryItems == null || inventoryItems2 == null || !inventoryItems.Contains(item)) { ClearPendingTransfer(localPlayer); return false; } Vector2i gridPos = item.m_gridPos; inventoryItems.Remove(item); item.m_gridPos = pos; SetEquippedFlag(item, equipped: true); inventoryItems2.Add(item); if (_equipmentInventory.GetItemAt(pos.x, pos.y) != item) { inventoryItems2.Remove(item); item.m_gridPos = gridPos; SetEquippedFlag(item, equipped: false); inventoryItems.Add(item); RestorePendingTransfer(localPlayer); return false; } RefreshEquipmentInventory(); if (_inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(fromInventory, null); } SaveEquipmentInventory(Player.m_localPlayer); ClearPendingTransfer(localPlayer); return true; } private static bool TryDropIntoFoodSlot(Inventory fromInventory, ItemData item, int amount, Vector2i pos) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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) //IL_0075: 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) if (_equipmentInventory == null || fromInventory == null || item == null || !IsFoodItem(item)) { return false; } int num = Mathf.Clamp((amount <= 0) ? item.m_stack : amount, 1, item.m_stack); ItemData itemAt = _equipmentInventory.GetItemAt(pos.x, pos.y); if (itemAt == item) { return true; } if (fromInventory == _equipmentInventory) { return TryMoveFoodInsideSheet(item, num, itemAt, pos); } int stack = item.m_stack; bool flag = _equipmentInventory.MoveItemToThis(fromInventory, item, num, pos.x, pos.y); if (!(item.m_stack != stack || flag)) { return false; } SetEquippedFlag(item, equipped: false); RefreshEquipmentInventory(); if (_inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(fromInventory, null); } SaveEquipmentInventory(Player.m_localPlayer); return true; } private static bool TryMoveFoodInsideSheet(ItemData item, int amount, ItemData target, Vector2i pos) { //IL_0020: 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) List<ItemData> inventoryItems = GetInventoryItems(_equipmentInventory); if (inventoryItems == null || item == null || !inventoryItems.Contains(item)) { return false; } if (target == null) { item.m_gridPos = pos; SetEquippedFlag(item, equipped: false); RefreshEquipmentInventory(); SaveEquipmentInventory(Player.m_localPlayer); return true; } if (!CanStackFood(target, item)) { return false; } int num = target.m_shared.m_maxStackSize - target.m_stack; if (num <= 0) { return false; } int num2 = Mathf.Min(Mathf.Clamp(amount, 1, item.m_stack), num); target.m_stack += num2; item.m_stack -= num2; SetEquippedFlag(target, equipped: false); SetEquippedFlag(item, equipped: false); if (item.m_stack <= 0) { inventoryItems.Remove(item); } RefreshEquipmentInventory(); SaveEquipmentInventory(Player.m_localPlayer); return true; } private static bool CanStackFood(ItemData target, ItemData item) { if (target == null || item == null || target.m_shared == null || item.m_shared == null) { return false; } if (target.m_shared.m_name == item.m_shared.m_name && target.m_quality == item.m_quality && target.m_worldLevel == item.m_worldLevel) { return target.m_shared.m_maxStackSize > 1; } return false; } private static void HandleEquipmentGridSelected(InventoryGui gui, InventoryGrid grid, ItemData item, Vector2i pos, Modifier mod) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) if (!IsEquipmentGrid(grid) || (Object)(object)gui == (Object)null) { return; } ItemData val = (ItemData)((_dragItemField == null) ? null : /*isinst with value type is only supported in some contexts*/); Inventory fromInventory = (Inventory)((_dragInventoryField == null) ? null : /*isinst with value type is only supported in some contexts*/); int amount = ((!(_dragAmountField == null)) ? ((int)_dragAmountField.GetValue(gui)) : 0); if (val != null) { if (TryDropIntoEquipmentSlot(fromInventory, val, amount, pos)) { ClearDragItem(gui); } } else if (item != null && _setupDragItemMethod != null) { SetEquippedFlag(item, equipped: false); _manualSheetDragItem = item; _setupDragItemMethod.Invoke(gui, new object[3] { item, _equipmentInventory, item.m_stack }); } } private static void ClearDragItem(InventoryGui gui) { if (!((Object)(object)gui == (Object)null)) { ItemData val = (ItemData)((_dragItemField == null) ? null : /*isinst with value type is only supported in some contexts*/); if (_manualSheetDragItem == val) { _manualSheetDragItem = null; } GameObject val2 = (GameObject)((_dragGoField == null) ? null : /*isinst with value type is only supported in some contexts*/); if ((Object)(object)val2 != (Object)null) { Object.Destroy((Object)(object)val2); } if (_dragGoField != null) { _dragGoField.SetValue(gui, null); } if (_dragItemField != null) { _dragItemField.SetValue(gui, null); } if (_dragInventoryField != null) { _dragInventoryField.SetValue(gui, null); } if (_dragAmountField != null) { _dragAmountField.SetValue(gui, 0); } } } private static int GetSlotIndex(Vector2i pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_002e: Unknown result type (might be due to invalid IL or missing references) if (pos.x < 0 || pos.x >= 3 || pos.y < 0 || pos.y >= 3) { return -1; } int num = pos.y * 3 + pos.x; if (num < 0 || num >= Slots.Length) { return -1; } return num; } private static bool IsEquipmentSlot(int slot) { if (slot >= 0 && slot < 6 && slot < Slots.Length) { return Slots[slot].Kind == SlotKind.Equipment; } return false; } private static bool IsFoodSlot(int slot) { if (slot >= 6 && slot < Slots.Length) { return Slots[slot].Kind == SlotKind.Food; } return false; } private static bool MatchesSlot(ItemData item, int slot) { //IL_003a: 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_0040: 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_0052: Unknown result type (might be due to invalid IL or missing references) if (item == null || item.m_shared == null || slot < 0 || slot >= Slots.Length) { return false; } if (IsFoodSlot(slot)) { return IsFoodItem(item); } if (!IsEquipmentSlot(slot)) { return false; } ItemType itemType = item.m_shared.m_itemType; if (IsExplicitlyExcludedEquipmentType(itemType)) { return false; } return itemType == Slots[slot].Type; } private static bool IsFoodItem(ItemData item) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 if (item == null || item.m_shared == null) { return false; } if ((int)item.m_shared.m_itemType == 2) { if (!(item.m_shared.m_food > 0f) && !(item.m_shared.m_foodStamina > 0f) && !(item.m_shared.m_foodEitr > 0f)) { return (Object)(object)item.m_shared.m_consumeStatusEffect != (Object)null; } return true; } return false; } private unsafe static bool IsExplicitlyExcludedEquipmentType(ItemType type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 if ((int)type == 4 || (int)type == 3 || (int)type == 14 || (int)type == 22 || (int)type == 20 || (int)type == 5 || (int)type == 19 || (int)type == 15) { return true; } string text = ((object)(*(ItemType*)(&type))/*cast due to .constrained prefix*/).ToString(); if (text.IndexOf("Bow", StringComparison.OrdinalIgnoreCase) < 0) { return text.IndexOf("Ranged", StringComparison.OrdinalIgnoreCase) >= 0; } return true; } private static void MoveItemBackToPlayerBag(ItemData item) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Inventory val = (((Object)(object)localPlayer == (Object)null) ? null : ((Humanoid)localPlayer).GetInventory()); if (item == null || val == null || _equipmentInventory == null || !_equipmentInventory.ContainsItem(item)) { return; } SetEquippedFlag(item, equipped: false); if (!val.AddItem(item)) { int slotIndex = GetSlotIndex(item.m_gridPos); SetEquippedFlag(item, slotIndex >= 0 && IsEquipmentSlot(slotIndex) && MatchesSlot(item, slotIndex)); if (_log != null) { _log.LogWarning((object)("Equipment Sheet: invalid item '" + GetItemDisplayName(item) + "' is in an equipment slot, but the player bag is full.")); } } else { _equipmentInventory.RemoveItem(item); if (_log != null) { _log.LogInfo((object)("Equipment Sheet: moved invalid item '" + GetItemDisplayName(item) + "' back to the player bag.")); } } } internal static void SaveEquipmentInventory(Player player) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown if (!((Object)(object)player == (Object)null) && _equipmentInventory != null) { Dictionary<string, string> customData = GetCustomData(player); if (customData != null) { ZPackage val = new ZPackage(); _equipmentInventory.Save(val); customData["is.codex.valheim.equipmentsheet.inventory.v1"] = val.GetBase64(); } } } private static void SavePendingTransfer(Player player, ItemData item) { //IL_0020: 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) //IL_0034: 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_003c: 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_004d: Expected O, but got Unknown if (!((Object)(object)player == (Object)null) && item != null) { Dictionary<string, string> customData = GetCustomData(player); if (customData != null) { Inventory val = new Inventory("EquipmentSheetPending", (Sprite)null, 1, 1); ItemData val2 = item.Clone(); val2.m_gridPos = new Vector2i(0, 0); val.AddItem(val2, val2.m_gridPos); ZPackage val3 = new ZPackage(); val.Save(val3); customData["is.codex.valheim.equipmentsheet.pending-transfer.v1"] = val3.GetBase64(); } } } private static void ClearPendingTransfer(Player player) { GetCustomData(player)?.Remove("is.codex.valheim.equipmentsheet.pending-transfer.v1"); } private static void RestorePendingTransfer(Player player) { //IL_0040: 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_004b: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null) { return; } Dictionary<string, string> customData = GetCustomData(player); if (customData == null || !customData.TryGetValue("is.codex.valheim.equipmentsheet.pending-transfer.v1", out var value) || string.IsNullOrEmpty(value)) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return; } try { Inventory val = new Inventory("EquipmentSheetPending", (Sprite)null, 1, 1); ZPackage val2 = new ZPackage(); val2.Load(Convert.FromBase64String(value)); val.Load(val2); List<ItemData> allItems = val.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val3 = allItems[i]; if (val3 != null) { ItemData val4 = val3.Clone(); SetEquippedFlag(val4, equipped: false); inventory.AddItem(val4); } } ClearPendingTransfer(player); if (_inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(inventory, null); } if (_log != null) { _log.LogWarning((object)"Equipment Sheet: restored an interrupted equipment transfer back to the player bag."); } } catch (Exception ex) { if (_log != null) { _log.LogWarning((object)("Equipment Sheet: failed to restore pending transfer: " + ex.Message)); } } } internal static void LoadEquipmentInventory(Player player) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown EnsureEquipmentInventory(); Dictionary<string, string> customData = GetCustomData(player); if (customData == null || !customData.TryGetValue("is.codex.valheim.equipmentsheet.inventory.v1", out var value) || string.IsNullOrEmpty(value)) { ClearEquipmentInventory(player, clearSavedData: false); return; } try { _loadingInventory = true; ZPackage val = new ZPackage(); val.Load(Convert.FromBase64String(value)); _equipmentInventory.RemoveAll(); _equipmentInventory.Load(val); MarkEquipmentItemsEquipped(); RefreshEquipmentInventory(); if (_log != null) { _log.LogInfo((object)"Equipment Sheet: loaded persistent equipment inventory."); } } catch (Exception ex) { if (_log != null) { _log.LogWarning((object)("Equipment Sheet: failed to load persistent equipment inventory: " + ex.Message)); } } finally { _loadingInventory = false; } SyncCharacterEquipment(player); } internal static void MoveSheetItemsToPlayerInventoryForDeath(Player player) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || _equipmentInventory == null) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); List<ItemData> inventoryItems = GetInventoryItems(inventory); List<ItemData> inventoryItems2 = GetInventoryItems(_equipmentInventory); if (inventory == null || inventoryItems == null || inventoryItems2 == null || inventoryItems2.Count == 0) { ClearEquipmentCustomData(player); return; } List<ItemData> list = new List<ItemData>(inventoryItems2); for (int i = 0; i < list.Count; i++) { ItemData val = list[i]; if (val != null) { int slotIndex = GetSlotIndex(val.m_gridPos); SetEquippedFlag(val, slotIndex >= 0 && IsEquipmentSlot(slotIndex) && MatchesSlot(val, slotIndex)); if (!inventoryItems.Contains(val)) { inventoryItems.Add(val); } inventoryItems2.Remove(val); } } ClearEquipmentCustomData(player); RefreshEquipmentInventory(); if (_inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(inventory, null); } if (_log != null) { _log.LogInfo((object)"Equipment Sheet: moved sheet items into the vanilla death-drop inventory."); } } private static void ClearEquipmentInventory(Player player, bool clearSavedData) { if (_equipmentInventory != null && _equipmentInventory.NrOfItems() > 0) { List<ItemData> oldItems = new List<ItemData>(_equipmentInventory.GetAllItems()); _loadingInventory = true; try { _equipmentInventory.RemoveAll(); } finally { _loadingInventory = false; } RefreshEquipmentInventory(); ClearCharacterEquipmentReferences(player, oldItems); } if (clearSavedData) { ClearEquipmentCustomData(player); } } private static void ClearCharacterEquipmentReferences(Player player, List<ItemData> oldItems) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player == (Object)null || oldItems == null || oldItems.Count == 0 || _setupEquipmentMethod == null) { return; } bool flag = false; for (int i = 0; i < 6; i++) { FieldInfo humanoidFieldForType = GetHumanoidFieldForType(Slots[i].Type); if (!(humanoidFieldForType == null)) { object? value = humanoidFieldForType.GetValue(player); ItemData val = (ItemData)((value is ItemData) ? value : null); if (val != null && oldItems.Contains(val)) { humanoidFieldForType.SetValue(player, null); SetEquippedFlag(val, equipped: false); flag = true; } } } if (flag) { _setupEquipmentMethod.Invoke(player, null); } } private static void ClearEquipmentCustomData(Player player) { Dictionary<string, string> customData = GetCustomData(player); if (customData != null) { customData.Remove("is.codex.valheim.equipmentsheet.inventory.v1"); customData.Remove("is.codex.valheim.equipmentsheet.pending-transfer.v1"); } } private static void MarkEquipmentItemsEquipped() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (_equipmentInventory != null) { List<ItemData> allItems = _equipmentInventory.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val = allItems[i]; int num = ((val == null) ? (-1) : GetSlotIndex(val.m_gridPos)); SetEquippedFlag(val, num >= 0 && IsEquipmentSlot(num) && MatchesSlot(val, num)); } } } private static void RefreshEquipmentInventory() { if (_equipmentInventory != null && _inventoryChangedMethod != null) { _inventoryChangedMethod.Invoke(_equipmentInventory, null); } } private static void SetEquippedFlag(ItemData item, bool equipped) { if (_itemEquippedField != null && item != null) { _itemEquippedField.SetValue(item, equipped); } } private static List<ItemData> GetInventoryItems(Inventory inventory) { if (!(_inventoryItemsField == null) && inventory != null) { return _inventoryItemsField.GetValue(inventory) as List<ItemData>; } return null; } internal static float GetEquipmentWeight() { if (_equipmentInventory != null) { return _equipmentInventory.GetTotalWeight(); } return 0f; } internal static bool BeginUpgradeRecipeScan(InventoryGui gui) { int num; if ((Object)(object)gui != (Object)null && _enabled != null && _enabled.Value) { num = (gui.InUpradeTab() ? 1 : 0); if (num != 0) { _upgradeRecipeScanDepth++; } } else { num = 0; } return (byte)num != 0; } internal static void EndUpgradeRecipeScan(bool active) { if (active && _upgradeRecipeScanDepth > 0) { _upgradeRecipeScanDepth--; } } internal static void AddSheetUpgradeItems(Inventory inventory, string name, List<ItemData> items) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (_upgradeRecipeScanDepth <= 0 || _equipmentInventory == null || (Object)(object)localPlayer == (Object)null || inventory != ((Humanoid)localPlayer).GetInventory() || string.IsNullOrEmpty(name) || items == null) { return; } List<ItemData> allItems = _equipmentInventory.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val = allItems[i]; int num = ((val == null) ? (-1) : GetSlotIndex(val.m_gridPos)); if (num >= 0 && IsEquipmentSlot(num) && MatchesSlot(val, num) && val.m_shared.m_name == name && val.m_worldLevel >= Game.m_worldLevel && !items.Contains(val)) { items.Add(val); } } } internal static bool BeginSheetUpgrade(InventoryGui gui, Player player) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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) if ((Object)(object)gui == (Object)null || (Object)(object)player == (Object)null || _equipmentInventory == null || _craftUpgradeItemField == null) { return false; } object? value = _craftUpgradeItemField.GetValue(gui); ItemData val = (ItemData)((value is ItemData) ? value : null); int num = ((val == null) ? (-1) : GetSlotIndex(val.m_gridPos)); if (num < 0 || !IsEquipmentSlot(num) || !MatchesSlot(val, num) || !_equipmentInventory.ContainsItem(val)) { return false; } Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return false; } if (_sheetUpgradeTransaction != null) { EndSheetUpgrade(new InvalidOperationException("A previous equipment upgrade transaction was still active.")); } SavePendingTransfer(player, val); _sheetUpgradeTransaction = new SheetUpgradeTransaction { Player = player, PlayerInventory = inventory, OriginalItem = val, SheetPosition = val.m_gridPos }; return true; } internal static void EndSheetUpgrade(Exception exception) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) SheetUpgradeTransaction sheetUpgradeTransaction = _sheetUpgradeTransaction; _sheetUpgradeTransaction = null; if (sheetUpgradeTransaction == null) { return; } int num; if (exception == null && sheetUpgradeTransaction.OriginalRemoved) { num = ((sheetUpgradeTransaction.ReplacementItem != null) ? 1 : 0); if (num != 0) { goto IL_00bd; } } else { num = 0; } if (sheetUpgradeTransaction.OriginalRemoved) { List<ItemData> inventoryItems = GetInventoryItems(_equipmentInventory); if (inventoryItems != null) { if (sheetUpgradeTransaction.ReplacementItem != null) { inventoryItems.Remove(sheetUpgradeTransaction.ReplacementItem); } if (!inventoryItems.Contains(sheetUpgradeTransaction.OriginalItem)) { sheetUpgradeTransaction.OriginalItem.m_gridPos = sheetUpgradeTransaction.SheetPosition; SetEquippedFlag(sheetUpgradeTransaction.OriginalItem, equipped: true); inventoryItems.Add(sheetUpgradeTransaction.OriginalItem); } } if (_log != null) { _log.LogWarning((object)("Equipment Sheet: restored '" + GetItemDisplayName(sheetUpgradeTransaction.OriginalItem) + "' after its upgrade did not complete.")); } } goto IL_00bd; IL_00bd: if (num != 0) { SetEquippedFlag(sheetUpgradeTransaction.ReplacementItem, equipped: true); } RefreshEquipmentInventory(); SyncCharacterEquipment(sheetUpgradeTransaction.Player); SaveEquipmentInventory(sheetUpgradeTransaction.Player); ClearPendingTransfer(sheetUpgradeTransaction.Player); } internal static void IncludeSheetUpgradeItem(Inventory inventory, ItemData item, ref bool result) { SheetUpgradeTransaction sheetUpgradeTransaction = _sheetUpgradeTransaction; if (!result && sheetUpgradeTransaction != null && inventory == sheetUpgradeTransaction.PlayerInventory && item == sheetUpgradeTransaction.OriginalItem && _equipmentInventory != null && _equipmentInventory.ContainsItem(item)) { result = true; } } internal static bool RemoveSheetUpgradeItem(Inventory inventory, ItemData item, ref bool result) { SheetUpgradeTransaction sheetUpgradeTransaction = _sheetUpgradeTransaction; if (sheetUpgradeTransaction == null || inventory != sheetUpgradeTransaction.PlayerInventory || item != sheetUpgradeTransaction.OriginalItem) { return true; } result = _equipmentInventory != null && _equipmentInventory.RemoveItem(item); sheetUpgradeTransaction.OriginalRemoved = result; return false; } internal static bool AddUpgradedSheetItem(Inventory inventory, string name, int stack, int quality, int variant, long crafterID, string crafterName, Vector2i position, bool pickedUp, ref ItemData result) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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) SheetUpgradeTransaction sheetUpgradeTransaction = _sheetUpgradeTransaction; if (sheetUpgradeTransaction == null || !sheetUpgradeTransaction.OriginalRemoved || inventory != sheetUpgradeTransaction.PlayerInventory || sheetUpgradeTransaction.OriginalItem == null || (Object)(object)sheetUpgradeTransaction.OriginalItem.m_dropPrefab == (Object)null || name != ((Object)sheetUpgradeTransaction.OriginalItem.m_dropPrefab).name || quality != sheetUpgradeTransaction.OriginalItem.m_quality + 1 || variant != sheetUpgradeTransaction.OriginalItem.m_variant || position.x != sheetUpgradeTransaction.SheetPosition.x || position.y != sheetUpgradeTransaction.SheetPosition.y) { return true; } result = _equipmentInventory.AddItem(name, stack, quality, variant, crafterID, crafterName, sheetUpgradeTransaction.SheetPosition, pickedUp); sheetUpgradeTransaction.ReplacementItem = result; return false; } internal static void AddEquippedItems(List<ItemData> items) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (_equipmentInventory == null || items == null) { return; } List<ItemData> allItems = _equipmentInventory.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val = allItems[i]; int num = ((val == null) ? (-1) : GetSlotIndex(val.m_gridPos)); if (num >= 0 && IsEquipmentSlot(num) && MatchesSlot(val, num) && !items.Contains(val)) { SetEquippedFlag(val, equipped: true); items.Add(val); } } } internal static void AddWornEquippedItems(List<ItemData> items) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (_equipmentInventory == null || items == null) { return; } List<ItemData> allItems = _equipmentInventory.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val = allItems[i]; int num = ((val == null) ? (-1) : GetSlotIndex(val.m_gridPos)); if (num >= 0 && IsEquipmentSlot(num) && MatchesSlot(val, num) && !items.Contains(val) && val.m_shared.m_useDurability && val.m_durability < val.GetMaxDurability()) { items.Add(val); } } } private static Dictionary<string, string> GetCustomData(Player player) { if (!(_customDataField == null) && !((Object)(object)player == (Object)null)) { return _customDataField.GetValue(player) as Dictionary<string, string>; } return null; } private static string GetItemDisplayName(ItemData item) { if (item == null || item.m_shared == null || string.IsNullOrEmpty(item.m_shared.m_name)) { return "<unknown>"; } return item.m_shared.m_name; } private static void ShowWrongItemTypeMessage() { if (!(Time.time - _lastWrongTypeMessageTime < 2f)) { _lastWrongTypeMessageTime = Time.time; if ((Object)(object)MessageHud.instance != (Object)null) { MessageHud.instance.ShowMessage((MessageType)2, "That item doesn't belong in that slot.", 0, (Sprite)null, false); } } } } [HarmonyPatch(typeof(InventoryGui), "UpdateContainer")] internal static class InventoryGuiUpdateContainerEquipmentSheetPatch { private static void Prefix(InventoryGui __instance, ref bool __state) { __state = EquipmentSheetPlugin.BeginContainerUpdateGuard(__instance); } private static void Postfix(InventoryGui __instance, bool __state) { EquipmentSheetPlugin.EndContainerUpdateGuard(__instance, __state); } } [HarmonyPatch(typeof(InventoryGui), "Awake")] internal static class InventoryGuiAwakeEquipmentSheetPatch { private static void Postfix(InventoryGui __instance) { EquipmentSheetPlugin.SetupPanel(__instance); } } [HarmonyPatch(typeof(Player), "Save")] internal static class PlayerSaveEquipmentSheetPatch { private static void Prefix(Player __instance) { EquipmentSheetPlugin.SaveEquipmentInventory(__instance); } } [HarmonyPatch(typeof(Player), "Load")] internal static class PlayerLoadEquipmentSheetPatch { private static void Postfix(Player __instance) { EquipmentSheetPlugin.LoadEquipmentInventory(__instance); } } [HarmonyPatch(typeof(Player), "CreateTombStone")] internal static class PlayerCreateTombStoneEquipmentSheetPatch { private static void Prefix(Player __instance) { EquipmentSheetPlugin.MoveSheetItemsToPlayerInventoryForDeath(__instance); } } [HarmonyPatch(typeof(Humanoid), "EquipItem", new Type[] { typeof(ItemData), typeof(bool) })] internal static class HumanoidEquipItemEquipmentSheetPatch { private static void Postfix(Humanoid __instance, ItemData item, bool __result) { EquipmentSheetPlugin.QueueAutoRouteEquippedItem(__instance, item, __result); } } [HarmonyPatch(typeof(InventoryGui), "UpdateRecipeList", new Type[] { typeof(List<Recipe>) })] internal static class InventoryGuiUpdateRecipeListEquipmentSheetPatch { private static void Prefix(InventoryGui __instance, ref bool __state) { __state = EquipmentSheetPlugin.BeginUpgradeRecipeScan(__instance); } private static Exception Finalizer(Exception __exception, bool __state) { EquipmentSheetPlugin.EndUpgradeRecipeScan(__state); return __exception; } } [HarmonyPatch(typeof(InventoryGui), "DoCrafting", new Type[] { typeof(Player) })] internal static class InventoryGuiDoCraftingEquipmentSheetPatch { private static void Prefix(InventoryGui __instance, Player player) { EquipmentSheetPlugin.BeginSheetUpgrade(__instance, player); } private static Exception Finalizer(Exception __exception) { EquipmentSheetPlugin.EndSheetUpgrade(__exception); return __exception; } } [HarmonyPatch(typeof(Inventory), "GetAllItems", new Type[] { typeof(string), typeof(List<ItemData>) })] internal static class InventoryGetAllItemsByNameEquipmentSheetPatch { private static void Postfix(Inventory __instance, string name, List<ItemData> items) { EquipmentSheetPlugin.AddSheetUpgradeItems(__instance, name, items); } } [HarmonyPatch(typeof(Inventory), "ContainsItem", new Type[] { typeof(ItemData) })] internal static class InventoryContainsItemEquipmentSheetPatch { private static void Postfix(Inventory __instance, ItemData item, ref bool __result) { EquipmentSheetPlugin.IncludeSheetUpgradeItem(__instance, item, ref __result); } } [HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[] { typeof(ItemData) })] internal static class InventoryRemoveItemEquipmentSheetPatch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { return EquipmentSheetPlugin.RemoveSheetUpgradeItem(__instance, item, ref __result); } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(string), typeof(int), typeof(int), typeof(int), typeof(long), typeof(string), typeof(Vector2i), typeof(bool) })] internal static class InventoryAddCraftedItemEquipmentSheetPatch { private static bool Prefix(Inventory __instance, string name, int stack, int quality, int variant, long crafterID, string crafterName, Vector2i position, bool pickedUp, ref ItemData __result) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) return EquipmentSheetPlugin.AddUpgradedSheetItem(__instance, name, stack, quality, variant, crafterID, crafterName, position, pickedUp, ref __result); } } [HarmonyPatch(typeof(Inventory), "GetTotalWeight")] internal static class InventoryTotalWeightEquipmentSheetPatch { private static void Postfix(Inventory __instance, ref float __result) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && __instance == ((Humanoid)localPlayer).GetInventory()) { __result += EquipmentSheetPlugin.GetEquipmentWeight(); } } } [HarmonyPatch(typeof(Inventory), "GetEquippedItems")] internal static class InventoryGetEquippedItemsEquipmentSheetPatch { private static void Postfix(Inventory __instance, ref List<ItemData> __result) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && __instance == ((Humanoid)localPlayer).GetInventory()) { EquipmentSheetPlugin.AddEquippedItems(__result); } } } [HarmonyPatch(typeof(Inventory), "GetWornItems")] internal static class InventoryGetWornItemsEquipmentSheetPatch { private static void Postfix(Inventory __instance, List<ItemData> worn) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && __instance == ((Humanoid)localPlayer).GetInventory()) { EquipmentSheetPlugin.AddWornEquippedItems(worn); } } } [HarmonyPatch(typeof(InventoryGrid), "DropItem")] internal static class InventoryGridDropItemEquipmentSheetPatch { private static bool Prefix(InventoryGrid __instance, Inventory __0, ItemData __1, int __2, Vector2i __3, ref bool __result) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (!EquipmentSheetPlugin.IsEquipmentGrid(__instance)) { return true; } __result = EquipmentSheetPlugin.TryDropIntoEquipmentSlot(__0, __1, __2, __3); return false; } }