Transplanted XInput2 code from jquake