Ejemplo n.º 1
0
 private void buttonMacroPlay_Click(object sender, EventArgs e)
 {
     if (((Control.ModifierKeys & Keys.Shift) == Keys.Shift) || string.IsNullOrEmpty(macroFile))
     {
         OpenFileDialog dialog = new OpenFileDialog();
         dialog.CheckFileExists = true;
         dialog.CheckPathExists = true;
         dialog.Multiselect     = false;
         dialog.Filter          = "Text files (*.txt)|*.txt|Macro files (*.macro)|*.macro|All files (*.*)|*.*";
         dialog.Title           = "Select a macro file to play";
         if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             macroFile = dialog.FileName;
         }
         else
         {
             return;
         }
     }
     if (!string.IsNullOrEmpty(macroFile))
     {
         MacroPlayer macroPlayer = new MacroPlayer(this, macroFile);
         macroPlayer.Play();
     }
 }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        /* Constructor */
        public MainForm()
        {
            InitializeComponent();

            // Setup global keyboard hook
            m_GlobalKeyboardHook = new GlobalKeyboardHook();
            m_GlobalKeyboardHook.KeyboardPressed += OnKeyPressed;

            // Setup global mouse hook
            m_GlobalMouseHook             = new GlobalMouseHook();
            m_GlobalMouseHook.MouseEvent += OnMouseEvent;

            // Create macro player
            m_MacroPlayer                  = new MacroPlayer();
            m_MacroPlayer.Loop             = true;
            m_MacroPlayer.RecordShortcut   = true;
            m_MacroPlayer.PropertyChanged += MacroPlayer_PropertyChanged;

            // Create remapper
            m_Remapper = new Remapper();

            // Create status checker
            m_StatusChecker = new StatusChecker();

            // Set control mode
            SetControlMode(ControlMode.Macro);

            // Create save/load helper
            m_SaveLoadHelper = new SaveLoadHelper(this, m_MacroPlayer);
            m_SaveLoadHelper.PropertyChanged += SaveLoadHelper_PropertyChanged;

            // Initialize interceptor
            InitInterceptor();
        }
Ejemplo n.º 4
0
        private static void PlayRecord(string recordFilePath)
        {
            var player      = new MacroPlayer();
            var loadedMacro = new Macro();

            loadedMacro.Load(recordFilePath);
            player.LoadMacro(loadedMacro);
            player.PlayMacro();
        }
Ejemplo n.º 5
0
        private void ExecuteMacroAction(MacroAction action)
        {
            //// TODO: Load sequence from cache
            ////List<DualShockState> sequence = new List<DualShockState>();

            UsingMacroPlayer = true;

            MacroPlayer.Stop();
            MacroPlayer.LoadFile(action.Path);
            MacroPlayer.Play();
        }
Ejemplo n.º 6
0
        /* Constructor */
        public MainForm()
        {
            InitializeComponent();

            // Create macro player
            m_MacroPlayer = new MacroPlayer();
            m_MacroPlayer.PropertyChanged += MacroPlayer_PropertyChanged;

            // Set control mode
            SetControlMode(ControlMode.Macro);

            // Create save/load helper
            m_SaveLoadHelper = new SaveLoadHelper(this, m_MacroPlayer);
            m_SaveLoadHelper.PropertyChanged += SaveLoadHelper_PropertyChanged;

            // Enable watchdog based on settings
            if (!Program.Settings.AutoInject)
            {
                Interceptor.InjectionMode = InjectionMode.Compatibility;
            }

            // Attempt to inject into PS4 Remote Play
            try
            {
                Interceptor.Inject();
            }
            // Injection failed
            catch (InterceptorException ex)
            {
                // Only handle when PS4 Remote Play is in used by another injection
                if (ex.InnerException != null && ex.InnerException.Message.Equals("STATUS_INTERNAL_ERROR: Unknown error in injected C++ completion routine. (Code: 15)"))
                {
                    MessageBox.Show("The process has been injected by another executable. Restart PS4 Remote Play and try again.", "Injection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(-1);
                }
                else
                {
                    // Handle exception if watchdog is disabled
                    if (!Program.Settings.AutoInject)
                    {
                        MessageBox.Show(string.Format("[{0}] - {1}", ex.GetType().ToString(), ex.Message), "Injection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(-1);
                    }
                }
            }

            // Start watchdog to automatically inject when possible
            if (Program.Settings.AutoInject)
            {
                Interceptor.Watchdog.Start();
            }
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
0
        public Remapper()
        {
            PressedKeys = new Dictionary <Keys, bool>();
            KeysDict    = new Dictionary <Keys, BaseAction>();

            IsCursorShowing = true;

            Counter             = 0;
            EnableMouseInput    = false;
            DebugCursor         = false;
            MouseSensitivity    = 1;
            MouseDecayRate      = 1;
            MouseDecayThreshold = 0.1;
            MouseAnalogDeadzone = 5;
            MouseMakeupSpeed    = 500;
            MouseMovementAnalog = AnalogStick.Right;
            MouseInvertXAxis    = false;
            MouseInvertYAxis    = false;
            CurrentX            = 128;
            CurrentY            = 128;
            LeftMouseMapping    = 11; // R2
            RightMouseMapping   = 10; // L2
            MiddleMouseMapping  = 9;  // L1

            MacroPlayer = new MacroPlayer();

            MappingsDataBinding = new List <MappingAction>()
            {
                new MappingAction("L Left", Keys.A, "LX", 0),
                new MappingAction("L Right", Keys.D, "LX", 255),
                new MappingAction("L Up", Keys.W, "LY", 0),
                new MappingAction("L Down", Keys.S, "LY", 255),

                new MappingAction("R Left", Keys.J, "RX", 0),
                new MappingAction("R Right", Keys.L, "RX", 255),
                new MappingAction("R Up", Keys.I, "RY", 0),
                new MappingAction("R Down", Keys.K, "RY", 255),

                new MappingAction("R1", Keys.E, "R1", true),
                new MappingAction("L1", Keys.Q, "L1", true),
                new MappingAction("L2", Keys.U, "L2", 255),
                new MappingAction("R2", Keys.O, "R2", 255),

                new MappingAction("Triangle", Keys.C, "Triangle", true),
                new MappingAction("Circle", Keys.Escape, "Circle", true),
                new MappingAction("Cross", Keys.Enter, "Cross", true),
                new MappingAction("Square", Keys.V, "Square", true),

                new MappingAction("DPad Up", Keys.Up, "DPad_Up", true),
                new MappingAction("DPad Down", Keys.Down, "DPad_Down", true),
                new MappingAction("DPad Left", Keys.Left, "DPad_Left", true),
                new MappingAction("DPad Right", Keys.Right, "DPad_Right", true),

                new MappingAction("L3", Keys.N, "L3", true),
                new MappingAction("R3", Keys.M, "R3", true),

                new MappingAction("Share", Keys.LControlKey, "Share", true),
                new MappingAction("Options", Keys.Z, "Options", true),
                new MappingAction("PS", Keys.LShiftKey, "PS", true),

                new MappingAction("Touch Button", Keys.T, "TouchButton", true)
            };

            MacrosDataBinding = new List <MacroAction>();

            // Load bindings if file exist
            if (File.Exists(GetBindingsFilePath()))
            {
                LoadBindings();
            }

            CreateActions();
        }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
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;
            }
        }