static BOOL CALLBACK enumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { enum_context_t *enum_context = (enum_context_t *)pvRef; jmethodID add_method; jstring name; DWORD instance; DWORD type; jint guid_type; jbyteArray guid; JNIEnv *env = enum_context->env; jobject device_obj = enum_context->device_obj; jclass obj_class = (*env)->GetObjectClass(env, device_obj); if (obj_class == NULL) return DIENUM_STOP; guid = wrapGUID(env, &(lpddoi->guidType)); if (guid == NULL) return DIENUM_STOP; add_method = (*env)->GetMethodID(env, obj_class, "addObject", "([BIIIIILjava/lang/String;)V"); if (add_method == NULL) return DIENUM_STOP; name = (*env)->NewStringUTF(env, lpddoi->tszName); if (name == NULL) return DIENUM_STOP; instance = DIDFT_GETINSTANCE(lpddoi->dwType); type = DIDFT_GETTYPE(lpddoi->dwType); guid_type = mapGUIDType(&(lpddoi->guidType)); //printfJava(env, "name %s guid_type %d id %d\n", lpddoi->tszName, guid_type, lpddoi->dwType); (*env)->CallBooleanMethod(env, device_obj, add_method, guid, (jint)guid_type, (jint)lpddoi->dwType, (jint)type, (jint)instance, (jint)lpddoi->dwFlags, name); if ((*env)->ExceptionOccurred(env)) { return DIENUM_STOP; } return DIENUM_CONTINUE; }
static void test_build_action_map(IDirectInputDevice8A *lpdid, DIACTIONFORMATA *lpdiaf, int action_index, DWORD expected_type, DWORD expected_inst) { HRESULT hr; DIACTIONA *actions; DWORD instance, type, how; GUID assigned_to; DIDEVICEINSTANCEA ddi; ddi.dwSize = sizeof(ddi); IDirectInputDevice_GetDeviceInfo(lpdid, &ddi); hr = IDirectInputDevice8_BuildActionMap(lpdid, lpdiaf, NULL, DIDBAM_HWDEFAULTS); ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr); actions = lpdiaf->rgoAction; instance = DIDFT_GETINSTANCE(actions[action_index].dwObjID); type = DIDFT_GETTYPE(actions[action_index].dwObjID); how = actions[action_index].dwHow; assigned_to = actions[action_index].guidInstance; ok (how == DIAH_USERCONFIG || how == DIAH_DEFAULT, "Action was not set dwHow=%08x\n", how); ok (instance == expected_inst, "Action not mapped correctly instance=%08x expected=%08x\n", instance, expected_inst); ok (type == expected_type, "Action type not mapped correctly type=%08x expected=%08x\n", type, expected_type); ok (IsEqualGUID(&assigned_to, &ddi.guidInstance), "Action and device GUID do not match action=%d\n", action_index); }
HRESULT WINAPI HOOKDirectInputDevice::GetDeviceState(DWORD cbData, LPVOID lpvData) { #if 0 HRESULT res = actualDirectInputDevice->GetDeviceState(cbData, lpvData); if (FAILED(res)) return res; LPDIOBJECTDATAFORMAT obj_dfmt = dformat->rgodf; int i, n = dformat->dwNumObjs; for (i=0; i<n; i++) { LPVOID ptr = (char*)lpvData + obj_dfmt[i].dwOfs; if (DIDFT_GETTYPE(obj_dfmt[i].dwType) == DIDFT_AXIS) { if (*obj_dfmt[i].pguid == GUID_YAxis) *(LPLONG)ptr *= 3; } } return res; #endif return actualDirectInputDevice->GetDeviceState(cbData, lpvData); }
BOOL FAR PASCAL EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { DInputDevice *device = (DInputDevice *)pvRef; DInputDevice::DeviceObjectInfo &infoList = const_cast<DInputDevice::DeviceObjectInfo &>(device->GetObjectInfoList()); Log(Debug, "Device object name: %S", lpddoi->tszName); DInputDevice::ObjectInfo info; int type = DIDFT_GETTYPE(lpddoi->dwType); info.name = lpddoi->tszName; info.id = DIDFT_GETINSTANCE(lpddoi->dwType); info.type = lpddoi->dwType; if ((type & DIDFT_AXIS) != 0) { device->GetAxisRange(type, info.min, info.max); infoList.axes.push_back(info); } else if ((type & DIDFT_BUTTON) != 0) { info.min = 0; info.max = 1; infoList.buttons.push_back(info); } else if (type == DIDFT_POV) { info.min = 0; info.max = 0; infoList.povs.push_back(info); } return DIENUM_CONTINUE; }
static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput) { SysMouseImpl* newDevice; LPDIDATAFORMAT df = NULL; unsigned i; char buffer[20]; HKEY hkey, appkey; newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl)); if (!newDevice) return NULL; newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt; newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt; newDevice->base.ref = 1; newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; newDevice->base.guid = *rguid; InitializeCriticalSection(&newDevice->base.crit); newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit"); newDevice->base.dinput = dinput; newDevice->base.event_proc = dinput_mouse_hook; get_app_key(&hkey, &appkey); if (!get_config_key(hkey, appkey, "MouseWarpOverride", buffer, sizeof(buffer))) { if (!strcasecmp(buffer, "disable")) newDevice->warp_override = WARP_DISABLE; else if (!strcasecmp(buffer, "force")) newDevice->warp_override = WARP_FORCE_ON; } if (appkey) RegCloseKey(appkey); if (hkey) RegCloseKey(hkey); /* Create copy of default data format */ if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed; memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize); if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed; memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize); /* Because we don't do any detection yet just modify instance and type */ for (i = 0; i < df->dwNumObjs; i++) if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_RELAXIS; else df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON; newDevice->base.data_format.wine_df = df; IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface); EnterCriticalSection(&dinput->crit); list_add_tail(&dinput->devices_list, &newDevice->base.entry); LeaveCriticalSection(&dinput->crit); return newDevice; failed: if (df) HeapFree(GetProcessHeap(), 0, df->rgodf); HeapFree(GetProcessHeap(), 0, df); HeapFree(GetProcessHeap(), 0, newDevice); return NULL; }
static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputImpl *dinput) { SysMouseImpl* newDevice; LPDIDATAFORMAT df = NULL; unsigned i; newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl)); if (!newDevice) return NULL; newDevice->base.lpVtbl = mvt; newDevice->base.ref = 1; newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; newDevice->base.guid = *rguid; InitializeCriticalSection(&newDevice->base.crit); newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit"); newDevice->base.dinput = dinput; newDevice->base.event_proc = dinput_mouse_hook; /* Create copy of default data format */ if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed; memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize); if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed; memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize); /* Because we don't do any detection yet just modify instance and type */ for (i = 0; i < df->dwNumObjs; i++) if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_RELAXIS; else df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON; newDevice->base.data_format.wine_df = df; IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput); return newDevice; failed: if (df) HeapFree(GetProcessHeap(), 0, df->rgodf); HeapFree(GetProcessHeap(), 0, df); HeapFree(GetProcessHeap(), 0, newDevice); return NULL; }
static void dump_data_format (const DIDATAFORMAT *format) { #ifdef GIMP_UNSTABLE gint i; g_print ("dwSize: %ld\n", format->dwSize); g_print ("dwObjSize: %ld\n", format->dwObjSize); g_print ("dwFlags: "); if (format->dwFlags == DIDF_ABSAXIS) g_print ("DIDF_ABSAXIS"); else if (format->dwFlags == DIDF_RELAXIS) g_print ("DIDF_RELAXIS"); else g_print ("%#lx", format->dwFlags); g_print ("\n"); g_print ("dwDataSize: %ld\n", format->dwDataSize); g_print ("dwNumObjs: %ld\n", format->dwNumObjs); for (i = 0; i < format->dwNumObjs; i++) { const DIOBJECTDATAFORMAT *oformat = (DIOBJECTDATAFORMAT *) (((char *) format->rgodf) + i*format->dwObjSize); unsigned char *guid; g_print ("Object %d:\n", i); if (oformat->pguid == NULL) g_print (" pguid: NULL\n"); else { UuidToString (oformat->pguid, &guid); g_print (" pguid: %s\n", guid); RpcStringFree (&guid); } g_print (" dwOfs: %ld\n", oformat->dwOfs); g_print (" dwType: "); switch (DIDFT_GETTYPE (oformat->dwType)) { #define CASE(x) case DIDFT_##x: g_print ("DIDFT_"#x); break CASE (RELAXIS); CASE (ABSAXIS); CASE (AXIS); CASE (PSHBUTTON); CASE (TGLBUTTON); CASE (BUTTON); CASE (POV); CASE (COLLECTION); CASE (NODATA); #undef CASE default: g_print ("%#x", DIDFT_GETTYPE (oformat->dwType)); } g_print (" "); if (DIDFT_GETINSTANCE (oformat->dwType) == DIDFT_GETINSTANCE (DIDFT_ANYINSTANCE)) g_print ("ANYINSTANCE"); else g_print ("#%d", DIDFT_GETINSTANCE (oformat->dwType)); #define BIT(x) if (oformat->dwType & DIDFT_##x) g_print (" "#x) BIT (FFACTUATOR); BIT (FFEFFECTTRIGGER); BIT (OUTPUT); BIT (VENDORDEFINED); BIT (ALIAS); BIT (OPTIONAL); #undef BIT g_print ("\n"); g_print (" dwFlags:"); switch (oformat->dwFlags & DIDOI_ASPECTACCEL) { case DIDOI_ASPECTPOSITION: g_print (" DIDOI_ASPECTPOSITION"); break; case DIDOI_ASPECTVELOCITY: g_print (" DIDOI_ASPECTVELOCITY"); break; case DIDOI_ASPECTACCEL: g_print (" DIDOI_ASPECTACCEL"); break; } if (oformat->dwFlags & DIDOI_ASPECTFORCE) g_print (" DIDOI_ASPECTFORCE"); g_print ("\n"); } #endif }
static BOOL CALLBACK enum_type_callback(LPCDIDEVICEOBJECTINSTANCE oi, LPVOID info) { DWORD expected = *(DWORD*)info; ok (expected & DIDFT_GETTYPE(oi->dwType), "EnumObjects() enumerated wrong type for obj %s, expected: %08x got: %08x\n", oi->tszName, expected, oi->dwType); return DIENUM_CONTINUE; }
HRESULT Rayman3XInput_DirectInputDevice8A::SetDataFormat(LPCDIDATAFORMAT lpdf) { Debug("R3XI: SetDataFormat called\n"); ResetControls(); if (lpdf->dwSize != sizeof(DIDATAFORMAT) || lpdf->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) { Debug("SetDataFormat called with invalid lpdf\n"); return DIERR_INVALIDPARAM; } for (DWORD i = 0; i < lpdf->dwNumObjs; ++i) { LPDIOBJECTDATAFORMAT odf = &lpdf->rgodf[i]; Debug("Object %d:\n", i); if (odf->pguid == NULL) { Debug(" GUID: NULL\n"); } else { OLECHAR* guidStr; StringFromCLSID(*odf->pguid, &guidStr); Debug(" GUID: %S\n", guidStr); CoTaskMemFree(guidStr); } Debug(" Offset: %d\n", odf->dwOfs); Debug(" Type: 0x%.08X\n", odf->dwType); Debug(" Flags: 0x%.08X\n", odf->dwFlags); if (odf->pguid != NULL) { // Find first available control with matching GUID ControlList::const_iterator it; for (it = m_availableControls.begin(); it != m_availableControls.end(); ++it) { if ((*it)->GetGUID() == *odf->pguid) { break; } } if (it != m_availableControls.end() && (*it)->IsTypeCompatible(DIDFT_GETTYPE(odf->dwType))) { // Assign the control to the offset Debug("Control assigned\n"); m_assignedControls[odf->dwOfs] = *it; m_availableControls.erase(it); } else { // No matching control found. Assign a "zero" control. Debug("No control assigned; assigning zero control\n"); AssignZeroControl(odf->dwOfs, DIDFT_GETTYPE(odf->dwType)); } } else { // Find first available control compatible with type ControlList::const_iterator it; for (it = m_availableControls.begin(); it != m_availableControls.end(); ++it) { if ((*it)->IsTypeCompatible(DIDFT_GETTYPE(odf->dwType))) { break; } } if (it != m_availableControls.end()) { Debug("Control assigned\n"); // Assign the control to the offset m_assignedControls[odf->dwOfs] = *it; m_availableControls.erase(it); } else { Debug("No control assigned; assigning zero control\n"); // No matching control found. Assign a "zero" control. AssignZeroControl(odf->dwOfs, DIDFT_GETTYPE(odf->dwType)); } } } return DI_OK; }