Decompiled source of SleepyTime v1.1.2

SleepyTime.dll

Decompiled 6 months ago
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 HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SleepyTime")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SleepyTime")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("55ede966-fe69-4ed9-8569-7858c0df423a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SleepyTime;

[BepInPlugin("PartyWhale.SleepyTime", "SleepyTime", "1.0.0")]
public class Mod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Game), "EverybodyIsTryingToSleep")]
	private class EverybodyIsTryingToSleep_Patch
	{
		private static bool Prefix(ref bool __result)
		{
			List<ZDO> allCharacterZDOS = ZNet.instance.GetAllCharacterZDOS();
			if (allCharacterZDOS.Count == 0)
			{
				__result = false;
				return false;
			}
			int num = 0;
			foreach (ZDO item in allCharacterZDOS)
			{
				if (item.GetBool(ZDOVars.s_inBed, false))
				{
					num++;
				}
			}
			if (num > 0)
			{
				Debug.Log((object)$"{num} out of {allCharacterZDOS.Count} characters sleeping (need at least {allCharacterZDOS.Count / 2})");
				if (num >= allCharacterZDOS.Count / 2)
				{
					Debug.Log((object)"Close enough.  Let's sleep!");
					__result = true;
				}
			}
			return false;
		}
	}

	private readonly Harmony harmony = new Harmony("PartyWhale.SleepyTime");

	private void Awake()
	{
		harmony.PatchAll();
	}
}