mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 23:09:22 +00:00
broken
This commit is contained in:
parent
26441f8b1e
commit
c7b16abd4f
27 changed files with 591 additions and 91 deletions
|
@ -20,7 +20,7 @@ public class CVRPickupObjectTracker : MonoBehaviour
|
|||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool isVR, Camera activeCamera)
|
||||
public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
if (pickupObject != null)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace NAK.DesktopVRSwitch.Patches;
|
|||
public class CameraFacingObjectTracker : MonoBehaviour
|
||||
{
|
||||
public CameraFacingObject cameraFacingObject;
|
||||
|
||||
void Start()
|
||||
{
|
||||
cameraFacingObject = GetComponent<CameraFacingObject>();
|
||||
|
@ -17,7 +18,7 @@ public class CameraFacingObjectTracker : MonoBehaviour
|
|||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool isVR, Camera activeCamera)
|
||||
public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
cameraFacingObject.m_Camera = activeCamera;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using ABI_RC.Systems.IK;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.IK.TrackingModules;
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRSwitch.Patches;
|
||||
|
@ -9,53 +8,80 @@ namespace NAK.DesktopVRSwitch.Patches;
|
|||
public class IKSystemTracker : MonoBehaviour
|
||||
{
|
||||
public IKSystem ikSystem;
|
||||
public Traverse _traverseModules;
|
||||
|
||||
void Start()
|
||||
{
|
||||
ikSystem = GetComponent<IKSystem>();
|
||||
_traverseModules = Traverse.Create(ikSystem).Field("_trackingModules");
|
||||
VRModeSwitchTracker.OnPreVRModeSwitch += PreVRModeSwitch;
|
||||
VRModeSwitchTracker.OnFailVRModeSwitch += FailedVRModeSwitch;
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
VRModeSwitchTracker.OnPreVRModeSwitch -= PreVRModeSwitch;
|
||||
VRModeSwitchTracker.OnFailVRModeSwitch -= FailedVRModeSwitch;
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool isVR, Camera activeCamera)
|
||||
public void PreVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
var _trackingModules = _traverseModules.GetValue<List<TrackingModule>>();
|
||||
SteamVRTrackingModule openVRTrackingModule = _trackingModules.FirstOrDefault(m => m is SteamVRTrackingModule) as SteamVRTrackingModule;
|
||||
if (openVRTrackingModule != null)
|
||||
{
|
||||
if (isVR)
|
||||
{
|
||||
openVRTrackingModule.ModuleStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
//why named destroy when it doesnt ?
|
||||
openVRTrackingModule.ModuleDestroy();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var steamVRTrackingModule = CreateSteamVRTrackingModule();
|
||||
ikSystem.AddTrackingModule(steamVRTrackingModule);
|
||||
}
|
||||
BodySystem.TrackingEnabled = false;
|
||||
BodySystem.TrackingPositionWeight = 0f;
|
||||
BodySystem.TrackingLocomotionEnabled = false;
|
||||
if (IKSystem.vrik != null)
|
||||
IKSystem.vrik.enabled = false;
|
||||
}
|
||||
|
||||
public void FailedVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
BodySystem.TrackingEnabled = true;
|
||||
BodySystem.TrackingPositionWeight = 1f;
|
||||
BodySystem.TrackingLocomotionEnabled = true;
|
||||
if (IKSystem.vrik != null)
|
||||
IKSystem.vrik.enabled = true;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
if (IKSystem.vrik != null)
|
||||
DestroyImmediate(IKSystem.vrik);
|
||||
|
||||
//make sure you are fully tracking
|
||||
BodySystem.TrackingEnabled = true;
|
||||
BodySystem.TrackingPositionWeight = 1f;
|
||||
BodySystem.TrackingLocomotionEnabled = true;
|
||||
BodySystem.isCalibratedAsFullBody = false;
|
||||
BodySystem.isCalibrating = false;
|
||||
BodySystem.isRecalibration = false;
|
||||
//make it so you dont instantly end up in FBT from Desktop
|
||||
IKSystem.firstAvatarLoaded = DesktopVRSwitch.EntryEnterCalibrationOnSwitch.Value;
|
||||
//turn of finger tracking just in case user switched controllers
|
||||
ikSystem.FingerSystem.controlActive = false;
|
||||
|
||||
//vrik should be deleted by avatar switch
|
||||
|
||||
SetupSteamVRTrackingModule(enableVR);
|
||||
}
|
||||
|
||||
//thanks for marking the constructor as internal
|
||||
private SteamVRTrackingModule CreateSteamVRTrackingModule()
|
||||
void SetupSteamVRTrackingModule(bool enableVR)
|
||||
{
|
||||
var steamVRTrackingModuleType = typeof(SteamVRTrackingModule);
|
||||
var constructor = steamVRTrackingModuleType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
|
||||
var instance = constructor.Invoke(null);
|
||||
return (SteamVRTrackingModule)instance;
|
||||
var openVRModule = ikSystem._trackingModules.OfType<SteamVRTrackingModule>().FirstOrDefault();
|
||||
|
||||
if (openVRModule != null)
|
||||
{
|
||||
if (enableVR)
|
||||
{
|
||||
openVRModule.ModuleStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
openVRModule.ModuleDestroy();
|
||||
}
|
||||
}
|
||||
else if (enableVR)
|
||||
{
|
||||
var newVRModule = new SteamVRTrackingModule();
|
||||
ikSystem.AddTrackingModule(newVRModule);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,17 +12,17 @@ public class MovementSystemTracker : MonoBehaviour
|
|||
void Start()
|
||||
{
|
||||
movementSystem = GetComponent<MovementSystem>();
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch += PreVRModeSwitch;
|
||||
VRModeSwitchTracker.OnPreVRModeSwitch += PreVRModeSwitch;
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch -= PreVRModeSwitch;
|
||||
VRModeSwitchTracker.OnPreVRModeSwitch -= PreVRModeSwitch;
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PreVRModeSwitch(bool isVR, Camera activeCamera)
|
||||
public void PreVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
//correct rotationPivot y position, so we dont teleport up/down
|
||||
Vector3 position = movementSystem.rotationPivot.transform.position;
|
||||
|
@ -34,15 +34,21 @@ public class MovementSystemTracker : MonoBehaviour
|
|||
|
||||
//I correct for this in lazy way, but i use rotationPivot instead of avatar root,
|
||||
//so the user can still switch even if avatar is null (if it failed to load for example).
|
||||
|
||||
movementSystem.ChangeCrouch(false);
|
||||
movementSystem.ChangeProne(false);
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool isVR, Camera activeCamera)
|
||||
public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
//immediatly update camera to new camera transform
|
||||
movementSystem.rotationPivot = activeCamera.transform;
|
||||
//lazy way of correcting Desktop & VR offset issue (game does the maths)
|
||||
movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false);
|
||||
//recenter desktop collision to player object
|
||||
if (!isVR) movementSystem.UpdateColliderCenter(movementSystem.transform.position);
|
||||
if (!enableVR) movementSystem.UpdateColliderCenter(movementSystem.transform.position);
|
||||
|
||||
movementSystem.ChangeCrouch(false);
|
||||
movementSystem.ChangeProne(false);
|
||||
}
|
||||
}
|
|
@ -10,35 +10,35 @@ public class VRModeSwitchTracker
|
|||
public static event UnityAction<bool, Camera> OnPostVRModeSwitch;
|
||||
public static event UnityAction<bool, Camera> OnFailVRModeSwitch;
|
||||
|
||||
public static void PreVRModeSwitch(bool isVR)
|
||||
public static void PreVRModeSwitch(bool enableVR)
|
||||
{
|
||||
TryCatchHell.TryCatchWrapper(() =>
|
||||
{
|
||||
DesktopVRSwitch.Logger.Msg("Invoking VRModeSwitchTracker.OnPreVRModeSwitch.");
|
||||
Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>();
|
||||
VRModeSwitchTracker.OnPreVRModeSwitch?.Invoke(isVR, activeCamera);
|
||||
VRModeSwitchTracker.OnPreVRModeSwitch?.Invoke(enableVR, activeCamera);
|
||||
},
|
||||
"Error while invoking VRModeSwitchTracker.OnPreVRModeSwitch. Did someone do a fucky?");
|
||||
}
|
||||
|
||||
public static void PostVRModeSwitch(bool isVR)
|
||||
public static void PostVRModeSwitch(bool enableVR)
|
||||
{
|
||||
TryCatchHell.TryCatchWrapper(() =>
|
||||
{
|
||||
DesktopVRSwitch.Logger.Msg("Invoking VRModeSwitchTracker.OnPostVRModeSwitch.");
|
||||
Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>();
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch?.Invoke(isVR, activeCamera);
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch?.Invoke(enableVR, activeCamera);
|
||||
},
|
||||
"Error while invoking VRModeSwitchTracker.OnPostVRModeSwitch. Did someone do a fucky?");
|
||||
}
|
||||
|
||||
public static void FailVRModeSwitch(bool isVR)
|
||||
public static void FailVRModeSwitch(bool enableVR)
|
||||
{
|
||||
TryCatchHell.TryCatchWrapper(() =>
|
||||
{
|
||||
DesktopVRSwitch.Logger.Msg("Invoking VRModeSwitchTracker.OnFailVRModeSwitch.");
|
||||
Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>();
|
||||
VRModeSwitchTracker.OnFailVRModeSwitch?.Invoke(isVR, activeCamera);
|
||||
VRModeSwitchTracker.OnFailVRModeSwitch?.Invoke(enableVR, activeCamera);
|
||||
},
|
||||
"Error while invoking OnFailVRModeSwitch.OnPreVRModeSwitch. Did someone do a fucky?");
|
||||
}
|
||||
|
|
|
@ -7,14 +7,10 @@ namespace NAK.DesktopVRSwitch.Patches;
|
|||
public class VRTrackerManagerTracker : MonoBehaviour
|
||||
{
|
||||
public VRTrackerManager vrTrackerManager;
|
||||
public Traverse _hasCheckedForKnucklesTraverse;
|
||||
public Traverse _posesTraverse;
|
||||
|
||||
void Start()
|
||||
{
|
||||
vrTrackerManager = GetComponent<VRTrackerManager>();
|
||||
_posesTraverse = Traverse.Create(vrTrackerManager).Field("poses");
|
||||
_hasCheckedForKnucklesTraverse = Traverse.Create(vrTrackerManager).Field("hasCheckedForKnuckles");
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
|
||||
}
|
||||
void OnDestroy()
|
||||
|
@ -22,14 +18,14 @@ public class VRTrackerManagerTracker : MonoBehaviour
|
|||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool isVR, Camera activeCamera)
|
||||
public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
|
||||
{
|
||||
//force the VRTrackerManager to reset anything its stored
|
||||
//this makes it get correct Left/Right hand if entering VR with different controllers
|
||||
//or if you restarted SteamVR and controllers are now in swapped index
|
||||
vrTrackerManager.poses = null;
|
||||
vrTrackerManager.leftHand = null;
|
||||
vrTrackerManager.rightHand = null;
|
||||
_posesTraverse.SetValue(null);
|
||||
_hasCheckedForKnucklesTraverse.SetValue(false);
|
||||
vrTrackerManager.hasCheckedForKnuckles = false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue