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 JustSleep v1.0.10
JustSleep.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using ConditionalConfigSync; 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("JustSleep")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("JustSleep")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("1f044c3f-2bd7-41a4-981b-5e0e47ba84e3")] [assembly: AssemblyFileVersion("1.0.10")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.10.0")] [module: UnverifiableCode] namespace JustSleep; [BepInPlugin("shudnal.JustSleep", "JustSleep", "1.0.10")] [BepInDependency("_shudnal.ConditionalConfigSync", "1.0.5")] public class JustSleep : BaseUnityPlugin { private enum HotkeyAction { None, Sleep, Claim } private enum BedAction { None, Claim, SetSpawn, Sleep } [HarmonyPatch(typeof(Fireplace), "GetHoverText")] private class Fireplace_GetHoverText_HoverTextWithSleepAction { [HarmonyPriority(800)] private static void Postfix(Fireplace __instance, ref string __result) { if (!IsSleepingWhileRestingAvailable()) { if (PlayerInSleepPosition() && restingTimer > 0f) { __result = __result + "\n" + Localization.instance.Localize("$se_resting_start") + "\n" + FromPercent(restingTimer / (float)sleepingWhileRestingSeconds.Value); } } else if (!((Character)Player.m_localPlayer).InBed()) { if (!EnvMan.CanSleep()) { __result += Localization.instance.Localize("\n$msg_cantsleep"); } else if (((Character)Player.m_localPlayer).GetSEMan().HaveStatusEffect(SEMan.s_statusEffectWet)) { __result += Localization.instance.Localize("\n$msg_bedwet"); } else if (Player.m_localPlayer.IsSensed()) { __result += Localization.instance.Localize("\n$msg_bedenemiesnearby"); } else { __result = __result + "\n" + GetActionHoverLine(GetSleepHotkeyText(defaultUsesAlternativeAction: true), "$piece_bed_sleep"); } } } } [HarmonyPatch(typeof(Fireplace), "Interact")] private class Fireplace_Interact_SleepAction { [HarmonyPriority(800)] private static bool Prefix(Humanoid user, bool hold, bool alt) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) if (hold || (Object)(object)user != (Object)(object)Player.m_localPlayer || !CanSleep()) { return true; } if (activeHotkeyAction == HotkeyAction.Sleep) { SetSleepingWhileResting(sleeping: true); return false; } if (sleepHotkeyOverride.Value && IsShortcutDown(sleepHotkey.Value)) { return false; } if (!alt) { return true; } if (sleepHotkeyOverride.Value) { return false; } SetSleepingWhileResting(sleeping: true); return false; } } [HarmonyPatch(typeof(Player), "Update")] private static class Player_Update_CustomHotkeys { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); MethodInfo inRadial = AccessTools.Method(typeof(Hud), "InRadial", (Type[])null, (Type[])null); MethodInfo getButtonUp = AccessTools.Method(typeof(ZInput), "GetButtonUp", new Type[1] { typeof(string) }, (Type[])null); MethodInfo methodInfo = AccessTools.Method(typeof(JustSleep), "CheckCustomHotkeys", (Type[])null, (Type[])null); CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, inRadial)), (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => instruction.opcode.FlowControl == FlowControl.Cond_Branch), (string)null), new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"JoyHide", (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, getButtonUp)), (string)null) }); if (!val.IsValid) { JustSleep instance = JustSleep.instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogError((object)"Failed to inject custom bed hotkey handling into Player.Update."); } return list; } CodeInstruction val2 = new CodeInstruction(OpCodes.Ldarg_0, (object)null); val2.labels.AddRange(val.Instruction.labels); val.Instruction.labels.Clear(); val2.blocks.AddRange(val.Instruction.blocks); val.Instruction.blocks.Clear(); val.Insert((CodeInstruction[])(object)new CodeInstruction[2] { val2, new CodeInstruction(OpCodes.Call, (object)methodInfo) }); return val.InstructionEnumeration(); } } [HarmonyPatch(typeof(Player), "SetControls")] private class Player_SetControls_StopSleeping { private static void Prefix(Player __instance, Vector3 movedir, bool attack, bool secondaryAttack, bool block, bool blockHold, bool jump, bool crouch) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)(object)__instance && isSittingSleeping && (((Character)__instance).IsAttached() || ((Character)__instance).InEmote()) && !__instance.IsSleeping() && (movedir != Vector3.zero || attack || secondaryAttack || block || blockHold || jump || crouch) && __instance.GetDoodadController() == null) { SetSleepingWhileResting(sleeping: false); } } } [HarmonyPatch(typeof(Player), "SetSleeping")] private class Player_SetSleeping_StopSleeping { private static void Prefix(Player __instance, bool sleep) { if ((Object)(object)Player.m_localPlayer == (Object)(object)__instance && isSittingSleeping && __instance.IsSleeping() && !sleep) { SetSleepingWhileResting(sleeping: false); if (((Character)__instance).IsSitting()) { ((Character)__instance).StopEmote(); } } } } [HarmonyPatch(typeof(Bed))] public static class BedPatches { private static readonly StringBuilder sb = new StringBuilder(); private static Bed alternativeInteractingBed; [HarmonyPostfix] [HarmonyPatch("GetHoverText")] public static void GetHoverText(Bed __instance, ref string __result) { if (modEnabled.Value) { GetBedActions(__instance, out var firstAction, out var secondAction); sb.Clear(); sb.Append(GetBedHeader(__instance)); AppendBedAction(sb, __instance, firstAction); AppendBedAction(sb, __instance, secondAction); __result = sb.ToString(); } } private static string GetBedHeader(Bed bed) { string ownerName = bed.GetOwnerName(); return (ownerName == "") ? Localization.instance.Localize("$piece_bed_unclaimed") : Localization.instance.Localize(ownerName + "'s $piece_bed"); } [HarmonyPrefix] [HarmonyPatch("Interact")] public static bool InteractPrefix(Bed __instance, bool repeat, bool alt) { alternativeInteractingBed = null; if (ShouldSuppressNativeBedInteraction(__instance, repeat, alt)) { return false; } GetBedActions(__instance, out var firstAction, out var secondAction); bool flag = HasBedAction(firstAction, secondAction, BedAction.Sleep); alternativeInteractingBed = ((alt && flag && BedSleepUsesAlternativeAction(__instance)) ? __instance : null); return true; } [HarmonyFinalizer] [HarmonyPatch("Interact")] public static void InteractFinalizer() { alternativeInteractingBed = null; } [HarmonyPostfix] [HarmonyPatch("GetOwner")] public static void GetOwner(Bed __instance, ref long __result) { if ((Object)(object)__instance == (Object)(object)alternativeInteractingBed) { __result = Game.instance.GetPlayerProfile().GetPlayerID(); } } [HarmonyPostfix] [HarmonyPatch("IsCurrent")] public static void IsCurrent(Bed __instance, ref bool __result) { __result = __result || (Object)(object)__instance == (Object)(object)alternativeInteractingBed; } } [HarmonyPatch(typeof(Hud), "Awake")] public static class Hud_Awake_BlackPanelInit { private static void Postfix(Hud __instance) { playersWithSleepText.Clear(); if ((Object)(object)__instance.m_loadingScreen == (Object)null) { return; } GameObject val = Object.Instantiate<GameObject>(((Component)__instance.m_loadingScreen).gameObject, ((Component)__instance.m_loadingScreen).transform.parent); ((Object)val).name = "JustSleep_SleepingBlack"; val.transform.SetSiblingIndex(0); Transform obj = val.transform.Find("Loading/TopFade"); if (obj != null) { obj.SetParent(val.transform); } Transform obj2 = val.transform.Find("Loading/BottomFade"); if (obj2 != null) { obj2.SetParent(val.transform); } for (int num = val.transform.childCount - 1; num >= 0; num--) { Transform child = val.transform.GetChild(num); switch (((Object)child).name) { case "Loading": case "Sleeping": case "Teleporting": case "Image": case "Tip": case "panel_separator": Object.Destroy((Object)(object)((Component)child).gameObject); break; } } screenBlackener = val.GetComponent<CanvasGroup>() ?? val.AddComponent<CanvasGroup>(); screenBlackener.alpha = 0f; screenBlackener.interactable = false; screenBlackener.blocksRaycasts = false; ((Component)screenBlackener).gameObject.SetActive(false); } } public const string pluginID = "shudnal.JustSleep"; public const string pluginName = "JustSleep"; public const string pluginVersion = "1.0.10"; internal static readonly ConfigSync configSync = new ConfigSync("shudnal.JustSleep") { DisplayName = "JustSleep", CurrentVersion = "1.0.10", MinimumRequiredVersion = "1.0.10", ModRequired = false }; private Harmony harmony; private static JustSleep instance; private static ConfigEntry<bool> modEnabled; private static ConfigEntry<bool> sleepingInNotOwnedBed; private static ConfigEntry<bool> sleepingWhileResting; private static ConfigEntry<int> sleepingWhileRestingSeconds; private static ConfigEntry<bool> sleepHotkeyOverride; private static ConfigEntry<KeyboardShortcut> sleepHotkey; private static ConfigEntry<bool> claimHotkeyOverride; private static ConfigEntry<KeyboardShortcut> claimHotkey; private static bool sanitizingHotkeys; private static HotkeyAction activeHotkeyAction; private const float automaticSleepFocusSeconds = 20f; private const float sleepLookRightSeconds = 3f; private const float sleepLookLeftSeconds = 0.25f; private const float sleepLookTransitionToFarSeconds = 0.4f; private const float sleepLookTransitionToNearSeconds = 1.6f; private const float sleepTextUpdateInterval = 0.2f; private const string rightSleepLookTargetPath = "Visual/Armature/Hips/RightUpLeg/RightLeg/RightFoot/RightToeBase/RightToeBase_end"; private const string leftSleepLookTargetPath = "Visual/Armature/Hips/LeftUpLeg/LeftLeg/LeftFoot/LeftToeBase/LeftToeBase_end"; private static readonly int sleepingWhileRestingZdoKey = StringExtensionMethods.GetStableHashCode("shudnal.JustSleep.SleepingWhileResting"); private static readonly HashSet<Player> playersWithSleepText = new HashSet<Player>(); private static float restingTimer = 0f; private static bool isSittingSleeping; private static Fireplace automaticSleepFireplace; private static float automaticSleepFocusTimer; private static float sleepTextUpdateTimer; private static CharacterAnimEvent sleepCharacterAnimEvent; private static Transform previousSleepLookTarget; private static Transform rightSleepLookTarget; private static Transform leftSleepLookTarget; private static Transform sleepLookTarget; private static bool sleepLookUsesRightTarget; private static bool sleepLookTransitioning; private static bool sleepLookTransitionToRight; private static float sleepLookTimer; private static float sleepLookTransitionTimer; private static Vector3 sleepLookTransitionStart; public static bool debugPreventAutomaticSleep; public static CanvasGroup screenBlackener; private void Awake() { harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "shudnal.JustSleep"); instance = this; ConfigInit(); Game.isModded = true; } private void FixedUpdate() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).GetSEMan() == null) { ResetAutomaticSleepFocus(); StopSleepLookAnimation(); isSittingSleeping = false; playersWithSleepText.Clear(); return; } UpdateSleepTexts(Time.fixedDeltaTime); if (((Character)localPlayer).GetSEMan().HaveStatusEffect(SEMan.s_statusEffectResting)) { restingTimer += Time.fixedDeltaTime; } else { restingTimer = 0f; } UpdateAutomaticSleepFocus(Time.fixedDeltaTime); if (isSittingSleeping) { UpdateVanillaSleepRequest(); UpdateSleepLookAnimation(Time.fixedDeltaTime); } if (isSittingSleeping && (Object)(object)Game.instance != (Object)null && !Game.instance.m_sleeping && !CanSleep()) { SetSleepingWhileResting(sleeping: false); } } private void Update() { UpdateScreenBlackener(Time.deltaTime); } private void OnDestroy() { if (isSittingSleeping && (Object)(object)Player.m_localPlayer != (Object)null) { SetSleepingWhileResting(sleeping: false); } else { StopSleepLookAnimation(); } ClearSleepTexts(); ((BaseUnityPlugin)this).Config.Save(); Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } private ConfigEntry<T> BindConfig<T>(string group, string name, T defaultValue, string description) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown return ((ConditionalConfigSync)configSync).AddConfigEntry<T>(((BaseUnityPlugin)this).Config, group, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), (ConfigSyncMode)1, true).SourceConfig; } private ConfigEntry<T> BindClientConfig<T>(string group, string name, T defaultValue, string description) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown return ((ConditionalConfigSync)configSync).AddConfigEntry<T>(((BaseUnityPlugin)this).Config, group, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), (ConfigSyncMode)1, false).SourceConfig; } private void ConfigInit() { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) modEnabled = BindConfig("General", "Enabled", defaultValue: true, "Enable the mod."); sleepingInNotOwnedBed = BindConfig("Sleeping in not owned beds", "Enabled", defaultValue: true, "Enable sleeping in not owned beds."); sleepingWhileResting = BindConfig("Sleeping while resting", "Enabled", defaultValue: true, "Enable option to sleep while Resting."); sleepingWhileRestingSeconds = BindConfig("Sleeping while resting", "Seconds to stay resting", 20, "How many seconds should pass while resting for sleep in front of fireplace to be available"); sleepHotkeyOverride = BindClientConfig("Hotkey - Sleep", "Override default hotkey", defaultValue: false, "Replace the default Sleep interaction hotkey with the configured hotkey."); sleepHotkey = BindClientConfig<KeyboardShortcut>("Hotkey - Sleep", "Hotkey", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Hotkey used for Sleep when the default hotkey override is enabled."); claimHotkeyOverride = BindClientConfig("Hotkey - Claim", "Override default hotkey", defaultValue: false, "Replace the default Claim interaction hotkey with the configured hotkey."); claimHotkey = BindClientConfig<KeyboardShortcut>("Hotkey - Claim", "Hotkey", new KeyboardShortcut((KeyCode)101, Array.Empty<KeyCode>()), "Hotkey used for Claim when the default hotkey override is enabled."); sleepHotkey.SettingChanged += delegate { SanitizeHotkey(sleepHotkey); }; claimHotkey.SettingChanged += delegate { SanitizeHotkey(claimHotkey); }; SanitizeHotkey(sleepHotkey); SanitizeHotkey(claimHotkey); } private unsafe static void SanitizeHotkey(ConfigEntry<KeyboardShortcut> hotkeyConfig) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (sanitizingHotkeys || hotkeyConfig == null) { return; } KeyboardShortcut value = hotkeyConfig.Value; KeyboardShortcut sanitizedHotkey = GetSanitizedHotkey(value); if (((object)(*(KeyboardShortcut*)(&value))/*cast due to .constrained prefix*/).Equals((object?)sanitizedHotkey)) { return; } sanitizingHotkeys = true; try { hotkeyConfig.Value = sanitizedHotkey; JustSleep justSleep = instance; if (justSleep != null) { ((BaseUnityPlugin)justSleep).Logger.LogWarning((object)$"Sanitized hotkey data on {((ConfigEntryBase)hotkeyConfig).Definition}: {sanitizedHotkey}."); } } finally { sanitizingHotkeys = false; } } private static KeyboardShortcut GetSanitizedHotkey(KeyboardShortcut shortcut) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) List<KeyCode> list = new List<KeyCode> { ((KeyboardShortcut)(ref shortcut)).MainKey }; list.AddRange(((KeyboardShortcut)(ref shortcut)).Modifiers); list = list.Where(IsHotkeyKeyValid).Distinct().ToList(); KeyCode mainKey = ((list.Contains(((KeyboardShortcut)(ref shortcut)).MainKey) && !IsModifier(((KeyboardShortcut)(ref shortcut)).MainKey)) ? ((KeyboardShortcut)(ref shortcut)).MainKey : ((IEnumerable<KeyCode>)list).FirstOrDefault((Func<KeyCode, bool>)((KeyCode key) => !IsModifier(key)))); if ((int)mainKey == 0) { return KeyboardShortcut.Empty; } KeyCode[] array = list.Where((KeyCode key) => key != mainKey && IsModifier(key)).OrderBy(GetModifierSortOrder).ThenBy((KeyCode key) => (int)key) .ToArray(); return new KeyboardShortcut(mainKey, array); } private static bool IsHotkeyKeyValid(KeyCode key) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 return (int)key != 0 && ZInput.IsKeyCodeValid(key) && (int)key != 323 && (int)key != 324; } private static bool IsModifier(KeyCode key) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Invalid comparison between Unknown and I4 //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Invalid comparison between Unknown and I4 return (int)key == 313 || (int)key == 308 || (int)key == 307 || (int)key == 304 || (int)key == 303 || (int)key == 306 || (int)key == 305 || (int)key == 310 || (int)key == 309 || (int)key == 310 || (int)key == 309 || (int)key == 311 || (int)key == 312; } private static int GetModifierSortOrder(KeyCode key) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Invalid comparison between Unknown and I4 //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Invalid comparison between Unknown and I4 if ((int)key == 306 || (int)key == 305) { return 0; } if ((int)key == 308 || (int)key == 307 || (int)key == 313) { return 1; } if ((int)key == 304 || (int)key == 303) { return 2; } return 3; } private static string FormatHotkey(KeyboardShortcut shortcut) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 //IL_008e: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0) { return "None"; } IEnumerable<KeyCode> source = ((KeyboardShortcut)(ref shortcut)).Modifiers.Where(IsModifier).Distinct().OrderBy(GetModifierSortOrder) .ThenBy((KeyCode key) => (int)key); return string.Join(" + ", source.Select(GetKeyDisplayName).Concat(new string[1] { GetKeyDisplayName(((KeyboardShortcut)(ref shortcut)).MainKey) })); } private unsafe static string GetKeyDisplayName(KeyCode key) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) string text = ZInput.KeyCodeToDisplayName(key); return string.IsNullOrEmpty(text) ? ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString() : text; } private static bool IsShortcutDown(KeyboardShortcut shortcut) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0 || !ZInput.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey, true)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers) { if (!ZInput.GetKey(modifier, true)) { return false; } } return true; } private static string GetAlternativeUseHotkeyText() { string text = ((!ZInput.IsNonClassicFunctionality() || !ZInput.IsGamepadActive()) ? "$KEY_AltPlace" : "$KEY_JoyAltKeys"); return Localization.instance.Localize(text + " + $KEY_Use"); } private static string GetSleepHotkeyText(bool defaultUsesAlternativeAction) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (sleepHotkeyOverride.Value) { return FormatHotkey(sleepHotkey.Value); } return defaultUsesAlternativeAction ? GetAlternativeUseHotkeyText() : Localization.instance.Localize("$KEY_Use"); } private static string GetClaimHotkeyText() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) return claimHotkeyOverride.Value ? FormatHotkey(claimHotkey.Value) : Localization.instance.Localize("$KEY_Use"); } private static string GetActionHoverLine(string hotkey, string action) { return Localization.instance.Localize("[<color=yellow><b>" + hotkey + "</b></color>] " + action); } private static void CheckCustomHotkeys(Player player) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (!modEnabled.Value || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || Hud.InRadial()) { return; } bool flag = sleepHotkeyOverride.Value && IsShortcutDown(sleepHotkey.Value); bool flag2 = claimHotkeyOverride.Value && IsShortcutDown(claimHotkey.Value); if (!flag && !flag2) { return; } GameObject hoverObject = ((Humanoid)player).GetHoverObject(); if ((Object)(object)hoverObject == (Object)null) { return; } Bed componentInParent = hoverObject.GetComponentInParent<Bed>(); if ((Object)(object)componentInParent != (Object)null) { GetBedActions(componentInParent, out var firstAction, out var secondAction); if (flag && HasBedAction(firstAction, secondAction, BedAction.Sleep)) { InvokeCustomInteraction(player, hoverObject, HotkeyAction.Sleep, alt: true); } else if (flag2 && HasBedClaimAction(firstAction, secondAction)) { InvokeCustomInteraction(player, hoverObject, HotkeyAction.Claim, alt: false); } } else if (flag && (Object)(object)hoverObject.GetComponentInParent<Fireplace>() != (Object)null && CanSleep()) { InvokeCustomInteraction(player, hoverObject, HotkeyAction.Sleep, alt: true); } } private static void InvokeCustomInteraction(Player player, GameObject hoverObject, HotkeyAction action, bool alt) { activeHotkeyAction = action; try { player.Interact(hoverObject, false, alt); } finally { activeHotkeyAction = HotkeyAction.None; } } private static bool IsBedUnclaimed(Bed bed) { return (Object)(object)bed != (Object)null && string.IsNullOrEmpty(bed.GetOwnerName()); } private static void GetBedActions(Bed bed, out BedAction firstAction, out BedAction secondAction) { firstAction = BedAction.None; secondAction = BedAction.None; if ((Object)(object)bed == (Object)null) { return; } bool flag = IsBedUnclaimed(bed); bool flag2 = !flag && bed.IsMine(); bool flag3 = flag2 && bed.IsCurrent(); if (flag) { firstAction = BedAction.Claim; if (sleepingInNotOwnedBed.Value) { secondAction = BedAction.Sleep; } } else if (flag2 && !flag3) { firstAction = BedAction.SetSpawn; if (sleepingInNotOwnedBed.Value) { secondAction = BedAction.Sleep; } } else if (flag3 || sleepingInNotOwnedBed.Value) { firstAction = BedAction.Sleep; } } private static bool HasBedAction(BedAction firstAction, BedAction secondAction, BedAction action) { return firstAction == action || secondAction == action; } private static bool HasBedClaimAction(BedAction firstAction, BedAction secondAction) { return HasBedAction(firstAction, secondAction, BedAction.Claim) || HasBedAction(firstAction, secondAction, BedAction.SetSpawn); } private static bool BedSleepUsesAlternativeAction(Bed bed) { return (Object)(object)bed == (Object)null || !bed.IsMine() || !bed.IsCurrent(); } private static string GetBedActionLocalization(BedAction action) { return action switch { BedAction.Claim => "$piece_bed_claim", BedAction.SetSpawn => "$piece_bed_setspawn", BedAction.Sleep => "$piece_bed_sleep", _ => string.Empty, }; } private static string GetBedActionHotkeyText(Bed bed, BedAction action) { return (action == BedAction.Sleep) ? GetSleepHotkeyText(BedSleepUsesAlternativeAction(bed)) : GetClaimHotkeyText(); } private static void AppendBedAction(StringBuilder builder, Bed bed, BedAction action) { if (action != BedAction.None) { if (builder.Length > 0) { builder.Append('\n'); } builder.Append(GetActionHoverLine(GetBedActionHotkeyText(bed, action), GetBedActionLocalization(action))); } } private static bool ShouldSuppressNativeBedInteraction(Bed bed, bool repeat, bool alt) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) if (!modEnabled.Value || (Object)(object)bed == (Object)null || repeat || activeHotkeyAction != HotkeyAction.None) { return false; } GetBedActions(bed, out var firstAction, out var secondAction); bool flag = HasBedAction(firstAction, secondAction, BedAction.Sleep); bool flag2 = HasBedClaimAction(firstAction, secondAction); if (flag && sleepHotkeyOverride.Value && IsShortcutDown(sleepHotkey.Value)) { return true; } if (flag2 && claimHotkeyOverride.Value && IsShortcutDown(claimHotkey.Value)) { return true; } if (flag && sleepHotkeyOverride.Value && alt == BedSleepUsesAlternativeAction(bed)) { return true; } return flag2 && claimHotkeyOverride.Value && !alt; } private static bool CanSleep() { return IsSleepingWhileRestingAvailable() && EnvMan.CanSleep() && !((Character)Player.m_localPlayer).GetSEMan().HaveStatusEffect(SEMan.s_statusEffectWet) && !Player.m_localPlayer.IsSensed(); } private static bool IsSleepingWhileRestingAvailable() { return sleepingWhileResting.Value && restingTimer >= (float)sleepingWhileRestingSeconds.Value && PlayerInSleepPosition(); } private static bool PlayerInSleepPosition() { return modEnabled.Value && (Object)(object)Player.m_localPlayer != (Object)null && (((Character)Player.m_localPlayer).IsSitting() || ((Character)Player.m_localPlayer).IsAttached()); } private static Fireplace GetHoveredFireplace() { Player localPlayer = Player.m_localPlayer; GameObject val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetHoverObject() : null); return ((Object)(object)val != (Object)null) ? val.GetComponentInParent<Fireplace>() : null; } private static void UpdateAutomaticSleepFocus(float dt) { if (isSittingSleeping || !CanSleep()) { ResetAutomaticSleepFocus(); return; } Fireplace hoveredFireplace = GetHoveredFireplace(); if ((Object)(object)hoveredFireplace == (Object)null || !hoveredFireplace.IsBurning()) { ResetAutomaticSleepFocus(); return; } if ((Object)(object)automaticSleepFireplace != (Object)(object)hoveredFireplace) { automaticSleepFireplace = hoveredFireplace; automaticSleepFocusTimer = 0f; } automaticSleepFocusTimer = Mathf.Min(automaticSleepFocusTimer + dt, 20f); if (automaticSleepFocusTimer >= 20f) { SetSleepingWhileResting(sleeping: true); } } private static void ResetAutomaticSleepFocus() { automaticSleepFireplace = null; automaticSleepFocusTimer = 0f; } private static void SetSleepingWhileResting(bool sleeping) { Player localPlayer = Player.m_localPlayer; isSittingSleeping = sleeping; if (sleeping) { ResetAutomaticSleepFocus(); StartSleepLookAnimation(); } else { StopSleepLookAnimation(); } if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)((Character)localPlayer).m_nview == (Object)null) && ((Character)localPlayer).m_nview.IsValid()) { ZDO zDO = ((Character)localPlayer).m_nview.GetZDO(); if (zDO != null) { zDO.Set(sleepingWhileRestingZdoKey, sleeping); SetVanillaInBedState(zDO, sleeping && !debugPreventAutomaticSleep); sleepTextUpdateTimer = 0f; } } } private static void UpdateVanillaSleepRequest() { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)((Character)localPlayer).m_nview == (Object)null) && ((Character)localPlayer).m_nview.IsValid()) { ZDO zDO = ((Character)localPlayer).m_nview.GetZDO(); if (zDO != null) { SetVanillaInBedState(zDO, !debugPreventAutomaticSleep); } } } private static void SetVanillaInBedState(ZDO zdo, bool inBed) { if (zdo.GetBool(ZDOVars.s_inBed, false) != inBed) { zdo.Set(ZDOVars.s_inBed, inBed); } } private static void StartSleepLookAnimation() { //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_0120: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)sleepCharacterAnimEvent != (Object)null && (Object)(object)rightSleepLookTarget != (Object)null && (Object)(object)leftSleepLookTarget != (Object)null && (Object)(object)sleepLookTarget != (Object)null) { return; } Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { CharacterAnimEvent componentInChildren = ((Component)localPlayer).GetComponentInChildren<CharacterAnimEvent>(); Transform val = ((Component)localPlayer).transform.Find("Visual/Armature/Hips/RightUpLeg/RightLeg/RightFoot/RightToeBase/RightToeBase_end"); Transform val2 = ((Component)localPlayer).transform.Find("Visual/Armature/Hips/LeftUpLeg/LeftLeg/LeftFoot/LeftToeBase/LeftToeBase_end"); if (!((Object)(object)componentInChildren == (Object)null) && !((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { sleepCharacterAnimEvent = componentInChildren; previousSleepLookTarget = componentInChildren.m_lookAt; rightSleepLookTarget = val; leftSleepLookTarget = val2; GameObject val3 = new GameObject("JustSleepLookTarget"); sleepLookTarget = val3.transform; sleepLookTarget.SetParent(((Component)localPlayer).transform, true); sleepLookUsesRightTarget = true; sleepLookTransitioning = false; sleepLookTransitionToRight = false; sleepLookTimer = 0f; sleepLookTransitionTimer = 0f; sleepLookTarget.position = GetSleepLookPosition(rightSleepLookTarget); sleepCharacterAnimEvent.m_lookAt = sleepLookTarget; } } } private static Vector3 GetSleepLookPosition(Transform source) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_003e: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; return ((Object)(object)localPlayer != (Object)null && (Object)(object)source != (Object)null) ? Vector3.Lerp(source.position, ((Component)localPlayer).transform.position, 0.5f) : Vector3.zero; } private static void UpdateSleepLookAnimation(float dt) { //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) StartSleepLookAnimation(); if ((Object)(object)sleepCharacterAnimEvent == (Object)null || (Object)(object)rightSleepLookTarget == (Object)null || (Object)(object)leftSleepLookTarget == (Object)null || (Object)(object)sleepLookTarget == (Object)null) { return; } if (sleepLookTransitioning) { sleepLookTransitionTimer += dt; float num = (sleepLookTransitionToRight ? 1.6f : 0.4f); float num2 = Mathf.Clamp01(sleepLookTransitionTimer / num); float num3 = num2 * num2 * (3f - 2f * num2); Transform source = (sleepLookTransitionToRight ? rightSleepLookTarget : leftSleepLookTarget); sleepLookTarget.position = Vector3.Lerp(sleepLookTransitionStart, GetSleepLookPosition(source), num3); if (num2 >= 1f) { sleepLookUsesRightTarget = sleepLookTransitionToRight; sleepLookTransitioning = false; sleepLookTimer = 0f; sleepLookTarget.position = GetSleepLookPosition(source); } } else { Transform source2 = (sleepLookUsesRightTarget ? rightSleepLookTarget : leftSleepLookTarget); sleepLookTarget.position = GetSleepLookPosition(source2); sleepLookTimer += dt; float num4 = (sleepLookUsesRightTarget ? 3f : 0.25f); if (!(sleepLookTimer < num4)) { sleepLookTransitioning = true; sleepLookTransitionToRight = !sleepLookUsesRightTarget; sleepLookTransitionTimer = 0f; sleepLookTransitionStart = sleepLookTarget.position; } } } private static void StopSleepLookAnimation() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)sleepCharacterAnimEvent != (Object)null && (Object)(object)sleepCharacterAnimEvent.m_lookAt == (Object)(object)sleepLookTarget) { sleepCharacterAnimEvent.m_lookAt = previousSleepLookTarget; } if ((Object)(object)sleepLookTarget != (Object)null) { Object.Destroy((Object)(object)((Component)sleepLookTarget).gameObject); } sleepCharacterAnimEvent = null; previousSleepLookTarget = null; rightSleepLookTarget = null; leftSleepLookTarget = null; sleepLookTarget = null; sleepLookUsesRightTarget = false; sleepLookTransitioning = false; sleepLookTransitionToRight = false; sleepLookTimer = 0f; sleepLookTransitionTimer = 0f; sleepLookTransitionStart = Vector3.zero; } private static void UpdateSleepTexts(float dt) { //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) sleepTextUpdateTimer -= dt; if (sleepTextUpdateTimer > 0f) { return; } sleepTextUpdateTimer = 0.2f; if ((Object)(object)Chat.instance == (Object)null || (Object)(object)Hud.instance == (Object)null || Hud.instance.m_userHidden) { playersWithSleepText.Clear(); return; } playersWithSleepText.RemoveWhere((Player player) => !Object.op_Implicit((Object)(object)player)); foreach (Player s_player in Player.s_players) { if ((Object)(object)s_player == (Object)null || (Object)(object)((Character)s_player).m_nview == (Object)null || !((Character)s_player).m_nview.IsValid()) { continue; } ZDO zDO = ((Character)s_player).m_nview.GetZDO(); bool flag = zDO != null && zDO.GetBool(sleepingWhileRestingZdoKey, false); bool flag2 = playersWithSleepText.Contains(s_player); if (flag) { if (Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)s_player).transform.position) > 20f) { playersWithSleepText.Remove(s_player); } else if (!flag2 || Chat.instance.FindNpcText(((Component)s_player).gameObject) == null) { Chat.instance.SetNpcText(((Component)s_player).gameObject, Vector3.up, 20f, 0f, "", "Zzzzz...", false); playersWithSleepText.Add(s_player); } } else if (flag2) { Chat.instance.ClearNpcText(((Component)s_player).gameObject); playersWithSleepText.Remove(s_player); } } } private static void ClearSleepTexts() { if ((Object)(object)Chat.instance != (Object)null) { foreach (Player item in playersWithSleepText) { if ((Object)(object)item != (Object)null) { Chat.instance.ClearNpcText(((Component)item).gameObject); } } } playersWithSleepText.Clear(); } private static string FromPercent(double percent) { return "<sup><alpha=#ff>▀▀▀▀▀▀▀▀▀▀<alpha=#ff></sup>".Insert(Mathf.Clamp(Mathf.RoundToInt((float)percent * 10f), 0, 10) + 16, "<alpha=#33>"); } private static void UpdateScreenBlackener(float dt) { if ((Object)(object)screenBlackener == (Object)null) { return; } if (isSittingSleeping) { ((Component)screenBlackener).gameObject.SetActive(true); screenBlackener.alpha = Mathf.MoveTowards(screenBlackener.alpha, 0.96f, dt / 2f); return; } if ((Object)(object)automaticSleepFireplace != (Object)null) { ((Component)screenBlackener).gameObject.SetActive(true); float num = Mathf.Clamp01(automaticSleepFocusTimer / 20f) * 0.96f; screenBlackener.alpha = Mathf.MoveTowards(screenBlackener.alpha, num, dt); return; } screenBlackener.alpha = Mathf.MoveTowards(screenBlackener.alpha, 0f, dt / 2f); if (screenBlackener.alpha <= 0f) { ((Component)screenBlackener).gameObject.SetActive(false); } } }