Testing Phase

Basics are implemented. Needs playtesting before potential rewrite and implementation of avatar parameters & manual control.
This commit is contained in:
NotAKidoS 2022-10-12 22:46:17 -05:00
parent c049d93d55
commit d033d3750e
8 changed files with 541 additions and 82 deletions

View file

@ -1,59 +1,89 @@
using ABI.CCK.Components;
using ABI_RC.Core.Player;
using ABI_RC.Systems.IK;
using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Core.Player;
using HarmonyLib;
using MelonLoader;
using RootMotion.FinalIK;
using UnityEngine;
using UnityEngine.Events;
namespace Blackout;
public class Blackout : MelonMod
{
BlackoutController m_blackoutController = null;
private static bool inVR;
private static MelonPreferences_Category m_categoryBlackout;
private static MelonPreferences_Entry<bool> m_entryEnabled;
private static MelonPreferences_Entry<float> m_entryDrowsyThreshold;
private static MelonPreferences_Entry<float> m_entryAwakeThreshold;
private static MelonPreferences_Entry<float> m_entryEnterSleepTime;
private static MelonPreferences_Entry<float> m_entryReturnSleepTime;
private static MelonPreferences_Entry<bool> m_entryEnabled, m_entryHudMessages;
//private static MelonPreferences_Entry<bool> m_entryVROnly;
private static MelonPreferences_Entry<float>
m_entryDrowsyThreshold, m_entryAwakeThreshold,
m_entryDrowsyModeTimer, m_entrySleepModeTimer,
m_entryDrowsyDimStrength;
public override void OnApplicationStart()
{
m_categoryBlackout = MelonPreferences.CreateCategory(nameof(Blackout));
m_entryEnabled = m_categoryBlackout.CreateEntry<bool>("Enabled", true, description: "Dim screen when sleeping.");
m_entryHudMessages = m_categoryBlackout.CreateEntry<bool>("Hud Messages", false, description: "Notify on state change.");
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_entryEnterSleepTime = m_categoryBlackout.CreateEntry<float>("Enter Sleep Time", 3f, description: "How many minutes without movement until enter sleep mode.");
m_entryReturnSleepTime = m_categoryBlackout.CreateEntry<float>("Return Sleep Time", 10f, description: "How many seconds should the wake state last before return.");
m_entryDrowsyModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Drowsy Time", 3f, description: "How many minutes without movement until enter drowsy mode.");
m_entrySleepModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Sleep Time", 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_entryVROnly = m_categoryBlackout.CreateEntry<bool>("VR Only", false, description: "Only enable mod in VR.");
m_categoryBlackout.SaveToFile(false);
m_entryEnabled.OnValueChangedUntyped += OnEnabled;
m_entryHudMessages.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyThreshold.OnValueChangedUntyped += OnUpdateSettings;
m_entryAwakeThreshold.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyModeTimer.OnValueChangedUntyped += OnUpdateSettings;
m_entrySleepModeTimer.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyDimStrength.OnValueChangedUntyped += OnUpdateSettings;
//m_entryVROnly.OnValueChangedUntyped += OnUpdateSettings;
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
}
System.Collections.IEnumerator WaitForLocalPlayer()
{
//load blackout_controller.asset
AssetsHandler.Load();
while (PlayerSetup.Instance == null)
yield return null;
m_blackoutController = PlayerSetup.Instance.gameObject.AddComponent<BlackoutController>();
inVR = PlayerSetup.Instance._inVr;
PlayerSetup.Instance.gameObject.AddComponent<BlackoutController>();
//update BlackoutController settings after it initializes
yield return new WaitForEndOfFrame();
OnUpdateSettings();
}
public void OnEnabled()
private void OnEnabled()
{
if (!m_blackoutController) return;
m_blackoutController.enabled = m_entryEnabled.Value;
if (!BlackoutController.Instance) return;
BlackoutController.Instance.enabled = m_entryEnabled.Value;
}
public void OnUpdateSettings()
private void OnUpdateSettings()
{
if (!m_blackoutController) return;
m_blackoutController.drowsyThreshold = m_entryDrowsyThreshold.Value;
m_blackoutController.wakeThreshold = m_entryAwakeThreshold.Value;
m_blackoutController.enterSleepTime = m_entryEnterSleepTime.Value;
m_blackoutController.returnSleepTime = m_entryReturnSleepTime.Value;
if (!BlackoutController.Instance) return;
BlackoutController.Instance.drowsyThreshold = m_entryDrowsyThreshold.Value;
BlackoutController.Instance.wakeThreshold = m_entryAwakeThreshold.Value;
BlackoutController.Instance.DrowsyModeTimer = m_entryDrowsyModeTimer.Value;
BlackoutController.Instance.SleepModeTimer = m_entrySleepModeTimer.Value;
BlackoutController.Instance.DrowsyDimStrength = m_entryDrowsyDimStrength.Value;
BlackoutController.Instance.HudMessages = m_entryHudMessages.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();
}
}
}
}