using Aki.Reflection.Patching; using BepInEx; using BepInEx.Configuration; using EFT.HandBook; using EFT.InventoryLogic; using EFT.UI; using EFT.UI.DragAndDrop; using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; namespace IcyClawz.MunitionsExpert { [BepInPlugin("com.IcyClawz.MunitionsExpert", "IcyClawz.MunitionsExpert", "1.2.0")] public class Plugin : BaseUnityPlugin { internal static ConfigEntry ColorizeItemBackgrounds; private void Awake() { ColorizeItemBackgrounds = Config.Bind("General", "Colorize Icon Backgrounds", true); IconCache.Initialize(); new StaticIconsPatch().Enable(); new AmmoTemplatePatch().Enable(); new ItemViewPatch().Enable(); new EntityIconPatch().Enable(); } } internal class StaticIconsPatch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(StaticIcons).GetMethod("GetAttributeIcon", BindingFlags.Public | BindingFlags.Instance); [PatchPrefix] private static bool PatchPrefix(ref Sprite __result, Enum id) { var icon = IconCache.Get(id); if (icon != null) { __result = icon; return false; } return true; } } internal class AmmoTemplatePatch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(AmmoTemplate).GetMethod("GetCachedReadonlyQualities", BindingFlags.Public | BindingFlags.Instance); [PatchPrefix] private static bool PatchPrefix(ref List __result, AmmoTemplate __instance) { if (__instance.GetCachedQualities() != null) { __result = null; return false; } return true; } [PatchPostfix] private static void PatchPostfix(ref List __result, AmmoTemplate __instance) { if (__result == null) { __result = __instance.GetCachedQualities(); return; } __instance.AddExtraAttributes(); } } internal class ItemViewPatch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(ItemView).GetMethod("UpdateColor", BindingFlags.NonPublic | BindingFlags.Instance); [PatchPrefix] private static void PatchPrefix(ref ItemView __instance) { if (Plugin.ColorizeItemBackgrounds.Value) { __instance.OverrideColor(__instance.Item); } } } internal class EntityIconPatch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(EntityIcon).GetMethod("Show", BindingFlags.Public | BindingFlags.Instance); [PatchPostfix] private static void PatchPostfix(ref EntityIcon __instance, Item item) { if (Plugin.ColorizeItemBackgrounds.Value) { __instance.OverrideColor(item); } } } }