Exemple #1
0
        public void OnReceiveData(ref DualShockState state)
        {
            if (IsPlaying)
            {
                if (IsRecording)
                {
                    Sequence.Add(state);
                }
                else
                {
                    if (Sequence[CurrentTick] != null)
                    {
                        state = Sequence[CurrentTick];
                    }
                }

                // Increment tick
                CurrentTick++;

                // Reset tick if out of bounds
                if (CurrentTick >= Sequence.Count)
                {
                    CurrentTick = 0;
                }
            }
        }
Exemple #2
0
        public void OnReceiveData(ref DualShockState state)
        {
            if (IsPlaying && !IsPaused)
            {
                // Recording
                if (IsRecording)
                {
                    Sequence.Add(state);
                }
                // Playing
                else
                {
                    DualShockState newState = Sequence[CurrentTick];
                    DualShockState oldState = state;

                    if (newState != null)
                    {
                        // Update the state
                        state = newState;
                        // Replace battery status
                        state.Battery    = oldState.Battery;
                        state.IsCharging = oldState.IsCharging;
                    }
                }

                // Increment tick
                CurrentTick++;

                // Reset tick if out of bounds
                if (CurrentTick >= Sequence.Count)
                {
                    CurrentTick = 0;
                }
            }
        }
        public void OnReceiveData(ref DualShockState state)
        {
            // if (!IsCursorHideRequested)
            //     return;
            //timer.Start();
            //counter++;
            //if (timer.ElapsedMilliseconds > 1000)
            //{
            //    Console.WriteLine("OnReceiveData is called " + counter + "times per second");
            //    counter = 0;
            //    timer.Restart();
            //}

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

            if (!IsProcessInForeground(RemotePlayProcess))
            {
                Utility.ShowCursor(true);
                return;
            }

            HandleKeyboardInput();

            HandleMouseInput();

            // Assign the state
            state = CurrentState;
        }
Exemple #4
0
        private void ExecuteAction(BaseAction action, DualShockState state = null)
        {
            if (action == null)
            {
                return;
            }

            // Test remap action
            {
                MappingAction cast = action as MappingAction;
                if (cast != null)
                {
                    ExecuteRemapAction(cast, state);
                    return;
                }
            }
            // Test macro action
            {
                MacroAction cast = action as MacroAction;
                if (cast != null)
                {
                    ExecuteMacroAction(cast);
                    return;
                }
            }
        }
Exemple #5
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;
            }
        }
 public static void Release(this DualShockState state, string[] properties)
 {
     foreach (var p in properties)
     {
         state.SetProperty(p, defaultState.GetProperty(p));
     }
 }
        public void ExecuteActionsByKey(Script script, List <Keys> keys)
        {
            var state = new DualShockState();

            foreach (var key in keys)
            {
                if (key == Keys.None)
                {
                    continue;
                }

                try
                {
                    BaseAction action = KeysDict[key];
                    ExecuteAction(script, action, state);
                }
                catch (KeyNotFoundException)
                {
                }
                catch (ArgumentException)
                {
                }
                catch (Exception)
                {
                }
            }
        }
Exemple #8
0
        public void OnReceiveData(ref DualShockState state)
        {
            DualShockState newState = GetState();

            if (newState != null)
            {
                state = newState;
            }
        }
Exemple #9
0
 private void HandleVirtualKeys(DualShockState dualShockState, List <VirtualKey> virtualKeys)
 {
     if (virtualKeys != null)
     {
         foreach (VirtualKey virtualKey in virtualKeys)
         {
             HandleVirtualKey(dualShockState, virtualKey);
         }
     }
 }
Exemple #10
0
        // Called when the user pressed play
        public override void Start()
        {
            base.Start();

            var sequences = File.ReadAllLines("combos.txt");

            foreach (var line in sequences)
            {
                List <DualShockState> newStateSequence = new List <DualShockState>();

                foreach (char button in line)
                {
                    DualShockState newAction = null;                     //Wont ever add null due to the default case
                    switch (button)
                    {
                    case 'U':
                        newAction = new DualShockState()
                        {
                            DPad_Up = true
                        };
                        break;

                    case 'D':
                        newAction = new DualShockState()
                        {
                            DPad_Down = true
                        };
                        break;

                    case 'L':
                        newAction = new DualShockState()
                        {
                            DPad_Left = true
                        };
                        break;

                    case 'R':
                        newAction = new DualShockState()
                        {
                            DPad_Right = true
                        };
                        break;

                    default:
                        throw new Exception("Invalid button");
                    }
                    newStateSequence.Add(newAction);
                }

                states.Add(newStateSequence);
            }
            MessageBox.Show($"Loaded {states.Count} actions");
            currentState = states[0];
        }
