/* * Opens the haptic device from the file descriptor. * * Steps: * - Open temporary DirectInputDevice interface. * - Create DirectInputDevice8 interface. * - Release DirectInputDevice interface. * - Call SDL_SYS_HapticOpenFromDevice8 */ static int SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance) { HRESULT ret; int ret2; LPDIRECTINPUTDEVICE8 device; LPDIRECTINPUTDEVICE8 device8; /* Open the device */ ret = IDirectInput8_CreateDevice(dinput, &instance.guidInstance, &device, NULL); if (FAILED(ret)) { DI_SetError("Creating DirectInput device", ret); return -1; } /* Now get the IDirectInputDevice8 interface, instead. */ ret = IDirectInputDevice8_QueryInterface(device, &IID_IDirectInputDevice8, (LPVOID *) &device8); /* Done with the temporary one now. */ IDirectInputDevice8_Release(device); if (FAILED(ret)) { DI_SetError("Querying DirectInput interface", ret); return -1; } ret2 = SDL_SYS_HapticOpenFromDevice8(haptic, device8, SDL_FALSE); if (ret2 < 0) { IDirectInputDevice8_Release(device8); return -1; } return 0; }
int SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item) { HRESULT ret; LPDIRECTINPUTDEVICE8 device; LPDIRECTINPUTDEVICE8 device8; /* Open the device */ ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance, &device, NULL); if (FAILED(ret)) { DI_SetError("Creating DirectInput device", ret); return -1; } /* Now get the IDirectInputDevice8 interface, instead. */ ret = IDirectInputDevice8_QueryInterface(device, &IID_IDirectInputDevice8, (LPVOID *)&device8); /* Done with the temporary one now. */ IDirectInputDevice8_Release(device); if (FAILED(ret)) { DI_SetError("Querying DirectInput interface", ret); return -1; } if (SDL_DINPUT_HapticOpenFromDevice(haptic, device8, SDL_FALSE) < 0) { IDirectInputDevice8_Release(device8); return -1; } return 0; }
static void dinput_free(void *data) { struct dinput_input *di = (struct dinput_input*)data; LPDIRECTINPUT8 hold_ctx = g_dinput_ctx; if (di) { /* Prevent a joypad driver to kill our context prematurely. */ g_dinput_ctx = NULL; if (di->joypad) di->joypad->destroy(); g_dinput_ctx = hold_ctx; /* Clear any leftover pointers. */ dinput_clear_pointers(di); if (di->keyboard) IDirectInputDevice8_Release(di->keyboard); if (di->mouse) IDirectInputDevice8_Release(di->mouse); free(di); } dinput_destroy_context(); }
/* * Closes the haptic device. */ void SDL_SYS_HapticClose(SDL_Haptic * haptic) { if (haptic->hwdata) { /* Free effects. */ SDL_free(haptic->effects); haptic->effects = NULL; haptic->neffects = 0; /* Clean up */ if (haptic->hwdata->bXInputHaptic) { haptic->hwdata->stopThread = 1; SDL_WaitThread(haptic->hwdata->thread, NULL); SDL_DestroyMutex(haptic->hwdata->mutex); } else { IDirectInputDevice8_Unacquire(haptic->hwdata->device); /* Only release if isn't grabbed by a joystick. */ if (haptic->hwdata->is_joystick == 0) { IDirectInputDevice8_Release(haptic->hwdata->device); } } /* Free */ SDL_free(haptic->hwdata); haptic->hwdata = NULL; } }
static void joydx_inactivate_joy(ALLEGRO_JOYSTICK_DIRECTX *joy) { if (joy->config_state == STATE_UNUSED) return; joy->config_state = STATE_UNUSED; joy->marked = false; if (joy->device) { IDirectInputDevice8_SetEventNotification(joy->device, NULL); IDirectInputDevice8_Release(joy->device); joy->device = NULL; } memset(&joy->guid, 0, sizeof(GUID)); if (joy->waker_event) { CloseHandle(joy->waker_event); joy->waker_event = NULL; } memset(&joy->parent.info, 0, sizeof(joy->parent.info)); /* XXX the joystick name really belongs in joy->parent.info too */ joy->name[0] = '\0'; memset(&joy->joystate, 0, sizeof(joy->joystate)); }
static void dinput_joypad_destroy(void) { unsigned i; settings_t *settings = config_get_ptr(); for (i = 0; i < MAX_USERS; i++) { if (g_pads[i].joypad) { IDirectInputDevice8_Unacquire(g_pads[i].joypad); IDirectInputDevice8_Release(g_pads[i].joypad); } free(g_pads[i].joy_name); g_pads[i].joy_name = NULL; free(g_pads[i].joy_friendly_name); g_pads[i].joy_friendly_name = NULL; *settings->input.device_names[i] = '\0'; } g_joypad_cnt = 0; memset(g_pads, 0, sizeof(g_pads)); /* Can be blocked by global Dinput context. */ dinput_destroy_context(); }
int SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance) { HRESULT ret; LPDIRECTINPUTDEVICE8 device; const DWORD needflags = DIDC_ATTACHED | DIDC_FORCEFEEDBACK; DIDEVCAPS capabilities; SDL_hapticlist_item *item = NULL; if (dinput == NULL) { return -1; /* not initialized. We'll pick these up on enumeration if we init later. */ } /* Make sure we don't already have it */ for (item = SDL_hapticlist; item; item = item->next) { if ((!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0)) { return -1; /* Already added */ } } /* Open the device */ ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL); if (FAILED(ret)) { /* DI_SetError("Creating DirectInput device",ret); */ return -1; } /* Get capabilities. */ SDL_zero(capabilities); capabilities.dwSize = sizeof(DIDEVCAPS); ret = IDirectInputDevice8_GetCapabilities(device, &capabilities); IDirectInputDevice8_Release(device); if (FAILED(ret)) { /* DI_SetError("Getting device capabilities",ret); */ return -1; } if ((capabilities.dwFlags & needflags) != needflags) { return -1; /* not a device we can use. */ } item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); if (item == NULL) { return SDL_OutOfMemory(); } item->name = WIN_StringToUTF8(pdidInstance->tszProductName); if (!item->name) { SDL_free(item); return -1; } /* Copy the instance over, useful for creating devices. */ SDL_memcpy(&item->instance, pdidInstance, sizeof(DIDEVICEINSTANCE)); SDL_memcpy(&item->capabilities, &capabilities, sizeof(capabilities)); return SDL_SYS_AddHapticDevice(item); }
HRESULT WINAPI HookDirectInput8Create( PVOID ModuleBase, ULONG Version, REFIID IID, PVOID* Out, LPUNKNOWN UnknownOuter ) { HRESULT Result; PVOID HookGetDeviceData, HookGetDeviceState; Result = StubDirectInput8Create((HINSTANCE)ModuleBase, Version, IID, Out, UnknownOuter); if (FAILED(Result)) return Result; if (IID == IID_IDirectInput8A) { HookGetDeviceData = HookGetDeviceDataA; HookGetDeviceState = HookGetDeviceStateA; } else if (IID == IID_IDirectInput8W) { HookGetDeviceData = HookGetDeviceDataW; HookGetDeviceState = HookGetDeviceStateW; } else { return Result; } SCOPE_EXIT { Nt_RestoreMemory(&StubDirectInput8Create); } SCOPE_EXIT_END; LPDIRECTINPUT8W DInput8W; LPDIRECTINPUTDEVICE8W KeyboardW; DInput8W = (LPDIRECTINPUT8W)*Out; if (FAILED(IDirectInput8_CreateDevice(DInput8W, GUID_SysKeyboard, &KeyboardW, NULL))) return Result; MEMORY_FUNCTION_PATCH f[] = { INLINE_HOOK_JUMP(KeyboardW->lpVtbl->GetDeviceState, HookGetDeviceState, StubGetDeviceState), INLINE_HOOK_JUMP(KeyboardW->lpVtbl->GetDeviceData, HookGetDeviceData, StubGetDeviceData), }; Nt_PatchMemory(NULL, 0, f, countof(f), NULL); IDirectInputDevice8_Release(KeyboardW); return Result; }
void SDL_DINPUT_HapticClose(SDL_Haptic * haptic) { IDirectInputDevice8_Unacquire(haptic->hwdata->device); /* Only release if isn't grabbed by a joystick. */ if (haptic->hwdata->is_joystick == 0) { IDirectInputDevice8_Release(haptic->hwdata->device); } }
/* * Callback to find the haptic devices. */ static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) { HRESULT ret; LPDIRECTINPUTDEVICE8 device; /* Copy the instance over, useful for creating devices. */ SDL_memcpy(&SDL_hapticlist[SDL_numhaptics].instance, pdidInstance, sizeof(DIDEVICEINSTANCE)); /* Open the device */ ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL); if (FAILED(ret)) { /* DI_SetError("Creating DirectInput device",ret); */ return DIENUM_CONTINUE; } /* Get capabilities. */ SDL_hapticlist[SDL_numhaptics].capabilities.dwSize = sizeof(DIDEVCAPS); ret = IDirectInputDevice8_GetCapabilities(device, &SDL_hapticlist[SDL_numhaptics]. capabilities); if (FAILED(ret)) { /* DI_SetError("Getting device capabilities",ret); */ IDirectInputDevice8_Release(device); return DIENUM_CONTINUE; } /* Copy the name */ SDL_hapticlist[SDL_numhaptics].name = WIN_StringToUTF8(SDL_hapticlist[SDL_numhaptics].instance.tszProductName); /* Close up device and count it. */ IDirectInputDevice8_Release(device); SDL_numhaptics++; /* Watch out for hard limit. */ if (SDL_numhaptics >= MAX_HAPTICS) return DIENUM_STOP; return DIENUM_CONTINUE; }
static void dinput_free(void *data) { struct dinput_input *di = (struct dinput_input*)data; LPDIRECTINPUT8 hold_ctx = g_ctx; if (di) { g_ctx = NULL; // Prevent a joypad driver to kill our context prematurely. di->joypad->destroy(); g_ctx = hold_ctx; if (di->keyboard) IDirectInputDevice8_Release(di->keyboard); if (di->mouse) IDirectInputDevice8_Release(di->mouse); free(di); } dinput_destroy_context(); }
static void dinput_joypad_destroy(void) { for (unsigned i = 0; i < MAX_PLAYERS; i++) { if (g_pads[i].joypad) { IDirectInputDevice8_Unacquire(g_pads[i].joypad); IDirectInputDevice8_Release(g_pads[i].joypad); } } g_joypad_cnt = 0; memset(g_pads, 0, sizeof(g_pads)); // Can be blocked by global Dinput context. dinput_destroy_context(); }
void PERDXDeInit(void) { u32 i; for (i = 0; i < numdevices; i++) { if (lpDIDevice[i]) { IDirectInputDevice8_Unacquire(lpDIDevice[i]); IDirectInputDevice8_Release(lpDIDevice[i]); lpDIDevice[i] = NULL; } } if (lpDI8) { IDirectInput8_Release(lpDI8); lpDI8 = NULL; } }
void PERDXDeInit(void) { u32 i; for (i = 0; i < num_devices; i++) { if (dev_list[i].lpDIDevice) { IDirectInputDevice8_Unacquire(dev_list[i].lpDIDevice); IDirectInputDevice8_Release(dev_list[i].lpDIDevice); dev_list[i].lpDIDevice = NULL; } } if (lpDI8) { IDirectInput8_Release(lpDI8); lpDI8 = NULL; } PERCORE_INITIALIZED = 0; }
/*********************************************************************** * destroy_joysticks [internal] */ static void destroy_joysticks(struct JoystickData *data) { int i, j; for (i = 0; i < data->num_joysticks; i++) { if (data->joysticks[i].forcefeedback && data->joysticks[i].num_effects > 0) { for (j = 0; j < data->joysticks[i].num_effects; j++) IDirectInputEffect_Release(data->joysticks[i].effects[j].effect); HeapFree(GetProcessHeap(), 0, data->joysticks[i].effects); } IDirectInputDevice8_Unacquire(data->joysticks[i].device); IDirectInputDevice8_Release(data->joysticks[i].device); } HeapFree(GetProcessHeap(), 0, data->joysticks); }
static void dinput_joypad_destroy(void) { unsigned i; for (i = 0; i < MAX_USERS; i++) { if (g_pads[i].joypad) { if (g_pads[i].rumble_iface[0]) { IDirectInputEffect_Stop(g_pads[i].rumble_iface[0]); IDirectInputEffect_Release(g_pads[i].rumble_iface[0]); } if (g_pads[i].rumble_iface[1]) { IDirectInputEffect_Stop(g_pads[i].rumble_iface[1]); IDirectInputEffect_Release(g_pads[i].rumble_iface[1]); } IDirectInputDevice8_Unacquire(g_pads[i].joypad); IDirectInputDevice8_Release(g_pads[i].joypad); } free(g_pads[i].joy_name); g_pads[i].joy_name = NULL; free(g_pads[i].joy_friendly_name); g_pads[i].joy_friendly_name = NULL; input_config_clear_device_name(i); } g_joypad_cnt = 0; memset(g_pads, 0, sizeof(g_pads)); /* Can be blocked by global Dinput context. */ dinput_destroy_context(); }
/* joystick_enum_callback: [primary thread] * Helper function to find out how many joysticks we have and set them up. * At the end joydx_num_joysticks and joydx_joystick[] will be initialised. */ static BOOL CALLBACK joystick_enum_callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { DIPROPRANGE property_range = { /* the header */ { sizeof(DIPROPRANGE), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ -32767, // lMin +32767 // lMax }; DIPROPDWORD property_deadzone = { /* the header */ { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ 2000, // dwData }; DIPROPDWORD property_buffersize = { /* the header */ { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ DEVICE_BUFFER_SIZE // number of data items }; LPDIRECTINPUTDEVICE _dinput_device1; LPDIRECTINPUTDEVICE2 dinput_device = NULL; HRESULT hr; LPVOID temp; CAPS_AND_NAMES caps_and_names; ALLEGRO_JOYSTICK_DIRECTX *joy; int num; (void)pvRef; /* check if the joystick already existed before */ joy = joydx_by_guid(lpddi->guidInstance); if (joy) { ALLEGRO_DEBUG("Device %s still exists\n", joydx_guid_string(joy)); joy->marked = true; return DIENUM_CONTINUE; } /* create the DirectInput joystick device */ hr = IDirectInput8_CreateDevice(joystick_dinput, &lpddi->guidInstance, &_dinput_device1, NULL); if (FAILED(hr)) goto Error; /* query the DirectInputDevice2 interface needed for the poll() method */ hr = IDirectInputDevice8_QueryInterface(_dinput_device1, &__al_IID_IDirectInputDevice8A, &temp); IDirectInputDevice8_Release(_dinput_device1); if (FAILED(hr)) goto Error; dinput_device = temp; /* enumerate objects available on the device */ memset(&caps_and_names, 0, sizeof(caps_and_names)); hr = IDirectInputDevice8_EnumObjects(dinput_device, object_enum_callback, &caps_and_names, DIDFT_PSHBUTTON | DIDFT_AXIS | DIDFT_POV); if (FAILED(hr)) goto Error; /* set data format */ hr = IDirectInputDevice8_SetDataFormat(dinput_device, &__al_c_dfDIJoystick); if (FAILED(hr)) goto Error; /* set the range of axes */ hr = IDirectInputDevice8_SetProperty(dinput_device, DIPROP_RANGE, &property_range.diph); if (FAILED(hr)) goto Error; /* set the dead zone of axes */ hr = IDirectInputDevice8_SetProperty(dinput_device, DIPROP_DEADZONE, &property_deadzone.diph); if (FAILED(hr)) goto Error; /* set the buffer size */ hr = IDirectInputDevice8_SetProperty(dinput_device, DIPROP_BUFFERSIZE, &property_buffersize.diph); if (FAILED(hr)) goto Error; /* set up the joystick structure */ joy = joydx_allocate_structure(&num); if (!joy) { ALLEGRO_ERROR("Joystick array full\n"); goto Error; } joy->config_state = STATE_BORN; joy->marked = true; joy->device = dinput_device; memcpy(&joy->guid, &lpddi->guidInstance, sizeof(GUID)); _al_sane_strncpy(joy->name, lpddi->tszInstanceName, sizeof(joy->name)); /* fill in the joystick structure */ fill_joystick_info_using_caps_and_names(joy, &caps_and_names); /* create a thread event for this joystick, unless it was already created */ joy->waker_event = CreateEvent(NULL, false, false, NULL); /* tell the joystick background thread to wake up when this joystick * device's state changes */ hr = IDirectInputDevice8_SetEventNotification(joy->device, joy->waker_event); if (FAILED(hr)) { ALLEGRO_ERROR("SetEventNotification failed for joystick %d: %s\n", num, dinput_err_str(hr)); goto Error; } if (hr == DI_POLLEDDEVICE) { /* This joystick device must be polled -- replace the Event with * a Waitable Timer object. * * Theoretically all polled devices could share a single * waitable timer object. But, really, how many such devices * are there going to be on a system? */ CloseHandle(joy->waker_event); joy->waker_event = CreateWaitableTimer(NULL, false, NULL); if (joy->waker_event == NULL) { ALLEGRO_ERROR("CreateWaitableTimer failed for polled device.\n"); goto Error; } { LARGE_INTEGER due_time; due_time.HighPart = 0; due_time.LowPart = 150; /* 15 ms (arbitrary) */ SetWaitableTimer(joy->waker_event, &due_time, true, /* periodic */ NULL, NULL, false); } } ALLEGRO_INFO("Joystick %d initialized, GUID: %s\n", num, joydx_guid_string(joy)); config_needs_merging = true; return DIENUM_CONTINUE; Error: if (dinput_device) IDirectInputDevice8_Release(dinput_device); if (joy) { joy->device = NULL; joydx_inactivate_joy(joy); } return DIENUM_CONTINUE; }
void SDL_DINPUT_JoystickClose(SDL_Joystick * joystick) { IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice); IDirectInputDevice8_Release(joystick->hwdata->InputDevice); }
int SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice) { HRESULT result; LPDIRECTINPUTDEVICE8 device; DIPROPDWORD dipdw; joystick->hwdata->buffered = SDL_TRUE; joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS); SDL_zero(dipdw); dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); result = IDirectInput8_CreateDevice(dinput, &(joystickdevice->dxdevice.guidInstance), &device, NULL); if (FAILED(result)) { return SetDIerror("IDirectInput::CreateDevice", result); } /* Now get the IDirectInputDevice8 interface, instead. */ result = IDirectInputDevice8_QueryInterface(device, &IID_IDirectInputDevice8, (LPVOID *)& joystick-> hwdata->InputDevice); /* We are done with this object. Use the stored one from now on. */ IDirectInputDevice8_Release(device); if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::QueryInterface", result); } /* Acquire shared access. Exclusive access is required for forces, * though. */ result = IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata-> InputDevice, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND); if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); } /* Use the extended data structure: DIJOYSTATE2. */ result = IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice, &SDL_c_dfDIJoystick2); if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::SetDataFormat", result); } /* Get device capabilities */ result = IDirectInputDevice8_GetCapabilities(joystick->hwdata->InputDevice, &joystick->hwdata->Capabilities); if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::GetCapabilities", result); } /* Force capable? */ if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) { result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::Acquire", result); } /* reset all actuators. */ result = IDirectInputDevice8_SendForceFeedbackCommand(joystick->hwdata-> InputDevice, DISFFC_RESET); /* Not necessarily supported, ignore if not supported. if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result); } */ result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice); if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::Unacquire", result); } /* Turn on auto-centering for a ForceFeedback device (until told * otherwise). */ dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = DIPROPAUTOCENTER_ON; result = IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice, DIPROP_AUTOCENTER, &dipdw.diph); /* Not necessarily supported, ignore if not supported. if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::SetProperty", result); } */ } /* What buttons and axes does it have? */ IDirectInputDevice8_EnumObjects(joystick->hwdata->InputDevice, EnumDevObjectsCallback, joystick, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); /* Reorder the input objects. Some devices do not report the X axis as * the first axis, for example. */ SortDevObjects(joystick); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = INPUT_QSIZE; /* Set the buffer size */ result = IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice, DIPROP_BUFFERSIZE, &dipdw.diph); if (result == DI_POLLEDDEVICE) { /* This device doesn't support buffering, so we're forced * to use less reliable polling. */ joystick->hwdata->buffered = SDL_FALSE; } else if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::SetProperty", result); } return 0; }
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; }
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; }
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]); } } } } } }
JNIEXPORT void JNICALL Java_net_java_games_input_IDirectInputDevice_nRelease(JNIEnv *env, jclass unused, jlong address) { LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address; IDirectInputDevice8_Release(lpDevice); }