diff --git a/Projects/TerraTech/TerraTech/Class1.cs b/Projects/TerraTech/TerraTech/Class1.cs index a0798f0..c9e938b 100644 --- a/Projects/TerraTech/TerraTech/Class1.cs +++ b/Projects/TerraTech/TerraTech/Class1.cs @@ -68,7 +68,7 @@ namespace TerraTech { ModuleBoosterManager.Setup(Config); ModuleShieldGeneratorManager.Setup(Config); ModuleWeaponGunManager.Setup(Config); - + ModuleEnergyManager.Setup(Config); xpMultiplier = Config.Bind("General", "XP Multiplier", 1f, new ConfigDescription("XP Multiplier", new AcceptableValueRange(min, max))); diff --git a/Projects/TerraTech/TerraTech/ModuleEnergyManager.cs b/Projects/TerraTech/TerraTech/ModuleEnergyManager.cs new file mode 100644 index 0000000..5e6499f --- /dev/null +++ b/Projects/TerraTech/TerraTech/ModuleEnergyManager.cs @@ -0,0 +1,50 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace TerraTech { + [HarmonyPatch] + public class ModuleEnergyManager { + private static readonly MultipliedObjectManager manager = + new MultipliedObjectManager(ConfigureModuleEnergy); + + public static ConfigEntry outputMultiplier; + public static ConfigEntry powerUpDelayMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + outputMultiplier = + config.Bind("Energy", "Output Multiplier", 1f, + new ConfigDescription("Output Multiplier", new AcceptableValueRange(min, max))); + outputMultiplier.SettingChanged += (sender, args) => DoPatch(); + + powerUpDelayMultiplier = config.Bind( + "Energy", "Power Up Delay Multiplier", 1f, + new ConfigDescription("Power Up Delay Multiplier", new AcceptableValueRange(min, max))); + powerUpDelayMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureModuleEnergy(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_OutputPerSecond", outputMultiplier)); + obj.AddField(new FieldConfiguration("m_PowerUpDelay", powerUpDelayMultiplier)); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergy), "OnAttached")] + static void PostfixCreate(ModuleEnergy __instance) { + manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergy), "OnDetaching")] + static void PostfixDestroy(ModuleEnergy __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 50a0578..53c7a4b 100644 --- a/Projects/TerraTech/TerraTech/TerraTech.csproj +++ b/Projects/TerraTech/TerraTech/TerraTech.csproj @@ -46,6 +46,7 @@ +