Exemple #11
0
        public DualShockState GetState()
        {
            string screenWidth  = Screen.PrimaryScreen.Bounds.Width.ToString();
            string screenHeight = Screen.PrimaryScreen.Bounds.Height.ToString();

            Log.Verbose("GamepadProcessor.GetState screen width={0} height={1}", screenWidth, screenHeight);

            RequestsPerSecondCounter++;
            if (RequestsPerSecondTimer.ElapsedMilliseconds >= 1000)
            {
                Log.Verbose("GamepadProcessor.GetState  RequestsPerSecondCounter={0}", RequestsPerSecondCounter);
                RequestsPerSecondTimer.Restart();
                RequestsPerSecondCounter = 0;
            }

            Guid uuid = Guid.NewGuid();

            // Log.Verbose(uuid + " GamepadProcessor.GetState in a");

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

            if (!ProcessUtil.IsRemotePlayInForeground())
            {
                Log.Verbose(uuid + "GamepadProcessor.GetState return null");
                Utility.ShowCursor(true);
                return(null);
            }

            //Stopwatch OnReceiveDataTimer = new Stopwatch();
            //OnReceiveDataTimer.Start();

            // Log.Verbose(uuid + " GamepadProcessor.GetState in b");

            HandleButtonPressed();

            HandleAimToggle();
            HandleMouseCursor();
            MouseWheelProcessor.Process(CurrentState);

            //Log.Verbose(uuid + " GamepadProcessor.GetState out " + DualShockStateToString(ref CurrentState));

            //Log.Verbose(uuid + " GamepadProcessor.GetState OnReceiveDataTimer {0} ms ", + OnReceiveDataTimer.ElapsedMilliseconds);
            //OnReceiveDataTimer.Stop();

            Log.Verbose(uuid + "GamepadProcessor.GetState return THING");
            return(CurrentState);
        }
Exemple #12
0
        public string DualShockStateToString(ref DualShockState state)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(", 'L1':");
            sb.Append(state.L1);
            sb.Append(", 'L2':");
            sb.Append(state.L2);
            sb.Append(", 'L3':");
            sb.Append(state.L3);

            sb.Append(", 'Lx':");
            sb.Append(state.LX);
            sb.Append(", 'Ly':");
            sb.Append(state.LY);

            sb.Append(", 'R1':");
            sb.Append(state.R1);
            sb.Append(", 'R2':");
            sb.Append(state.R2);
            sb.Append(", 'R3':");
            sb.Append(state.R3);

            sb.Append(", 'Rx':");
            sb.Append(state.RX);
            sb.Append(", 'Ry':");
            sb.Append(state.RY);

            sb.Append(", 'circle':");
            sb.Append(state.Circle);
            sb.Append(", 'cross':");
            sb.Append(state.Cross);
            sb.Append(", 'square':");
            sb.Append(state.Square);
            sb.Append(", 'triangle':");
            sb.Append(state.Triangle);

            sb.Append(", 'DPad_Up':");
            sb.Append(state.DPad_Up);
            sb.Append(", 'DPad_Down':");
            sb.Append(state.DPad_Down);
            sb.Append(", 'DPad_Left':");
            sb.Append(state.DPad_Left);
            sb.Append(", 'DPad_Right':");
            sb.Append(state.DPad_Right);

            sb.Append(", 'PS':");
            sb.Append(state.PS);

            sb.Append("}");

            return(sb.ToString());
        }
Exemple #13
0
 public static void TrimSequence(List <DualShockState> sequence, bool fromEnd)
 {
     if (!fromEnd)
     {
         int offset = 5;
         for (var i = 0; i < sequence.Count; i++)
         {
             var isDefaultState = DualShockState.IsDefaultState(sequence.ElementAt(i));
             if (!isDefaultState)
             {
                 if (i == 0)
                 {
                     return;
                 }
                 var offsetVal = i - offset;
                 if (offsetVal == 0)
                 {
                     return;
                 }
                 sequence.RemoveRange(0, offsetVal);
                 return;
             }
         }
     }
     else
     {
         int offset = 5;
         for (var i = sequence.Count - 1; i >= 0; i--)
         {
             var isDefaultState = DualShockState.IsDefaultState(sequence.ElementAt(i));
             if (!isDefaultState)
             {
                 if (i == sequence.Count - 1)
                 {
                     return;
                 }
                 var count     = i + offset;
                 var offsetVal = sequence.Count - count;
                 if (count + offsetVal > sequence.Count)
                 {
                     return;
                 }
                 sequence.RemoveRange(count, offsetVal);
                 return;
             }
         }
     }
 }
