Beispiel #1
0
        private void ExecuteRemapAction(MappingAction action, DualShockState state)
        {
            if (state == null)
            {
                state = new DualShockState();
            }

            // Try to set property using Reflection
            bool didSetProperty = false;

            try
            {
                RemapperUtility.SetValue(state, action.Property, action.Value);
                didSetProperty = true;
            }
            catch (Exception ex) { Debug.WriteLine(ex.StackTrace); }

            if (didSetProperty)
            {
                MacroPlayer.Stop();
                UsingMacroPlayer = false;

                state.Battery    = 255;
                state.IsCharging = true;
                CurrentState     = state;
            }
        }
Beispiel #2
0
 private void ShowCursorAndToolbar(bool value)
 {
     if (value)
     {
         RemapperUtility.ShowSystemCursor(true);
         RemapperUtility.ShowStreamingToolBar(RemotePlayProcess, true);
         IsCursorShowing = true;
     }
     else
     {
         RemapperUtility.ShowSystemCursor(false);
         RemapperUtility.ShowStreamingToolBar(RemotePlayProcess, false);
         IsCursorShowing = false;
     }
 }
Beispiel #3
0
        public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
        {
            bool focusedWindow = CheckFocusedWindow();

            // Focused
            if (focusedWindow)
            {
                if (EnableMouseInput)
                {
                    // Hide cursor
                    if (!DebugCursor && IsCursorShowing)
                    {
                        ShowCursorAndToolbar(false);
                    }
                }
            }
            // Not focused
            else
            {
                // Show cursor
                if (!DebugCursor && !IsCursorShowing)
                {
                    ShowCursorAndToolbar(true);
                }

                // Ignore the rest if not focused
                return;
            }

            // Ignore if disabled
            if (!EnableMouseInput)
            {
                return;
            }

            #region Mouse clicks
            // Left mouse
            if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonDown)
            {
                LeftMouseDown = true;
                e.Handled     = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonUp)
            {
                LeftMouseDown = false;
                e.Handled     = focusedWindow;
            }
            // Right mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonDown)
            {
                RightMouseDown = true;
                e.Handled      = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonUp)
            {
                RightMouseDown = false;
                e.Handled      = focusedWindow;
            }
            // Middle mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonDown)
            {
                MiddleMouseDown = true;
                e.Handled       = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonUp)
            {
                MiddleMouseDown = false;
                e.Handled       = focusedWindow;
            }
            #endregion
            #region Mouse move
            else if (e.MouseState == GlobalMouseHook.MouseState.Move)
            {
                var rawX = e.MouseData.Point.X;
                var rawY = e.MouseData.Point.Y;

                var rawXOld = rawX;
                var rawYOld = rawY;
                //Console.Write(rawX);

                #region Store mouse stroke
                var newStroke = new MouseStroke()
                {
                    Timestamp = DateTime.Now,
                    RawData   = e,
                    DidMoved  = true,
                    X         = rawX + CursorOverflowX,
                    Y         = rawY + CursorOverflowY
                };

                if (CurrentMouseStroke != null)
                {
                    double deltaTime = (newStroke.Timestamp - CurrentMouseStroke.Timestamp).TotalSeconds;

                    if (deltaTime != 0) // moving too fast causes NaN
                    {
                        newStroke.VelocityX = (newStroke.X - CurrentMouseStroke.X) / deltaTime;
                        newStroke.VelocityY = (newStroke.Y - CurrentMouseStroke.Y) / deltaTime;
                        double newX = newStroke.VelocityX;
                        double newY = newStroke.VelocityY;

                        // increase lower values to high, because there are problems with PS4's deadzone (center + 64 to slowly moving mouse, center + 63 to not moving mouse)

                        Debug.WriteLine(newX);
                        if ((newX > -50 && newX < 0) || (newX > 0 && newX < 50))
                        {
                            newX = newX * (MouseDecayRate * 80);
                        }
                        else if ((newX > -100 && newX < 0) || (newX > 0 && newX < 100))
                        {
                            newX = newX * (MouseDecayRate * 70);
                        }
                        else if ((newX > -150 && newX < 0) || (newX > 0 && newX < 150))
                        {
                            newX = newX * (MouseDecayRate * 30);
                        }
                        else if ((newX > -200 && newX < 0) || (newX > 0 && newX < 200))
                        {
                            newX = newX * (MouseDecayRate * 10);
                        }

                        if ((newY > -50 && newY < 0) || (newY > 0 && newY < 50))
                        {
                            newY = newY * (MouseDecayRate * 80);
                        }
                        else if ((newY > -100 && newY < 0) || (newY > 0 && newY < 100))
                        {
                            newY = newY * (MouseDecayRate * 70);
                        }
                        else if ((newY > -150 && newY < 0) || (newY > 0 && newY < 150))
                        {
                            newY = newY * (MouseDecayRate * 30);
                        }
                        else if ((newY > -200 && newY < 0) || (newY > 0 && newY < 200))
                        {
                            newY = newY * (MouseDecayRate * 10);
                        }

                        if (MouseInvertXAxis == true)
                        {
                            newX = -newX;
                        }
                        if (MouseInvertYAxis == true)
                        {
                            newY = -newY;
                        }
                        CurrentX = CurrentX + ((newX * MouseSensitivity) / 10000);
                        CurrentY = CurrentY + ((newY * MouseSensitivity) / 10000);
                        Counter  = MouseMakeupSpeed;
                    }
                }

                CurrentMouseStroke = newStroke;
                #endregion

                #region Adjust cursor position;
                var didSetPosition = false;
                var screen         = Screen.FromHandle(RemotePlayProcess.MainWindowHandle);
                var workingArea    = screen.WorkingArea;
                var tmpX           = rawX - workingArea.X;
                var tmpY           = rawY - workingArea.Y;

                if (tmpX >= workingArea.Width)
                {
                    CursorOverflowX += workingArea.Width;
                    tmpX             = 0;
                    didSetPosition   = true;
                }
                else if (tmpX <= 0)
                {
                    CursorOverflowX -= workingArea.Width;
                    tmpX             = workingArea.Width;
                    didSetPosition   = true;
                }

                if (tmpY >= workingArea.Height)
                {
                    CursorOverflowY += workingArea.Height;
                    tmpY             = 0;
                    didSetPosition   = true;
                }
                else if (tmpY <= 0)
                {
                    CursorOverflowY -= workingArea.Height;
                    tmpY             = workingArea.Height;
                    didSetPosition   = true;
                }

                // Block cursor
                if (didSetPosition)
                {
                    RemapperUtility.SetCursorPosition(tmpX, tmpY);
                    e.Handled = true;
                }
                #endregion
                #endregion
            }
        }
