diff --git a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs index fa510aa..c605a9a 100644 --- a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs +++ b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Emit; using BepInEx; using BepInEx.Configuration; using Controllers; @@ -12,6 +13,7 @@ using Gameplay.Buildings; using Gameplay.GameResources; using Gameplay.InGameResources; using Gameplay.Rebuilding; +using Gameplay.Rebuilding.Walls; using Gameplay.Scavenge; using Gameplay.Units.Characters; using Gameplay.Units.Icons; @@ -21,6 +23,7 @@ using Gameplay.Vehicles; using HarmonyLib; using HarmonyLib.Tools; using MapEssentials.Temp; +using UnityEngine; using Zenject; // See: @@ -86,6 +89,8 @@ namespace InfectionFreeZone { public static ConfigEntry childToAdultRatioInfluenceFloorParam; public static ConfigEntry childToAdultRatioInfluenceCeilingParam; + public static ConfigEntry rotationTimestepMultiplier; + public void Awake() { resourceMultiplierDebug = Config.Bind("General", "Resource Multiplier Debug", false); resourceMultiplier = Config.Bind("General", "Resource Multiplier", 1f); @@ -146,6 +151,8 @@ namespace InfectionFreeZone { childToAdultRatioInfluenceCeilingParam = Config.Bind("Birthing Config", "Child to Adult Ratio Influence Ceiling Param", 0f); + rotationTimestepMultiplier = Config.Bind("General", "Rotation Timestep Multiplier", 1f); + Logger.LogInfo("Cyka mod loaded"); HarmonyFileLog.Enabled = true; Harmony harmony = new Harmony(pluginGuid); @@ -289,17 +296,19 @@ namespace InfectionFreeZone { public static void PrefixBuildingDeconstruction(ref BuildingDestruction __instance) { if (Main.deconstructionWorkersPer100m.Value <= 0) return; - + var trav = Traverse.Create(__instance); var config = trav.Field("_deconstructionConfig"); var configV = config.Value; if (Main.buildingDeconstructionResourcesMultiplierDebug.Value) - Console.WriteLine($"Building deconstruction workers per 100m is {configV.deconstructWorkersPer100m3OfBuilding}"); - + Console.WriteLine( + $"Building deconstruction workers per 100m is {configV.deconstructWorkersPer100m3OfBuilding}"); + configV.deconstructWorkersPer100m3OfBuilding = Main.deconstructionWorkersPer100m.Value; config.Value = configV; if (Main.buildingDeconstructionResourcesMultiplierDebug.Value) - Console.WriteLine($"Building deconstruction workers per 100m modified to {configV.deconstructWorkersPer100m3OfBuilding}"); + Console.WriteLine( + $"Building deconstruction workers per 100m modified to {configV.deconstructWorkersPer100m3OfBuilding}"); } [HarmonyPostfix] @@ -440,5 +449,41 @@ namespace InfectionFreeZone { charactersConfigV.bornConfig = bornConfig; charactersConfig.Value = charactersConfigV; } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(PlaceableObject), "RotateRight")] + public static IEnumerable PostfixRotateRight(IEnumerable instructions) { + var codes = new List(instructions); + for (var i = 0; i < codes.Count; i++) { + var code = codes[i]; + Console.WriteLine($"Opcode is {code.opcode}"); + if (code.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)code.operand, 100f)) { + Console.WriteLine($"Operand is {code.operand}"); + codes[i] = new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "rotationTimestepMultiplier")); + codes.Insert(i+1, new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(Main).GetField("rotationTimestepMultiplier").FieldType, "Value"))); + Console.WriteLine($"Operand modified to {codes[i].operand}"); + } + } + + return codes.AsEnumerable(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(PlaceableObject), "RotateLeft")] + public static IEnumerable PostfixRotateLeft(IEnumerable instructions) { + var codes = new List(instructions); + for (var i = 0; i < codes.Count; i++) { + var code = codes[i]; + Console.WriteLine($"Opcode is {code.opcode}"); + if (code.opcode == OpCodes.Ldc_R4 && Mathf.Approximately((float)code.operand, 100f)) { + Console.WriteLine($"Operand is {code.operand}"); + codes[i] = new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "rotationTimestepMultiplier")); + codes.Insert(i+1, new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(Main).GetField("rotationTimestepMultiplier").FieldType, "Value"))); + Console.WriteLine($"Operand modified to {codes[i].operand}"); + } + } + + return codes.AsEnumerable(); + } } } \ No newline at end of file