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]
public class Patches {
[HarmonyPatch(typeof(ManLicenses), "AddXP")]
public class XPMultiplierPatch {
static void Prefix(FactionSubTypes corporation, ref int xp, bool showUI = true) {
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) {
static void MoneyMulti(ref int amount) {
amount *= Main.moneyMultiplier.Value;
}
}
@@ -86,38 +85,47 @@ namespace TerraTech {
[HarmonyPatch]
public class WeaponPropertiesManager {
private static Dictionary<ModuleWeaponGun, float> cooldowns = new Dictionary<ModuleWeaponGun, float>();
private static Dictionary<ModuleWeaponGun, float> weapons = new Dictionary<ModuleWeaponGun, float>();
[HarmonyPostfix]
[HarmonyPatch(typeof(ModuleWeaponGun), "OnPool")]
static void Postfix1WeaponCreate(ModuleWeaponGun __instance) {
cooldowns.Add(__instance, __instance.m_ShotCooldown);
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(__instance);
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<ModuleWeaponGun, float> keyValuePair in cooldowns) {
foreach (KeyValuePair<ModuleWeaponGun, float> 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];
}
}