using Aki.Reflection.Patching; using BepInEx; using EFT.UI; using System.Linq; using System.Reflection; using DynamicInteraction = GClass2816; using ItemContext = GClass2623; using ItemInfoInteractions = GClass2817; namespace IcyClawz.CustomInteractions; [BepInPlugin("com.IcyClawz.CustomInteractions", "IcyClawz.CustomInteractions", "1.3.1")] 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, ref ItemUiContext __instance, ItemContext itemContext) { foreach (var provider in CustomInteractionsManager.Providers.OfType()) { var interactions = provider.GetCustomInteractions(__instance, itemContext.ViewType, itemContext.Item); if (interactions is null) continue; foreach (CustomInteraction interaction in interactions) __result.AddCustomInteraction(interaction); } } } 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 impl) { __instance.AddCustomButton(impl); return false; } return true; } }