Add battery capacity multiplier configuration
This commit is contained in:
65
Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs
Normal file
65
Projects/TerraTech/TerraTech/ModuleEnergyStoreManager.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace TerraTech {
|
||||
[HarmonyPatch]
|
||||
public class ModuleEnergyStoreManager {
|
||||
private static Dictionary<ModuleEnergyStore, float> batteryCapacity =
|
||||
new Dictionary<ModuleEnergyStore, float>();
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")]
|
||||
static void PostfixCreate(ModuleEnergyStore __instance) {
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("ModuleEnergyStore.OnAttached");
|
||||
if (!batteryCapacity.ContainsKey(__instance)) {
|
||||
batteryCapacity.Add(__instance, __instance.m_BatteryCapacity);
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Patching {0}; m_BatteryCapacity: {1}", __instance.ToString(),
|
||||
__instance.m_BatteryCapacity);
|
||||
}
|
||||
|
||||
DoPatchSingle(__instance);
|
||||
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Patched {0}; m_BatteryCapacity: {1}", __instance.ToString(),
|
||||
__instance.m_BatteryCapacity);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")]
|
||||
static void PostfixDestroy(ModuleEnergyStore __instance) {
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("ModuleEnergyStore.OnDetaching");
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Restoring {0}; m_BatteryCapacity: {1}", __instance.ToString(),
|
||||
__instance.m_BatteryCapacity);
|
||||
|
||||
DoRestoreSingle(__instance);
|
||||
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Restored {0}; m_BatteryCapacity: {1}", __instance.ToString(),
|
||||
__instance.m_BatteryCapacity);
|
||||
|
||||
batteryCapacity.Remove(__instance);
|
||||
}
|
||||
|
||||
public static void DoPatch() {
|
||||
if (Main.debug.Value)
|
||||
Console.WriteLine("Modifying {0} ModuleEnergyStore", batteryCapacity.Count);
|
||||
foreach (KeyValuePair<ModuleEnergyStore, float> keyValuePair in batteryCapacity) {
|
||||
DoRestoreSingle(keyValuePair.Key);
|
||||
DoPatchSingle(keyValuePair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
static void DoPatchSingle(ModuleEnergyStore moduleEnergyStore) {
|
||||
moduleEnergyStore.m_BatteryCapacity =
|
||||
batteryCapacity[moduleEnergyStore] * Main.batteryCapacityMultiplier.Value;
|
||||
}
|
||||
|
||||
static void DoRestoreSingle(ModuleEnergyStore moduleEnergyStore) {
|
||||
if (batteryCapacity.ContainsKey(moduleEnergyStore))
|
||||
moduleEnergyStore.m_BatteryCapacity = batteryCapacity[moduleEnergyStore];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user