diff --git a/Projects/TerraTech/TerraTech/Class1.cs b/Projects/TerraTech/TerraTech/Class1.cs index 0e8d82c..761ee46 100644 --- a/Projects/TerraTech/TerraTech/Class1.cs +++ b/Projects/TerraTech/TerraTech/Class1.cs @@ -39,6 +39,9 @@ namespace TerraTech { public static ConfigEntry wirelessChargingRadiusMultiplier; public static ConfigEntry wirelessChargingPowerPerArcMultiplier; public static ConfigEntry wirelessChargingArcFiringIntervalMultiplier; + public static ConfigEntry shieldRadiusMultiplier; + public static ConfigEntry shieldHeartbeatIntervalMultiplier; + public static ConfigEntry powerUpDelayMultiplier; public static ConfigEntry weaponRotationSpeedMultiplier; public static ConfigEntry shopBlocksGeneratedTotalMultiplier; public static ConfigEntry shopPerBlockStopMultiplier; @@ -138,6 +141,17 @@ namespace TerraTech { "Shop", "Shop Per Block Stop Multiplier", 1f, new ConfigDescription("Shop Per Block Stop Multiplier", new AcceptableValueRange(1f, 32f))); + shieldRadiusMultiplier = Config.Bind( + "Shield", "Shield Radius Multiplier", 1f, + new ConfigDescription("Shield Radius Multiplier", new AcceptableValueRange(0.001f, 32f))); + shieldHeartbeatIntervalMultiplier = + Config.Bind("Shield", "Shield Heartbeat Interval Multiplier", 1f, + new ConfigDescription("Shield Heartbeat Interval Multiplier", + new AcceptableValueRange(0.001f, 32f))); + powerUpDelayMultiplier = Config.Bind( + "PowerUp", "Power Up Delay Multiplier", 1f, + new ConfigDescription("Power Up Delay Multiplier", new AcceptableValueRange(0.001f, 32f))); + shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch(); diff --git a/Projects/TerraTech/TerraTech/ModuleEnergy.cs b/Projects/TerraTech/TerraTech/ModuleEnergy.cs new file mode 100644 index 0000000..d3d846e --- /dev/null +++ b/Projects/TerraTech/TerraTech/ModuleEnergy.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using HarmonyLib; + +namespace TerraTech { + [HarmonyPatch] + public class ModuleEnergy { + private static Dictionary powerUpDelay = + new Dictionary(); + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergy), "OnAttached")] + static void PostfixCreate(ModuleEnergy __instance) { + var trav = Traverse.Create(__instance); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + if (Main.debug.Value) + Console.WriteLine("ModuleEnergy.OnAttached"); + + if (!powerUpDelay.ContainsKey(__instance)) { + powerUpDelay.Add(__instance, (float)powerUpDelayField.GetValue()); + if (Main.debug.Value) + Console.WriteLine("Patching {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + } + + DoPatchSingle(__instance); + + if (Main.debug.Value) + Console.WriteLine("Patched {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergy), "OnDetaching")] + static void PostfixDestroy(ModuleEnergy __instance) { + var trav = Traverse.Create(__instance); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + if (Main.debug.Value) + Console.WriteLine("ModuleEnergy.OnDetaching"); + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + + DoRestoreSingle(__instance); + + if (Main.debug.Value) + Console.WriteLine("Restored {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + + powerUpDelay.Remove(__instance); + } + + public static void DoPatch() { + if (Main.debug.Value) + Console.WriteLine("Modifying {0} ModuleEnergy", powerUpDelay.Count); + foreach (KeyValuePair keyValuePair in powerUpDelay) { + DoRestoreSingle(keyValuePair.Key); + DoPatchSingle(keyValuePair.Key); + } + } + + static void DoPatchSingle(ModuleEnergy moduleEnergy) { + var trav = Traverse.Create(moduleEnergy); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + powerUpDelayField.SetValue(powerUpDelay[moduleEnergy] * Main.powerUpDelayMultiplier.Value); + } + + static void DoRestoreSingle(ModuleEnergy moduleEnergy) { + var trav = Traverse.Create(moduleEnergy); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + if (powerUpDelay.ContainsKey(moduleEnergy)) + powerUpDelayField.SetValue(powerUpDelay[moduleEnergy]); + } + } +} diff --git a/Projects/TerraTech/TerraTech/ModuleShieldGeneratorManager.cs b/Projects/TerraTech/TerraTech/ModuleShieldGeneratorManager.cs new file mode 100644 index 0000000..090dd97 --- /dev/null +++ b/Projects/TerraTech/TerraTech/ModuleShieldGeneratorManager.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using HarmonyLib; + +namespace TerraTech { + [HarmonyPatch] + public class ModuleShieldGeneratorManager { + private static Dictionary healingHeartbeatInterval = + new Dictionary(); + private static Dictionary radius = new Dictionary(); + private static Dictionary powerUpDelay = + new Dictionary(); + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleShieldGenerator), "OnAttached")] + static void PostfixCreate(ModuleShieldGenerator __instance) { + var trav = Traverse.Create(__instance); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + if (Main.debug.Value) + Console.WriteLine("ModuleShieldGenerator.OnAttached"); + if (!healingHeartbeatInterval.ContainsKey(__instance)) { + healingHeartbeatInterval.Add(__instance, __instance.m_HealingHeartbeatInterval); + if (Main.debug.Value) + Console.WriteLine("Patching {0}; m_HealingHeartbeatInterval: {1}", __instance.ToString(), + __instance.m_HealingHeartbeatInterval); + } + if (!radius.ContainsKey(__instance)) { + radius.Add(__instance, __instance.m_Radius); + if (Main.debug.Value) + Console.WriteLine("Patching {0}; m_Radius: {1}", __instance.ToString(), __instance.m_Radius); + } + if (!powerUpDelay.ContainsKey(__instance)) { + powerUpDelay.Add(__instance, (float)powerUpDelayField.GetValue()); + if (Main.debug.Value) + Console.WriteLine("Patching {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + } + + DoPatchSingle(__instance); + + if (Main.debug.Value) + Console.WriteLine("Patched {0}; m_HealingHeartbeatInterval: {1}", __instance.ToString(), + __instance.m_HealingHeartbeatInterval); + if (Main.debug.Value) + Console.WriteLine("Patched {0}; m_Radius: {1}", __instance.ToString(), __instance.m_Radius); + if (Main.debug.Value) + Console.WriteLine("Patched {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleShieldGenerator), "OnDetaching")] + static void PostfixDestroy(ModuleShieldGenerator __instance) { + var trav = Traverse.Create(__instance); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + if (Main.debug.Value) + Console.WriteLine("ModuleShieldGenerator.OnDetaching"); + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; m_HealingHeartbeatInterval: {1}", __instance.ToString(), + __instance.m_HealingHeartbeatInterval); + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; m_Radius: {1}", __instance.ToString(), __instance.m_Radius); + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + + DoRestoreSingle(__instance); + + if (Main.debug.Value) + Console.WriteLine("Restored {0}; m_HealingHeartbeatInterval: {1}", __instance.ToString(), + __instance.m_HealingHeartbeatInterval); + if (Main.debug.Value) + Console.WriteLine("Restored {0}; m_Radius: {1}", __instance.ToString(), __instance.m_Radius); + if (Main.debug.Value) + Console.WriteLine("Restored {0}; m_PowerUpDelay: {1}", __instance.ToString(), + (float)powerUpDelayField.GetValue()); + + healingHeartbeatInterval.Remove(__instance); + radius.Remove(__instance); + powerUpDelay.Remove(__instance); + } + + public static void DoPatch() { + if (Main.debug.Value) + Console.WriteLine("Modifying {0} ModuleShieldGenerator", healingHeartbeatInterval.Count); + foreach (KeyValuePair keyValuePair in healingHeartbeatInterval) { + DoRestoreSingle(keyValuePair.Key); + DoPatchSingle(keyValuePair.Key); + } + } + + static void DoPatchSingle(ModuleShieldGenerator moduleShieldGenerator) { + var trav = Traverse.Create(moduleShieldGenerator); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + moduleShieldGenerator.m_HealingHeartbeatInterval = + healingHeartbeatInterval[moduleShieldGenerator] * Main.shieldHeartbeatIntervalMultiplier.Value; + moduleShieldGenerator.m_Radius = radius[moduleShieldGenerator] * Main.shieldRadiusMultiplier.Value; + powerUpDelayField.SetValue(powerUpDelay[moduleShieldGenerator] * Main.powerUpDelayMultiplier.Value); + } + + static void DoRestoreSingle(ModuleShieldGenerator moduleShieldGenerator) { + var trav = Traverse.Create(moduleShieldGenerator); + var powerUpDelayField = trav.Field("m_PowerUpDelay"); + + if (healingHeartbeatInterval.ContainsKey(moduleShieldGenerator)) + moduleShieldGenerator.m_HealingHeartbeatInterval = healingHeartbeatInterval[moduleShieldGenerator]; + if (radius.ContainsKey(moduleShieldGenerator)) + moduleShieldGenerator.m_Radius = radius[moduleShieldGenerator]; + if (powerUpDelay.ContainsKey(moduleShieldGenerator)) + powerUpDelayField.SetValue(powerUpDelay[moduleShieldGenerator]); + } + } +} diff --git a/Projects/TerraTech/TerraTech/TerraTech.csproj b/Projects/TerraTech/TerraTech/TerraTech.csproj index 96a450d..8331aaf 100644 --- a/Projects/TerraTech/TerraTech/TerraTech.csproj +++ b/Projects/TerraTech/TerraTech/TerraTech.csproj @@ -45,6 +45,8 @@ + +