Initial Release

Added UIExpansionKit support, moved Harmony patches to own cs, added accidental feature that disables automatic state change, added option to lower FPS while in sleep state.
This commit is contained in:
NotAKidoS 2022-10-14 02:00:05 -05:00
parent d033d3750e
commit e6784b967e
5 changed files with 80 additions and 30 deletions

View file

@ -7,11 +7,13 @@ namespace Blackout;
public class Blackout : MelonMod
{
private static bool inVR;
private static MelonPreferences_Category m_categoryBlackout;
private static MelonPreferences_Entry<bool> m_entryEnabled, m_entryHudMessages;
//private static MelonPreferences_Entry<bool> m_entryVROnly;
private static MelonPreferences_Entry<float>
public const string SettingsCategory = "Blackout";
internal static bool inVR;
internal static MelonPreferences_Category m_categoryBlackout;
internal static MelonPreferences_Entry<bool> m_entryEnabled, m_entryHudMessages, m_entryDropFPSOnSleep;
//internal static MelonPreferences_Entry<bool> m_entryVROnly;
internal static MelonPreferences_Entry<float>
m_entryDrowsyThreshold, m_entryAwakeThreshold,
m_entryDrowsyModeTimer, m_entrySleepModeTimer,
m_entryDrowsyDimStrength;
@ -19,8 +21,9 @@ public class Blackout : MelonMod
public override void OnApplicationStart()
{
m_categoryBlackout = MelonPreferences.CreateCategory(nameof(Blackout));
m_entryEnabled = m_categoryBlackout.CreateEntry<bool>("Enabled", true, description: "Dim screen when sleeping.");
m_entryEnabled = m_categoryBlackout.CreateEntry<bool>("Automatic State Change", true, description: "Dim screen when there is no movement for a while.");
m_entryHudMessages = m_categoryBlackout.CreateEntry<bool>("Hud Messages", false, description: "Notify on state change.");
m_entryDropFPSOnSleep = m_categoryBlackout.CreateEntry<bool>("Lower FPS While Sleep", false, description: "Lowers FPS to 5 while in Sleep State.");
m_entryDrowsyThreshold = m_categoryBlackout.CreateEntry<float>("Drowsy Threshold", 1f, description: "Degrees of movement to return partial vision.");
m_entryAwakeThreshold = m_categoryBlackout.CreateEntry<float>("Awake Threshold", 12f, description: "Degrees of movement to return full vision.");
m_entryDrowsyModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Drowsy Time", 3f, description: "How many minutes without movement until enter drowsy mode.");
@ -29,8 +32,12 @@ public class Blackout : MelonMod
//m_entryVROnly = m_categoryBlackout.CreateEntry<bool>("VR Only", false, description: "Only enable mod in VR.");
m_categoryBlackout.SaveToFile(false);
//please tell me a better way to do this
//this is fucking
//gross pleas etell me how to do this but not like this
m_entryEnabled.OnValueChangedUntyped += OnEnabled;
m_entryHudMessages.OnValueChangedUntyped += OnUpdateSettings;
m_entryDropFPSOnSleep.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyThreshold.OnValueChangedUntyped += OnUpdateSettings;
m_entryAwakeThreshold.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyModeTimer.OnValueChangedUntyped += OnUpdateSettings;
@ -38,6 +45,13 @@ public class Blackout : MelonMod
m_entryDrowsyDimStrength.OnValueChangedUntyped += OnUpdateSettings;
//m_entryVROnly.OnValueChangedUntyped += OnUpdateSettings;
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
//UIExpansionKit addon
if (MelonHandler.Mods.Any(it => it.Info.Name == "UI Expansion Kit"))
{
MelonLogger.Msg("Initializing UIExpansionKit support.");
UiExtensionsAddon.Init();
}
}
System.Collections.IEnumerator WaitForLocalPlayer()
@ -70,20 +84,11 @@ public class Blackout : MelonMod
BlackoutController.Instance.SleepModeTimer = m_entrySleepModeTimer.Value;
BlackoutController.Instance.DrowsyDimStrength = m_entryDrowsyDimStrength.Value;
BlackoutController.Instance.HudMessages = m_entryHudMessages.Value;
BlackoutController.Instance.DropFPSOnSleep = m_entryDropFPSOnSleep.Value;
}
//Support for changing VRMode during runtime.
[HarmonyPatch]
private class HarmonyPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), "CalibrateAvatar")]
private static void CheckVRModeSwitch()
{
if (inVR != PlayerSetup.Instance._inVr)
{
BlackoutController.Instance.SetupBlackoutInstance();
}
}
}
//UIExpansionKit actions
public static void AwakeState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
public static void DrowsyState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Drowsy);
public static void SleepingState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Sleeping);
}