示例#1
0
        private void Awake()
        {
            StaticLogger = Logger;

            VRAssetBundle = AssetBundle.LoadFromMemory(Properties.Resources.vrmodassets);

            ModConfig.Init();
            ActionAddons.Init();
            SettingsAddon.Init();
            UIFixes.Init();
            CameraFixes.Init();
            CutsceneFixes.Init();
            FocusChecker.Init();
            if (ModConfig.InitialMotionControlsValue)
            {
                RoR2.RoR2Application.isModded = true;
                MotionControls.Init();
                MotionControlledAbilities.Init();
                EntityStateAnimationParameter.Init();
            }

            RoR2.RoR2Application.onLoad += () =>
            {
                StartCoroutine(InitVR(ModConfig.InitialOculusModeValue));
                RecenterController.Init();
                UIPointer.Init();
            };
        }
示例#2
0
        private static void ControllerMovementDirection(ILContext il)
        {
            ILCursor c = new ILCursor(il);

            c.GotoNext(x => x.MatchStloc(5));
            c.EmitDelegate <Func <Transform, Transform> >((headTransform) =>
            {
                if (!ModConfig.ControllerMovementDirection.Value)
                {
                    return(headTransform);
                }

                if (MotionControls.HandsReady)
                {
                    // If controller movement tracking is enabled, replace the base camera transform with the controller transform.
                    return(MotionControls.GetHandByDominance(false).muzzle.transform);
                }
                else
                {
                    // See below for handling of the case where hands are not ready.
                    return(headTransform);
                }
            });

            c.GotoNext(x => x.MatchLdloca(6));
            c.GotoNext(x => x.MatchLdloca(6));

            c.Emit(OpCodes.Ldloc_S, (byte)6);
            c.EmitDelegate <Func <Vector2, Vector2> >((vector) =>
            {
                if (!ModConfig.ControllerMovementDirection.Value || MotionControls.HandsReady)
                {
                    return(vector);
                }

                // Special case only for if hands are not ready; in this case, we can't assume a hand transform exists, so we fall back to old logic.
                // Note: this will only provide y-axis rotation (yaw); z-axis rotation (pitch) will still be controlled by the head.

                Quaternion controllerRotation = InputTracking.GetLocalRotation(XRNode.LeftHand);
                Quaternion headRotation       = Camera.main.transform.localRotation;

                float angleDifference = headRotation.eulerAngles.y - controllerRotation.eulerAngles.y;

                return(Quaternion.Euler(new Vector3(0, 0, angleDifference)) * vector);
            });
            c.Emit(OpCodes.Stloc_S, (byte)6);

            c.GotoNext(x => x.MatchCallvirt <Transform>("get_right"));
            c.Index += 1;
            c.EmitDelegate <Func <Vector3, Vector3> >((vector) =>
            {
                if (!ModConfig.ControllerMovementDirection.Value || !MotionControls.HandsReady)
                {
                    return(vector);
                }
                // In flight mode, clamp the controller's left-right vector to the xz plane (normal to Vector3.up) so that only pitch and yaw are affected, not roll.
                return(Vector3.ProjectOnPlane(vector, Vector3.up).normalized *vector.magnitude);
            });
        }
示例#3
0
 private static void ChangeRayColor(object sender, EventArgs e)
 {
     RayColor = HexToColor(RayColorHex.Value);
     if (MotionControls.HandsReady)
     {
         MotionControls.UpdateRayColor();
     }
 }
示例#4
0
        private static void ChangeHandDominance(object sender, EventArgs e)
        {
            if (LeftDominantHand.Value == prevLeftHandedValue)
            {
                return;
            }

            prevLeftHandedValue = LeftDominantHand.Value;

            Controllers.ChangeDominanceDependantMaps();
            MotionControls.UpdateDominance();
        }
示例#5
0
        private static Ray GetVRCrosshairRaycastRay(On.RoR2.CameraModes.CameraModePlayerBasic.orig_GetCrosshairRaycastRay orig, RoR2.CameraModes.CameraModePlayerBasic self, ref RoR2.CameraModes.CameraModeBase.CameraModeContext context, Vector2 crosshairOffset, Vector3 raycastStartPlanePoint, ref CameraState cameraState)
        {
            if (MotionControls.HandsReady)
            {
                return(MotionControls.GetHandByDominance(true).aimRay);
            }

            Camera sceneCam = context.cameraInfo.sceneCam;

            if (!sceneCam)
            {
                return(default(Ray));
            }
            float      fov        = sceneCam.fieldOfView;
            float      num        = fov * sceneCam.aspect;
            Quaternion quaternion = Quaternion.Euler(crosshairOffset.y * fov, crosshairOffset.x * num, 0f);

            quaternion = sceneCam.transform.rotation * quaternion;
            return(new Ray(Vector3.ProjectOnPlane(sceneCam.transform.position - raycastStartPlanePoint, sceneCam.transform.rotation * Vector3.forward) + raycastStartPlanePoint, quaternion * Vector3.forward));
        }
