[TrackedControllerFix] Fixes for 2023r171

This commit is contained in:
NotAKidoS 2023-07-28 23:13:24 -05:00
parent 2d6c4a3fc5
commit ffca0b8f3f
5 changed files with 90 additions and 50 deletions

View file

@ -4,11 +4,11 @@ using Valve.VR;
namespace NAK.TrackedControllerFix.HarmonyPatches; namespace NAK.TrackedControllerFix.HarmonyPatches;
class PlayerSetupPatches internal class PlayerSetupPatches
{ {
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))] [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.vrLeftHandTracker.AddComponent<TrackedControllerFixer>().inputSource = SteamVR_Input_Sources.LeftHand;
__instance.vrRightHandTracker.AddComponent<TrackedControllerFixer>().inputSource = SteamVR_Input_Sources.RightHand; __instance.vrRightHandTracker.AddComponent<TrackedControllerFixer>().inputSource = SteamVR_Input_Sources.RightHand;

View file

@ -9,7 +9,7 @@ public class TrackedControllerFix : MelonMod
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
} }
void ApplyPatches(Type type) private void ApplyPatches(Type type)
{ {
try try
{ {

View file

@ -20,11 +20,13 @@ using System.Reflection;
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] [assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
[assembly: MelonColor(255, 52, 152, 219)]
[assembly: MelonAuthorColor(255, 158, 21, 32)]
[assembly: HarmonyDontPatchAll] [assembly: HarmonyDontPatchAll]
namespace NAK.TrackedControllerFix.Properties; namespace NAK.TrackedControllerFix.Properties;
internal static class AssemblyInfoParams internal static class AssemblyInfoParams
{ {
public const string Version = "1.0.5"; public const string Version = "1.0.6";
public const string Author = "NotAKidoS"; public const string Author = "NotAKidoS";
} }

View file

@ -1,72 +1,110 @@
using UnityEngine; using ABI_RC.Core.Savior;
using UnityEngine;
using Valve.VR; using Valve.VR;
namespace NAK.TrackedControllerFix; namespace NAK.TrackedControllerFix;
public class TrackedControllerFixer : MonoBehaviour public class TrackedControllerFixer : MonoBehaviour
{ {
#region Variables
public SteamVR_Input_Sources inputSource; public SteamVR_Input_Sources inputSource;
public int deviceIndex = -1; public int deviceIndex = -1;
SteamVR_TrackedObject trackedObject; private SteamVR_TrackedObject _trackedObject;
SteamVR_Behaviour_Pose oldBehaviourPose; private SteamVR_Behaviour_Pose _oldBehaviourPose;
SteamVR_Action_Pose actionPose; 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>(); _trackedObject = gameObject.AddComponent<SteamVR_TrackedObject>();
oldBehaviourPose = gameObject.GetComponent<SteamVR_Behaviour_Pose>(); _oldBehaviourPose = gameObject.GetComponent<SteamVR_Behaviour_Pose>();
oldBehaviourPose.broadcastDeviceChanges = false; //this fucks us _oldBehaviourPose.broadcastDeviceChanges = false; //this messes us up
oldBehaviourPose.enabled = false; _renderModel = gameObject.GetComponentInChildren<SteamVR_RenderModel>();
_actionPose = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose", false);
renderModel = gameObject.GetComponentInChildren<SteamVR_RenderModel>();
actionPose = SteamVR_Input.GetAction<SteamVR_Action_Pose>("Pose", false);
if (actionPose != null) CheckDeviceIndex();
} }
void OnEnable() private void OnEnable()
{ {
// DesktopVRSwitch support UpdateBehaviourPose(false);
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged += OnDeviceConnectedChanged; UpdateActionPose(true);
if (oldBehaviourPose != null)
oldBehaviourPose.enabled = false;
} }
void OnDisable() private void OnDisable()
{ {
// DesktopVRSwitch support UpdateBehaviourPose(true);
if (actionPose != null) actionPose[inputSource].onDeviceConnectedChanged -= OnDeviceConnectedChanged; UpdateActionPose(false);
if (oldBehaviourPose != null)
oldBehaviourPose.enabled = true;
} }
void Update() private void Update()
{ {
if (_oldBehaviourPose.enabled)
return;
if (deviceIndex < 0) if (deviceIndex < 0)
CheckDeviceIndex(); 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 (CheckVR.Instance.forceOpenXr)
if (changedSource != inputSource) return; 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(); CheckDeviceIndex();
} }
void CheckDeviceIndex() private void CheckDeviceIndex()
{ {
if (actionPose[inputSource].deviceIsConnected) if (!_actionPose[inputSource].deviceIsConnected)
{ return;
int trackedDeviceIndex = (int)actionPose[inputSource].trackedDeviceIndex;
if (deviceIndex != trackedDeviceIndex) int trackedDeviceIndex = (int)_actionPose[inputSource].trackedDeviceIndex;
{ if (deviceIndex == trackedDeviceIndex)
deviceIndex = trackedDeviceIndex; return;
trackedObject?.SetDeviceIndex(deviceIndex);
renderModel?.SetDeviceIndex(deviceIndex); deviceIndex = trackedDeviceIndex;
} _trackedObject?.SetDeviceIndex(deviceIndex);
} _renderModel?.SetDeviceIndex(deviceIndex);
} }
#endregion
} }

View file

@ -1,12 +1,12 @@
{ {
"_id": -1, "_id": 161,
"name": "TrackedControllerFix", "name": "TrackedControllerFix",
"modversion": "1.0.5", "modversion": "1.0.6",
"gameversion": "2022r170p1", "gameversion": "2023r171",
"loaderversion": "0.6.1", "loaderversion": "0.6.1",
"modtype": "Mod", "modtype": "Mod",
"author": "NotAKidoS", "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": [ "searchtags": [
"vr", "vr",
"quest", "quest",
@ -18,6 +18,6 @@
], ],
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r9/TrackedControllerFix.dll", "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r9/TrackedControllerFix.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/TrackedControllerFix/", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/TrackedControllerFix/",
"changelog": "Initial CVRMG Release", "changelog": "- Fixes for 2023r171.\n- Prevented from initializing when launching with OpenXR.",
"embedcolor": "3498db" "embedcolor": "#3498db"
} }