From 8c58bf504cae888b66aefa055490165904477d76 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 23 Feb 2025 16:02:33 +0100 Subject: [PATCH] "Fix" rotation speed maybe --- Projects/TerraTech/TerraTech/Class1.cs | 1 + Projects/TerraTech/TerraTech/Patches.cs | 10 ------ .../TerraTech/WeaponPropertiesManager.cs | 34 ++++++++++++------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Projects/TerraTech/TerraTech/Class1.cs b/Projects/TerraTech/TerraTech/Class1.cs index c98dcc2..bda3470 100644 --- a/Projects/TerraTech/TerraTech/Class1.cs +++ b/Projects/TerraTech/TerraTech/Class1.cs @@ -130,6 +130,7 @@ namespace TerraTech { allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false); shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); + weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch(); magnetStrenghtMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch(); magnetRadiusMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch(); diff --git a/Projects/TerraTech/TerraTech/Patches.cs b/Projects/TerraTech/TerraTech/Patches.cs index 0241eb0..d4a9482 100644 --- a/Projects/TerraTech/TerraTech/Patches.cs +++ b/Projects/TerraTech/TerraTech/Patches.cs @@ -21,15 +21,5 @@ namespace TerraTech { static void HeartbeatMulti(ref float interval) { interval *= Main.heartbeatIntervalMultiplier.Value; } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ModuleWeaponGun), "RotateSpeed", MethodType.Getter)] - static void WeaponRotationSpeedMulti(ref float __result) { - if (Main.debug.Value) - Console.WriteLine("WeaponRotationSpeedMulti: {0}", __result); - __result *= Main.weaponRotationSpeedMultiplier.Value; - if (Main.debug.Value) - Console.WriteLine("WeaponRotationSpeedMulti: {0}", __result); - } } } diff --git a/Projects/TerraTech/TerraTech/WeaponPropertiesManager.cs b/Projects/TerraTech/TerraTech/WeaponPropertiesManager.cs index 6806bfa..9363d48 100644 --- a/Projects/TerraTech/TerraTech/WeaponPropertiesManager.cs +++ b/Projects/TerraTech/TerraTech/WeaponPropertiesManager.cs @@ -6,11 +6,11 @@ using HarmonyLib; namespace TerraTech { [HarmonyPatch] public class WeaponPropertiesManager { - private static Dictionary shotCooldown = new Dictionary(); + private static Dictionary shotCooldown = new Dictionary(); [HarmonyPrefix] - [HarmonyPatch(typeof(ModuleWeaponGun), "OnAttached")] - static void PostfixCreate(ModuleWeaponGun __instance) { + [HarmonyPatch(typeof(ModuleWeapon), "OnAttached")] + static void PostfixCreate(ModuleWeapon __instance) { // Console.WriteLine("ModuleWeaponGun.OnAttached"); if (!shotCooldown.ContainsKey(__instance)) { shotCooldown.Add(__instance, __instance.m_ShotCooldown); @@ -23,8 +23,8 @@ namespace TerraTech { } [HarmonyPrefix] - [HarmonyPatch(typeof(ModuleWeaponGun), "OnDetaching")] - static void PostfixDestroy(ModuleWeaponGun __instance) { + [HarmonyPatch(typeof(ModuleWeapon), "OnDetaching")] + static void PostfixDestroy(ModuleWeapon __instance) { // Console.WriteLine("ModuleWeaponGun.OnDetaching"); // Console.WriteLine("Restoring {0}; m_ShotCooldown: {1}", __instance.name, // __instance.m_ShotCooldown); @@ -36,20 +36,30 @@ namespace TerraTech { public static void DoPatch() { // Console.WriteLine("Modifying {0} ModuleWeaponGun", shotCooldown.Count); - foreach (KeyValuePair keyValuePair in shotCooldown) { + foreach (KeyValuePair keyValuePair in shotCooldown) { DoRestoreSingle(keyValuePair.Key); DoPatchSingle(keyValuePair.Key); } } - static void DoPatchSingle(ModuleWeaponGun moduleWeaponGun) { - moduleWeaponGun.m_ShotCooldown = shotCooldown[moduleWeaponGun] / Main.shootingSpeedMultiplier.Value; + static void DoPatchSingle(ModuleWeapon moduleWeapon) { + if (Main.debug.Value) + Console.WriteLine("Patching {0}; m_ShotCooldown: {1}", moduleWeapon.name, moduleWeapon.m_ShotCooldown); + moduleWeapon.m_ShotCooldown = shotCooldown[moduleWeapon] / Main.shootingSpeedMultiplier.Value; + moduleWeapon.m_RotateSpeed *= Main.weaponRotationSpeedMultiplier.Value; + if (Main.debug.Value) + Console.WriteLine("Patched {0}; m_ShotCooldown: {1}", moduleWeapon.name, moduleWeapon.m_ShotCooldown); } - static void DoRestoreSingle(ModuleWeaponGun moduleWeaponGun) { - if (shotCooldown.ContainsKey(moduleWeaponGun)) { - moduleWeaponGun.m_ShotCooldown = shotCooldown[moduleWeaponGun]; + static void DoRestoreSingle(ModuleWeapon moduleWeapon) { + if (Main.debug.Value) + Console.WriteLine("Restoring {0}; m_ShotCooldown: {1}", moduleWeapon.name, moduleWeapon.m_ShotCooldown); + if (shotCooldown.ContainsKey(moduleWeapon)) { + moduleWeapon.m_ShotCooldown = shotCooldown[moduleWeapon]; + if (Main.debug.Value) + Console.WriteLine("Restored {0}; m_ShotCooldown: {1}", moduleWeapon.name, + moduleWeapon.m_ShotCooldown); } } } -} \ No newline at end of file +}