Increase levels per upgrade for world mines
This commit is contained in:
@@ -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<float> unityGenerationMultiplier;
|
||||
public static ConfigEntry<float> depotTransferSpeedMultiplier;
|
||||
public static ConfigEntry<float> worldMineSpeedMultiplier;
|
||||
public static ConfigEntry<float> 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();
|
||||
|
@@ -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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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 <Stdfld someField> 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<int, EntityCosts>),
|
||||
typeof(int),
|
||||
typeof(Quantity),
|
||||
typeof(WorldMapEntityProto.Gfx),
|
||||
typeof(int),
|
||||
typeof(int),
|
||||
typeof(IEnumerable<Tag>),
|
||||
})]
|
||||
static void worldMineLevelIncrementMultiplier(WorldMapMineProto __instance) {
|
||||
Traverse traverse = Traverse.Create(__instance);
|
||||
|
||||
// int level = traverse.Field("Level").GetValue<int>();
|
||||
int maxLevel = traverse.Field("MaxLevel").GetValue<int>();
|
||||
// int levelsPerUpgrade = traverse.Field("LevelsPerUpgrade").GetValue<int>();
|
||||
|
||||
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<int, EntityCosts>),
|
||||
typeof(int),
|
||||
typeof(Quantity),
|
||||
typeof(WorldMapEntityProto.Gfx),
|
||||
typeof(int),
|
||||
typeof(int),
|
||||
typeof(IEnumerable<Tag>),
|
||||
})]
|
||||
static IEnumerable<CodeInstruction> cookWorldMineLevelIncrementMultiplier(
|
||||
IEnumerable<CodeInstruction> instructions) {
|
||||
Dictionary<int, OpCode> matchTable = new Dictionary<int, OpCode>();
|
||||
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<CodeInstruction>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user