diff --git a/Patches/RebindGrenadesPatch.cs b/Patches/RebindGrenadesPatch.cs new file mode 100644 index 0000000..7262243 --- /dev/null +++ b/Patches/RebindGrenadesPatch.cs @@ -0,0 +1,48 @@ +using EFT; +using EFT.InventoryLogic; +using HarmonyLib; +using SPT.Reflection.Patching; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace UIFixes +{ + public class RebindGrenadesPatch : ModulePatch + { + private static readonly EquipmentSlot[] Slots = [EquipmentSlot.Pockets, EquipmentSlot.TacticalVest, EquipmentSlot.Backpack, EquipmentSlot.SecuredContainer, EquipmentSlot.ArmBand]; + + protected override MethodBase GetTargetMethod() + { + Type type = typeof(Player).GetNestedTypes().Single(t => t.GetField("DiscardResult") != null); + return AccessTools.Method(type, "RaiseEvents"); + } + + // This is a grenade specific event emitter that has all the info needed to do this + [PatchPostfix] + public static void Postfix(CommandStatus status, GClass2799 ___DiscardResult) + { + if (status != CommandStatus.Succeed) + { + return; + } + + var unbindResult = ___DiscardResult.UnbindResults.FirstOrDefault(); + if (unbindResult != null) + { + InventoryControllerClass controller = unbindResult.Controller; + EBoundItem index = unbindResult.Index; + + List matchingGrenades = []; + controller.GetAcceptableItemsNonAlloc(Slots, matchingGrenades, g => g.TemplateId == unbindResult.Item.TemplateId); + + var nextGrenade = matchingGrenades.FirstOrDefault(g => controller.IsAtBindablePlace(g)); + if (nextGrenade != null) + { + controller.TryRunNetworkTransaction(GClass2818.Run(controller, nextGrenade, index, true), null); + } + } + } + } +} diff --git a/Plugin.cs b/Plugin.cs index e57e4c3..902ed61 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -56,6 +56,7 @@ namespace UIFixes new FixTraderControllerSimulateFalsePatch().Enable(); LoadMultipleMagazinesPatches.Enable(); new PutToolsBackPatch().Enable(); + new RebindGrenadesPatch().Enable(); } public static bool InRaid()