using System; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace SleepResetPowers; [BepInPlugin("flashbak.sleepresetpowers", "SleepResetsForsakenPowers", "1.0.1")] public class SleepResetPowersPlugin : BaseUnityPlugin { public const string PluginGuid = "flashbak.sleepresetpowers"; public const string PluginName = "SleepResetsForsakenPowers"; public const string PluginVersion = "1.0.1"; private static readonly FieldInfo CooldownField = AccessTools.Field(typeof(Player), "m_guardianPowerCooldown"); private static readonly MethodInfo InBedMethod = AccessTools.Method(typeof(Player), "InBed", (Type[])null, (Type[])null); private static ManualLogSource Log; private ConfigEntry _enabled; private ConfigEntry _verboseLogging; private bool _wasInBed; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; _enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Master switch. When false, cooldowns are never reset by this mod."); _verboseLogging = ((BaseUnityPlugin)this).Config.Bind("General", "VerboseLogging", false, "Log a message every time a Forsaken Power cooldown is reset (useful for testing)."); if (CooldownField == null) { Log.LogError((object)"Could not find Player.m_guardianPowerCooldown — the game's field may have been renamed by an update. Cooldown reset is disabled."); } Log.LogInfo((object)"SleepResetsForsakenPowers v1.0.1 loaded."); } private void Update() { if (!_enabled.Value || CooldownField == null) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { _wasInBed = false; return; } bool flag = IsInBed(localPlayer); if (!flag && _wasInBed) { ResetGuardianPowerCooldown(localPlayer); } _wasInBed = flag; } private static bool IsInBed(Player player) { if (InBedMethod != null) { return (bool)InBedMethod.Invoke(player, null); } ZNetView component = ((Component)player).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { return component.GetZDO().GetBool("inBed", false); } return false; } private void ResetGuardianPowerCooldown(Player player) { float num = (float)CooldownField.GetValue(player); if (!(num <= 0f)) { CooldownField.SetValue(player, 0f); if (_verboseLogging.Value) { Log.LogInfo((object)$"Player woke up — reset Forsaken Power cooldown (was {num:0.#}s)."); } } } }