Exemplo n.º 1
0
        public void ShouldGetCurrentState(uint index)
        {
            var result   = new XInputState();
            var opResult = XInputInvoker.XInputGetState(index, ref result);

            Assert.Equal(XInputOpResult.Success, opResult);
        }
Exemplo n.º 2
0
        private ushort[] GetScancodeSequense(XInputState st, GamePadEventType type)
        {
            string[] keystroke = new string[] { };
            switch (type)
            {
            case GamePadEventType.Button:
                keystroke = Parse.Keystroke(Parse.KeysToString(Controller.GetProfile(), (XInputWrapper.GP)st.Gamepad.WButtons));
                break;

            case GamePadEventType.RightTrigger:
                keystroke = Parse.Keystroke(Parse.KeysToString(Controller.GetProfile(), (XInputWrapper.GP) 0x3333));
                break;

            case GamePadEventType.LeftTrigger:
                keystroke = Parse.Keystroke(Parse.KeysToString(Controller.GetProfile(), (XInputWrapper.GP) 0x5555));
                break;
            }
            List <ushort> result = new List <ushort>();

            foreach (var item in keystroke)
            {
                HardwareButtons code = (HardwareButtons)Enum.Parse(typeof(HardwareButtons), item);
                if (User32Wrapper.VKeys.TryGetValue((int)code, out ushort value))
                {
                    result.Add(value);
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 3
0
 private static GamepadModel Map(XInputState state)
 {
     return(new GamepadModel
     {
         LeftThumbStick = new ThumbStickModel
         {
             Vertical = state.Gamepad.sThumbLY,
             Horizontal = state.Gamepad.sThumbLX
         },
         RightThumbStick = new ThumbStickModel
         {
             Horizontal = state.Gamepad.sThumbRX,
             Vertical = state.Gamepad.sThumbRY
         },
         LeftTrigger = state.Gamepad.bLeftTrigger,
         RightTrigger = state.Gamepad.bRightTrigger,
         IsLeftTriggerButtonPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_LEFT_SHOULDER),
         IsRightTriggerButtonPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_RIGHT_SHOULDER),
         IsLeftThumbStickPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_LEFT_THUMB),
         IsRightThumbStickPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_RIGHT_THUMB),
         IsAPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_A),
         IsBPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_B),
         IsXPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_X),
         IsYPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_Y),
         IsBackPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_BACK),
         IsStartPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_START),
         DPad = new DPadModel
         {
             IsDownPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_DPAD_DOWN),
             IsUpPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_DPAD_UP),
             IsLeftPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_DPAD_LEFT),
             IsRightPressed = GetButtonState(state, ButtonFlags.XINPUT_GAMEPAD_DPAD_RIGHT),
         }
     });
 }
Exemplo n.º 4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            XInputState state = new XInputState();

            XInput.XInputGetState(0, ref state);
            List <XBoxControllerInput> currentInputs = getCurrentInputs(state);

            btn_a.Visible = currentInputs.Contains(XBoxControllerInput.A);
            btn_b.Visible = currentInputs.Contains(XBoxControllerInput.B);
            btn_x.Visible = currentInputs.Contains(XBoxControllerInput.X);
            btn_y.Visible = currentInputs.Contains(XBoxControllerInput.Y);

            btn_R.Visible = currentInputs.Contains(XBoxControllerInput.RShoulder);
            btn_L.Visible = currentInputs.Contains(XBoxControllerInput.LShoulder);

            btn_Ddown.Visible  = currentInputs.Contains(XBoxControllerInput.DDown);
            btn_Dup.Visible    = currentInputs.Contains(XBoxControllerInput.DUp);
            btn_Dleft.Visible  = currentInputs.Contains(XBoxControllerInput.DLeft);
            btn_Dright.Visible = currentInputs.Contains(XBoxControllerInput.DRight);

            btn_start.Visible      = currentInputs.Contains(XBoxControllerInput.Start);
            btn_back.Visible       = currentInputs.Contains(XBoxControllerInput.Back);
            stick.BackgroundImage  = currentInputs.Contains(XBoxControllerInput.LStick) ? Properties.Resources.stick_2 : Properties.Resources.stick_1;
            stick2.BackgroundImage = currentInputs.Contains(XBoxControllerInput.RStick) ? Properties.Resources.stick_2 : Properties.Resources.stick_1;

            btnR_trig.Visible = currentInputs.Contains(XBoxControllerInput.RTrigger);
            btnL_trig.Visible = currentInputs.Contains(XBoxControllerInput.LTrigger);

            stick.Left  = StickOriginX + STICK_DISTANCE * state.sThumbLX / 32768;
            stick.Top   = StickOriginY - STICK_DISTANCE * state.sThumbLY / 32768;
            stick2.Left = StickOriginX2 + STICK_DISTANCE * state.sThumbRX / 32768;
            stick2.Top  = StickOriginY2 - STICK_DISTANCE * state.sThumbRY / 32768;
        }
