feat: added inventory patch, in-raid and stash

This commit is contained in:
Yui
2024-11-04 01:37:34 -03:00
parent ac5140ce24
commit fa0821686b
10 changed files with 43 additions and 18 deletions

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.Tooltips
{
/// <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.Tooltips
{
/// <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 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.Tooltips
{
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.Tooltips
{
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.Tooltips
{
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.Tooltips
{
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.Tooltips
{
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>Template: {GridItemTooltipPatch.HoveredItem?.Template}<br>Item hashsum: {GridItemTooltipPatch.HoveredItem?.GetHashSum()}<br>Custom hash: {GridItemTooltipPatch.HoveredItem?.GetCustomHash()}<br>Item durability: {GridItemTooltipPatch.HoveredItem?.GetDurability()}<br>Item uses: {GridItemTooltipPatch.HoveredItem?.GetUses()}<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.Tooltips
{
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;
}
}
}