Load ammo preset will pull from equipment

This commit is contained in:
Tyfon
2024-06-04 12:46:25 -07:00
parent 7b68597808
commit 302cfe9af1
2 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using Aki.Reflection.Patching;
using EFT.InventoryLogic;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace UIFixes
{
public class LoadMagPresetsPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
Type type = AccessTools.Method(typeof(ISession), nameof(ISession.SaveMagBuild)).GetParameters()[0].ParameterType;
return AccessTools.Method(type, "smethod_0");
}
// This method returns a list of places to search for ammo. For whatever reason, it only looks
// in equipment if stash + sorting table are not present.
// Can't just add equipment because that includes equipped slots and it likes to pull the chambered bullet out of equipped guns
[PatchPostfix]
public static void Postfix(Inventory inventory, List<LootItemClass> __result)
{
if (!__result.Contains(inventory.Equipment))
{
var vest = inventory.Equipment.GetSlot(EquipmentSlot.TacticalVest);
if (vest.ContainedItem is LootItemClass vestLootItem)
{
__result.Add(vestLootItem);
}
var pockets = inventory.Equipment.GetSlot(EquipmentSlot.Pockets);
if (pockets.ContainedItem is LootItemClass pocketsLootItem)
{
__result.Add(pocketsLootItem);
}
var backpack = inventory.Equipment.GetSlot(EquipmentSlot.Backpack);
if (backpack.ContainedItem is LootItemClass backpackLootItem)
{
__result.Add(backpackLootItem);
}
var secureContainer = inventory.Equipment.GetSlot(EquipmentSlot.SecuredContainer);
if (secureContainer.ContainedItem is LootItemClass secureContainerLootItem)
{
__result.Add(secureContainerLootItem);
}
}
}
}
}

View File

@@ -44,6 +44,7 @@ namespace UIFixes
new FocusTradeQuantityPatch().Enable();
RememberRepairerPatches.Enable();
new GridWindowButtonsPatch().Enable();
new LoadMagPresetsPatch().Enable();
}
public static bool InRaid()