示例#6
0
        internal static void AdjustHUD(HUD hud)
        {
            if (ModConfig.InitialMotionControlsValue)
            {
                CrosshairManager crosshairManager = hud.GetComponent <CrosshairManager>();

                if (crosshairManager)
                {
                    //Thanks HutchyBen
                    crosshairManager.hitmarker.enabled = false;
                }
            }

            Transform steamBuild = hud.mainContainer.transform.Find("SteamBuildLabel");

            if (steamBuild)
            {
                steamBuild.gameObject.SetActive(false);
            }

            RectTransform springCanvas = hud.mainUIPanel.transform.Find("SpringCanvas") as RectTransform;

            springCanvas.anchorMin = ModConfig.AnchorMin;
            springCanvas.anchorMax = ModConfig.AnchorMax;

            RectTransform notificationArea = hud.mainContainer.transform.Find("NotificationArea") as RectTransform;

            notificationArea.anchorMin = new Vector2(0.5f, ModConfig.AnchorMin.y);
            notificationArea.anchorMax = new Vector2(0.5f, ModConfig.AnchorMin.y);

            RectTransform mapNameCluster = hud.mainContainer.transform.Find("MapNameCluster") as RectTransform;

            mapNameCluster.anchorMin = new Vector2(0.5f, (ModConfig.AnchorMax.y - 0.5f) * 0.54f + 0.5f);
            mapNameCluster.anchorMax = new Vector2(0.5f, (ModConfig.AnchorMax.y - 0.5f) * 0.54f + 0.5f);

            RectTransform scoreboardPanel = springCanvas.Find("ScoreboardPanel") as RectTransform;

            scoreboardPanel.offsetMin = new Vector2(0, scoreboardPanel.offsetMin.y);
            scoreboardPanel.offsetMax = new Vector2(0, scoreboardPanel.offsetMax.y);

            if (!GetUICamera())
            {
                return;
            }

            hud.canvas.renderMode = RenderMode.WorldSpace;
            RectTransform rectTransform = hud.transform as RectTransform;

            rectTransform.sizeDelta  = new Vector2(ModConfig.HUDWidth.Value, ModConfig.HUDHeight.Value);
            rectTransform.localScale = menuScale;
            rectTransform.SetParent(cachedUICam.transform);
            rectTransform.localRotation = Quaternion.identity;
            rectTransform.localPosition = new Vector3(0, 0, 12.35f);
            rectTransform.pivot         = menuPivot;


            if (ModConfig.TempWristHUDValue)
            {
                RectTransform healthCluster = springCanvas.Find("BottomLeftCluster/BarRoots") as RectTransform;
                healthCluster.pivot = new Vector2(0.5f, 0f);

                if (ModConfig.BetterHealthBar.Value)
                {
                    healthCluster.SetParent(springCanvas);
                    healthCluster.localRotation = Quaternion.identity;
                    healthCluster.offsetMin     = new Vector2(300, healthCluster.offsetMin.y);
                    healthCluster.offsetMax     = new Vector2(-300, healthCluster.offsetMax.y);

                    Vector3 notificationPosition = notificationArea.localPosition;
                    notificationPosition.y        += 80;
                    notificationArea.localPosition = notificationPosition;

                    RectTransform spectatorLabel = springCanvas.Find("BottomCenterCluster/SpectatorLabel") as RectTransform;

                    Vector3 labelPosition = spectatorLabel.localPosition;
                    labelPosition.y += 68;
                    spectatorLabel.localPosition = labelPosition;
                }
                else
                {
                    healthCluster.localRotation = Quaternion.identity;
                    healthCluster.localPosition = Vector3.zero;
                    MotionControls.AddWristHUD(true, healthCluster);
                }

                RectTransform moneyCluster = springCanvas.Find("UpperLeftCluster") as RectTransform;
                moneyCluster.localRotation = Quaternion.identity;
                moneyCluster.pivot         = new Vector2(0.5f, 1f);
                moneyCluster.localPosition = Vector3.zero;
                MotionControls.AddWristHUD(true, moneyCluster);

                RectTransform contextCluster = springCanvas.Find("RightCluster") as RectTransform;
                contextCluster.localRotation = Quaternion.identity;
                contextCluster.pivot         = new Vector2(0f, 0f);
                contextCluster.localPosition = Vector3.zero;
                (contextCluster.GetChild(0) as RectTransform).pivot = new Vector2(0f, 2f);
                MotionControls.AddWristHUD(false, contextCluster);

                RectTransform cooldownsCluster = springCanvas.Find("BottomRightCluster") as RectTransform;
                cooldownsCluster.localRotation = Quaternion.identity;
                cooldownsCluster.pivot         = new Vector2(0.2f, -0.6f);
                cooldownsCluster.localPosition = Vector3.zero;
                MotionControls.AddWristHUD(false, cooldownsCluster);

                MotionControls.SetSprintIcon(cooldownsCluster.Find("Scaler/SprintCluster/SprintIcon").GetComponent <Image>());
            }

            if (ModConfig.TempWatchHUDValue)
            {
                Transform  topCluster   = springCanvas.Find("TopCenterCluster");
                GameObject clusterClone = GameObject.Instantiate(topCluster.gameObject, topCluster.parent);
                foreach (Transform child in clusterClone.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }
                RectTransform cloneRect = clusterClone.transform as RectTransform;
                cloneRect.pivot         = new Vector2(0.5f, 1f);
                cloneRect.localPosition = Vector3.zero;
                RectTransform inventoryCluster = topCluster.Find("ItemInventoryDisplayRoot") as RectTransform;
                inventoryCluster.SetParent(cloneRect);
                inventoryCluster.localPosition = Vector3.zero;
                MotionControls.AddWatchHUD(true, cloneRect);

                RectTransform chatCluster = springCanvas.Find("BottomLeftCluster/ChatBoxRoot") as RectTransform;
                chatCluster.localRotation = Quaternion.identity;
                chatCluster.pivot         = new Vector2(0.5f, 0f);
                chatCluster.localPosition = Vector3.zero;
                MotionControls.AddWatchHUD(true, chatCluster);

                RectTransform difficultyCluster = springCanvas.Find("UpperRightCluster") as RectTransform;
                difficultyCluster.localRotation = Quaternion.identity;
                difficultyCluster.pivot         = new Vector2(-1f, -2.5f);
                difficultyCluster.localPosition = Vector3.zero;
                MotionControls.AddWatchHUD(false, difficultyCluster);

                RectTransform alliesCluster = springCanvas.Find("LeftCluster") as RectTransform;
                alliesCluster.localRotation = Quaternion.identity;
                alliesCluster.pivot         = new Vector2(1f, 0.5f);
                alliesCluster.localPosition = Vector3.zero;
                MotionControls.AddWatchHUD(false, alliesCluster);
            }

            if (ModConfig.UseSmoothHUD.Value)
            {
                hud.mainContainer.AddComponent <SmoothHUD>().Init(hud.cameraRigController.uiCam.transform);
            }
        }
