diff --git a/Projects/TerraTech/TerraTech/Class1.cs b/Projects/TerraTech/TerraTech/Class1.cs index 761ee46..69299af 100644 --- a/Projects/TerraTech/TerraTech/Class1.cs +++ b/Projects/TerraTech/TerraTech/Class1.cs @@ -42,6 +42,7 @@ namespace TerraTech { public static ConfigEntry shieldRadiusMultiplier; public static ConfigEntry shieldHeartbeatIntervalMultiplier; public static ConfigEntry powerUpDelayMultiplier; + public static ConfigEntry batteryCapacityMultiplier; public static ConfigEntry weaponRotationSpeedMultiplier; public static ConfigEntry shopBlocksGeneratedTotalMultiplier; public static ConfigEntry shopPerBlockStopMultiplier; @@ -151,6 +152,9 @@ namespace TerraTech { powerUpDelayMultiplier = Config.Bind( "PowerUp", "Power Up Delay Multiplier", 1f, new ConfigDescription("Power Up Delay Multiplier", new AcceptableValueRange(0.001f, 32f))); + batteryCapacityMultiplier = Config.Bind( + "PowerUp", "Battery Capacity Multiplier", 1f, + new ConfigDescription("Battery Capacity Multiplier", new AcceptableValueRange(0.001f, 32f))); shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); diff --git a/Projects/TerraTech/TerraTech/ModuleEnergy.cs b/Projects/TerraTech/TerraTech/ModuleEnergy.cs index d3d846e..4abe749 100644 --- a/Projects/TerraTech/TerraTech/ModuleEnergy.cs +++ b/Projects/TerraTech/TerraTech/ModuleEnergy.cs @@ -5,8 +5,7 @@ using HarmonyLib; namespace TerraTech { [HarmonyPatch] public class ModuleEnergy { - private static Dictionary powerUpDelay = - new Dictionary(); + private static Dictionary powerUpDelay = new Dictionary(); [HarmonyPrefix] [HarmonyPatch(typeof(ModuleEnergy), "OnAttached")] diff --git a/Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs b/Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs new file mode 100644 index 0000000..ae08618 --- /dev/null +++ b/Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs @@ -0,0 +1,65 @@ +using HarmonyLib; + +namespace TerraTech { + [HarmonyPatch] + public class ModuleEnergyStoreManager { + private static Dictionary batteryCapacity = + new Dictionary(); + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")] + static void PostfixCreate(ModuleEnergyStore __instance) { + if (Main.debug.Value) + Console.WriteLine("ModuleEnergyStore.OnAttached"); + if (!batteryCapacity.ContainsKey(__instance)) { + batteryCapacity.Add(__instance, __instance.m_BatteryCapacity); + if (Main.debug.Value) + Console.WriteLine("Patching {0}; m_BatteryCapacity: {1}", __instance.ToString(), + __instance.m_BatteryCapacity); + } + + DoPatchSingle(__instance); + + if (Main.debug.Value) + Console.WriteLine("Patched {0}; m_BatteryCapacity: {1}", __instance.ToString(), + __instance.m_BatteryCapacity); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")] + static void PostfixDestroy(ModuleEnergyStore __instance) { + if (Main.debug.Value) + Console.WriteLine("ModuleEnergyStore.OnDetaching"); + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; m_BatteryCapacity: {1}", __instance.ToString(), + __instance.m_BatteryCapacity); + + DoRestoreSingle(__instance); + + if (Main.debug.Value) + Console.WriteLine("Restored {0}; m_BatteryCapacity: {1}", __instance.ToString(), + __instance.m_BatteryCapacity); + + batteryCapacity.Remove(__instance); + } + + public static void DoPatch() { + if (Main.debug.Value) + Console.WriteLine("Modifying {0} ModuleEnergyStore", batteryCapacity.Count); + foreach (KeyValuePair keyValuePair in batteryCapacity) { + DoRestoreSingle(keyValuePair.Key); + DoPatchSingle(keyValuePair.Key); + } + } + + static void DoPatchSingle(ModuleEnergyStore moduleEnergyStore) { + moduleEnergyStore.m_BatteryCapacity = + batteryCapacity[moduleEnergyStore] * Main.batteryCapacityMultiplier.Value; + } + + static void DoRestoreSingle(ModuleEnergyStore moduleEnergyStore) { + if (batteryCapacity.ContainsKey(moduleEnergyStore)) + moduleEnergyStore.m_BatteryCapacity = batteryCapacity[moduleEnergyStore]; + } + } +} diff --git a/Projects/TerraTech/TerraTech/TerraTech.csproj b/Projects/TerraTech/TerraTech/TerraTech.csproj index 8331aaf..a6db341 100644 --- a/Projects/TerraTech/TerraTech/TerraTech.csproj +++ b/Projects/TerraTech/TerraTech/TerraTech.csproj @@ -46,6 +46,7 @@ +