Exemplo n.º 5
0
        void tick (object sender, EventArgs e)
        {
            var state = new XInputState ();
            if (XInputDLL.XInputGetState (_id, ref state) > 0) {
                if (ControllerDisconnected != null) ControllerDisconnected (this, EventArgs.Empty);
                Finish ();
                return;
            }

            var outState = new ControllerStateBuilder ();
            
            outState.SetButton ("a", (state.wButtons & 0x1000) != 0);
            outState.SetButton ("b", (state.wButtons & 0x2000) != 0);
            outState.SetButton ("x", (state.wButtons & 0x4000) != 0);
            outState.SetButton ("y", (state.wButtons & 0x8000) != 0);
            outState.SetButton ("up", (state.wButtons & 0x0001) != 0);
            outState.SetButton ("down", (state.wButtons & 0x0002) != 0);
            outState.SetButton ("left", (state.wButtons & 0x0004) != 0);
            outState.SetButton ("right", (state.wButtons & 0x0008) != 0);
            outState.SetButton ("start", (state.wButtons & 0x0010) != 0);
            outState.SetButton ("back", (state.wButtons & 0x0020) != 0);
            outState.SetButton ("l3", (state.wButtons & 0x0040) != 0);
            outState.SetButton ("r3", (state.wButtons & 0x0080) != 0);
            outState.SetButton ("l", (state.wButtons & 0x0100) != 0);
            outState.SetButton ("r", (state.wButtons & 0x0200) != 0);

            outState.SetAnalog ("lstick_x", (float)state.sThumbLX / 32768);
            outState.SetAnalog ("lstick_y", (float)state.sThumbLY / 32768);
            outState.SetAnalog ("rstick_x", (float)state.sThumbRX / 32768);
            outState.SetAnalog ("rstick_y", (float)state.sThumbRY / 32768);
            outState.SetAnalog ("trig_l", (float)state.bLeftTrigger / 255);
            outState.SetAnalog ("trig_r", (float)state.bRightTrigger / 255);

            if (ControllerStateChanged != null) ControllerStateChanged (this, outState.Build ());
        }
