Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 63 +++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 36 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 040a97eb06b..3e398f11dad 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -67,6 +67,20 @@ static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl( struct dinpu return &This->IDirectInputDevice8W_iface; }
+static inline const char *debugstr_didataformat( const DIDATAFORMAT *data ) +{ + if (!data) return "(null)"; + return wine_dbg_sprintf( "%p dwSize %u, dwObjsize %u, dwFlags %#x, dwDataSize %u, dwNumObjs %u, rgodf %p", + data, data->dwSize, data->dwObjSize, data->dwFlags, data->dwDataSize, data->dwNumObjs, data->rgodf ); +} + +static inline const char *debugstr_diobjectdataformat( const DIOBJECTDATAFORMAT *data ) +{ + if (!data) return "(null)"; + return wine_dbg_sprintf( "%p, pguid %s, dwOfs %#x, dwType %#x, dwFlags %#x", data, + debugstr_guid( data->pguid ), data->dwOfs, data->dwType, data->dwFlags ); +} + /****************************************************************************** * Various debugging tools */ @@ -225,40 +239,6 @@ static const char *_dump_dinput_GUID( const GUID *guid ) return debugstr_guid(guid); }
-static void _dump_DIDATAFORMAT( const DIDATAFORMAT *df ) -{ - unsigned int i; - - TRACE("Dumping DIDATAFORMAT structure:\n"); - TRACE(" - dwSize: %d\n", df->dwSize); - if (df->dwSize != sizeof(DIDATAFORMAT)) { - WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize); - } - TRACE(" - dwObjsize: %d\n", df->dwObjSize); - if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) { - WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize); - } - TRACE(" - dwFlags: 0x%08x (", df->dwFlags); - switch (df->dwFlags) { - case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break; - case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break; - default: TRACE("unknown"); break; - } - TRACE(")\n"); - TRACE(" - dwDataSize: %d\n", df->dwDataSize); - TRACE(" - dwNumObjs: %d\n", df->dwNumObjs); - - for (i = 0; i < df->dwNumObjs; i++) { - TRACE(" - Object %d:\n", i); - TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid)); - TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs); - TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType); - TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n"); - TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags); - TRACE(" "); _dump_ObjectDataFormat_flags(df->rgodf[i].dwFlags); TRACE("\n"); - } -} - /****************************************************************************** * Get the default and the app-specific config keys. */ @@ -933,11 +913,16 @@ static HRESULT WINAPI dinput_device_SetDataFormat( IDirectInputDevice8W *iface, { struct dinput_device *This = impl_from_IDirectInputDevice8W( iface ); HRESULT res = DI_OK; + ULONG i;
TRACE( "iface %p, format %p.\n", iface, format );
if (!format) return E_POINTER; - _dump_DIDATAFORMAT( format ); + if (TRACE_ON( dinput )) + { + TRACE( "user format %s\n", debugstr_didataformat( format ) ); + for (i = 0; i < format->dwNumObjs; ++i) TRACE( " %u: object %s\n", i, debugstr_diobjectdataformat( format->rgodf + i ) ); + }
if (format->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM; if (format->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) return DIERR_INVALIDPARAM; @@ -2182,7 +2167,7 @@ HRESULT dinput_device_init( IDirectInputDevice8W *iface ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); DIDATAFORMAT *format = impl->data_format.wine_df; - ULONG size; + ULONG i, size;
IDirectInputDevice8_EnumObjects( iface, enum_objects_init, iface, DIDFT_ALL ); if (format->dwDataSize > DEVICE_STATE_MAX_SIZE) @@ -2199,5 +2184,11 @@ HRESULT dinput_device_init( IDirectInputDevice8W *iface ) format->dwNumObjs = 0; IDirectInputDevice8_EnumObjects( iface, enum_objects_init, iface, DIDFT_ALL );
+ if (TRACE_ON( dinput )) + { + TRACE( "device format %s\n", debugstr_didataformat( format ) ); + for (i = 0; i < format->dwNumObjs; ++i) TRACE( " %u: object %s\n", i, debugstr_diobjectdataformat( format->rgodf + i ) ); + } + return DI_OK; }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput8/tests/hid.c | 160 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+)
diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index b23d3a6bfd8..bf3a9801689 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -3764,6 +3764,7 @@ static void test_simple_joystick(void) .dwHeaderSize = sizeof(DIPROPHEADER), }, }; + DIOBJECTDATAFORMAT objdataformat[32] = {{0}}; WCHAR cwd[MAX_PATH], tempdir[MAX_PATH]; DIDEVICEOBJECTDATA objdata[32] = {{0}}; DIDEVICEOBJECTINSTANCEW objinst = {0}; @@ -4403,6 +4404,165 @@ static void test_simple_joystick(void) check_member( state, expect_state[3], "%#x", rgbButtons[1] ); check_member( state, expect_state[3], "%#x", rgbButtons[2] );
+ hr = IDirectInputDevice8_Unacquire( device ); + ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); + + dataformat.dwSize = sizeof(DIDATAFORMAT); + dataformat.dwObjSize = sizeof(DIOBJECTDATAFORMAT); + dataformat.dwFlags = DIDF_ABSAXIS; + dataformat.dwDataSize = sizeof(buffer); + dataformat.dwNumObjs = 0; + dataformat.rgodf = objdataformat; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + + dataformat.dwNumObjs = 1; + dataformat.dwDataSize = 8; + objdataformat[0].pguid = NULL; + objdataformat[0].dwOfs = 2; + objdataformat[0].dwType = DIDFT_AXIS|DIDFT_ANYINSTANCE; + objdataformat[0].dwFlags = 0; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + objdataformat[0].dwOfs = 4; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + dataformat.dwDataSize = 10; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + dataformat.dwDataSize = 8; + objdataformat[0].dwOfs = 2; + objdataformat[0].dwType = DIDFT_OPTIONAL|0xff|DIDFT_ANYINSTANCE; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + + dataformat.dwNumObjs = 2; + dataformat.dwDataSize = 5; + objdataformat[0].pguid = NULL; + objdataformat[0].dwOfs = 4; + objdataformat[0].dwType = DIDFT_BUTTON|DIDFT_ANYINSTANCE; + objdataformat[0].dwFlags = 0; + objdataformat[1].pguid = NULL; + objdataformat[1].dwOfs = 0; + objdataformat[1].dwType = DIDFT_AXIS|DIDFT_MAKEINSTANCE( 0 ); + objdataformat[1].dwFlags = 0; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + dataformat.dwDataSize = 8; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + + dataformat.dwNumObjs = 4; + dataformat.dwDataSize = 12; + objdataformat[0].pguid = NULL; + objdataformat[0].dwOfs = 0; + objdataformat[0].dwType = DIDFT_AXIS|DIDFT_MAKEINSTANCE( 0 ); + objdataformat[0].dwFlags = 0; + objdataformat[1].pguid = NULL; + objdataformat[1].dwOfs = 0; + objdataformat[1].dwType = DIDFT_AXIS|DIDFT_MAKEINSTANCE( 0 ); + objdataformat[1].dwFlags = 0; + objdataformat[2].pguid = &GUID_ZAxis; + objdataformat[2].dwOfs = 8; + objdataformat[2].dwType = 0xff|DIDFT_ANYINSTANCE; + objdataformat[2].dwFlags = 0; + objdataformat[3].pguid = &GUID_POV; + objdataformat[3].dwOfs = 0; + objdataformat[3].dwType = 0xff|DIDFT_ANYINSTANCE; + objdataformat[3].dwFlags = 0; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].dwType = DIDFT_AXIS|DIDFT_MAKEINSTANCE( 12 ); + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].dwType = DIDFT_AXIS|DIDFT_MAKEINSTANCE( 0xff ); + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].dwType = DIDFT_AXIS|DIDFT_MAKEINSTANCE( 1 ); + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].pguid = &GUID_RzAxis; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].pguid = &GUID_Unknown; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + todo_wine + ok( hr == DIERR_INVALIDPARAM, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].pguid = &GUID_YAxis; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + objdataformat[1].pguid = NULL; + objdataformat[1].dwType = DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_MAKEINSTANCE( 0 ); + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + + + dataformat.dwNumObjs = 0; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + hr = IDirectInputDevice8_Acquire( device ); + ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); + + send_hid_input( file, &injected_input[4], sizeof(*injected_input) ); + res = WaitForSingleObject( event, 100 ); + todo_wine + ok( res == WAIT_TIMEOUT, "WaitForSingleObject failed\n" ); + ResetEvent( event ); + + hr = IDirectInputDevice8_GetDeviceState( device, dataformat.dwDataSize, buffer ); + ok( hr == DI_OK, "GetDeviceState returned: %#x\n", hr ); + hr = IDirectInputDevice8_Unacquire( device ); + ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); + + + dataformat.dwNumObjs = 4; + hr = IDirectInputDevice8_SetDataFormat( device, &dataformat ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + hr = IDirectInputDevice8_Acquire( device ); + ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); + + send_hid_input( file, &injected_input[4], sizeof(*injected_input) ); + res = WaitForSingleObject( event, 100 ); + todo_wine + ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" ); + ResetEvent( event ); + send_hid_input( file, &injected_input[3], sizeof(*injected_input) ); + res = WaitForSingleObject( event, 100 ); + ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" ); + ResetEvent( event ); + + hr = IDirectInputDevice8_GetDeviceState( device, dataformat.dwDataSize, buffer ); + ok( hr == DI_OK, "GetDeviceState returned: %#x\n", hr ); + todo_wine + ok( ((ULONG *)buffer)[0] == 0x512b, "got %#x, expected %#x\n", ((ULONG *)buffer)[0], 0x512b ); + ok( ((ULONG *)buffer)[1] == 0, "got %#x, expected %#x\n", ((ULONG *)buffer)[1], 0 ); + ok( ((ULONG *)buffer)[2] == 0x7fff, "got %#x, expected %#x\n", ((ULONG *)buffer)[2], 0x7fff ); + hr = IDirectInputDevice8_Unacquire( device ); + ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); + + + hr = IDirectInputDevice8_SetDataFormat( device, &c_dfDIJoystick2 ); + ok( hr == DI_OK, "SetDataFormat returned: %#x\n", hr ); + hr = IDirectInputDevice8_Acquire( device ); + ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); + + send_hid_input( file, &injected_input[4], sizeof(*injected_input) ); + res = WaitForSingleObject( event, 100 ); + ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" ); + ResetEvent( event ); + send_hid_input( file, &injected_input[3], sizeof(*injected_input) ); + res = WaitForSingleObject( event, 100 ); + ok( res == WAIT_OBJECT_0, "WaitForSingleObject failed\n" ); + ResetEvent( event ); + prop_range.diph.dwHow = DIPH_DEVICE; prop_range.diph.dwObj = 0; prop_range.lMin = 1000;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=100897
Your paranoid android.
=== w1064_tsign (64 bit report) ===
dinput8: hid.c:4748: Test failed: state[0]: WaitForSingleObject succeeded
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 45 ++++++++++++++++++------------------ dlls/dinput/device_private.h | 2 +- dlls/dinput/mouse.c | 6 ++--- 3 files changed, 26 insertions(+), 27 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 3e398f11dad..07c4bba04c0 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -400,16 +400,14 @@ static void fill_DataFormat( void *out, DWORD size, const void *in, const DataFo } }
-static void release_DataFormat( DataFormat *format ) +static void dinput_device_release_user_format( struct dinput_device *impl ) { - TRACE("Deleting DataFormat: %p\n", format); - - free( format->dt ); - format->dt = NULL; - free( format->offsets ); - format->offsets = NULL; - free( format->user_df ); - format->user_df = NULL; + free( impl->data_format.dt ); + impl->data_format.dt = NULL; + free( impl->data_format.offsets ); + impl->data_format.offsets = NULL; + free( impl->user_format ); + impl->user_format = NULL; }
static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx) @@ -441,8 +439,9 @@ LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD return NULL; }
-static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format) +static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const DIDATAFORMAT *asked_format ) { + DataFormat *format = &impl->data_format; DataTransform *dt; unsigned int i, j; int same = 1; @@ -456,8 +455,8 @@ static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *forma if (!dt || !done) goto failed;
if (!(format->offsets = malloc( format->wine_df->dwNumObjs * sizeof(int) ))) goto failed; - if (!(format->user_df = malloc( asked_format->dwSize ))) goto failed; - memcpy(format->user_df, asked_format, asked_format->dwSize); + if (!(impl->user_format = malloc( asked_format->dwSize ))) goto failed; + memcpy( impl->user_format, asked_format, asked_format->dwSize );
TRACE("Creating DataTransform :\n");
@@ -575,8 +574,8 @@ failed: format->dt = NULL; free( format->offsets ); format->offsets = NULL; - free( format->user_df ); - format->user_df = NULL; + free( impl->user_format ); + impl->user_format = NULL;
return DIERR_OUTOFMEMORY; } @@ -863,7 +862,7 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface ) EnterCriticalSection( &impl->crit ); if (impl->acquired) hr = DI_NOEFFECT; - else if (!impl->data_format.user_df) + else if (!impl->user_format) hr = DIERR_INVALIDPARAM; else if ((impl->dwCoopLevel & DISCL_FOREGROUND) && impl->win != GetForegroundWindow()) hr = DIERR_OTHERAPPHASPRIO; @@ -934,8 +933,8 @@ static HRESULT WINAPI dinput_device_SetDataFormat( IDirectInputDevice8W *iface, This->action_map = NULL; This->num_actions = 0;
- release_DataFormat(&This->data_format); - res = create_DataFormat( format, &This->data_format ); + dinput_device_release_user_format( This ); + res = dinput_device_init_user_format( This, format );
LeaveCriticalSection(&This->crit); return res; @@ -1036,7 +1035,7 @@ void dinput_device_destroy( IDirectInputDevice8W *iface ) /* Free data format */ free( This->data_format.wine_df->rgodf ); free( This->data_format.wine_df ); - release_DataFormat(&This->data_format); + dinput_device_release_user_format( This );
/* Free action mapping */ free( This->action_map ); @@ -1387,11 +1386,11 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co TRACE( "Axis mode: %s\n", value->dwData == DIPROPAXISMODE_ABS ? "absolute" : "relative" ); EnterCriticalSection( &impl->crit ); if (impl->acquired) hr = DIERR_ACQUIRED; - else if (!impl->data_format.user_df) hr = DI_OK; + else if (!impl->user_format) hr = DI_OK; else { - impl->data_format.user_df->dwFlags &= ~DIDFT_AXIS; - impl->data_format.user_df->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; + impl->user_format->dwFlags &= ~DIDFT_AXIS; + impl->user_format->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; hr = DI_OK; } LeaveCriticalSection( &impl->crit ); @@ -1531,12 +1530,12 @@ static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface, EnterCriticalSection( &impl->crit ); if (!impl->acquired) hr = DIERR_NOTACQUIRED; - else if (size != impl->data_format.user_df->dwDataSize) + else if (size != impl->user_format->dwDataSize) hr = DIERR_INVALIDPARAM; else { fill_DataFormat( data, size, impl->device_state, &impl->data_format ); - if (!(impl->data_format.user_df->dwFlags & DIDF_ABSAXIS)) + if (!(impl->user_format->dwFlags & DIDF_ABSAXIS)) impl->vtbl->enum_objects( iface, &filter, DIDFT_RELAXIS, reset_axis_data, impl->device_state ); hr = DI_OK; } diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 7ee0ef312c0..4420f59cc6d 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -44,7 +44,6 @@ typedef struct
int *offsets; /* object offsets */ LPDIDATAFORMAT wine_df; /* wine internal data format */ - LPDIDATAFORMAT user_df; /* user defined data format */ } DataFormat;
typedef struct @@ -103,6 +102,7 @@ struct dinput_device DWORD buffersize; /* size of the queue - set in 'SetProperty' */
DataFormat data_format; /* user data format and wine to user format converter */ + DIDATAFORMAT *user_format;
/* Action mapping */ int num_actions; /* number of actions mapped */ diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 4e1762fbc50..628011c13e1 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -189,7 +189,7 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA state->lX += rel.x; state->lY += rel.y;
- if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) { pt.x = state->lX; pt.y = state->lY; @@ -269,7 +269,7 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam state->lX += pt.x = hook->pt.x - pt.x; state->lY += pt.y = hook->pt.y - pt.y;
- if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) { pt1.x = state->lX; pt1.y = state->lY; @@ -409,7 +409,7 @@ static HRESULT mouse_acquire( IDirectInputDevice8W *iface )
/* Init the mouse state */ GetCursorPos( &point ); - if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) { state->lX = point.x; state->lY = point.y;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 36 +++++++++--------------------------- dlls/dinput8/tests/hid.c | 1 - 2 files changed, 9 insertions(+), 28 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 07c4bba04c0..c6db17dcaa0 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -580,22 +580,6 @@ failed: return DIERR_OUTOFMEMORY; }
-static int verify_offset(const DataFormat *df, int offset) -{ - int i; - - if (!df->offsets) - return -1; - - for (i = df->wine_df->dwNumObjs - 1; i >= 0; i--) - { - if (df->offsets[i] == offset) - return offset; - } - - return -1; -} - static int id_to_object( LPCDIDATAFORMAT df, int id ) { int i; @@ -1320,6 +1304,8 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co { struct set_object_property_params params = {.iface = iface, .header = header, .property = LOWORD( guid )}; struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); + DWORD object_mask = DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV; + DIDEVICEOBJECTINSTANCEW instance; DIPROPHEADER filter; HRESULT hr;
@@ -1421,18 +1407,14 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co case (DWORD_PTR)DIPROP_APPDATA: { const DIPROPPOINTER *value = (const DIPROPPOINTER *)header; - int offset = -1; + int user_offset; if (header->dwSize != sizeof(DIPROPPOINTER)) return DIERR_INVALIDPARAM; - - if (header->dwHow == DIPH_BYID) - offset = id_to_offset( &impl->data_format, header->dwObj ); - else if (header->dwHow == DIPH_BYOFFSET) - offset = verify_offset( &impl->data_format, header->dwObj ); - else - return DIERR_UNSUPPORTED; - - if (offset == -1) return DIERR_OBJECTNOTFOUND; - if (!set_app_data( impl, offset, value->uData )) return DIERR_OUTOFMEMORY; + if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; + hr = impl->vtbl->enum_objects( iface, &filter, object_mask, find_object, &instance ); + if (FAILED(hr)) return hr; + if (hr == DIENUM_CONTINUE) return DIERR_OBJECTNOTFOUND; + if ((user_offset = id_to_offset( &impl->data_format, instance.dwType )) < 0) return DIERR_OBJECTNOTFOUND; + if (!set_app_data( impl, user_offset, value->uData )) return DIERR_OUTOFMEMORY; return DI_OK; } default: diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index bf3a9801689..6798df914a4 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -4785,7 +4785,6 @@ static void test_simple_joystick(void) prop_pointer.diph.dwObj = MAKELONG( HID_USAGE_GENERIC_X, HID_USAGE_PAGE_GENERIC ); prop_pointer.uData = 0xfeedcafe; hr = IDirectInputDevice8_SetProperty( device, DIPROP_APPDATA, &prop_pointer.diph ); - todo_wine ok( hr == DI_OK, "SetProperty DIPROP_APPDATA returned %#x\n", hr );
prop_dword.dwData = 0xdeadbeef;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 20 ++------------------ dlls/dinput/device_private.h | 1 - 2 files changed, 2 insertions(+), 19 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index c6db17dcaa0..e0e59012611 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -342,10 +342,6 @@ static void fill_DataFormat( void *out, DWORD size, const void *in, const DataFo char *out_c = out;
memset(out, 0, size); - if (df->dt == NULL) { - /* This means that the app uses Wine's internal data format */ - memcpy(out, in, min(size, df->internal_format_size)); - } else { for (i = 0; i < df->size; i++) { if (df->dt[i].offset_in >= 0) { switch (df->dt[i].size) { @@ -396,7 +392,6 @@ static void fill_DataFormat( void *out, DWORD size, const void *in, const DataFo break; } } - } } }
@@ -444,7 +439,6 @@ static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const DataFormat *format = &impl->data_format; DataTransform *dt; unsigned int i, j; - int same = 1; int *done; int index = 0; DWORD next = 0; @@ -517,11 +511,8 @@ static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const format->offsets[i] = asked_format->rgodf[j].dwOfs; dt[index].value = 0; next = next + dt[index].size; - - if (format->wine_df->rgodf[i].dwOfs != dt[index].offset_out) - same = 0; - - index++; + + index++; break; } } @@ -540,8 +531,6 @@ static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const TRACE(" * dwFlags: 0x%08x\n", asked_format->rgodf[j].dwFlags); TRACE(" "); _dump_ObjectDataFormat_flags(asked_format->rgodf[j].dwFlags); TRACE("\n");
- same = 0; - if (!(asked_format->rgodf[j].dwType & DIDFT_POV)) continue; /* fill_DataFormat memsets the buffer to 0 */
@@ -556,12 +545,7 @@ static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const } }
- format->internal_format_size = format->wine_df->dwDataSize; format->size = index; - if (same) { - free( dt ); - dt = NULL; - } format->dt = dt;
free( done ); diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 4420f59cc6d..1b81a374058 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -39,7 +39,6 @@ typedef struct typedef struct { int size; - int internal_format_size; DataTransform *dt;
int *offsets; /* object offsets */