Пример #1
0
        private static bool IsSerialOccupied(int serial)
        {
            if (--serial < 0 || serial > 3)
            {
                throw new ArgumentException(string.Format("Serial index ({0}) must be within range", serial));
            }

            var state = new XINPUT_STATE();
            return (XInputNatives.XInputGetState((uint) serial, ref state) == ResultWin32.ERROR_SUCCESS);
        }
Пример #2
0
 public static uint XInputGetStateEx(uint dwUserIndex, ref XINPUT_STATE pState)
 {
     throw new NotImplementedException();
 }
Пример #3
0
 public static extern uint XInputGetState(uint dwUserIndex, ref XINPUT_STATE pState);
Пример #4
0
        public static uint XInputGetState(uint dwUserIndex, ref XINPUT_STATE pState)
        {
            #if !EXPERIMENTAL
            return OriginalXInputGetStateFunction.Value(dwUserIndex, ref pState);
            #else
            if (OriginalXInputGetStateFunction.Value(dwUserIndex, ref pState) == ResultWin32.ERROR_SUCCESS)
            {
                return ResultWin32.ERROR_SUCCESS;
            }

            try
            {
                ScpHidReport report = null;

                while (dwUserIndex == 0 && (report = Proxy.GetReport(dwUserIndex)) == null)
                {
                    Thread.Sleep(100);
                }

                if (report == null || report.PadState != DsState.Connected)
                {
                    return ResultWin32.ERROR_DEVICE_NOT_CONNECTED;
                }

                var xPad = new XINPUT_GAMEPAD();

                pState.dwPacketNumber = report.PacketCounter;

                switch (report.Model)
                {
                    case DsModel.DS3:
                    {
                        // select & start
                        xPad.wButtons |= (ushort) report[Ds3Button.Select].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Start].Xbox360Button;

                        // d-pad
                        xPad.wButtons |= (ushort) report[Ds3Button.Up].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Right].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Down].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Left].Xbox360Button;

                        // shoulders
                        xPad.wButtons |= (ushort) report[Ds3Button.L1].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.R1].Xbox360Button;

                        // face buttons
                        xPad.wButtons |= (ushort) report[Ds3Button.Triangle].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Circle].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Cross].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.Square].Xbox360Button;

                        // PS/Guide
                        xPad.wButtons |= (ushort) report[Ds3Button.Ps].Xbox360Button;

                        // thumbs
                        xPad.wButtons |= (ushort) report[Ds3Button.L3].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds3Button.R3].Xbox360Button;

                        // triggers
                        xPad.bLeftTrigger = report[Ds3Axis.L2].Value;
                        xPad.bRightTrigger = report[Ds3Axis.R2].Value;

                        // thumb axes
                        xPad.sThumbLX = (short) +DsMath.Scale(report[Ds3Axis.Lx].Value, false);
                        xPad.sThumbLY = (short) -DsMath.Scale(report[Ds3Axis.Ly].Value, false);
                        xPad.sThumbRX = (short) +DsMath.Scale(report[Ds3Axis.Rx].Value, false);
                        xPad.sThumbRY = (short) -DsMath.Scale(report[Ds3Axis.Ry].Value, false);
                    }
                        break;
                    case DsModel.DS4:
                    {
                        // select & start
                        xPad.wButtons |= (ushort) report[Ds4Button.Share].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Options].Xbox360Button;

                        // d-pad
                        xPad.wButtons |= (ushort) report[Ds4Button.Up].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Right].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Down].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Left].Xbox360Button;

                        // shoulders
                        xPad.wButtons |= (ushort) report[Ds4Button.L1].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.R1].Xbox360Button;

                        // face buttons
                        xPad.wButtons |= (ushort) report[Ds4Button.Triangle].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Circle].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Cross].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.Square].Xbox360Button;

                        // PS/Guide
                        xPad.wButtons |= (ushort) report[Ds4Button.Ps].Xbox360Button;

                        // thumbs
                        xPad.wButtons |= (ushort) report[Ds4Button.L3].Xbox360Button;
                        xPad.wButtons |= (ushort) report[Ds4Button.R3].Xbox360Button;

                        // triggers
                        xPad.bLeftTrigger = report[Ds4Axis.L2].Value;
                        xPad.bRightTrigger = report[Ds4Axis.R2].Value;

                        // thumb axes
                        xPad.sThumbLX = (short) +DsMath.Scale(report[Ds4Axis.Lx].Value, false);
                        xPad.sThumbLY = (short) -DsMath.Scale(report[Ds4Axis.Ly].Value, false);
                        xPad.sThumbRX = (short) +DsMath.Scale(report[Ds4Axis.Rx].Value, false);
                        xPad.sThumbRY = (short) -DsMath.Scale(report[Ds4Axis.Ry].Value, false);
                    }
                        break;
                }

                pState.Gamepad = xPad;
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Unexpected error: {0}", ex);
                return ResultWin32.ERROR_DEVICE_NOT_CONNECTED;
            }

            return ResultWin32.ERROR_SUCCESS;
            #endif
        }