feat: added support to get item durability

This commit is contained in:
Yui
2024-10-12 19:38:51 -03:00
parent ee7ff8111b
commit fd6e821f3e
31 changed files with 2260 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
using EFT.InventoryLogic;
using SPT.Reflection.Utils;
using System.Text;
namespace LootValueEX.Extensions
{
internal static class ItemExtensions
{
internal static bool IsExamined(this Item? item) => item != null && ClientAppUtils.GetMainApp().GetClientBackEndSession().Profile.Examined(item);
internal static string CustomHash(this Item? item)
{
if (item == null)
return string.Empty;
string itemHashTemplate = string.Format("{0}|{1}|{2}", item.TemplateId, item.StackMaxSize, item.StackObjectsCount);
return "0";
}
internal static string AttributesToString(this Item? item)
{
if (item == null)
return String.Empty;
if (item.Attributes.IsNullOrEmpty())
return String.Empty;
StringBuilder sb = new StringBuilder();
item.Attributes.ForEach(attr => sb.Append($"\n{attr.Id}\n\tName: {attr.Name}\n\tBase Value: {attr.Base()}\n\tString value: {attr.StringValue()}\n\tDisplay Type: {attr.DisplayType()}"));
return sb.ToString();
}
internal static float GetDurability(this Item? item)
{
if (item == null)
return -1f;
try
{
return item.Attributes.Single(att => att.Id.Equals(EItemAttributeId.Durability)).Base();
}catch(InvalidOperationException)
{
return -1f;
}
}
}
}

View File

@@ -0,0 +1,8 @@
namespace LootValueEX.Extensions
{
internal static class TarkovApplicationExtensions
{
internal static IEnumerable<TraderClass> GetValidTraders(this EFT.TarkovApplication client) => client.GetClientBackEndSession().DisplayableTraders;
internal static bool RagfairUnlocked(this EFT.TarkovApplication client) => client.Session.RagFair.Available;
}
}

View File

@@ -0,0 +1,34 @@
using EFT.UI;
using EFT.UI.DragAndDrop;
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System.Reflection;
namespace LootValueEX.Patches
{
/// <summary>
/// This patch will affect the following screens: Stash, Weapon Preset Builder, Character Gear, Character Preset Selector, New Ragfair Offer, Message Items, Loot
/// </summary>
internal class BarterItemPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(TradingRequisitePanel).GetMethod("method_1", BindingFlags.Instance | BindingFlags.Public);
internal static bool PatchTooltip { get; private set; } = false;
internal static EFT.InventoryLogic.Item? HoveredItem { get; private set; }
[PatchPrefix]
static void EnableTooltipPatch(GClass2064 ___gclass2064_0)
{
//This does not check if the item has been examined since the game also show what the item is on the barter regardless
PatchTooltip = true;
HoveredItem = ___gclass2064_0.RequiredItem;
}
[PatchPostfix]
static void DisableTooltipPatch()
{
PatchTooltip = false;
HoveredItem = null;
}
}
}

View File

@@ -0,0 +1,35 @@
using EFT.InventoryLogic;
using EFT.UI.DragAndDrop;
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System.Reflection;
namespace LootValueEX.Patches
{
/// <summary>
/// This patch will affect the following screens: Stash, Weapon Preset Builder, Character Gear, Character Preset Selector, New Ragfair Offer, Message Items, Loot
/// </summary>
internal class GridItemTooltipPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(GridItemView).GetMethod("ShowTooltip", BindingFlags.Instance | BindingFlags.Public);
internal static bool PatchTooltip { get; private set; } = false;
internal static EFT.InventoryLogic.Item? HoveredItem { get; private set; }
[PatchPrefix]
static void EnableTooltipPatch(GridItemView __instance)
{
if (!__instance.Item.IsExamined())
return;
PatchTooltip = true;
HoveredItem = __instance.Item;
}
[PatchPostfix]
static void DisableTooltipPatch()
{
PatchTooltip = false;
HoveredItem = null;
}
}
}

View File

