Fix excavator capacity bullshit

This commit is contained in:
2024-10-18 22:59:48 +02:00
parent f663d28109
commit ef58960245

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using HarmonyLib; using HarmonyLib;
using Mafi; using Mafi;
@@ -22,78 +23,79 @@ using Mafi.Core.Ports.Io;
using Mafi.Core.Products; using Mafi.Core.Products;
using Mafi.Core.Prototypes; using Mafi.Core.Prototypes;
using Mafi.Core.Terrain; using Mafi.Core.Terrain;
using Mafi.Core.Vehicles.Excavators;
using Mafi.Core.World.Entities; using Mafi.Core.World.Entities;
namespace CykaOfIndustry { namespace CykaOfIndustry {
[HarmonyPatch] [HarmonyPatch]
public class Patches { public class Patches {
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ExcavatorProtoBuilder.ExcavatorProtoBuilderState), "SetCapacity")] [HarmonyPatch(typeof(ExcavatorProtoBuilder.ExcavatorProtoBuilderState), "SetCapacity")]
static void excavatorCapacityMultiplier(ref int quantity) { static void excavatorCapacityMultiplier(ref int quantity) {
// Console.WriteLine("IndustrialCyka: Old excavator capacity: {0}", quantity); // Console.WriteLine("IndustrialCyka: Old excavator capacity: {0}", quantity);
quantity *= Main.excavatorCapacityMultiplier.Value; quantity *= Main.excavatorCapacityMultiplier.Value;
// Console.WriteLine("IndustrialCyka: Old excavator capacity: {0}", quantity); // Console.WriteLine("IndustrialCyka: Old excavator capacity: {0}", quantity);
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ExcavatorProtoBuilder.ExcavatorProtoBuilderState), "SetMinedThicknessByDistanceMeters")] [HarmonyPatch(typeof(ExcavatorProtoBuilder.ExcavatorProtoBuilderState), "SetMinedThicknessByDistanceMeters")]
static void excavatorMiningAreaMultiplier(ref float[] thicknessMeters) { static void excavatorMiningAreaMultiplier(ref float[] thicknessMeters) {
for (int i = 0; i < thicknessMeters.Length; i++) { for (int i = 0; i < thicknessMeters.Length; i++) {
// Console.WriteLine("IndustrialCyka: Old mining area: {0}", thicknessMeters[i]); // Console.WriteLine("IndustrialCyka: Old mining area: {0}", thicknessMeters[i]);
thicknessMeters[i] *= Main.excavatorMiningAreaMultiplier.Value; thicknessMeters[i] *= Main.excavatorMiningAreaMultiplier.Value;
// Console.WriteLine("IndustrialCyka: New mining area: {0}", thicknessMeters[i]); // Console.WriteLine("IndustrialCyka: New mining area: {0}", thicknessMeters[i]);
} }
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ExcavatorProtoBuilder.ExcavatorProtoBuilderState), "SetMaxMiningDistance")] [HarmonyPatch(typeof(ExcavatorProtoBuilder.ExcavatorProtoBuilderState), "SetMaxMiningDistance")]
static void excavatorReachMultiplier(ref RelTile1i minMiningDistance, ref RelTile1i maxMiningDistance) { static void excavatorReachMultiplier(ref RelTile1i minMiningDistance, ref RelTile1i maxMiningDistance) {
Console.WriteLine("Min distance: {0}, max distance: {1}", minMiningDistance, maxMiningDistance); Console.WriteLine("Min distance: {0}, max distance: {1}", minMiningDistance, maxMiningDistance);
minMiningDistance = new RelTile1i((int)(minMiningDistance.Value * Main.excavatorMinReachMultiplier.Value)); minMiningDistance = new RelTile1i((int)(minMiningDistance.Value * Main.excavatorMinReachMultiplier.Value));
maxMiningDistance = new RelTile1i((int)(maxMiningDistance.Value * Main.excavatorMaxReachMultiplier.Value)); maxMiningDistance = new RelTile1i((int)(maxMiningDistance.Value * Main.excavatorMaxReachMultiplier.Value));
Console.WriteLine("Min distance: {0}, max distance: {1}", minMiningDistance, maxMiningDistance); Console.WriteLine("Min distance: {0}, max distance: {1}", minMiningDistance, maxMiningDistance);
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(TruckProtoBuilder.TruckProtoBuilderState), "SetCapacity")] [HarmonyPatch(typeof(TruckProtoBuilder.TruckProtoBuilderState), "SetCapacity")]
static void truckCapacityMultiplier(ref int quantity) { static void truckCapacityMultiplier(ref int quantity) {
// Console.WriteLine("IndustrialCyka: Old truck capacity: {0}", quantity); // Console.WriteLine("IndustrialCyka: Old truck capacity: {0}", quantity);
quantity *= Main.truckCapacityMultiplier.Value; quantity *= Main.truckCapacityMultiplier.Value;
// Console.WriteLine("IndustrialCyka: New truck capacity: {0}", quantity); // Console.WriteLine("IndustrialCyka: New truck capacity: {0}", quantity);
} }
// [HarmonyPrefix] // [HarmonyPrefix]
// [HarmonyPatch(typeof(StorageProtoBuilder.State), "SetCapacity")] // [HarmonyPatch(typeof(StorageProtoBuilder.State), "SetCapacity")]
// static void storageCapacityMultiplier(ref int capacity) { // static void storageCapacityMultiplier(ref int capacity) {
// // Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", capacity); // // Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", capacity);
// capacity = (int)(capacity * Main.storageCapacityMultiplier.Value); // capacity = (int)(capacity * Main.storageCapacityMultiplier.Value);
// // Console.WriteLine("IndustrialCyka: New storage capacity: {0}", capacity); // // Console.WriteLine("IndustrialCyka: New storage capacity: {0}", capacity);
// } // }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(CargoShipModuleProto), MethodType.Constructor, [HarmonyPatch(typeof(CargoShipModuleProto), MethodType.Constructor,
new[] { new[] {
typeof(Proto.ID), typeof(Proto.Str), typeof(ProductType), typeof(Quantity), typeof(Proto.ID), typeof(Proto.Str), typeof(ProductType), typeof(Quantity),
typeof(CargoShipModuleProto.Gfx) typeof(CargoShipModuleProto.Gfx)
})] })]
static void cargoShipCapacityMultiplier(CargoShipModuleProto __instance) { static void cargoShipCapacityMultiplier(CargoShipModuleProto __instance) {
// Console.WriteLine("IndustrialCyka: Old ship capacity: {0}", __instance.Capacity.Value); // Console.WriteLine("IndustrialCyka: Old ship capacity: {0}", __instance.Capacity.Value);
__instance.Capacity = new Quantity(__instance.Capacity.Value * Main.cargoShipCapacityMultiplier.Value); __instance.Capacity = new Quantity(__instance.Capacity.Value * Main.cargoShipCapacityMultiplier.Value);
// Console.WriteLine("IndustrialCyka: New ship capacity: {0}", __instance.Capacity.Value); // Console.WriteLine("IndustrialCyka: New ship capacity: {0}", __instance.Capacity.Value);
} }
// No workey... idk how it's supposed to work, speed is always 1 or 100% // No workey... idk how it's supposed to work, speed is always 1 or 100%
// [HarmonyPrefix] // [HarmonyPrefix]
// [HarmonyPatch(typeof(DrivingEntity), "SetSpeedFactor")] // [HarmonyPatch(typeof(DrivingEntity), "SetSpeedFactor")]
// static void vehicleSpeedMultiplier(ref Percent speedFactor) { // static void vehicleSpeedMultiplier(ref Percent speedFactor) {
// // Console.WriteLine("IndustrialCyka: Old speed: {0}", speedFactor.ToString()); // // Console.WriteLine("IndustrialCyka: Old speed: {0}", speedFactor.ToString());
// // typeof(Percent) // // typeof(Percent)
// // .GetField("RawValue",BindingFlags.Instance|BindingFlags.NonPublic) // // .GetField("RawValue",BindingFlags.Instance|BindingFlags.NonPublic)
// // .SetValue(speedFactor,speedFactor.ToFloat() / Main.vehicleSpeedMultiplier.Value); // // .SetValue(speedFactor,speedFactor.ToFloat() / Main.vehicleSpeedMultiplier.Value);
// Percent newSpeedFactor = Percent.FromFloat(speedFactor.ToFloat() / Main.vehicleSpeedMultiplier.Value); // Percent newSpeedFactor = Percent.FromFloat(speedFactor.ToFloat() / Main.vehicleSpeedMultiplier.Value);
// speedFactor = newSpeedFactor; // speedFactor = newSpeedFactor;
// // Console.WriteLine("IndustrialCyka: New speed: {1}", newSpeedFactor.RawValue.ToString()); // // Console.WriteLine("IndustrialCyka: New speed: {1}", newSpeedFactor.RawValue.ToString());
// } // }
// [HarmonyPostfix] // [HarmonyPostfix]
// [HarmonyPatch(typeof(SmoothDriver), "SetSpeedFactor")] // [HarmonyPatch(typeof(SmoothDriver), "SetSpeedFactor")]
@@ -116,350 +118,366 @@ namespace CykaOfIndustry {
// // maxBackwardsSpeedField.GetValue(), maxAccelerationField.GetValue()); // // maxBackwardsSpeedField.GetValue(), maxAccelerationField.GetValue());
// } // }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(StorageBaseProto), MethodType.Constructor, [HarmonyPatch(typeof(StorageBaseProto), MethodType.Constructor,
new[] { new[] {
typeof(StaticEntityProto.ID), typeof(StaticEntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(EntityLayout), typeof(EntityLayout),
typeof(Quantity), typeof(Quantity),
typeof(EntityCosts), typeof(EntityCosts),
typeof(LayoutEntityProto.Gfx), typeof(LayoutEntityProto.Gfx),
typeof(Quantity), typeof(Quantity),
typeof(Duration), typeof(Duration),
typeof(IEnumerable<Tag>) typeof(IEnumerable<Tag>)
})] })]
static void storageCapacityMultiplier(StorageProto __instance) { static void storageCapacityMultiplier(StorageProto __instance) {
// Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", __instance.Capacity.Value); // Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", __instance.Capacity.Value);
// Console.WriteLine("IndustrialCyka: Old storage transfer limit: {0}", __instance.TransferLimit.Value); // Console.WriteLine("IndustrialCyka: Old storage transfer limit: {0}", __instance.TransferLimit.Value);
Traverse traverse = Traverse.Create(__instance); Traverse traverse = Traverse.Create(__instance);
traverse.Field("Capacity") traverse.Field("Capacity")
.SetValue(new Quantity((int)(__instance.Capacity.Value * Main.storageCapacityMultiplier.Value))); .SetValue(new Quantity((int)(__instance.Capacity.Value * Main.storageCapacityMultiplier.Value)));
traverse.Field("TransferLimit").SetValue(new Quantity(10000)); traverse.Field("TransferLimit").SetValue(new Quantity(10000));
traverse.Field("TransferLimitDuration").SetValue(Duration.FromTicks(1)); traverse.Field("TransferLimitDuration").SetValue(Duration.FromTicks(1));
// Console.WriteLine("IndustrialCyka: New storage capacity: {0}", __instance.Capacity.Value); // Console.WriteLine("IndustrialCyka: New storage capacity: {0}", __instance.Capacity.Value);
// Console.WriteLine("IndustrialCyka: New storage transfer limit: {0}", __instance.TransferLimit.Value); // Console.WriteLine("IndustrialCyka: New storage transfer limit: {0}", __instance.TransferLimit.Value);
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(UpointsManager), "GenerateUnity")] [HarmonyPatch(typeof(UpointsManager), "GenerateUnity")]
static void unityGenerationMultiplier(Proto.ID categoryId, ref Upoints generated) { static void unityGenerationMultiplier(Proto.ID categoryId, ref Upoints generated) {
// Console.WriteLine("IndustrialCyka: Old generated {0} unity", generated.Value); // Console.WriteLine("IndustrialCyka: Old generated {0} unity", generated.Value);
Fix32 multi = Fix32.FromFloat(Main.unityGenerationMultiplier.Value); Fix32 multi = Fix32.FromFloat(Main.unityGenerationMultiplier.Value);
generated = new Upoints(generated.Value * multi); generated = new Upoints(generated.Value * multi);
// Console.WriteLine("IndustrialCyka: New generated {0} unity", generated.Value); // Console.WriteLine("IndustrialCyka: New generated {0} unity", generated.Value);
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(Machine), "updateWorkOnRecipes")] [HarmonyPatch(typeof(Machine), "updateWorkOnRecipes")]
static IEnumerable<CodeInstruction> unityBooster(IEnumerable<CodeInstruction> instructions) { static IEnumerable<CodeInstruction> unityBooster(IEnumerable<CodeInstruction> instructions) {
Dictionary<int, OpCode> matchTable = new Dictionary<int, OpCode>(); Dictionary<int, OpCode> matchTable = new Dictionary<int, OpCode>();
matchTable[0] = OpCodes.Ldsfld; matchTable[0] = OpCodes.Ldsfld;
matchTable[1] = OpCodes.Br; matchTable[1] = OpCodes.Br;
matchTable[2] = OpCodes.Ldc_I4_2; matchTable[2] = OpCodes.Ldc_I4_2;
int matches = 0; int matches = 0;
int totalMatch = matchTable.Count; int totalMatch = matchTable.Count;
var codes = new List<CodeInstruction>(instructions); var codes = new List<CodeInstruction>(instructions);
for (int i = 0; i < codes.Count; i++) { for (int i = 0; i < codes.Count; i++) {
if (matches >= totalMatch) { if (matches >= totalMatch) {
break; break;
} }
if (codes[i].opcode.Equals(matchTable[matches])) { if (codes[i].opcode.Equals(matchTable[matches])) {
if (matches == totalMatch - 1) { if (matches == totalMatch - 1) {
codes[i].opcode = OpCodes.Ldc_I4_6; codes[i].opcode = OpCodes.Ldc_I4_6;
} }
matches++; matches++;
} }
} }
// for (int i = 0; i < codes.Count; i++) { // for (int i = 0; i < codes.Count; i++) {
// Console.WriteLine(codes[i].ToString()); // Console.WriteLine(codes[i].ToString());
// } // }
return codes.AsEnumerable(); return codes.AsEnumerable();
} }
// Could not make this work either... idk why... Doesn't make sense... // Could not make this work either... idk why... Doesn't make sense...
// [HarmonyPostfix] // [HarmonyPostfix]
// [HarmonyPatch(typeof(SimpleVirtualResource), "MineResourceAt")] // [HarmonyPatch(typeof(SimpleVirtualResource), "MineResourceAt")]
// static void infiniteGroundResources(SimpleVirtualResource __instance) { // static void infiniteGroundResources(SimpleVirtualResource __instance) {
// // Console.WriteLine("IndustrialCyka: Patching ground resources (Capacity)"); // // Console.WriteLine("IndustrialCyka: Patching ground resources (Capacity)");
// Traverse traverse = Traverse.Create(__instance); // Traverse traverse = Traverse.Create(__instance);
// Traverse capacityField = traverse.Field("Capacity"); // Traverse capacityField = traverse.Field("Capacity");
// capacityField.SetValue(1000000000); // capacityField.SetValue(1000000000);
// Traverse quantityField = traverse.Field("Quantity"); // Traverse quantityField = traverse.Field("Quantity");
// quantityField.SetValue(1000000000); // quantityField.SetValue(1000000000);
// } // }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(ProductBuffer), "ForceNewCapacityTo")] [HarmonyPatch(typeof(ProductBuffer), "ForceNewCapacityTo")]
static void bufferCapacityMultiplier(ref Quantity newCapacity) { static void bufferCapacityMultiplier(ref Quantity newCapacity) {
if (newCapacity.Value <= 0) { if (newCapacity.Value <= 0) {
return; return;
} }
Quantity newNewCapacity = new Quantity((int)(newCapacity.Value * Main.bufferCapacityMultiplier.Value)); Quantity newNewCapacity = new Quantity((int)(newCapacity.Value * Main.bufferCapacityMultiplier.Value));
newCapacity = newNewCapacity; newCapacity = newNewCapacity;
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(CargoDepotModuleProto), MethodType.Constructor, [HarmonyPatch(typeof(CargoDepotModuleProto), MethodType.Constructor,
new[] { new[] {
typeof(CargoDepotModuleProto.ID), typeof(CargoDepotModuleProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(EntityLayout), typeof(EntityLayout),
typeof(ProductType), typeof(ProductType),
typeof(Option<CargoDepotModuleProto>), typeof(Option<CargoDepotModuleProto>),
typeof(Quantity), typeof(Quantity),
typeof(Quantity), typeof(Quantity),
typeof(Duration), typeof(Duration),
typeof(Electricity), typeof(Electricity),
typeof(bool), typeof(bool),
typeof(Percent), typeof(Percent),
typeof(EntityCosts), typeof(EntityCosts),
typeof(CargoDepotModuleProto.Gfx), typeof(CargoDepotModuleProto.Gfx),
typeof(IEnumerable<Tag>), typeof(IEnumerable<Tag>),
})] })]
static void depotTransferSpeedMultiplier(CargoDepotModuleProto __instance) { static void depotTransferSpeedMultiplier(CargoDepotModuleProto __instance) {
// Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", __instance.Capacity.Value); // Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", __instance.Capacity.Value);
Traverse traverse = Traverse.Create(__instance); Traverse traverse = Traverse.Create(__instance);
traverse.Field("QuantityPerExchange") traverse.Field("QuantityPerExchange")
.SetValue(new Quantity((int)(__instance.QuantityPerExchange.Value * .SetValue(new Quantity((int)(__instance.QuantityPerExchange.Value *
Main.depotTransferSpeedMultiplier.Value))); Main.depotTransferSpeedMultiplier.Value)));
// Console.WriteLine("IndustrialCyka: New storage capacity: {0}", __instance.Capacity.Value); // Console.WriteLine("IndustrialCyka: New storage capacity: {0}", __instance.Capacity.Value);
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor, [HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor,
new[] { new[] {
typeof(EntityProto.ID), typeof(EntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(ProductQuantity), typeof(ProductQuantity),
typeof(Duration), typeof(Duration),
typeof(Upoints), typeof(Upoints),
typeof(UpointsCategoryProto), typeof(UpointsCategoryProto),
typeof(EntityCosts), typeof(EntityCosts),
typeof(Func<int, EntityCosts>), typeof(Func<int, EntityCosts>),
typeof(int), typeof(int),
typeof(Quantity), typeof(Quantity),
typeof(WorldMapEntityProto.Gfx), typeof(WorldMapEntityProto.Gfx),
typeof(int), typeof(int),
typeof(int), typeof(int),
typeof(IEnumerable<Tag>), typeof(IEnumerable<Tag>),
})] })]
static void worldMineSpeedMultiplier(WorldMapMineProto __instance) { static void worldMineSpeedMultiplier(WorldMapMineProto __instance) {
// Console.WriteLine("Before: {0}", __instance.ProducedProductPerStep.Quantity.Value); // Console.WriteLine("Before: {0}", __instance.ProducedProductPerStep.Quantity.Value);
ProductQuantity newProductQuantity = new ProductQuantity(__instance.ProducedProductPerStep.Product, ProductQuantity newProductQuantity = new ProductQuantity(__instance.ProducedProductPerStep.Product,
new Quantity((int)(__instance.ProducedProductPerStep.Quantity.Value * new Quantity((int)(__instance.ProducedProductPerStep.Quantity.Value *
Main.worldMineSpeedMultiplier.Value))); Main.worldMineSpeedMultiplier.Value)));
Traverse.Create(__instance) Traverse.Create(__instance)
.Field("ProducedProductPerStep") .Field("ProducedProductPerStep")
.SetValue(newProductQuantity); .SetValue(newProductQuantity);
// Console.WriteLine("After: {0}", __instance.ProducedProductPerStep.Quantity.Value); // Console.WriteLine("After: {0}", __instance.ProducedProductPerStep.Quantity.Value);
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor, [HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor,
new[] { new[] {
typeof(EntityProto.ID), typeof(EntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(ProductQuantity), typeof(ProductQuantity),
typeof(Duration), typeof(Duration),
typeof(Upoints), typeof(Upoints),
typeof(UpointsCategoryProto), typeof(UpointsCategoryProto),
typeof(EntityCosts), typeof(EntityCosts),
typeof(Func<int, EntityCosts>), typeof(Func<int, EntityCosts>),
typeof(int), typeof(int),
typeof(Quantity), typeof(Quantity),
typeof(WorldMapEntityProto.Gfx), typeof(WorldMapEntityProto.Gfx),
typeof(int), typeof(int),
typeof(int), typeof(int),
typeof(IEnumerable<Tag>), typeof(IEnumerable<Tag>),
})] })]
static void worldMineLevelIncrementMultiplier(WorldMapMineProto __instance) { static void worldMineLevelIncrementMultiplier(WorldMapMineProto __instance) {
Traverse traverse = Traverse.Create(__instance); Traverse traverse = Traverse.Create(__instance);
// int level = traverse.Field("Level").GetValue<int>(); // int level = traverse.Field("Level").GetValue<int>();
int maxLevel = traverse.Field("MaxLevel").GetValue<int>(); int maxLevel = traverse.Field("MaxLevel").GetValue<int>();
// int levelsPerUpgrade = traverse.Field("LevelsPerUpgrade").GetValue<int>(); // int levelsPerUpgrade = traverse.Field("LevelsPerUpgrade").GetValue<int>();
int newLevelsPerUpgrade = 10; int newLevelsPerUpgrade = 10;
int newMaxLevel = (int)Math.Ceiling((double)maxLevel / newLevelsPerUpgrade) * newLevelsPerUpgrade; int newMaxLevel = (int)Math.Ceiling((double)maxLevel / newLevelsPerUpgrade) * newLevelsPerUpgrade;
// Console.WriteLine("Level: {0}, MaxLevel: {1}, LevelsPerUpgrade: {2}", level, maxLevel, levelsPerUpgrade); // Console.WriteLine("Level: {0}, MaxLevel: {1}, LevelsPerUpgrade: {2}", level, maxLevel, levelsPerUpgrade);
// Console.WriteLine("NewMaxLevel: {0}", newMaxLevel); // Console.WriteLine("NewMaxLevel: {0}", newMaxLevel);
traverse.Field("MaxLevel").SetValue(newMaxLevel); traverse.Field("MaxLevel").SetValue(newMaxLevel);
traverse.Field("LevelsPerUpgrade").SetValue(newLevelsPerUpgrade); traverse.Field("LevelsPerUpgrade").SetValue(newLevelsPerUpgrade);
} }
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor, [HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor,
new[] { new[] {
typeof(EntityProto.ID), typeof(EntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(ProductQuantity), typeof(ProductQuantity),
typeof(Duration), typeof(Duration),
typeof(Upoints), typeof(Upoints),
typeof(UpointsCategoryProto), typeof(UpointsCategoryProto),
typeof(EntityCosts), typeof(EntityCosts),
typeof(Func<int, EntityCosts>), typeof(Func<int, EntityCosts>),
typeof(int), typeof(int),
typeof(Quantity), typeof(Quantity),
typeof(WorldMapEntityProto.Gfx), typeof(WorldMapEntityProto.Gfx),
typeof(int), typeof(int),
typeof(int), typeof(int),
typeof(IEnumerable<Tag>), typeof(IEnumerable<Tag>),
})] })]
static IEnumerable<CodeInstruction> cookWorldMineLevelIncrementMultiplier( static IEnumerable<CodeInstruction> cookWorldMineLevelIncrementMultiplier(
IEnumerable<CodeInstruction> instructions) { IEnumerable<CodeInstruction> instructions) {
Dictionary<int, OpCode> matchTable = new Dictionary<int, OpCode>(); Dictionary<int, OpCode> matchTable = new Dictionary<int, OpCode>();
matchTable[0] = OpCodes.Rem; matchTable[0] = OpCodes.Rem;
matchTable[1] = OpCodes.Ldfld; matchTable[1] = OpCodes.Ldfld;
matchTable[2] = OpCodes.Ldarg_0; matchTable[2] = OpCodes.Ldarg_0;
matchTable[3] = OpCodes.Ldfld; matchTable[3] = OpCodes.Ldfld;
matchTable[4] = OpCodes.Ldarg_0; matchTable[4] = OpCodes.Ldarg_0;
int matches = 0; int matches = 0;
int totalMatch = matchTable.Count; int totalMatch = matchTable.Count;
var codes = new List<CodeInstruction>(instructions); var codes = new List<CodeInstruction>(instructions);
for (int i = codes.Count - 1; i >= 0; i--) { for (int i = codes.Count - 1; i >= 0; i--) {
if (matches >= totalMatch) { if (matches >= totalMatch) {
break; break;
} }
if (codes[i].opcode.Equals(matchTable[matches])) { if (codes[i].opcode.Equals(matchTable[matches])) {
if (matches == totalMatch - 1) { if (matches == totalMatch - 1) {
codes[i + 4].opcode = OpCodes.Add; codes[i + 4].opcode = OpCodes.Add;
codes[i + 5].opcode = OpCodes.Brtrue_S; codes[i + 5].opcode = OpCodes.Brtrue_S;
break; break;
} }
matches++; matches++;
} }
else { else {
matches = 0; matches = 0;
} }
} }
return codes.AsEnumerable(); return codes.AsEnumerable();
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(SettlementHousingModuleProto), MethodType.Constructor, new[] { [HarmonyPatch(typeof(SettlementHousingModuleProto), MethodType.Constructor, new[] {
typeof(StaticEntityProto.ID), typeof(StaticEntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(EntityLayout), typeof(EntityLayout),
typeof(EntityCosts), typeof(EntityCosts),
typeof(int), typeof(int),
typeof(Upoints), typeof(Upoints),
typeof(ImmutableArray<KeyValuePair<ImmutableArray<PopNeedProto>, Percent>>), typeof(ImmutableArray<KeyValuePair<ImmutableArray<PopNeedProto>, Percent>>),
typeof(IReadOnlyDictionary<PopNeedProto, Percent>), typeof(IReadOnlyDictionary<PopNeedProto, Percent>),
typeof(Option<SettlementHousingModuleProto>), typeof(Option<SettlementHousingModuleProto>),
typeof(SettlementHousingModuleProto.Gfx), typeof(SettlementHousingModuleProto.Gfx),
})] })]
static void housingCapacityMultiplier(SettlementHousingModuleProto __instance) { static void housingCapacityMultiplier(SettlementHousingModuleProto __instance) {
Traverse.Create(__instance).Field<int>("Capacity").Value = Traverse.Create(__instance).Field<int>("Capacity").Value =
(int)(__instance.Capacity * Main.housingCapacityMultiplier.Value); (int)(__instance.Capacity * Main.housingCapacityMultiplier.Value);
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(StackerProto), MethodType.Constructor, new[] { [HarmonyPatch(typeof(StackerProto), MethodType.Constructor, new[] {
typeof(StaticEntityProto.ID), typeof(StaticEntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(EntityLayout), typeof(EntityLayout),
typeof(EntityCosts), typeof(EntityCosts),
typeof(Electricity), typeof(Electricity),
typeof(ThicknessTilesI), typeof(ThicknessTilesI),
typeof(RelTile3i), typeof(RelTile3i),
typeof(Duration), typeof(Duration),
typeof(Duration), typeof(Duration),
typeof(StackerProto.Gfx), typeof(StackerProto.Gfx),
typeof(ThicknessTilesI), typeof(ThicknessTilesI),
typeof(IEnumerable<Tag>), typeof(IEnumerable<Tag>),
})] })]
static void dumpDelayMultiplier(StackerProto __instance) { static void dumpDelayMultiplier(StackerProto __instance) {
Duration newDelay = Duration newDelay =
new Duration(Math.Max((int)(__instance.DumpDelay.Ticks * Main.dumpDelayMultiplier.Value), 1)); new Duration(Math.Max((int)(__instance.DumpDelay.Ticks * Main.dumpDelayMultiplier.Value), 1));
Traverse.Create(__instance).Field("DumpDelay").SetValue(newDelay); Traverse.Create(__instance).Field("DumpDelay").SetValue(newDelay);
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(TransportProto), MethodType.Constructor, new[] { [HarmonyPatch(typeof(TransportProto), MethodType.Constructor, new[] {
typeof(StaticEntityProto.ID), typeof(StaticEntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(ThicknessTilesF), typeof(ThicknessTilesF),
typeof(Quantity), typeof(Quantity),
typeof(RelTile1f), typeof(RelTile1f),
typeof(RelTile1f), typeof(RelTile1f),
typeof(RelTile1i), typeof(RelTile1i),
typeof(bool), typeof(bool),
typeof(bool), typeof(bool),
typeof(Option<TerrainTileSurfaceProto>), typeof(Option<TerrainTileSurfaceProto>),
typeof(RelTile1i), typeof(RelTile1i),
typeof(IoPortShapeProto), typeof(IoPortShapeProto),
typeof(Electricity), typeof(Electricity),
typeof(Percent), typeof(Percent),
typeof(bool), typeof(bool),
typeof(bool), typeof(bool),
typeof(EntityCosts), typeof(EntityCosts),
typeof(RelTile1i), typeof(RelTile1i),
typeof(Duration), typeof(Duration),
typeof(Option<TransportProto>), typeof(Option<TransportProto>),
typeof(VirtualProductProto), typeof(VirtualProductProto),
typeof(Quantity), typeof(Quantity),
typeof(TransportProto.Gfx), typeof(TransportProto.Gfx),
})] })]
static void transportSpeedMultiplier(ref StaticEntityProto.ID id, ref Proto.Str strings, static void transportSpeedMultiplier(ref StaticEntityProto.ID id, ref Proto.Str strings,
ref ThicknessTilesF surfaceRelativeHeight, ref Quantity maxQuantityPerTransportedProduct, ref ThicknessTilesF surfaceRelativeHeight, ref Quantity maxQuantityPerTransportedProduct,
ref RelTile1f transportedProductsSpacing, ref RelTile1f speedPerTick, ref RelTile1i zStepLength, ref RelTile1f transportedProductsSpacing, ref RelTile1f speedPerTick, ref RelTile1i zStepLength,
ref bool needsPillarsAtGround, ref bool canBeBuried, ref bool needsPillarsAtGround, ref bool canBeBuried,
ref Option<TerrainTileSurfaceProto> tileSurfaceWhenOnGround, ref RelTile1i maxPillarSupportRadius, ref Option<TerrainTileSurfaceProto> tileSurfaceWhenOnGround, ref RelTile1i maxPillarSupportRadius,
ref IoPortShapeProto portsShape, ref Electricity baseElectricityCost, ref Percent cornersSharpnessPercent, ref IoPortShapeProto portsShape, ref Electricity baseElectricityCost, ref Percent cornersSharpnessPercent,
ref bool allowMixedProducts, ref bool isBuildable, ref EntityCosts costs, ref RelTile1i lengthPerCost, ref bool allowMixedProducts, ref bool isBuildable, ref EntityCosts costs, ref RelTile1i lengthPerCost,
ref Duration constructionDurationPerProduct, ref Option<TransportProto> nextTier, ref Duration constructionDurationPerProduct, ref Option<TransportProto> nextTier,
ref VirtualProductProto maintenanceProduct, Quantity maintenancePerTile, ref TransportProto.Gfx graphics) { ref VirtualProductProto maintenanceProduct, Quantity maintenancePerTile, ref TransportProto.Gfx graphics) {
if (TransportPillarProto.MAX_PILLAR_HEIGHT.Value < 25) if (TransportPillarProto.MAX_PILLAR_HEIGHT.Value < 25)
typeof(TransportPillarProto).GetField("MAX_PILLAR_HEIGHT").SetValue(null, new ThicknessTilesI(25)); typeof(TransportPillarProto).GetField("MAX_PILLAR_HEIGHT").SetValue(null, new ThicknessTilesI(25));
if (IoPort.MAX_TRANSFER_PER_TICK.Value < 10000) if (IoPort.MAX_TRANSFER_PER_TICK.Value < 10000)
typeof(IoPort).GetField("MAX_TRANSFER_PER_TICK").SetValue(null, new Quantity(10000)); typeof(IoPort).GetField("MAX_TRANSFER_PER_TICK").SetValue(null, new Quantity(10000));
maxQuantityPerTransportedProduct *= 1000; maxQuantityPerTransportedProduct *= 1000;
maxQuantityPerTransportedProduct = maxQuantityPerTransportedProduct.Min(new Quantity(10000)); maxQuantityPerTransportedProduct = maxQuantityPerTransportedProduct.Min(new Quantity(10000));
Console.WriteLine("maxQuantityPerTransportedProduct {0}", maxQuantityPerTransportedProduct); Console.WriteLine("maxQuantityPerTransportedProduct {0}", maxQuantityPerTransportedProduct);
speedPerTick *= 10; speedPerTick *= 10;
transportedProductsSpacing = speedPerTick; transportedProductsSpacing = speedPerTick;
zStepLength = RelTile1i.One; zStepLength = RelTile1i.One;
canBeBuried = true; canBeBuried = true;
maxPillarSupportRadius = new RelTile1i(8); maxPillarSupportRadius = new RelTile1i(8);
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(ShipyardProto), MethodType.Constructor, new[] { [HarmonyPatch(typeof(ShipyardProto), MethodType.Constructor, new[] {
typeof(StaticEntityProto.ID), typeof(StaticEntityProto.ID),
typeof(Proto.Str), typeof(Proto.Str),
typeof(EntityLayout), typeof(EntityLayout),
typeof(EntityCosts), typeof(EntityCosts),
typeof(bool), typeof(bool),
typeof(Quantity), typeof(Quantity),
typeof(Option<ShipyardProto>), typeof(Option<ShipyardProto>),
typeof(ImmutableArray<ImmutableArray<RectangleTerrainArea2iRelative>>), typeof(ImmutableArray<ImmutableArray<RectangleTerrainArea2iRelative>>),
typeof(StackerProto.Gfx), typeof(StackerProto.Gfx),
typeof(ImmutableArray<String>), typeof(ImmutableArray<String>),
typeof(bool), typeof(bool),
})] })]
static void shipyardCargoMultiplier(ShipyardProto __instance) { static void shipyardCargoMultiplier(ShipyardProto __instance) {
Traverse.Create(__instance).Field("CargoCapacity").SetValue(new Quantity( Traverse.Create(__instance).Field("CargoCapacity").SetValue(new Quantity(
(int)(__instance.CargoCapacity.Value * Main.shipyardCargoMultiplier.Value))); (int)(__instance.CargoCapacity.Value * Main.shipyardCargoMultiplier.Value)));
} }
} }
}
[HarmonyPatch(typeof(Excavator), "MineMixedAt")]
public class MineMixedAtPatch {
public static Dictionary<Excavator, Quantity> originalCapacity = new Dictionary<Excavator, Quantity>();
static void Prefix(ref Excavator __instance) {
if (!originalCapacity.ContainsKey(__instance)) {
originalCapacity.Add(__instance, __instance.Prototype.Capacity);
}
var trav = Traverse.Create(__instance.Prototype);
trav.Field("Capacity")
.SetValue(new Quantity(originalCapacity[__instance].Value * Main.excavatorCapacityMultiplier.Value));
Console.WriteLine("IndustrialCyka: Excavator capacity: {0}", __instance.Prototype.Capacity.Value);
}
}
}