From ace4fba19e1fcb6b5cce276e4c94c1ef0af98017 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 28 Sep 2024 21:42:59 +0200 Subject: [PATCH] Add sunset hour offset --- .../InfectionFreeZone/InfectionFreeZone.cs | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs index c605a9a..298d292 100644 --- a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs +++ b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs @@ -6,6 +6,7 @@ using BepInEx; using BepInEx.Configuration; using Controllers; using Controllers.CharacterLogic; +using Controllers.Time; using Controllers.Weather; using GameCustomization; using Gameplay; @@ -34,6 +35,9 @@ using Zenject; // AreaWork // Gameplay.Vehicles.Vehicle.Update() : void @060044A1 // System.Single Gameplay.Units.Movements.Movement::CalculateSpeed() +// GameConfig looks interesting +// See dayLengthInSeconds (defaults to 720 actually) +// System.Single Controllers.Time.TimeController::GetSunsetHour(System.Int32,System.Double,System.Double) namespace InfectionFreeZone { [BepInPlugin(pluginGuid, pluginName, pluginVersion)] @@ -90,6 +94,7 @@ namespace InfectionFreeZone { public static ConfigEntry childToAdultRatioInfluenceCeilingParam; public static ConfigEntry rotationTimestepMultiplier; + public static ConfigEntry sunsetHourOffset; public void Awake() { resourceMultiplierDebug = Config.Bind("General", "Resource Multiplier Debug", false); @@ -152,6 +157,7 @@ namespace InfectionFreeZone { Config.Bind("Birthing Config", "Child to Adult Ratio Influence Ceiling Param", 0f); rotationTimestepMultiplier = Config.Bind("General", "Rotation Timestep Multiplier", 1f); + sunsetHourOffset = Config.Bind("General", "Sunset Hour Offset", 0f); Logger.LogInfo("Cyka mod loaded"); HarmonyFileLog.Enabled = true; @@ -459,8 +465,12 @@ namespace InfectionFreeZone { 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"))); + 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}"); } } @@ -477,13 +487,26 @@ namespace InfectionFreeZone { 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"))); + 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(); } + + [HarmonyPostfix] + [HarmonyPatch(typeof(TimeController), "GetSunsetHour")] + public static void PostfixGetSunsetHour(ref float __result) { + if (Main.sunsetHourOffset.Value <= 0) + return; + + __result += Main.sunsetHourOffset.Value; + } } } \ No newline at end of file