示例#1
0
 public static void Postfix(InputField ___m_nameInput)
 {
     if (VHVRConfig.UseVrControls())
     {
         InputManager.start(___m_nameInput, true);
     }
 }
示例#2
0
 public static void Postfix(InputField __instance)
 {
     if (VHVRConfig.UseVrControls() && __instance.inputType == InputField.InputType.Password)
     {
         InputManager.start(__instance, true);
     }
 }
示例#3
0
        private static bool InitializeXRSDKLoaders(XRManagerSettings managerSettings)
        {
            LogDebug("Initializing XRSDK Loaders...");
            if (managerSettings == null)
            {
                LogError("XRManagerSettings instance is null, cannot initialize loader.");
                return(false);
            }
            managerSettings.InitializeLoaderSync();
            if (managerSettings.activeLoader == null)
            {
                LogError("XRManager.activeLoader is null! Cannot initialize VR!");
                return(false);
            }
            OpenVRSettings openVrSettings = OpenVRSettings.GetSettings(false);

            if (openVrSettings != null)
            {
                OpenVRSettings.MirrorViewModes mirrorMode = VHVRConfig.GetMirrorViewMode();
                LogInfo("Mirror View Mode: " + mirrorMode);
                openVrSettings.SetMirrorViewMode(mirrorMode);
            }
            LogDebug("Got non-null Active Loader.");
            return(true);
        }
示例#4
0
 public static void Postfix(InputField __instance)
 {
     if (VHVRConfig.UseVrControls())
     {
         InputManager.start(__instance);
     }
 }
示例#5
0
        static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            var original = new List <CodeInstruction>(instructions);
            var patched  = new List <CodeInstruction>();

            if (!VHVRConfig.UseVrControls())
            {
                return(original);
            }
            bool addedInstruction = false;

            for (int i = 0; i < original.Count; i++)
            {
                var instruction = original[i];
                if (!addedInstruction && instruction.opcode == OpCodes.Ldc_I4)
                {
                    int operand = (int)instruction.operand;
                    if (operand == (int)KeyCode.LeftShift)
                    {
                        // Add our custom check
                        patched.Add(CodeInstruction.Call(typeof(InventoryGrid_OnLeftClick_Patch), nameof(getClickModifier)));
                        addedInstruction = true;
                        // Skip over the next instruction too since it will be the keycode comparison
                        i++;
                    }
                }
                else
                {
                    patched.Add(instruction);
                }
            }
            return(patched);
        }
            static void Postfix(Player __instance, ShipControlls ___m_shipControl)
            {
                if (__instance != Player.m_localPlayer || !VHVRConfig.UseVrControls())
                {
                    return;
                }
                var useAction = VRControls.instance.useLeftHandAction;

                if (useAction == null)
                {
                    LogWarning("Left Hand Use Action not initialized.");
                    return;
                }
                if (!useAction.GetStateDown(SteamVR_Input_Sources.LeftHand))
                {
                    if (useAction.GetState(SteamVR_Input_Sources.LeftHand) && leftHover)
                    {
                        Player_Interact_ReversePatch.Run(__instance, leftHover, true);
                    }
                }
                else if (leftHover)
                {
                    Player_Interact_ReversePatch.Run(__instance, leftHover, false);
                }
                else if (___m_shipControl)
                {
                    __instance.StopShipControl();
                }
            }
