feat: async inventory processing

TODO: Do !!NOT!! process containers twice!
This commit is contained in:
Yui
2024-11-06 17:45:58 -03:00
parent fa0821686b
commit a86213d3a6
2 changed files with 45 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
using System.Reflection;
using System.Diagnostics;
using System.Reflection;
using EFT;
using EFT.HealthSystem;
using EFT.UI;
@@ -14,10 +15,40 @@ namespace LootValueEX.Patches.Screens
[PatchPostfix]
private static void PatchPostfix(ref Profile ___profile_0, ref LootItemClass ___lootItemClass)
{
___profile_0.Inventory.GetPlayerItems(EFT.InventoryLogic.EPlayerItems.Equipment).ExecuteForEach(item => Plugin.Log.LogDebug($"{item.LocalizedName()} ({item.TemplateId}): {item.GetCustomHash()}"));
Profile profile = ___profile_0;
TaskCompletionSource<bool> tcsInventory = new();
CancellationTokenSource ctsInventory = new CancellationTokenSource(5000);
Task<bool> taskInventory = tcsInventory.Task;
Task.Factory.StartNew(async () =>
{
Stopwatch sw = Stopwatch.StartNew();
foreach(EFT.InventoryLogic.Item item in profile.Inventory.GetPlayerItems(EFT.InventoryLogic.EPlayerItems.Equipment))
{
Plugin.Log.LogDebug($"Equip Process: {item.LocalizedName()} ({item.TemplateId}): {await item.GetCustomHashAsync()}");
}
sw.Stop();
Plugin.Log.LogDebug($"Equipment processing finished in {sw.ElapsedMilliseconds}ms");
tcsInventory.SetResult(true);
}, ctsInventory.Token);
if(___lootItemClass != null)
___lootItemClass.GetAllItems().ExecuteForEach(item => Plugin.Log.LogDebug($"{item.LocalizedName()} ({item.TemplateId}): {item.GetCustomHash()}"));
{
LootItemClass lootItemClass = ___lootItemClass;
TaskCompletionSource<bool> tcsLoot = new();
CancellationTokenSource ctsLoot = new CancellationTokenSource(5000);
Task<bool> taskLoot = tcsLoot.Task;
Task.Factory.StartNew(async () =>
{
Stopwatch sw = Stopwatch.StartNew();
foreach (EFT.InventoryLogic.Item item in lootItemClass.GetAllItems())
{
Plugin.Log.LogDebug($"LootItemClass process: {item.LocalizedName()} ({item.TemplateId}): {await item.GetCustomHashAsync()}");
}
Plugin.Log.LogDebug($"LootItemClass processing finished in {sw.ElapsedMilliseconds}ms");
tcsLoot.SetResult(true);
}, ctsLoot.Token);
}
}
}
}