Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of EndlessDays v1.5.0
plugins/EndlessDays/EndlessDays.dll
Decompiled a month agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("EndlessDays")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.5.0.0")] [assembly: AssemblyInformationalVersion("1.5.0")] [assembly: AssemblyProduct("EndlessDays")] [assembly: AssemblyTitle("EndlessDays")] [assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was created with the assistance of generative AI (code); see the README credits for which assets.")] [assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")] [assembly: AssemblyVersion("1.5.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EndlessDays { internal static class ClockDisplay { private const int DayStartMinutes = 360; private const int MinutesInADay = 1440; internal static bool SetClockPrefix(object __instance, float timeNormalized, float numberOfHours, bool createNewLine) { if (!DayLoop.ShowsTrueClock || GameAccess.ClockNumber == null) { return true; } try { object value = GameAccess.ClockNumber.GetValue(__instance); PropertyInfo propertyInfo = value?.GetType().GetProperty("text"); if (propertyInfo == null) { return true; } propertyInfo.SetValue(value, Format(timeNormalized, numberOfHours, createNewLine)); return false; } catch (Exception ex) { Plugin.Logger.LogDebug((object)("Clock text failed: " + ex.Message)); return true; } } internal static bool GetClockTimeFormattedPrefix(float timeNormalized, float numberOfHours, bool createNewLine, ref string __result) { if (!DayLoop.ShowsTrueClock) { return true; } __result = Format(timeNormalized, numberOfHours, createNewLine); return false; } private static string Format(float timeNormalized, float numberOfHours, bool createNewLine) { int num = ((int)((timeNormalized * numberOfHours + (float)DayLoop.ShiftHours) * 60f) + 360) % 1440; if (num < 0) { num += 1440; } int num2 = num / 60; int num3 = ((num2 % 12 == 0) ? 12 : (num2 % 12)); string text = (createNewLine ? "\n" : " ") + ((num2 < 12) ? "AM" : "PM"); return $"{num3}:{num % 60:00}" + text; } } internal static class ClockSync { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnClock; } private const string ClockMessage = "EndlessDays.Clock"; private static CustomMessagingManager? registeredOn; internal static void Register() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; CustomMessagingManager val = (((Object)(object)singleton != (Object)null && singleton.IsListening) ? singleton.CustomMessagingManager : null); if (val != null && val != registeredOn) { object obj = <>O.<0>__OnClock; if (obj == null) { HandleNamedMessageDelegate val2 = OnClock; <>O.<0>__OnClock = val2; obj = (object)val2; } val.RegisterNamedMessageHandler("EndlessDays.Clock", (HandleNamedMessageDelegate)obj); registeredOn = val; } } internal unsafe static void Send(int shiftHours, int day) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsServer || singleton.CustomMessagingManager == null) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref shiftHours, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref day, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessageToAll("EndlessDays.Clock", val, (NetworkDelivery)2); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } private static void OnClock(ulong sender, FastBufferReader reader) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && !singleton.IsServer && sender == 0L) { int hostShiftHours = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref hostShiftHours, default(ForPrimitives)); int hostDay = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref hostDay, default(ForPrimitives)); DayLoop.HostClockReceived(hostShiftHours, hostDay); } } } internal sealed class PluginConfig { internal readonly ConfigEntry<bool> Enabled; internal readonly ConfigEntry<bool> FreshSpawnsEachMorning; internal readonly ConfigEntry<bool> WipeMonstersEachMorning; internal readonly ConfigEntry<bool> ShowNewDayMessage; internal readonly ConfigEntry<bool> OneJobPerLanding; internal PluginConfig(ConfigFile cfg) { Enabled = cfg.Bind<bool>("General", "Enabled", true, "Turn the endless day on or off. The host's setting decides for the whole lobby."); FreshSpawnsEachMorning = cfg.Bind<bool>("General", "FreshSpawnsEachMorning", true, "At 6 AM a new day of monster spawning starts on top of the monsters still alive, so they pile up the longer you stay (host only). Off: once the moon's monster limit is full, new monsters only come when others die."); WipeMonstersEachMorning = cfg.Bind<bool>("General", "WipeMonstersEachMorning", false, "At 6 AM, despawn every living monster and start monster spawning over, like a fresh landing (host only). Off: monsters carry over and spawn exactly as the game decides."); ShowNewDayMessage = cfg.Bind<bool>("General", "ShowNewDayMessage", true, "Show a popup when a new day starts at midnight."); OneJobPerLanding = cfg.Bind<bool>("General", "OneJobPerLanding", true, "However long you stay on a moon, the quota deadline goes down by one job when you leave, like a normal landing, and the deadline screens and warnings say jobs instead of days. Off: the deadline runs down with the clock, so a long stay can use up several days. The host's setting decides the deadline; the wording follows each player's own."); ClearUnusedEntries(cfg); } private static void ClearUnusedEntries(ConfigFile cfg) { if (((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(cfg, null) is Dictionary<ConfigDefinition, string> { Count: not 0 } dictionary) { dictionary.Clear(); cfg.Save(); } } } internal static class DayLoop { private const int DefaultNumberOfHours = 18; private const int HoursInADay = 24; private const float StepBeforeMidnightHours = 0.25f; private const int DefaultWaveGapHours = 2; private const float StepToleranceHours = 0.25f; private const int FailedStepsBeforePause = 2; private const float SlopeSampleSeconds = 10f; private const double SyncEverySeconds = 5.0; private const float ClientJumpHours = 0.5f; private const double PendingShiftSeconds = 3.0; private static bool onMoon; private static bool isHost; private static int numberOfHours; private static float lengthOfHours; private static int waveGapHours; private static int shiftHours; private static int day; private static float lastTrueHours; private static bool paused; private static int failedSteps; private static float expectedGameHours = -1f; private static float leaveTimeOnLanding; private static float pendingSkipHours = -1f; private static DateTime nextSyncUtc = DateTime.MinValue; private static bool syncBroken; private static bool hostKnown; private static int pendingShiftHours = -1; private static DateTime pendingSinceUtc; private static float lastClientGameHours; private static bool loggedUpdateError; internal static bool ShowsTrueClock { get { if (onMoon) { if (!isHost) { return hostKnown; } return true; } return false; } } internal static bool Active { get { if (onMoon && !paused) { if (!isHost) { return hostKnown; } return true; } return false; } } internal static int ShiftHours => shiftHours; internal static float LeaveTimeOnLanding => leaveTimeOnLanding; private static int CycleHours => Math.Max(24, numberOfHours + waveGapHours); private static float StepHour => (float)numberOfHours - 0.25f; internal static void TimeOfDayUpdatePostfix(object __instance) { if (__instance == null) { return; } RegisterSync(); try { object value = GameAccess.StartOfRoundInstance.GetValue(null, null); if (value == null) { return; } if (!OnTimedMoon(value)) { if (onMoon && !(bool)GameAccess.ShipHasLanded.GetValue(value)) { LeaveMoon(); } return; } float num = (float)GameAccess.TotalTime.GetValue(__instance); if (num <= 0f) { return; } bool flag = (bool)GameAccess.IsServer.GetValue(__instance, null); if (!flag || Plugin.BoundConfig.Enabled.Value) { object value2 = GameAccess.CurrentLevel.GetValue(value); if (!onMoon) { EnterMoon(__instance, flag, num); } if (isHost) { HostTick(__instance, value2); } else { ClientTick(__instance); } Deadline.Hold(__instance); if (ShowsTrueClock) { SkyCycle.Apply(__instance, GameHours(__instance) + (float)shiftHours, StepHour, CycleHours); } else { SkyCycle.Clear(); } } } catch (Exception ex) { if (!loggedUpdateError) { loggedUpdateError = true; Plugin.Logger.LogError((object)("Day cycle error: " + ex)); } } } private static bool OnTimedMoon(object round) { if (!(bool)GameAccess.ShipHasLanded.GetValue(round) || (bool)GameAccess.ShipIsLeaving.GetValue(round)) { return false; } if (GameAccess.InShipPhase != null && (bool)GameAccess.InShipPhase.GetValue(round)) { return false; } object value = GameAccess.CurrentLevel.GetValue(round); if (value != null) { if (!(GameAccess.PlanetHasTime == null)) { return (bool)GameAccess.PlanetHasTime.GetValue(value); } return true; } return false; } private static void EnterMoon(object tod, bool server, float total) { onMoon = true; isHost = server; numberOfHours = 18; if (GameAccess.NumberOfHours != null) { int num = (int)GameAccess.NumberOfHours.GetValue(tod); if (num > 0 && num <= 24) { numberOfHours = num; } } lengthOfHours = total / (float)numberOfHours; object obj = GameAccess.RoundManagerInstance?.GetValue(null, null); waveGapHours = ((obj != null && GameAccess.HoursBetweenSpawnWaves != null) ? Math.Max(1, (int)GameAccess.HoursBetweenSpawnWaves.GetValue(obj)) : 2); if (server || !hostKnown) { shiftHours = 0; day = 1; } lastTrueHours = GameHours(tod) + (float)shiftHours; lastClientGameHours = GameHours(tod); pendingShiftHours = -1; paused = false; failedSteps = 0; expectedGameHours = -1f; leaveTimeOnLanding = ((GameAccess.ShipLeaveAutomaticallyTime != null) ? ((float)GameAccess.ShipLeaveAutomaticallyTime.GetValue(tod)) : float.MaxValue); pendingSkipHours = -1f; nextSyncUtc = DateTime.MinValue; Deadline.StartStay(tod); } private static void LeaveMoon() { onMoon = false; SkyCycle.Clear(); hostKnown = false; pendingSkipHours = -1f; } private static void HostTick(object tod, object? level) { float num = GameHours(tod); CheckLastStep(tod, num); float num2 = num + (float)shiftHours; CheckMidnight(lastTrueHours, num2); if (!paused) { if (num2 >= (float)CycleHours) { StepBack(tod, level, CycleHours - shiftHours); shiftHours = 0; num2 -= (float)CycleHours; Plugin.Logger.LogInfo((object)$"Morning of day {day} on this moon."); if (Plugin.BoundConfig.WipeMonstersEachMorning.Value) { MonsterReset.Wipe(); } else if (Plugin.BoundConfig.FreshSpawnsEachMorning.Value) { MonsterReset.FreshBudget(); } } else { int num3 = ShiftFor(num2); if (num3 > shiftHours) { StepBack(tod, level, num3 - shiftHours); shiftHours = num3; } } if (pendingSkipHours >= 0f) { float target = pendingSkipHours; pendingSkipHours = -1f; float fromTrueHours = num2; JumpForward(tod, level, num2, target); num2 = GameHours(tod) + (float)shiftHours; CheckMidnight(fromTrueHours, num2); } } lastTrueHours = num2; if (DateTime.UtcNow >= nextSyncUtc) { SendClock(); } } private static int ShiftFor(float trueHours) { if (trueHours < StepHour) { return 0; } return waveGapHours * ((int)Math.Floor((trueHours - StepHour) / (float)waveGapHours) + 1); } private static float GameHours(object tod) { return (float)GameAccess.CurrentDayTime.GetValue(tod) / lengthOfHours; } private static void CheckLastStep(object tod, float gameHours) { if (expectedGameHours < 0f) { return; } float num = expectedGameHours; expectedGameHours = -1f; if (gameHours <= num + 0.25f) { failedSteps = 0; return; } Plugin.Logger.LogWarning((object)"The clock did not move back."); if (++failedSteps >= 2) { paused = true; Plugin.Logger.LogError((object)"The clock won't move back; the ship leaves at midnight on this moon."); } } internal static void HideWarningPrefix(object __instance, out bool __state) { __state = Active && !(bool)GameAccess.ShipLeavingAlertCalled.GetValue(__instance); if (__state) { GameAccess.ShipLeavingAlertCalled.SetValue(__instance, true); } } internal static void HideWarningPostfix(object __instance, bool __state) { if (__state) { GameAccess.ShipLeavingAlertCalled.SetValue(__instance, false); } } private static void StepBack(object tod, object? level, int hours) { if (hours > 0) { float num = GameHours(tod); if (MoveClock(tod, level, (float)(-hours) * lengthOfHours)) { SpawnPlan.ShiftBack(hours, lengthOfHours); } expectedGameHours = num - (float)hours; nextSyncUtc = DateTime.MinValue; } } private static void JumpForward(object tod, object? level, float trueHours, float target) { if (target <= trueHours) { pendingSkipHours = target; target = CycleHours; } int num = Math.Min(ShiftFor(target), ShiftFor((float)CycleHours - 0.01f)); if (num > shiftHours) { StepBack(tod, level, num - shiftHours); shiftHours = num; trueHours = GameHours(tod) + (float)shiftHours; } MoveClock(tod, level, (target - trueHours) * lengthOfHours); expectedGameHours = -1f; } private static bool MoveClock(object tod, object? level, float planetSeconds) { try { float num = MeasureSlope(tod, level); if (num <= 0f) { return false; } float num2 = (float)GameAccess.GlobalTime.GetValue(tod); GameAccess.GlobalTime.SetValue(tod, num2 + planetSeconds / num); float num3 = (float)GameAccess.CalculatePlanetTime.Invoke(tod, new object[1] { level }); float num4 = (float)GameAccess.TotalTime.GetValue(tod); GameAccess.CurrentDayTime.SetValue(tod, num3); GameAccess.NormalizedTime?.SetValue(tod, num3 / num4); GameAccess.Hour?.SetValue(tod, (int)(num3 / lengthOfHours)); GameAccess.NextTimeSync?.SetValue(tod, 0f); return true; } catch (Exception ex) { Plugin.Logger.LogWarning((object)("Moving the clock failed: " + ex.Message)); return false; } } private static float MeasureSlope(object tod, object? level) { if (level == null) { return -1f; } object[] parameters = new object[1] { level }; float num = (float)GameAccess.GlobalTime.GetValue(tod); float num2 = (float)GameAccess.CalculatePlanetTime.Invoke(tod, parameters); GameAccess.GlobalTime.SetValue(tod, num + 10f); float num3 = (float)GameAccess.CalculatePlanetTime.Invoke(tod, parameters); GameAccess.GlobalTime.SetValue(tod, num); float num4 = (num3 - num2) / 10f; if (!(num4 > 0.0001f)) { return -1f; } return num4; } private static void CheckMidnight(float fromTrueHours, float toTrueHours) { if (fromTrueHours < (float)numberOfHours && toTrueHours >= (float)numberOfHours) { StartNewDay(); } } private static void StartNewDay() { day++; Plugin.Logger.LogInfo((object)$"Midnight: day {day} on this moon."); ShowNewDay(day); nextSyncUtc = DateTime.MinValue; } private static void RegisterSync() { if (syncBroken) { return; } try { ClockSync.Register(); } catch (Exception ex) { syncBroken = true; Plugin.Logger.LogWarning((object)("Could not listen for the host's clock: " + ex.Message)); } } private static void SendClock() { nextSyncUtc = DateTime.UtcNow.AddSeconds(5.0); if (syncBroken) { return; } try { ClockSync.Send(shiftHours, day); } catch (Exception ex) { syncBroken = true; Plugin.Logger.LogWarning((object)("Could not send the clock to other players: " + ex.Message)); } } internal static void SkipTo(float hoursAfterSix) { if (!onMoon || !isHost || paused) { NewDayPopup.Tip("Endless Days", "Only the host can skip time, on a moon."); } else { pendingSkipHours = hoursAfterSix; } } internal static void HostClockReceived(int hostShiftHours, int hostDay) { if (!isHost) { bool num = hostKnown && hostDay > day; day = hostDay; if (!hostKnown) { shiftHours = hostShiftHours; hostKnown = true; } else if (hostShiftHours != shiftHours) { pendingShiftHours = hostShiftHours; pendingSinceUtc = DateTime.UtcNow; } else { pendingShiftHours = -1; } if (num) { ShowNewDay(day); } } } private static void ClientTick(object tod) { float num = GameHours(tod); float num2 = lastClientGameHours - num; lastClientGameHours = num; if (hostKnown) { if (num2 > 0.5f) { shiftHours = ((pendingShiftHours >= 0) ? pendingShiftHours : ((shiftHours + (int)Math.Round(num2)) % CycleHours)); pendingShiftHours = -1; } else if (pendingShiftHours >= 0 && (DateTime.UtcNow - pendingSinceUtc).TotalSeconds > 3.0) { shiftHours = pendingShiftHours; pendingShiftHours = -1; } } } private static void ShowNewDay(int newDay) { if (Plugin.BoundConfig.ShowNewDayMessage.Value) { NewDayPopup.Show(newDay); } } } internal static class Deadline { private static bool holding; private static float afterThisJob; private const string HaltDays = "0 days left to meet the quota"; internal static void StartStay(object tod) { holding = false; if (Plugin.BoundConfig.OneJobPerLanding.Value && GameAccess.CanHoldDeadline) { float num = (float)GameAccess.TimeUntilDeadline.GetValue(tod); float val = (float)GameAccess.GlobalTimeAtEndOfDay.GetValue(tod) - (float)GameAccess.GlobalTime.GetValue(tod); afterThisJob = num - Math.Max(0f, val); holding = true; } } internal static void Hold(object tod) { if (holding && DayLoop.Active && (float)GameAccess.TimeUntilDeadline.GetValue(tod) < afterThisJob) { GameAccess.TimeUntilDeadline.SetValue(tod, afterThisJob); } } internal static void PassTimeToNextDayPrefix() { if (holding) { holding = false; object obj = GameAccess.TimeOfDayInstance?.GetValue(null, null); if (obj != null) { float val = (float)GameAccess.GlobalTimeAtEndOfDay.GetValue(obj) - (float)GameAccess.GlobalTime.GetValue(obj); GameAccess.TimeUntilDeadline.SetValue(obj, afterThisJob + Math.Max(0f, val)); } } } internal static void MonitorPostfix() { if (Plugin.BoundConfig.OneJobPerLanding.Value) { object value = GameAccess.StartOfRoundInstance.GetValue(null, null); string text = GameAccess.GetText(value, GameAccess.DeadlineMonitorText); if (text != null && text.EndsWith(" Days", StringComparison.Ordinal)) { GameAccess.SetText(value, GameAccess.DeadlineMonitorText, text.Substring(0, text.Length - 4) + "Jobs"); } } } internal static void HaltTipPrefix(ref string bodyText) { if (Plugin.BoundConfig.OneJobPerLanding.Value && bodyText != null && bodyText.Contains("0 days left to meet the quota")) { bodyText = bodyText.Replace("0 days left to meet the quota", "0 jobs left to meet the quota"); } } internal static void DaysLeftPostfix() { if (!Plugin.BoundConfig.OneJobPerLanding.Value) { return; } object owner = GameAccess.HudInstance?.GetValue(null, null); FieldInfo[] daysLeftTexts = GameAccess.DaysLeftTexts; foreach (FieldInfo field in daysLeftTexts) { string text = GameAccess.GetText(owner, field); if (text != null) { GameAccess.SetText(owner, field, text.Replace("Days Left", "Jobs Left").Replace("Day Left", "Job Left")); } } } } internal static class GameAccess { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; internal static MethodInfo TimeOfDayUpdate = null; internal static PropertyInfo? TimeOfDayInstance; internal static FieldInfo CurrentDayTime = null; internal static FieldInfo TotalTime = null; internal static FieldInfo GlobalTime = null; internal static MethodInfo CalculatePlanetTime = null; internal static PropertyInfo IsServer = null; internal static FieldInfo? NormalizedTime; internal static FieldInfo? Hour; internal static FieldInfo? NumberOfHours; internal static FieldInfo? LengthOfHours; internal static FieldInfo? NextTimeSync; internal static FieldInfo? ShipLeaveAutomaticallyTime; internal static MethodInfo? SetShipLeaveEarlyClientRpc; internal static FieldInfo? ShipLeavingAlertCalled; internal static MethodInfo? TimeOfDayEvents; internal static FieldInfo? ShipLeavingEarlyDialogue; internal static FieldInfo? TimeUntilDeadline; internal static FieldInfo? GlobalTimeAtEndOfDay; internal static MethodInfo? UpdateProfitQuotaCurrentTime; internal static MethodInfo? PassTimeToNextDay; internal static FieldInfo? DeadlineMonitorText; internal static FieldInfo? SunAnimator; internal static FieldInfo? SunDirect; internal static FieldInfo? SunIndirect; internal static PropertyInfo StartOfRoundInstance = null; internal static FieldInfo ShipHasLanded = null; internal static FieldInfo ShipIsLeaving = null; internal static FieldInfo CurrentLevel = null; internal static FieldInfo? InShipPhase; internal static FieldInfo? PlanetHasTime; internal static PropertyInfo? RoundManagerInstance; internal static FieldInfo? CurrentHour; internal static FieldInfo? HoursBetweenSpawnWaves; internal static FieldInfo? EnemySpawnTimes; internal static FieldInfo? CurrentEnemySpawnIndex; internal static FieldInfo? AllEnemyVents; internal static FieldInfo? VentSpawnTime; internal static FieldInfo? VentOccupied; internal static FieldInfo? VentEnemyTypeIndex; internal static MethodInfo? SyncVentSpawnTime; internal static FieldInfo? SpawnedEnemies; internal static MethodInfo? DespawnEnemyOnServer; internal static FieldInfo? IsEnemyDead; internal static PropertyInfo? EnemyNetworkObject; internal static readonly List<KeyValuePair<FieldInfo, object>> SpawnBudgetResets = new List<KeyValuePair<FieldInfo, object>>(); internal static PropertyInfo? HudInstance; internal static MethodInfo? DisplayTip; internal static MethodInfo? SetClock; internal static MethodInfo? GetClockTimeFormatted; internal static FieldInfo? ClockNumber; internal static MethodInfo? ReadDialogue; internal static MethodInfo? DisplayDaysLeft; internal static FieldInfo?[] DaysLeftTexts = Array.Empty<FieldInfo>(); internal static FieldInfo? ShipLeavingEarlyIcon; internal static bool CanHoldDeadline { get { if (TimeUntilDeadline != null && GlobalTimeAtEndOfDay != null) { return PassTimeToNextDay != null; } return false; } } internal static bool CanShiftSpawnSchedule { get { if (CurrentHour != null && EnemySpawnTimes != null && AllEnemyVents != null && VentSpawnTime != null) { return VentOccupied != null; } return false; } } internal static bool Resolve() { Type type = AccessTools.TypeByName("TimeOfDay"); Type type2 = AccessTools.TypeByName("StartOfRound"); Type type3 = AccessTools.TypeByName("SelectableLevel"); if (type == null || type2 == null || type3 == null) { return false; } TimeOfDayUpdate = AccessTools.Method(type, "Update", (Type[])null, (Type[])null); TimeOfDayInstance = type.GetProperty("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); CurrentDayTime = Field(type, "currentDayTime", typeof(float)); TotalTime = Field(type, "totalTime", typeof(float)); GlobalTime = Field(type, "globalTime", typeof(float)); CalculatePlanetTime = type.GetMethod("CalculatePlanetTime", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { type3 }, null); IsServer = type.GetProperty("IsServer", BindingFlags.Instance | BindingFlags.Public); NormalizedTime = Field(type, "normalizedTimeOfDay", typeof(float)); Hour = Field(type, "hour", typeof(int)); NumberOfHours = Field(type, "numberOfHours", typeof(int)); LengthOfHours = Field(type, "lengthOfHours", typeof(float)); NextTimeSync = Field(type, "nextTimeSync", typeof(float)); ShipLeaveAutomaticallyTime = Field(type, "shipLeaveAutomaticallyTime", typeof(float)); SetShipLeaveEarlyClientRpc = type.GetMethod("SetShipLeaveEarlyClientRpc", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); ShipLeavingAlertCalled = Field(type, "shipLeavingAlertCalled", typeof(bool)); TimeOfDayEvents = AccessTools.Method(type, "TimeOfDayEvents", (Type[])null, (Type[])null); ShipLeavingEarlyDialogue = type.GetField("shipLeavingEarlyDialogue", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); TimeUntilDeadline = Field(type, "timeUntilDeadline", typeof(float)); GlobalTimeAtEndOfDay = Field(type, "globalTimeAtEndOfDay", typeof(float)); UpdateProfitQuotaCurrentTime = AccessTools.Method(type, "UpdateProfitQuotaCurrentTime", (Type[])null, (Type[])null); PassTimeToNextDay = AccessTools.Method(type2, "PassTimeToNextDay", (Type[])null, (Type[])null); DeadlineMonitorText = type2.GetField("deadlineMonitorText", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); SunAnimator = Field(type, "sunAnimator", typeof(Animator)); SunDirect = Field(type, "sunDirect", typeof(Light)); SunIndirect = Field(type, "sunIndirect", typeof(Light)); PlanetHasTime = Field(type3, "planetHasTime", typeof(bool)); StartOfRoundInstance = type2.GetProperty("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); ShipHasLanded = Field(type2, "shipHasLanded", typeof(bool)); ShipIsLeaving = Field(type2, "shipIsLeaving", typeof(bool)); CurrentLevel = type2.GetField("currentLevel", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); InShipPhase = Field(type2, "inShipPhase", typeof(bool)); ResolveRoundManager(); ResolveHud(); if (!(TimeOfDayUpdate != null) || !(CurrentDayTime != null) || !(TotalTime != null) || !(GlobalTime != null) || !(CalculatePlanetTime != null) || !(IsServer != null) || !(StartOfRoundInstance != null) || !(ShipHasLanded != null) || !(ShipIsLeaving != null) || !(CurrentLevel != null)) { return false; } if (NextTimeSync == null) { Plugin.Logger.LogWarning((object)"Clock sync not found; other players' clocks may lag behind after midnight."); } if (ShipLeavingAlertCalled == null || TimeOfDayEvents == null) { Plugin.Logger.LogWarning((object)"Ship warning not found; the 'leaving at midnight' warning may still play."); } if (!CanShiftSpawnSchedule) { Plugin.Logger.LogWarning((object)"Spawn schedule not found; monsters may stop spawning after the first midnight."); } if (DespawnEnemyOnServer == null || SpawnedEnemies == null || EnemyNetworkObject == null) { Plugin.Logger.LogWarning((object)"Enemy despawn code not found; the morning wipe is off (the day cycle still works)."); } if (!CanHoldDeadline) { Plugin.Logger.LogWarning((object)"Quota deadline not found; a long stay on a moon may use up more than one job."); } if (SunAnimator == null) { Plugin.Logger.LogWarning((object)"Sky animation not found; the night sky and sunrise follow the game's clock."); } if (SetClock == null || ClockNumber == null) { Plugin.Logger.LogWarning((object)"HUD clock not found; the clock will show the game's own time at night."); } if (DisplayTip == null) { Plugin.Logger.LogWarning((object)"HUD popup not found; no new-day message."); } return true; } private static void ResolveRoundManager() { Type type = AccessTools.TypeByName("RoundManager"); Type type2 = AccessTools.TypeByName("EnemyAI"); Type type3 = AccessTools.TypeByName("EnemyVent"); if (type == null) { return; } RoundManagerInstance = type.GetProperty("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); CurrentHour = Field(type, "currentHour", typeof(int)); HoursBetweenSpawnWaves = Field(type, "hourTimeBetweenEnemySpawnBatches", typeof(int)); EnemySpawnTimes = Field(type, "enemySpawnTimes", typeof(List<int>)); CurrentEnemySpawnIndex = Field(type, "currentEnemySpawnIndex", typeof(int)); AllEnemyVents = ((type3 == null) ? null : Field(type, "allEnemyVents", type3.MakeArrayType())); if (type3 != null) { VentSpawnTime = Field(type3, "spawnTime", typeof(float)); VentOccupied = Field(type3, "occupied", typeof(bool)); VentEnemyTypeIndex = Field(type3, "enemyTypeIndex", typeof(int)); SyncVentSpawnTime = type3.GetMethod("SyncVentSpawnTimeClientRpc", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2] { typeof(int), typeof(int) }, null); } SpawnedEnemies = type.GetField("SpawnedEnemies", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name == "DespawnEnemyOnServer" && methodInfo.GetParameters().Length == 1) { DespawnEnemyOnServer = methodInfo; break; } } if (type2 != null) { IsEnemyDead = Field(type2, "isEnemyDead", typeof(bool)); EnemyNetworkObject = type2.GetProperty("NetworkObject", BindingFlags.Instance | BindingFlags.Public); } string[] array = new string[7] { "currentEnemyPower", "currentEnemyPowerNoDeaths", "currentOutsideEnemyPower", "currentOutsideEnemyPowerNoDeaths", "currentDaytimeEnemyPower", "currentDaytimeEnemyPowerNoDeaths", "currentWeedEnemyPower" }; foreach (string name in array) { AddReset(type, name, 0f); } AddReset(type, "cannotSpawnMoreInsideEnemies", false); AddReset(type, "currentInsideEnemyDiversityLevel", 0); AddReset(type, "currentOutsideEnemyDiversityLevel", 0); AddReset(type, "minEnemiesToSpawn", 0); AddReset(type, "minOutsideEnemiesToSpawn", 0); array = new string[4] { "firstTimeSpawningEnemies", "firstTimeSpawningOutsideEnemies", "firstTimeSpawningDaytimeEnemies", "firstTimeSpawningWeedEnemies" }; foreach (string name2 in array) { AddReset(type, name2, true); } } private static void ResolveHud() { Type type = AccessTools.TypeByName("HUDManager"); if (type == null) { return; } HudInstance = type.GetProperty("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); ClockNumber = type.GetField("clockNumber", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name == "DisplayTip" && DisplayTip == null) { DisplayTip = methodInfo; } } Type[] types = new Type[3] { typeof(float), typeof(float), typeof(bool) }; SetClock = type.GetMethod("SetClock", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, types, null); GetClockTimeFormatted = type.GetMethod("GetClockTimeFormatted", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, types, null); ReadDialogue = AccessTools.Method(type, "ReadDialogue", (Type[])null, (Type[])null); DisplayDaysLeft = type.GetMethod("DisplayDaysLeft", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null); DaysLeftTexts = new FieldInfo[2] { type.GetField("profitQuotaDaysLeftText", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), type.GetField("profitQuotaDaysLeftText2", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) }; ShipLeavingEarlyIcon = type.GetField("shipLeavingEarlyIcon", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } internal static string? GetText(object? owner, FieldInfo? field) { object obj = ((owner == null) ? null : field?.GetValue(owner)); return obj?.GetType().GetProperty("text")?.GetValue(obj, null) as string; } internal static void SetText(object? owner, FieldInfo? field, string text) { object obj = ((owner == null) ? null : field?.GetValue(owner)); obj?.GetType().GetProperty("text")?.SetValue(obj, text, null); } private static FieldInfo? Field(Type type, string name, Type expected) { FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (!(field != null) || !(field.FieldType == expected)) { return null; } return field; } private static void AddReset(Type type, string name, object value) { FieldInfo fieldInfo = Field(type, name, value.GetType()); if (fieldInfo != null) { SpawnBudgetResets.Add(new KeyValuePair<FieldInfo, object>(fieldInfo, value)); } } } internal static class LeaveVote { private const string GameVoteMessage = "WARNING! Please return by"; private const string Suggestion = "The dead crew voted to leave. Head back to the ship and pull the lever when you're ready."; internal static void ReadDialoguePrefix(object dialogueArray) { if (!DayLoop.Active || !(dialogueArray is Array { Length: not 0 } array) || GameAccess.ShipLeavingEarlyDialogue == null) { return; } object obj = GameAccess.TimeOfDayInstance?.GetValue(null, null); if (obj != null && array == GameAccess.ShipLeavingEarlyDialogue.GetValue(obj)) { object value = array.GetValue(0); FieldInfo fieldInfo = value?.GetType().GetField("bodyText"); if (fieldInfo?.GetValue(value) is string text && text.StartsWith("WARNING! Please return by", StringComparison.Ordinal)) { fieldInfo.SetValue(value, "The dead crew voted to leave. Head back to the ship and pull the lever when you're ready."); } } } internal static void VotePassedPostfix(object __instance) { if (!DayLoop.Active) { return; } GameAccess.ShipLeaveAutomaticallyTime?.SetValue(__instance, DayLoop.LeaveTimeOnLanding); GameAccess.ShipLeavingAlertCalled?.SetValue(__instance, false); try { object obj = GameAccess.HudInstance?.GetValue(null, null); object? obj2 = GameAccess.ShipLeavingEarlyIcon?.GetValue(obj); Behaviour val = (Behaviour)((obj2 is Behaviour) ? obj2 : null); if (val != null) { val.enabled = false; } } catch (Exception ex) { Plugin.Logger.LogDebug((object)("Leave icon: " + ex.Message)); } Plugin.Logger.LogInfo((object)"The dead crew voted to leave; the ship waits for the lever."); } } internal static class MonsterReset { internal static void FreshBudget() { try { object obj = GameAccess.RoundManagerInstance?.GetValue(null, null); if (obj != null) { ResetBudgets(obj); Plugin.Logger.LogInfo((object)"New day of monster spawning (the monsters still alive stay)."); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Fresh monster budget failed: " + ex)); } } internal static void Wipe() { try { object obj = GameAccess.RoundManagerInstance?.GetValue(null, null); if (obj != null) { int num = DespawnLivingMonsters(obj); SpawnPlan.Clear(); GameAccess.CurrentHour?.SetValue(obj, 0); ResetBudgets(obj); Plugin.Logger.LogInfo((object)$"Morning wipe: {num} monsters despawned, spawning starts over."); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Morning wipe failed: " + ex)); } } private static void ResetBudgets(object manager) { foreach (KeyValuePair<FieldInfo, object> spawnBudgetReset in GameAccess.SpawnBudgetResets) { spawnBudgetReset.Key.SetValue(manager, spawnBudgetReset.Value); } } private static int DespawnLivingMonsters(object manager) { if (GameAccess.DespawnEnemyOnServer == null || GameAccess.EnemyNetworkObject == null || !(GameAccess.SpawnedEnemies?.GetValue(manager) is IList list)) { return 0; } object[] array = new object[list.Count]; list.CopyTo(array, 0); int num = 0; object[] array2 = array; foreach (object obj in array2) { try { if (obj != null && (!(GameAccess.IsEnemyDead != null) || !(bool)GameAccess.IsEnemyDead.GetValue(obj))) { object value = GameAccess.EnemyNetworkObject.GetValue(obj, null); if (value != null) { GameAccess.DespawnEnemyOnServer.Invoke(manager, new object[1] { value }); num++; } } } catch (Exception ex) { Plugin.Logger.LogDebug((object)("Skipped a monster despawn: " + ex.Message)); } } return num; } } internal static class NewDayPopup { internal static void Show(int day) { Tip("A NEW DAY", Plugin.BoundConfig.OneJobPerLanding.Value ? $"Day {day} on this moon. Still the same job: the deadline only moves when you leave." : $"Day {day} on this moon. The ship waits until you pull the lever."); } internal static void Tip(string header, string body) { try { object obj = GameAccess.HudInstance?.GetValue(null, null); MethodInfo displayTip = GameAccess.DisplayTip; if (obj != null && !(displayTip == null)) { ParameterInfo[] parameters = displayTip.GetParameters(); object[] array = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { Type parameterType = parameters[i].ParameterType; array[i] = (parameters[i].HasDefaultValue ? parameters[i].DefaultValue : (parameterType.IsValueType ? Activator.CreateInstance(parameterType) : null)); } if (array.Length != 0) { array[0] = header; } if (array.Length > 1) { array[1] = body; } displayTip.Invoke(obj, array); } } catch (Exception ex) { Plugin.Logger.LogDebug((object)("HUD tip failed: " + ex.Message)); } } } [BepInPlugin("EndlessDays", "EndlessDays", "1.5.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger; internal static PluginConfig BoundConfig { get; private set; } private void Awake() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Expected O, but got Unknown //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00b4: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Expected O, but got Unknown //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Expected O, but got Unknown //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Expected O, but got Unknown //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Expected O, but got Unknown //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config); if (!GameAccess.Resolve()) { Logger.LogError((object)"Could not find required game code. The game may have updated; EndlessDays is disabled."); return; } Harmony val = new Harmony("EndlessDays"); val.Patch((MethodBase)GameAccess.TimeOfDayUpdate, (HarmonyMethod)null, new HarmonyMethod(typeof(DayLoop), "TimeOfDayUpdatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); if (GameAccess.TimeOfDayEvents != null && GameAccess.ShipLeavingAlertCalled != null) { val.Patch((MethodBase)GameAccess.TimeOfDayEvents, new HarmonyMethod(typeof(DayLoop), "HideWarningPrefix", (Type[])null), new HarmonyMethod(typeof(DayLoop), "HideWarningPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.SetShipLeaveEarlyClientRpc != null) { val.Patch((MethodBase)GameAccess.SetShipLeaveEarlyClientRpc, (HarmonyMethod)null, new HarmonyMethod(typeof(LeaveVote), "VotePassedPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.ReadDialogue != null) { val.Patch((MethodBase)GameAccess.ReadDialogue, new HarmonyMethod(typeof(LeaveVote), "ReadDialoguePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.CanHoldDeadline) { val.Patch((MethodBase)GameAccess.PassTimeToNextDay, new HarmonyMethod(typeof(Deadline), "PassTimeToNextDayPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.UpdateProfitQuotaCurrentTime != null && GameAccess.DeadlineMonitorText != null) { val.Patch((MethodBase)GameAccess.UpdateProfitQuotaCurrentTime, (HarmonyMethod)null, new HarmonyMethod(typeof(Deadline), "MonitorPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.DisplayDaysLeft != null) { val.Patch((MethodBase)GameAccess.DisplayDaysLeft, (HarmonyMethod)null, new HarmonyMethod(typeof(Deadline), "DaysLeftPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.DisplayTip != null) { val.Patch((MethodBase)GameAccess.DisplayTip, new HarmonyMethod(typeof(Deadline), "HaltTipPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.SetClock != null) { val.Patch((MethodBase)GameAccess.SetClock, new HarmonyMethod(typeof(ClockDisplay), "SetClockPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (GameAccess.GetClockTimeFormatted != null) { val.Patch((MethodBase)GameAccess.GetClockTimeFormatted, new HarmonyMethod(typeof(ClockDisplay), "GetClockTimeFormattedPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } GameObject val2 = new GameObject("EndlessDaysSky") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val2); val2.AddComponent<SkyCycleRunner>(); Logger.LogInfo((object)"EndlessDays 1.5.0 loaded. The ship will wait for you, all night."); } } internal static class SkyCycle { private const string SkyParameter = "timeOfDay"; private const float MidnightSky = 0.99f; private const float MorningSky = 0f; internal const float SunriseHours = 1f; private const float MidnightSunIntensity = 1f; private const float MidnightAmbientIntensity = 0f; private const float MorningSunIntensity = 14.6f; private const float MorningAmbientIntensity = 4f; private const string NightSkyVolume = "Sky and Fog Global Volume (1)"; private static float sunrise = -1f; private static object? timeOfDay; private static Animator? cachedAnimator; private static Component? nightVolume; private static FieldInfo? volumeWeight; private static float nightSun = 1f; private static float nightAmbient = 0f; private static float morningSun = -1f; private static float morningAmbient = -1f; internal static void Apply(object tod, float trueHours, float nightFromHours, float morningAtHours) { sunrise = -1f; if (trueHours < nightFromHours) { return; } object? obj = GameAccess.SunAnimator?.GetValue(tod); Animator val = (Animator)((obj is Animator) ? obj : null); if (val == null) { return; } float num = morningAtHours - 1f; if (trueHours < num) { val.SetFloat("timeOfDay", 0.99f); object? obj2 = GameAccess.SunDirect?.GetValue(tod); Light val2 = (Light)((obj2 is Light) ? obj2 : null); if (val2 != null && (Object)(object)val2 != (Object)null) { nightSun = val2.intensity; } object? obj3 = GameAccess.SunIndirect?.GetValue(tod); Light val3 = (Light)((obj3 is Light) ? obj3 : null); if (val3 != null && (Object)(object)val3 != (Object)null) { nightAmbient = val3.intensity; } morningSun = -1f; } else { val.SetFloat("timeOfDay", 0f); timeOfDay = tod; sunrise = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((trueHours - num) / 1f)); if (val != cachedAnimator) { cachedAnimator = val; Transform val4 = ((Component)val).transform.Find("Sky and Fog Global Volume (1)"); nightVolume = (((Object)(object)val4 != (Object)null) ? ((Component)val4).GetComponent("Volume") : null); volumeWeight = ((object)nightVolume)?.GetType().GetField("weight"); } } } internal static void Clear() { sunrise = -1f; timeOfDay = null; morningSun = -1f; } internal static void FadeLights() { object obj = timeOfDay; if (!(sunrise < 0f) && obj != null) { object? obj2 = GameAccess.SunDirect?.GetValue(obj); Light val = (Light)((obj2 is Light) ? obj2 : null); object? obj3 = GameAccess.SunIndirect?.GetValue(obj); Light val2 = (Light)((obj3 is Light) ? obj3 : null); if (morningSun < 0f) { morningSun = (((Object)(object)val != (Object)null && val.intensity > nightSun) ? val.intensity : 14.6f); morningAmbient = (((Object)(object)val2 != (Object)null && val2.intensity > nightAmbient) ? val2.intensity : 4f); } if ((Object)(object)val != (Object)null) { val.intensity = Mathf.Lerp(nightSun, morningSun, sunrise); } if ((Object)(object)val2 != (Object)null) { val2.intensity = Mathf.Lerp(nightAmbient, morningAmbient, sunrise); } if ((Object)(object)nightVolume != (Object)null && volumeWeight != null) { volumeWeight.SetValue(nightVolume, 1f - sunrise); } } } } internal sealed class SkyCycleRunner : MonoBehaviour { private void LateUpdate() { SkyCycle.FadeLights(); } } internal static class SpawnPlan { internal static void ShiftBack(int hours, float lengthOfHours) { if (hours <= 0 || !GameAccess.CanShiftSpawnSchedule) { return; } try { object obj = GameAccess.RoundManagerInstance?.GetValue(null, null); if (obj == null) { return; } int num = (int)GameAccess.CurrentHour.GetValue(obj); GameAccess.CurrentHour.SetValue(obj, Math.Max(0, num - hours)); int num2 = (int)Math.Round((float)hours * lengthOfHours); if (GameAccess.EnemySpawnTimes.GetValue(obj) is List<int> list) { for (int i = 0; i < list.Count; i++) { list[i] -= num2; } } if (!(GameAccess.AllEnemyVents.GetValue(obj) is IEnumerable enumerable)) { return; } foreach (object item in enumerable) { if (item != null && (bool)GameAccess.VentOccupied.GetValue(item)) { MoveVent(item, (float)GameAccess.VentSpawnTime.GetValue(item) - (float)num2); } } } catch (Exception ex) { Plugin.Logger.LogWarning((object)("Could not move the spawn schedule: " + ex.Message)); } } internal static void Clear() { if (!GameAccess.CanShiftSpawnSchedule) { return; } try { object obj = GameAccess.RoundManagerInstance?.GetValue(null, null); if (obj == null) { return; } (GameAccess.EnemySpawnTimes.GetValue(obj) as List<int>)?.Clear(); GameAccess.CurrentEnemySpawnIndex?.SetValue(obj, 0); if (!(GameAccess.AllEnemyVents.GetValue(obj) is IEnumerable enumerable)) { return; } foreach (object item in enumerable) { if (item != null) { GameAccess.VentOccupied.SetValue(item, false); } } } catch (Exception ex) { Plugin.Logger.LogWarning((object)("Could not clear the spawn schedule: " + ex.Message)); } } private static void MoveVent(object vent, float spawnTime) { GameAccess.VentSpawnTime.SetValue(vent, spawnTime); if (GameAccess.SyncVentSpawnTime != null && GameAccess.VentEnemyTypeIndex != null) { int num = (int)GameAccess.VentEnemyTypeIndex.GetValue(vent); GameAccess.SyncVentSpawnTime.Invoke(vent, new object[2] { (int)spawnTime, num }); } } } public static class TestMenuActions { private const float FiveToTenPm = 15.916667f; private const float FiveToMidnight = 17.916666f; private const float FiveToTwoAm = 19.916666f; private const float FiveToFiveAm = 22.916666f; private const float FiveToSixAm = 23.916666f; public static void SkipToFiveToTenPm() { DayLoop.SkipTo(15.916667f); } public static void SkipToFiveToMidnight() { DayLoop.SkipTo(17.916666f); } public static void SkipToFiveToTwoAm() { DayLoop.SkipTo(19.916666f); } public static void SkipToFiveToFiveAm() { DayLoop.SkipTo(22.916666f); } public static void SkipToFiveToSixAm() { DayLoop.SkipTo(23.916666f); } } public static class PluginInfo { public const string PLUGIN_GUID = "EndlessDays"; public const string PLUGIN_NAME = "EndlessDays"; public const string PLUGIN_VERSION = "1.5.0"; } }