mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-01 22:09:23 +00:00
bump
This commit is contained in:
parent
24d8c6a3ec
commit
65d325d4fd
11 changed files with 277 additions and 109 deletions
|
@ -1,7 +1,7 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Blackout;
|
namespace NAK.Melons.Blackout;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
<Reference Include="Assembly-CSharp-firstpass">
|
<Reference Include="Assembly-CSharp-firstpass">
|
||||||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
|
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="BTKUILib">
|
||||||
|
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\BTKUILib.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Cohtml.Runtime">
|
<Reference Include="Cohtml.Runtime">
|
||||||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll</HintPath>
|
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
|
@ -5,7 +5,7 @@ using MelonLoader;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Blackout;
|
namespace NAK.Melons.Blackout;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -30,28 +30,37 @@ namespace Blackout;
|
||||||
public class BlackoutController : MonoBehaviour
|
public class BlackoutController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static BlackoutController Instance;
|
public static BlackoutController Instance;
|
||||||
|
|
||||||
|
// The current state of the player's consciousness.
|
||||||
public BlackoutState CurrentState = BlackoutState.Awake;
|
public BlackoutState CurrentState = BlackoutState.Awake;
|
||||||
|
|
||||||
//degrees of movement to give partial vision
|
// Should the states automatically change based on time?
|
||||||
public float drowsyThreshold = 1f;
|
public bool AutomaticStateChange = true;
|
||||||
//degrees of movement to give complete vision
|
// Should the sleep state be automatically transitioned to? Some may prefer drowsy state only due to dimming.
|
||||||
public float wakeThreshold = 12f;
|
public bool AutoSleepState = true;
|
||||||
|
|
||||||
//how long without movement until the screen dims
|
// The minimum amount of movement required to partially restore vision.
|
||||||
public float DrowsyModeTimer = 3f; // MINUTES
|
public float drowsyThreshold = 2f;
|
||||||
//how long should the wake state last before return
|
// The minimum amount of movement required to fully restore vision.
|
||||||
public float SleepModeTimer = 10f; // SECONDS
|
public float wakeThreshold = 4f;
|
||||||
|
|
||||||
//how much does DrowsyMode affect the screen
|
// The amount of time the player must remain still to enter drowsy state (in minutes).
|
||||||
public float DrowsyDimStrength = 0.5f;
|
public float DrowsyModeTimer = 3f;
|
||||||
|
// The amount of time the player must remain in drowsy state before entering sleep state (in seconds).
|
||||||
|
public float SleepModeTimer = 10f;
|
||||||
|
|
||||||
//this is uh, not work well- might rewrite now that i know how this should work
|
// The amount by which DrowsyMode affects the screen.
|
||||||
public bool HudMessages = false;
|
public float DrowsyDimStrength = 0.6f;
|
||||||
|
// Should DrowsyDimStrength be affected by velocity?
|
||||||
|
public bool DrowsyVelocityMultiplier = true;
|
||||||
|
|
||||||
//lower FPS while in sleep mode
|
// Whether to display HUD messages.
|
||||||
|
public bool HudMessages = true;
|
||||||
|
|
||||||
|
// Whether to lower the frame rate while in sleep mode.
|
||||||
public bool DropFPSOnSleep = false;
|
public bool DropFPSOnSleep = false;
|
||||||
|
|
||||||
|
// The available states of consciousness.
|
||||||
public enum BlackoutState
|
public enum BlackoutState
|
||||||
{
|
{
|
||||||
Awake = 0,
|
Awake = 0,
|
||||||
|
@ -60,14 +69,16 @@ public class BlackoutController : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
private Camera activeModeCam;
|
private Camera activeModeCam;
|
||||||
private Quaternion oldHeadRotation = Quaternion.identity;
|
private Vector3 headVelocity = Vector3.zero;
|
||||||
private float angularMovement = 0f;
|
private Vector3 lastHeadPos = Vector3.zero;
|
||||||
private float curTime = 0f;
|
private float curTime = 0f;
|
||||||
private float lastAwakeTime = 0f;
|
private float lastAwakeTime = 0f;
|
||||||
private int nextUpdate = 1;
|
|
||||||
private Animator blackoutAnimator;
|
private Animator blackoutAnimator;
|
||||||
private int targetFPS;
|
private int targetFPS;
|
||||||
|
|
||||||
|
public void ChangeBlackoutStateFromInt(int state) => ChangeBlackoutState((BlackoutState)state);
|
||||||
|
|
||||||
|
// Changes the player's state of consciousness.
|
||||||
public void ChangeBlackoutState(BlackoutState newState)
|
public void ChangeBlackoutState(BlackoutState newState)
|
||||||
{
|
{
|
||||||
if (!blackoutAnimator) return;
|
if (!blackoutAnimator) return;
|
||||||
|
@ -75,47 +86,61 @@ public class BlackoutController : MonoBehaviour
|
||||||
|
|
||||||
lastAwakeTime = curTime;
|
lastAwakeTime = curTime;
|
||||||
|
|
||||||
|
// Update the blackout animator based on the new state.
|
||||||
switch (newState)
|
switch (newState)
|
||||||
{
|
{
|
||||||
case BlackoutState.Awake:
|
case BlackoutState.Awake:
|
||||||
blackoutAnimator.SetBool("BlackoutState.Drowsy", false);
|
blackoutAnimator.SetBool("BlackoutState.Drowsy", false);
|
||||||
blackoutAnimator.SetBool("BlackoutState.Sleeping", false);
|
blackoutAnimator.SetBool("BlackoutState.Sleeping", false);
|
||||||
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength);
|
drowsyMagnitude = 0f;
|
||||||
break;
|
break;
|
||||||
case BlackoutState.Drowsy:
|
case BlackoutState.Drowsy:
|
||||||
blackoutAnimator.SetBool("BlackoutState.Drowsy", true);
|
blackoutAnimator.SetBool("BlackoutState.Drowsy", true);
|
||||||
blackoutAnimator.SetBool("BlackoutState.Sleeping", false);
|
blackoutAnimator.SetBool("BlackoutState.Sleeping", false);
|
||||||
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength);
|
drowsyMagnitude = 0f;
|
||||||
break;
|
break;
|
||||||
case BlackoutState.Sleeping:
|
case BlackoutState.Sleeping:
|
||||||
blackoutAnimator.SetBool("BlackoutState.Drowsy", false);
|
blackoutAnimator.SetBool("BlackoutState.Drowsy", false);
|
||||||
blackoutAnimator.SetBool("BlackoutState.Sleeping", true);
|
blackoutAnimator.SetBool("BlackoutState.Sleeping", true);
|
||||||
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength);
|
drowsyMagnitude = 1f;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the current state and send a HUD message if enabled.
|
||||||
BlackoutState prevState = CurrentState;
|
BlackoutState prevState = CurrentState;
|
||||||
CurrentState = newState;
|
CurrentState = newState;
|
||||||
SendHUDMessage($"Exiting {prevState} and entering {newState} state.");
|
SendHUDMessage($"Exiting {prevState} and entering {newState} state.");
|
||||||
ChangeTargetFPS();
|
ChangeTargetFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize BlackoutInstance object
|
public void AdjustDrowsyDimStrength(float multiplier = 1f)
|
||||||
|
{
|
||||||
|
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength * multiplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the BlackoutInstance object.
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
|
// Get the blackout asset and instantiate it.
|
||||||
GameObject blackoutAsset = AssetsHandler.GetAsset("Assets/BundledAssets/Blackout/Blackout.prefab");
|
GameObject blackoutAsset = AssetsHandler.GetAsset("Assets/BundledAssets/Blackout/Blackout.prefab");
|
||||||
GameObject blackoutGO = Instantiate(blackoutAsset, new Vector3(0, 0, 0), Quaternion.identity);
|
GameObject blackoutGO = Instantiate(blackoutAsset, new Vector3(0, 0, 0), Quaternion.identity);
|
||||||
|
|
||||||
if (blackoutGO == null) return;
|
|
||||||
|
|
||||||
blackoutGO.name = "BlackoutInstance";
|
blackoutGO.name = "BlackoutInstance";
|
||||||
|
|
||||||
|
// Get the blackout animator component.
|
||||||
blackoutAnimator = blackoutGO.GetComponent<Animator>();
|
blackoutAnimator = blackoutGO.GetComponent<Animator>();
|
||||||
|
if (!blackoutAnimator)
|
||||||
|
{
|
||||||
|
MelonLogger.Error("Blackout: Could not find blackout animator component!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetupBlackoutInstance();
|
SetupBlackoutInstance();
|
||||||
|
|
||||||
//we dont want this to ever disable (unless in awake state maybe?
|
//we dont want this to ever disable
|
||||||
Camera.onPreRender += OnPreRender;
|
Camera.onPreRender += OnPreRender;
|
||||||
Camera.onPostRender += OnPostRender;
|
Camera.onPostRender += OnPostRender;
|
||||||
}
|
}
|
||||||
|
@ -123,41 +148,45 @@ public class BlackoutController : MonoBehaviour
|
||||||
//Automatic State Change
|
//Automatic State Change
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
//only run once a second, angularMovement is "smoothed out" at high FPS otherwise
|
//get the current position of the player's head
|
||||||
//for the sake of responsivness while user is in a sleepy state, this might be removed to prevent confusion...
|
Vector3 curHeadPos = activeModeCam.transform.position;
|
||||||
curTime = Time.time;
|
//calculate the player's head velocity by taking the difference in position
|
||||||
if (!(curTime >= nextUpdate)) return;
|
headVelocity = (curHeadPos - lastHeadPos) / Time.deltaTime;
|
||||||
nextUpdate = Mathf.FloorToInt(curTime) + 1;
|
//store the current head position for use in the next frame
|
||||||
|
lastHeadPos = curHeadPos;
|
||||||
|
|
||||||
//get difference between last frame rotation and current rotation
|
if (AutomaticStateChange)
|
||||||
Quaternion currentHeadRotation = activeModeCam.transform.rotation;
|
|
||||||
angularMovement = Quaternion.Angle(oldHeadRotation, currentHeadRotation);
|
|
||||||
oldHeadRotation = currentHeadRotation;
|
|
||||||
|
|
||||||
//handle current state
|
|
||||||
switch (CurrentState)
|
|
||||||
{
|
{
|
||||||
case BlackoutState.Awake:
|
curTime = Time.time;
|
||||||
HandleAwakeState();
|
//handle current state
|
||||||
break;
|
switch (CurrentState)
|
||||||
case BlackoutState.Drowsy:
|
{
|
||||||
HandleDrowsyState();
|
case BlackoutState.Awake:
|
||||||
break;
|
HandleAwakeState();
|
||||||
case BlackoutState.Sleeping:
|
break;
|
||||||
HandleSleepingState();
|
case BlackoutState.Drowsy:
|
||||||
break;
|
HandleDrowsyState();
|
||||||
default:
|
break;
|
||||||
break;
|
case BlackoutState.Sleeping:
|
||||||
|
HandleSleepingState();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CalculateDimmingMultiplier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable()
|
public void OnEnable()
|
||||||
{
|
{
|
||||||
curTime = Time.time;
|
curTime = Time.time;
|
||||||
lastAwakeTime = curTime;
|
lastAwakeTime = curTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable()
|
public void OnDisable()
|
||||||
{
|
{
|
||||||
ChangeBlackoutState(BlackoutState.Awake);
|
ChangeBlackoutState(BlackoutState.Awake);
|
||||||
}
|
}
|
||||||
|
@ -204,8 +233,17 @@ public class BlackoutController : MonoBehaviour
|
||||||
if (!CohtmlHud.Instance || !HudMessages) return;
|
if (!CohtmlHud.Instance || !HudMessages) return;
|
||||||
|
|
||||||
StringBuilder secondmessage = new StringBuilder();
|
StringBuilder secondmessage = new StringBuilder();
|
||||||
if (enabled)
|
if (AutomaticStateChange)
|
||||||
secondmessage = new StringBuilder(GetNextStateTimer().ToString() + " seconds till next state change.");
|
{
|
||||||
|
if (CurrentState == BlackoutState.Drowsy && !AutoSleepState)
|
||||||
|
{
|
||||||
|
secondmessage = new StringBuilder("AutoSleepState is disabled. Staying in Drowsy State.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
secondmessage = new StringBuilder(GetNextStateTimer().ToString() + " seconds till next state change.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CohtmlHud.Instance.ViewDropTextImmediate("Blackout", message, secondmessage.ToString());
|
CohtmlHud.Instance.ViewDropTextImmediate("Blackout", message, secondmessage.ToString());
|
||||||
}
|
}
|
||||||
|
@ -223,7 +261,7 @@ public class BlackoutController : MonoBehaviour
|
||||||
private void HandleAwakeState()
|
private void HandleAwakeState()
|
||||||
{
|
{
|
||||||
//small movement should reset sleep timer
|
//small movement should reset sleep timer
|
||||||
if (angularMovement > drowsyThreshold)
|
if (headVelocity.magnitude > drowsyThreshold)
|
||||||
{
|
{
|
||||||
lastAwakeTime = curTime;
|
lastAwakeTime = curTime;
|
||||||
}
|
}
|
||||||
|
@ -233,23 +271,51 @@ public class BlackoutController : MonoBehaviour
|
||||||
ChangeBlackoutState(BlackoutState.Drowsy);
|
ChangeBlackoutState(BlackoutState.Drowsy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float fadeSpeed = 0.8f; // The speed at which the value fades back to 0 or increases
|
||||||
|
public float minimumThreshold = 0.5f; // The minimum value that the drowsy magnitude can have
|
||||||
|
public float drowsyMagnitude = 0f;
|
||||||
|
|
||||||
|
private void CalculateDimmingMultiplier()
|
||||||
|
{
|
||||||
|
if (!DrowsyVelocityMultiplier)
|
||||||
|
{
|
||||||
|
AdjustDrowsyDimStrength();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float normalizedMagnitude = headVelocity.magnitude / wakeThreshold;
|
||||||
|
float targetMagnitude = 1f - normalizedMagnitude;
|
||||||
|
targetMagnitude = Mathf.Max(targetMagnitude, minimumThreshold);
|
||||||
|
drowsyMagnitude = Mathf.Lerp(drowsyMagnitude, targetMagnitude, fadeSpeed * Time.deltaTime);
|
||||||
|
AdjustDrowsyDimStrength(drowsyMagnitude);
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleDrowsyState()
|
private void HandleDrowsyState()
|
||||||
{
|
{
|
||||||
//hard movement should exit drowsy state
|
//hard movement should exit drowsy state
|
||||||
if (angularMovement > wakeThreshold)
|
if (headVelocity.magnitude > wakeThreshold)
|
||||||
{
|
{
|
||||||
ChangeBlackoutState(BlackoutState.Awake);
|
ChangeBlackoutState(BlackoutState.Awake);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//small movement should reset sleep timer
|
||||||
|
if (headVelocity.magnitude > drowsyThreshold)
|
||||||
|
{
|
||||||
|
lastAwakeTime = curTime;
|
||||||
}
|
}
|
||||||
//enter full sleep mode
|
//enter full sleep mode
|
||||||
if (curTime > lastAwakeTime + SleepModeTimer)
|
if (AutoSleepState && curTime > lastAwakeTime + SleepModeTimer)
|
||||||
{
|
{
|
||||||
ChangeBlackoutState(BlackoutState.Sleeping);
|
ChangeBlackoutState(BlackoutState.Sleeping);
|
||||||
}
|
}
|
||||||
|
CalculateDimmingMultiplier();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleSleepingState()
|
private void HandleSleepingState()
|
||||||
{
|
{
|
||||||
//small movement should enter drowsy state
|
//small movement should enter drowsy state
|
||||||
if (angularMovement > drowsyThreshold)
|
if (headVelocity.magnitude > drowsyThreshold)
|
||||||
{
|
{
|
||||||
ChangeBlackoutState(BlackoutState.Drowsy);
|
ChangeBlackoutState(BlackoutState.Drowsy);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ using ABI_RC.Core.Savior;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
|
|
||||||
namespace Blackout;
|
namespace NAK.Melons.Blackout.HarmonyPatches;
|
||||||
|
|
||||||
[HarmonyPatch]
|
[HarmonyPatch]
|
||||||
internal class HarmonyPatches
|
internal class HarmonyPatches
|
||||||
|
|
63
Blackout/Integrations/BTKUIAddon.cs
Normal file
63
Blackout/Integrations/BTKUIAddon.cs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
using BTKUILib;
|
||||||
|
using BTKUILib.UIObjects;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace NAK.Melons.Blackout;
|
||||||
|
|
||||||
|
public static class BTKUIAddon
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
//Add myself to the Misc Menu
|
||||||
|
Page miscPage = QuickMenuAPI.MiscTabPage;
|
||||||
|
Category miscCategory = miscPage.AddCategory(Blackout.SettingsCategory);
|
||||||
|
|
||||||
|
AddMelonToggle(ref miscCategory, Blackout.m_entryEnabled);
|
||||||
|
|
||||||
|
//Add my own page to not clog up Misc Menu
|
||||||
|
|
||||||
|
Page blackoutPage = miscCategory.AddPage("Blackout Settings", "", "Configure the settings for Blackout.", "Blackout");
|
||||||
|
blackoutPage.MenuTitle = "Blackout Settings";
|
||||||
|
blackoutPage.MenuSubtitle = "Dim screen after set time of sitting still, or configure with manual control. Should be nice for VR sleeping.";
|
||||||
|
|
||||||
|
Category blackoutCategory = blackoutPage.AddCategory("Blackout");
|
||||||
|
|
||||||
|
AddMelonToggle(ref blackoutCategory, Blackout.m_entryEnabled);
|
||||||
|
|
||||||
|
//manual state changing
|
||||||
|
var state_Awake = blackoutCategory.AddButton("Awake State", null, "Enter the Awake State.");
|
||||||
|
state_Awake.OnPress += () => BlackoutController.Instance?.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
|
||||||
|
var state_Drowsy = blackoutCategory.AddButton("Drowsy State", null, "Enter the Drowsy State.");
|
||||||
|
state_Drowsy.OnPress += () => BlackoutController.Instance?.ChangeBlackoutState(BlackoutController.BlackoutState.Drowsy);
|
||||||
|
var state_Sleeping = blackoutCategory.AddButton("Sleeping State", null, "Enter the Sleeping State.");
|
||||||
|
state_Sleeping.OnPress += () => BlackoutController.Instance?.ChangeBlackoutState(BlackoutController.BlackoutState.Sleeping);
|
||||||
|
|
||||||
|
//dimming strength
|
||||||
|
AddMelonSlider(ref blackoutPage, Blackout.m_entryDrowsyDimStrength, 0f, 1f);
|
||||||
|
|
||||||
|
//velocity dim multiplier
|
||||||
|
AddMelonToggle(ref blackoutCategory, Blackout.m_entryDrowsyVelocityMultiplier);
|
||||||
|
|
||||||
|
//hud messages
|
||||||
|
AddMelonToggle(ref blackoutCategory, Blackout.m_entryHudMessages);
|
||||||
|
|
||||||
|
//lower fps while sleep (desktop)
|
||||||
|
AddMelonToggle(ref blackoutCategory, Blackout.m_entryDropFPSOnSleep);
|
||||||
|
|
||||||
|
//auto sleep state
|
||||||
|
AddMelonToggle(ref blackoutCategory, Blackout.m_entryAutoSleepState);
|
||||||
|
|
||||||
|
//i will add the rest of the settings once BTKUILib supports int input
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddMelonToggle(ref Category category, MelonLoader.MelonPreferences_Entry<bool> entry)
|
||||||
|
{
|
||||||
|
category.AddToggle(entry.DisplayName, entry.Description, entry.Value).OnValueUpdated += b => entry.Value = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddMelonSlider(ref Page page, MelonLoader.MelonPreferences_Entry<float> entry, float min, float max)
|
||||||
|
{
|
||||||
|
page.AddSlider(entry.DisplayName, entry.Description, entry.Value, min, max).OnValueUpdated += f => entry.Value = f;
|
||||||
|
}
|
||||||
|
}
|
29
Blackout/Integrations/UIExpansionKitAddon.cs
Normal file
29
Blackout/Integrations/UIExpansionKitAddon.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using UIExpansionKit.API;
|
||||||
|
|
||||||
|
namespace NAK.Melons.Blackout;
|
||||||
|
public static class UIExpansionKitAddon
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
ive spent hours debugging this, and no matter what the buttons wont actually call the actions
|
||||||
|
from logging shit to straight up closing the game, nothing
|
||||||
|
|
||||||
|
implementing btkuilib support, but gonna leave this shit as a reminder why to not use uiexpansionkit
|
||||||
|
also because it **used to work**... a game update broke it and uiexpansionkit hasnt updated since
|
||||||
|
|
||||||
|
what pisses me off more, is that DesktopVRSwitch works, and that was originally copied from Blackout -_-
|
||||||
|
https://github.com/NotAKidOnSteam/DesktopVRSwitch/blob/main/DesktopVRSwitch/UIExpansionKitAddon.cs
|
||||||
|
**/
|
||||||
|
var settings = ExpansionKitApi.GetSettingsCategory(Blackout.SettingsCategory);
|
||||||
|
settings.AddSimpleButton("Awake State", AwakeState);
|
||||||
|
settings.AddSimpleButton("Drowsy State", DrowsyState);
|
||||||
|
settings.AddSimpleButton("Sleep State", SleepingState);
|
||||||
|
}
|
||||||
|
//UIExpansionKit actions
|
||||||
|
internal static void AwakeState() => BlackoutController.Instance?.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
|
||||||
|
internal static void DrowsyState() => BlackoutController.Instance?.ChangeBlackoutState(BlackoutController.BlackoutState.Drowsy);
|
||||||
|
internal static void SleepingState() => BlackoutController.Instance?.ChangeBlackoutState(BlackoutController.BlackoutState.Sleeping);
|
||||||
|
}
|
|
@ -2,43 +2,58 @@
|
||||||
using ABI_RC.Core.Savior;
|
using ABI_RC.Core.Savior;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
|
|
||||||
namespace Blackout;
|
namespace NAK.Melons.Blackout;
|
||||||
|
|
||||||
public class Blackout : MelonMod
|
public class Blackout : MelonMod
|
||||||
{
|
{
|
||||||
internal static bool inVR;
|
internal static bool inVR;
|
||||||
internal const string SettingsCategory = "Blackout";
|
internal const string SettingsCategory = "Blackout";
|
||||||
|
|
||||||
private static MelonPreferences_Category m_categoryBlackout;
|
internal static MelonPreferences_Category m_categoryBlackout;
|
||||||
private static MelonPreferences_Entry<bool> m_entryEnabled, m_entryHudMessages, m_entryDropFPSOnSleep;
|
internal static MelonPreferences_Entry<bool>
|
||||||
private static MelonPreferences_Entry<float>
|
m_entryEnabled,
|
||||||
|
m_entryAutoSleepState,
|
||||||
|
m_entryHudMessages,
|
||||||
|
m_entryDropFPSOnSleep,
|
||||||
|
m_entryDrowsyVelocityMultiplier;
|
||||||
|
internal static MelonPreferences_Entry<float>
|
||||||
m_entryDrowsyThreshold, m_entryAwakeThreshold,
|
m_entryDrowsyThreshold, m_entryAwakeThreshold,
|
||||||
m_entryDrowsyModeTimer, m_entrySleepModeTimer,
|
m_entryDrowsyModeTimer, m_entrySleepModeTimer,
|
||||||
m_entryDrowsyDimStrength;
|
m_entryDrowsyDimStrength;
|
||||||
|
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
m_categoryBlackout = MelonPreferences.CreateCategory(nameof(Blackout));
|
m_categoryBlackout = MelonPreferences.CreateCategory(SettingsCategory);
|
||||||
m_entryEnabled = m_categoryBlackout.CreateEntry<bool>("Automatic State Change", true, description: "Dim screen when there is no movement for a while.");
|
m_entryEnabled = m_categoryBlackout.CreateEntry<bool>("Automatic State Change", true, description: "Should the screen automatically dim if head is still for enough time?");
|
||||||
m_entryHudMessages = m_categoryBlackout.CreateEntry<bool>("Hud Messages", false, description: "Notify on state change.");
|
m_entryEnabled.OnEntryValueChangedUntyped.Subscribe(OnUpdateEnabled);
|
||||||
m_entryDropFPSOnSleep = m_categoryBlackout.CreateEntry<bool>("Lower FPS While Sleep", false, description: "Lowers FPS to 5 while in Sleep State.");
|
m_entryHudMessages = m_categoryBlackout.CreateEntry<bool>("Hud Messages", true, description: "Notify on state change.");
|
||||||
m_entryDrowsyThreshold = m_categoryBlackout.CreateEntry<float>("Drowsy Threshold", 1f, description: "Degrees of movement to return partial vision.");
|
m_entryDropFPSOnSleep = m_categoryBlackout.CreateEntry<bool>("Limit FPS While Sleep", false, description: "Limits FPS to 5 while in Sleep State. This only works in Desktop, as SteamVR/HMD handles VR FPS.");
|
||||||
m_entryAwakeThreshold = m_categoryBlackout.CreateEntry<float>("Awake Threshold", 12f, description: "Degrees of movement to return full vision.");
|
m_entryDrowsyVelocityMultiplier = m_categoryBlackout.CreateEntry<bool>("Drowsy Velocity Multiplier", true, description: "Should head velocity act as a multiplier to Drowsy Dim Strength?");
|
||||||
|
m_entryAutoSleepState = m_categoryBlackout.CreateEntry<bool>("Auto Sleep State", true, description: "Should the sleep state be used during Automatic State Change?");
|
||||||
|
m_entryDrowsyThreshold = m_categoryBlackout.CreateEntry<float>("Drowsy Threshold", 2f, description: "Velocity to return partial vision.");
|
||||||
|
m_entryAwakeThreshold = m_categoryBlackout.CreateEntry<float>("Awake Threshold", 4f, description: "Velocity to return full vision.");
|
||||||
m_entryDrowsyModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Drowsy Time (Minutes)", 3f, description: "How many minutes without movement until enter drowsy mode.");
|
m_entryDrowsyModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Drowsy Time (Minutes)", 3f, description: "How many minutes without movement until enter drowsy mode.");
|
||||||
m_entrySleepModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Sleep Time (Seconds)", 10f, description: "How many seconds without movement until enter sleep mode.");
|
m_entrySleepModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Sleep Time (Seconds)", 10f, description: "How many seconds without movement until enter sleep mode.");
|
||||||
m_entryDrowsyDimStrength = m_categoryBlackout.CreateEntry<float>("Drowsy Dim Strength", 0.5f, description: "How strong of a dimming effect should drowsy mode have.");
|
m_entryDrowsyDimStrength = m_categoryBlackout.CreateEntry<float>("Drowsy Dim Strength", 0.6f, description: "How strong of a dimming effect should drowsy mode have.");
|
||||||
m_categoryBlackout.SaveToFile(false);
|
|
||||||
|
|
||||||
foreach (var setting in m_categoryBlackout.Entries)
|
foreach (var setting in m_categoryBlackout.Entries)
|
||||||
{
|
{
|
||||||
setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
|
if (!setting.OnEntryValueChangedUntyped.GetSubscribers().Any())
|
||||||
|
setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
//UIExpansionKit addon
|
//UIExpansionKit addon
|
||||||
if (MelonMod.RegisteredMelons.Any(it => it.Info.Name == "UI Expansion Kit"))
|
if (MelonMod.RegisteredMelons.Any(it => it.Info.Name == "UI Expansion Kit"))
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Initializing UIExpansionKit support.");
|
MelonLogger.Msg("Initializing UIExpansionKit support.");
|
||||||
UiExtensionsAddon.Init();
|
UIExpansionKitAddon.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
//BTKUILib addon
|
||||||
|
if (MelonMod.RegisteredMelons.Any(it => it.Info.Name == "BTKUILib"))
|
||||||
|
{
|
||||||
|
MelonLogger.Msg("Initializing BTKUILib support.");
|
||||||
|
BTKUIAddon.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
||||||
|
@ -60,32 +75,37 @@ public class Blackout : MelonMod
|
||||||
yield return null;
|
yield return null;
|
||||||
|
|
||||||
UpdateAllSettings();
|
UpdateAllSettings();
|
||||||
|
OnEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnabled()
|
private void OnEnabled()
|
||||||
{
|
{
|
||||||
if (!BlackoutController.Instance) return;
|
if (!BlackoutController.Instance) return;
|
||||||
BlackoutController.Instance.enabled = m_entryEnabled.Value;
|
if (m_entryEnabled.Value)
|
||||||
|
{
|
||||||
|
BlackoutController.Instance.OnEnable();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BlackoutController.Instance.OnDisable();
|
||||||
|
}
|
||||||
|
BlackoutController.Instance.AutomaticStateChange = m_entryEnabled.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAllSettings()
|
private void UpdateAllSettings()
|
||||||
{
|
{
|
||||||
if (!BlackoutController.Instance) return;
|
if (!BlackoutController.Instance) return;
|
||||||
BlackoutController.Instance.enabled = m_entryEnabled.Value;
|
|
||||||
BlackoutController.Instance.HudMessages = m_entryHudMessages.Value;
|
BlackoutController.Instance.HudMessages = m_entryHudMessages.Value;
|
||||||
|
BlackoutController.Instance.AutoSleepState = m_entryAutoSleepState.Value;
|
||||||
BlackoutController.Instance.DropFPSOnSleep = m_entryDropFPSOnSleep.Value;
|
BlackoutController.Instance.DropFPSOnSleep = m_entryDropFPSOnSleep.Value;
|
||||||
BlackoutController.Instance.drowsyThreshold = m_entryDrowsyThreshold.Value;
|
BlackoutController.Instance.drowsyThreshold = m_entryDrowsyThreshold.Value;
|
||||||
BlackoutController.Instance.wakeThreshold = m_entryAwakeThreshold.Value;
|
BlackoutController.Instance.wakeThreshold = m_entryAwakeThreshold.Value;
|
||||||
BlackoutController.Instance.DrowsyModeTimer = m_entryDrowsyModeTimer.Value;
|
BlackoutController.Instance.DrowsyModeTimer = m_entryDrowsyModeTimer.Value;
|
||||||
BlackoutController.Instance.SleepModeTimer = m_entrySleepModeTimer.Value;
|
BlackoutController.Instance.SleepModeTimer = m_entrySleepModeTimer.Value;
|
||||||
BlackoutController.Instance.DrowsyDimStrength = m_entryDrowsyDimStrength.Value;
|
BlackoutController.Instance.DrowsyDimStrength = m_entryDrowsyDimStrength.Value;
|
||||||
|
BlackoutController.Instance.DrowsyVelocityMultiplier = m_entryDrowsyVelocityMultiplier.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUpdateEnabled(object arg1, object arg2) => OnEnabled();
|
private void OnUpdateEnabled(object arg1, object arg2) => OnEnabled();
|
||||||
private void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();
|
private void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();
|
||||||
|
|
||||||
//UIExpansionKit actions
|
|
||||||
internal static void AwakeState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
|
|
||||||
internal static void DrowsyState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Drowsy);
|
|
||||||
internal static void SleepingState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Sleeping);
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using Blackout.Properties;
|
using NAK.Melons.Blackout.Properties;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
@ -6,13 +6,13 @@ using System.Reflection;
|
||||||
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
|
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
|
||||||
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
|
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
|
||||||
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
|
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
|
||||||
[assembly: AssemblyTitle(nameof(Blackout))]
|
[assembly: AssemblyTitle(nameof(NAK.Melons.Blackout))]
|
||||||
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
|
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
|
||||||
[assembly: AssemblyProduct(nameof(Blackout))]
|
[assembly: AssemblyProduct(nameof(NAK.Melons.Blackout))]
|
||||||
|
|
||||||
[assembly: MelonInfo(
|
[assembly: MelonInfo(
|
||||||
typeof(Blackout.Blackout),
|
typeof(NAK.Melons.Blackout.Blackout),
|
||||||
nameof(Blackout),
|
nameof(NAK.Melons.Blackout),
|
||||||
AssemblyInfoParams.Version,
|
AssemblyInfoParams.Version,
|
||||||
AssemblyInfoParams.Author,
|
AssemblyInfoParams.Author,
|
||||||
downloadLink: "https://github.com/NotAKidOnSteam/Blackout"
|
downloadLink: "https://github.com/NotAKidOnSteam/Blackout"
|
||||||
|
@ -21,10 +21,11 @@ using System.Reflection;
|
||||||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||||
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||||
|
[assembly: MelonOptionalDependencies("UIExpansionKit", "BTKUILib")]
|
||||||
|
|
||||||
namespace Blackout.Properties;
|
namespace NAK.Melons.Blackout.Properties;
|
||||||
internal static class AssemblyInfoParams
|
internal static class AssemblyInfoParams
|
||||||
{
|
{
|
||||||
public const string Version = "1.0.4";
|
public const string Version = "2.0.0";
|
||||||
public const string Author = "NotAKidoS";
|
public const string Author = "NotAKidoS";
|
||||||
}
|
}
|
2
Blackout/Resource1.Designer.cs
generated
2
Blackout/Resource1.Designer.cs
generated
|
@ -8,7 +8,7 @@
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Blackout {
|
namespace NAK.Melons.Blackout {
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using UIExpansionKit.API;
|
|
||||||
|
|
||||||
namespace Blackout;
|
|
||||||
public static class UiExtensionsAddon
|
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
||||||
public static void Init()
|
|
||||||
{
|
|
||||||
var settings = ExpansionKitApi.GetSettingsCategory(Blackout.SettingsCategory);
|
|
||||||
settings.AddSimpleButton("Awake State", Blackout.AwakeState);
|
|
||||||
settings.AddSimpleButton("Drowsy State", Blackout.DrowsyState);
|
|
||||||
settings.AddSimpleButton("Sleep State", Blackout.SleepingState);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"_id": 106,
|
"_id": 106,
|
||||||
"name": "Blackout",
|
"name": "Blackout",
|
||||||
"modversion": "1.0.4",
|
"modversion": "2.0.0",
|
||||||
"gameversion": "2022r169",
|
"gameversion": "2022r170",
|
||||||
"loaderversion": "0.5.7",
|
"loaderversion": "0.5.7",
|
||||||
"modtype": "Mod",
|
"modtype": "Mod",
|
||||||
"author": "NotAKidoS",
|
"author": "NotAKidoS",
|
||||||
"description": "Dim screen after set time of sitting still. Should be nice for VR sleeping.\n\nNotable Options:\n Cap FPS while sleeping.\nManual control via UIX\nConfigurable dimming strength.",
|
"description": "Dim screen after set time of sitting still. Should be nice for VR sleeping.\n\nNotable Options:\n Cap FPS while sleeping.\nManual control via BTKUILib\nConfigurable dimming strength.",
|
||||||
"searchtags": [
|
"searchtags": [
|
||||||
"black",
|
"black",
|
||||||
"dimmer",
|
"dimmer",
|
||||||
|
@ -14,10 +14,11 @@
|
||||||
"sleeper"
|
"sleeper"
|
||||||
],
|
],
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"None"
|
"BTKUILib",
|
||||||
|
"UIExpansionKit"
|
||||||
],
|
],
|
||||||
"downloadlink": "https://github.com/NotAKidOnSteam/Blackout/releases/download/r5/Blackout.dll",
|
"downloadlink": "https://github.com/NotAKidOnSteam/Blackout/releases/download/v2.0.0/Blackout.dll",
|
||||||
"sourcelink": "https://github.com/NotAKidOnSteam/Blackout/",
|
"sourcelink": "https://github.com/NotAKidOnSteam/Blackout/",
|
||||||
"changelog": "Small tweak to fix VRMode change detection with latest experimental.",
|
"changelog": "- Added BTKUILib support.\n- Added dimming strength velocity multiplier option.\n- Added option to not use Automatic Sleep State.\n- Dimming strengh now updates in realtime when configuring.",
|
||||||
"embedcolor": "#161b22"
|
"embedcolor": "#161b22"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue