mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 22:39:22 +00:00
[DesktopVRSwitch] WIP TEST set desktop graphic settings
This commit is contained in:
parent
0c6d2cabc9
commit
03514305be
3 changed files with 82 additions and 32 deletions
|
@ -3,6 +3,20 @@ using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.XR;
|
using UnityEngine.XR;
|
||||||
using Valve.VR;
|
using Valve.VR;
|
||||||
|
using ABI_RC.Core.Savior;
|
||||||
|
using ABI_RC.Core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
SteamVR overrides:
|
||||||
|
|
||||||
|
Application.targetFrameRate = -1;
|
||||||
|
Application.runInBackground = true;
|
||||||
|
QualitySettings.maxQueuedFrames = -1;
|
||||||
|
QualitySettings.vSyncCount = 0;
|
||||||
|
Time.fixedDeltaTime = Time.timeScale / hmd_DisplayFrequency;
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
namespace NAK.DesktopVRSwitch;
|
namespace NAK.DesktopVRSwitch;
|
||||||
|
|
||||||
|
@ -46,10 +60,10 @@ public class DesktopVRSwitcher : MonoBehaviour
|
||||||
|
|
||||||
private IEnumerator StartVRSystem()
|
private IEnumerator StartVRSystem()
|
||||||
{
|
{
|
||||||
|
|
||||||
PreVRModeSwitch(true);
|
PreVRModeSwitch(true);
|
||||||
XRSettings.LoadDeviceByName("OpenVR");
|
XRSettings.LoadDeviceByName("OpenVR");
|
||||||
yield return null; //wait a frame before checking
|
yield return null; //wait a frame before checking
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
|
if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
|
||||||
{
|
{
|
||||||
DesktopVRSwitch.Logger.Msg("Starting SteamVR...");
|
DesktopVRSwitch.Logger.Msg("Starting SteamVR...");
|
||||||
|
@ -59,10 +73,13 @@ public class DesktopVRSwitcher : MonoBehaviour
|
||||||
//but only if SteamVR_Settings.instance.activateFirstActionSetOnStart is enabled
|
//but only if SteamVR_Settings.instance.activateFirstActionSetOnStart is enabled
|
||||||
//which in ChilloutVR, it is, because all those settings are default
|
//which in ChilloutVR, it is, because all those settings are default
|
||||||
SteamVR_Input.Initialize(true);
|
SteamVR_Input.Initialize(true);
|
||||||
|
|
||||||
yield return null;
|
yield return null;
|
||||||
|
|
||||||
PostVRModeSwitch(true);
|
PostVRModeSwitch(true);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopVRSwitch.Logger.Error("Initializing VR Failed. Is there no VR device connected?");
|
DesktopVRSwitch.Logger.Error("Initializing VR Failed. Is there no VR device connected?");
|
||||||
FailedVRModeSwitch(true);
|
FailedVRModeSwitch(true);
|
||||||
yield break;
|
yield break;
|
||||||
|
@ -72,6 +89,7 @@ public class DesktopVRSwitcher : MonoBehaviour
|
||||||
{
|
{
|
||||||
PreVRModeSwitch(false);
|
PreVRModeSwitch(false);
|
||||||
yield return null;
|
yield return null;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
|
if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
|
||||||
{
|
{
|
||||||
//SteamVR.SafeDispose(); //might fuck with SteamVRTrackingModule
|
//SteamVR.SafeDispose(); //might fuck with SteamVRTrackingModule
|
||||||
|
@ -79,11 +97,14 @@ public class DesktopVRSwitcher : MonoBehaviour
|
||||||
SteamVR_Input.actionSets[0].Deactivate(SteamVR_Input_Sources.Any);
|
SteamVR_Input.actionSets[0].Deactivate(SteamVR_Input_Sources.Any);
|
||||||
XRSettings.LoadDeviceByName("");
|
XRSettings.LoadDeviceByName("");
|
||||||
XRSettings.enabled = false;
|
XRSettings.enabled = false;
|
||||||
|
|
||||||
yield return null;
|
yield return null;
|
||||||
Time.fixedDeltaTime = 0.02f; //reset physics time to Desktop default
|
|
||||||
|
ResetSteamVROverrides();
|
||||||
PostVRModeSwitch(false);
|
PostVRModeSwitch(false);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopVRSwitch.Logger.Error("Attempted to exit VR without a VR device loaded.");
|
DesktopVRSwitch.Logger.Error("Attempted to exit VR without a VR device loaded.");
|
||||||
FailedVRModeSwitch(false);
|
FailedVRModeSwitch(false);
|
||||||
yield break;
|
yield break;
|
||||||
|
@ -137,5 +158,38 @@ public class DesktopVRSwitcher : MonoBehaviour
|
||||||
|
|
||||||
_switchInProgress = false;
|
_switchInProgress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResetSteamVROverrides()
|
||||||
|
{
|
||||||
|
// Reset physics time to Desktop default
|
||||||
|
Time.fixedDeltaTime = 0.02f;
|
||||||
|
|
||||||
|
// Reset queued frames
|
||||||
|
QualitySettings.maxQueuedFrames = 2;
|
||||||
|
|
||||||
|
// Reset framerate target
|
||||||
|
int graphicsFramerateTarget = MetaPort.Instance.settings.GetSettingInt("GraphicsFramerateTarget", 0);
|
||||||
|
CVRTools.SetFramerateTarget(graphicsFramerateTarget);
|
||||||
|
|
||||||
|
// Reset VSync setting
|
||||||
|
bool graphicsVSync = MetaPort.Instance.settings.GetSettingsBool("GraphicsVSync", false);
|
||||||
|
QualitySettings.vSyncCount = graphicsVSync ? 1 : 0;
|
||||||
|
|
||||||
|
// Reset anti-aliasing
|
||||||
|
int graphicsMsaaLevel = MetaPort.Instance.settings.GetSettingInt("GraphicsMsaaLevel", 0);
|
||||||
|
QualitySettings.antiAliasing = graphicsMsaaLevel;
|
||||||
|
|
||||||
|
// Reset eye tracking initialization
|
||||||
|
bool interactionTobiiEyeTracking = MetaPort.Instance.settings.GetSettingsBool("InteractionTobiiEyeTracking", false);
|
||||||
|
if (interactionTobiiEyeTracking)
|
||||||
|
{
|
||||||
|
MetaPort.Instance.TobiiXrInitializer.Initialize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Won't do anything if not already running
|
||||||
|
MetaPort.Instance.TobiiXrInitializer.DeInitialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,39 +11,34 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace NAK.DesktopVRSwitch.HarmonyPatches;
|
namespace NAK.DesktopVRSwitch.HarmonyPatches;
|
||||||
|
|
||||||
internal class PlayerSetupPatches
|
class CheckVRPatches
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(PlayerSetup), "Start")]
|
[HarmonyPatch(typeof(CheckVR), nameof(CheckVR.Start))]
|
||||||
private static void Postfix_PlayerSetup_Start(ref PlayerSetup __instance)
|
private static void Postfix_CheckVR_Start(ref CheckVR __instance)
|
||||||
{
|
{
|
||||||
if (CheckVR.Instance != null)
|
|
||||||
{
|
|
||||||
CheckVR.Instance.gameObject.AddComponent<DesktopVRSwitcher>();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
__instance.gameObject.AddComponent<DesktopVRSwitcher>();
|
__instance.gameObject.AddComponent<DesktopVRSwitcher>();
|
||||||
DesktopVRSwitch.Logger.Error("CheckVR not found. Reverting to fallback method. This should never happen!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class MovementSystemPatches
|
class MovementSystemPatches
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(MovementSystem), "Start")]
|
[HarmonyPatch(typeof(MovementSystem), nameof(MovementSystem.Start))]
|
||||||
private static void Postfix_MovementSystem_Start(ref MovementSystem __instance)
|
private static void Postfix_MovementSystem_Start(ref MovementSystem __instance)
|
||||||
{
|
{
|
||||||
__instance.gameObject.AddComponent<MovementSystemTracker>();
|
__instance.gameObject.AddComponent<MovementSystemTracker>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CVRPickupObjectPatches
|
class CVRPickupObjectPatches
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(CVRPickupObject), "Start")]
|
[HarmonyPatch(typeof(CVRPickupObject), nameof(CVRPickupObject.Start))]
|
||||||
private static void Prefix_CVRPickupObject_Start(ref CVRPickupObject __instance)
|
private static void Prefix_CVRPickupObject_Start(ref CVRPickupObject __instance)
|
||||||
{
|
{
|
||||||
if (__instance.gripType == CVRPickupObject.GripType.Free) return;
|
if (__instance.gripType == CVRPickupObject.GripType.Free) return;
|
||||||
|
|
||||||
Transform vrOrigin = __instance.gripOrigin;
|
Transform vrOrigin = __instance.gripOrigin;
|
||||||
Transform desktopOrigin = __instance.gripOrigin.Find("[Desktop]");
|
Transform desktopOrigin = __instance.gripOrigin.Find("[Desktop]");
|
||||||
if (vrOrigin != null && desktopOrigin != null)
|
if (vrOrigin != null && desktopOrigin != null)
|
||||||
|
@ -55,50 +50,51 @@ internal class CVRPickupObjectPatches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CVRWorldPatches
|
class CVRWorldPatches
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(CVRWorld), "SetDefaultCamValues")]
|
[HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.SetDefaultCamValues))]
|
||||||
private static void CVRWorld_SetDefaultCamValues_Postfix()
|
private static void Postfix_CVRWorld_SetDefaultCamValues()
|
||||||
{
|
{
|
||||||
ReferenceCameraPatch.OnWorldLoad();
|
ReferenceCameraPatch.OnWorldLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(CVRWorld), "CopyRefCamValues")]
|
[HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.CopyRefCamValues))]
|
||||||
private static void CVRWorld_CopyRefCamValues_Postfix()
|
private static void Postfix_CVRWorld_CopyRefCamValues()
|
||||||
{
|
{
|
||||||
ReferenceCameraPatch.OnWorldLoad();
|
ReferenceCameraPatch.OnWorldLoad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CameraFacingObjectPatches
|
class CameraFacingObjectPatches
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(CameraFacingObject), "Start")]
|
[HarmonyPatch(typeof(CameraFacingObject), nameof(CameraFacingObject.Start))]
|
||||||
private static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance)
|
private static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance)
|
||||||
{
|
{
|
||||||
__instance.gameObject.AddComponent<CameraFacingObjectTracker>();
|
__instance.gameObject.AddComponent<CameraFacingObjectTracker>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class IKSystemPatches
|
class IKSystemPatches
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(IKSystem), "Start")]
|
[HarmonyPatch(typeof(IKSystem), nameof(IKSystem.Start))]
|
||||||
private static void Postfix_IKSystem_Start(ref IKSystem __instance)
|
private static void Postfix_IKSystem_Start(ref IKSystem __instance)
|
||||||
{
|
{
|
||||||
__instance.gameObject.AddComponent<IKSystemTracker>();
|
__instance.gameObject.AddComponent<IKSystemTracker>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix] //lazy fix so i dont need to wait few frames
|
[HarmonyPostfix] //lazy fix so i dont need to wait few frames
|
||||||
[HarmonyPatch(typeof(TrackingPoint), "Initialize")]
|
[HarmonyPatch(typeof(TrackingPoint), nameof(TrackingPoint.Initialize))]
|
||||||
private static void Postfix_TrackingPoint_Initialize(ref TrackingPoint __instance)
|
private static void Postfix_TrackingPoint_Initialize(ref TrackingPoint __instance)
|
||||||
{
|
{
|
||||||
__instance.referenceTransform.localScale = Vector3.one;
|
__instance.referenceTransform.localScale = Vector3.one;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix] //lazy fix so device indecies can change properly
|
[HarmonyPostfix] //lazy fix so device indecies can change properly
|
||||||
[HarmonyPatch(typeof(SteamVRTrackingModule), "ModuleDestroy")]
|
[HarmonyPatch(typeof(SteamVRTrackingModule), nameof(SteamVRTrackingModule.ModuleDestroy))]
|
||||||
private static void Postfix_SteamVRTrackingModule_ModuleDestroy(ref SteamVRTrackingModule __instance)
|
private static void Postfix_SteamVRTrackingModule_ModuleDestroy(ref SteamVRTrackingModule __instance)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < __instance.TrackingPoints.Count; i++)
|
for (int i = 0; i < __instance.TrackingPoints.Count; i++)
|
||||||
|
@ -109,10 +105,10 @@ internal class IKSystemPatches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class VRTrackerManagerPatches
|
class VRTrackerManagerPatches
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(VRTrackerManager), "Start")]
|
[HarmonyPatch(typeof(VRTrackerManager), nameof(VRTrackerManager.Start))]
|
||||||
private static void Postfix_VRTrackerManager_Start(ref VRTrackerManager __instance)
|
private static void Postfix_VRTrackerManager_Start(ref VRTrackerManager __instance)
|
||||||
{
|
{
|
||||||
__instance.gameObject.AddComponent<VRTrackerManagerTracker>();
|
__instance.gameObject.AddComponent<VRTrackerManagerTracker>();
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class DesktopVRSwitch : MelonMod
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
Logger = LoggerInstance;
|
Logger = LoggerInstance;
|
||||||
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
|
ApplyPatches(typeof(HarmonyPatches.CheckVRPatches));
|
||||||
ApplyPatches(typeof(HarmonyPatches.CVRPickupObjectPatches));
|
ApplyPatches(typeof(HarmonyPatches.CVRPickupObjectPatches));
|
||||||
ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches));
|
ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches));
|
||||||
ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches));
|
ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches));
|
||||||
|
@ -37,7 +37,7 @@ public class DesktopVRSwitch : MelonMod
|
||||||
ApplyPatches(typeof(HarmonyPatches.VRTrackerManagerPatches));
|
ApplyPatches(typeof(HarmonyPatches.VRTrackerManagerPatches));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyPatches(Type type)
|
void ApplyPatches(Type type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -45,8 +45,8 @@ public class DesktopVRSwitch : MelonMod
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Msg($"Failed while patching {type.Name}!");
|
LoggerInstance.Msg($"Failed while patching {type.Name}!");
|
||||||
Logger.Error(e);
|
LoggerInstance.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue