diff --git a/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs b/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs index 0ccf5be..692e2c2 100644 --- a/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs +++ b/Projects/CaptainOfIndustry/CaptainOfIndustry/Class1.cs @@ -1,5 +1,4 @@ -using System.Linq; -using BepInEx; +using BepInEx; using BepInEx.Configuration; using HarmonyLib; using HarmonyLib.Tools; @@ -22,6 +21,7 @@ namespace CaptainOfIndustry { public static ConfigEntry unityGenerationMultiplier; public static ConfigEntry depotTransferSpeedMultiplier; public static ConfigEntry worldMineSpeedMultiplier; + public static ConfigEntry worldMineLevelIncrementMultiplier; public void Awake() { excavatorCapacityMultiplier = Config.Bind("General", "Excavator Capacity Multiplier", 1, new ConfigDescription("Excavator Capacity Multiplier")); @@ -33,6 +33,7 @@ namespace CaptainOfIndustry { unityGenerationMultiplier = Config.Bind("General", "Unity Generation Multiplier", 1f, new ConfigDescription("Unity Generation Multiplier")); depotTransferSpeedMultiplier = Config.Bind("General", "Depot Transfer Speed Multiplier", 1f, new ConfigDescription("Depot Transfer Speed Multiplier")); worldMineSpeedMultiplier = Config.Bind("General", "World Mine Speed Multiplier", 1f, new ConfigDescription("World Mine Speed Multiplier")); + worldMineLevelIncrementMultiplier = Config.Bind("General", "World Mine Level Increment Multiplier", 1f, new ConfigDescription("World Mine Level Increment 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 b8d6938..c3a5bdf 100644 --- a/Projects/CaptainOfIndustry/CaptainOfIndustry/Patches.cs +++ b/Projects/CaptainOfIndustry/CaptainOfIndustry/Patches.cs @@ -1,12 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Reflection.Emit; using HarmonyLib; using Mafi; using Mafi.Core; -using Mafi.Core.Buildings.Cargo; using Mafi.Core.Buildings.Cargo.Modules; using Mafi.Core.Buildings.Cargo.Ships.Modules; using Mafi.Core.Buildings.Storages; @@ -15,7 +13,6 @@ using Mafi.Core.Entities.Dynamic; using Mafi.Core.Entities.Static; using Mafi.Core.Entities.Static.Layout; using Mafi.Core.Factory.Machines; -using Mafi.Core.Map; using Mafi.Core.Population; using Mafi.Core.Products; using Mafi.Core.Prototypes; @@ -172,22 +169,6 @@ namespace CaptainOfIndustry { return codes.AsEnumerable(); } - // static IEnumerable Transpiler(IEnumerable instructions) - // { - // var found = false; - // foreach (var instruction in instructions) - // { - // if (instruction.StoresField(f_someField)) - // { - // yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); - // found = true; - // } - // yield return instruction; - // } - // if (found is false) - // ReportError("Cannot find in OriginalType.OriginalMethod"); - // } - // Could not make this work either... idk why... Doesn't make sense... // [HarmonyPostfix] // [HarmonyPatch(typeof(SimpleVirtualResource), "MineResourceAt")] @@ -269,5 +250,92 @@ namespace CaptainOfIndustry { .SetValue(newProductQuantity); // Console.WriteLine("After: {0}", __instance.ProducedProductPerStep.Quantity.Value); } + + [HarmonyPostfix] + [HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor, + new[] { + typeof(EntityProto.ID), + typeof(Proto.Str), + typeof(ProductQuantity), + typeof(Duration), + typeof(Upoints), + typeof(UpointsCategoryProto), + typeof(EntityCosts), + typeof(Func), + typeof(int), + typeof(Quantity), + typeof(WorldMapEntityProto.Gfx), + typeof(int), + typeof(int), + typeof(IEnumerable), + })] + static void worldMineLevelIncrementMultiplier(WorldMapMineProto __instance) { + Traverse traverse = Traverse.Create(__instance); + + // int level = traverse.Field("Level").GetValue(); + int maxLevel = traverse.Field("MaxLevel").GetValue(); + // int levelsPerUpgrade = traverse.Field("LevelsPerUpgrade").GetValue(); + + int newLevelsPerUpgrade = 10; + int newMaxLevel = (int)Math.Ceiling((double)maxLevel / newLevelsPerUpgrade) * newLevelsPerUpgrade; + + // Console.WriteLine("Level: {0}, MaxLevel: {1}, LevelsPerUpgrade: {2}", level, maxLevel, levelsPerUpgrade); + // Console.WriteLine("NewMaxLevel: {0}", newMaxLevel); + + traverse.Field("MaxLevel").SetValue(newMaxLevel); + traverse.Field("LevelsPerUpgrade").SetValue(newLevelsPerUpgrade); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(WorldMapMineProto), MethodType.Constructor, + new[] { + typeof(EntityProto.ID), + typeof(Proto.Str), + typeof(ProductQuantity), + typeof(Duration), + typeof(Upoints), + typeof(UpointsCategoryProto), + typeof(EntityCosts), + typeof(Func), + typeof(int), + typeof(Quantity), + typeof(WorldMapEntityProto.Gfx), + typeof(int), + typeof(int), + typeof(IEnumerable), + })] + static IEnumerable cookWorldMineLevelIncrementMultiplier( + IEnumerable instructions) { + Dictionary matchTable = new Dictionary(); + matchTable[0] = OpCodes.Rem; + matchTable[1] = OpCodes.Ldfld; + matchTable[2] = OpCodes.Ldarg_0; + matchTable[3] = OpCodes.Ldfld; + matchTable[4] = OpCodes.Ldarg_0; + int matches = 0; + int totalMatch = matchTable.Count; + + var codes = new List(instructions); + for (int i = codes.Count - 1; i >= 0; i--) { + if (matches >= totalMatch) { + break; + } + + if (codes[i].opcode.Equals(matchTable[matches])) { + if (matches == totalMatch - 1) { + codes[i + 4].opcode = OpCodes.Add; + codes[i + 5].opcode = OpCodes.Brtrue_S; + break; + } + + matches++; + } + else { + matches = 0; + } + } + + return codes.AsEnumerable(); + } } }