diff --git a/Projects/TerraTech/TerraTech/Class1.cs b/Projects/TerraTech/TerraTech/Class1.cs index 4578fc3..058573a 100644 --- a/Projects/TerraTech/TerraTech/Class1.cs +++ b/Projects/TerraTech/TerraTech/Class1.cs @@ -46,16 +46,15 @@ namespace TerraTech { } } - [HarmonyPatch(typeof(ManLicenses), "AddXP")] - public class XPMultiplierPatch { - static void Prefix(FactionSubTypes corporation, ref int xp, bool showUI = true) { + [HarmonyPatch] + public class Patches { + [HarmonyPatch(typeof(ManLicenses), "AddXP")] + static void XPMulti(FactionSubTypes corporation, ref int xp, bool showUI = true) { xp *= Main.xpMultiplier.Value; } - } - [HarmonyPatch(typeof(ManPlayer), "AddMoney")] - public class MoneyMultiplierPatch { - static void Prefix(ref int amount) { + [HarmonyPatch(typeof(ManPlayer), "AddMoney")] + static void MoneyMulti(ref int amount) { amount *= Main.moneyMultiplier.Value; } } @@ -86,38 +85,47 @@ namespace TerraTech { [HarmonyPatch] public class WeaponPropertiesManager { - private static Dictionary cooldowns = new Dictionary(); + private static Dictionary weapons = new Dictionary(); [HarmonyPostfix] [HarmonyPatch(typeof(ModuleWeaponGun), "OnPool")] static void Postfix1WeaponCreate(ModuleWeaponGun __instance) { - cooldowns.Add(__instance, __instance.m_ShotCooldown); - if (ShouldPatch()) { - DoPatchSingle(__instance); + AddIfMissing(__instance); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ModuleWeaponGun), "OnSpawn")] + static void Postfix2WeaponCreate(ModuleWeaponGun __instance) { + AddIfMissing(__instance); + } + + private static void AddIfMissing(ModuleWeaponGun weaponGun) { + if (!weapons.ContainsKey(weaponGun)) { + weapons.Add(weaponGun, weaponGun.m_ShotCooldown); + if (ShouldPatch()) { + DoPatchSingle(weaponGun); + } } } [HarmonyPostfix] [HarmonyPatch(typeof(ModuleWeaponGun), "OnRecycle")] static void Postfix1WeaponDestroy(ModuleWeaponGun __instance) { - cooldowns.Remove(__instance); + weapons.Remove(__instance); } - [HarmonyPrefix] - [HarmonyPatch(typeof(ModuleWeaponGun), "ProcessFiring")] - static void PrefixProcessFiring(ModuleWeaponGun __instance, ref bool firing) { - if (firing) { - if (!cooldowns.ContainsKey(__instance)) { - cooldowns.Add(__instance, __instance.m_ShotCooldown); - DoPatchSingle(__instance); - } - } - } + // [HarmonyPrefix] + // [HarmonyPatch(typeof(ModuleWeaponGun), "ProcessFiring")] + // static void PrefixProcessFiring(ModuleWeaponGun __instance, ref bool firing) { + // if (firing) { + // Console.WriteLine("" + cooldowns.ContainsKey(__instance) + " " + __instance.m_ShotCooldown); + // } + // } public static void DoPatch() { - Console.WriteLine("Modifying " + cooldowns.Count + " weapons"); + Console.WriteLine("Modifying " + weapons.Count + " weapons"); Console.WriteLine("Should patch: " + ShouldPatch()); - foreach (KeyValuePair keyValuePair in cooldowns) { + foreach (KeyValuePair keyValuePair in weapons) { if (ShouldPatch()) { DoPatchSingle(keyValuePair.Key); } else { @@ -127,12 +135,15 @@ namespace TerraTech { } static void DoPatchSingle(ModuleWeaponGun weapon) { + // Console.WriteLine("Patching " + weapon.name); + // Console.WriteLine("Old value " + weapon.m_ShotCooldown); weapon.m_ShotCooldown /= Main.shootingSpeedMultiplier.Value; + // Console.WriteLine("New value " + weapon.m_ShotCooldown); } static void DoRestoreSingle(ModuleWeaponGun weapon) { - if (cooldowns.ContainsKey(weapon)) { - weapon.m_ShotCooldown = cooldowns[weapon]; + if (weapons.ContainsKey(weapon)) { + weapon.m_ShotCooldown = weapons[weapon]; } } diff --git a/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.dll b/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.dll index 9be9c4f..3575c87 100644 Binary files a/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.dll and b/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.dll differ diff --git a/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.pdb b/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.pdb index f82d826..a5d811e 100644 Binary files a/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.pdb and b/Projects/TerraTech/TerraTech/bin/Debug/TerraTech.pdb differ diff --git a/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.dll b/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.dll index 9be9c4f..3575c87 100644 Binary files a/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.dll and b/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.dll differ diff --git a/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.pdb b/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.pdb index f82d826..a5d811e 100644 Binary files a/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.pdb and b/Projects/TerraTech/TerraTech/obj/Debug/TerraTech.pdb differ