Exemple #14
0
        public void PressQueue(DualShockState state, string[] properties, int delay = 150)
        {
            if (properties == null)
            {
                return;
            }

            if (!Host.IsRunning || Host.IsPaused)
            {
                return;
            }

            CurrentQueueState.PatchState(state);
            ReleaseQueueState.Add(new KeyValuePair <string[], DateTime>(properties, DateTime.Now.AddMilliseconds(delay)));
            FlushQueue();
        }
        private static void OnReceiveData(ref DualShockState state)
        {
            /* -- Modify the controller state here -- */

            // Force press X
            state.Cross = true;

            // Force left analog upwards
            state.LY = 0;

            // Force left analog downwards
            // state.LY = 255;

            // Force left analog to center
            // state.LX = 128;
            // state.LY = 128;
        }
Exemple #16
0
        private void ResolveAction(ref DualShockState state)
        {
            if (_currentPress == null)
            {
                return;
            }

            if (state.FrameCounter < 40 && !_currentPress.Up)
            {
                _currentPress.State.CopyTo(state);
                _currentPress.Down = true;
            }

            if (state.FrameCounter == 60 && _currentPress.Down && !_currentPress.Up)
            {
                _currentPress.Up = true;
            }
        }
Exemple #17
0
        public void OnReceiveData(ref DualShockState state)
        {
            state.Cross      = xPressed > 0;
            state.Circle     = oPressed > 0;
            state.DPad_Right = rightPressed > 0;
            state.DPad_Down  = downPressed > 0;

            deltatime.Stop();
            double dt = deltatime.ElapsedMilliseconds / 1000.0;

            xPressed     -= dt;
            rightPressed -= dt;
            downPressed  -= dt;
            oPressed     -= dt;

            deltatime.Reset();
            deltatime.Start();
        }
Exemple #18
0
        /* Constructor */
        public Script()
        {
            // General
            Config.Name      = "Marvel Heroes Omega";
            Config.LoopDelay = 100;

            // Setup scenes
            Config.Scenes = new List <Scene>()
            {
                new TeleportLoading(),
                new IntroLoading(),
                new Launch()
            };

            // Setup form
            ScriptForm = MainForm = new MainForm();

            // Setup custom button queue
            CurrentQueueState = new DualShockState();
            ReleaseQueueState = new List <KeyValuePair <string[], DateTime> >();
        }
Exemple #19
0
        public void Process(DualShockState state)
        {
            if (MouseButtonHoldTimer.ElapsedMilliseconds > UserSettings.GetInstance().MouseWheelScrollHoldDuration)
            {
                LastVirtualKeys = null;
            }

            if (LastVirtualKeys == null)
            {
                // Queue.Count because "Dequeue" and "Peek" will block/wait until there is an event in the queue
                if (MouseWheelQueue.Count > 0)
                {
                    MouseEventArgs e            = MouseWheelQueue.Dequeue();
                    ExtraButtons   scrollAction = MouseWheelScrollProcessor.GetScrollAction(e);
                    LastVirtualKeys = GetVirtualKeys(scrollAction);
                    MouseButtonHoldTimer.Restart();
                }
            }

            HandleVirtualKeys(state, LastVirtualKeys);
        }
