Rebind matching grenades

This commit is contained in:
Tyfon
2024-07-07 16:19:52 -07:00
parent db97ca1070
commit 1ed8b9d7f4
2 changed files with 49 additions and 0 deletions

View File

@@ -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<GrenadeClass> matchingGrenades = [];
controller.GetAcceptableItemsNonAlloc<GrenadeClass>(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);
}
}
}
}
}

View File

@@ -56,6 +56,7 @@ namespace UIFixes
new FixTraderControllerSimulateFalsePatch().Enable();
LoadMultipleMagazinesPatches.Enable();
new PutToolsBackPatch().Enable();
new RebindGrenadesPatch().Enable();
}
public static bool InRaid()