Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #define X_INPUT_GET_STATE(name) DWORD WINAPI name(DWORD dwUserIndex, XINPUT_STATE *pState)
  2. typedef X_INPUT_GET_STATE(x_input_get_state);
  3. X_INPUT_GET_STATE(XInputGetStateStub)
  4. {
  5. return(0);
  6. }
  7. global_variable x_input_get_state *XInputGetState_ = XInputGetStateStub;
  8. #define XInputGetState XInputGetState_
  9.  
  10. #define X_INPUT_SET_STATE(name) DWORD WINAPI name(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration)
  11. typedef X_INPUT_SET_STATE(x_input_set_state);
  12. X_INPUT_SET_STATE(XInputSetStateStub)
  13. {
  14. return(0);
  15. }
  16. global_variable x_input_set_state *XInputSetState_ = XInputSetStateStub;
  17. #define XInputSetState XInputSetState_
  18.  
  19. internal void
  20. Win32LoadXInput(void)
  21. {
  22. HMODULE XInputLibrary = LoadLibraryA("xinput1_3.dll");
  23. if(XInputLibrary)
  24. {
  25. XInputGetState = (x_input_get_state *)GetProcAddress(XInputLibrary, "XInputGetState");
  26. XInputSetState = (x_input_set_state *)GetProcAddress(XInputLibrary, "XInputSetState");
  27. }
  28. }
  29.  
  30. ...
  31.  
  32. int CALLBACK
  33. WinMain(HINSTANCE Instance,
  34. HINSTANCE PrevInstance,
  35. LPSTR CommandLine,
  36. int ShowCode)
  37. {
  38. Win32LoadXInput();
  39.  
  40. ...
  41.  
  42.  
  43. for(DWORD ControllerIndex = 0; ControllerIndex < XUSER_MAX_COUNT; ++ControllerIndex)
  44. {
  45. XINPUT_STATE ControllerState;
  46. if(XInputGetState(ControllerIndex, &ControllerState) == ERROR_SUCCESS)
  47. {
  48. //NOTE: Controller plugged in
  49. XINPUT_GAMEPAD *Pad = &ControllerState.Gamepad;
  50.  
  51. bool Up = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_UP);
  52. bool Down = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
  53. bool Left = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
  54. bool Right = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
  55. bool Start = (Pad->wButtons & XINPUT_GAMEPAD_START);
  56. bool Back = (Pad->wButtons & XINPUT_GAMEPAD_BACK);
  57. bool LeftShoulder = (Pad->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
  58. bool RightShoulder = (Pad->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
  59. bool AButton = (Pad->wButtons & XINPUT_GAMEPAD_A);
  60. bool BButton = (Pad->wButtons & XINPUT_GAMEPAD_B);
  61. bool XButton = (Pad->wButtons & XINPUT_GAMEPAD_X);
  62. bool YButton = (Pad->wButtons & XINPUT_GAMEPAD_Y);
  63.  
  64. int16 StickX = Pad->sThumbLX;
  65. int16 StickY = Pad->sThumbLY;
  66.  
  67. if(AButton)
  68. {
  69. YOffset += 2;
  70. }
  71.  
  72. }
  73.  
  74. else
  75. {
  76. //NOTE: Controller not plugged in
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement