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,64 +249,74 @@ 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) {
wcscpy(productID, instanceID);
wchar_t *temp = 0;
for (int j=0; j<3; j++) {
wchar_t *s = wcschr(productID, '#');
if (!s) break;
*s = '\\';
if (j==2) {
*s = 0;
}
if (j==1) temp = s;
}
wsprintfW(keyName, L"SYSTEM\\CurrentControlSet\\Enum%s", productID+3);
if (temp) *temp = 0;
displayName[0] = 0;
HKEY hKey;
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey)) {
DWORD type;
DWORD len = 10000 * sizeof(wchar_t);
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE*)displayName, &len) &&
len && type == REG_SZ) {
wchar_t *temp2 = wcsrchr(displayName, ';');
if (!temp2) temp2 = displayName;
else temp2++;
// Could do without this, but more effort than it's worth.
wcscpy(keyName, temp2);
}
RegCloseKey(hKey);
}
if (list[i].dwType == RIM_TYPEKEYBOARD) {
if (!displayName[0]) wsprintfW(displayName, L"Raw Keyboard %i", keyboardCount++);
else wsprintfW(displayName, L"Raw KB: %s", keyName);
dm->AddDevice(new RawInputKeyboard(list[i].hDevice, displayName, instanceID));
}
else if (list[i].dwType == RIM_TYPEMOUSE) {
if (!displayName[0]) wsprintfW(displayName, L"Raw Mouse %i", mouseCount++);
else wsprintfW(displayName, L"Raw MS: %s", keyName);
dm->AddDevice(new RawInputMouse(list[i].hDevice, displayName, instanceID, productID));
}
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++) {
wchar_t *s = wcschr(productID, '#');
if (!s) break;
*s = '\\';
if (j==2) {
*s = 0;
}
if (j==1) temp = s;
}
wsprintfW(keyName, L"SYSTEM\\CurrentControlSet\\Enum%s", productID+3);
if (temp) *temp = 0;
displayName[0] = 0;
HKEY hKey;
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey)) {
DWORD type;
DWORD len = 10000 * sizeof(wchar_t);
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE*)displayName, &len) &&
len && type == REG_SZ) {
wchar_t *temp2 = wcsrchr(displayName, ';');
if (!temp2) temp2 = displayName;
else temp2++;
// Could do without this, but more effort than it's worth.
wcscpy(keyName, temp2);
}
RegCloseKey(hKey);
}
if (list[i].dwType == RIM_TYPEKEYBOARD) {
if (!displayName[0]) wsprintfW(displayName, L"Raw Keyboard %i", keyboardCount++);
else wsprintfW(displayName, L"Raw KB: %s", keyName);
dm->AddDevice(new RawInputKeyboard(list[i].hDevice, displayName, instanceID));
}
else if (list[i].dwType == RIM_TYPEMOUSE) {
if (!displayName[0]) wsprintfW(displayName, L"Raw Mouse %i", mouseCount++);
else wsprintfW(displayName, L"Raw MS: %s", keyName);
dm->AddDevice(new RawInputMouse(list[i].hDevice, displayName, instanceID, productID));
}
}
free(list);
}
}
free(list);
free(instanceID);
dm->AddDevice(new RawInputKeyboard(0, L"Simulated Keyboard"));
dm->AddDevice(new RawInputMouse(0, L"Simulated Mouse"));