Exemple #20
0
        public void ExecuteActionsByKey(List <Keys> keys)
        {
            var state = new DualShockState();

            foreach (var key in keys)
            {
                if (key == Keys.None)
                {
                    continue;
                }

                try
                {
                    BaseAction action = KeysDict[key];
                    ExecuteAction(action, state);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
            }
        }
        private void ExecuteRemapAction(Script script, MappingAction action, DualShockState state)
        {
            if (state == null)
            {
                state = new DualShockState();
            }

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

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

            if (didSetProperty)
            {
                script.StopMacro();
                script.SetButtons(state);
            }
        }
Exemple #22
0
        private void exportButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = Path.GetDirectoryName(CurrentPath);
            saveFileDialog.Filter           = SaveLoadHelper.XML_FILTER;
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName         = Path.GetFileName(CurrentPath).Replace(".xml", ".min.xml");

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                List <string> excludeProperties = new List <string>();

                var checkedItems = propertiesCheckedListBox.CheckedItems;
                foreach (var item in propertiesCheckedListBox.Items)
                {
                    if (!checkedItems.Contains(item))
                    {
                        excludeProperties.Add(item.ToString());
                    }
                }

                // Compress macro
                DualShockState.SerializeCompressed(saveFileDialog.FileName, Sequence, excludeProperties);

                // Show results
                long newFileSize    = new FileInfo(saveFileDialog.FileName).Length;
                long sizeDifference = FileSize - newFileSize;
                MessageBox.Show(
                    $"File size reduced by {GetBytesReadable(sizeDifference)}" + "\n\n" +
                    $"Before: {GetBytesReadable(FileSize)}" + "\n" +
                    $"After: {GetBytesReadable(newFileSize)}", "Compress Macro",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #23
0
 public void SaveFile(string path)
 {
     DualShockState.Serialize(path, Sequence);
 }
Exemple #24
0
 public void Run(ref DualShockState state)
 {
 }
Exemple #25
0
 public void PressQueue(DualShockState state, string property, int delay = 150)
 {
     PressQueue(state, new string[] { property }, delay);
 }
Exemple #26
0
 public void OnReceiveData(ref DualShockState state)
 {
     UpdateStatus(InterceptorStatus);
 }
        // DualShockState from PS4RemotePlayInjection
        public static void ConvertandSendReport(IDualShock4Controller controller, DualShockState state)
        {
            // 2021.12.21 pancakeslp
            // ` controller.ResetReport(); `
            // it might make sense to reset the controller/report
            // but sometimes the report might auto submit, resulting in what looks like a twitch
            //
            // this is most easilly observed with having the ADS toggle on,
            // and then ADSing and taking your hand off the mouse

            //Left
            controller.SetButtonState(DualShock4Button.ShoulderLeft, state.L1);
            SetTriggerLeft(controller, state.L2);
            controller.SetButtonState(DualShock4Button.ThumbLeft, state.L3);

            DualShock4DPadDirection tempDPad = DualShock4DPadDirection.None;

            if (state.DPad_Up && state.DPad_Right)
            {
                tempDPad = DualShock4DPadDirection.Northeast;
            }
            else if (state.DPad_Up && state.DPad_Left)
            {
                tempDPad = DualShock4DPadDirection.Northwest;
            }
            else if (state.DPad_Up)
            {
                tempDPad = DualShock4DPadDirection.North;
            }
            else if (state.DPad_Right && state.DPad_Down)
            {
                tempDPad = DualShock4DPadDirection.Southeast;
            }
            else if (state.DPad_Right)
            {
                tempDPad = DualShock4DPadDirection.East;
            }
            else if (state.DPad_Down && state.DPad_Left)
            {
                tempDPad = DualShock4DPadDirection.Southwest;
            }
            else if (state.DPad_Down)
            {
                tempDPad = DualShock4DPadDirection.South;
            }
            else if (state.DPad_Left)
            {
                tempDPad = DualShock4DPadDirection.West;
            }
            controller.SetDPadDirection(tempDPad);

            controller.SetAxisValue(DualShock4Axis.LeftThumbX, state.LX);
            controller.SetAxisValue(DualShock4Axis.LeftThumbY, state.LY);


            //middle
            controller.SetButtonState(DualShock4Button.Options, state.Options);
            controller.SetButtonState(DualShock4Button.Share, state.Share);

            controller.SetButtonState(DualShock4SpecialButton.Ps, state.PS);
            controller.SetButtonState(DualShock4SpecialButton.Touchpad, state.TouchButton);


            //Right
            controller.SetButtonState(DualShock4Button.ShoulderRight, state.R1);
            SetTriggerRight(controller, state.R2);
            controller.SetButtonState(DualShock4Button.ThumbRight, state.R3);

            controller.SetButtonState(DualShock4Button.Circle, state.Circle);
            controller.SetButtonState(DualShock4Button.Cross, state.Cross);
            controller.SetButtonState(DualShock4Button.Square, state.Square);
            controller.SetButtonState(DualShock4Button.Triangle, state.Triangle);

            controller.SetAxisValue(DualShock4Axis.RightThumbX, state.RX);
            controller.SetAxisValue(DualShock4Axis.RightThumbY, state.RY);

            controller.SubmitReport();
        }
Exemple #28
0
 public ButtonAction()
 {
     State = new DualShockState();
     Down  = false;
     Up    = false;
 }
Exemple #29
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;
            }
        }
Exemple #30
0
 public void LoadFile(string path)
 {
     Sequence = DualShockState.Deserialize(path);
 }