[DesktopVRSwitch] More fixes for 2023r171.

This commit is contained in:
NotAKidoS 2023-09-15 17:47:26 -05:00
parent 9f01f8e6a7
commit 3d6b1f75a4
17 changed files with 67 additions and 62 deletions

View file

@ -3,7 +3,6 @@ using ABI_RC.Core.Savior;
using ABI_RC.Core.Util.Object_Behaviour;
using ABI_RC.Systems.IK;
using ABI_RC.Systems.IK.TrackingModules;
using cohtml;
using cohtml.Net;
using HarmonyLib;
using NAK.DesktopVRSwitch.Patches;
@ -103,7 +102,7 @@ internal class CVRPickupObjectPatches
return;
Transform vrOrigin = __instance.gripOrigin;
Transform desktopOrigin = vrOrigin?.Find("[Desktop]");
Transform desktopOrigin = vrOrigin != null ? vrOrigin.Find("[Desktop]") : null;
if (vrOrigin != null && desktopOrigin != null)
{
CVRPickupObjectTracker tracker = __instance.gameObject.AddComponent<CVRPickupObjectTracker>();
@ -122,9 +121,12 @@ internal class CVRPickupObjectPatches
internal class CohtmlUISystemPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.RegisterGamepad))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.RegisterGamepad), typeof(uint), typeof(string), typeof(uint), typeof(uint), typeof(IntPtr))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.RegisterGamepad), typeof(uint), typeof(string), typeof(uint), typeof(uint))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadState), typeof(cohtml.GamepadState))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadState), typeof(uint), typeof(float[]), typeof(float[]))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.UnregisterGamepad))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadState))]
[HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadStateExtended))]
private static bool Prefix_UISystem_FuckOff()
{
/**
@ -153,7 +155,9 @@ internal class SteamVRBehaviourPatches
// If we don't switch fast enough, SteamVR will force close.
// World Transition might cause issues. Might need to override.
VRModeSwitchManager.Instance?.AttemptSwitch();
if (VRModeSwitchManager.Instance != null)
VRModeSwitchManager.Instance.AttemptSwitch();
return false;
}
}

View file

@ -1,7 +1,6 @@
using BTKUILib;
using BTKUILib.UIObjects;
using System.Runtime.CompilerServices;
using ABI_RC.Core.Base;
namespace NAK.DesktopVRSwitch.Integrations;
@ -55,10 +54,10 @@ public static class BTKUIAddon
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, int decimalPlaces = 2)
{
page.AddSlider(entry.DisplayName, entry.Description, entry.Value, min, max, decimalPlaces).OnValueUpdated += f => entry.Value = f;
}
// private static void AddMelonSlider(ref Page page, MelonLoader.MelonPreferences_Entry<float> entry, float min, float max, int decimalPlaces = 2)
// {
// page.AddSlider(entry.DisplayName, entry.Description, entry.Value, min, max, decimalPlaces).OnValueUpdated += f => entry.Value = f;
// }
#endregion
}

View file

@ -37,10 +37,11 @@ public class DesktopVRSwitch : MelonMod
public override void OnUpdate()
{
if (Input.GetKeyDown(KeyCode.F6) && Input.GetKey(KeyCode.LeftControl))
{
VRModeSwitchManager.Instance?.AttemptSwitch();
}
if (!Input.GetKeyDown(KeyCode.F6) || !Input.GetKey(KeyCode.LeftControl))
return;
if (VRModeSwitchManager.Instance != null)
VRModeSwitchManager.Instance.AttemptSwitch();
}
private static void RegisterVRModeTrackers()

View file

@ -6,7 +6,7 @@ public static class ModSettings
{
internal const string SettingsCategory = nameof(DesktopVRSwitch);
public static readonly MelonPreferences_Category Category =
private static readonly MelonPreferences_Category Category =
MelonPreferences.CreateCategory(SettingsCategory);
public static readonly MelonPreferences_Entry<bool> EntryEnterCalibrationOnSwitch =

View file

@ -27,6 +27,6 @@ using System.Reflection;
namespace NAK.DesktopVRSwitch.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "4.4.0";
public const string Version = "4.4.1";
public const string Author = "NotAKidoS";
}

View file

@ -10,22 +10,22 @@ internal class VRModeSwitchDebugger : MonoBehaviour
private void OnEnable()
{
if (_switchCoroutine == null)
{
if (_switchCoroutine != null)
return;
_switchCoroutine = StartCoroutine(SwitchLoop());
_sleep = new WaitForSeconds(2f);
}
}
private void OnDisable()
{
if (_switchCoroutine != null)
{
if (_switchCoroutine == null)
return;
StopCoroutine(_switchCoroutine);
_switchCoroutine = null;
_sleep = null;
}
}
private IEnumerator SwitchLoop()
{

View file

@ -43,7 +43,7 @@ public class VRModeSwitchManager : MonoBehaviour
#region Public Methods
public static bool IsInXR() => XRGeneralSettings.Instance.Manager.activeLoader != null;
private static bool IsInXR() => XRGeneralSettings.Instance.Manager.activeLoader != null;
public void AttemptSwitch() => StartCoroutine(StartSwitchInternal());
@ -56,10 +56,12 @@ public class VRModeSwitchManager : MonoBehaviour
if (SwitchInProgress)
yield break;
bool useWorldTransition = UseWorldTransition;
SwitchInProgress = true;
yield return null;
if (UseWorldTransition)
if (useWorldTransition)
yield return StartCoroutine(StartTransition());
bool isUsingVr = IsInXR();
@ -68,7 +70,7 @@ public class VRModeSwitchManager : MonoBehaviour
yield return StartCoroutine(XRAndReloadAvatar(!isUsingVr));
if (UseWorldTransition)
if (useWorldTransition)
yield return StartCoroutine(ContinueTransition());
SwitchInProgress = false;
@ -145,7 +147,7 @@ public class VRModeSwitchManager : MonoBehaviour
{
try
{
var playerCamera = Utils.GetPlayerCameraObject(isUsingVr).GetComponent<Camera>();
Camera playerCamera = Utils.GetPlayerCameraObject(isUsingVr).GetComponent<Camera>();
switchEvent?.Invoke(this, new VRModeEventArgs(isUsingVr, playerCamera));
}
catch (Exception e)

View file

@ -1,5 +1,4 @@
using ABI_RC.Core.Savior;
using UnityEngine;
namespace NAK.DesktopVRSwitch.VRModeTrackers;

View file

@ -1,5 +1,4 @@
using ABI_RC.Core.Savior;
using ABI_RC.Systems.InputManagement;
using ABI_RC.Systems.InputManagement;
using ABI_RC.Systems.InputManagement.InputModules;
namespace NAK.DesktopVRSwitch.VRModeTrackers;

View file

@ -20,8 +20,9 @@ public class CVRPickupObjectTracker : MonoBehaviour
public void OnPostSwitch(object sender, VRModeSwitchManager.VRModeEventArgs args)
{
if (_pickupObject != null)
{
if (_pickupObject == null)
return;
// Drop the object if it is being held locally
if (_pickupObject._controllerRay != null)
_pickupObject._controllerRay.DropObject(true);
@ -30,4 +31,3 @@ public class CVRPickupObjectTracker : MonoBehaviour
(_storedGripOrigin, _pickupObject.gripOrigin) = (_pickupObject.gripOrigin, _storedGripOrigin);
}
}
}

View file

@ -16,8 +16,9 @@ public class CVR_InteractableManagerTracker : VRModeTracker
private void OnPostSwitch(object sender, VRModeSwitchManager.VRModeEventArgs args)
{
DesktopVRSwitch.Logger.Msg($"Setting CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions to {!args.IsUsingVr}");
DesktopVRSwitch.Logger.Msg($"Enabling CVR_InteractableManager enableInteractions.");
CVR_InteractableManager.enableInteractions = !args.IsUsingVr;
// ?
CVR_InteractableManager.enableInteractions = true;
}
}

View file

@ -29,7 +29,6 @@ public class CVR_MenuManagerTracker : VRModeTracker
DesktopVRSwitch.Logger.Msg("Updating CVR_Menu_Data core data.");
CVR_MenuManager.Instance.coreData.core.inVr = args.IsUsingVr;
CVR_MenuManager.Instance.quickMenu.transform.localPosition = Vector3.zero;
CVR_MenuManager.Instance.quickMenu.transform.localRotation = Quaternion.identity;
CVR_MenuManager.Instance.quickMenu.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
}
}

View file

@ -21,10 +21,14 @@ public class CohtmlHudTracker : VRModeTracker
DesktopVRSwitch.Logger.Msg("Configuring new hud affinity for CohtmlHud.");
CohtmlHud.Instance.gameObject.transform.parent = Utils.GetPlayerCameraObject(args.IsUsingVr).transform;
// This handles rotation and position
CVRTools.ConfigureHudAffinity();
CohtmlHud.Instance.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f);
CohtmlHud.Instance.markMenuAsReady();
// required to set menu vr mode (why is it offset in js?)
CohtmlHud.uiCoreGameData.isVr = args.IsUsingVr;
if (CohtmlHud.Instance._isReady)
CohtmlHud.Instance.hudView.View.TriggerEvent("updateCoreGameVars", CohtmlHud.uiCoreGameData);
}
}

View file

@ -64,7 +64,7 @@ public class IKSystemTracker : VRModeTracker
private void SetupSteamVRTrackingModule(bool enableVR)
{
var openVRModule = IKSystem.Instance._trackingModules.OfType<SteamVRTrackingModule>().FirstOrDefault();
SteamVRTrackingModule openVRModule = IKSystem.Instance._trackingModules.OfType<SteamVRTrackingModule>().FirstOrDefault();
if (openVRModule != null)
{
@ -75,8 +75,7 @@ public class IKSystemTracker : VRModeTracker
}
else if (enableVR)
{
var newVRModule = new SteamVRTrackingModule();
IKSystem.Instance.AddTrackingModule(newVRModule);
IKSystem.Instance.AddTrackingModule(new SteamVRTrackingModule());
}
}
}

View file

@ -59,7 +59,7 @@ public class MovementSystemTracker : VRModeTracker
DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility and applying stored position and rotation.");
MovementSystem.Instance.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform;
MovementSystem.Instance.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false);
MovementSystem.Instance.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation);
if (!intoVR)
MovementSystem.Instance.UpdateColliderCenter(MovementSystem.Instance.transform.position);
@ -67,7 +67,5 @@ public class MovementSystemTracker : VRModeTracker
MovementSystem.Instance.ChangeCrouch(false);
MovementSystem.Instance.ChangeProne(false);
MovementSystem.Instance.SetImmobilized(false);
yield break;
}
}

View file

@ -18,7 +18,7 @@ internal static class XRHandler
if (XRGeneralSettings.Instance.Manager.activeLoader != null)
XRGeneralSettings.Instance.Manager.StartSubsystems();
else
StopXR();
yield return StopXR();
yield return null;
}

View file

@ -1,23 +1,23 @@
{
"_id": 103,
"name": "DesktopVRSwitch",
"modversion": "4.4.0",
"gameversion": "2022r170p1",
"modversion": "4.4.1",
"gameversion": "2023r171",
"loaderversion": "0.6.1",
"modtype": "Mod",
"author": "NotAKidoS",
"description": "Allows you to switch between Desktop and VR with a keybind.\n**Press Control + F6 to switch.**\n\nWhile this mod is a nice convienence feature to have access to, not every ChilloutVR system or mod is built to support it. I cannot possibly cover every edge case or mitigate issues with every mod. **Use at your own discretion.**",
"description": "Allows you to switch between Desktop and VR with a keybind.\n**Press Control + F6 to switch.**\n\nWhile this mod is a nice convenience feature to have access to, not every ChilloutVR system or mod is built to support it. I cannot possibly cover every edge case or mitigate issues with every mod. **Use at your own discretion.**",
"searchtags": [
"desktop",
"vr",
"switch",
"hotswap"
"restart"
],
"requirements": [
"None"
],
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r12/DesktopVRSwitch.dll",
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r20/DesktopVRSwitch.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRSwitch/",
"changelog": "- Fixed issue with Zoom gamerule being ignored if first joined in VR.\n- Fixed issue with post processing settings not being updated.\n- Fixed conflict with Third Person.\n- Fixed conflict with DesktopVRIK.\n- Potentially fixed rare Cohtml crash regarding Gamepad registering on switch.\n- Potentially fixed eye tracking not being handled on switch.\n- Fixed a bunch of QualitySettings that SteamVR would override not being reset on switch to Desktop.\n- Potentially fixed issue where entering VR after restarting SteamVR resulted in low renderscale.\n- Fixed issue with CVRPickupObject patch breaking other mods.\n- Reworked how SteamVR is initialized & deinitialized.\n- Hijacked world transition system for switch transition.\n- Added option to automatically switch to Desktop when closing SteamVR.",
"changelog": "- Fixes for 2023r171.",
"embedcolor": "3498db"
}