示例#7
0
        private static void EditPointerPosition(On.RoR2.UI.MPInput.orig_Update orig, MPInput self)
        {
            if (!cachedUICam || !Utils.isUsingUI || Utils.localInputPlayer == null || Utils.localInputPlayer.controllers.GetLastActiveController() == null || Utils.localInputPlayer.controllers.GetLastActiveController().type == Rewired.ControllerType.Joystick)
            {
                if (cursorInstance && cursorInstance.activeSelf)
                {
                    cursorInstance.SetActive(false);
                }

                orig(self);
                return;
            }

            if (!cursorInstance && cursorPrefab)
            {
                cursorInstance = GameObject.Instantiate(cursorPrefab);
            }

            self.internalScreenPositionDelta = Vector2.zero;
            self._scrollDelta = new Vector2(0f, self.player.GetAxis(26));

            if (self.GetMouseButtonDown(0))
            {
                clickTime     = Time.realtimeSinceStartup;
                clickPosition = pointerHitPosition;
            }
            else if (self.GetMouseButtonUp(0))
            {
                clickTime = 0;
            }

            Camera uiCam = cachedUICam;

            Ray ray;

            if (MotionControls.HandsReady)
            {
                ray = MotionControls.GetHandByDominance(true).uiRay;
            }
            else
            {
                ray = new Ray(uiCam.transform.position, uiCam.transform.forward);
            }

            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100, LayerIndex.ui.mask))
            {
                pointerHitPosition = hit.point;

                if (cursorInstance)
                {
                    if (!cursorInstance.activeSelf)
                    {
                        cursorInstance.SetActive(true);
                    }

                    cursorInstance.transform.position = pointerHitPosition;
                    cursorInstance.transform.rotation = Quaternion.LookRotation(hit.normal, Vector3.up);
                }

                lastHitCanvas = hit.collider.GetComponent <Canvas>();
            }
            else if (cursorInstance.activeSelf)
            {
                cursorInstance.SetActive(false);
            }

            Vector3 mousePosition = uiCam.WorldToScreenPoint(pointerHitPosition);

            if (Time.realtimeSinceStartup - clickTime > 0.25f || (pointerHitPosition - clickPosition).magnitude > 1f)
            {
                self.internalMousePosition = mousePosition;
            }
        }