示例#7
0
            private static float calculateSmoothSnapAngle(float mouseX)
            {
                float dt = Time.deltaTime;

                currentDt += dt;
                if (currentDt < SMOOTH_SNAP_INCREMENT_TIME_DELTA)
                {
                    return(0f);
                }
                else
                {
                    // We've hit our deltaT target, so reset it and continue
                    // with calculating the next increment.
                    currentDt = 0f;
                }
                float finalSnapTarget     = VHVRConfig.GetSnapTurnAngle() * smoothSnapDirection;
                float smoothSnapIncrement = VHVRConfig.SmoothSnapSpeed() * smoothSnapDirection;

                if (Mathf.Abs(finalSnapTarget) > Mathf.Abs(currentSmoothSnapAmount + smoothSnapIncrement))
                {
                    // We can still increment by the full "smoothSnapIncrement" and
                    // be below our final target.
                    return(smoothSnapIncrement);
                }
                else
                {
                    // If we increment by the full amount, we'll exceed our target, so
                    // we should only return the difference
                    return((Mathf.Abs(finalSnapTarget) - Mathf.Abs(currentSmoothSnapAmount)) * smoothSnapDirection);
                }
            }
示例#8
0
        private void OnRenderObject()
        {
            fixedSpear.transform.position = transform.position;
            if (VHVRConfig.SpearTwoHanded())
            {
                if (SteamVR_Actions.valheim_Grab.GetState(SteamVR_Input_Sources.LeftHand) && SteamVR_Actions.valheim_Grab.GetState(SteamVR_Input_Sources.RightHand))
                {
                    UpdateTwoHandedWield();
                    return;
                }
                else if (SteamVR_Actions.valheim_Grab.GetStateUp(SteamVR_Input_Sources.LeftHand) || SteamVR_Actions.valheim_Grab.GetStateUp(SteamVR_Input_Sources.RightHand))
                {
                    _isTwoHanded = isTwoHanded.SingleHanded;
                    ResetSpearOffset();
                }
            }
            switch (VHVRConfig.SpearThrowType())
            {
            case "DartType":
                UpdateDartSpearThrowCalculation();
                return;

            case "TwoStagedThrowing":
                UpdateTwoStagedThrowCalculation();
                return;

            case "SecondHandAiming":
                UpdateSecondHandAimCalculation();
                return;

            default:
                UpdateDartSpearThrowCalculation();
                return;
            }
        }
示例#9
0
        private ThrowCalculate CalculateThrowAndDistance()
        {
            var     dist     = 0.0f;
            Vector3 posEnd   = Player.m_localPlayer.transform.InverseTransformPoint(VRPlayer.rightHand.transform.position);
            Vector3 posStart = Player.m_localPlayer.transform.InverseTransformPoint(VRPlayer.rightHand.transform.position);

            foreach (Vector3 snapshot in snapshots)
            {
                var curDist = Vector3.Distance(snapshot, posEnd);
                if (curDist > dist)
                {
                    dist     = curDist;
                    posStart = snapshot;
                }
            }

            var throwSpeed = 1f;

            if (VHVRConfig.SpearThrowSpeedDynamic())
            {
                var speedModifier = slowThrowModifier;
                if (dist > fastThrowMinDist)
                {
                    speedModifier = fastThrowModifier;
                }
                else if (dist > mediumThrowMinDist)
                {
                    speedModifier = mediumThrowModifier;
                }
                throwSpeed = Vector3.Distance(posEnd, posStart) * speedModifier;
            }
            return(new ThrowCalculate(posStart, posEnd, throwSpeed));
        }
示例#10
0
 void maybeUpdateHeadPosition()
 {
     if (VHVRConfig.AllowHeadRepositioning())
     {
         if (Input.GetKeyDown(VHVRConfig.GetHeadForwardKey()))
         {
             updateHeadOffset(new Vector3(0f, 0f, 0.1f));
         }
         if (Input.GetKeyDown(VHVRConfig.GetHeadBackwardKey()))
         {
             updateHeadOffset(new Vector3(0f, 0f, -0.1f));
         }
         if (Input.GetKeyDown(VHVRConfig.GetHeadLeftKey()))
         {
             updateHeadOffset(new Vector3(-0.1f, 0f, 0f));
         }
         if (Input.GetKeyDown(VHVRConfig.GetHeadRightKey()))
         {
             updateHeadOffset(new Vector3(0.1f, 0f, 0f));
         }
         if (Input.GetKeyDown(VHVRConfig.GetHeadUpKey()))
         {
             updateHeadOffset(new Vector3(0f, 0.1f, 0f));
         }
         if (Input.GetKeyDown(VHVRConfig.GetHeadDownKey()))
         {
             updateHeadOffset(new Vector3(0f, -0.1f, 0f));
         }
     }
 }
