2023-07-08 23:42:42 +03:00
|
|
|
using Aki.Reflection.Patching;
|
|
|
|
using BepInEx;
|
2023-07-31 21:55:40 +03:00
|
|
|
using BepInEx.Configuration;
|
2023-07-08 23:42:42 +03:00
|
|
|
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
|
|
|
|
{
|
2023-10-09 03:21:08 +03:00
|
|
|
[BepInPlugin("com.IcyClawz.MunitionsExpert", "IcyClawz.MunitionsExpert", "1.2.0")]
|
2023-07-08 23:42:42 +03:00
|
|
|
public class Plugin : BaseUnityPlugin
|
|
|
|
{
|
2023-07-31 21:55:40 +03:00
|
|
|
internal static ConfigEntry<bool> ColorizeItemBackgrounds;
|
|
|
|
|
2023-07-08 23:42:42 +03:00
|
|
|
private void Awake()
|
|
|
|
{
|
2023-07-31 21:55:40 +03:00
|
|
|
ColorizeItemBackgrounds = Config.Bind("General", "Colorize Icon Backgrounds", true);
|
2023-07-08 23:42:42 +03:00
|
|
|
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<ItemAttributeClass> __result, AmmoTemplate __instance)
|
|
|
|
{
|
|
|
|
if (__instance.GetCachedQualities() != null)
|
|
|
|
{
|
|
|
|
__result = null;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[PatchPostfix]
|
|
|
|
private static void PatchPostfix(ref List<ItemAttributeClass> __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)
|
|
|
|
{
|
2023-07-31 21:55:40 +03:00
|
|
|
if (Plugin.ColorizeItemBackgrounds.Value)
|
|
|
|
{
|
|
|
|
__instance.OverrideColor(__instance.Item);
|
|
|
|
}
|
2023-07-08 23:42:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-07-31 21:55:40 +03:00
|
|
|
if (Plugin.ColorizeItemBackgrounds.Value)
|
|
|
|
{
|
|
|
|
__instance.OverrideColor(item);
|
|
|
|
}
|
2023-07-08 23:42:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|