using System; using BepInEx.Configuration; using HarmonyLib; namespace BanquetForCyka { [HarmonyPatch] public class ModuleEnergyStoreManager { private static readonly MultipliedObjectManager Manager = new MultipliedObjectManager(ConfigureModuleEnergyStore); private static ConfigEntry playerOnly; private static ConfigEntry capacityMultiplier; public static void Setup(ConfigFile config) { float min = 0.01f; float max = 32f; playerOnly = config.Bind("Energy", "Player Only", false, new ConfigDescription("Player Only")); playerOnly.SettingChanged += (sender, args) => DoPatch(); capacityMultiplier = config.Bind("Energy", "Capacity Multiplier", 1f, new ConfigDescription("Capacity Multiplier", new AcceptableValueRange(min, max))); capacityMultiplier.SettingChanged += (sender, args) => DoPatch(); } private static void ConfigureModuleEnergyStore(MultipliedObject obj) { obj.AddField(new FieldConfiguration("m_Capacity", capacityMultiplier, ShouldApply)); } private static readonly Func ShouldApply = obj => { if (!playerOnly.Value) return true; return CykUtil.IsPlayerTank(obj as Module); }; [HarmonyPrefix] [HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")] public static void PostfixCreate(ModuleEnergyStore __instance) { Manager.OnObjectAttached(__instance); } [HarmonyPrefix] [HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")] public static void PostfixDestroy(ModuleEnergyStore __instance) { Manager.OnObjectDetached(__instance); } private static void DoPatch() { Manager.ApplyAll(); } public static readonly Func Register = obj => { if (Main.debug.Value) Console.WriteLine("Registering ModuleEnergyStore: {0}", obj); PostfixCreate(obj as ModuleEnergyStore); return true; }; } }