diff --git a/Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs b/Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs new file mode 100644 index 0000000..c0c2251 --- /dev/null +++ b/Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs @@ -0,0 +1,43 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace TerraTech { + [HarmonyPatch] + public class ModuleEnergyStoreManager { + private static readonly MultipliedObjectManager manager = + new MultipliedObjectManager(ConfigureModuleEnergyStore); + + public static ConfigEntry capacityMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + 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)); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")] + static void PostfixCreate(ModuleEnergyStore __instance) { + manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")] + static void PostfixDestroy(ModuleEnergyStore __instance) { + manager.OnObjectDetached(__instance); + } + + public static void DoPatch() { + manager.ApplyAll(); + } + } +} diff --git a/Projects/TerraTech/TerraTech/TerraTech.csproj b/Projects/TerraTech/TerraTech/TerraTech.csproj index 53c7a4b..1f54740 100644 --- a/Projects/TerraTech/TerraTech/TerraTech.csproj +++ b/Projects/TerraTech/TerraTech/TerraTech.csproj @@ -47,6 +47,7 @@ +