Beispiel #4
0
 private bool CheckFocusedWindow()
 {
     return(RemapperUtility.IsProcessInForeground(RemotePlayProcess));
 }
Beispiel #5
0
        public void OnReceiveData(ref DualShockState state)
        {
            // Macro
            if (UsingMacroPlayer)
            {
                MacroPlayer.OnReceiveData(ref state);
            }
            // Mapping
            else
            {
                if (!CheckFocusedWindow())
                {
                    return;
                }

                // Create the default state to modify
                if (CurrentState == null)
                {
                    CurrentState = new DualShockState()
                    {
                        Battery = 255
                    };
                }

                // Mouse Input
                if (EnableMouseInput)
                {
                    var checkState = new DualShockState();

                    // Left mouse
                    var leftMap = MappingsDataBinding.ElementAtOrDefault(LeftMouseMapping);
                    if (leftMap != null)
                    {
                        if (LeftMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, leftMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, leftMap.Property);
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, defaultValue);
                        }
                    }


                    // Right mouse
                    var rightMap = MappingsDataBinding.ElementAtOrDefault(RightMouseMapping);
                    if (rightMap != null)
                    {
                        if (RightMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, rightMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, rightMap.Property);
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, defaultValue);
                        }
                    }

                    // Middle mouse
                    var middleMap = MappingsDataBinding.ElementAtOrDefault(MiddleMouseMapping);
                    if (middleMap != null)
                    {
                        if (MiddleMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, middleMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, middleMap.Property);
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, defaultValue);
                        }
                    }


                    string analogProperty = MouseMovementAnalog == AnalogStick.Left ? "L" : "R";

                    // Moving mouse

                    // Move mouse to center everytime
                    if (Counter <= 0)
                    {
                        double CenteredX = CurrentX - 127.5;
                        double CenteredY = CurrentY - 127.5;

                        CurrentX = CurrentX - ((CenteredX / 1000) * MouseDecayThreshold);
                        CurrentY = CurrentY - ((CenteredY / 1000) * MouseDecayThreshold);
                    }
                    else
                    {
                        Counter = Math.Max(0, Counter - 1);
                    }

                    // Limit borders
                    if (CurrentX > 255 - MouseAnalogDeadzone)
                    {
                        CurrentX = 255 - MouseAnalogDeadzone;
                    }
                    else if (CurrentX < MouseAnalogDeadzone)
                    {
                        CurrentX = MouseAnalogDeadzone;
                    }

                    if (CurrentY > 255 - MouseAnalogDeadzone)
                    {
                        CurrentY = 255 - MouseAnalogDeadzone;
                    }
                    else if (CurrentY < MouseAnalogDeadzone)
                    {
                        CurrentY = MouseAnalogDeadzone;
                    }

                    // Set values
                    RemapperUtility.SetValue(CurrentState, analogProperty + "X", CurrentX);
                    RemapperUtility.SetValue(CurrentState, analogProperty + "Y", CurrentY);

                    // Invoke callback - set visible icon in settings
                    OnMouseAxisChanged?.Invoke((int)CurrentX, (int)CurrentY);
                }

                // Assign the state
                state = CurrentState;
            }
        }
