494 lines
23 KiB
C#
494 lines
23 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using HarmonyLib;
|
|
using HarmonyLib.Tools;
|
|
using UnityEngine;
|
|
|
|
// TODO: Make battery bigger
|
|
// TODO: Make shield and repair bigger
|
|
// TODO: Make fuel tanks bigger
|
|
|
|
namespace TerraTech {
|
|
[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
|
|
public class Main : BaseUnityPlugin {
|
|
private const string pluginGuid = "CykaMod";
|
|
private const string pluginName = "CykaMod";
|
|
private const string pluginVersion = "1.0.0";
|
|
|
|
public static ConfigEntry<float> xpMultiplier;
|
|
public static ConfigEntry<float> moneyMultiplier;
|
|
public static ConfigEntry<float> energyGenMultiplier;
|
|
public static ConfigEntry<float> heartbeatIntervalMultiplier;
|
|
public static ConfigEntry<float> shootingSpeedMultiplier;
|
|
public static ConfigEntry<float> muzzleVelocityMultiplier;
|
|
public static ConfigEntry<bool> allProjectilesHoming;
|
|
public static ConfigEntry<float> magnetStrenghtMultiplier;
|
|
public static ConfigEntry<float> magnetRadiusMultiplier;
|
|
public static ConfigEntry<float> beamStrenghtMultiplier;
|
|
public static ConfigEntry<float> beamRadiusMultiplier;
|
|
public static ConfigEntry<float> fuelTankRefillMultiplier;
|
|
public static ConfigEntry<float> minerGroundArea;
|
|
public static ConfigEntry<float> minerMiningSpeed;
|
|
|
|
public void Awake() {
|
|
xpMultiplier = Config.Bind("General", "XP Multiplier", 1f, new ConfigDescription("XP Multiplier", new AcceptableValueRange<float>(1f, 32f)));
|
|
moneyMultiplier = Config.Bind("General", "Money Multiplier", 1f,
|
|
new ConfigDescription("Money Multiplier", new AcceptableValueRange<float>(1f, 32f)));
|
|
energyGenMultiplier = Config.Bind("General", "Energy Generation Multiplier", 1f,
|
|
new ConfigDescription("Energy Generation Multiplier", new AcceptableValueRange<float>(1f, 64f)));
|
|
heartbeatIntervalMultiplier = Config.Bind("General", "Heartbeat Interval Multiplier", 1f,
|
|
new ConfigDescription("Heartbeat Interval Multiplier", new AcceptableValueRange<float>(0.1f, 2f)));
|
|
shootingSpeedMultiplier = Config.Bind("Weapons", "Shooting Speed Multiplier", 1f,
|
|
new ConfigDescription("Shooting Speed Multiplier", new AcceptableValueRange<float>(0.5f, 8f)));
|
|
muzzleVelocityMultiplier = Config.Bind("Weapons", "Muzzle Velocity Multiplier", 1f,
|
|
new ConfigDescription("Muzzle Velocity Multiplier", new AcceptableValueRange<float>(1f, 32f)));
|
|
magnetStrenghtMultiplier = Config.Bind("Attractors", "Magnet Strength Multiplier", 1f,
|
|
new ConfigDescription("Magnet Strength Multiplier", new AcceptableValueRange<float>(1f, 16f)));
|
|
magnetRadiusMultiplier = Config.Bind("Attractors", "Magnet Radius Multiplier", 1f,
|
|
new ConfigDescription("Magnet Radius Multiplier", new AcceptableValueRange<float>(1f, 16f)));
|
|
beamStrenghtMultiplier = Config.Bind("Attractors", "Beam Strength Multiplier", 1f,
|
|
new ConfigDescription("Beam Strength Multiplier", new AcceptableValueRange<float>(1f, 16f)));
|
|
beamRadiusMultiplier = Config.Bind("Attractors", "Beam Radius Multiplier", 1f,
|
|
new ConfigDescription("Beam Radius Multiplier", new AcceptableValueRange<float>(1f, 16f)));
|
|
fuelTankRefillMultiplier = Config.Bind("Propulsion", "Fuel Tank Refill Rate Multiplier", 1f,
|
|
new ConfigDescription("Fuel Tank Refill Rate Multiplier", new AcceptableValueRange<float>(1f, 32f)));
|
|
minerGroundArea = Config.Bind("Production", "Miner Ground Deposit Scan Area", 1f,
|
|
new ConfigDescription("Miner Ground Deposit Scan Area", new AcceptableValueRange<float>(1f, 32f)));
|
|
minerMiningSpeed = Config.Bind("Production", "Miner Mining Speed", 1f,
|
|
new ConfigDescription("Miner Mining Speed", new AcceptableValueRange<float>(1f, 32f)));
|
|
|
|
allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false);
|
|
|
|
shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
|
|
energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch();
|
|
magnetStrenghtMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
|
|
magnetRadiusMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
|
|
beamStrenghtMultiplier.SettingChanged += (sender, args) => BeamPropertiesManager.DoPatch();
|
|
beamRadiusMultiplier.SettingChanged += (sender, args) => BeamPropertiesManager.DoPatch();
|
|
fuelTankRefillMultiplier.SettingChanged += (sender, args) => FuelPropertiesManager.DoPatch();
|
|
minerGroundArea.SettingChanged += (sender, args) => MinerPropertiesManager.DoPatch();
|
|
minerMiningSpeed.SettingChanged += (sender, args) => MinerPropertiesManager.DoPatch();
|
|
|
|
Logger.LogInfo("Cyka mod loaded");
|
|
HarmonyFileLog.Enabled = true;
|
|
Harmony harmony = new Harmony(pluginGuid);
|
|
harmony.PatchAll();
|
|
var originalMethods = harmony.GetPatchedMethods();
|
|
Logger.LogInfo("Patched " + originalMethods.Count() + " methods");
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class Patches {
|
|
[HarmonyPrefix]
|
|
[HarmonyPatch(typeof(ManLicenses), "AddXP")]
|
|
static void XPMulti(FactionSubTypes corporation, ref int xp, bool showUI = true) {
|
|
xp = (int)(xp * Main.xpMultiplier.Value);
|
|
}
|
|
|
|
[HarmonyPrefix]
|
|
[HarmonyPatch(typeof(ManPlayer), "AddMoney")]
|
|
static void MoneyMulti(ref int amount) {
|
|
amount = (int)(amount * Main.moneyMultiplier.Value);
|
|
}
|
|
|
|
[HarmonyPrefix]
|
|
[HarmonyPatch(typeof(TechHolders), "SetHeartbeatInterval")]
|
|
static void HeartbeatMulti(ref float interval) {
|
|
interval *= Main.heartbeatIntervalMultiplier.Value;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Projectile), "Fire")]
|
|
public class HomingProjectilePatch {
|
|
private static Dictionary<FireData, bool> patchedObjects = new Dictionary<FireData, bool>();
|
|
|
|
static void Prefix(Vector3 fireDirection, ref FireData fireData, ref ModuleWeaponGun weapon, Tank shooter, ref bool seekingRounds, bool replayRounds) {
|
|
if (Main.allProjectilesHoming.Value) {
|
|
seekingRounds = true;
|
|
}
|
|
if (Main.muzzleVelocityMultiplier.Value != -1f && !patchedObjects.ContainsKey(fireData)) {
|
|
fireData.m_MuzzleVelocity *= Main.muzzleVelocityMultiplier.Value;
|
|
patchedObjects.Add(fireData, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class WeaponPropertiesManager {
|
|
private static Dictionary<ModuleWeaponGun, float> weapons = new Dictionary<ModuleWeaponGun, float>();
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleWeaponGun), "OnAttached")]
|
|
static void PostfixCreate(ModuleWeaponGun __instance) {
|
|
if (!weapons.ContainsKey(__instance)) {
|
|
weapons.Add(__instance, __instance.m_ShotCooldown);
|
|
DoPatchSingle(__instance);
|
|
}
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleWeaponGun), "OnDetaching")]
|
|
static void PostfixDestroy(ModuleWeaponGun __instance) {
|
|
DoRestoreSingle(__instance);
|
|
weapons.Remove(__instance);
|
|
}
|
|
|
|
public static void DoPatch() {
|
|
// Console.WriteLine("Modifying " + weapons.Count + " weapons");
|
|
foreach (KeyValuePair<ModuleWeaponGun, float> keyValuePair in weapons) {
|
|
DoRestoreSingle(keyValuePair.Key);
|
|
DoPatchSingle(keyValuePair.Key);
|
|
}
|
|
}
|
|
|
|
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 (weapons.ContainsKey(weapon)) {
|
|
weapon.m_ShotCooldown = weapons[weapon];
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class GeneratorPropertiesManager {
|
|
private static Dictionary<ModuleEnergy, float> generators = new Dictionary<ModuleEnergy, float>();
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleEnergy), "OnAttached")]
|
|
static void PostfixCreate(ModuleEnergy __instance) {
|
|
if (!generators.ContainsKey(__instance)) {
|
|
generators.Add(__instance, GetValue(__instance));
|
|
DoPatchSingle(__instance);
|
|
}
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleEnergy), "OnDetaching")]
|
|
static void PostfixDestroy(ModuleEnergy __instance) {
|
|
DoRestoreSingle(__instance);
|
|
generators.Remove(__instance);
|
|
}
|
|
|
|
public static void DoPatch() {
|
|
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
|
// Console.WriteLine("Should patch: " + ShouldPatch());
|
|
foreach (KeyValuePair<ModuleEnergy, float> keyValuePair in generators) {
|
|
DoRestoreSingle(keyValuePair.Key);
|
|
DoPatchSingle(keyValuePair.Key);
|
|
}
|
|
}
|
|
|
|
static void DoPatchSingle(ModuleEnergy moduleEnergy) {
|
|
// Console.WriteLine("Patching " + moduleEnergy.name);
|
|
// Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
|
SetValue(moduleEnergy, GetValue(moduleEnergy) * Main.energyGenMultiplier.Value);
|
|
// Console.WriteLine("New value " + GetValue(moduleEnergy));
|
|
}
|
|
|
|
static void DoRestoreSingle(ModuleEnergy moduleEnergy) {
|
|
if (generators.ContainsKey(moduleEnergy)) {
|
|
SetValue(moduleEnergy, generators[moduleEnergy]);
|
|
}
|
|
}
|
|
|
|
private static float GetValue(ModuleEnergy moduleEnergy) {
|
|
return Traverse.Create(moduleEnergy).Field("m_OutputPerSecond").GetValue() as float? ?? 0f;
|
|
}
|
|
|
|
private static void SetValue(ModuleEnergy moduleEnergy, float value) {
|
|
Traverse.Create(moduleEnergy).Field("m_OutputPerSecond").SetValue(value);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class FuelPropertiesManager {
|
|
private static Dictionary<ModuleFuelTank, float> tanks = new Dictionary<ModuleFuelTank, float>();
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleFuelTank), "OnAttached")]
|
|
static void PostfixCreate(ModuleFuelTank __instance) {
|
|
if (!tanks.ContainsKey(__instance)) {
|
|
tanks.Add(__instance, GetValue(__instance));
|
|
DoPatchSingle(__instance);
|
|
}
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleFuelTank), "OnDetaching")]
|
|
static void PostfixDestroy(ModuleFuelTank __instance) {
|
|
DoRestoreSingle(__instance);
|
|
tanks.Remove(__instance);
|
|
}
|
|
|
|
public static void DoPatch() {
|
|
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
|
// Console.WriteLine("Should patch: " + ShouldPatch());
|
|
foreach (KeyValuePair<ModuleFuelTank, float> keyValuePair in tanks) {
|
|
DoRestoreSingle(keyValuePair.Key);
|
|
DoPatchSingle(keyValuePair.Key);
|
|
}
|
|
}
|
|
|
|
static void DoPatchSingle(ModuleFuelTank moduleFuelTank) {
|
|
// Console.WriteLine("Patching " + moduleEnergy.name);
|
|
// Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
|
SetValue(moduleFuelTank, GetValue(moduleFuelTank) * Main.energyGenMultiplier.Value);
|
|
// Console.WriteLine("New value " + GetValue(moduleEnergy));
|
|
}
|
|
|
|
static void DoRestoreSingle(ModuleFuelTank moduleFuelTank) {
|
|
if (tanks.ContainsKey(moduleFuelTank)) {
|
|
SetValue(moduleFuelTank, tanks[moduleFuelTank]);
|
|
}
|
|
}
|
|
|
|
private static float GetValue(ModuleFuelTank moduleFuelTank) {
|
|
return moduleFuelTank.m_RefillRate;
|
|
}
|
|
|
|
private static void SetValue(ModuleFuelTank moduleFuelTank, float value) {
|
|
moduleFuelTank.m_RefillRate = value;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class MagnetPropertiesManager {
|
|
private static Dictionary<ModuleItemHolderMagnet, float> strenghts = new Dictionary<ModuleItemHolderMagnet, float>();
|
|
private static Dictionary<ModuleItemHolderMagnet, float> radii = new Dictionary<ModuleItemHolderMagnet, float>();
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleItemHolderMagnet), "OnAttached")]
|
|
static void PostfixCreate(ModuleItemHolderMagnet __instance) {
|
|
if (!strenghts.ContainsKey(__instance)) {
|
|
strenghts.Add(__instance, GetStrength(__instance));
|
|
radii.Add(__instance, GetRadius(__instance));
|
|
DoPatchSingle(__instance);
|
|
}
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleItemHolderMagnet), "OnDetaching")]
|
|
static void PostfixDestroy(ModuleItemHolderMagnet __instance) {
|
|
DoRestoreSingle(__instance);
|
|
strenghts.Remove(__instance);
|
|
radii.Remove(__instance);
|
|
}
|
|
|
|
public static void DoPatch() {
|
|
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
|
// Console.WriteLine("Should patch: " + ShouldPatch());
|
|
foreach (KeyValuePair<ModuleItemHolderMagnet, float> keyValuePair in strenghts) {
|
|
DoRestoreSingle(keyValuePair.Key);
|
|
DoPatchSingle(keyValuePair.Key);
|
|
}
|
|
}
|
|
|
|
static void DoPatchSingle(ModuleItemHolderMagnet moduleItemHolderMagnet) {
|
|
// Console.WriteLine("Patching " + moduleEnergy.name);
|
|
// Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
|
SetStrength(moduleItemHolderMagnet, GetStrength(moduleItemHolderMagnet) * Main.magnetStrenghtMultiplier.Value);
|
|
SetRadius(moduleItemHolderMagnet, GetRadius(moduleItemHolderMagnet) * Main.magnetRadiusMultiplier.Value);
|
|
// Console.WriteLine("New value " + GetValue(moduleEnergy));
|
|
}
|
|
|
|
static void DoRestoreSingle(ModuleItemHolderMagnet moduleItemHolderMagnet) {
|
|
if (strenghts.ContainsKey(moduleItemHolderMagnet)) {
|
|
SetStrength(moduleItemHolderMagnet, strenghts[moduleItemHolderMagnet]);
|
|
}
|
|
if (radii.ContainsKey(moduleItemHolderMagnet)) {
|
|
SetRadius(moduleItemHolderMagnet, radii[moduleItemHolderMagnet]);
|
|
}
|
|
}
|
|
|
|
private static float GetStrength(ModuleItemHolderMagnet moduleItemHolderMagnet) {
|
|
return Traverse.Create(moduleItemHolderMagnet).Field("m_Strength").GetValue() as float? ?? 0f;
|
|
}
|
|
|
|
private static void SetStrength(ModuleItemHolderMagnet moduleItemHolderMagnet, float value) {
|
|
Traverse.Create(moduleItemHolderMagnet).Field("m_Strength").SetValue(value);
|
|
}
|
|
|
|
private static float GetRadius(ModuleItemHolderMagnet moduleItemHolderMagnet) {
|
|
ModuleItemPickup moduleItemPickup = Traverse.Create(moduleItemHolderMagnet).Field("m_Pickup").GetValue() as ModuleItemPickup;
|
|
if (moduleItemPickup) {
|
|
float radius = Traverse.Create(moduleItemPickup).Field("m_PickupRange").GetValue() as float? ?? 0f;
|
|
return radius;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
private static void SetRadius(ModuleItemHolderMagnet moduleItemHolderMagnet, float value) {
|
|
ModuleItemPickup moduleItemPickup = Traverse.Create(moduleItemHolderMagnet).Field("m_Pickup").GetValue() as ModuleItemPickup;
|
|
if (moduleItemPickup) {
|
|
Traverse.Create(moduleItemPickup).Field("m_PickupRange").SetValue(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class BeamPropertiesManager {
|
|
private static Dictionary<ModuleItemHolderBeam, float> strenghts = new Dictionary<ModuleItemHolderBeam, float>();
|
|
private static Dictionary<ModuleItemHolderBeam, float> radii = new Dictionary<ModuleItemHolderBeam, float>();
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleItemHolderBeam), "OnAttached")]
|
|
static void PostfixCreate(ModuleItemHolderBeam __instance) {
|
|
if (!strenghts.ContainsKey(__instance)) {
|
|
strenghts.Add(__instance, GetStrength(__instance));
|
|
radii.Add(__instance, GetRadius(__instance));
|
|
DoPatchSingle(__instance);
|
|
}
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleItemHolderBeam), "OnDetaching")]
|
|
static void PostfixDestroy(ModuleItemHolderBeam __instance) {
|
|
DoRestoreSingle(__instance);
|
|
strenghts.Remove(__instance);
|
|
radii.Remove(__instance);
|
|
}
|
|
|
|
public static void DoPatch() {
|
|
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
|
// Console.WriteLine("Should patch: " + ShouldPatch());
|
|
foreach (KeyValuePair<ModuleItemHolderBeam, float> keyValuePair in strenghts) {
|
|
DoRestoreSingle(keyValuePair.Key);
|
|
DoPatchSingle(keyValuePair.Key);
|
|
}
|
|
}
|
|
|
|
static void DoPatchSingle(ModuleItemHolderBeam moduleItemHolderBeam) {
|
|
// Console.WriteLine("Patching " + moduleEnergy.name);
|
|
// Console.WriteLine("Old value " + GetValue(moduleEnergy));
|
|
SetStrength(moduleItemHolderBeam, GetStrength(moduleItemHolderBeam) * Main.beamStrenghtMultiplier.Value);
|
|
SetRadius(moduleItemHolderBeam, GetRadius(moduleItemHolderBeam) * Main.beamRadiusMultiplier.Value);
|
|
// Console.WriteLine("New value " + GetValue(moduleEnergy));
|
|
}
|
|
|
|
static void DoRestoreSingle(ModuleItemHolderBeam moduleItemHolderBeam) {
|
|
if (strenghts.ContainsKey(moduleItemHolderBeam)) {
|
|
SetStrength(moduleItemHolderBeam, strenghts[moduleItemHolderBeam]);
|
|
}
|
|
if (radii.ContainsKey(moduleItemHolderBeam)) {
|
|
SetRadius(moduleItemHolderBeam, radii[moduleItemHolderBeam]);
|
|
}
|
|
}
|
|
|
|
private static float GetStrength(ModuleItemHolderBeam moduleItemHolderBeam) {
|
|
return Traverse.Create(moduleItemHolderBeam).Field("m_Strength").GetValue() as float? ?? 0f;
|
|
}
|
|
|
|
private static void SetStrength(ModuleItemHolderBeam moduleItemHolderBeam, float value) {
|
|
Traverse.Create(moduleItemHolderBeam).Field("m_Strength").SetValue(value);
|
|
}
|
|
|
|
private static float GetRadius(ModuleItemHolderBeam moduleItemHolderBeam) {
|
|
ModuleItemPickup moduleItemPickup = Traverse.Create(moduleItemHolderBeam).Field("m_Pickup").GetValue() as ModuleItemPickup;
|
|
if (moduleItemPickup) {
|
|
float radius = Traverse.Create(moduleItemPickup).Field("m_PickupRange").GetValue() as float? ?? 0f;
|
|
return radius;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
private static void SetRadius(ModuleItemHolderBeam moduleItemHolderBeam, float value) {
|
|
ModuleItemPickup moduleItemPickup = Traverse.Create(moduleItemHolderBeam).Field("m_Pickup").GetValue() as ModuleItemPickup;
|
|
if (moduleItemPickup) {
|
|
Traverse.Create(moduleItemPickup).Field("m_PickupRange").SetValue(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public class MinerPropertiesManager {
|
|
private static Dictionary<ModuleItemProducer, float> area = new Dictionary<ModuleItemProducer, float>();
|
|
private static Dictionary<ModuleItemProducer, float> speed = new Dictionary<ModuleItemProducer, float>();
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleItemProducer), "GetClosestResourceReservoirInRange")]
|
|
static void PostfixCreate(ModuleItemProducer __instance) {
|
|
// Console.WriteLine("ModuleItemProducer OnPool");
|
|
if (!area.ContainsKey(__instance)) {
|
|
// Console.WriteLine("Is new ModuleItemProducer");
|
|
area.Add(__instance, GetArea(__instance));
|
|
speed.Add(__instance, GetSpeed(__instance));
|
|
DoPatchSingle(__instance);
|
|
} else {
|
|
if (GetArea(__instance) == area[__instance]) {
|
|
DoPatchSingle(__instance);
|
|
}
|
|
if (GetSpeed(__instance) == speed[__instance]) {
|
|
DoPatchSingle(__instance);
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
[HarmonyPatch(typeof(ModuleItemProducer), "OnRecycle")]
|
|
static void PostfixDestroy(ModuleItemProducer __instance) {
|
|
// Console.WriteLine("ModuleItemProducer OnRecycle");
|
|
DoRestoreSingle(__instance);
|
|
area.Remove(__instance);
|
|
speed.Remove(__instance);
|
|
}
|
|
|
|
public static void DoPatch() {
|
|
// Console.WriteLine("Modifying " + generators.Count + " generators");
|
|
// Console.WriteLine("Should patch: " + ShouldPatch());
|
|
foreach (KeyValuePair<ModuleItemProducer, float> keyValuePair in area) {
|
|
DoRestoreSingle(keyValuePair.Key);
|
|
DoPatchSingle(keyValuePair.Key);
|
|
}
|
|
}
|
|
|
|
static void DoPatchSingle(ModuleItemProducer moduleItemProducer) {
|
|
// Console.WriteLine("Patching " + moduleItemProducer.name);
|
|
// Console.WriteLine("Old value " + GetArea(moduleItemProducer));
|
|
// Console.WriteLine("Multiplier " + Main.minerGroundArea.Value);
|
|
SetArea(moduleItemProducer, area[moduleItemProducer] * Main.minerGroundArea.Value);
|
|
SetSpeed(moduleItemProducer, speed[moduleItemProducer] / Main.minerMiningSpeed.Value);
|
|
// Console.WriteLine("New value " + GetArea(moduleItemProducer));
|
|
}
|
|
|
|
[HarmonyPrefix]
|
|
[HarmonyPatch(typeof(ModuleItemProducer), "GetClosestResourceReservoirInRange")]
|
|
static void Test(ModuleItemProducer __instance) {
|
|
Console.WriteLine("" + GetArea(__instance));
|
|
}
|
|
|
|
static void DoRestoreSingle(ModuleItemProducer moduleItemProducer) {
|
|
if (area.ContainsKey(moduleItemProducer)) {
|
|
SetArea(moduleItemProducer, area[moduleItemProducer]);
|
|
}
|
|
if (speed.ContainsKey(moduleItemProducer)) {
|
|
SetSpeed(moduleItemProducer, speed[moduleItemProducer]);
|
|
}
|
|
}
|
|
|
|
private static float GetArea(ModuleItemProducer moduleItemProducer) {
|
|
return Traverse.Create(moduleItemProducer).Field("m_ResourceGroundRadius").GetValue() as float? ?? 0f;
|
|
}
|
|
|
|
private static void SetArea(ModuleItemProducer moduleItemProducer, float value) {
|
|
Traverse.Create(moduleItemProducer).Field("m_ResourceGroundRadius").SetValue(value);
|
|
}
|
|
|
|
private static float GetSpeed(ModuleItemProducer moduleItemProducer) {
|
|
return Traverse.Create(moduleItemProducer).Field("m_SecPerItemProduced").GetValue() as float? ?? 0f;
|
|
}
|
|
|
|
private static void SetSpeed(ModuleItemProducer moduleItemProducer, float value) {
|
|
Traverse.Create(moduleItemProducer).Field("m_SecPerItemProduced").SetValue(value);
|
|
}
|
|
}
|
|
} |