diff --git a/Source/Networking/VRNetPlayer.cs b/Source/Networking/VRNetPlayer.cs index 869df166..2d147d0d 100644 --- a/Source/Networking/VRNetPlayer.cs +++ b/Source/Networking/VRNetPlayer.cs @@ -15,7 +15,6 @@ namespace LCVR.Networking; /// /// A behaviour that is attached to other VR players /// -[DefaultExecutionOrder(-100)] public class VRNetPlayer : MonoBehaviour { private GameObject playerGhost; @@ -171,6 +170,9 @@ private void Awake() else component.enabled = true; } + + // Create a "prefix" script that runs before other game scripts + gameObject.AddComponent(); } private void BuildVRRig() @@ -247,6 +249,8 @@ private void BuildVRRig() private void Update() { + UpdateIKWeights(); + // Apply crouch offset crouchOffset = Mathf.Lerp(crouchOffset, crouchState switch { @@ -295,8 +299,6 @@ private void Update() private void LateUpdate() { - UpdateBones(); - var positionOffset = new Vector3(0, crouchState switch { CrouchState.Roomscale => 0.1f, @@ -370,14 +372,8 @@ private void LateUpdate() if (StartOfRound.Instance.localPlayerController.localVisorTargetPoint is not null) usernameBillboard.LookAt(StartOfRound.Instance.localPlayerController.localVisorTargetPoint); } - - private void UpdateBones() - { - Bones.ServerItemHolder.localPosition = new Vector3(0.002f, 0.056f, -0.046f); - Bones.ServerItemHolder.localRotation = Quaternion.identity; - } - public void UpdateIKWeights() + private void UpdateIKWeights() { // Constants PlayerController.cameraLookRig1.weight = 0.45f; @@ -566,6 +562,31 @@ public class PlayerData { public bool DisableSteeringWheel { get; set; } } + + /// + /// A script for remote VR players that runs before other scripts in the game + /// + [DefaultExecutionOrder(-100)] + private class VRNetPlayerEarly : MonoBehaviour + { + private VRNetPlayer player; + + private void Awake() + { + player = GetComponent(); + } + + private void LateUpdate() + { + UpdateBones(); + } + + private void UpdateBones() + { + player.Bones.ServerItemHolder.localPosition = new Vector3(0.002f, 0.056f, -0.046f); + player.Bones.ServerItemHolder.localRotation = Quaternion.identity; + } + } } [Serialize] diff --git a/Source/Patches/PlayerControllerPatches.cs b/Source/Patches/PlayerControllerPatches.cs index dc63a687..d33ae2f6 100644 --- a/Source/Patches/PlayerControllerPatches.cs +++ b/Source/Patches/PlayerControllerPatches.cs @@ -357,7 +357,7 @@ static Vector3 GetClampedCameraPosition(PlayerControllerB player) } /// - /// Allow interacting with items even when we're inside of a special menu + /// Allow interacting with items even when we're inside a special menu /// [HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.ActivateItem_performed))] [HarmonyTranspiler] @@ -377,27 +377,6 @@ private static IEnumerable AllowActivateDuringMenu(IEnumerable< [HarmonyPatch] internal static class UniversalPlayerControllerPatches { - /// - /// Prevent the use of the secondary arm rigs, so that VR arms still freely move when inside the Company Cruiser - /// - [HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.Update))] - [HarmonyPostfix] - private static void KeepRigConstraints(PlayerControllerB __instance) - { - // Handle IK for local player - if (VRSession.InVR && __instance.IsLocalPlayer() && VRSession.Instance is {} session) - { - session.LocalPlayer.UpdateIKWeights(); - return; - } - - // Handle IK for remote player - if (NetworkSystem.Instance.TryGetPlayer((ushort)__instance.playerClientId, out var player)) - { - player.UpdateIKWeights(); - } - } - /// /// Disable the EnterLadder animation to fix some clunkyness with holding items /// diff --git a/Source/Player/VRPlayer.cs b/Source/Player/VRPlayer.cs index 7b34cd5b..aa6e98b2 100644 --- a/Source/Player/VRPlayer.cs +++ b/Source/Player/VRPlayer.cs @@ -482,6 +482,8 @@ private void ResetHeight_performed(InputAction.CallbackContext obj) private void Update() { + UpdateIKWeights(); + // Make sure the XR Origin has the same parent as the player if (xrOrigin.parent != transform.parent) { @@ -720,7 +722,7 @@ private void OnDestroy() Actions.Instance["Reset Height"].performed -= ResetHeight_performed; } - public void UpdateIKWeights() + private void UpdateIKWeights() { // Constants PlayerController.cameraLookRig1.weight = 0.45f; diff --git a/Source/Plugin.cs b/Source/Plugin.cs index 58ba3d0a..7e0dcbff 100644 --- a/Source/Plugin.cs +++ b/Source/Plugin.cs @@ -25,7 +25,7 @@ public class Plugin : BaseUnityPlugin { public const string PLUGIN_GUID = "io.daxcess.lcvr"; public const string PLUGIN_NAME = "LCVR"; - public const string PLUGIN_VERSION = "1.3.3"; + public const string PLUGIN_VERSION = "1.3.4"; #if DEBUG private const string SKIP_CHECKSUM_VAR = $"--lcvr-skip-checksum={PLUGIN_VERSION}-dev";