forked from aly/qstbak
355 lines
12 KiB
C#
355 lines
12 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using Dalamud.Plugin.Services;
|
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
|
using LLib.GameData;
|
|
using Lumina.Excel;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace LLib.Gear;
|
|
|
|
public sealed class BestItemFinder
|
|
{
|
|
public static readonly IReadOnlyList<InventoryType> ArmoryAndEquipped;
|
|
|
|
public static readonly IReadOnlyList<InventoryType> ArmoryEquippedAndBags;
|
|
|
|
private readonly GearStatsCalculator _calculator;
|
|
|
|
private readonly ExcelSheet<Item> _itemSheet;
|
|
|
|
private readonly ExcelSheet<ClassJobCategory> _classJobCategorySheet;
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
public BestItemFinder(GearStatsCalculator calculator, IDataManager dataManager)
|
|
{
|
|
_206D_206D_200D_200E_206B_206F_200E_200E_206D_200F_200F_202C_206F_200D_200C_200E_206A_202D_206A_200D_202A_202E_200B_206C_206C_202A_206A_202B_202D_202E_200F_200B_206E_202C_202A_206F_202D_202B_200F_200C_202E((object)calculator, global::_003CModule_003E._206A_206D_202C_206E_206D_206E_202A_200F_200D_206A_200F_206C_202C_202D_206D_206A_200D_200F_206A_206C_202C_206D_206E_200F_200F_200C_206B_200B_206B_206E_202B_206B_200E_200E_200B_206F_200F_202E_200C_200C_202E<string>(1061074664));
|
|
_206D_206D_200D_200E_206B_206F_200E_200E_206D_200F_200F_202C_206F_200D_200C_200E_206A_202D_206A_200D_202A_202E_200B_206C_206C_202A_206A_202B_202D_202E_200F_200B_206E_202C_202A_206F_202D_202B_200F_200C_202E((object)dataManager, global::_003CModule_003E._206E_202B_206C_202A_202A_200E_202B_202B_206D_200B_200C_206B_200B_206D_202E_202D_206C_202B_200B_206A_202D_206C_202A_200F_202D_200C_200B_200B_200B_200D_202C_206E_206D_202E_200C_206B_206A_206D_202D_202C_202E<string>(-1509101314));
|
|
_calculator = calculator;
|
|
_itemSheet = dataManager.GetExcelSheet<Item>();
|
|
_classJobCategorySheet = dataManager.GetExcelSheet<ClassJobCategory>();
|
|
}
|
|
|
|
public unsafe BestItemRef? FindBest(EClassJob job, IReadOnlyList<uint> acceptedSlotCategories, StatPriority priority, IReadOnlyList<InventoryType> containers, byte playerLevel, EItemRankingMode rankingMode, BestItemRef? excludeContainerSlot = null)
|
|
{
|
|
BestItemRef? result = null;
|
|
ItemRankingKey best = ItemRankingKey.None;
|
|
int num = (job.DealsMagicDamage() ? (-539654856) : (-539654853));
|
|
InventoryItem* inventorySlot = default(InventoryItem*);
|
|
BestItemRef valueOrDefault = default(BestItemRef);
|
|
int num10 = default(int);
|
|
Item value = default(Item);
|
|
Item? rowOrDefault = default(Item?);
|
|
InventoryType current = default(InventoryType);
|
|
ItemRankingKey itemRankingKey = default(ItemRankingKey);
|
|
EBaseParam param = default(EBaseParam);
|
|
InventoryContainer* inventoryContainer = default(InventoryContainer*);
|
|
InventoryManager* ptr = default(InventoryManager*);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -539654855;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
int num13;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 3:
|
|
num = -539654853;
|
|
break;
|
|
case 2:
|
|
num13 = 12;
|
|
goto IL_0093;
|
|
case 0:
|
|
return null;
|
|
case 1:
|
|
num13 = 13;
|
|
goto IL_0093;
|
|
case 4:
|
|
{
|
|
IEnumerator<InventoryType> enumerator = containers.GetEnumerator();
|
|
try
|
|
{
|
|
num = 1383035705;
|
|
while (true)
|
|
{
|
|
int num7 = num;
|
|
num3 = 1383035707;
|
|
num4 = num7;
|
|
int num8 = num4 + num3;
|
|
int num9 = num4 & num3;
|
|
switch (num8 - (num9 + num9))
|
|
{
|
|
case 2:
|
|
num = (_202D_206A_202A_206D_202C_202E_206A_206C_200D_200F_206E_202B_206D_206D_200B_206D_206B_200E_200D_206E_206C_206A_202B_206D_200B_200D_202B_202B_206B_206A_200D_202A_200B_206D_200B_202D_206A_202E_206F_206D_202E((IEnumerator)enumerator) ? 1383035691 : 1383035701);
|
|
break;
|
|
case 13:
|
|
num = ((inventorySlot->ItemId == 0) ? 1383035706 : 1383035700);
|
|
break;
|
|
case 4:
|
|
num = ((valueOrDefault.Slot == num10) ? 1383035706 : 1383035690);
|
|
break;
|
|
case 6:
|
|
value = rowOrDefault.Value;
|
|
num = ((!IsAcceptedSlot(value.EquipSlotCategory.RowId, acceptedSlotCategories)) ? 1383035706 : 1383035697);
|
|
break;
|
|
case 5:
|
|
valueOrDefault = excludeContainerSlot.GetValueOrDefault();
|
|
num = ((valueOrDefault.Container != current) ? 1383035690 : 1383035711);
|
|
break;
|
|
case 0:
|
|
num = 1383035705;
|
|
break;
|
|
case 3:
|
|
{
|
|
EquipmentStats equipmentStats = _calculator.CalculateGearStats(inventorySlot);
|
|
itemRankingKey = new ItemRankingKey(value.LevelItem.RowId, priority.Score(equipmentStats), equipmentStats.Get(param));
|
|
num = ((!IsUpgrade(rankingMode, itemRankingKey, best)) ? 1383035706 : 1383035708);
|
|
break;
|
|
}
|
|
case 9:
|
|
inventorySlot = inventoryContainer->GetInventorySlot(num10);
|
|
num = ((inventorySlot == null) ? 1383035706 : 1383035702);
|
|
break;
|
|
case 10:
|
|
num = ((value.LevelEquip > playerLevel) ? 1383035706 : 1383035703);
|
|
break;
|
|
case 15:
|
|
num = ((!excludeContainerSlot.HasValue) ? 1383035690 : 1383035710);
|
|
break;
|
|
case 7:
|
|
result = new BestItemRef(current, num10, inventorySlot->ItemId, itemRankingKey.ItemLevel, itemRankingKey.Score);
|
|
best = itemRankingKey;
|
|
num = 1383035706;
|
|
break;
|
|
case 11:
|
|
num = ((num10 < inventoryContainer->Size) ? 1383035698 : 1383035705);
|
|
break;
|
|
case 12:
|
|
num = ((!IsItemForJob(value, job)) ? 1383035706 : 1383035704);
|
|
break;
|
|
case 16:
|
|
current = enumerator.Current;
|
|
inventoryContainer = ptr->GetInventoryContainer(current);
|
|
num = ((inventoryContainer == null) ? 1383035705 : 1383035699);
|
|
break;
|
|
case 1:
|
|
{
|
|
int num11 = num10;
|
|
num3 = 1;
|
|
num4 = num11;
|
|
num10 = (num4 | num3) + (num4 & num3);
|
|
num = 1383035696;
|
|
break;
|
|
}
|
|
case 17:
|
|
rowOrDefault = _itemSheet.GetRowOrDefault(inventorySlot->ItemId);
|
|
num = ((!rowOrDefault.HasValue) ? 1383035706 : 1383035709);
|
|
break;
|
|
case 8:
|
|
num10 = 0;
|
|
num = 1383035696;
|
|
break;
|
|
case 14:
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
num = ((enumerator == null) ? 1816874723 : 1816874720);
|
|
while (true)
|
|
{
|
|
int num12 = num;
|
|
num3 = 1816874722;
|
|
num4 = num12;
|
|
switch ((num4 | num3) - (num4 & num3))
|
|
{
|
|
case 0:
|
|
num = 1816874720;
|
|
break;
|
|
case 2:
|
|
_206C_202E_206F_206E_206E_200E_200C_206A_200B_206E_202C_202E_206D_202D_202D_202E_206E_206D_200D_200D_202A_202B_202C_202B_200B_200F_202B_202B_200F_200C_202D_206C_200D_202B_200E_200F_206D_206E_206B_200C_202E((IDisposable)enumerator);
|
|
num = 1816874723;
|
|
break;
|
|
case 1:
|
|
goto end_IL_042f;
|
|
}
|
|
continue;
|
|
end_IL_042f:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
IL_0093:
|
|
param = (EBaseParam)num13;
|
|
ptr = InventoryManager.Instance();
|
|
num = ((ptr != null) ? (-539654851) : (-539654855));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool IsUpgrade(EItemRankingMode mode, ItemRankingKey candidate, ItemRankingKey best)
|
|
{
|
|
int num = ((mode != EItemRankingMode.DamageFirst) ? (-1413450028) : (-1413450032));
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -1413450029;
|
|
int num4 = num2;
|
|
switch ((num4 | num3) - (num4 & num3))
|
|
{
|
|
case 8:
|
|
num = -1413450032;
|
|
break;
|
|
case 7:
|
|
num = ((mode != EItemRankingMode.ItemLevelFirst) ? (-1413450031) : (-1413450025));
|
|
break;
|
|
case 9:
|
|
return candidate.ItemLevel > best.ItemLevel;
|
|
case 4:
|
|
num = ((candidate.ItemLevel == best.ItemLevel) ? (-1413450027) : (-1413450022));
|
|
break;
|
|
case 2:
|
|
num = ((candidate.Score == best.Score) ? (-1413450029) : (-1413450026));
|
|
break;
|
|
case 5:
|
|
return candidate.Score > best.Score;
|
|
case 1:
|
|
return candidate.Damage > best.Damage;
|
|
case 3:
|
|
num = ((candidate.Damage == best.Damage) ? (-1413450028) : (-1413450030));
|
|
break;
|
|
case 6:
|
|
return candidate.Score > best.Score;
|
|
case 0:
|
|
return candidate.ItemLevel > best.ItemLevel;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsItemForJob(Item item, EClassJob job)
|
|
{
|
|
uint rowId = item.ClassJobCategory.RowId;
|
|
int num = ((rowId != 0) ? (-1361138782) : (-1361138777));
|
|
ClassJobCategory? rowOrDefault = default(ClassJobCategory?);
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -1361138778;
|
|
int num4 = num2;
|
|
switch ((num4 | num3) - (num4 & num3))
|
|
{
|
|
case 3:
|
|
num = -1361138777;
|
|
break;
|
|
case 2:
|
|
return false;
|
|
case 1:
|
|
return true;
|
|
case 0:
|
|
return job.IsInCategory(rowOrDefault.Value);
|
|
case 4:
|
|
rowOrDefault = _classJobCategorySheet.GetRowOrDefault(rowId);
|
|
num = (rowOrDefault.HasValue ? (-1361138778) : (-1361138780));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool IsAcceptedSlot(uint itemSlotCategory, IReadOnlyList<uint> accepted)
|
|
{
|
|
IEnumerator<uint> enumerator = accepted.GetEnumerator();
|
|
try
|
|
{
|
|
int num = -1139406440;
|
|
while (true)
|
|
{
|
|
int num2 = num;
|
|
int num3 = -1139406439;
|
|
int num4 = num2;
|
|
int num5 = num4 + num3;
|
|
int num6 = num4 & num3;
|
|
switch (num5 - (num6 + num6))
|
|
{
|
|
case 1:
|
|
num = (_202D_206A_202A_206D_202C_202E_206A_206C_200D_200F_206E_202B_206D_206D_200B_206D_206B_200E_200D_206E_206C_206A_202B_206D_200B_200D_202B_202B_206B_206A_200D_202A_200B_206D_200B_202D_206A_202E_206F_206D_202E((IEnumerator)enumerator) ? (-1139406438) : (-1139406439));
|
|
break;
|
|
case 3:
|
|
num = ((enumerator.Current != itemSlotCategory) ? (-1139406440) : (-1139406437));
|
|
break;
|
|
case 4:
|
|
num = -1139406440;
|
|
break;
|
|
case 2:
|
|
return true;
|
|
case 0:
|
|
goto end_IL_0012;
|
|
}
|
|
continue;
|
|
end_IL_0012:
|
|
break;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
int num = ((enumerator == null) ? (-1966232189) : (-1966232192));
|
|
while (true)
|
|
{
|
|
int num7 = num;
|
|
int num3 = -1966232191;
|
|
int num4 = num7;
|
|
switch ((num4 | num3) - (num4 & num3))
|
|
{
|
|
case 0:
|
|
num = -1966232192;
|
|
break;
|
|
case 1:
|
|
_206C_202E_206F_206E_206E_200E_200C_206A_200B_206E_202C_202E_206D_202D_202D_202E_206E_206D_200D_200D_202A_202B_202C_202B_200B_200F_202B_202B_200F_200C_202D_206C_200D_202B_200E_200F_206D_206E_206B_200C_202E((IDisposable)enumerator);
|
|
num = -1966232189;
|
|
break;
|
|
case 2:
|
|
goto end_IL_00c5;
|
|
}
|
|
continue;
|
|
end_IL_00c5:
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static BestItemFinder()
|
|
{
|
|
InventoryType[] array = new InventoryType[12];
|
|
_200B_206D_202E_206F_206A_206F_202B_200E_206E_200B_202D_206C_200F_206D_200D_206B_206A_202C_202C_206E_206E_202C_206D_206C_206F_202C_200F_200F_202A_202D_202B_206F_200E_202C_202C_200D_200B_206D_200D_200D_202E((Array)array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
|
|
ArmoryAndEquipped = new global::_003C_003Ez__ReadOnlyArray<InventoryType>(array);
|
|
InventoryType[] array2 = new InventoryType[16];
|
|
_200B_206D_202E_206F_206A_206F_202B_200E_206E_200B_202D_206C_200F_206D_200D_206B_206A_202C_202C_206E_206E_202C_206D_206C_206F_202C_200F_200F_202A_202D_202B_206F_200E_202C_202C_200D_200B_206D_200D_200D_202E((Array)array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
|
|
ArmoryEquippedAndBags = new global::_003C_003Ez__ReadOnlyArray<InventoryType>(array2);
|
|
}
|
|
|
|
static void _206D_206D_200D_200E_206B_206F_200E_200E_206D_200F_200F_202C_206F_200D_200C_200E_206A_202D_206A_200D_202A_202E_200B_206C_206C_202A_206A_202B_202D_202E_200F_200B_206E_202C_202A_206F_202D_202B_200F_200C_202E(object P_0, string P_1)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(P_0, P_1);
|
|
}
|
|
|
|
static bool _202D_206A_202A_206D_202C_202E_206A_206C_200D_200F_206E_202B_206D_206D_200B_206D_206B_200E_200D_206E_206C_206A_202B_206D_200B_200D_202B_202B_206B_206A_200D_202A_200B_206D_200B_202D_206A_202E_206F_206D_202E(IEnumerator P_0)
|
|
{
|
|
return P_0.MoveNext();
|
|
}
|
|
|
|
static void _206C_202E_206F_206E_206E_200E_200C_206A_200B_206E_202C_202E_206D_202D_202D_202E_206E_206D_200D_200D_202A_202B_202C_202B_200B_200F_202B_202B_200F_200C_202D_206C_200D_202B_200E_200F_206D_206E_206B_200C_202E(IDisposable P_0)
|
|
{
|
|
P_0.Dispose();
|
|
}
|
|
|
|
static void _200B_206D_202E_206F_206A_206F_202B_200E_206E_200B_202D_206C_200F_206D_200D_206B_206A_202C_202C_206E_206E_202C_206D_206C_206F_202C_200F_200F_202A_202D_202B_206F_200E_202C_202C_200D_200B_206D_200D_200D_202E(Array P_0, RuntimeFieldHandle P_1)
|
|
{
|
|
RuntimeHelpers.InitializeArray(P_0, P_1);
|
|
}
|
|
}
|