Exemplo n.º 6
0
        static object GetElementFromXInputState(XInputState state, EventType SourceEvent)
        {
            switch (SourceEvent)
            {
            case EventType.ThumbLX:
                return(state.Gamepad.ThumbLX);

            case EventType.ThumbLY:
                return(state.Gamepad.ThumbLY);

            case EventType.ThumbRX:
                return(state.Gamepad.ThumbRX);

            case EventType.ThumbRY:
                return(state.Gamepad.ThumbRY);

            case EventType.LeftTrigger:
                return(state.Gamepad.LeftTrigger);

            case EventType.RightTrigger:
                return(state.Gamepad.RightTrigger);

            case EventType.Buttons:
                return(state.Gamepad.Buttons);

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 7
0
        private List<XBoxControllerInput> getCurrentInputs(XInputState state)
        {
            List<XBoxControllerInput> ret = new List<XBoxControllerInput>();

            if ((state.wButtons & 0x1000) != 0) ret.Add(XBoxControllerInput.A);
            if ((state.wButtons & 0x2000) != 0) ret.Add(XBoxControllerInput.B);
            if ((state.wButtons & 0x4000) != 0) ret.Add(XBoxControllerInput.X);
            if ((state.wButtons & 0x8000) != 0) ret.Add(XBoxControllerInput.Y);

            if ((state.wButtons & 0x0001) != 0) ret.Add(XBoxControllerInput.DUp);
            if ((state.wButtons & 0x0002) != 0) ret.Add(XBoxControllerInput.DDown);
            if ((state.wButtons & 0x0004) != 0) ret.Add(XBoxControllerInput.DLeft);
            if ((state.wButtons & 0x0008) != 0) ret.Add(XBoxControllerInput.DRight);

            if ((state.wButtons & 0x0010) != 0) ret.Add(XBoxControllerInput.Start);
            if ((state.wButtons & 0x0020) != 0) ret.Add(XBoxControllerInput.Back);
            if ((state.wButtons & 0x0040) != 0) ret.Add(XBoxControllerInput.LStick);
            if ((state.wButtons & 0x0080) != 0) ret.Add(XBoxControllerInput.RStick);

            if ((state.wButtons & 0x0100) != 0) ret.Add(XBoxControllerInput.LShoulder);
            if ((state.wButtons & 0x0200) != 0) ret.Add(XBoxControllerInput.RShoulder);

            if (state.bLeftTrigger > TRIGGER_THRESHOLD) ret.Add(XBoxControllerInput.LTrigger);
            if (state.bRightTrigger > TRIGGER_THRESHOLD) ret.Add(XBoxControllerInput.RTrigger);

            return ret;
        }
Exemplo n.º 8
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            XInputState state = new XInputState();
            XInput.XInputGetState(0, ref state);
            List<XBoxControllerInput> currentInputs = getCurrentInputs(state);

            btn_a.Visible = currentInputs.Contains(XBoxControllerInput.A);
            btn_b.Visible = currentInputs.Contains(XBoxControllerInput.B);
            btn_x.Visible = currentInputs.Contains(XBoxControllerInput.X);
            btn_y.Visible = currentInputs.Contains(XBoxControllerInput.Y);

            btn_R.Visible = currentInputs.Contains(XBoxControllerInput.RShoulder);
            btn_L.Visible = currentInputs.Contains(XBoxControllerInput.LShoulder);

            btn_Ddown.Visible = currentInputs.Contains(XBoxControllerInput.DDown);
            btn_Dup.Visible = currentInputs.Contains(XBoxControllerInput.DUp);
            btn_Dleft.Visible = currentInputs.Contains(XBoxControllerInput.DLeft);
            btn_Dright.Visible = currentInputs.Contains(XBoxControllerInput.DRight);

            btn_start.Visible = currentInputs.Contains(XBoxControllerInput.Start);
            btn_back.Visible = currentInputs.Contains(XBoxControllerInput.Back);

            btnR_trig.Visible = currentInputs.Contains(XBoxControllerInput.RTrigger);
            btnL_trig.Visible = currentInputs.Contains(XBoxControllerInput.LTrigger);

            stick.Left = StickOriginX + STICK_DISTANCE * state.sThumbLX / 32768;
            stick.Top = StickOriginY - STICK_DISTANCE * state.sThumbLY / 32768;
            stick2.Left = StickOriginX2 + STICK_DISTANCE * state.sThumbRX / 32768;
            stick2.Top = StickOriginY2 - STICK_DISTANCE * state.sThumbRY / 32768;
        }
Exemplo n.º 9
0
        void tick(object sender, EventArgs e)
        {
            XInputState state = new XInputState ();

            if (XInputDLL.XInputGetState (0, ref state) > 0) {
                if (ControllerDisconnected != null) ControllerDisconnected (this, EventArgs.Empty);
                Finish ();
                return;
            }

            _buttons ["a"]     = (state.wButtons & 0x1000) != 0;
            _buttons ["b"]     = (state.wButtons & 0x2000) != 0;
            _buttons ["x"]     = (state.wButtons & 0x4000) != 0;
            _buttons ["y"]     = (state.wButtons & 0x8000) != 0;
            _buttons ["up"]    = (state.wButtons & 0x0001) != 0;
            _buttons ["down"]  = (state.wButtons & 0x0002) != 0;
            _buttons ["left"]  = (state.wButtons & 0x0004) != 0;
            _buttons ["right"] = (state.wButtons & 0x0008) != 0;
            _buttons ["start"] = (state.wButtons & 0x0010) != 0;
            _buttons ["back"]  = (state.wButtons & 0x0020) != 0;
            _buttons ["l3"]    = (state.wButtons & 0x0040) != 0;
            _buttons ["r3"]    = (state.wButtons & 0x0080) != 0;
            _buttons ["l"]     = (state.wButtons & 0x0100) != 0;
            _buttons ["r"]     = (state.wButtons & 0x0200) != 0;

            _analogs ["lstick_x"] = (float)state.sThumbLX / 32768;
            _analogs ["lstick_y"] = (float)state.sThumbLY / 32768;
            _analogs ["rstick_x"] = (float)state.sThumbRX / 32768;
            _analogs ["rstick_y"] = (float)state.sThumbRY / 32768;
            _analogs ["trig_l"]   = (float)state.bLeftTrigger / 255;
            _analogs ["trig_r"]   = (float)state.bRightTrigger / 255;

            if (ControllerStateChanged != null) ControllerStateChanged (this, EventArgs.Empty);
        }
Exemplo n.º 10
0
        static void BackgroundGetControllerInput()
        {
            var         values   = Enum.GetValues(typeof(EventType));
            XInputState OldState = new XInputState();
            XInputState NewState = new XInputState();

            XInputGetState(0, out OldState);

            while (IsProcessKeepRunning)
            {
                Thread.Sleep(UpdateInterval_Millisecond);
                XInputGetState(0, out NewState);

                foreach (EventType ControllerEvent in values)
                {
                    if (ControllerEvent == EventType.Buttons)
                    {
                        int OldVal             = OldState.Gamepad.Buttons,
                                   NewVal      = NewState.Gamepad.Buttons;
                        int StateChangedButton = OldVal ^ NewVal;
                        if (StateChangedButton == 0)
                        {
                            continue;
                        }
                        for (int i = 0; i < wButtonsName.Length; ++i)
                        {
                            int Mask = 1 << i;
                            if ((StateChangedButton & Mask) == 0)
                            {
                                continue;
                            }
                            bool IsNowBtnPressed = (NewVal & Mask) != 0;
                            EventSender(ControllerEvent, $"{wButtonsName[i]}|{(IsNowBtnPressed ? "Pressed" : "Release")}");
                        }
                    }
                    else if (ControllerEvent < EventType.LeftTrigger) //ThumB
                    {
                        object OldVal = GetElementFromXInputState(OldState, ControllerEvent),
                               NewVal = GetElementFromXInputState(NewState, ControllerEvent);

                        EventSender(ControllerEvent, $"{OldVal.ToString()}|{(Math.Abs((int)(short) NewVal) > ThumbEPS? NewVal.ToString(): "0")}");
                    }
                    else
                    {
                        object OldVal = GetElementFromXInputState(OldState, ControllerEvent),
                               NewVal = GetElementFromXInputState(NewState, ControllerEvent);

                        if (!OldVal.Equals(NewVal))
                        {
                            EventSender(ControllerEvent, $"{OldVal.ToString()}|{NewVal.ToString()}");
                        }
                    }
                }
                Swap(ref OldState, ref NewState);
            }
        }
Exemplo n.º 11
0
            public override bool Equals(object obj)
            {
                if ((obj == null) || (!(obj is XInputState)))
                {
                    return(false);
                }
                XInputState source = (XInputState)obj;

                return((PacketNumber == source.PacketNumber) && (Gamepad.Equals(source.Gamepad)));
            }
Exemplo n.º 12
0
 public static List<uint> GetDevices()
 {
     var result = new List<uint>();
     var dummy = new XInputState();
     for (uint i = 0; i < 4; i++) //Poll all 4 possible controllers to see which are connected, thats how it works :/
     {
         if (XInputDLL.XInputGetState(i, ref dummy) == 0)
         {
             result.Add(i);
         }
     }
     return result;
 }
Exemplo n.º 13
0
        public static Collection <uint> GetDevices()
        {
            Collection <uint> result = new Collection <uint>();
            XInputState       dummy  = new XInputState();

            for (uint i = 0; i < 4; i++) //Poll all 4 possible controllers to see which are connected, thats how it works :/
            {
                if (NativeMethods.XInputGetState(i, ref dummy) == 0)
                {
                    result.Add(i);
                }
            }
            return(result);
        }
Exemplo n.º 14
0
        public int GetState(int dwUserIndex, ref XInputState pState)
        {
            switch (dllIndex)
            {
            case 0:
                return(XInputGetState14(dwUserIndex, ref pState));

            case 1:
                return(XInputGetState13(dwUserIndex, ref pState));

            case 2:
                return(XInputGetState9(dwUserIndex, ref pState));

            default:
                return(0);
            }
        }
Exemplo n.º 15
0
        private void ExecuteAction(XInputState st, GamePadEventType etype, InputType itype)
        {
            if (etype == GamePadEventType.RightThumbStick)
            {
                _win32Sender.SendMouseMoveInput(st.Gamepad.SThumbRX, st.Gamepad.SThumbRY, GamePadStickType.Right);
            }
            else if (etype == GamePadEventType.LeftThumbStick)
            {
                _win32Sender.SendMouseMoveInput(st.Gamepad.SThumbLX, st.Gamepad.SThumbLY, GamePadStickType.Left);
            }
            else
            {
                ushort[] sequense = GetScancodeSequense(st, etype);
                if (sequense.Length == 0)
                {
                    return;
                }

                _win32Sender.SendKeyboardInput(sequense, itype);
            }
        }
Exemplo n.º 16
0
        private void Tick(object sender, EventArgs e)
        {
            XInputState state = new XInputState();

            if (NativeMethods.XInputGetState(_id, ref state) > 0)
            {
                ControllerDisconnected?.Invoke(this, EventArgs.Empty);
                Finish();
                return;
            }

            ControllerStateBuilder outState = new ControllerStateBuilder();

            outState.SetButton("a", (state.wButtons & 0x1000) != 0);
            outState.SetButton("b", (state.wButtons & 0x2000) != 0);
            outState.SetButton("x", (state.wButtons & 0x4000) != 0);
            outState.SetButton("y", (state.wButtons & 0x8000) != 0);
            outState.SetButton("up", (state.wButtons & 0x0001) != 0);
            outState.SetButton("down", (state.wButtons & 0x0002) != 0);
            outState.SetButton("left", (state.wButtons & 0x0004) != 0);
            outState.SetButton("right", (state.wButtons & 0x0008) != 0);
            outState.SetButton("start", (state.wButtons & 0x0010) != 0);
            outState.SetButton("back", (state.wButtons & 0x0020) != 0);
            outState.SetButton("l3", (state.wButtons & 0x0040) != 0);
            outState.SetButton("r3", (state.wButtons & 0x0080) != 0);
            outState.SetButton("l", (state.wButtons & 0x0100) != 0);
            outState.SetButton("r", (state.wButtons & 0x0200) != 0);

            outState.SetAnalog("lstick_x", (float)state.sThumbLX / 32768, state.sThumbLX);
            outState.SetAnalog("lstick_y", (float)state.sThumbLY / 32768, state.sThumbLY);
            outState.SetAnalog("rstick_x", (float)state.sThumbRX / 32768, state.sThumbRX);
            outState.SetAnalog("rstick_y", (float)state.sThumbRY / 32768, state.sThumbRY);
            outState.SetAnalog("trig_l", (float)state.bLeftTrigger / 255, state.bLeftTrigger);
            outState.SetAnalog("trig_r", (float)state.bRightTrigger / 255, state.bRightTrigger);

            ControllerStateChanged?.Invoke(this, outState.Build());
        }
Exemplo n.º 17
0
        void tick (object sender, EventArgs e)
        {
            var state = new XInputState ();

            if (XInputDLL.XInputGetState (0, ref state) > 0) {
                if (ControllerDisconnected != null) ControllerDisconnected (this, EventArgs.Empty);
                Finish ();
                return;
            }

            var outState = new ControllerStateBuilder ();
            
            outState.SetButton ("a", (state.wButtons & 0x1000) != 0);
            outState.SetButton ("b", (state.wButtons & 0x2000) != 0);
            outState.SetButton ("x", (state.wButtons & 0x4000) != 0);
            outState.SetButton ("y", (state.wButtons & 0x8000) != 0);
            outState.SetButton ("up", (state.wButtons & 0x0001) != 0);
            outState.SetButton ("down", (state.wButtons & 0x0002) != 0);
            outState.SetButton ("left", (state.wButtons & 0x0004) != 0);
            outState.SetButton ("right", (state.wButtons & 0x0008) != 0);
            outState.SetButton ("start", (state.wButtons & 0x0010) != 0);
            outState.SetButton ("back", (state.wButtons & 0x0020) != 0);
            outState.SetButton ("l3", (state.wButtons & 0x0040) != 0);
            outState.SetButton ("r3", (state.wButtons & 0x0080) != 0);
            outState.SetButton ("l", (state.wButtons & 0x0100) != 0);
            outState.SetButton ("r", (state.wButtons & 0x0200) != 0);

            outState.SetAnalog ("lstick_x", (float)state.sThumbLX / 32768);
            outState.SetAnalog ("lstick_y", (float)state.sThumbLY / 32768);
            outState.SetAnalog ("rstick_x", (float)state.sThumbRX / 32768);
            outState.SetAnalog ("rstick_y", (float)state.sThumbRY / 32768);
            outState.SetAnalog ("trig_l", (float)state.bLeftTrigger / 255);
            outState.SetAnalog ("trig_r", (float)state.bRightTrigger / 255);

            if (ControllerStateChanged != null) ControllerStateChanged (this, outState.Build ());
        }
Exemplo n.º 18
0
    /// <summary>
    /// 熱血インプットで入力された値を元に、
    /// 移動・ダッシュ・ブレーキの状態を管理
    /// </summary>
    public void MoveMain(NekketsuSound NSound)
    {
        if (!NAct.squatFlag &&
            NAct.NowDamage == DamagePattern.None)
        {
            #region 歩き

            // もし、右キーが押されたら
            if (NAct.XInputState == XInputState.XRightPushMoment ||
                NAct.XInputState == XInputState.XRightPushButton)
            {
                if (!NAct.brakeFlag)
                {
                    NAct.leftFlag = false;
                }

                if (!NAct.dashFlag && !NAct.jumpFlag && !NAct.brakeFlag)
                {
                    NAct.vx = NAct.speed; // 右に歩く移動量を入れる
                }
            }
            // もし、左キーが押されたら ★else if でもキーボード同時押し対策NG★
            else if (NAct.XInputState == XInputState.XLeftPushMoment ||
                     NAct.XInputState == XInputState.XLeftPushButton)
            {
                if (!NAct.brakeFlag)
                {
                    NAct.leftFlag = true;
                }

                if (!NAct.dashFlag && !NAct.jumpFlag && !NAct.brakeFlag)
                {
                    NAct.vx = -NAct.speed; // 左に歩く移動量を入れる
                }
            }

            // もし、上キーが押されたら
            if (NAct.ZInputState == ZInputState.ZBackPushMoment ||
                NAct.ZInputState == ZInputState.ZBackPushButton)
            {
                if (!NAct.jumpFlag)
                {
                    NAct.vz = NAct.speed * Settings.Instance.Move.ZWalkSpeed; // 上に進む移動量を入れる(熱血っぽく奥行きは移動量小)
                }
            }
            // もし、下キーが押されたら
            else if (NAct.ZInputState == ZInputState.ZFrontPushMoment ||
                     NAct.ZInputState == ZInputState.ZFrontPushButton)
            {
                if (!NAct.jumpFlag)
                {
                    NAct.vz = -NAct.speed * Settings.Instance.Move.ZWalkSpeed; // 下に進む移動量を入れる(熱血っぽく奥行きは移動量小)
                }
            }

            #endregion

            #region ダッシュ

            if (!NAct.dashFlag)
            {
                // 非ダッシュ状態で、横移動し始めた瞬間か?
                if (NAct.XInputState == XInputState.XRightPushMoment ||
                    NAct.XInputState == XInputState.XLeftPushMoment)
                {
                    if (!pushMove)
                    {
                        //ダッシュしたい方向と同じ方向キーが押されている
                        if (XInputDashVector == NAct.XInputState)
                        {
                            //ダッシュの準備をする
                            pushMove    = true;
                            leftDash    = NAct.leftFlag;
                            nowTimeDash = 0;
                        }

                        //ダッシュしようとしている方向を覚えておく
                        XInputDashVector = NAct.XInputState;
                    }
                    else
                    {
                        // ダッシュ準備済なので、ダッシュしてよい状態か判断
                        if (canDash && !NAct.jumpFlag &&
                            leftDash == NAct.leftFlag &&
                            nowTimeDash <= NAct.nextButtonDownTimeDash)
                        {
                            NAct.dashFlag = true;
                        }
                    }
                }
                else
                {
                    // 非ダッシュ状態で、ダッシュ準備済か?
                    // 1度左右キーが押された状態で、ダッシュ受付時間内にもう一度左右キーが押された時
                    if (pushMove &&
                        !NAct.brakeFlag)
                    {
                        // 時間計測
                        nowTimeDash += Time.deltaTime;

                        if (nowTimeDash > NAct.nextButtonDownTimeDash)
                        {
                            pushMove         = false;
                            canDash          = false;
                            XInputDashVector = XInputState.XNone;
                        }
                        else
                        {
                            canDash = true;
                        }
                    }
                }
            }
            else
            {   //ダッシュ済の場合
                if (!NAct.brakeFlag)
                {
                    // ダッシュ中に逆方向を押した場合
                    if (leftDash != NAct.leftFlag)
                    {
                        /// @@@ if文で代入の値を変える場合は、
                        /// バグを避けるためにも可能な限り代入を一箇所にしたほうがよいですね。
                        /// ここで言えば
                        /// int GetSign(bool leftDash) { return leftDash ? -1 : +1;}
                        /// というような関数を作っておき、
                        ///  NAct.vx = GetSign(leftDash) * NAct.speed * Settings.Instance.Move.DashSpeed;
                        /// と書けば1行ですむ上に、左右で値を間違えてしまうことなどもなくなります。
                        if (leftDash)
                        {
                            // 左ダッシュの移動量を入れる
                            NAct.vx = -NAct.speed * Settings.Instance.Move.DashSpeed;
                        }
                        else
                        {
                            // 右ダッシュの移動量を入れる
                            NAct.vx = NAct.speed * Settings.Instance.Move.DashSpeed;;
                        }

                        NAct.dashFlag = false;
                        pushMove      = false;
                        canDash       = false;

                        // ブレーキ状態
                        if (!NAct.jumpFlag)
                        {
                            NAct.brakeFlag = true;
                            NSound.SEPlay(SEPattern.brake);
                        }
                    }
                    else
                    {
                        // ダッシュ中の加速を計算する。
                        // ダッシュ中は方向キー入力なしで自動で進む。(クロカン・障害ふう)
                        if (NAct.leftFlag)
                        {
                            // 左ダッシュの移動量を入れる
                            NAct.vx = -NAct.speed * Settings.Instance.Move.DashSpeed;
                        }
                        else
                        {
                            // 右ダッシュの移動量を入れる
                            NAct.vx = NAct.speed * Settings.Instance.Move.DashSpeed;;
                        }
                    }
                }
            }

            // ブレーキ処理
            if (!NAct.jumpFlag && NAct.brakeFlag)
            {
                if (NAct.leftFlag)
                {
                    NAct.vx = NAct.speed * NAct.st_brake; // 右に進む移動量を入れる
                }
                else
                {
                    NAct.vx = -NAct.speed * NAct.st_brake; // 左に進む移動量を入れる
                }
                // ブレーキ状態の時間計測
                nowTimebrake += Time.deltaTime;

                // ブレーキ状態解除
                if (nowTimebrake > Settings.Instance.Move.BrakeTime)
                {
                    NAct.brakeFlag = false;
                    nowTimebrake   = 0;
                }
            }

            // ダッシュ入力受付中
            if (pushMove)
            {
                // 時間計測
                nowTimeDash += Time.deltaTime;

                if (nowTimeDash > NAct.nextButtonDownTimeDash)
                {
                    pushMove         = false;
                    canDash          = false;
                    XInputDashVector = XInputState.XNone;
                }
            }
            #endregion
        }
    }
Exemplo n.º 19
0
        private List <XBoxControllerInput> getCurrentInputs(XInputState state)
        {
            List <XBoxControllerInput> ret = new List <XBoxControllerInput>();

            if ((state.wButtons & 0x1000) != 0)
            {
                ret.Add(XBoxControllerInput.A);
            }
            if ((state.wButtons & 0x2000) != 0)
            {
                ret.Add(XBoxControllerInput.B);
            }
            if ((state.wButtons & 0x4000) != 0)
            {
                ret.Add(XBoxControllerInput.X);
            }
            if ((state.wButtons & 0x8000) != 0)
            {
                ret.Add(XBoxControllerInput.Y);
            }

            if ((state.wButtons & 0x0001) != 0)
            {
                ret.Add(XBoxControllerInput.DUp);
            }
            if ((state.wButtons & 0x0002) != 0)
            {
                ret.Add(XBoxControllerInput.DDown);
            }
            if ((state.wButtons & 0x0004) != 0)
            {
                ret.Add(XBoxControllerInput.DLeft);
            }
            if ((state.wButtons & 0x0008) != 0)
            {
                ret.Add(XBoxControllerInput.DRight);
            }

            if ((state.wButtons & 0x0010) != 0)
            {
                ret.Add(XBoxControllerInput.Start);
            }
            if ((state.wButtons & 0x0020) != 0)
            {
                ret.Add(XBoxControllerInput.Back);
            }
            if ((state.wButtons & 0x0040) != 0)
            {
                ret.Add(XBoxControllerInput.LStick);
            }
            if ((state.wButtons & 0x0080) != 0)
            {
                ret.Add(XBoxControllerInput.RStick);
            }

            if ((state.wButtons & 0x0100) != 0)
            {
                ret.Add(XBoxControllerInput.LShoulder);
            }
            if ((state.wButtons & 0x0200) != 0)
            {
                ret.Add(XBoxControllerInput.RShoulder);
            }

            if (state.bLeftTrigger > TRIGGER_THRESHOLD)
            {
                ret.Add(XBoxControllerInput.LTrigger);
            }
            if (state.bRightTrigger > TRIGGER_THRESHOLD)
            {
                ret.Add(XBoxControllerInput.RTrigger);
            }

            return(ret);
        }
Exemplo n.º 20
0
 static public extern uint XInputGetState(uint userIndex, ref XInputState inputState);
Exemplo n.º 21
0
 public static extern int XInputGetState
 (
     int dwUserIndex,                                // [in] Index of the gamer associated with the device
     ref XInputState state                           // [out] Receives the current state
 );
Exemplo n.º 22
0
 private static extern int XInputGetState14(int dwUserIndex, ref XInputState pState);
Exemplo n.º 23
0
 public bool Equals(XInputState rhs)
 {
     return(PacketNumber == rhs.PacketNumber &&
            Gamepad.Equals(rhs.Gamepad));
 }
Exemplo n.º 24
0
 internal static extern int XInputGetState
 (
     int dwUserIndex,
     ref XInputState pState
 );
Exemplo n.º 25
0
 private static bool GetButtonState(XInputState state, ButtonFlags button)
 {
     return(state.Gamepad.IsButtonPressed((int)button));
 }
Exemplo n.º 26
0
 public static extern int XInputGetState(int userIndex, ref XInputState state);
Exemplo n.º 27
0
 public void Copy(XInputState source)
 {
     PacketNumber = source.PacketNumber;
     Gamepad.Copy(source.Gamepad);
 }
Exemplo n.º 28
0
 public XInputGamePad()
 {
     batteryInfo = new XInputBatteryInformation();
     _state      = new XInputState();
 }
Exemplo n.º 29
0
 internal static extern int XInputGetState(
     int dwUserIndex,
     ref XInputState pState
     );
Exemplo n.º 30
0
 public static extern uint XInputGetState(uint userIndex, ref XInputState inputState);
Exemplo n.º 31
0
 static extern int XInputGetState(int dwUserIndex, out XInputState pState);
Exemplo n.º 32
0
 public extern static uint XInputGetState(
     int index,            // [in] Index of the gamer associated with the device
     out XInputState state // [out] Receives the current state
     );
Exemplo n.º 33
0
        public static void ScanDevices()
        {
            // Scan for devices
            lock (_allControllers)
            {
                if (Settings.Default.EnableDS4)
                {
                    try
                    {
                        DS4Devices.findControllers();

                        var listDS4 = DS4Devices.getDS4Controllers();

                        foreach (var controller in listDS4)
                        {
                            if (_allControllers.Count(c => c.UnderlyingDevice == controller.HidDevice) == 0)
                            {
                                Logger.Write("Found new DS4 device: {0}", controller.MacAddress);
                                _allControllers.Add(new DS4Input(controller.MacAddress));
                                ControllersUpdated?.Invoke();
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    { }
                    catch (Exception ex)
                    {
                        Logger.Write("DS4 driver error: ", ex);
                        MessageBox.Show(string.Format(Resources.ErrorDriverDs4Disabled, ex.Message), Resources.ErrorDriverDisabledTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                        Settings.Default.EnableDS4 = false;
                        Settings.Default.Save();
                    }
                }

                if (Settings.Default.EnableXbox)
                {
                    // Scan for Xbox controllers
                    try
                    {
                        for (int i = XboxController.FIRST_CONTROLLER_INDEX; i < XboxController.MAX_CONTROLLER_COUNT; i++)
                        {
                            XInputState stateController = new XInputState();
                            int         result          = XInput.XInputGetState(i, ref stateController);
                            if (result == 0) // Controller found
                            {
                                var controller = XboxController.RetrieveController(i);
                                if (_allControllers.Count(c => c.UnderlyingDevice == controller) == 0)
                                {
                                    Logger.Write("Found new XInput device: {0}", i);
                                    _allControllers.Add(new XboxInput(i));
                                    ControllersUpdated?.Invoke();
                                }
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    { }
                    catch (Exception ex)
                    {
                        Logger.Write("XInput driver error: ", ex);
                        MessageBox.Show(string.Format(Resources.ErrorDriverXboxDisabled, ex.Message), Resources.ErrorDriverDisabledTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                        Settings.Default.EnableXbox = false;
                        Settings.Default.Save();
                    }
                }
            }
        }
Exemplo n.º 34
0
 public XInputBus(int id)
 {
     inputs = new XInputState();
     ID     = id;
     busRef = BusAccess.Instance;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Gets the XInput state.
 /// </summary>
 /// <param name="dwUserIndex">The Index.</param>
 /// <param name="pState">The InputState.</param>
 /// <returns></returns>
 internal static int XInputGetState(int dwUserIndex, ref XInputState pState)
 {
     return(NativeMethods.XInputGetState(dwUserIndex, ref pState));
 }
Exemplo n.º 36
0
 /// <summary>
 /// Gets the XInput state.
 /// </summary>
 /// <param name="dwUserIndex">The Index.</param>
 /// <param name="pState">The InputState.</param>
 /// <returns></returns>
 internal static int XInputGetState(int dwUserIndex, ref XInputState pState)
 {
     return NativeMethods.XInputGetState(dwUserIndex, ref pState);
 }
Exemplo n.º 37
0
    /// <summary>
    /// 熱血インプットで入力された値を元に、
    /// 移動・ダッシュ・ブレーキの状態を管理
    /// </summary>
    public void MoveMain(NekketsuSound NSound)
    {
        if (!NAct.NJumpV.squatFlag &&
            NAct.NAttackV.NowDamage == DamagePattern.None &&
            NAct.NAttackV.DamageRigidityFlag == false)
        {
            #region 歩き

            // もし、右キーが押されたら
            if (NAct.NMoveV.XInputState == XInputState.XRightPushMoment ||
                NAct.NMoveV.XInputState == XInputState.XRightPushButton)
            {
                if (!NAct.NMoveV.brakeFlag)
                {
                    NAct.NMoveV.leftFlag = false;
                }

                if (!NAct.NMoveV.dashFlag && !NAct.NJumpV.jumpFlag && !NAct.NMoveV.brakeFlag)
                {
                    NAct.NVariable.vx = NAct.NVariable.st_speed; // 右に歩く移動量を入れる
                }
            }
            // もし、左キーが押されたら ★else if でもキーボード同時押し対策NG★
            else if (NAct.NMoveV.XInputState == XInputState.XLeftPushMoment ||
                     NAct.NMoveV.XInputState == XInputState.XLeftPushButton)
            {
                if (!NAct.NMoveV.brakeFlag)
                {
                    NAct.NMoveV.leftFlag = true;
                }

                if (!NAct.NMoveV.dashFlag && !NAct.NJumpV.jumpFlag && !NAct.NMoveV.brakeFlag)
                {
                    NAct.NVariable.vx = -NAct.NVariable.st_speed; // 左に歩く移動量を入れる
                }
            }

            // もし、上キーが押されたら
            if (NAct.NMoveV.ZInputState == ZInputState.ZBackPushMoment ||
                NAct.NMoveV.ZInputState == ZInputState.ZBackPushButton)
            {
                if (!NAct.NJumpV.jumpFlag)
                {
                    NAct.NVariable.vz = NAct.NVariable.st_speed * Settings.Instance.Move.ZWalkSpeed; // 上に進む移動量を入れる(熱血っぽく奥行きは移動量小)
                }
            }
            // もし、下キーが押されたら
            else if (NAct.NMoveV.ZInputState == ZInputState.ZFrontPushMoment ||
                     NAct.NMoveV.ZInputState == ZInputState.ZFrontPushButton)
            {
                if (!NAct.NJumpV.jumpFlag)
                {
                    NAct.NVariable.vz = -NAct.NVariable.st_speed * Settings.Instance.Move.ZWalkSpeed; // 下に進む移動量を入れる(熱血っぽく奥行きは移動量小)
                }
            }

            #endregion

            #region ダッシュ

            if (!NAct.NMoveV.dashFlag)
            {
                // 非ダッシュ状態で、横移動し始めた瞬間か?
                if (NAct.NMoveV.XInputState == XInputState.XRightPushMoment ||
                    NAct.NMoveV.XInputState == XInputState.XLeftPushMoment)
                {
                    if (!pushMove)
                    {
                        //ダッシュしたい方向と同じ方向キーが押されている
                        if (XInputDashVector == NAct.NMoveV.XInputState)
                        {
                            //ダッシュの準備をする
                            pushMove    = true;
                            leftDash    = NAct.NMoveV.leftFlag;
                            nowTimeDash = 0;
                        }

                        //ダッシュしようとしている方向を覚えておく
                        XInputDashVector = NAct.NMoveV.XInputState;
                    }
                    else
                    {
                        // ダッシュ準備済なので、ダッシュしてよい状態か判断
                        if (canDash && !NAct.NJumpV.jumpFlag &&
                            leftDash == NAct.NMoveV.leftFlag &&
                            nowTimeDash <= NAct.NMoveV.nextButtonDownTimeDash)
                        {
                            NAct.NMoveV.dashFlag = true;
                        }
                    }
                }
                else
                {
                    // 非ダッシュ状態で、ダッシュ準備済か?
                    // 1度左右キーが押された状態で、ダッシュ受付時間内にもう一度左右キーが押された時
                    if (pushMove &&
                        !NAct.NMoveV.brakeFlag)
                    {
                        // 時間計測
                        nowTimeDash += Time.deltaTime;

                        if (nowTimeDash > NAct.NMoveV.nextButtonDownTimeDash)
                        {
                            pushMove         = false;
                            canDash          = false;
                            XInputDashVector = XInputState.XNone;
                        }
                        else
                        {
                            canDash = true;
                        }
                    }
                }
            }
            else
            {   //ダッシュ済の場合
                if (!NAct.NMoveV.brakeFlag)
                {
                    // ダッシュ中に逆方向を押した場合
                    if (leftDash != NAct.NMoveV.leftFlag)
                    {
                        // 逆方向の移動量を入れる
                        NAct.NVariable.vx = GetSign(NAct.NMoveV.leftFlag) * NAct.NVariable.st_speed * Settings.Instance.Move.DashSpeed;

                        NAct.NMoveV.dashFlag = false;
                        pushMove             = false;
                        canDash = false;

                        // ブレーキ状態
                        if (!NAct.NJumpV.jumpFlag)
                        {
                            NAct.NMoveV.brakeFlag = true;
                            NSound.SEPlay(SEPattern.brake);
                        }
                    }
                    else
                    {
                        // ダッシュの移動量を入れる
                        NAct.NVariable.vx = GetSign(NAct.NMoveV.leftFlag) * NAct.NVariable.st_speed * Settings.Instance.Move.DashSpeed;
                    }
                }
            }

            // ブレーキ処理
            if (!NAct.NJumpV.jumpFlag && NAct.NMoveV.brakeFlag)
            {
                // ブレーキ中の移動量を入れる
                NAct.NVariable.vx = GetSign(!NAct.NMoveV.leftFlag) * NAct.NVariable.st_speed * NAct.NVariable.st_brake;

                // ブレーキ状態の時間計測
                nowTimebrake += Time.deltaTime;

                // ブレーキ状態解除
                if (nowTimebrake > Settings.Instance.Move.BrakeTime)
                {
                    NAct.NMoveV.brakeFlag = false;
                    nowTimebrake          = 0;
                }
            }

            // ダッシュ入力受付中
            if (pushMove)
            {
                // 時間計測
                nowTimeDash += Time.deltaTime;

                if (nowTimeDash > NAct.NMoveV.nextButtonDownTimeDash)
                {
                    pushMove         = false;
                    canDash          = false;
                    XInputDashVector = XInputState.XNone;
                }
            }
            #endregion
        }
    }