Fix weapon fire speed patch

This commit is contained in:
David Majdandžić
2023-04-10 17:18:07 +02:00
parent d973d67b0d
commit d8dbbd2068
5 changed files with 37 additions and 26 deletions

View File

@@ -46,16 +46,15 @@ namespace TerraTech {
} }
} }
[HarmonyPatch(typeof(ManLicenses), "AddXP")] [HarmonyPatch]
public class XPMultiplierPatch { public class Patches {
static void Prefix(FactionSubTypes corporation, ref int xp, bool showUI = true) { [HarmonyPatch(typeof(ManLicenses), "AddXP")]
static void XPMulti(FactionSubTypes corporation, ref int xp, bool showUI = true) {
xp *= Main.xpMultiplier.Value; xp *= Main.xpMultiplier.Value;
} }
}
[HarmonyPatch(typeof(ManPlayer), "AddMoney")] [HarmonyPatch(typeof(ManPlayer), "AddMoney")]
public class MoneyMultiplierPatch { static void MoneyMulti(ref int amount) {
static void Prefix(ref int amount) {
amount *= Main.moneyMultiplier.Value; amount *= Main.moneyMultiplier.Value;
} }
} }
@@ -86,38 +85,47 @@ namespace TerraTech {
[HarmonyPatch] [HarmonyPatch]
public class WeaponPropertiesManager { public class WeaponPropertiesManager {
private static Dictionary<ModuleWeaponGun, float> cooldowns = new Dictionary<ModuleWeaponGun, float>(); private static Dictionary<ModuleWeaponGun, float> weapons = new Dictionary<ModuleWeaponGun, float>();
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(ModuleWeaponGun), "OnPool")] [HarmonyPatch(typeof(ModuleWeaponGun), "OnPool")]
static void Postfix1WeaponCreate(ModuleWeaponGun __instance) { static void Postfix1WeaponCreate(ModuleWeaponGun __instance) {
cooldowns.Add(__instance, __instance.m_ShotCooldown); AddIfMissing(__instance);
if (ShouldPatch()) { }
DoPatchSingle(__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] [HarmonyPostfix]
[HarmonyPatch(typeof(ModuleWeaponGun), "OnRecycle")] [HarmonyPatch(typeof(ModuleWeaponGun), "OnRecycle")]
static void Postfix1WeaponDestroy(ModuleWeaponGun __instance) { static void Postfix1WeaponDestroy(ModuleWeaponGun __instance) {
cooldowns.Remove(__instance); weapons.Remove(__instance);
} }
[HarmonyPrefix] // [HarmonyPrefix]
[HarmonyPatch(typeof(ModuleWeaponGun), "ProcessFiring")] // [HarmonyPatch(typeof(ModuleWeaponGun), "ProcessFiring")]
static void PrefixProcessFiring(ModuleWeaponGun __instance, ref bool firing) { // static void PrefixProcessFiring(ModuleWeaponGun __instance, ref bool firing) {
if (firing) { // if (firing) {
if (!cooldowns.ContainsKey(__instance)) { // Console.WriteLine("" + cooldowns.ContainsKey(__instance) + " " + __instance.m_ShotCooldown);
cooldowns.Add(__instance, __instance.m_ShotCooldown); // }
DoPatchSingle(__instance); // }
}
}
}
public static void DoPatch() { public static void DoPatch() {
Console.WriteLine("Modifying " + cooldowns.Count + " weapons"); Console.WriteLine("Modifying " + weapons.Count + " weapons");
Console.WriteLine("Should patch: " + ShouldPatch()); Console.WriteLine("Should patch: " + ShouldPatch());
foreach (KeyValuePair<ModuleWeaponGun, float> keyValuePair in cooldowns) { foreach (KeyValuePair<ModuleWeaponGun, float> keyValuePair in weapons) {
if (ShouldPatch()) { if (ShouldPatch()) {
DoPatchSingle(keyValuePair.Key); DoPatchSingle(keyValuePair.Key);
} else { } else {
@@ -127,12 +135,15 @@ namespace TerraTech {
} }
static void DoPatchSingle(ModuleWeaponGun weapon) { static void DoPatchSingle(ModuleWeaponGun weapon) {
// Console.WriteLine("Patching " + weapon.name);
// Console.WriteLine("Old value " + weapon.m_ShotCooldown);
weapon.m_ShotCooldown /= Main.shootingSpeedMultiplier.Value; weapon.m_ShotCooldown /= Main.shootingSpeedMultiplier.Value;
// Console.WriteLine("New value " + weapon.m_ShotCooldown);
} }
static void DoRestoreSingle(ModuleWeaponGun weapon) { static void DoRestoreSingle(ModuleWeaponGun weapon) {
if (cooldowns.ContainsKey(weapon)) { if (weapons.ContainsKey(weapon)) {
weapon.m_ShotCooldown = cooldowns[weapon]; weapon.m_ShotCooldown = weapons[weapon];
} }
} }