2023-07-08 23:42:42 +03:00
|
|
|
using Aki.Reflection.Patching;
|
|
|
|
using BepInEx;
|
|
|
|
using EFT.UI;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
|
2023-10-15 13:39:51 +03:00
|
|
|
using DynamicInteraction = GClass2816;
|
|
|
|
using ItemContext = GClass2623;
|
|
|
|
using ItemInfoInteractions = GClass2817<EFT.InventoryLogic.EItemInfoButton>;
|
2023-07-08 23:42:42 +03:00
|
|
|
|
|
|
|
namespace IcyClawz.CustomInteractions
|
|
|
|
{
|
2023-10-15 13:39:51 +03:00
|
|
|
[BepInPlugin("com.IcyClawz.CustomInteractions", "IcyClawz.CustomInteractions", "1.3.1")]
|
2023-07-08 23:42:42 +03:00
|
|
|
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
|
2023-07-08 23:42:42 +03:00
|
|
|
{
|
|
|
|
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
|
2023-07-08 23:42:42 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|