LilyPad: More minor fixes to failure detection in raw input initialization code. Gabest already fixed the big one.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1013 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
mattmenke 2009-04-19 03:33:32 +00:00
parent a2a1d58b4b
commit 1d2ae02c97
2 changed files with 68 additions and 51 deletions

View File

@ -105,12 +105,14 @@ struct Stick {
int vert;
};
// Sum of states of all controls for a pad (Not including toggles).
struct ButtonSum {
int buttons[12];
Stick sticks[3];
};
// Freeze data, for a single pad.
// Freeze data, for a single pad. Basically has all pad state that
// a PS2 can set.
struct PadFreezeData {
// Digital / Analog / DS2 Native
u8 mode;
@ -129,9 +131,14 @@ struct PadFreezeData {
class Pad : public PadFreezeData {
public:
ButtonSum sum, lockedSum;
// Current pad state.
ButtonSum sum;
// State of locked buttons. Already included by sum, used
// as initial value of sum.
ButtonSum lockedSum;
int lockedState;
// Flags for which controls (buttons or axes) are locked, if any.
DWORD lockedState;
// Last vibration value. Only used so as not to call vibration
// functions when old and new values are both 0.

View File

@ -249,21 +249,31 @@ int InitializeRawInput() {
}
void EnumRawInputDevices() {
UINT count = 0;
if (InitializeRawInput() && pGetRawInputDeviceList(0, &count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1) {
int count = 0;
if (InitializeRawInput() && pGetRawInputDeviceList(0, (unsigned int*)&count, sizeof(RAWINPUTDEVICELIST)) && count > 0) {
wchar_t *instanceID = (wchar_t *) malloc(41000*sizeof(wchar_t));
wchar_t *keyName = instanceID + 11000;
wchar_t *displayName = keyName + 10000;
wchar_t *productID = displayName + 10000;
RAWINPUTDEVICELIST *list = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * count);
int keyboardCount = 1;
int mouseCount = 1;
if (count) {
RAWINPUTDEVICELIST *list = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * count);
if (list && pGetRawInputDeviceList(list, &count, sizeof(RAWINPUTDEVICELIST))) {
for (UINT i=0; i<count; i++) {
UINT nameLen = 10000;
if ((int)pGetRawInputDeviceInfo(list[i].hDevice, RIDI_DEVICENAME, instanceID, &nameLen) > 0 &&
nameLen >= 3) {
count = pGetRawInputDeviceList(list, (unsigned int*)&count, sizeof(RAWINPUTDEVICELIST));
// Not necessary, but reminder that count is -1 on failure.
if (count > 0) {
for (int i=0; i<count; i++) {
if (list[i].dwType != RIM_TYPEKEYBOARD && list[i].dwType != RIM_TYPEMOUSE) continue;
UINT bufferLen = 10000;
int nameLen = pGetRawInputDeviceInfo(list[i].hDevice, RIDI_DEVICENAME, instanceID, &bufferLen);
if (nameLen >= 4) {
// nameLen includes terminating null.
nameLen--;
// Strip out GUID parts of instanceID to make it a generic product id,
// and reformat it to point to registry entry containing device description.
wcscpy(productID, instanceID);
wchar_t *temp = 0;
for (int j=0; j<3; j++) {
@ -275,6 +285,7 @@ void EnumRawInputDevices() {
}
if (j==1) temp = s;
}
wsprintfW(keyName, L"SYSTEM\\CurrentControlSet\\Enum%s", productID+3);
if (temp) *temp = 0;
displayName[0] = 0;
@ -304,9 +315,8 @@ void EnumRawInputDevices() {
}
}
}
}
free(list);
}
}
free(instanceID);
dm->AddDevice(new RawInputKeyboard(0, L"Simulated Keyboard"));
dm->AddDevice(new RawInputMouse(0, L"Simulated Mouse"));