示例#11
0
            public override void OnEnable()
            {
                base.OnEnable();
                var sharpenAmmount = VHVRConfig.GetTaaSharpenAmmount();

                m_sharpenOverride = sharpenAmmount >= 0 && sharpenAmmount <= 3 ? (float?)sharpenAmmount : null;
            }
示例#12
0
        private void FixedUpdate()
        {
            tickCounter++;
            if (tickCounter < 5)
            {
                return;
            }

            snapshots.Add(Player.m_localPlayer.transform.InverseTransformPoint(VRPlayer.rightHand.transform.position));

            if (snapshots.Count > MAX_SNAPSHOTS)
            {
                snapshots.RemoveAt(0);
            }

            tickCounter = 0;
            if (!VHVRConfig.UseSpearDirectionGraphic())
            {
                return;
            }

            if (directionCooldown <= 0)
            {
                directionCooldown     = 0;
                directionLine.enabled = false;
            }
            else if (!isThrowingStance)
            {
                directionCooldown -= Time.deltaTime * 5;
            }
        }
示例#13
0
        private void maybeInitHeadPosition(Player playerCharacter)
        {
            if (!headPositionInitialized && inFirstPerson)
            {
                // First set the position without any adjustment
                Vector3 desiredPosition = getDesiredPosition(playerCharacter);
                _instance.transform.localPosition = desiredPosition - playerCharacter.transform.position;

                if (_headZoomLevel != HeadZoomLevel.FirstPerson)
                {
                    _instance.transform.localPosition += getHeadOffset(_headZoomLevel);
                }
                else
                {
                    setPlayerVisualsOffset(playerCharacter.transform, -getHeadOffset(_headZoomLevel));
                }

                var hmd = Valve.VR.InteractionSystem.Player.instance.hmdTransform;
                // Measure the distance between HMD and desires location, and save it.
                FIRST_PERSON_HEIGHT_OFFSET = desiredPosition.y - hmd.position.y;
                if (VHVRConfig.UseLookLocomotion())
                {
                    _instance.transform.localRotation = Quaternion.Euler(0f, -hmd.localRotation.eulerAngles.y, 0f);
                }
                headPositionInitialized = true;

                referencePlayerHeight = Valve.VR.InteractionSystem.Player.instance.eyeHeight;
            }
        }
示例#14
0
        void StartValheimVR()
        {
            HarmonyPatcher.DoPatching();

            if (VHVRConfig.NonVrPlayer())
            {
                LogDebug("Non VR Mode Patching Complete.");
                return;
            }

            if (VRManager.InitializeVR())
            {
                VRManager.StartVR();
                vrPlayer = new GameObject("VRPlayer");
                DontDestroyOnLoad(vrPlayer);
                vrPlayer.AddComponent <VRPlayer>();
                vrGui = new GameObject("VRGui");
                DontDestroyOnLoad(vrGui);
                vrGui.AddComponent <VRGUI>();
                if (VHVRConfig.RecenterOnStart())
                {
                    VRManager.tryRecenter();
                }
            }
            else
            {
                LogError("Could not initialize VR.");
                enabled = false;
            }
        }
示例#15
0
 static void Prefix(ref float bowDrawPercentage)
 {
     if (VHVRConfig.UseVrControls())
     {
         bowDrawPercentage = 0;
     }
 }