Beispiel #6
0
        public void OnReceiveData(ref DualShockState state)
        {
            // Macro
            if (UsingMacroPlayer)
            {
                MacroPlayer.OnReceiveData(ref state);
            }
            // Mapping
            else
            {
                if (!CheckFocusedWindow())
                {
                    return;
                }

                // Create the default state to modify
                if (CurrentState == null)
                {
                    CurrentState = new DualShockState()
                    {
                        Battery = 255
                    };
                }

                // Mouse Input
                if (EnableMouseInput)
                {
                    var checkState = new DualShockState();

                    // Left mouse
                    var leftMap = MappingsDataBinding.ElementAtOrDefault(LeftMouseMapping);
                    if (leftMap != null)
                    {
                        if (LeftMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, leftMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, leftMap.Property);
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, defaultValue);
                        }
                    }


                    // Right mouse
                    var rightMap = MappingsDataBinding.ElementAtOrDefault(RightMouseMapping);
                    if (rightMap != null)
                    {
                        if (RightMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, rightMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, rightMap.Property);
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, defaultValue);
                        }
                    }

                    // Middle mouse
                    var middleMap = MappingsDataBinding.ElementAtOrDefault(MiddleMouseMapping);
                    if (middleMap != null)
                    {
                        if (MiddleMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, middleMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, middleMap.Property);
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, defaultValue);
                        }
                    }

                    // Mouse moved
                    if (CurrentMouseStroke != null && CurrentMouseStroke.DidMoved)
                    {
                        MouseSpeedX = (CurrentMouseStroke.VelocityX * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;
                        if (MouseInvertXAxis)
                        {
                            MouseSpeedX *= -1;
                        }

                        MouseSpeedY = (CurrentMouseStroke.VelocityY * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;
                        if (MouseInvertYAxis)
                        {
                            MouseSpeedY *= -1;
                        }

                        CurrentMouseStroke.DidMoved = false;

                        // Stop release timer
                        //if (MouseReleaseTimer != null)
                        //{
                        //    MouseReleaseTimer.Stop();
                        //    MouseReleaseTimer = null;
                        //}
                    }
                    // Mouse idle
                    else
                    {
                        // Start decay
                        MouseSpeedX /= MouseDecayRate;
                        MouseSpeedY /= MouseDecayRate;

                        // Stop decaying joystick if below threshold
                        //if (Math.Abs(MouseSpeedX) < MouseDecayThreshold || Math.Abs(MouseSpeedY) < MouseDecayThreshold)
                        //{
                        //    // Reset mouse speed
                        //    if (Math.Abs(MouseSpeedX) < MouseDecayThreshold) MouseSpeedX = 0;
                        //    if (Math.Abs(MouseSpeedY) < MouseDecayThreshold) MouseSpeedY = 0;

                        //    // Start release timer
                        //    if (MouseReleaseTimer == null)
                        //    {
                        //        MouseReleaseTimer = new System.Timers.Timer(MOUSE_RELEASE_TIME);
                        //        MouseReleaseTimer.Start();
                        //        MouseReleaseTimer.Elapsed += (s, e) =>
                        //        {
                        //            // Recenter cursor
                        //            RemapperUtility.SetCursorPosition(MOUSE_CENTER_X, MOUSE_CENTER_Y);

                        //            // Reset cursor overflow
                        //            CursorOverflowX = 0;
                        //            CursorOverflowY = 0;

                        //            // Stop release timer
                        //            MouseReleaseTimer.Stop();
                        //            MouseReleaseTimer = null;
                        //        };

                        //    }
                        //}
                    }

                    const double min            = 0;
                    const double max            = 255;
                    string       analogProperty = MouseMovementAnalog == AnalogStick.Left ? "L" : "R";

                    // Minimum speed
                    double positiveSpeed = 128 + MouseAnalogDeadzone;
                    double negativeSpeed = 128 - MouseAnalogDeadzone;

                    // Base speed
                    double baseX = ((MouseSpeedX > 0) ? positiveSpeed : ((MouseSpeedX < 0) ? negativeSpeed : 128));
                    double baseY = ((MouseSpeedY > 0) ? positiveSpeed : ((MouseSpeedY < 0) ? negativeSpeed : 128));

                    // Makeup speed
                    double makeupX = Math.Sign(MouseSpeedX) * MouseMakeupSpeed;
                    double makeupY = Math.Sign(MouseSpeedY) * MouseMakeupSpeed;

                    // Scale speed to analog values
                    double rx = baseX + (makeupX * MouseSpeedX * MouseSpeedX * 127);
                    double ry = baseY + (makeupY * MouseSpeedY * MouseSpeedY * 127);

                    byte scaledX = (byte)((rx < min) ? min : (rx > max) ? max : rx);
                    byte scaledY = (byte)((ry < min) ? min : (ry > max) ? max : ry);

                    // Set the analog values
                    RemapperUtility.SetValue(CurrentState, analogProperty + "X", scaledX);
                    RemapperUtility.SetValue(CurrentState, analogProperty + "Y", scaledY);

                    // Invoke callback
                    OnMouseAxisChanged?.Invoke(scaledX, scaledY);
                }

                // Assign the state
                state = CurrentState;
            }
        }