@@ -0,0 +1,34 @@
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace LootValueEX.Patches
{
internal class HandbookPatching : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(EFT.HandBook.EntityIcon).GetMethod("method_1", BindingFlags.Public | BindingFlags.Instance);
internal static bool PatchTooltip { get; private set; } = false;
internal static EFT.InventoryLogic.Item? HoveredItem { get; private set; }
[PatchPrefix]
internal static void EnableTooltipPatch(ref EFT.InventoryLogic.Item ___item_0)
{
if (!___item_0.IsExamined())
return;
PatchTooltip = true;
HoveredItem = ___item_0;
}
[PatchPostfix]
internal static void DisableTooltipPatch()
{
PatchTooltip = false;
HoveredItem = null;
}
}
}

View File

@@ -0,0 +1,28 @@
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using System.Reflection;
namespace LootValueEX.Patches
{
class InsuranceGridPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(EFT.UI.Insurance.InsuranceItemView).GetMethod("OnPointerEnter", BindingFlags.Public | BindingFlags.Instance);
internal static bool PatchTooltip { get; private set; } = false;
internal static EFT.InventoryLogic.Item? HoveredItem { get; private set; }
[PatchPrefix]
internal static void EnableTooltipPatch(ref EFT.InventoryLogic.Item ___item_0)
{
if (!___item_0.IsExamined())
return;
PatchTooltip = true;
HoveredItem = ___item_0;
}
[PatchPostfix]
internal static void DisableTooltipPatch()
{
PatchTooltip = false;
HoveredItem = null;
}
}
}

View File

@@ -0,0 +1,29 @@
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using System.Reflection;
namespace LootValueEX.Patches
{
class InsuranceSlotPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(EFT.UI.Insurance.InsuranceSlotItemView).GetMethod("OnPointerEnter", BindingFlags.Public | BindingFlags.Instance);
internal static bool PatchTooltip { get; private set; } = false;
internal static EFT.InventoryLogic.Item? HoveredItem { get; private set; }
[PatchPrefix]
internal static void EnableTooltipPatch(EFT.UI.Insurance.InsuranceSlotItemView __instance)
{
if (!__instance.Item.IsExamined())
return;
PatchTooltip = true;
HoveredItem = __instance.Item;
}
[PatchPostfix]
internal static void DisableTooltipPatch()
{
PatchTooltip = false;
HoveredItem = null;
}
}
}

View File

@@ -0,0 +1,30 @@
using SPT.Reflection.Patching;
using System.Reflection;
namespace LootValueEX.Patches
{
internal class ItemPricePatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(EFT.UI.PriceTooltip).GetMethod("Show",
BindingFlags.Instance | BindingFlags.Public,
null,
[typeof(EFT.InventoryLogic.EOwnerType), typeof(string), typeof(int), typeof(string)],
null);
internal static bool PatchTooltip { get; private set; } = false;
[PatchPrefix]
internal static void EnableTooltipPatch()
{
if (TradingItemPatch.HoveredItem == null)
return;
PatchTooltip = true;
}
[PatchPostfix]
internal static void DisableTooltipPatch()
{
PatchTooltip = false;
}
}
}

View File

@@ -0,0 +1,52 @@
using EFT.UI;
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace LootValueEX.Patches
{
internal class TooltipPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(SimpleTooltip).GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(x => x.Name == "Show").ToList()[0];
[PatchPostfix]
public static void AlterText(SimpleTooltip __instance, string text)
{
StackTrace stackTrace = new StackTrace();
Plugin.Log.LogDebug("Stacktrace of tooltip call: \n" + stackTrace.ToString());
if (GridItemTooltipPatch.PatchTooltip)
{
text += $"<br>TemplateID: {GridItemTooltipPatch.HoveredItem?.TemplateId}<br>Item hashsum: {GridItemTooltipPatch.HoveredItem?.GetHashSum()}<br>Item durability: {GridItemTooltipPatch.HoveredItem?.GetDurability()}<br><color=#ff0fff><b>GridItemView</b></color>";
Plugin.Log.LogDebug(GridItemTooltipPatch.HoveredItem?.AttributesToString());
}
if (InsuranceSlotPatch.PatchTooltip)
{
text += $"<br>TemplateID: {InsuranceSlotPatch.HoveredItem?.TemplateId}<br><color=#00ffff><b>InsuranceSlotItemView</b></color>";
}
if (ItemPricePatch.PatchTooltip)
{
text += $"<br>TemplateID: {TradingItemPatch.HoveredItem?.TemplateId}<br><color=#00ff00><b>PriceTooltip</b></color>";
}
if (HandbookPatching.PatchTooltip)
{
text += $"<br>TemplateID: {HandbookPatching.HoveredItem?.TemplateId}<br><color=#0000ff><b>EntityIcon</b></color>";
}
if (InsuranceGridPatch.PatchTooltip)
{
text += $"<br>TemplateID: {InsuranceGridPatch.HoveredItem?.TemplateId}<br><color=#21f788><b>InsuranceItemView</b></color>";
}
if (BarterItemPatch.PatchTooltip)
{
text += $"<br>TemplateID: {BarterItemPatch.HoveredItem?.TemplateId}<br><color=#ff6521><b>TradingRequisitePanel</b></color>";
}
__instance.SetText(text);
}
}
}

