diff --git a/TrackedControllerFix/HarmonyPatches.cs b/TrackedControllerFix/HarmonyPatches.cs index ad37b78..f8e8aa7 100644 --- a/TrackedControllerFix/HarmonyPatches.cs +++ b/TrackedControllerFix/HarmonyPatches.cs @@ -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().inputSource = SteamVR_Input_Sources.LeftHand; __instance.vrRightHandTracker.AddComponent().inputSource = SteamVR_Input_Sources.RightHand; diff --git a/TrackedControllerFix/Main.cs b/TrackedControllerFix/Main.cs index 1990d6f..ec78d2d 100644 --- a/TrackedControllerFix/Main.cs +++ b/TrackedControllerFix/Main.cs @@ -9,7 +9,7 @@ public class TrackedControllerFix : MelonMod ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); } - void ApplyPatches(Type type) + private void ApplyPatches(Type type) { try { diff --git a/TrackedControllerFix/Properties/AssemblyInfo.cs b/TrackedControllerFix/Properties/AssemblyInfo.cs index f2e67c4..e26c390 100644 --- a/TrackedControllerFix/Properties/AssemblyInfo.cs +++ b/TrackedControllerFix/Properties/AssemblyInfo.cs @@ -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"; } \ No newline at end of file diff --git a/TrackedControllerFix/TrackedControllerFixer.cs b/TrackedControllerFix/TrackedControllerFixer.cs index 1b265ce..0be8203 100644 --- a/TrackedControllerFix/TrackedControllerFixer.cs +++ b/TrackedControllerFix/TrackedControllerFixer.cs @@ -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(); - oldBehaviourPose = gameObject.GetComponent(); - oldBehaviourPose.broadcastDeviceChanges = false; //this fucks us - oldBehaviourPose.enabled = false; - - renderModel = gameObject.GetComponentInChildren(); - - actionPose = SteamVR_Input.GetAction("Pose", false); - if (actionPose != null) CheckDeviceIndex(); + _trackedObject = gameObject.AddComponent(); + _oldBehaviourPose = gameObject.GetComponent(); + _oldBehaviourPose.broadcastDeviceChanges = false; //this messes us up + _renderModel = gameObject.GetComponentInChildren(); + _actionPose = SteamVR_Input.GetAction("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 } \ No newline at end of file diff --git a/TrackedControllerFix/format.json b/TrackedControllerFix/format.json index 8344edb..2409c16 100644 --- a/TrackedControllerFix/format.json +++ b/TrackedControllerFix/format.json @@ -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" } \ No newline at end of file