Example #1
0
        public static void setJoystick(ref vJoy joystick, ControllerState input, uint joystickID, ControllerDeadZones deadZones)
        {
            bool res;
            var multiplier = 127;

            if (!deadZones.analogStick.inDeadZone(input.StickX, input.StickY))
            {
                res = joystick.SetAxis(multiplier * input.StickX, joystickID, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(multiplier * (255 - input.StickY), joystickID, HID_USAGES.HID_USAGE_Y);
            }
            else
            {
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_Y);
            }
            
            if (!deadZones.cStick.inDeadZone(input.CX, input.CY))
            {
                res = joystick.SetAxis(multiplier * input.CX, joystickID, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(multiplier * (255 - input.CY), joystickID, HID_USAGES.HID_USAGE_RY);
            }
            else
            {
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_RY);
            }
            
            if (!deadZones.LTrigger.inDeadZone(input.LAnalog))
            {
                res = joystick.SetAxis(multiplier * input.LAnalog, joystickID, HID_USAGES.HID_USAGE_Z);
            }
            else
            {
                res = joystick.SetAxis(0, joystickID, HID_USAGES.HID_USAGE_Z);
            }
            if (!deadZones.RTrigger.inDeadZone(input.RAnalog))
            {
                res = joystick.SetAxis(multiplier * input.RAnalog, joystickID, HID_USAGES.HID_USAGE_RZ);
            }
            else
            {
                res = joystick.SetAxis(0, joystickID, HID_USAGES.HID_USAGE_RZ);
            }

            //dpad button mode for DDR pad support
            res = joystick.SetBtn(input.DUp, joystickID, 9);
            res = joystick.SetBtn(input.DDown, joystickID, 10);
            res = joystick.SetBtn(input.DLeft, joystickID, 11);
            res = joystick.SetBtn(input.DRight, joystickID, 12);

            //buttons
            res = joystick.SetBtn(input.A, joystickID, 1);
            res = joystick.SetBtn(input.B, joystickID, 2);
            res = joystick.SetBtn(input.X, joystickID, 3);
            res = joystick.SetBtn(input.Y, joystickID, 4);
            res = joystick.SetBtn(input.Z, joystickID, 5);
            res = joystick.SetBtn(input.RDigital, joystickID, 6);
            res = joystick.SetBtn(input.LDigital, joystickID, 7);
            res = joystick.SetBtn(input.Start, joystickID, 8);
        }
Example #2
0
 public Client()
 {
     State = new ControllerState(0);
     // fix this later
     SocketClient.ClientLog += Client_Log;
     InitializeComponent();
     updateBoxes();
     updateStateTextBox();
 }
Example #3
0
        public static ControllerState deserialize(byte[] input)
        {
            var pad = new ControllerState(0);

            if (input.Length != 9)
                throw new Exception("Invalid byte array for input");

            if ((int)input[0] <= 0)
                return pad;

            pad.A = (input[1] & (1 << 0)) != 0;
            pad.B = (input[1] & (1 << 1)) != 0;
            pad.X = (input[1] & (1 << 2)) != 0;
            pad.Y = (input[1] & (1 << 3)) != 0;

            pad.DLeft  = (input[1] & (1 << 4)) != 0;
            pad.DRight = (input[1] & (1 << 5)) != 0;
            pad.DDown  = (input[1] & (1 << 6)) != 0;
            pad.DUp    = (input[1] & (1 << 7)) != 0;

            //Generate POV state for vJoy.
            if (pad.DRight)     { pad.POVstate = 1; }
            else if (pad.DDown) { pad.POVstate = 2; }
            else if (pad.DLeft) { pad.POVstate = 3; }
            else if (pad.DUp)   { pad.POVstate = 0; }
            else                 { pad.POVstate = -1; }

            pad.Start       = (input[2] & (1 << 0)) != 0;
            pad.Z           = (input[2] & (1 << 1)) != 0;
            pad.RDigital   = (input[2] & (1 << 2)) != 0;
            pad.LDigital   = (input[2] & (1 << 3)) != 0;

            pad.StickX     = input[3];
            pad.StickY     = input[4];
            pad.CX         = input[5];
            pad.CY         = input[6];
            pad.LAnalog    = input[7];
            pad.RAnalog    = input[8];

            return pad;
        }
Example #4
0
 public void Add(int frame, ControllerState currentState)
 {
     _moveDict.Add(frame, currentState);
 }
Example #5
0
 private Bot()
 {
     Prev = new ControllerState(-1);
 }
Example #6
0
 private void LogFrameState(int frameNum, ControllerState controllerState, bool rem)
 {
     _log?.Invoke(null,
         !rem
             ? new Logging.LogEventArgs($"Something went wrong on frame {frameNum}")
             : new Logging.LogEventArgs($"F: {frameNum} - {controllerState}"));
 }
Example #7
0
        public bool ProcessMoves()
        {
            var lastFrameNum = GameState.LastFrame;
            var thisFrameNum = GameState.GetFrame();

            if (thisFrameNum == lastFrameNum)
                return false;

            AIProcess(thisFrameNum);

            if (thisFrameNum != lastFrameNum + 1 && thisFrameNum > lastFrameNum)
                _log?.Invoke(null, new Logging.LogEventArgs($"Lost frames between { lastFrameNum } and { thisFrameNum }"));

            Prev = State;
            if (MQueue.HasFrame(thisFrameNum))
            {
                State = MQueue.Get(thisFrameNum);
                var rem = MQueue.Remove(thisFrameNum);
                LogFrameState(thisFrameNum, State, rem);
            }
            else
            {
                State = new ControllerState(thisFrameNum);
            }
            return true;
        }
Example #8
0
 public void Add(int frame, ControllerState currentState)
 {
     _moveDict.Add(frame, currentState);
 }