forked from aly/qstbak
474 lines
13 KiB
C#
474 lines
13 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
|
using Lumina.Excel;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace LLib.Inventory;
|
|
|
|
public static class InventoryHelper
|
|
{
|
|
public unsafe static int GetItemCount(uint itemId, bool checkEquipped = false, bool checkArmory = false)
|
|
{
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
int num = ((ptr != null) ? (-1076709592) : (-1076709591));
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -1076709592;
|
|
int num4 = num2;
|
|
switch ((num4 | num3) - (num4 & num3))
|
|
{
|
|
case 0:
|
|
return ptr->GetInventoryItemCount(itemId, isHq: false, checkEquipped, checkArmory, 0) + ptr->GetInventoryItemCount(itemId, isHq: true, checkEquipped, checkArmory, 0);
|
|
case 1:
|
|
return 0;
|
|
case 2:
|
|
goto IL_0063;
|
|
}
|
|
continue;
|
|
IL_0063:
|
|
num = -1076709591;
|
|
}
|
|
}
|
|
|
|
public unsafe static int GetItemCount(uint itemId, InventoryType inventoryType)
|
|
{
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
int num = ((ptr != null) ? (-397486013) : (-397486005));
|
|
int num7 = default(int);
|
|
int num8 = default(int);
|
|
InventoryItem* inventorySlot = default(InventoryItem*);
|
|
InventoryContainer* inventoryContainer = default(InventoryContainer*);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -397486013;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 1:
|
|
return 0;
|
|
case 7:
|
|
{
|
|
int num9 = num7;
|
|
num3 = 1;
|
|
num4 = num9;
|
|
num7 = (num4 | num3) + (num4 & num3);
|
|
num = -397486009;
|
|
break;
|
|
}
|
|
case 8:
|
|
return 0;
|
|
case 3:
|
|
{
|
|
int num10 = num8;
|
|
num3 = inventorySlot->Quantity;
|
|
num4 = num10;
|
|
int num11 = num4 ^ num3;
|
|
int num12 = num4 & num3;
|
|
num8 = num11 + (num12 + num12);
|
|
num = -397486012;
|
|
break;
|
|
}
|
|
case 0:
|
|
inventoryContainer = ptr->GetInventoryContainer(inventoryType);
|
|
num = ((inventoryContainer != null) ? (-397486007) : (-397486014));
|
|
break;
|
|
case 4:
|
|
num = ((num7 < inventoryContainer->Size) ? (-397486010) : (-397486011));
|
|
break;
|
|
case 6:
|
|
return num8;
|
|
case 9:
|
|
num = ((inventorySlot->ItemId != itemId) ? (-397486012) : (-397486016));
|
|
break;
|
|
case 10:
|
|
num8 = 0;
|
|
num7 = 0;
|
|
num = -397486009;
|
|
break;
|
|
case 5:
|
|
inventorySlot = inventoryContainer->GetInventorySlot(num7);
|
|
num = ((inventorySlot == null) ? (-397486012) : (-397486006));
|
|
break;
|
|
case 2:
|
|
num = -397486005;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool HasFreeInventorySlot()
|
|
{
|
|
return CountFreeInventorySlots() > 0;
|
|
}
|
|
|
|
public unsafe static int CountFreeInventorySlots()
|
|
{
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
int num = ((ptr != null) ? 1747914912 : 1747914917);
|
|
InventoryContainer* inventoryContainer = default(InventoryContainer*);
|
|
InventoryType inventoryType = default(InventoryType);
|
|
int num5 = default(int);
|
|
int num9 = default(int);
|
|
InventoryItem* inventorySlot = default(InventoryItem*);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = 1747914921;
|
|
int num4 = num2;
|
|
switch ((num4 | num3) - (num4 & num3))
|
|
{
|
|
case 6:
|
|
inventoryContainer = ptr->GetInventoryContainer(inventoryType);
|
|
num = ((inventoryContainer == null) ? 1747914922 : 1747914926);
|
|
break;
|
|
case 4:
|
|
num = ((inventoryType <= InventoryType.Inventory4) ? 1747914927 : 1747914915);
|
|
break;
|
|
case 2:
|
|
num = ((num5 < inventoryContainer->Size) ? 1747914921 : 1747914922);
|
|
break;
|
|
case 3:
|
|
inventoryType++;
|
|
num = 1747914925;
|
|
break;
|
|
case 5:
|
|
{
|
|
int num10 = num9;
|
|
num3 = 1;
|
|
num4 = num10;
|
|
num9 = (num4 | num3) + (num4 & num3);
|
|
num = 1747914920;
|
|
break;
|
|
}
|
|
case 7:
|
|
num5 = 0;
|
|
num = 1747914923;
|
|
break;
|
|
case 9:
|
|
num9 = 0;
|
|
inventoryType = InventoryType.Inventory1;
|
|
num = 1747914925;
|
|
break;
|
|
case 8:
|
|
num = ((inventorySlot->ItemId != 0) ? 1747914920 : 1747914924);
|
|
break;
|
|
case 10:
|
|
return num9;
|
|
case 12:
|
|
return 0;
|
|
case 11:
|
|
num = 1747914917;
|
|
break;
|
|
case 1:
|
|
{
|
|
int num6 = num5;
|
|
num3 = 1;
|
|
num4 = num6;
|
|
int num7 = num4 ^ num3;
|
|
int num8 = num4 & num3;
|
|
num5 = num7 + (num8 + num8);
|
|
num = 1747914923;
|
|
break;
|
|
}
|
|
case 0:
|
|
inventorySlot = inventoryContainer->GetInventorySlot(num5);
|
|
num = ((inventorySlot == null) ? 1747914924 : 1747914913);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
public unsafe static int CountInventorySlotsWithCondition(uint itemId, Predicate<int> predicate)
|
|
{
|
|
_206A_202D_202D_202C_200F_206B_206C_202C_206D_202D_206C_200C_206B_202B_200C_200E_202C_200E_200F_206B_202B_202D_200F_202D_200B_200B_206D_206A_200C_200B_202D_206F_202C_200F_206C_206A_206A_206D_200E_200C_202E((object)predicate, global::_003CModule_003E._206A_202C_200C_206F_202A_200C_200F_206F_202B_202B_200D_206F_206D_200E_206A_206B_202A_200F_200B_206C_202B_202A_202B_206C_200F_206C_202C_202C_200C_206C_206F_200C_200B_202D_200E_202A_202A_206B_206B_200F_202E<string>(-279872189));
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
int num = ((ptr != null) ? (-1746491217) : (-1746491226));
|
|
InventoryType inventoryType = default(InventoryType);
|
|
int num7 = default(int);
|
|
int num11 = default(int);
|
|
InventoryContainer* inventoryContainer = default(InventoryContainer*);
|
|
InventoryItem* inventorySlot = default(InventoryItem*);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -1746491230;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 14:
|
|
num = ((inventoryType <= InventoryType.Inventory4) ? (-1746491221) : (-1746491231));
|
|
break;
|
|
case 11:
|
|
num7 = 0;
|
|
num = -1746491225;
|
|
break;
|
|
case 13:
|
|
num11 = 0;
|
|
inventoryType = InventoryType.Inventory1;
|
|
num = -1746491220;
|
|
break;
|
|
case 9:
|
|
inventoryContainer = ptr->GetInventoryContainer(inventoryType);
|
|
num = ((inventoryContainer == null) ? (-1746491230) : (-1746491223));
|
|
break;
|
|
case 5:
|
|
num = ((num7 < inventoryContainer->Size) ? (-1746491232) : (-1746491230));
|
|
break;
|
|
case 10:
|
|
{
|
|
int num8 = num7;
|
|
num3 = 1;
|
|
num4 = num8;
|
|
int num9 = num4 ^ num3;
|
|
int num10 = num4 & num3;
|
|
num7 = num9 + (num10 + num10);
|
|
num = -1746491225;
|
|
break;
|
|
}
|
|
case 2:
|
|
inventorySlot = inventoryContainer->GetInventorySlot(num7);
|
|
num = ((inventorySlot == null) ? (-1746491224) : (-1746491227));
|
|
break;
|
|
case 8:
|
|
{
|
|
int num12 = num11;
|
|
num3 = 1;
|
|
num4 = num12;
|
|
int num13 = num4 ^ num3;
|
|
int num14 = num4 & num3;
|
|
num11 = num13 + (num14 + num14);
|
|
num = -1746491224;
|
|
break;
|
|
}
|
|
case 0:
|
|
inventoryType++;
|
|
num = -1746491220;
|
|
break;
|
|
case 7:
|
|
num = ((inventorySlot->ItemId == 0) ? (-1746491224) : (-1746491218));
|
|
break;
|
|
case 6:
|
|
num = -1746491226;
|
|
break;
|
|
case 3:
|
|
return num11;
|
|
case 1:
|
|
num = ((!predicate(inventorySlot->Quantity)) ? (-1746491224) : (-1746491222));
|
|
break;
|
|
case 12:
|
|
num = ((inventorySlot->ItemId != itemId) ? (-1746491224) : (-1746491229));
|
|
break;
|
|
case 4:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool IsItemEquipped(uint itemId)
|
|
{
|
|
return GetEquippedItemSlot(itemId) >= 0;
|
|
}
|
|
|
|
public unsafe static int GetEquippedItemSlot(uint itemId)
|
|
{
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
int num = ((ptr != null) ? 1216447237 : 1216447232);
|
|
InventoryItem* inventorySlot = default(InventoryItem*);
|
|
InventoryContainer* inventoryContainer = default(InventoryContainer*);
|
|
int num8 = default(int);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = 1216447236;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 9:
|
|
inventorySlot = inventoryContainer->GetInventorySlot(num8);
|
|
num = ((inventorySlot == null) ? 1216447246 : 1216447244);
|
|
break;
|
|
case 3:
|
|
return num8;
|
|
case 10:
|
|
{
|
|
int num7 = num8;
|
|
num3 = 1;
|
|
num4 = num7;
|
|
int num9 = num4 ^ num3;
|
|
int num10 = num4 & num3;
|
|
num8 = num9 + (num10 + num10);
|
|
num = 1216447236;
|
|
break;
|
|
}
|
|
case 4:
|
|
return -1;
|
|
case 6:
|
|
return -1;
|
|
case 5:
|
|
num = 1216447232;
|
|
break;
|
|
case 0:
|
|
num = ((num8 < inventoryContainer->Size) ? 1216447245 : 1216447234);
|
|
break;
|
|
case 2:
|
|
num8 = 0;
|
|
num = 1216447236;
|
|
break;
|
|
case 7:
|
|
return -1;
|
|
case 1:
|
|
inventoryContainer = ptr->GetInventoryContainer(InventoryType.EquippedItems);
|
|
num = ((inventoryContainer != null) ? 1216447238 : 1216447235);
|
|
break;
|
|
case 8:
|
|
num = ((inventorySlot->ItemId != itemId) ? 1216447246 : 1216447239);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
public unsafe static int GetRemainingStackCapacity(uint itemId, ExcelSheet<Item> itemSheet)
|
|
{
|
|
_206A_202D_202D_202C_200F_206B_206C_202C_206D_202D_206C_200C_206B_202B_200C_200E_202C_200E_200F_206B_202B_202D_200F_202D_200B_200B_206D_206A_200C_200B_202D_206F_202C_200F_206C_206A_206A_206D_200E_200C_202E((object)itemSheet, global::_003CModule_003E._200E_206F_206C_206C_200E_202A_206D_206B_200B_202D_202B_200F_200F_206B_206C_206F_202D_206F_206A_202D_206A_200B_200B_202B_202D_202C_200F_200D_202E_200E_200D_202A_202B_206F_202E_200E_200B_206B_200E_202E_202E<string>(-2041652730));
|
|
InventoryManager* ptr = InventoryManager.Instance();
|
|
int num = ((ptr != null) ? 2074514221 : 2074514216);
|
|
int num9 = default(int);
|
|
InventoryType inventoryType = default(InventoryType);
|
|
int num7 = default(int);
|
|
InventoryItem* inventorySlot = default(InventoryItem*);
|
|
InventoryContainer* inventoryContainer = default(InventoryContainer*);
|
|
int num8 = default(int);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = 2074514213;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 14:
|
|
return 0;
|
|
case 8:
|
|
num9 = (int)(itemSheet.GetRowOrDefault(itemId)?.StackSize ?? 0);
|
|
num = ((num9 > 1) ? 2074514215 : 2074514219);
|
|
break;
|
|
case 10:
|
|
inventoryType++;
|
|
num = 2074514220;
|
|
break;
|
|
case 11:
|
|
num7 = 0;
|
|
num = 2074514213;
|
|
break;
|
|
case 1:
|
|
inventorySlot = inventoryContainer->GetInventorySlot(num7);
|
|
num = ((inventorySlot == null) ? 2074514214 : 2074514211);
|
|
break;
|
|
case 4:
|
|
return num8;
|
|
case 2:
|
|
num8 = 0;
|
|
inventoryType = InventoryType.Inventory1;
|
|
num = 2074514220;
|
|
break;
|
|
case 6:
|
|
num = ((inventorySlot->ItemId != itemId) ? 2074514214 : 2074514208);
|
|
break;
|
|
case 15:
|
|
{
|
|
int num11 = num8;
|
|
int num12 = num9;
|
|
num3 = inventorySlot->Quantity;
|
|
num4 = num12;
|
|
num3 = ~(~num4 + num3);
|
|
num4 = num11;
|
|
num8 = (num4 | num3) + (num4 & num3);
|
|
num = 2074514214;
|
|
break;
|
|
}
|
|
case 12:
|
|
num = 2074514216;
|
|
break;
|
|
case 3:
|
|
{
|
|
int num10 = num7;
|
|
num3 = 1;
|
|
num4 = num10;
|
|
num7 = (num4 | num3) + (num4 & num3);
|
|
num = 2074514213;
|
|
break;
|
|
}
|
|
case 7:
|
|
inventoryContainer = ptr->GetInventoryContainer(inventoryType);
|
|
num = ((inventoryContainer == null) ? 2074514223 : 2074514222);
|
|
break;
|
|
case 9:
|
|
num = ((inventoryType <= InventoryType.Inventory4) ? 2074514210 : 2074514209);
|
|
break;
|
|
case 0:
|
|
num = ((num7 < inventoryContainer->Size) ? 2074514212 : 2074514223);
|
|
break;
|
|
case 13:
|
|
return 0;
|
|
case 5:
|
|
num = (((inventorySlot->Flags & InventoryItem.ItemFlags.HighQuality) != InventoryItem.ItemFlags.None) ? 2074514214 : 2074514218);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
public static int GetMaxHoldableQuantity(uint itemId, ExcelSheet<Item> itemSheet)
|
|
{
|
|
_206A_202D_202D_202C_200F_206B_206C_202C_206D_202D_206C_200C_206B_202B_200C_200E_202C_200E_200F_206B_202B_202D_200F_202D_200B_200B_206D_206A_200C_200B_202D_206F_202C_200F_206C_206A_206A_206D_200E_200C_202E((object)itemSheet, global::_003CModule_003E._200E_206F_206C_206C_200E_202A_206D_206B_200B_202D_202B_200F_200F_206B_206C_206F_202D_206F_206A_202D_206A_200B_200B_202B_202D_202C_200F_200D_202E_200E_200D_202A_202B_206F_202E_200E_200B_206B_200E_202E_202E<string>(-2041652730));
|
|
Item? rowOrDefault = itemSheet.GetRowOrDefault(itemId);
|
|
int num = (rowOrDefault.HasValue ? (-1200966345) : (-1200966350));
|
|
int stackSize = default(int);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -1200966351;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 6:
|
|
num = ((!rowOrDefault.Value.IsUnique) ? (-1200966349) : (-1200966352));
|
|
break;
|
|
case 1:
|
|
return (GetItemCount(itemId, checkEquipped: true, checkArmory: true) <= 0) ? 1 : 0;
|
|
case 4:
|
|
return GetRemainingStackCapacity(itemId, itemSheet) + CountFreeInventorySlots() * stackSize;
|
|
case 3:
|
|
return 0;
|
|
case 2:
|
|
stackSize = (int)rowOrDefault.Value.StackSize;
|
|
num = ((stackSize > 0) ? (-1200966347) : (-1200966348));
|
|
break;
|
|
case 0:
|
|
num = -1200966350;
|
|
break;
|
|
case 5:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void _206A_202D_202D_202C_200F_206B_206C_202C_206D_202D_206C_200C_206B_202B_200C_200E_202C_200E_200F_206B_202B_202D_200F_202D_200B_200B_206D_206A_200C_200B_202D_206F_202C_200F_206C_206A_206A_206D_200E_200C_202E(object P_0, string P_1)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(P_0, P_1);
|
|
}
|
|
}
|