mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[TrackedControllerFix] Fixes for 2023r171
This commit is contained in:
parent
2d6c4a3fc5
commit
ffca0b8f3f
5 changed files with 90 additions and 50 deletions
|
@ -4,11 +4,11 @@ using Valve.VR;
|
|||
|
||||
namespace NAK.TrackedControllerFix.HarmonyPatches;
|
||||
|
||||
class PlayerSetupPatches
|
||||
internal class PlayerSetupPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))]
|
||||
static void Post_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
private static void Postfix_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
{
|
||||
__instance.vrLeftHandTracker.AddComponent<TrackedControllerFixer>().inputSource = SteamVR_Input_Sources.LeftHand;
|
||||
__instance.vrRightHandTracker.AddComponent<TrackedControllerFixer>().inputSource = SteamVR_Input_Sources.RightHand;
|
||||
|
|
|
@ -9,7 +9,7 @@ public class TrackedControllerFix : MelonMod
|
|||
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
|
||||
}
|
||||
|
||||
void ApplyPatches(Type type)
|
||||
private void ApplyPatches(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -20,11 +20,13 @@ using System.Reflection;
|
|||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||
[assembly: MelonColor(255, 52, 152, 219)]
|
||||
[assembly: MelonAuthorColor(255, 158, 21, 32)]
|
||||
[assembly: HarmonyDontPatchAll]
|
||||
|
||||
namespace NAK.TrackedControllerFix.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.5";
|
||||
public const string Version = "1.0.6";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
|
@ -1,72 +1,110 @@
|
|||
using UnityEngine;
|
||||
using ABI_RC.Core.Savior;
|
||||
using UnityEngine;
|
||||
using Valve.VR;
|
||||
|
||||
namespace NAK.TrackedControllerFix;
|
||||
|
||||
public class TrackedControllerFixer : MonoBehaviour
|
||||
{
|
||||
#region Variables
|
||||
|
||||
public SteamVR_Input_Sources inputSource;
|
||||
public int deviceIndex = -1;
|
||||
|
||||
SteamVR_TrackedObject trackedObject;
|
||||
SteamVR_Behaviour_Pose oldBehaviourPose;
|
||||
SteamVR_Action_Pose actionPose;
|
||||
private SteamVR_TrackedObject _trackedObject;
|
||||
private SteamVR_Behaviour_Pose _oldBehaviourPose;
|
||||
private SteamVR_Action_Pose _actionPose;
|
||||
private SteamVR_RenderModel _renderModel;
|
||||
|
||||
SteamVR_RenderModel renderModel;
|
||||
#endregion
|
||||
|
||||
void Awake()
|
||||
#region Unity Methods
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
trackedObject = gameObject.AddComponent<SteamVR_TrackedObject>();
|
||||
oldBehaviourPose = gameObject.GetComponent<SteamVR_Behaviour_Pose>();
|
||||
oldBehaviourPose.broadcastDeviceChanges = false; //this fucks us
|
||||
oldBehaviourPose.enabled = false;
|
||||
|
||||
renderModel = gameObject.GetComponentInChildren<SteamVR_RenderModel>();
|
||||
|
||||
actionPose = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose", false);
|
||||
if (actionPose != null) CheckDeviceIndex();
|
||||
_trackedObject = gameObject.AddComponent<SteamVR_TrackedObject>();
|
||||
_oldBehaviourPose = gameObject.GetComponent<SteamVR_Behaviour_Pose>();
|
||||
_oldBehaviourPose.broadcastDeviceChanges = false; //this messes us up
|
||||
_renderModel = gameObject.GetComponentInChildren<SteamVR_RenderModel>();
|
||||
_actionPose = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose", false);
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
private void OnEnable()
|
||||
{
|
||||
// DesktopVRSwitch support
|
||||
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged += OnDeviceConnectedChanged;
|
||||
if (oldBehaviourPose != null)
|
||||
oldBehaviourPose.enabled = false;
|
||||
UpdateBehaviourPose(false);
|
||||
UpdateActionPose(true);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
private void OnDisable()
|
||||
{
|
||||
// DesktopVRSwitch support
|
||||
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged -= OnDeviceConnectedChanged;
|
||||
if (oldBehaviourPose != null)
|
||||
oldBehaviourPose.enabled = true;
|
||||
UpdateBehaviourPose(true);
|
||||
UpdateActionPose(false);
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
if (_oldBehaviourPose.enabled)
|
||||
return;
|
||||
|
||||
if (deviceIndex < 0)
|
||||
CheckDeviceIndex();
|
||||
}
|
||||
|
||||
void OnDeviceConnectedChanged(SteamVR_Action_Pose changedAction, SteamVR_Input_Sources changedSource, bool connected)
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateBehaviourPose(bool enable)
|
||||
{
|
||||
if (actionPose != changedAction) actionPose = changedAction;
|
||||
if (changedSource != inputSource) return;
|
||||
if (CheckVR.Instance.forceOpenXr)
|
||||
return;
|
||||
|
||||
if (_oldBehaviourPose == null)
|
||||
return;
|
||||
|
||||
_oldBehaviourPose.enabled = enable;
|
||||
}
|
||||
|
||||
private void UpdateActionPose(bool enable)
|
||||
{
|
||||
if (CheckVR.Instance.forceOpenXr)
|
||||
return;
|
||||
|
||||
if (_actionPose == null)
|
||||
return;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
_actionPose[inputSource].onDeviceConnectedChanged += OnDeviceConnectedChanged;
|
||||
CheckDeviceIndex();
|
||||
return;
|
||||
}
|
||||
|
||||
_actionPose[inputSource].onDeviceConnectedChanged -= OnDeviceConnectedChanged;
|
||||
}
|
||||
|
||||
private void OnDeviceConnectedChanged(SteamVR_Action_Pose changedAction, SteamVR_Input_Sources changedSource, bool connected)
|
||||
{
|
||||
_actionPose = changedAction;
|
||||
if (changedSource != inputSource)
|
||||
return;
|
||||
|
||||
CheckDeviceIndex();
|
||||
}
|
||||
|
||||
void CheckDeviceIndex()
|
||||
private void CheckDeviceIndex()
|
||||
{
|
||||
if (actionPose[inputSource].deviceIsConnected)
|
||||
{
|
||||
int trackedDeviceIndex = (int)actionPose[inputSource].trackedDeviceIndex;
|
||||
if (deviceIndex != trackedDeviceIndex)
|
||||
{
|
||||
deviceIndex = trackedDeviceIndex;
|
||||
trackedObject?.SetDeviceIndex(deviceIndex);
|
||||
renderModel?.SetDeviceIndex(deviceIndex);
|
||||
}
|
||||
}
|
||||
if (!_actionPose[inputSource].deviceIsConnected)
|
||||
return;
|
||||
|
||||
int trackedDeviceIndex = (int)_actionPose[inputSource].trackedDeviceIndex;
|
||||
if (deviceIndex == trackedDeviceIndex)
|
||||
return;
|
||||
|
||||
deviceIndex = trackedDeviceIndex;
|
||||
_trackedObject?.SetDeviceIndex(deviceIndex);
|
||||
_renderModel?.SetDeviceIndex(deviceIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"_id": -1,
|
||||
"_id": 161,
|
||||
"name": "TrackedControllerFix",
|
||||
"modversion": "1.0.5",
|
||||
"gameversion": "2022r170p1",
|
||||
"modversion": "1.0.6",
|
||||
"gameversion": "2023r171",
|
||||
"loaderversion": "0.6.1",
|
||||
"modtype": "Mod",
|
||||
"author": "NotAKidoS",
|
||||
"description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.\n\nSupport for SmoothRay & DesktopVRSwitch.",
|
||||
"description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.\n\nSupport for SmoothRay & DesktopVRSwitch.\n**Only supports OpenVR, not OpenXR.**",
|
||||
"searchtags": [
|
||||
"vr",
|
||||
"quest",
|
||||
|
@ -18,6 +18,6 @@
|
|||
],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r9/TrackedControllerFix.dll",
|
||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/TrackedControllerFix/",
|
||||
"changelog": "Initial CVRMG Release",
|
||||
"embedcolor": "3498db"
|
||||
"changelog": "- Fixes for 2023r171.\n- Prevented from initializing when launching with OpenXR.",
|
||||
"embedcolor": "#3498db"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue