using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("NowYouSleep")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("NowYouSleep")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("406b012c-b787-44eb-afa1-2e527bde40aa")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace NowYouSleep; [BepInPlugin("hex.nowyousleep", "NowYouSleep", "1.0.0")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; private ConfigEntry _modEnabled; private ConfigEntry _debugModeEnabled; internal const string PluginGuid = "hex.nowyousleep"; internal const string PluginName = "NowYouSleep"; internal const string PluginVersion = "1.0.0"; internal static Plugin Instance { get; private set; } internal static ManualLogSource Log { get; private set; } internal bool IsNowYouSleepEnabled { get { if (_modEnabled != null) { return _modEnabled.Value; } return false; } } internal bool IsDebugModeEnabled { get { if (_debugModeEnabled != null) { return _debugModeEnabled.Value; } return false; } } private void Awake() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; _modEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Whether NowYouSleep is enabled."); _debugModeEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "DebugMode", false, "Whether to enable debug logging for NowYouSleep."); _harmony = new Harmony("hex.nowyousleep"); _harmony.PatchAll(); Log.LogInfo((object)"v1.0.0 loaded."); } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); _harmony = null; } Log.LogInfo((object)"v1.0.0 unloaded."); Instance = null; } internal void LogDebug(string message) { if (IsDebugModeEnabled) { Log.LogInfo((object)message); } } } [HarmonyPatch(typeof(Game), "EverybodyIsTryingToSleep")] internal static class GameEverybodyIsTryingToSleepPatch { [HarmonyPrefix] private static bool Prefix(ref bool __result) { if ((Object)(object)Plugin.Instance == (Object)null || !Plugin.Instance.IsNowYouSleepEnabled) { return true; } Plugin.Instance.LogDebug("Sleep check running..."); if ((Object)(object)ZNet.instance == (Object)null) { Plugin.Instance.LogDebug("ZNet.instance is null. Falling back to vanilla sleep check."); return true; } List allCharacterZDOS = ZNet.instance.GetAllCharacterZDOS(); if (allCharacterZDOS == null || allCharacterZDOS.Count == 0) { Plugin.Instance.LogDebug("No character ZDOs found. Returning false."); __result = false; return false; } Plugin.Instance.LogDebug($"ZDO count: {allCharacterZDOS.Count}"); foreach (ZDO item in allCharacterZDOS) { if (item.GetBool(ZDOVars.s_inBed, false)) { Plugin.Instance.LogDebug("At least one player is trying to sleep. Allowing sleep skip."); __result = true; return false; } } __result = false; return false; } }