diff --git a/TrackedControllerFix/HarmonyPatches.cs b/TrackedControllerFix/HarmonyPatches.cs new file mode 100644 index 0000000..ce8110e --- /dev/null +++ b/TrackedControllerFix/HarmonyPatches.cs @@ -0,0 +1,19 @@ +using ABI_RC.Core.Player; +using HarmonyLib; +using Valve.VR; + +namespace NAK.Melons.TrackedControllerFix.HarmonyPatches; + +internal class PlayerSetupPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), "Start")] + private static void Post_PlayerSetup_Start(ref PlayerSetup __instance) + { + // Add TrackedControllerFix + var vrLeftHandTracker = __instance.vrLeftHandTracker.AddComponent(); + vrLeftHandTracker.inputSource = SteamVR_Input_Sources.LeftHand; + var vrRightHandTracker = __instance.vrRightHandTracker.AddComponent(); + vrRightHandTracker.inputSource = SteamVR_Input_Sources.RightHand; + } +} \ No newline at end of file diff --git a/TrackedControllerFix/Main.cs b/TrackedControllerFix/Main.cs new file mode 100644 index 0000000..1f303a8 --- /dev/null +++ b/TrackedControllerFix/Main.cs @@ -0,0 +1,24 @@ +using MelonLoader; + +namespace NAK.Melons.TrackedControllerFix; + +public class TrackedControllerFixMod : MelonMod +{ + public override void OnInitializeMelon() + { + ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); + } + + private void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } + } +} \ No newline at end of file diff --git a/TrackedControllerFix/Properties/AssemblyInfo.cs b/TrackedControllerFix/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6e0b55a --- /dev/null +++ b/TrackedControllerFix/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using MelonLoader; +using NAK.Melons.TrackedControllerFix.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.Melons.TrackedControllerFix))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.Melons.TrackedControllerFix))] + +[assembly: MelonInfo( + typeof(NAK.Melons.TrackedControllerFix.TrackedControllerFixMod), + nameof(NAK.Melons.TrackedControllerFix), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/TrackedControllerFix" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.Melons.TrackedControllerFix.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.2"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/TrackedControllerFix/TrackedControllerFix.cs b/TrackedControllerFix/TrackedControllerFix.cs new file mode 100644 index 0000000..0078e3c --- /dev/null +++ b/TrackedControllerFix/TrackedControllerFix.cs @@ -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("Pose", false); + + private void Start() + { + trackedObject = gameObject.AddComponent(); + oldBehaviourPose = gameObject.GetComponent(); + 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); + } + } + } +} \ No newline at end of file diff --git a/TrackedControllerFix/TrackedControllerFix.csproj b/TrackedControllerFix/TrackedControllerFix.csproj new file mode 100644 index 0000000..e4c8455 --- /dev/null +++ b/TrackedControllerFix/TrackedControllerFix.csproj @@ -0,0 +1,70 @@ + + + + + netstandard2.1 + enable + latest + false + + + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Aura2_Core.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\SteamVR.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\UIExpansionKit.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.Postprocessing.Runtime.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.TextMeshPro.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.VRModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.XRModule.dll + + + + + + + + + diff --git a/TrackedControllerFix/TrackedControllerFix.sln b/TrackedControllerFix/TrackedControllerFix.sln new file mode 100644 index 0000000..da2e91a --- /dev/null +++ b/TrackedControllerFix/TrackedControllerFix.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrackedControllerFix", "TrackedControllerFix.csproj", "{988BC351-E04B-4756-A6FC-A7E55E830DB6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {988BC351-E04B-4756-A6FC-A7E55E830DB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {988BC351-E04B-4756-A6FC-A7E55E830DB6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {988BC351-E04B-4756-A6FC-A7E55E830DB6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {988BC351-E04B-4756-A6FC-A7E55E830DB6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F38A646E-1C36-4233-AC20-4E9F0CED9BDF} + EndGlobalSection +EndGlobal diff --git a/TrackedControllerFix/format.json b/TrackedControllerFix/format.json new file mode 100644 index 0000000..7d05f54 --- /dev/null +++ b/TrackedControllerFix/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "TrackedControllerFix", + "modversion": "1.0.0", + "gameversion": "2022r170", + "loaderversion": "0.5.7", + "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.", + "searchtags": [ + "vr", + "quest", + "controller", + "tracking" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/releases/download/v1.0.0/TrackedControllerFix.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/", + "changelog": "Initial Release", + "embedcolor": "3498db" +} \ No newline at end of file