예제 #1
0
        public void OnTick(object sender, EventArgs e)
        {
            _controllerEmulation.Enabled = !Game.IsPaused;
            _mouseEmulation.Enabled      = !Game.IsPaused && !_menuPool.IsAnyMenuOpen() && _isWindowForeground;

            CheckFreelookDevice();

            var lastMenuOpen = _menuOpen;

            _menuOpen = _menuPool.IsAnyMenuOpen();

            if (lastMenuOpen && !_menuOpen)
            {
                SaveSettings();
            }

            _isPaused = Game.IsPaused;
            Game.Player.Character.CanBeKnockedOffBike = _settings.DontFallFromBikesEnabled;             //Bug in Script hook
            CheckUserPresense();

            if (Game.IsPaused)
            {
                return;
            }

            _isInVehicle  = Game.Player.Character.IsInVehicle();
            _isInAircraft = Game.Player.Character.IsInPlane || Game.Player.Character.IsInHeli;

            Vector3 shootCoord;
            Vector3 shootCoordSnap;
            Vector3 shootMissileCoord;
            Ped     ped;

            FindGazeProjection(out shootCoord, out shootCoordSnap, out shootMissileCoord, out ped);

            ProcessControls(shootCoord, shootCoordSnap, shootMissileCoord);

            //TurnHead(ped, shootCoord);
            _menuPool.ProcessMenus();

            _aiming.Process();

            _gazeVisualization.Process();
            _debugOutput.Process();

            if (_settings.PedestrianInteractionEnabled)
            {
                if (ped != null && ped.Handle != Game.Player.Character.Handle)
                {
                    _pedestrianInteraction.ProcessLookingAtPedestrion(ped, _tickStopwatch.Elapsed);
                }

                _pedestrianInteraction.Process();
            }

            DrawDeadzones();
            DeadzoneCreator();
            DeadzoneMonitor();

            _mouseEmulation.ProcessInput();
            _tickStopwatch.Restart();
        }
