mirror of https://github.com/PCSX2/pcsx2.git
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:
parent
a2a1d58b4b
commit
1d2ae02c97
|
@ -105,12 +105,14 @@ struct Stick {
|
||||||
int vert;
|
int vert;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Sum of states of all controls for a pad (Not including toggles).
|
||||||
struct ButtonSum {
|
struct ButtonSum {
|
||||||
int buttons[12];
|
int buttons[12];
|
||||||
Stick sticks[3];
|
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 {
|
struct PadFreezeData {
|
||||||
// Digital / Analog / DS2 Native
|
// Digital / Analog / DS2 Native
|
||||||
u8 mode;
|
u8 mode;
|
||||||
|
@ -129,9 +131,14 @@ struct PadFreezeData {
|
||||||
|
|
||||||
class Pad : public PadFreezeData {
|
class Pad : public PadFreezeData {
|
||||||
public:
|
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
|
// Last vibration value. Only used so as not to call vibration
|
||||||
// functions when old and new values are both 0.
|
// functions when old and new values are both 0.
|
||||||
|
|
|
@ -249,64 +249,74 @@ int InitializeRawInput() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnumRawInputDevices() {
|
void EnumRawInputDevices() {
|
||||||
UINT count = 0;
|
int count = 0;
|
||||||
if (InitializeRawInput() && pGetRawInputDeviceList(0, &count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1) {
|
if (InitializeRawInput() && pGetRawInputDeviceList(0, (unsigned int*)&count, sizeof(RAWINPUTDEVICELIST)) && count > 0) {
|
||||||
wchar_t *instanceID = (wchar_t *) malloc(41000*sizeof(wchar_t));
|
wchar_t *instanceID = (wchar_t *) malloc(41000*sizeof(wchar_t));
|
||||||
wchar_t *keyName = instanceID + 11000;
|
wchar_t *keyName = instanceID + 11000;
|
||||||
wchar_t *displayName = keyName + 10000;
|
wchar_t *displayName = keyName + 10000;
|
||||||
wchar_t *productID = displayName + 10000;
|
wchar_t *productID = displayName + 10000;
|
||||||
|
|
||||||
|
RAWINPUTDEVICELIST *list = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * count);
|
||||||
int keyboardCount = 1;
|
int keyboardCount = 1;
|
||||||
int mouseCount = 1;
|
int mouseCount = 1;
|
||||||
if (count) {
|
count = pGetRawInputDeviceList(list, (unsigned int*)&count, sizeof(RAWINPUTDEVICELIST));
|
||||||
RAWINPUTDEVICELIST *list = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * count);
|
|
||||||
if (list && pGetRawInputDeviceList(list, &count, sizeof(RAWINPUTDEVICELIST))) {
|
// Not necessary, but reminder that count is -1 on failure.
|
||||||
for (UINT i=0; i<count; i++) {
|
if (count > 0) {
|
||||||
UINT nameLen = 10000;
|
for (int i=0; i<count; i++) {
|
||||||
if ((int)pGetRawInputDeviceInfo(list[i].hDevice, RIDI_DEVICENAME, instanceID, &nameLen) > 0 &&
|
if (list[i].dwType != RIM_TYPEKEYBOARD && list[i].dwType != RIM_TYPEMOUSE) continue;
|
||||||
nameLen >= 3) {
|
|
||||||
wcscpy(productID, instanceID);
|
UINT bufferLen = 10000;
|
||||||
wchar_t *temp = 0;
|
int nameLen = pGetRawInputDeviceInfo(list[i].hDevice, RIDI_DEVICENAME, instanceID, &bufferLen);
|
||||||
for (int j=0; j<3; j++) {
|
if (nameLen >= 4) {
|
||||||
wchar_t *s = wcschr(productID, '#');
|
// nameLen includes terminating null.
|
||||||
if (!s) break;
|
nameLen--;
|
||||||
*s = '\\';
|
|
||||||
if (j==2) {
|
// Strip out GUID parts of instanceID to make it a generic product id,
|
||||||
*s = 0;
|
// and reformat it to point to registry entry containing device description.
|
||||||
}
|
wcscpy(productID, instanceID);
|
||||||
if (j==1) temp = s;
|
wchar_t *temp = 0;
|
||||||
}
|
for (int j=0; j<3; j++) {
|
||||||
wsprintfW(keyName, L"SYSTEM\\CurrentControlSet\\Enum%s", productID+3);
|
wchar_t *s = wcschr(productID, '#');
|
||||||
if (temp) *temp = 0;
|
if (!s) break;
|
||||||
displayName[0] = 0;
|
*s = '\\';
|
||||||
HKEY hKey;
|
if (j==2) {
|
||||||
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey)) {
|
*s = 0;
|
||||||
DWORD type;
|
}
|
||||||
DWORD len = 10000 * sizeof(wchar_t);
|
if (j==1) temp = s;
|
||||||
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE*)displayName, &len) &&
|
}
|
||||||
len && type == REG_SZ) {
|
|
||||||
wchar_t *temp2 = wcsrchr(displayName, ';');
|
wsprintfW(keyName, L"SYSTEM\\CurrentControlSet\\Enum%s", productID+3);
|
||||||
if (!temp2) temp2 = displayName;
|
if (temp) *temp = 0;
|
||||||
else temp2++;
|
displayName[0] = 0;
|
||||||
// Could do without this, but more effort than it's worth.
|
HKEY hKey;
|
||||||
wcscpy(keyName, temp2);
|
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey)) {
|
||||||
}
|
DWORD type;
|
||||||
RegCloseKey(hKey);
|
DWORD len = 10000 * sizeof(wchar_t);
|
||||||
}
|
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE*)displayName, &len) &&
|
||||||
if (list[i].dwType == RIM_TYPEKEYBOARD) {
|
len && type == REG_SZ) {
|
||||||
if (!displayName[0]) wsprintfW(displayName, L"Raw Keyboard %i", keyboardCount++);
|
wchar_t *temp2 = wcsrchr(displayName, ';');
|
||||||
else wsprintfW(displayName, L"Raw KB: %s", keyName);
|
if (!temp2) temp2 = displayName;
|
||||||
dm->AddDevice(new RawInputKeyboard(list[i].hDevice, displayName, instanceID));
|
else temp2++;
|
||||||
}
|
// Could do without this, but more effort than it's worth.
|
||||||
else if (list[i].dwType == RIM_TYPEMOUSE) {
|
wcscpy(keyName, temp2);
|
||||||
if (!displayName[0]) wsprintfW(displayName, L"Raw Mouse %i", mouseCount++);
|
}
|
||||||
else wsprintfW(displayName, L"Raw MS: %s", keyName);
|
RegCloseKey(hKey);
|
||||||
dm->AddDevice(new RawInputMouse(list[i].hDevice, displayName, instanceID, productID));
|
}
|
||||||
}
|
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);
|
free(instanceID);
|
||||||
dm->AddDevice(new RawInputKeyboard(0, L"Simulated Keyboard"));
|
dm->AddDevice(new RawInputKeyboard(0, L"Simulated Keyboard"));
|
||||||
dm->AddDevice(new RawInputMouse(0, L"Simulated Mouse"));
|
dm->AddDevice(new RawInputMouse(0, L"Simulated Mouse"));
|
||||||
|
|
Loading…
Reference in New Issue