示例#16
0
        static bool Prefix(out Vector3 spawnPoint, out Vector3 aimDir, Humanoid ___m_character)
        {
            spawnPoint = Vector3.zero;
            aimDir     = Vector3.zero;

            if (___m_character != Player.m_localPlayer || !VHVRConfig.UseVrControls())
            {
                return(true);
            }

            if (EquipScript.getLeft() == EquipType.Bow)
            {
                spawnPoint = BowLocalManager.spawnPoint;
                aimDir     = BowLocalManager.aimDir;
                return(false);
            }

            switch (EquipScript.getRight())
            {
            case EquipType.Fishing:
                spawnPoint = FishingManager.spawnPoint;
                aimDir     = FishingManager.aimDir;
                return(false);

            case EquipType.Spear:
            case EquipType.SpearChitin:
                spawnPoint = SpearManager.spawnPoint;
                aimDir     = SpearManager.aimDir;
                return(false);
            }

            return(true);
        }
 static void Postfix()
 {
     if (StaticObjects.quickSwitch != null && VHVRConfig.UseVrControls())
     {
         StaticObjects.quickSwitch.GetComponent <QuickSwitch>().refreshItems();
         StaticObjects.quickActions.GetComponent <QuickActions>().refreshItems();
     }
 }
 public static void Postfix(Player __instance)
 {
     if (VHVRConfig.NonVrPlayer() || __instance != Player.m_localPlayer)
     {
         return;
     }
     __instance.FaceLookDirection();
 }
示例#19
0
 public static void Postfix(TextInput __instance)
 {
     if (VHVRConfig.UseVrControls())
     {
         instance = __instance;
         InputManager.start(instance.m_textField, true, OnClose);
     }
 }
示例#20
0
 static bool Prefix(Player __instance)
 {
     if (VHVRConfig.NonVrPlayer())
     {
         return(true);
     }
     return(__instance != Player.m_localPlayer);
 }
 public static void Postfix(Player __instance, ref Vector3 ___m_lookDir)
 {
     if (VHVRConfig.NonVrPlayer() || __instance != Player.m_localPlayer || !VRPlayer.attachedToPlayer)
     {
         return;
     }
     ___m_lookDir = __instance.gameObject.transform.forward;
 }
示例#22
0
        static void Postfix(bool __result, string ___m_rightItem, ref GameObject ___m_rightItemInstance)
        {
            if (!__result || ___m_rightItemInstance == null)
            {
                return;
            }

            MeshFilter meshFilter = ___m_rightItemInstance.GetComponentInChildren <MeshFilter>();

            if (meshFilter == null)
            {
                return;
            }

            Player player = ___m_rightItemInstance.GetComponentInParent <Player>();

            if (player == null)
            {
                return;
            }

            var vrPlayerSync = player.GetComponent <VRPlayerSync>();

            if (vrPlayerSync != null)
            {
                player.GetComponent <VRPlayerSync>().currentRightWeapon      = meshFilter.gameObject;
                player.GetComponent <VRPlayerSync>().currentRightWeapon.name = ___m_rightItem;
                VrikCreator.resetVrikHandTransform(player);
            }

            if (Player.m_localPlayer != player || !VHVRConfig.UseVrControls())
            {
                return;
            }

            if (StaticObjects.quickSwitch != null)
            {
                StaticObjects.quickSwitch.GetComponent <QuickSwitch>().refreshItems();
                StaticObjects.quickActions.GetComponent <QuickActions>().refreshItems();
            }

            switch (EquipScript.getRight())
            {
            case EquipType.Fishing:
                meshFilter.gameObject.AddComponent <FishingManager>();
                return;

            case EquipType.Spear:
            case EquipType.SpearChitin:
                meshFilter.gameObject.AddComponent <SpearManager>();
                // (no return, we want collider for spear also)
                break;
            }

            StaticObjects.rightWeaponCollider().GetComponent <WeaponCollision>().setColliderParent(meshFilter.transform, ___m_rightItem, true);
            ParticleFix.maybeFix(___m_rightItemInstance);
        }
