BOOL CALLBACK EnumPeripheralsCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { if (GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_JOYSTICK) { #ifdef HAVE_XINPUT if (IsXInputDevice(&lpddi->guidProduct)) { dev_list[num_devices].lpDIDevice = NULL; dev_list[num_devices].is_xinput_device = TRUE; dev_list[num_devices].user_index=((int *)pvRef)[0]; ((int *)pvRef)[0]++; num_devices++; } else #endif { dev_list[num_devices].is_xinput_device = FALSE; if (SUCCEEDED(IDirectInput8_CreateDevice(lpDI8, &lpddi->guidInstance, &dev_list[num_devices].lpDIDevice, NULL) )) num_devices++; } } return DIENUM_CONTINUE; }
BOOL CALLBACK EnumSemanticsCallback //Callback function that receive DirectInput devices ( LPCDIDEVICEINSTANCE lpddi, //Adress of structure describing device instance LPDIRECTINPUTDEVICE8 lpdid, //Pointer to device interface DWORD dwFlags, //Flags telling why being enumerated DWORD dwRemaining, //Number of devices remaining to be enumerated LPVOID pvRef) //Application defined value. Always NULL here { HRESULT hr; if (GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_MOUSE || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_KEYBOARD ) return DIENUM_CONTINUE; printf("Device %s\n",lpddi->tszProductName); #define X(x) if (dwFlags & x) printf("\tdwFlags |= "#x"\n"); X(DIEDBS_MAPPEDPRI1) X(DIEDBS_MAPPEDPRI2) X(DIEDBS_RECENTDEVICE) X(DIEDBS_NEWDEVICE) #undef X hr = lpdid->BuildActionMap(&g_ActionFormat,NULL,DIDBAM_INITIALIZE); _dump_diactionformatA(&g_ActionFormat); return DIENUM_CONTINUE; }
BOOL CALLBACK EnumPeripheralsCallbackGamepad (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { if (GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_JOYSTICK || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_KEYBOARD) { SendMessage((HWND)pvRef, CB_ADDSTRING, 0, (LPARAM)lpddi->tszInstanceName); memcpy(&GUIDDevice[numguids], &lpddi->guidInstance, sizeof(GUID)); numguids++; } return DIENUM_CONTINUE; }
BOOL CALLBACK EnumPeripheralsCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { if (GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_JOYSTICK || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_KEYBOARD) { if (SUCCEEDED(IDirectInput8_CreateDevice(lpDI8, &lpddi->guidInstance, &lpDIDevice[numdevices], NULL) )) numdevices++; } return DIENUM_CONTINUE; }
/* device enumeration callback */ BOOL CALLBACK EnumDevCallback(const DIDEVICEINSTANCE *dev, VOID *ctx) { /* take the first joystick we get */ if (GET_DIDEVICE_TYPE(dev->dwDevType) == DI8DEVTYPE_JOYSTICK || GET_DIDEVICE_TYPE(dev->dwDevType) == DI8DEVTYPE_GAMEPAD) { struct DEVINFO *info = (struct DEVINFO *)ctx; info->productGuid = dev->guidProduct; info->deviceID = dev->guidInstance; info->vendor = dev->tszInstanceName; return DIENUM_STOP; } return DIENUM_CONTINUE; }
//----------------------------------------------------------------------------- // Name: InputAddDeviceCB() // Desc: Called from CMultiplayerInputDeviceManager whenever a device is added. // Set the dead zone, and creates a new InputDeviceState for each device //----------------------------------------------------------------------------- HRESULT CMyApplication::InputAddDeviceCB( CMultiplayerInputDeviceManager::PlayerInfo* pPlayerInfo, CMultiplayerInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi ) { if( (GET_DIDEVICE_TYPE(pdidi->dwDevType) != DI8DEVTYPE_KEYBOARD) && (GET_DIDEVICE_TYPE(pdidi->dwDevType) != DI8DEVTYPE_MOUSE) ) { // Setup the deadzone DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = 500; pDeviceInfo->pdidDevice->SetProperty( DIPROP_DEADZONE, &dipdw.diph ); } // Create a new InputDeviceState for each device so the // app can record its state InputDeviceState* pNewInputDeviceState = new InputDeviceState; ZeroMemory( pNewInputDeviceState, sizeof(InputDeviceState) ); pDeviceInfo->pParam = (LPVOID) pNewInputDeviceState; HWND hPlayerDevice; switch( pPlayerInfo->dwPlayerIndex ) { case 0: hPlayerDevice = GetDlgItem( m_hWnd, IDC_DEVICE_ASSIGNED_P1 ); break; case 1: hPlayerDevice = GetDlgItem( m_hWnd, IDC_DEVICE_ASSIGNED_P2 ); break; case 2: hPlayerDevice = GetDlgItem( m_hWnd, IDC_DEVICE_ASSIGNED_P3 ); break; case 3: hPlayerDevice = GetDlgItem( m_hWnd, IDC_DEVICE_ASSIGNED_P4 ); break; } SendMessage( hPlayerDevice, LB_ADDSTRING, 0, (LPARAM) pdidi->tszProductName ); return S_OK; }
BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE* instance, VOID* context) { HRESULT hr; LPDIRECTINPUTDEVICE8 lpdid; if (GET_DIDEVICE_TYPE(instance->dwDevType) == DI8DEVTYPE_MOUSE || GET_DIDEVICE_TYPE(instance->dwDevType) == DI8DEVTYPE_KEYBOARD ) return DIENUM_CONTINUE; hr = gp_DI->CreateDevice(instance->guidInstance, &lpdid, NULL); if(SUCCEEDED(hr)) { _dump_DIDEVICEINSTANCE(instance); printf("Objects:\n"); lpdid->EnumObjects(enumObjectsCallback, NULL, DIDFT_ALL); } else { printf("Error\n"); HRNAME(hr); } return DIENUM_CONTINUE; }
BOOL __stdcall enumCallbackDetour(const DIDEVICEINSTANCEA* instance, VOID* context) { BOOL result; unsigned int type = GET_DIDEVICE_TYPE(instance->dwDevType); unsigned int subtype = GET_DIDEVICE_SUBTYPE(instance->dwDevType); if (type == DI8DEVTYPE_1STPERSON && subtype == DI8DEVTYPE1STPERSON_SIXDOF) { if (SpoofControllerType) ((DIDEVICEINSTANCEA*)instance)->dwDevType = 0x10215; //DI8DEVTYPE_GAMEPAD | DI8DEVTYPEGAMEPAD_STANDARD } result = D3D9Hook_enumcallbck(instance, context); return result; }
static void ReportDevType( DWORD devType ) { byte baseType = GET_DIDEVICE_TYPE( devType ); byte subType = GET_DIDEVICE_SUBTYPE( devType ); switch ( baseType ) { default: DevMsg( "unknown type\n" ); break; case DI8DEVTYPE_DEVICE: DevMsg( "DEVICE\n" ); break; case DI8DEVTYPE_MOUSE: DevMsg( "MOUSE\n" ); switch ( subType ) { default: break; case DI8DEVTYPEMOUSE_UNKNOWN: DevMsg( "DI8DEVTYPEMOUSE_UNKNOWN\n" ); break; case DI8DEVTYPEMOUSE_TRADITIONAL: DevMsg( "DI8DEVTYPEMOUSE_TRADITIONAL\n" ); break; case DI8DEVTYPEMOUSE_FINGERSTICK: DevMsg( "DI8DEVTYPEMOUSE_FINGERSTICK\n" ); break; case DI8DEVTYPEMOUSE_TOUCHPAD: DevMsg( "DI8DEVTYPEMOUSE_TOUCHPAD\n" ); break; case DI8DEVTYPEMOUSE_TRACKBALL: DevMsg( "DI8DEVTYPEMOUSE_TRACKBALL\n" ); break; case DI8DEVTYPEMOUSE_ABSOLUTE: DevMsg( "DI8DEVTYPEMOUSE_ABSOLUTE\n" ); break; } break; case DI8DEVTYPE_KEYBOARD: DevMsg( "KEYBOARD\n" ); switch ( subType ) { default: break; case DI8DEVTYPEKEYBOARD_UNKNOWN: DevMsg( "DI8DEVTYPEKEYBOARD_UNKNOWN\n" ); break; case DI8DEVTYPEKEYBOARD_PCXT: DevMsg( "DI8DEVTYPEKEYBOARD_PCXT\n" ); break; case DI8DEVTYPEKEYBOARD_OLIVETTI: DevMsg( "DI8DEVTYPEKEYBOARD_OLIVETTI\n" ); break; case DI8DEVTYPEKEYBOARD_PCAT: DevMsg( "DI8DEVTYPEKEYBOARD_PCAT\n" ); break; case DI8DEVTYPEKEYBOARD_PCENH: DevMsg( "DI8DEVTYPEKEYBOARD_PCENH:\n" ); break; case DI8DEVTYPEKEYBOARD_NOKIA1050: DevMsg( "DI8DEVTYPEKEYBOARD_NOKIA1050\n" ); break; case DI8DEVTYPEKEYBOARD_NOKIA9140: DevMsg( "DI8DEVTYPEKEYBOARD_NOKIA9140\n" ); break; case DI8DEVTYPEKEYBOARD_NEC98: DevMsg( "DI8DEVTYPEKEYBOARD_NEC98\n" ); break; case DI8DEVTYPEKEYBOARD_NEC98LAPTOP: DevMsg( "DI8DEVTYPEKEYBOARD_NEC98LAPTOP\n" ); break; case DI8DEVTYPEKEYBOARD_NEC98106: DevMsg( "DI8DEVTYPEKEYBOARD_NEC98106\n" ); break; case DI8DEVTYPEKEYBOARD_JAPAN106: DevMsg( "DI8DEVTYPEKEYBOARD_JAPAN106\n" ); break; case DI8DEVTYPEKEYBOARD_JAPANAX: DevMsg( "DI8DEVTYPEKEYBOARD_JAPANAX\n" ); break; case DI8DEVTYPEKEYBOARD_J3100: DevMsg( "DI8DEVTYPEKEYBOARD_J3100\n" ); break; } break; case DI8DEVTYPE_JOYSTICK: DevMsg( "JOYSTICK\n" ); switch ( subType ) { default: break; case DI8DEVTYPEJOYSTICK_LIMITED : DevMsg( "DI8DEVTYPEJOYSTICK_LIMITED\n" ); break; case DI8DEVTYPEJOYSTICK_STANDARD: DevMsg( "DI8DEVTYPEJOYSTICK_STANDARD\n" ); break; } break; case DI8DEVTYPE_GAMEPAD: DevMsg( "GAMEPAD\n" ); switch ( subType ) { default: break; case DI8DEVTYPEGAMEPAD_LIMITED: DevMsg( "DI8DEVTYPEGAMEPAD_LIMITED\n" ); break; case DI8DEVTYPEGAMEPAD_STANDARD: DevMsg( "DI8DEVTYPEGAMEPAD_STANDARD\n" ); break; case DI8DEVTYPEGAMEPAD_TILT: DevMsg( "DI8DEVTYPEGAMEPAD_TILT\n" ); break; } break; case DI8DEVTYPE_DRIVING: DevMsg( "DRIVING\n" ); switch ( subType ) { default: break; case DI8DEVTYPEDRIVING_LIMITED: DevMsg( "DI8DEVTYPEDRIVING_LIMITED\n" ); break; case DI8DEVTYPEDRIVING_COMBINEDPEDALS: DevMsg( "DI8DEVTYPEDRIVING_COMBINEDPEDALS\n" ); break; case DI8DEVTYPEDRIVING_DUALPEDALS: DevMsg( "DI8DEVTYPEDRIVING_DUALPEDALS\n" ); break; case DI8DEVTYPEDRIVING_THREEPEDALS: DevMsg( "DI8DEVTYPEDRIVING_THREEPEDALS\n" ); break; case DI8DEVTYPEDRIVING_HANDHELD: DevMsg( "DI8DEVTYPEDRIVING_HANDHELD\n" ); break; } break; case DI8DEVTYPE_FLIGHT: DevMsg( "FLIGHT\n" ); switch ( subType ) { default: break; case DI8DEVTYPEFLIGHT_LIMITED: DevMsg( "DI8DEVTYPEFLIGHT_LIMITED\n" ); break; case DI8DEVTYPEFLIGHT_STICK: DevMsg( "DI8DEVTYPEFLIGHT_STICK\n" ); break; case DI8DEVTYPEFLIGHT_YOKE: DevMsg( "DI8DEVTYPEFLIGHT_YOKE\n" ); break; case DI8DEVTYPEFLIGHT_RC: DevMsg( "DI8DEVTYPEFLIGHT_RC\n" ); break; } break; case DI8DEVTYPE_1STPERSON: DevMsg( "1STPERSON\n" ); switch ( subType ) { default: break; case DI8DEVTYPE1STPERSON_LIMITED: DevMsg( "DI8DEVTYPE1STPERSON_LIMITED\n" ); break; case DI8DEVTYPE1STPERSON_UNKNOWN: DevMsg( "DI8DEVTYPE1STPERSON_UNKNOWN\n" ); break; case DI8DEVTYPE1STPERSON_SIXDOF: DevMsg( "DI8DEVTYPE1STPERSON_SIXDOF\n" ); break; case DI8DEVTYPE1STPERSON_SHOOTER: DevMsg( "DI8DEVTYPE1STPERSON_SHOOTER\n" ); break; } break; case DI8DEVTYPE_DEVICECTRL: DevMsg( "DEVICECTRL\n" ); switch ( subType ) { default: break; case DI8DEVTYPEDEVICECTRL_UNKNOWN: DevMsg( "DI8DEVTYPEDEVICECTRL_UNKNOWN\n" ); break; case DI8DEVTYPEDEVICECTRL_COMMSSELECTION: DevMsg( "DI8DEVTYPEDEVICECTRL_COMMSSELECTION\n" ); break; case DI8DEVTYPEDEVICECTRL_COMMSSELECTION_HARDWIRED: DevMsg( "DI8DEVTYPEDEVICECTRL_COMMSSELECTION_HARDWIRED\n" ); break; } break; case DI8DEVTYPE_SCREENPOINTER: DevMsg( "SCREENPOINTER\n" ); switch ( subType ) { default: break; case DI8DEVTYPESCREENPTR_UNKNOWN: DevMsg( "DI8DEVTYPESCREENPTR_UNKNOWN\n" ); break; case DI8DEVTYPESCREENPTR_LIGHTGUN: DevMsg( "DI8DEVTYPESCREENPTR_LIGHTGUN\n" ); break; case DI8DEVTYPESCREENPTR_LIGHTPEN: DevMsg( "DI8DEVTYPESCREENPTR_LIGHTPEN\n" ); break; case DI8DEVTYPESCREENPTR_TOUCH: DevMsg( "DI8DEVTYPESCREENPTR_TOUCH\n" ); break; } break; case DI8DEVTYPE_REMOTE: DevMsg( "REMOTE\n" ); switch ( subType ) { default: break; case DI8DEVTYPEREMOTE_UNKNOWN: DevMsg( "DI8DEVTYPEREMOTE_UNKNOWN\n" ); break; } break; case DI8DEVTYPE_SUPPLEMENTAL: DevMsg( "SUPPLEMENTAL\n" ); switch ( subType ) { default: break; case DI8DEVTYPESUPPLEMENTAL_UNKNOWN: DevMsg( "DI8DEVTYPESUPPLEMENTAL_UNKNOWN\n" ); break; case DI8DEVTYPESUPPLEMENTAL_2NDHANDCONTROLLER: DevMsg( "DI8DEVTYPESUPPLEMENTAL_2NDHANDCONTROLLER\n" ); break; case DI8DEVTYPESUPPLEMENTAL_HEADTRACKER: DevMsg( "DI8DEVTYPESUPPLEMENTAL_HEADTRACKER\n" ); break; case DI8DEVTYPESUPPLEMENTAL_HANDTRACKER: DevMsg( "DI8DEVTYPESUPPLEMENTAL_HANDTRACKER\n" ); break; case DI8DEVTYPESUPPLEMENTAL_SHIFTSTICKGATE: DevMsg( "DI8DEVTYPESUPPLEMENTAL_SHIFTSTICKGATE\n" ); break; case DI8DEVTYPESUPPLEMENTAL_SHIFTER: DevMsg( "DI8DEVTYPESUPPLEMENTAL_SHIFTER\n" ); break; case DI8DEVTYPESUPPLEMENTAL_THROTTLE: DevMsg( "DI8DEVTYPESUPPLEMENTAL_THROTTLE\n" ); break; case DI8DEVTYPESUPPLEMENTAL_SPLITTHROTTLE: DevMsg( "DI8DEVTYPESUPPLEMENTAL_SPLITTHROTTLE\n" ); break; case DI8DEVTYPESUPPLEMENTAL_COMBINEDPEDALS: DevMsg( "DI8DEVTYPESUPPLEMENTAL_COMBINEDPEDALS\n" ); break; case DI8DEVTYPESUPPLEMENTAL_DUALPEDALS: DevMsg( "DI8DEVTYPESUPPLEMENTAL_DUALPEDALS\n" ); break; case DI8DEVTYPESUPPLEMENTAL_THREEPEDALS: DevMsg( "DI8DEVTYPESUPPLEMENTAL_THREEPEDALS\n" ); break; case DI8DEVTYPESUPPLEMENTAL_RUDDERPEDALS: DevMsg( "DI8DEVTYPESUPPLEMENTAL_RUDDERPEDALS\n" ); break; } break; } }
int PERDXFetchNextPress(HWND hWnd, u32 guidnum, char *buttonname) { LPDIRECTINPUT8 lpDI8temp = NULL; LPDIRECTINPUTDEVICE8 lpDIDevicetemp; DIDEVCAPS didc; int buttonid=-1; if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8, (LPVOID *)&lpDI8temp, NULL))) return -1; if (FAILED(IDirectInput8_CreateDevice(lpDI8temp, &GUIDDevice[guidnum], &lpDIDevicetemp, NULL))) { IDirectInput8_Release(lpDI8temp); return -1; } didc.dwSize = sizeof(DIDEVCAPS); if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevicetemp, &didc))) { IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); return -1; } if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD) { if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevicetemp, &c_dfDIKeyboard))) { IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); return -1; } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK) { if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevicetemp, &c_dfDIJoystick))) { IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); return -1; } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE) { if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevicetemp, &c_dfDIMouse2))) { IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); return -1; } } if (DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_BUTTONCONFIG), hWnd, (DLGPROC)ButtonConfigDlgProc, (LPARAM)lpDIDevicetemp) == TRUE) { // Figure out what kind of code to generate if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD) { memset(buttonname, 0, MAX_PATH); buttonid = nextpress.dwOfs; // This fixes some strange inconsistencies if (buttonid == DIK_PAUSE) buttonid = DIK_NUMLOCK; else if (buttonid == DIK_NUMLOCK) buttonid = DIK_PAUSE; if (buttonid & 0x80) buttonid += 0x80; GetKeyNameTextA(buttonid << 16, buttonname, MAX_PATH); buttonid = nextpress.dwOfs; } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK) { if (nextpress.dwOfs == DIJOFS_X) { if (nextpress.dwData <= 0x8000) { sprintf(buttonname, "Axis Left"); buttonid = 0x00; } else { sprintf(buttonname, "Axis Right"); buttonid = 0x01; } } else if (nextpress.dwOfs == DIJOFS_Y) { if (nextpress.dwData <= 0x8000) { sprintf(buttonname, "Axis Up"); buttonid = 0x02; } else { sprintf(buttonname, "Axis Down"); buttonid = 0x03; } } else if (nextpress.dwOfs == DIJOFS_POV(0)) { if (nextpress.dwData < 9000) { sprintf(buttonname, "POV Up"); buttonid = 0x04; } else if (nextpress.dwData < 18000) { sprintf(buttonname, "POV Right"); buttonid = 0x05; } else if (nextpress.dwData < 27000) { sprintf(buttonname, "POV Down"); buttonid = 0x06; } else { sprintf(buttonname, "POV Left"); buttonid = 0x07; } } else if (nextpress.dwOfs >= DIJOFS_BUTTON(0) && nextpress.dwOfs <= DIJOFS_BUTTON(127)) { sprintf(buttonname, "Button %d", (int)(nextpress.dwOfs - 0x2F)); buttonid = nextpress.dwOfs; } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE) { buttonid = nextpress.dwOfs-DIMOFS_BUTTON0; sprintf(buttonname, "Button %d", buttonid+1); } } IDirectInputDevice8_Unacquire(lpDIDevicetemp); IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); return buttonid; }
int PERDXInitControlConfig(HWND hWnd, u8 padnum, int *controlmap, const char *inifilename) { char tempstr[MAX_PATH]; char string1[20]; GUID guid; u32 i; int idlist[] = { IDC_UPTEXT, IDC_RIGHTTEXT, IDC_DOWNTEXT, IDC_LEFTTEXT, IDC_RTEXT, IDC_LTEXT, IDC_STARTTEXT, IDC_ATEXT, IDC_BTEXT, IDC_CTEXT, IDC_XTEXT, IDC_YTEXT, IDC_ZTEXT }; sprintf(string1, "Peripheral%d%C", ((padnum/6)+1), 'A'+(padnum%6)); // Let's first fetch the guid of the device and see if we can get a match if (GetPrivateProfileStringA(string1, "GUID", "", tempstr, MAX_PATH, inifilename) == 0) { if (padnum == 0) { // Let's use default values SendDlgItemMessage(hWnd, IDC_DXDEVICECB, CB_SETCURSEL, 1, 0); controlmap[0] = DIK_UP; controlmap[1] = DIK_RIGHT; controlmap[2] = DIK_DOWN; controlmap[3] = DIK_LEFT; controlmap[4] = DIK_Z; controlmap[5] = DIK_X; controlmap[6] = DIK_J; controlmap[7] = DIK_K; controlmap[8] = DIK_L; controlmap[9] = DIK_M; controlmap[10] = DIK_U; controlmap[11] = DIK_I; controlmap[12] = DIK_O; for (i = 0; i < 13; i++) { ConvertKBIDToName(controlmap[i], tempstr); SetDlgItemText(hWnd, idlist[i], _16(tempstr)); } } else { SendDlgItemMessage(hWnd, IDC_DXDEVICECB, CB_SETCURSEL, 0, 0); return -1; } } else { LPDIRECTINPUT8 lpDI8temp = NULL; LPDIRECTINPUTDEVICE8 lpDIDevicetemp; DIDEVCAPS didc; int buttonid; StringToGUID(tempstr, &guid); // Let's find a match for (i = 0; i < numguids; i++) { if (memcmp(&guid, &GUIDDevice[i], sizeof(GUID)) == 0) { SendDlgItemMessage(hWnd, IDC_DXDEVICECB, CB_SETCURSEL, i+1, 0); break; } } if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8, (LPVOID *)&lpDI8temp, NULL))) return -1; if (FAILED(IDirectInput8_CreateDevice(lpDI8temp, &GUIDDevice[i], &lpDIDevicetemp, NULL))) { IDirectInput8_Release(lpDI8temp); return -1; } didc.dwSize = sizeof(DIDEVCAPS); if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevicetemp, &didc))) { IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); return -1; } if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD) { sprintf(string1, "Peripheral%d%C", ((padnum/6)+1), 'A'+(padnum%6)); for (i = 0; i < 13; i++) { buttonid = GetPrivateProfileIntA(string1, PerPadNames[i], 0, inifilename); printf("%2d: %d\n", i, buttonid); controlmap[i] = buttonid; ConvertKBIDToName(buttonid, tempstr); SetDlgItemText(hWnd, idlist[i], _16(tempstr)); } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK) { sprintf(string1, "Peripheral%d%C", ((padnum/6)+1), 'A'+(padnum%6)); for (i = 0; i < 13; i++) { buttonid = GetPrivateProfileIntA(string1, PerPadNames[i], 0, inifilename); controlmap[i] = buttonid; ConvertJoyIDToName(buttonid, tempstr); SetDlgItemText(hWnd, idlist[i], _16(tempstr)); } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE) { for (i = 0; i < 13; i++) { buttonid = GetPrivateProfileIntA(string1, PerPadNames[i], 0, inifilename); controlmap[i] = buttonid; ConvertMouseIDToName(buttonid, tempstr); SetDlgItemText(hWnd, idlist[i], _16(tempstr)); } } IDirectInputDevice8_Release(lpDIDevicetemp); IDirectInput8_Release(lpDI8temp); } return 0; }
void PERDXLoadDevices(char *inifilename) { char tempstr[MAX_PATH]; char string1[20]; char string2[20]; GUID guid; DIDEVCAPS didc; u32 i; int j, i2; int buttonid; DIPROPDWORD dipdw; int id; DWORD coopflags=DISCL_FOREGROUND | DISCL_NONEXCLUSIVE; BOOL loaddefault=TRUE; int numpads; HRESULT hr; if (!PERCore) return; PerPortReset(); memset(pad, 0, sizeof(pad)); // Check Connection Type if (GetPrivateProfileStringA("Input", "Port1Type", "", tempstr, MAX_PATH, inifilename) == 0) { // Check if it's using the old ini settings for peripherals if (GetPrivateProfileStringA("Peripheral1", "GUID", "", tempstr, MAX_PATH, inifilename) != 0) { // Convert to the newer type of settings for (i = 0; i < 2; i++) { sprintf(string1, "Port%dType", (int)i+1); WritePrivateProfileStringA("Input", string1, "1", inifilename); sprintf(string1, "Peripheral%d", (int)i+1); sprintf(string2, "Peripheral%dA", (int)i+1); if (GetPrivateProfileStringA(string1, "GUID", "", tempstr, MAX_PATH, inifilename)) WritePrivateProfileStringA(string2, "GUID", tempstr, inifilename); if (GetPrivateProfileStringA(string1, "EmulateType", "", tempstr, MAX_PATH, inifilename)) WritePrivateProfileStringA(string2, "EmulateType", tempstr, inifilename); for (i2 = 0; i2 < 13; i2++) { if (GetPrivateProfileStringA(string1, PerPadNames[i2], "", tempstr, MAX_PATH, inifilename)) WritePrivateProfileStringA(string2, PerPadNames[i2], tempstr, inifilename); } } // Remove old ini entries for (i = 0; i < 12; i++) { sprintf(string1, "Peripheral%d", (int)i+1); WritePrivateProfileStringA(string1, NULL, NULL, inifilename); } loaddefault = FALSE; } } else loaddefault = FALSE; if (loaddefault) { LoadDefaultPort1A(); return; } // Load new type settings for (i = 0; i < 2; i++) { sprintf(string1, "Port%dType", (int)i+1); if (GetPrivateProfileStringA("Input", string1, "", tempstr, MAX_PATH, inifilename) != 0) { porttype[i] = atoi(tempstr); switch(porttype[i]) { case 1: numpads = 1; break; case 2: numpads = 6; break; default: numpads = 0; break; } // Load new type settings for (j = 0; j < numpads; j++) { int padindex=(6*i)+j; padconf_struct *curdevice=&paddevice[padindex]; sprintf(string1, "Peripheral%d%C", (int)i+1, 'A' + j); // Let's first fetch the guid of the device if (GetPrivateProfileStringA(string1, "GUID", "", tempstr, MAX_PATH, inifilename) == 0) continue; if (GetPrivateProfileStringA(string1, "EmulateType", "0", string2, MAX_PATH, inifilename)) { curdevice->emulatetype = atoi(string2); if (curdevice->emulatetype == 0) continue; } if (curdevice->lpDIDevice) { // Free the default keyboard, etc. IDirectInputDevice8_Unacquire(curdevice->lpDIDevice); IDirectInputDevice8_Release(curdevice->lpDIDevice); } StringToGUID(tempstr, &guid); // Ok, now that we've got the GUID of the device, let's set it up if (FAILED(IDirectInput8_CreateDevice(lpDI8, &guid, &lpDIDevice[padindex], NULL) )) { curdevice->lpDIDevice = NULL; curdevice->emulatetype = 0; continue; } curdevice->lpDIDevice = lpDIDevice[padindex]; didc.dwSize = sizeof(DIDEVCAPS); if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevice[padindex], &didc) )) continue; if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD) { if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevice[padindex], &c_dfDIKeyboard) )) continue; curdevice->type = TYPE_KEYBOARD; coopflags |= DISCL_NOWINKEY; } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK) { if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevice[padindex], &c_dfDIJoystick2) )) continue; curdevice->type = TYPE_JOYSTICK; } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE) { if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevice[padindex], &c_dfDIMouse2) )) continue; curdevice->type = TYPE_MOUSE; coopflags = DISCL_FOREGROUND | DISCL_EXCLUSIVE; } hr = IDirectInputDevice8_SetCooperativeLevel(lpDIDevice[i], DXGetWindow(), coopflags); if (FAILED(hr)) continue; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = 8; // should be enough // Setup Buffered input if (FAILED(IDirectInputDevice8_SetProperty(lpDIDevice[padindex], DIPROP_BUFFERSIZE, &dipdw.diph))) continue; IDirectInputDevice8_Acquire(lpDIDevice[padindex]); switch(curdevice->emulatetype) { case 1: // Standard Pad id = PERPAD; break; case 2: // Analog Pad case 3: // Stunner case 5: // Keyboard id = 0; break; case 4: // Mouse id = PERMOUSE; break; default: break; } // Make sure we're added to the smpc list if (i == 0) pad[padindex] = PerAddPeripheral(&PORTDATA1, id); else pad[padindex] = PerAddPeripheral(&PORTDATA2, id); // Now that we're all setup, let's fetch the controls from the ini if (curdevice->emulatetype != 3 && curdevice->emulatetype != 4) { for (i2 = 0; i2 < 13; i2++) { buttonid = GetPrivateProfileIntA(string1, PerPadNames[i2], 0, inifilename); PerSetKey(buttonid, i2, pad[padindex]); } } else if (curdevice->emulatetype == 4) { for (i2 = 0; i2 < 4; i2++) { buttonid = GetPrivateProfileIntA(string1, mouse_names[i2], 0, inifilename); PerSetKey(buttonid, PERMOUSE_LEFT+i2, pad[padindex]); } } } } } }
LRESULT CALLBACK ButtonConfigDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static LPDIRECTINPUTDEVICE8 lpDIDevicetemp; DIPROPDWORD dipdw; HRESULT hr; DWORD size; DIDEVICEOBJECTDATA didod[8]; DWORD i; DIDEVCAPS didc; switch (uMsg) { case WM_INITDIALOG: { lpDIDevicetemp = (LPDIRECTINPUTDEVICE8)lParam; if (FAILED(IDirectInputDevice8_SetCooperativeLevel(lpDIDevicetemp, hDlg, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE | DISCL_NOWINKEY))) return FALSE; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = 8; // should be enough // Setup Buffered input if (FAILED((hr = IDirectInputDevice8_SetProperty(lpDIDevicetemp, DIPROP_BUFFERSIZE, &dipdw.diph)))) return FALSE; if (!SetTimer(hDlg, 1, 100, NULL)) return FALSE; PostMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDC_WAITINPUT), TRUE); hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHook, GetModuleHandle(NULL), GetCurrentThreadId()); return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_CUSTOMCANCEL: { EndDialog(hDlg, FALSE); return TRUE; } default: break; } break; } case WM_TIMER: { size = 8; if (wParam == 1) { memset(&didod, 0, sizeof(DIDEVICEOBJECTDATA) * 8); // Let's see if there's any data waiting hr = IDirectInputDevice8_Poll(lpDIDevicetemp); if (FAILED(hr)) { if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) { // Make sure device is acquired while(IDirectInputDevice8_Acquire(lpDIDevicetemp) == DIERR_INPUTLOST) {} return TRUE; } } // Poll events if (FAILED(IDirectInputDevice8_GetDeviceData(lpDIDevicetemp, sizeof(DIDEVICEOBJECTDATA), didod, &size, 0))) { if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) { // Make sure device is acquired while(IDirectInputDevice8_Acquire(lpDIDevicetemp) == DIERR_INPUTLOST) {} return TRUE; } } didc.dwSize = sizeof(DIDEVCAPS); if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevicetemp, &didc))) return TRUE; if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD) { for (i = 0; i < size; i++) { if (didod[i].dwData & 0x80) { // We're done. time to bail EndDialog(hDlg, TRUE); memcpy(&nextpress, &didod[i], sizeof(DIDEVICEOBJECTDATA)); break; } } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK) { for (i = 0; i < size; i++) { if (didod[i].dwOfs == 0 || didod[i].dwOfs == 4) { if (didod[i].dwData <= 0x1000 || didod[i].dwData >= 0xF000) { // We're done. time to bail EndDialog(hDlg, TRUE); memcpy(&nextpress, &didod[i], sizeof(DIDEVICEOBJECTDATA)); break; } } else if (didod[i].dwOfs == 0x20) { if (((int)didod[i].dwData) >= 0) { // We're done. time to bail EndDialog(hDlg, TRUE); memcpy(&nextpress, &didod[i], sizeof(DIDEVICEOBJECTDATA)); } } else if (didod[i].dwOfs >= 0x30) { if (didod[i].dwData & 0x80) { // We're done. time to bail EndDialog(hDlg, TRUE); memcpy(&nextpress, &didod[i], sizeof(DIDEVICEOBJECTDATA)); break; } } } } else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE) { for (i = 0; i < size; i++) { // Make sure it's a button press if (didod[i].dwOfs >= DIMOFS_BUTTON0 && didod[i].dwOfs <= DIMOFS_BUTTON7) { if (didod[i].dwData & 0x80) { EndDialog(hDlg, TRUE); memcpy(&nextpress, &didod[i], sizeof(DIDEVICEOBJECTDATA)); break; } } } } return TRUE; } return FALSE; } case WM_DESTROY: { KillTimer(hDlg, 1); UnhookWindowsHookEx(hook); break; } } return FALSE; }