62 lines
2.2 KiB
C#
Raw Normal View History

using Aki.Reflection.Patching;
using BepInEx;
using EFT.UI;
using System.Linq;
using System.Reflection;
using DynamicInteraction = GClass2900;
using ItemContext = GClass2710;
using ItemInfoInteractions = GClass2901<EFT.InventoryLogic.EItemInfoButton>;
namespace IcyClawz.CustomInteractions
{
[BepInPlugin("com.IcyClawz.CustomInteractions", "IcyClawz.CustomInteractions", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
new ItemUiContextPatch().Enable();
new InteractionButtonsContainerPatch().Enable();
}
}
2023-07-09 22:38:08 +03:00
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);
}
}
}
}
}
2023-07-09 22:38:08 +03:00
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;
}
}
}