[DesktopVRSwitch] Nuke CohtmlUISystem Gamepad handling for now.

This commit is contained in:
NotAKidoS 2023-06-19 23:47:43 -05:00
parent 5f95755ad2
commit 0fb7c3d401
19 changed files with 146 additions and 21 deletions

View file

@ -7,6 +7,7 @@ using HarmonyLib;
using NAK.DesktopVRSwitch.Patches; using NAK.DesktopVRSwitch.Patches;
using NAK.DesktopVRSwitch.VRModeTrackers; using NAK.DesktopVRSwitch.VRModeTrackers;
using UnityEngine; using UnityEngine;
using cohtml;
namespace NAK.DesktopVRSwitch.HarmonyPatches; namespace NAK.DesktopVRSwitch.HarmonyPatches;
@ -64,6 +65,49 @@ class CameraFacingObjectPatches
[HarmonyPatch(typeof(CameraFacingObject), nameof(CameraFacingObject.Start))] [HarmonyPatch(typeof(CameraFacingObject), nameof(CameraFacingObject.Start))]
static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance) static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance)
{ {
__instance.gameObject.AddComponent<CameraFacingObjectTracker>(); __instance.gameObject.AddComponent<CameraFacingObjectTracker>()._cameraFacingObject = __instance;
}
}
class CVRPickupObjectPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(CVRPickupObject), nameof(CVRPickupObject.Start))]
static void Prefix_CVRPickupObject_Start(ref CVRPickupObject __instance)
{
if (__instance.gripType == CVRPickupObject.GripType.Free)
return;
Transform vrOrigin = __instance.gripOrigin;
Transform desktopOrigin = __instance.gripOrigin.Find("[Desktop]");
if (vrOrigin != null && desktopOrigin != null)
{
var tracker = __instance.gameObject.AddComponent<CVRPickupObjectTracker>();
tracker._pickupObject = __instance;
tracker._storedGripOrigin = (!MetaPort.Instance.isUsingVr ? vrOrigin : desktopOrigin);
}
}
}
class CohtmlUISystemPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(CohtmlUISystem), nameof(CohtmlUISystem.RegisterGamepad))]
[HarmonyPatch(typeof(CohtmlUISystem), nameof(CohtmlUISystem.UnregisterGamepad))]
[HarmonyPatch(typeof(CohtmlUISystem), nameof(CohtmlUISystem.UpdateGamepadState))]
static bool Prefix_CohtmlUISystem_FuckOff()
{
/**
GameFace Version 1.34.0.4 released 10 Nov 2022
Fixed a crash when registering and unregistering gamepads
Fix Fixed setting a gamepad object when creating GamepadEvent from JavaScript
Fix Fixed a crash when unregistering a gamepad twice
Fix Fixed a GamepadEvent related crash during garbage collector tracing
we are using 1.17.0 (released 10/09/21) :):):)
**/
// dont
return false;
} }
} }

View file

@ -1,4 +1,5 @@
using MelonLoader; 
using MelonLoader;
using NAK.DesktopVRSwitch.VRModeTrackers; using NAK.DesktopVRSwitch.VRModeTrackers;
using UnityEngine; using UnityEngine;
@ -28,7 +29,10 @@ public class DesktopVRSwitch : MelonMod
Category.CreateEntry("Enter Calibration on Switch", true, description: "Should you automatically be placed into calibration after switch if FBT is available? Overridden by Save Calibration IK setting."); Category.CreateEntry("Enter Calibration on Switch", true, description: "Should you automatically be placed into calibration after switch if FBT is available? Overridden by Save Calibration IK setting.");
public static readonly MelonPreferences_Entry<bool> EntryUseTransitionOnSwitch = public static readonly MelonPreferences_Entry<bool> EntryUseTransitionOnSwitch =
Category.CreateEntry("Use Transition on Switch", true, description: "Should the world transition play on VRMode switch?"); Category.CreateEntry("Use Transition on Switch", true, description: "Should the world transition play on VRMode switch?");
public static readonly MelonPreferences_Entry<bool> EntryRenderVRGameView =
Category.CreateEntry("Render VR Game View", true, description: "Should the VR view be displayed in the game window?");
public override void OnInitializeMelon() public override void OnInitializeMelon()
{ {
@ -40,10 +44,14 @@ public class DesktopVRSwitch : MelonMod
ApplyPatches(typeof(HarmonyPatches.CheckVRPatches)); ApplyPatches(typeof(HarmonyPatches.CheckVRPatches));
// nameplate fixes // nameplate fixes
ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches)); ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches));
// pickup fixes
ApplyPatches(typeof(HarmonyPatches.CVRPickupObjectPatches));
// lazy fix to reset iksystem // lazy fix to reset iksystem
ApplyPatches(typeof(HarmonyPatches.IKSystemPatches)); ApplyPatches(typeof(HarmonyPatches.IKSystemPatches));
// post processing fixes // post processing fixes
ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches)); ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches));
// cohtml gamepad handling nuke
ApplyPatches(typeof(HarmonyPatches.CohtmlUISystemPatches));
} }
public override void OnUpdate() public override void OnUpdate()