Beispiel #7
0
        public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e)
        {
            bool focusedWindow = CheckFocusedWindow();

            // When not focused, we don't do anything.
            if (!focusedWindow)
            {
                return;
            }

            // Ignore if disabled
            if (!EnableMouseInput)
            {
                return;
            }

            #region Mouse clicks
            // Left mouse
            if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonDown)
            {
                LeftMouseDown = true;
                e.Handled     = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.LeftButtonUp)
            {
                LeftMouseDown = false;
                e.Handled     = focusedWindow;
            }
            // Right mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonDown)
            {
                RightMouseDown = true;
                e.Handled      = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.RightButtonUp)
            {
                RightMouseDown = false;
                e.Handled      = focusedWindow;
            }
            // Middle mouse
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonDown)
            {
                MiddleMouseDown = true;
                e.Handled       = focusedWindow;
            }
            else if (e.MouseState == GlobalMouseHook.MouseState.MiddleButtonUp)
            {
                MiddleMouseDown = false;
                e.Handled       = focusedWindow;
            }
            #endregion
            #region Mouse move
            else if (e.MouseState == GlobalMouseHook.MouseState.Move)
            {
                var screen      = Screen.FromHandle(RemotePlayProcess.MainWindowHandle);
                var workingArea = screen.WorkingArea;
                var referenceX  = workingArea.Width / 2;
                var referenceY  = workingArea.Height / 2;

                var rawX = e.MouseData.Point.X;
                var rawY = e.MouseData.Point.Y;

                #region Store mouse stroke
                var newStroke = new MouseStroke()
                {
                    Timestamp = DateTime.Now,
                    RawData   = e,
                    DidMoved  = true,
                    X         = rawX,
                    Y         = rawY
                };

                if (CurrentMouseStroke != null)
                {
                    double deltaTime = (newStroke.Timestamp - CurrentMouseStroke.Timestamp).TotalSeconds;

                    if (deltaTime != 0) // moving too fast causes NaN
                    {
                        // Velocity is relative to the middle of the screen
                        newStroke.VelocityX = (CurrentMouseStroke.X - 1440) / deltaTime;
                        newStroke.VelocityY = (CurrentMouseStroke.Y - 870) / deltaTime;

                        if (MouseInvertXAxis)
                        {
                            newStroke.VelocityX = -newStroke.VelocityX;
                        }
                        if (MouseInvertYAxis)
                        {
                            newStroke.VelocityY = -newStroke.VelocityY;
                        }

                        newStroke.VelocityX = (newStroke.VelocityX * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;
                        newStroke.VelocityY = (newStroke.VelocityY * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;

                        // Add quadratic scaling
//                        newStroke.VelocityX *= Math.Abs(newStroke.VelocityX/8);
//                        newStroke.VelocityY *= Math.Abs(newStroke.VelocityY/8);

                        if (Math.Abs(newStroke.VelocityX) > 0.0)
                        {
                            newStroke.VelocityX += (Math.Sign(newStroke.VelocityX) * 22);
                        }
                        if (Math.Abs(newStroke.VelocityY) > 0.0)
                        {
                            newStroke.VelocityY += (Math.Sign(newStroke.VelocityY) * 22);
                        }

                        TempCurrentX += newStroke.VelocityX;
                        TempCurrentY += newStroke.VelocityY;

//                        Console.WriteLine("RefX: " + referenceX + " - RefY: " + referenceY);
//                        Console.WriteLine("X: " + CurrentMouseStroke.X + " - Y: " + CurrentMouseStroke.Y);
//                        Console.WriteLine("VelX: " + newStroke.VelocityX + " - VelY: " + newStroke.VelocityY);
//                        Console.WriteLine("rawX: " + rawX + " - rawY: " + rawY);
                        // Reset the mouse to the reference position
                    }
                }

                CurrentMouseStroke = newStroke;
                #endregion

                #region Adjust cursor position;
                RemapperUtility.SetCursorPosition(referenceX, referenceY);
                e.Handled = true;

                #endregion
                #endregion
            }
        }
Beispiel #8
0
        public void OnReceiveData(ref DualShockState state)
        {
            // Macro
            if (UsingMacroPlayer)
            {
                MacroPlayer.OnReceiveData(ref state);
            }
            // Mapping
            else
            {
                if (!CheckFocusedWindow())
                {
                    return;
                }

                // Create the default state to modify
                if (CurrentState == null)
                {
                    CurrentState = new DualShockState()
                    {
                        Battery = 255
                    };
                }

                // Mouse Input
                if (EnableMouseInput)
                {
                    var checkState = new DualShockState();

                    // Left mouse
                    var leftMap = MappingsDataBinding.ElementAtOrDefault(LeftMouseMapping);
                    if (leftMap != null)
                    {
                        if (LeftMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, leftMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, leftMap.Property);
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, defaultValue);
                        }
                    }


                    // Right mouse
                    var rightMap = MappingsDataBinding.ElementAtOrDefault(RightMouseMapping);
                    if (rightMap != null)
                    {
                        if (RightMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, rightMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, rightMap.Property);
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, defaultValue);
                        }
                    }

                    // Middle mouse
                    var middleMap = MappingsDataBinding.ElementAtOrDefault(MiddleMouseMapping);
                    if (middleMap != null)
                    {
                        if (MiddleMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, middleMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, middleMap.Property);
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, defaultValue);
                        }
                    }


                    string analogProperty = MouseMovementAnalog == AnalogStick.Left ? "L" : "R";

                    // Moving mouse

                    // Move mouse every X frames
                    if (TempFrame >= FrameRefresh)
                    {
                        TempFrame    = 0;
                        CurrentX     = 127.5 + TempCurrentX;
                        CurrentY     = 127.5 + TempCurrentY;
                        TempCurrentX = 0;
                        TempCurrentY = 0;

                        // Limit borders
                        if (CurrentX > 255 - Borders)
                        {
                            CurrentX = 255 - Borders;
                        }
                        else if (CurrentX < Borders)
                        {
                            CurrentX = Borders;
                        }

                        if (CurrentY > 255 - Borders)
                        {
                            CurrentY = 255 - Borders;
                        }
                        else if (CurrentY < Borders)
                        {
                            CurrentY = Borders;
                        }

                        // Set values
                        RemapperUtility.SetValue(CurrentState, analogProperty + "X", CurrentX);
                        RemapperUtility.SetValue(CurrentState, analogProperty + "Y", CurrentY);

                        // Invoke callback - set visible icon in settings
                        OnMouseAxisChanged?.Invoke((int)CurrentX, (int)CurrentY);
                    }
                    else
                    {
                        TempFrame = TempFrame + 1;
                    }
                }

                // Assign the state
                state = CurrentState;
            }
        }