View File

@@ -0,0 +1,26 @@
using LootValueEX.Extensions;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System.Reflection;
namespace LootValueEX.Patches
{
class TradingItemPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(EFT.UI.DragAndDrop.TradingItemView).GetMethod("ShowTooltip", BindingFlags.Instance | BindingFlags.Public);
internal static EFT.InventoryLogic.Item? HoveredItem { get; private set; }
[PatchPrefix]
internal static void GetHoveredItem(EFT.UI.DragAndDrop.TradingItemView __instance)
{
if (!__instance.Item.IsExamined())
return;
HoveredItem = __instance.Item;
}
[PatchPostfix]
internal static void RemoveHoveredItem()
{
HoveredItem = null;
}
}
}

24
Plugin/Plugin.cs Normal file
View File

@@ -0,0 +1,24 @@
using BepInEx;
using BepInEx.Logging;
namespace LootValueEX
{
[BepInPlugin("pro.kaiden.lootvalueex", "LootValueEX", "0.1.0")]
internal class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log { get; private set; }
private void Awake()
{
Log = base.Logger;
new Patches.GridItemTooltipPatch().Enable();
new Patches.TooltipPatch().Enable();
new Patches.InsuranceGridPatch().Enable();
new Patches.InsuranceSlotPatch().Enable();
new Patches.ItemPricePatch().Enable();
new Patches.TradingItemPatch().Enable();
new Patches.HandbookPatching().Enable();
new Patches.BarterItemPatch().Enable();
}
}
}

88
Plugin/Plugin.csproj Normal file
View File

@@ -0,0 +1,88 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>LootValueEX</AssemblyName>
<RootNamespace>LootValueEX</RootNamespace>
<LangVersion>latest</LangVersion>
<AppDesignerFolder>..\Properties</AppDesignerFolder>
</PropertyGroup>
<ItemGroup>
<Reference Include="PhysicsModule">
<HintPath>..\References\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="0Harmony">
<HintPath>..\References\BepInEx\0Harmony.dll</HintPath>
</Reference>
<Reference Include="spt-common">
<HintPath>..\References\SPT\spt-common.dll</HintPath>
</Reference>
<Reference Include="spt-reflection">
<HintPath>..\References\SPT\spt-reflection.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\References\hollowed.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\References\BepInEx\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Comfort">
<HintPath>..\References\Managed\Comfort.dll</HintPath>
</Reference>
<Reference Include="Comfort.Unity, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\Comfort.Unity.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Sirenix.Serialization, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\Sirenix.Serialization.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Unity.TextMeshPro, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\References\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\References\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\References\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy &quot;$(SolutionDir)Plugin\bin\$(ConfigurationName)\net472\LootValueEX.dll&quot; &quot;G:\Games\eft-dev\BepInEx\plugins\&quot;" />
</Target>
</Project>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace LootValueEX.Utils
{
internal class HashingUtils
{
internal static string ConvertToSha256(string value)
{
StringBuilder sb = new StringBuilder();
using (var hash = SHA256.Create())
{
Encoding encoding = Encoding.UTF8;
byte[] result = hash.ComputeHash(encoding.GetBytes(value));
foreach (byte b in result)
{
sb.Append(b.ToString("x2"));
}
}
return sb.ToString();
}
}
}