From c1f259d0d5fe6aed0d4b187d7713112300db102c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Wed, 17 Apr 2024 15:07:38 +0200 Subject: [PATCH] Code format and add storage multiplier --- .../CaptainOfIndustry/Class1.cs | 2 + .../CaptainOfIndustry/Patches.cs | 50 +++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs b/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs index 25b6756..8ebbd7f 100644 --- a/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs +++ b/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs @@ -19,6 +19,7 @@ namespace CaptainOfIndustry { public static ConfigEntry cargoShipCapacityMultiplier; public static ConfigEntry excavatorMiningAreaMultiplier; public static ConfigEntry vehicleSpeedMultiplier; + public static ConfigEntry storageCapacityMultiplier; public void Awake() { excavatorCapacityMultiplier = Config.Bind("General", "Excavator Capacity Multiplier", 1, new ConfigDescription("Excavator Capacity Multiplier")); @@ -26,6 +27,7 @@ namespace CaptainOfIndustry { cargoShipCapacityMultiplier = Config.Bind("General", "Cargo Ship Capacity Multiplier", 1, new ConfigDescription("Cargo Ship Capacity Multiplier")); excavatorMiningAreaMultiplier = Config.Bind("General", "Excavator Mining Area Multiplier", 1f, new ConfigDescription("Excavator Mining Area Multiplier")); vehicleSpeedMultiplier = Config.Bind("General", "Vehicle Speed Multiplier", 1f, new ConfigDescription("Vehicle Speed Multiplier")); + storageCapacityMultiplier = Config.Bind("General", "Storage Capacity Multiplier", 1f, new ConfigDescription("Storage Capacity Multiplier")); // shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch(); // energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch(); diff --git a/Projects/CaptainOfIndustry/CaptainOfIndustry/Patches.cs b/Projects/CaptainOfIndustry/CaptainOfIndustry/Patches.cs index e3d27b1..2dd44df 100644 --- a/Projects/CaptainOfIndustry/CaptainOfIndustry/Patches.cs +++ b/Projects/CaptainOfIndustry/CaptainOfIndustry/Patches.cs @@ -1,9 +1,13 @@ using System; +using System.Collections.Generic; using System.Reflection; using HarmonyLib; using Mafi; using Mafi.Core.Buildings.Cargo.Ships.Modules; +using Mafi.Core.Buildings.Storages; using Mafi.Core.Entities.Dynamic; +using Mafi.Core.Entities.Static; +using Mafi.Core.Entities.Static.Layout; using Mafi.Core.Map; using Mafi.Core.Products; using Mafi.Core.Prototypes; @@ -29,6 +33,14 @@ namespace CaptainOfIndustry { Console.WriteLine("IndustrialCyka: New truck capacity: {0}", quantity); } + // [HarmonyPrefix] + // [HarmonyPatch(typeof(StorageProtoBuilder.State), "SetCapacity")] + // static void storageCapacityMultiplier(ref int capacity) { + // Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", capacity); + // capacity = (int)(capacity * Main.storageCapacityMultiplier.Value); + // Console.WriteLine("IndustrialCyka: New storage capacity: {0}", capacity); + // } + [HarmonyPostfix] [HarmonyPatch(typeof(CargoShipModuleProto), MethodType.Constructor, new[] { @@ -74,13 +86,41 @@ namespace CaptainOfIndustry { Traverse maxBackwardsSpeedField = traverse.Field("m_maxBackwardsSpeed"); Traverse maxAccelerationField = traverse.Field("m_maxAcceleration"); - Console.WriteLine("IndustrialCyka: Old speeds: (F) {0}, (B) {1}, (A) {2}", maxForwardsSpeedField.GetValue(), maxBackwardsSpeedField.GetValue(), maxAccelerationField.GetValue()); + Console.WriteLine("IndustrialCyka: Old speeds: (F) {0}, (B) {1}, (A) {2}", maxForwardsSpeedField.GetValue(), + maxBackwardsSpeedField.GetValue(), maxAccelerationField.GetValue()); - maxForwardsSpeedField.SetValue((Fix32) maxForwardsSpeedField.GetValue() * speedMulti); - maxBackwardsSpeedField.SetValue((Fix32) maxBackwardsSpeedField.GetValue() * speedMulti); - maxAccelerationField.SetValue((Fix32) maxAccelerationField.GetValue() * speedMulti); + maxForwardsSpeedField.SetValue((Fix32)maxForwardsSpeedField.GetValue() * speedMulti); + maxBackwardsSpeedField.SetValue((Fix32)maxBackwardsSpeedField.GetValue() * speedMulti); + maxAccelerationField.SetValue((Fix32)maxAccelerationField.GetValue() * speedMulti); - Console.WriteLine("IndustrialCyka: New speeds: (F) {0}, (B) {1}, (A) {2}", maxForwardsSpeedField.GetValue(), maxBackwardsSpeedField.GetValue(), maxAccelerationField.GetValue()); + Console.WriteLine("IndustrialCyka: New speeds: (F) {0}, (B) {1}, (A) {2}", maxForwardsSpeedField.GetValue(), + maxBackwardsSpeedField.GetValue(), maxAccelerationField.GetValue()); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(StorageBaseProto), MethodType.Constructor, + new[] { + typeof(StaticEntityProto.ID), + typeof(Proto.Str), + typeof(EntityLayout), + typeof(Quantity), + typeof(EntityCosts), + typeof(LayoutEntityProto.Gfx), + typeof(Quantity), + typeof(Duration), + typeof(IEnumerable) + })] + static void storageCapacityMultiplier(StorageProto __instance) { + Console.WriteLine("IndustrialCyka: Old storage capacity: {0}", __instance.Capacity.Value); + Console.WriteLine("IndustrialCyka: Old storage transfer limit: {0}", __instance.TransferLimit.Value); + Traverse traverse = Traverse.Create(__instance); + + traverse.Field("Capacity").SetValue(new Quantity((int)(__instance.Capacity.Value * Main.storageCapacityMultiplier.Value))); + traverse.Field("TransferLimit").SetValue(new Quantity(10000)); + traverse.Field("TransferLimitDuration").SetValue(Duration.FromTicks(1)); + + Console.WriteLine("IndustrialCyka: New storage capacity: {0}", __instance.Capacity.Value); + Console.WriteLine("IndustrialCyka: New storage transfer limit: {0}", __instance.TransferLimit.Value); } // Could not make this work either... idk why... Doesn't make sense...