示例#23
0
        static void Prefix(Character ___m_character, ref Animator ___m_animator)
        {
            if (___m_character != Player.m_localPlayer || !VHVRConfig.UseVrControls())
            {
                return;
            }

            ___m_animator.speed = 1000f;
        }
示例#24
0
 private void updateAltPieceRotataionTimer()
 {
     altPieceRotationElapsedTime += Time.deltaTime;
     if (altPieceRotationElapsedTime >= ALT_PIECE_ROTATION_TIME_DELAY * VHVRConfig.AltPieceRotationDelay())
     {
         altPieceTriggered           = true;
         altPieceRotationElapsedTime = 0f;
     }
 }
示例#25
0
        static void Postfix(bool __result, GameObject ___m_beardItemInstance)
        {
            if (!__result || !VHVRConfig.UseVrControls())
            {
                return;
            }

            MeshHider.hide(___m_beardItemInstance);
        }
示例#26
0
        public void SetHudActive(Character c, bool active)
        {
            HudData data = getEnemyHud(c);

            if (data != null)
            {
                data.gui.SetActive(active && VHVRConfig.ShowEnemyHuds());
            }
        }
示例#27
0
 private static void Postfix()
 {
     if (!VHVRConfig.NonVrPlayer())
     {
         foreach (Material material in Resources.FindObjectsOfTypeAll <Material>())
         {
             material.SetInt("_CamCull", 0);
         }
     }
 }
示例#28
0
        static bool Prefix(ref Transform __result, ref Humanoid ___m_character)
        {
            if (___m_character != Player.m_localPlayer || !VHVRConfig.UseVrControls())
            {
                return(true);
            }

            __result = StaticObjects.rightWeaponCollider().transform;
            return(false);
        }
 static void Postfix(Player __instance, ref GameObject hover, int ___m_interactMask)
 {
     if (__instance != Player.m_localPlayer || !VHVRConfig.UseVrControls())
     {
         currentHitPositionRight = Vector3.zero;
         currentHitPositionLeft  = Vector3.zero;
         return;
     }
     UpdateHoverObject(__instance, ref hover, ___m_interactMask, VRPlayer.rightPointer, ref currentHitPositionRight);
     UpdateHoverObject(__instance, ref leftHover, ___m_interactMask, VRPlayer.leftPointer, ref currentHitPositionLeft);
 }
示例#30
0
        static void Postfix(bool __result, string ___m_leftItem, GameObject ___m_leftItemInstance)
        {
            if (!__result || ___m_leftItemInstance == null)
            {
                return;
            }

            MeshFilter meshFilter = ___m_leftItemInstance.GetComponentInChildren <MeshFilter>();

            if (meshFilter == null)
            {
                return;
            }

            Player player = ___m_leftItemInstance.GetComponentInParent <Player>();

            if (player == null)
            {
                return;
            }

            var vrPlayerSync = player.GetComponent <VRPlayerSync>();

            if (vrPlayerSync != null)
            {
                player.GetComponent <VRPlayerSync>().currentLeftWeapon = meshFilter.gameObject;
                VrikCreator.resetVrikHandTransform(player);
            }

            if (Player.m_localPlayer != player || !VHVRConfig.UseVrControls())
            {
                return;
            }

            if (StaticObjects.quickSwitch != null)
            {
                StaticObjects.quickSwitch.GetComponent <QuickSwitch>().refreshItems();
                StaticObjects.quickActions.GetComponent <QuickActions>().refreshItems();
            }

            switch (EquipScript.getLeft())
            {
            case EquipType.Bow:
                meshFilter.gameObject.AddComponent <BowLocalManager>();
                return;

            case EquipType.Shield:
                meshFilter.gameObject.AddComponent <ShieldManager>()._name = ___m_leftItem;
                return;
            }

            StaticObjects.leftWeaponCollider().GetComponent <WeaponCollision>().setColliderParent(meshFilter.transform, ___m_leftItem, false);
            ParticleFix.maybeFix(___m_leftItemInstance);
        }