mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
dancing around issues
This commit is contained in:
parent
7403b6c3e7
commit
a8b97607e1
2 changed files with 60 additions and 35 deletions
|
@ -1,5 +1,4 @@
|
|||
using ABI_RC.Core.Base;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Player;
|
||||
using HarmonyLib;
|
||||
using Valve.VR;
|
||||
|
||||
|
@ -7,42 +6,14 @@ namespace NAK.Melons.TrackedControllerFix.HarmonyPatches;
|
|||
|
||||
internal class PlayerSetupPatches
|
||||
{
|
||||
public static SteamVR_Behaviour_Pose vrLeftHandPose;
|
||||
public static SteamVR_Behaviour_Pose vrRightHandPose;
|
||||
|
||||
public static SteamVR_TrackedObject vrLeftHandTracker;
|
||||
public static SteamVR_TrackedObject vrRightHandTracker;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "Start")]
|
||||
private static void Post_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
{
|
||||
// Add SteamVR_TrackedObject and get SteamVR_Behaviour_Pose
|
||||
vrLeftHandTracker = __instance.vrLeftHandTracker.AddComponent<SteamVR_TrackedObject>();
|
||||
vrRightHandTracker = __instance.vrRightHandTracker.AddComponent<SteamVR_TrackedObject>();
|
||||
vrLeftHandPose = __instance.vrLeftHandTracker.GetComponent<SteamVR_Behaviour_Pose>();
|
||||
vrRightHandPose = __instance.vrRightHandTracker.GetComponent<SteamVR_Behaviour_Pose>();
|
||||
vrLeftHandPose.enabled = false;
|
||||
vrRightHandPose.enabled = false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "SetupAvatarVr")]
|
||||
private static void Prefix_PlayerSetup_SetupAvatarVr()
|
||||
{
|
||||
// This is a super lazy way of doing this...
|
||||
// but this is the best way to support DesktopVRSwitch & not redo the controller inputs
|
||||
if (vrLeftHandTracker != null)
|
||||
{
|
||||
vrLeftHandPose.enabled = true;
|
||||
vrLeftHandTracker.SetDeviceIndex(vrLeftHandPose.GetDeviceIndex());
|
||||
vrLeftHandPose.enabled = false;
|
||||
}
|
||||
if (vrRightHandTracker != null)
|
||||
{
|
||||
vrRightHandPose.enabled = true;
|
||||
vrRightHandTracker.SetDeviceIndex(vrRightHandPose.GetDeviceIndex());
|
||||
vrRightHandPose.enabled = false;
|
||||
}
|
||||
// Add TrackedControllerFix
|
||||
var vrLeftHandTracker = __instance.vrLeftHandTracker.AddComponent<TrackedControllerFix>();
|
||||
vrLeftHandTracker.inputSource = SteamVR_Input_Sources.LeftHand;
|
||||
var vrRightHandTracker = __instance.vrRightHandTracker.AddComponent<TrackedControllerFix>();
|
||||
vrRightHandTracker.inputSource = SteamVR_Input_Sources.RightHand;
|
||||
}
|
||||
}
|
54
TrackedControllerFix/TrackedControllerFix.cs
Normal file
54
TrackedControllerFix/TrackedControllerFix.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using UnityEngine;
|
||||
using Valve.VR;
|
||||
|
||||
namespace NAK.Melons.TrackedControllerFix;
|
||||
|
||||
public class TrackedControllerFix : MonoBehaviour
|
||||
{
|
||||
public SteamVR_Input_Sources inputSource;
|
||||
public int deviceIndex;
|
||||
|
||||
private SteamVR_TrackedObject trackedObject;
|
||||
private SteamVR_Behaviour_Pose oldBehaviourPose;
|
||||
private SteamVR_Action_Pose actionPose = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose", false);
|
||||
|
||||
private void Start()
|
||||
{
|
||||
trackedObject = gameObject.AddComponent<SteamVR_TrackedObject>();
|
||||
oldBehaviourPose = gameObject.GetComponent<SteamVR_Behaviour_Pose>();
|
||||
oldBehaviourPose.broadcastDeviceChanges = false; //this fucks us
|
||||
if (actionPose != null) CheckDeviceIndex();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged += OnDeviceConnectedChanged;
|
||||
oldBehaviourPose.enabled = false;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged -= OnDeviceConnectedChanged;
|
||||
oldBehaviourPose.enabled = true;
|
||||
}
|
||||
|
||||
private void OnDeviceConnectedChanged(SteamVR_Action_Pose changedAction, SteamVR_Input_Sources changedSource, bool connected)
|
||||
{
|
||||
if (actionPose != changedAction) actionPose = changedAction;
|
||||
if (changedSource != inputSource) return;
|
||||
CheckDeviceIndex();
|
||||
}
|
||||
|
||||
private void CheckDeviceIndex()
|
||||
{
|
||||
if (actionPose[inputSource].active && actionPose[inputSource].deviceIsConnected)
|
||||
{
|
||||
int trackedDeviceIndex = (int)actionPose[inputSource].trackedDeviceIndex;
|
||||
if (deviceIndex != trackedDeviceIndex)
|
||||
{
|
||||
deviceIndex = trackedDeviceIndex;
|
||||
trackedObject.SetDeviceIndex(deviceIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue