예제 #1
0
 private void UpdateViewer()
 {
     while (true)
     {
         try {
             bool skipSleep = false;
             if (memory.HookProcess())
             {
                 GamepadState state      = memory.GamePadState();
                 Actions      newActions = Actions.None;
                 newActions |= state.DPad.Up ? Actions.Up : Actions.None;
                 newActions |= state.DPad.Down ? Actions.Down : Actions.None;
                 newActions |= state.DPad.Left ? Actions.Left : Actions.None;
                 newActions |= state.DPad.Right ? Actions.Right : Actions.None;
                 newActions |= state.Buttons.A ? Actions.Jump1 : Actions.None;
                 newActions |= state.Buttons.B ? Actions.Dash1 : Actions.None;
                 newActions |= state.Buttons.Y ? Actions.Jump2 : Actions.None;
                 newActions |= state.Buttons.X ? Actions.Dash2 : Actions.None;
                 newActions |= state.Buttons.RightShoulder || state.Triggers.Right > 0.5 ? Actions.RightBumper : Actions.None;
                 newActions |= state.Buttons.LeftShoulder || state.Triggers.Left > 0.5 ? Actions.LeftBumper : Actions.None;
                 newActions |= state.Buttons.Start ? Actions.Start : Actions.None;
                 newActions |= state.Buttons.Back ? Actions.Select : Actions.None;
                 int newDirection = 0;
                 if (state.ThumbSticks.LeftX != 0 || state.ThumbSticks.LeftY != 0)
                 {
                     newActions  |= Actions.Analog;
                     newDirection = (int)(Math.Atan2(state.ThumbSticks.LeftX, state.ThumbSticks.LeftY) * 180 / Math.PI);
                     if (newDirection < 0)
                     {
                         newDirection += 360;
                     }
                 }
                 if (actions != newActions || newDirection != direction)
                 {
                     actions   = newActions;
                     direction = newDirection;
                     skipSleep = true;
                     Invoke((Action)Refresh);
                 }
             }
             if (!skipSleep)
             {
                 Thread.Sleep(10);
             }
         } catch { }
     }
 }
예제 #2
0
        public GamepadState GamePadState()
        {
            GamepadState state = new GamepadState();

            for (int i = 0; i < 4; i++)
            {
                IntPtr pad      = (IntPtr)MInput.Read <uint>(Program, MInput.Version == PointerVersion.XNA ? 0x8 : 0x0, 0x8 + (i * 4));
                bool   attached = Program.Read <bool>(pad, 0x10);
                if (attached)
                {
                    if (MInput.Version == PointerVersion.XNA)
                    {
                        byte[] data = Program.Read(pad, 0x60, 0x80);
                        state.IsConnected  = true;
                        state.PacketNumber = BitConverter.ToInt32(data, 0x4);

                        state.ThumbSticks.LeftX  = BitConverter.ToSingle(data, 0x8);
                        state.ThumbSticks.LeftY  = BitConverter.ToSingle(data, 0xc);
                        state.ThumbSticks.RightX = BitConverter.ToSingle(data, 0x10);
                        state.ThumbSticks.RightY = BitConverter.ToSingle(data, 0x14);

                        state.Triggers.Left  = BitConverter.ToSingle(data, 0x18);
                        state.Triggers.Right = BitConverter.ToSingle(data, 0x1c);

                        state.Buttons.A             = BitConverter.ToInt32(data, 0x20) != 0;
                        state.Buttons.B             = BitConverter.ToInt32(data, 0x24) != 0;
                        state.Buttons.X             = BitConverter.ToInt32(data, 0x28) != 0;
                        state.Buttons.Y             = BitConverter.ToInt32(data, 0x2c) != 0;
                        state.Buttons.LeftStick     = BitConverter.ToInt32(data, 0x30) != 0;
                        state.Buttons.RightStick    = BitConverter.ToInt32(data, 0x34) != 0;
                        state.Buttons.LeftShoulder  = BitConverter.ToInt32(data, 0x38) != 0;
                        state.Buttons.RightShoulder = BitConverter.ToInt32(data, 0x3c) != 0;
                        state.Buttons.Back          = BitConverter.ToInt32(data, 0x40) != 0;
                        state.Buttons.Start         = BitConverter.ToInt32(data, 0x44) != 0;
                        state.Buttons.BigButton     = BitConverter.ToInt32(data, 0x48) != 0;

                        state.DPad.Up    = BitConverter.ToInt32(data, 0x4c) != 0;
                        state.DPad.Right = BitConverter.ToInt32(data, 0x50) != 0;
                        state.DPad.Down  = BitConverter.ToInt32(data, 0x54) != 0;
                        state.DPad.Left  = BitConverter.ToInt32(data, 0x58) != 0;
                    }
                    else
                    {
                        byte[] data = Program.Read(pad, 0x34, 0x48);
                        state.IsConnected  = true;
                        state.PacketNumber = BitConverter.ToInt32(data, 0x4);

                        int buttons = BitConverter.ToInt32(data, 0x8);
                        state.Buttons.A             = (buttons & 4096) != 0;
                        state.Buttons.B             = (buttons & 8192) != 0;
                        state.Buttons.X             = (buttons & 16384) != 0;
                        state.Buttons.Y             = (buttons & 32768) != 0;
                        state.Buttons.LeftStick     = (buttons & 64) != 0;
                        state.Buttons.RightStick    = (buttons & 128) != 0;
                        state.Buttons.LeftShoulder  = (buttons & 256) != 0;
                        state.Buttons.RightShoulder = (buttons & 512) != 0;
                        state.Buttons.Back          = (buttons & 32) != 0;
                        state.Buttons.Start         = (buttons & 16) != 0;
                        state.Buttons.BigButton     = (buttons & 2048) != 0;

                        state.DPad.Up    = (buttons & 1) != 0;
                        state.DPad.Down  = (buttons & 2) != 0;
                        state.DPad.Left  = (buttons & 4) != 0;
                        state.DPad.Right = (buttons & 8) != 0;

                        state.ThumbSticks.LeftX  = BitConverter.ToSingle(data, 0x1c);
                        state.ThumbSticks.LeftY  = BitConverter.ToSingle(data, 0x20);
                        state.ThumbSticks.RightX = BitConverter.ToSingle(data, 0x24);
                        state.ThumbSticks.RightY = BitConverter.ToSingle(data, 0x28);

                        state.Triggers.Left  = BitConverter.ToSingle(data, 0x2c);
                        state.Triggers.Right = BitConverter.ToSingle(data, 0x30);
                    }
                    break;
                }
            }
            return(state);
        }