Add sunset hour offset

This commit is contained in:
2024-09-28 21:42:59 +02:00
parent 1904f12d6c
commit ace4fba19e

View File

@@ -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<float> childToAdultRatioInfluenceCeilingParam;
public static ConfigEntry<float> rotationTimestepMultiplier;
public static ConfigEntry<float> 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;
}
}
}