예제 #2
0
        public void Process(DateTime tickStopwatch, Vector2 gazePoint, double aspectRatio, Vector3 shootCoord, Vector3 shootCoordSnap, Vector3 shootMissileCoord, Ped ped, Entity missileTarget)
        {
            _lastTickTime            = tickStopwatch;
            _isPaused                = Game.IsPaused;
            _isInVehicle             = Game.Player.Character.IsInVehicle();
            _isInAircraft            = Game.Player.Character.IsInPlane || Game.Player.Character.IsInHeli;
            _isMeleeWeapon           = Util.IsMelee(Game.Player.Character.Weapons.Current.Hash);
            _isThrowableWeapon       = Util.IsThrowable(Game.Player.Character.Weapons.Current.Hash);
            _isSniperWeaponAndZoomed = Util.IsSniper(Game.Player.Character.Weapons.Current.Hash) &&
                                       (GameplayCamera.IsFirstPersonAimCamActive);
            _menuOpen = _menuPool.IsAnyMenuOpen();

            var controllerState = _controllerEmulation.ControllerState;

            if (!_menuOpen &&
                (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) ||
                 User32.IsKeyPressed(VirtualKeyStates.VK_LMENU)))
            {
                //character selection
                _isInRadialMenu = true;
            }
            else if (!_isInVehicle && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
            {
                _isInRadialMenu = true;
                _radialMenu.Process(gazePoint, aspectRatio);
            }
            else
            {
                _isInRadialMenu = false;
                _freelook.Process(gazePoint, ped, aspectRatio);
            }

            if (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb) &&
                controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Start) &&
                !_menuOpen)
            {
                _settingsMenu.OpenMenu();
            }

            if (shootCoord.Length() > 0 && Geometry.IsInFrontOfThePlayer(shootCoord))
            {
                var injectRightTrigger = 0;
                if (_settings.FreelookDevice == FeeelookDevice.Gamepad &&
                    _settings.AimWithGazeEnabled &&
                    !Game.Player.Character.IsInVehicle() &&
                    Game.IsKeyPressed(Keys.B))
                {
                    injectRightTrigger += 1;
                }

                if (_settings.FreelookDevice == FeeelookDevice.Gamepad &&
                    _settings.ThirdPersonFreelookEnabled &&
                    Game.Player.Character.IsInVehicle() &&
                    Game.IsKeyPressed(Keys.W))
                {
                    _injectRightTrigger += 1;                     //TODO: block keyboard
                }

                _injectRightTrigger = injectRightTrigger;

                if (_settings.AimWithGazeEnabled &&
                    ((!_isInVehicle &&
                      !_isMeleeWeapon &&
                      !_isThrowableWeapon &&
                      !_isSniperWeaponAndZoomed &&
                      ((!_isInRadialMenu && controllerState.Gamepad.LeftTrigger > 0) ||
                       User32.IsKeyPressed(VirtualKeyStates.VK_RBUTTON)
                      )
                      )))
                {
                    if (!_lastAimCameraAtTarget)
                    {
                        _freelook.AimCameraAtTarget(shootCoordSnap);
                    }
                    _lastAimCameraAtTarget = true;
                }
                else
                {
                    _lastAimCameraAtTarget = false;
                }

                //If you use mouse - shoot in the middle of the screen
                if (!_isInVehicle &&
                    (User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON) ||
                     User32.IsKeyPressed(VirtualKeyStates.VK_RBUTTON)))
                {
                    Vector3 camPoint;
                    Geometry.ScreenRelToWorld(new Vector2(0, 0), out camPoint, out shootCoord);
                }

                if (_settings.AimWithGazeEnabled &&
                    !_isInVehicle &&
                    (!_isMeleeWeapon &&
                     !_isThrowableWeapon &&
                     !_isSniperWeaponAndZoomed &&
                     ((!_isInRadialMenu && controllerState.Gamepad.RightTrigger > 0) ||
                      (Game.IsKeyPressed(Keys.B))
                     )
                    )
                    )
                {
                    _aiming.Shoot(shootCoord);
                }

                if (_settings.AimWithGazeEnabled &&
                    _isInVehicle &&
                    ((!_menuOpen && User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON)) ||
                     (Game.IsKeyPressed(Keys.B)) ||
                     (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON1)) ||
                     (!_isInAircraft && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
                    )
                    )
                {
                    _aiming.ShootBullet(shootCoord);
                }



                if ((_settings.MissilesAtGazeEnabled &&
                     Game.Player.Character.IsInVehicle()) &&
                    missileTarget != null)
                {
                    Vector2 screenCoords;
                    if (Geometry.WorldToScreenRel(missileTarget.Position, out screenCoords))
                    {
                        _aiming.MoveCrosshair(screenCoords);
                        _aiming.MissileLockedCrosshairVisible = true;
                    }
                }
                else
                {
                    Vector2 screenCoords;
                    if (Geometry.WorldToScreenRel(shootCoord, out screenCoords))
                    {
                        _aiming.MoveCrosshair(screenCoords);
                        _aiming.MissileLockedCrosshairVisible = false;
                    }
                }

                if (_settings.IncinerateAtGazeEnabled &&
                    (Game.IsKeyPressed(Keys.J) ||
                     (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON2)) ||
                     (!_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A))))
                {
                    _aiming.Incinerate(shootCoordSnap);
                }

                if (_settings.TaseAtGazeEnabled &&
                    (Game.IsKeyPressed(Keys.H) ||
                     Game.IsKeyPressed(Keys.PageDown) ||
                     (!_isInAircraft && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder))))
                {
                    _aiming.Tase(shootCoordSnap);
                }

                if (Game.IsKeyPressed(Keys.U))
                {
                    _aiming.Water(shootCoord);
                }
            }

            if (shootMissileCoord.Length() > 0 && Geometry.IsInFrontOfThePlayer(shootMissileCoord))
            {
                if (_settings.MissilesAtGazeEnabled &&
                    (Game.IsKeyPressed(Keys.N) ||
                     Game.IsKeyPressed(Keys.PageUp) ||
                     (!_isInRadialMenu && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B))))
                {
                    if (missileTarget != null)
                    {
                        _aiming.ShootMissile(missileTarget);
                    }
                    else
                    {
                        _aiming.ShootMissile(shootMissileCoord);
                    }
                }
            }
            _aiming.Process(_isInRadialMenu);
        }