using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; [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("ArgusMagnus")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("ArgusMagnus")] [assembly: AssemblyDescription("Allow players to vote to sleep and skip the night when at least one player is in bed")] [assembly: AssemblyFileVersion("1.99.8.0")] [assembly: AssemblyInformationalVersion("1.99.8-beta+328851184cc278c858ffbc70e717af9f9d7b6973")] [assembly: AssemblyProduct("ServersideQoL.JustSleep")] [assembly: AssemblyTitle("ServersideQoL.JustSleep")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")] [assembly: AssemblyVersion("1.99.8.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 ServersideQoL.JustSleep { public sealed class Config : ConfigBase { public sealed class LocalizationConfig { private string Prompt { get; init; } = "{0} of {1} players want to sleep.
Sit down if you want to sleep as well"; public string FormatPrompt(int sleepingPlayers, int totalPlayers) { return string.Format(Prompt, sleepingPlayers, totalPlayers); } } private const string Section = "JustSleep"; public override ConfigEntry Enabled { get; } = ConfigBase.BindEx(cfg, "JustSleep", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated)null, "Enabled"); public ConfigEntry MinPlayersInBed { get; } = ConfigBase.BindEx(cfg, "JustSleep", 1, "Minimum number of players in bed to show the sleep prompt to the other players", (AcceptableValueBase)(object)new AcceptableValueRange(1, 10), (Deprecated)null, "MinPlayersInBed"); public ConfigEntry RequiredPlayerPercentage { get; } = ConfigBase.BindEx(cfg, "JustSleep", 100, "Percentage of players that must be in bed or sitting to skip the night", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), (Deprecated)null, "RequiredPlayerPercentage"); public ConfigEntry SleepPromptMessageType { get; } = ConfigBase.BindEx(cfg, "JustSleep", (MessageType)2, "Type of message to show for the sleep prompt", (AcceptableValueBase)(object)AcceptableEnum.Default, (Deprecated)null, "SleepPromptMessageType"); public YamlConfigEntry Localization { get; } = ConfigBase.BindYaml(cfg, "Localization"); public Config(ConfigFile cfg, Logger logger) : base(cfg, logger) { } } [BepInPlugin("ArgusMagnus.ServersideQoL.JustSleep", "ServersideQoL.JustSleep", "1.99.8")] public sealed class JustSleepPlugin : ServersideQoLPluginBase { public const string Author = "ArgusMagnus"; public const string PluginName = "ServersideQoL.JustSleep"; public const string PluginGuid = "ArgusMagnus.ServersideQoL.JustSleep"; public const string PluginVersion = "1.99.8"; public const string PluginInformationalVersion = "1.99.8-beta"; internal static Harmony HarmonyInstance { get; } = new Harmony("ArgusMagnus.ServersideQoL.JustSleep"); private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639215507745838134L, default(TimeSpan)); protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger) { return new Config(configFile, logger); } protected override void RegisterProcessors(IProcessorCollection processors) { processors.Add(); } private void Awake() { ServersideQoLPluginBase.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.8-beta", BuildTimestamp.LocalDateTime)); } } [Processor("500d524e-2dbc-493d-8231-c8e9f03158bf")] [DependsOn] public sealed class PlayerProcessor : Processor> { [HarmonyPatch(typeof(Game), "EverybodyIsTryingToSleep")] private static class EverybodyIsTryingToSleepPatch { [HarmonyPrefix] public static bool Prefix(ref bool __result) { __result = EverybodyIsTryingToSleep(); return false; } } private bool _patched; protected override void Initialize() { if (!_patched) { _patched = true; JustSleepPlugin.HarmonyInstance.PatchAll(typeof(EverybodyIsTryingToSleepPatch)); } } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList peers, ProcessorPrefabInfo prefabInfo) { return (ProcessResult)2; } private static bool EverybodyIsTryingToSleep() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Invalid comparison between Unknown and I4 //IL_00d2: Unknown result type (might be due to invalid IL or missing references) IReadOnlyCollection playerStates = Processor.Instance().PlayerStates; if (playerStates == null || playerStates.Count <= 0) { return false; } int num = 0; int num2 = 0; foreach (PlayerState item in playerStates) { ZDOVars vars = item.ZDO.Vars; if (((ZDOVars)(ref vars)).GetInBed(false)) { num++; continue; } vars = item.ZDO.Vars; if ((int)((ZDOVars)(ref vars)).GetEmote((Emotes)(-1)) == 1) { num2++; } } if (num == playerStates.Count) { return true; } if (num < ConfigBase.Instance.MinPlayersInBed.Value) { return false; } int num3 = num + num2; if (num3 * 100 / playerStates.Count >= ConfigBase.Instance.RequiredPlayerPercentage.Value) { return true; } RPC.ShowMessage(ZRoutedRpc.Everybody, ConfigBase.Instance.SleepPromptMessageType.Value, ConfigBase.Instance.Localization.Value.FormatPrompt(num3, playerStates.Count)); return false; } } }