View file

@ -1,4 +1,5 @@
using ABI_RC.Systems.UI; using ABI_RC.Systems.UI;
using NAK.DesktopVRSwitch.VRModeTrackers;
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
@ -16,7 +17,7 @@ using Valve.VR;
**/ **/
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch;
public class VRModeSwitchManager : MonoBehaviour public class VRModeSwitchManager : MonoBehaviour
{ {

View file

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

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Savior; using ABI_RC.Core.Savior;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVRInputManagerTracker : VRModeTracker public class CVRInputManagerTracker : VRModeTracker

View file

@ -5,18 +5,17 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVRPickupObjectTracker : MonoBehaviour public class CVRPickupObjectTracker : MonoBehaviour
{ {
private CVRPickupObject _pickupObject; internal CVRPickupObject _pickupObject;
private Transform _storedGripOrigin; internal Transform _storedGripOrigin;
public CVRPickupObjectTracker(CVRPickupObject pickupObject, Transform storedGripOrigin) void Start()
{ {
this._pickupObject = pickupObject; VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
this._storedGripOrigin = storedGripOrigin;
} }
private void OnDestroy() void OnDestroy()
{ {
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
} }
public void OnPostSwitch(bool intoVR) public void OnPostSwitch(bool intoVR)

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.InteractionSystem;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVR_InteractableManagerTracker : VRModeTracker public class CVR_InteractableManagerTracker : VRModeTracker

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.InteractionSystem;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CVR_MenuManagerTracker : VRModeTracker public class CVR_MenuManagerTracker : VRModeTracker

View file

@ -5,21 +5,18 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CameraFacingObjectTracker : MonoBehaviour public class CameraFacingObjectTracker : MonoBehaviour
{ {
private CameraFacingObject _cameraFacingObject; internal CameraFacingObject _cameraFacingObject;
public CameraFacingObjectTracker(CameraFacingObject cameraFacingObject) void Start()
{ {
this._cameraFacingObject = cameraFacingObject; VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
} }
private void OnDestroy() void OnDestroy()
{ {
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
} }
public void OnPreSwitch(bool intoVR) { }
public void OnFailedSwitch(bool intoVR) { }
public void OnPostSwitch(bool intoVR) public void OnPostSwitch(bool intoVR)
{ {
_cameraFacingObject.m_Camera = Utils.GetPlayerCameraObject(intoVR).GetComponent<Camera>(); _cameraFacingObject.m_Camera = Utils.GetPlayerCameraObject(intoVR).GetComponent<Camera>();

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Savior; using ABI_RC.Core.Savior;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class CheckVRTracker : VRModeTracker public class CheckVRTracker : VRModeTracker

View file

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

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class HudOperationsTracker : VRModeTracker public class HudOperationsTracker : VRModeTracker

View file

@ -2,6 +2,7 @@
using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.IK.TrackingModules; using ABI_RC.Systems.IK.TrackingModules;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class IKSystemTracker : VRModeTracker public class IKSystemTracker : VRModeTracker

View file

@ -1,9 +1,14 @@
using ABI_RC.Core.Savior; using ABI_RC.Core.Savior;
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class MetaPortTracker : VRModeTracker public class MetaPortTracker : VRModeTracker
{ {
private MetaPort _metaPort;
public override void TrackerInit() public override void TrackerInit()
{ {
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
@ -16,7 +21,7 @@ public class MetaPortTracker : VRModeTracker
private void OnPostSwitch(bool intoVR) private void OnPostSwitch(bool intoVR)
{ {
MetaPort _metaPort = MetaPort.Instance; _metaPort = MetaPort.Instance;
if (_metaPort == null) if (_metaPort == null)
{ {
DesktopVRSwitch.Logger.Error("Error while getting MetaPort!"); DesktopVRSwitch.Logger.Error("Error while getting MetaPort!");
@ -27,6 +32,13 @@ public class MetaPortTracker : VRModeTracker
// Main thing most of the game checks for if using VR // Main thing most of the game checks for if using VR
_metaPort.isUsingVr = intoVR; _metaPort.isUsingVr = intoVR;
// replace
UpdateRichPresence();
ResetSteamVROverrides(intoVR);
}
private void UpdateRichPresence()
{
// Hacky way of updating rich presence // Hacky way of updating rich presence
if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true)) if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true))
{ {
@ -41,4 +53,43 @@ public class MetaPortTracker : VRModeTracker
_metaPort.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true); _metaPort.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true);
} }
} }
private void ResetSteamVROverrides(bool intoVR)
{
if (intoVR)
{
// Testing
XRSettings.eyeTextureResolutionScale = 1;
XRSettings.gameViewRenderMode = DesktopVRSwitch.EntryRenderVRGameView.Value ? GameViewRenderMode.LeftEye : GameViewRenderMode.None;
SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false;
if (MetaPort.Instance.settings.GetSettingsBool("InteractionTobiiEyeTracking", false))
{
MetaPort.Instance.TobiiXrInitializer.Initialize();
}
return;
}
// 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);
ABI_RC.Core.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;
// Won't do anything if not already running
MetaPort.Instance.TobiiXrInitializer.DeInitialize();
}
} }

View file

@ -1,4 +1,5 @@
using ABI_RC.Systems.MovementSystem; using ABI_RC.Systems.MovementSystem;
using UnityEngine; using UnityEngine;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
@ -12,12 +13,14 @@ public class MovementSystemTracker : VRModeTracker
public override void TrackerInit() public override void TrackerInit()
{ {
VRModeSwitchManager.OnPreVRModeSwitch += OnPreSwitch; VRModeSwitchManager.OnPreVRModeSwitch += OnPreSwitch;
VRModeSwitchManager.OnFailVRModeSwitch += OnFailedSwitch;
VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch;
} }
public override void TrackerDestroy() public override void TrackerDestroy()
{ {
VRModeSwitchManager.OnPreVRModeSwitch -= OnPreSwitch; VRModeSwitchManager.OnPreVRModeSwitch -= OnPreSwitch;
VRModeSwitchManager.OnFailVRModeSwitch -= OnFailedSwitch;
VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch;
} }
@ -28,10 +31,16 @@ public class MovementSystemTracker : VRModeTracker
preSwitchWorldPosition = Utils.GetPlayerRootPosition(); preSwitchWorldPosition = Utils.GetPlayerRootPosition();
preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation; preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation;
_movementSystem.SetImmobilized(true);
_movementSystem.ChangeCrouch(false); _movementSystem.ChangeCrouch(false);
_movementSystem.ChangeProne(false); _movementSystem.ChangeProne(false);
} }
private void OnFailedSwitch(bool intoVR)
{
_movementSystem.SetImmobilized(false);
}
private void OnPostSwitch(bool intoVR) private void OnPostSwitch(bool intoVR)
{ {
_movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform; _movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform;
@ -40,6 +49,7 @@ public class MovementSystemTracker : VRModeTracker
if (!intoVR) if (!intoVR)
_movementSystem.UpdateColliderCenter(_movementSystem.transform.position); _movementSystem.UpdateColliderCenter(_movementSystem.transform.position);
_movementSystem.SetImmobilized(false);
_movementSystem.ChangeCrouch(false); _movementSystem.ChangeCrouch(false);
_movementSystem.ChangeProne(false); _movementSystem.ChangeProne(false);
} }

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class PlayerSetupTracker : VRModeTracker public class PlayerSetupTracker : VRModeTracker
@ -29,8 +30,11 @@ public class PlayerSetupTracker : VRModeTracker
// This might error if we started in VR. // This might error if we started in VR.
// '_cam' is not set until Start(). // '_cam' is not set until Start().
CVR_DesktopCameraController.UpdateFov(); if (CVR_DesktopCameraController._cam == null)
CVR_DesktopCameraController._cam = _playerSetup.desktopCamera.GetComponent<UnityEngine.Camera>();
CVR_DesktopCameraController.UpdateFov();
// UICamera has a script that copies the FOV from the desktop cam. // UICamera has a script that copies the FOV from the desktop cam.
// Toggling the cameras on/off resets the aspect ratio, // Toggling the cameras on/off resets the aspect ratio,
// so when rigs switch, that is already handled. // so when rigs switch, that is already handled.

View file

@ -1,5 +1,6 @@
using ABI_RC.Systems.Camera; using ABI_RC.Systems.Camera;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class PortableCameraTracker : VRModeTracker public class PortableCameraTracker : VRModeTracker

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class VRTrackerManagerTracker : VRModeTracker public class VRTrackerManagerTracker : VRModeTracker

View file

@ -1,5 +1,6 @@
using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.InteractionSystem;
namespace NAK.DesktopVRSwitch.VRModeTrackers; namespace NAK.DesktopVRSwitch.VRModeTrackers;
public class ViewManagerTracker : VRModeTracker public class ViewManagerTracker : VRModeTracker