"Fix" rotation speed maybe

This commit is contained in:
2025-02-23 16:02:33 +01:00
parent b5d75ccffd
commit 8c58bf504c
3 changed files with 23 additions and 22 deletions

View File

@@ -130,6 +130,7 @@ namespace TerraTech {
allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false); allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false);
shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
weaponRotationSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch(); energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch();
magnetStrenghtMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch(); magnetStrenghtMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
magnetRadiusMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch(); magnetRadiusMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();

View File

@@ -21,15 +21,5 @@ namespace TerraTech {
static void HeartbeatMulti(ref float interval) { static void HeartbeatMulti(ref float interval) {
interval *= Main.heartbeatIntervalMultiplier.Value; 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);
}
} }
} }

View File

@@ -6,11 +6,11 @@ using HarmonyLib;
namespace TerraTech { namespace TerraTech {
[HarmonyPatch] [HarmonyPatch]
public class WeaponPropertiesManager { public class WeaponPropertiesManager {
private static Dictionary<ModuleWeaponGun, float> shotCooldown = new Dictionary<ModuleWeaponGun, float>(); private static Dictionary<ModuleWeapon, float> shotCooldown = new Dictionary<ModuleWeapon, float>();
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ModuleWeaponGun), "OnAttached")] [HarmonyPatch(typeof(ModuleWeapon), "OnAttached")]
static void PostfixCreate(ModuleWeaponGun __instance) { static void PostfixCreate(ModuleWeapon __instance) {
// Console.WriteLine("ModuleWeaponGun.OnAttached"); // Console.WriteLine("ModuleWeaponGun.OnAttached");
if (!shotCooldown.ContainsKey(__instance)) { if (!shotCooldown.ContainsKey(__instance)) {
shotCooldown.Add(__instance, __instance.m_ShotCooldown); shotCooldown.Add(__instance, __instance.m_ShotCooldown);
@@ -23,8 +23,8 @@ namespace TerraTech {
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ModuleWeaponGun), "OnDetaching")] [HarmonyPatch(typeof(ModuleWeapon), "OnDetaching")]
static void PostfixDestroy(ModuleWeaponGun __instance) { static void PostfixDestroy(ModuleWeapon __instance) {
// Console.WriteLine("ModuleWeaponGun.OnDetaching"); // Console.WriteLine("ModuleWeaponGun.OnDetaching");
// Console.WriteLine("Restoring {0}; m_ShotCooldown: {1}", __instance.name, // Console.WriteLine("Restoring {0}; m_ShotCooldown: {1}", __instance.name,
// __instance.m_ShotCooldown); // __instance.m_ShotCooldown);
@@ -36,20 +36,30 @@ namespace TerraTech {
public static void DoPatch() { public static void DoPatch() {
// Console.WriteLine("Modifying {0} ModuleWeaponGun", shotCooldown.Count); // Console.WriteLine("Modifying {0} ModuleWeaponGun", shotCooldown.Count);
foreach (KeyValuePair<ModuleWeaponGun, float> keyValuePair in shotCooldown) { foreach (KeyValuePair<ModuleWeapon, float> keyValuePair in shotCooldown) {
DoRestoreSingle(keyValuePair.Key); DoRestoreSingle(keyValuePair.Key);
DoPatchSingle(keyValuePair.Key); DoPatchSingle(keyValuePair.Key);
} }
} }
static void DoPatchSingle(ModuleWeaponGun moduleWeaponGun) { static void DoPatchSingle(ModuleWeapon moduleWeapon) {
moduleWeaponGun.m_ShotCooldown = shotCooldown[moduleWeaponGun] / Main.shootingSpeedMultiplier.Value; 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) { static void DoRestoreSingle(ModuleWeapon moduleWeapon) {
if (shotCooldown.ContainsKey(moduleWeaponGun)) { if (Main.debug.Value)
moduleWeaponGun.m_ShotCooldown = shotCooldown[moduleWeaponGun]; 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);
} }
} }
} }
} }