62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using Aki.Reflection.Patching;
|
|
using BepInEx;
|
|
using EFT.UI;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
using DynamicInteraction = GClass2815;
|
|
using ItemContext = GClass2622;
|
|
using ItemInfoInteractions = GClass2816<EFT.InventoryLogic.EItemInfoButton>;
|
|
|
|
namespace IcyClawz.CustomInteractions
|
|
{
|
|
[BepInPlugin("com.IcyClawz.CustomInteractions", "IcyClawz.CustomInteractions", "1.3.0")]
|
|
public class Plugin : BaseUnityPlugin
|
|
{
|
|
private void Awake()
|
|
{
|
|
new ItemUiContextPatch().Enable();
|
|
new InteractionButtonsContainerPatch().Enable();
|
|
}
|
|
}
|
|
|
|
internal class ItemUiContextPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod() =>
|
|
typeof(ItemUiContext).GetMethod("GetItemContextInteractions", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
[PatchPostfix]
|
|
private static void Postfix(ref ItemInfoInteractions __result, ItemUiContext __instance, ItemContext itemContext)
|
|
{
|
|
foreach (var provider in CustomInteractionsManager.Providers.OfType<IItemCustomInteractionsProvider>())
|
|
{
|
|
var customInteractions = provider.GetCustomInteractions(__instance, itemContext.ViewType, itemContext.Item);
|
|
if (customInteractions != null)
|
|
{
|
|
foreach (CustomInteraction customInteraction in customInteractions)
|
|
{
|
|
__result.AddCustomInteraction(customInteraction);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class InteractionButtonsContainerPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod() =>
|
|
typeof(InteractionButtonsContainer).GetMethod("method_3", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
[PatchPrefix]
|
|
private static bool Prefix(ref InteractionButtonsContainer __instance, DynamicInteraction interaction)
|
|
{
|
|
if (interaction is CustomInteractionImpl customInteractionImpl)
|
|
{
|
|
__instance.AddCustomButton(customInteractionImpl);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|