From 302cfe9af14b768c21165e2ebf7a3a8f741e59b8 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:46:25 -0700 Subject: [PATCH] Load ammo preset will pull from equipment --- Patches/LoadMagPresetsPatch.cs | 52 ++++++++++++++++++++++++++++++++++ Plugin.cs | 1 + 2 files changed, 53 insertions(+) create mode 100644 Patches/LoadMagPresetsPatch.cs diff --git a/Patches/LoadMagPresetsPatch.cs b/Patches/LoadMagPresetsPatch.cs new file mode 100644 index 0000000..95f2123 --- /dev/null +++ b/Patches/LoadMagPresetsPatch.cs @@ -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 __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); + } + } + } + } +} diff --git a/Plugin.cs b/Plugin.cs index fc514df..7fed687 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -44,6 +44,7 @@ namespace UIFixes new FocusTradeQuantityPatch().Enable(); RememberRepairerPatches.Enable(); new GridWindowButtonsPatch().Enable(); + new LoadMagPresetsPatch().Enable(); } public static bool InRaid()