2000-11-05 21:25:02 +01:00
|
|
|
/* DirectInput Device
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998,1999 Lionel Ulmer
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-11-05 21:25:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* This file contains all the Device specific functions that can be used as stubs
|
|
|
|
by real device implementations.
|
|
|
|
|
|
|
|
It also contains all the helper functions.
|
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2021-11-18 09:53:13 +01:00
|
|
|
#include <math.h>
|
2021-10-11 10:10:58 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "winbase.h"
|
2007-09-25 03:34:27 +02:00
|
|
|
#include "winreg.h"
|
2006-03-18 19:26:37 +01:00
|
|
|
#include "winuser.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "dinput.h"
|
2021-10-11 10:10:56 +02:00
|
|
|
#include "dinputd.h"
|
2021-10-18 10:21:52 +02:00
|
|
|
#include "hidusage.h"
|
2021-10-11 10:10:56 +02:00
|
|
|
|
|
|
|
#include "initguid.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "device_private.h"
|
2006-03-18 19:26:37 +01:00
|
|
|
#include "dinput_private.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2021-10-11 10:10:58 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2018-07-03 00:04:47 +02:00
|
|
|
#define WM_WINE_NOTIFY_ACTIVITY WM_USER
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2021-10-11 10:10:56 +02:00
|
|
|
/* Windows uses this GUID for guidProduct on non-keyboard/mouse devices.
|
|
|
|
* Data1 contains the device VID (low word) and PID (high word).
|
|
|
|
* Data4 ends with the ASCII bytes "PIDVID".
|
|
|
|
*/
|
|
|
|
DEFINE_GUID( dinput_pidvid_guid, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 'P', 'I', 'D', 'V', 'I', 'D' );
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static inline struct dinput_device *impl_from_IDirectInputDevice8W( IDirectInputDevice8W *iface )
|
2011-01-09 23:43:21 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
return CONTAINING_RECORD( iface, struct dinput_device, IDirectInputDevice8W_iface );
|
2011-01-09 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl( struct dinput_device *This )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return &This->IDirectInputDevice8A_iface;
|
2011-01-09 23:43:55 +01:00
|
|
|
}
|
2021-10-27 09:40:59 +02:00
|
|
|
static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl( struct dinput_device *This )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return &This->IDirectInputDevice8W_iface;
|
2011-01-09 23:43:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-28 10:12:30 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:02:45 +01:00
|
|
|
static inline BOOL is_exclusively_acquired( struct dinput_device *device )
|
|
|
|
{
|
2022-01-24 12:02:46 +01:00
|
|
|
return device->status == STATUS_ACQUIRED && (device->dwCoopLevel & DISCL_EXCLUSIVE);
|
2022-01-24 12:02:45 +01:00
|
|
|
}
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Various debugging tools
|
|
|
|
*/
|
2008-12-03 12:13:37 +01:00
|
|
|
static void _dump_cooperativelevel_DI(DWORD dwFlags) {
|
2004-06-02 02:36:54 +02:00
|
|
|
if (TRACE_ON(dinput)) {
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int i;
|
2004-06-02 02:36:54 +02:00
|
|
|
static const struct {
|
|
|
|
DWORD mask;
|
|
|
|
const char *name;
|
|
|
|
} flags[] = {
|
|
|
|
#define FE(x) { x, #x}
|
|
|
|
FE(DISCL_BACKGROUND),
|
|
|
|
FE(DISCL_EXCLUSIVE),
|
|
|
|
FE(DISCL_FOREGROUND),
|
2006-07-28 16:13:21 +02:00
|
|
|
FE(DISCL_NONEXCLUSIVE),
|
|
|
|
FE(DISCL_NOWINKEY)
|
2000-11-05 21:25:02 +01:00
|
|
|
#undef FE
|
2004-06-02 02:36:54 +02:00
|
|
|
};
|
2007-12-18 10:01:51 +01:00
|
|
|
TRACE(" cooperative level : ");
|
2018-10-14 23:56:43 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(flags); i++)
|
2004-06-02 02:36:54 +02:00
|
|
|
if (flags[i].mask & dwFlags)
|
2007-12-12 08:48:31 +01:00
|
|
|
TRACE("%s ",flags[i].name);
|
|
|
|
TRACE("\n");
|
2004-06-02 02:36:54 +02:00
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2007-09-25 03:34:32 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Get the default and the app-specific config keys.
|
|
|
|
*/
|
|
|
|
BOOL get_app_key(HKEY *defkey, HKEY *appkey)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH+16];
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
*appkey = 0;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
|
|
|
|
if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", defkey))
|
|
|
|
*defkey = 0;
|
|
|
|
|
|
|
|
len = GetModuleFileNameA(0, buffer, MAX_PATH);
|
|
|
|
if (len && len < MAX_PATH)
|
|
|
|
{
|
|
|
|
HKEY tmpkey;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
|
|
|
|
if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
|
|
|
|
{
|
|
|
|
char *p, *appname = buffer;
|
|
|
|
if ((p = strrchr(appname, '/'))) appname = p + 1;
|
|
|
|
if ((p = strrchr(appname, '\\'))) appname = p + 1;
|
|
|
|
strcat(appname, "\\DirectInput");
|
|
|
|
|
2007-09-29 18:23:11 +02:00
|
|
|
if (RegOpenKeyA(tmpkey, appname, appkey)) *appkey = 0;
|
2007-09-25 03:34:32 +02:00
|
|
|
RegCloseKey(tmpkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *defkey || *appkey;
|
|
|
|
}
|
|
|
|
|
2007-09-25 03:34:27 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Get a config key from either the app-specific or the default config
|
|
|
|
*/
|
2021-09-15 09:29:50 +02:00
|
|
|
DWORD get_config_key( HKEY defkey, HKEY appkey, const WCHAR *name, WCHAR *buffer, DWORD size )
|
2007-09-25 03:34:27 +02:00
|
|
|
{
|
2021-09-15 09:29:50 +02:00
|
|
|
if (appkey && !RegQueryValueExW( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
|
2007-09-25 03:34:27 +02:00
|
|
|
|
2021-09-15 09:29:50 +02:00
|
|
|
if (defkey && !RegQueryValueExW( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
|
2007-09-25 03:34:27 +02:00
|
|
|
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2021-10-11 10:10:55 +02:00
|
|
|
BOOL device_instance_is_disabled( DIDEVICEINSTANCEW *instance, BOOL *override )
|
|
|
|
{
|
|
|
|
static const WCHAR disabled_str[] = {'d', 'i', 's', 'a', 'b', 'l', 'e', 'd', 0};
|
|
|
|
static const WCHAR override_str[] = {'o', 'v', 'e', 'r', 'r', 'i', 'd', 'e', 0};
|
|
|
|
static const WCHAR joystick_key[] = {'J', 'o', 'y', 's', 't', 'i', 'c', 'k', 's', 0};
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
HKEY hkey, appkey, temp;
|
|
|
|
BOOL disable = FALSE;
|
|
|
|
|
|
|
|
get_app_key( &hkey, &appkey );
|
|
|
|
if (override) *override = FALSE;
|
|
|
|
|
|
|
|
/* Joystick settings are in the 'joysticks' subkey */
|
|
|
|
if (appkey)
|
|
|
|
{
|
|
|
|
if (RegOpenKeyW( appkey, joystick_key, &temp )) temp = 0;
|
|
|
|
RegCloseKey( appkey );
|
|
|
|
appkey = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hkey)
|
|
|
|
{
|
|
|
|
if (RegOpenKeyW( hkey, joystick_key, &temp )) temp = 0;
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
hkey = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for the "controllername"="disabled" key */
|
|
|
|
if (!get_config_key( hkey, appkey, instance->tszInstanceName, buffer, sizeof(buffer) ))
|
|
|
|
{
|
2021-10-11 10:10:58 +02:00
|
|
|
if (!wcscmp( disabled_str, buffer ))
|
2021-10-11 10:10:55 +02:00
|
|
|
{
|
|
|
|
TRACE( "Disabling joystick '%s' based on registry key.\n", debugstr_w(instance->tszInstanceName) );
|
|
|
|
disable = TRUE;
|
|
|
|
}
|
2021-10-11 10:10:58 +02:00
|
|
|
else if (override && !wcscmp( override_str, buffer ))
|
2021-10-11 10:10:55 +02:00
|
|
|
{
|
|
|
|
TRACE( "Force enabling joystick '%s' based on registry key.\n", debugstr_w(instance->tszInstanceName) );
|
|
|
|
*override = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appkey) RegCloseKey( appkey );
|
|
|
|
if (hkey) RegCloseKey( hkey );
|
|
|
|
|
|
|
|
return disable;
|
|
|
|
}
|
|
|
|
|
2021-10-28 10:12:32 +02:00
|
|
|
static void dinput_device_release_user_format( struct dinput_device *impl )
|
2004-09-02 22:09:54 +02:00
|
|
|
{
|
2021-10-29 09:40:39 +02:00
|
|
|
if (impl->user_format) free( impl->user_format->rgodf );
|
2021-10-28 10:12:32 +02:00
|
|
|
free( impl->user_format );
|
|
|
|
impl->user_format = NULL;
|
2004-09-02 22:09:54 +02:00
|
|
|
}
|
|
|
|
|
2008-12-03 12:13:37 +01:00
|
|
|
static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx)
|
2007-01-04 07:04:24 +01:00
|
|
|
{
|
|
|
|
if (idx < 0 || idx >= df->dwNumObjs) return NULL;
|
|
|
|
return (LPDIOBJECTDATAFORMAT)((LPBYTE)df->rgodf + idx * df->dwObjSize);
|
|
|
|
}
|
|
|
|
|
2011-07-21 20:36:31 +02:00
|
|
|
/* dataformat_to_odf_by_type
|
|
|
|
* Find the Nth object of the selected type in the DataFormat
|
|
|
|
*/
|
|
|
|
LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type)
|
|
|
|
{
|
|
|
|
int i, nfound = 0;
|
|
|
|
|
|
|
|
for (i=0; i < df->dwNumObjs; i++)
|
|
|
|
{
|
|
|
|
LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(df, i);
|
|
|
|
|
|
|
|
if (odf->dwType & type)
|
|
|
|
{
|
|
|
|
if (n == nfound)
|
|
|
|
return odf;
|
|
|
|
|
|
|
|
nfound++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-29 09:40:40 +02:00
|
|
|
static BOOL match_device_object( DIDATAFORMAT *device_format, DIDATAFORMAT *user_format,
|
2022-01-04 10:41:09 +01:00
|
|
|
const DIDATAFORMAT *format, const DIOBJECTDATAFORMAT *match_obj, DWORD version )
|
2006-12-10 22:15:20 +01:00
|
|
|
{
|
2021-10-29 09:40:40 +02:00
|
|
|
DWORD i, device_instance, instance = DIDFT_GETINSTANCE( match_obj->dwType );
|
2021-10-29 09:40:39 +02:00
|
|
|
DIOBJECTDATAFORMAT *device_obj, *user_obj;
|
2021-10-29 09:40:40 +02:00
|
|
|
|
2022-01-04 10:41:09 +01:00
|
|
|
if (version < 0x0700 && instance == 0xff) instance = 0xffff;
|
|
|
|
|
2021-10-29 09:40:40 +02:00
|
|
|
for (i = 0; i < device_format->dwNumObjs; i++)
|
2006-12-12 16:58:40 +01:00
|
|
|
{
|
2021-10-29 09:40:39 +02:00
|
|
|
user_obj = user_format->rgodf + i;
|
2021-10-29 09:40:40 +02:00
|
|
|
device_obj = device_format->rgodf + i;
|
|
|
|
device_instance = DIDFT_GETINSTANCE( device_obj->dwType );
|
2021-10-29 09:40:39 +02:00
|
|
|
|
2021-10-29 09:40:40 +02:00
|
|
|
if (!(user_obj->dwType & DIDFT_OPTIONAL)) continue; /* already matched */
|
|
|
|
if (match_obj->pguid && device_obj->pguid && !IsEqualGUID( device_obj->pguid, match_obj->pguid )) continue;
|
|
|
|
if (instance != DIDFT_GETINSTANCE( DIDFT_ANYINSTANCE ) && instance != device_instance) continue;
|
|
|
|
if (!(DIDFT_GETTYPE( match_obj->dwType ) & DIDFT_GETTYPE( device_obj->dwType ))) continue;
|
|
|
|
|
|
|
|
TRACE( "match %s with device %s\n", debugstr_diobjectdataformat( match_obj ),
|
|
|
|
debugstr_diobjectdataformat( device_obj ) );
|
|
|
|
|
|
|
|
*user_obj = *device_obj;
|
|
|
|
user_obj->dwOfs = match_obj->dwOfs;
|
|
|
|
return TRUE;
|
2004-06-02 02:36:54 +02:00
|
|
|
}
|
2009-01-04 01:53:22 +01:00
|
|
|
|
2021-10-29 09:40:40 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const DIDATAFORMAT *format )
|
|
|
|
{
|
2021-10-29 09:40:41 +02:00
|
|
|
DIDATAFORMAT *user_format, *device_format = impl->device_format;
|
2021-10-29 09:40:40 +02:00
|
|
|
DIOBJECTDATAFORMAT *user_obj, *match_obj;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!device_format) return DIERR_INVALIDPARAM;
|
|
|
|
if (!(user_format = malloc( sizeof(DIDATAFORMAT) ))) return DIERR_OUTOFMEMORY;
|
|
|
|
*user_format = *device_format;
|
|
|
|
user_format->dwFlags = format->dwFlags;
|
|
|
|
user_format->dwDataSize = format->dwDataSize;
|
|
|
|
user_format->dwNumObjs += format->dwNumObjs;
|
|
|
|
if (!(user_format->rgodf = calloc( user_format->dwNumObjs, sizeof(DIOBJECTDATAFORMAT) )))
|
|
|
|
{
|
|
|
|
free( user_format );
|
|
|
|
return DIERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_obj = user_format->rgodf + user_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf) user_obj->dwType |= DIDFT_OPTIONAL;
|
|
|
|
|
|
|
|
for (i = 0; i < format->dwNumObjs; ++i)
|
|
|
|
{
|
|
|
|
match_obj = format->rgodf + i;
|
|
|
|
|
2022-01-04 10:41:09 +01:00
|
|
|
if (!match_device_object( device_format, user_format, format, match_obj, impl->dinput->dwVersion ))
|
2021-10-29 09:40:40 +02:00
|
|
|
{
|
|
|
|
WARN( "object %s not found\n", debugstr_diobjectdataformat( match_obj ) );
|
|
|
|
if (!(match_obj->dwType & DIDFT_OPTIONAL)) goto failed;
|
|
|
|
user_obj = user_format->rgodf + device_format->dwNumObjs + i;
|
|
|
|
*user_obj = *match_obj;
|
2021-10-29 09:40:39 +02:00
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
2021-10-29 09:40:40 +02:00
|
|
|
|
|
|
|
user_obj = user_format->rgodf + user_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf) user_obj->dwType &= ~DIDFT_OPTIONAL;
|
2006-12-10 22:15:20 +01:00
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
impl->user_format = user_format;
|
2006-12-12 16:57:54 +01:00
|
|
|
return DI_OK;
|
|
|
|
|
|
|
|
failed:
|
2021-10-29 09:40:40 +02:00
|
|
|
free( user_format->rgodf );
|
2021-10-29 09:40:39 +02:00
|
|
|
free( user_format );
|
2021-10-29 09:40:40 +02:00
|
|
|
return DIERR_INVALIDPARAM;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
static int id_to_offset( struct dinput_device *impl, int id )
|
2006-12-10 22:15:29 +01:00
|
|
|
{
|
2021-10-29 09:40:41 +02:00
|
|
|
DIDATAFORMAT *device_format = impl->device_format, *user_format = impl->user_format;
|
2021-10-29 09:40:39 +02:00
|
|
|
DIOBJECTDATAFORMAT *user_obj;
|
2006-12-10 22:15:29 +01:00
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
if (!user_format) return -1;
|
2006-12-10 22:15:29 +01:00
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
user_obj = user_format->rgodf + device_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf)
|
|
|
|
{
|
|
|
|
if (!user_obj->dwType) continue;
|
|
|
|
if ((user_obj->dwType & 0x00ffffff) == (id & 0x00ffffff)) return user_obj->dwOfs;
|
|
|
|
}
|
2007-01-06 01:14:55 +01:00
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
return -1;
|
2007-01-06 01:14:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static DWORD semantic_to_obj_id( struct dinput_device *This, DWORD dwSemantic )
|
2011-07-02 06:06:37 +02:00
|
|
|
{
|
|
|
|
DWORD type = (0x0000ff00 & dwSemantic) >> 8;
|
2021-10-13 09:21:20 +02:00
|
|
|
BOOL byofs = (dwSemantic & 0x80000000) != 0;
|
|
|
|
DWORD value = (dwSemantic & 0x000000ff);
|
2013-10-07 22:49:35 +02:00
|
|
|
BOOL found = FALSE;
|
2021-10-13 09:21:20 +02:00
|
|
|
DWORD instance;
|
2011-07-02 06:06:37 +02:00
|
|
|
int i;
|
|
|
|
|
2021-10-29 09:40:41 +02:00
|
|
|
for (i = 0; i < This->device_format->dwNumObjs && !found; i++)
|
2011-07-02 06:06:37 +02:00
|
|
|
{
|
2021-10-29 09:40:41 +02:00
|
|
|
LPDIOBJECTDATAFORMAT odf = dataformat_to_odf( This->device_format, i );
|
2011-07-02 06:06:37 +02:00
|
|
|
|
2021-10-13 09:21:20 +02:00
|
|
|
if (byofs && value != odf->dwOfs) continue;
|
|
|
|
if (!byofs && value != DIDFT_GETINSTANCE(odf->dwType)) continue;
|
|
|
|
instance = DIDFT_GETINSTANCE(odf->dwType);
|
|
|
|
found = TRUE;
|
2011-07-02 06:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) return 0;
|
|
|
|
|
|
|
|
if (type & DIDFT_AXIS) type = DIDFT_RELAXIS;
|
|
|
|
if (type & DIDFT_BUTTON) type = DIDFT_PSHBUTTON;
|
|
|
|
|
2021-10-13 09:21:20 +02:00
|
|
|
return type | (0x0000ff00 & (instance << 8));
|
2011-07-02 06:06:37 +02:00
|
|
|
}
|
|
|
|
|
2012-08-24 19:04:52 +02:00
|
|
|
/*
|
|
|
|
* get_mapping_key
|
|
|
|
* Retrieves an open registry key to save the mapping, parametrized for an username,
|
|
|
|
* specific device and specific action mapping guid.
|
|
|
|
*/
|
|
|
|
static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WCHAR *guid)
|
|
|
|
{
|
2021-10-11 10:10:59 +02:00
|
|
|
static const WCHAR *subkey = L"Software\\Wine\\DirectInput\\Mappings\\%s\\%s\\%s";
|
2012-08-24 19:04:52 +02:00
|
|
|
HKEY hkey;
|
|
|
|
WCHAR *keyname;
|
|
|
|
|
2021-10-11 10:10:58 +02:00
|
|
|
SIZE_T len = wcslen( subkey ) + wcslen( username ) + wcslen( device ) + wcslen( guid ) + 1;
|
2021-10-11 10:11:00 +02:00
|
|
|
keyname = malloc( sizeof(WCHAR) * len );
|
2021-10-11 10:10:58 +02:00
|
|
|
swprintf( keyname, len, subkey, username, device, guid );
|
2012-08-24 19:04:52 +02:00
|
|
|
|
|
|
|
/* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */
|
|
|
|
if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey))
|
|
|
|
hkey = 0;
|
|
|
|
|
2021-10-11 10:11:00 +02:00
|
|
|
free( keyname );
|
2012-08-24 19:04:52 +02:00
|
|
|
|
|
|
|
return hkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUsername)
|
|
|
|
{
|
|
|
|
WCHAR *guid_str = NULL;
|
|
|
|
DIDEVICEINSTANCEW didev;
|
|
|
|
HKEY hkey;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
didev.dwSize = sizeof(didev);
|
|
|
|
IDirectInputDevice8_GetDeviceInfo(iface, &didev);
|
|
|
|
|
|
|
|
if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
|
|
|
|
return DI_SETTINGSNOTSAVED;
|
|
|
|
|
|
|
|
hkey = get_mapping_key(didev.tszInstanceName, lpszUsername, guid_str);
|
|
|
|
|
|
|
|
if (!hkey)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(guid_str);
|
|
|
|
return DI_SETTINGSNOTSAVED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write each of the actions mapped for this device.
|
|
|
|
Format is "dwSemantic"="dwObjID" and key is of type REG_DWORD
|
|
|
|
*/
|
|
|
|
for (i = 0; i < lpdiaf->dwNumActions; i++)
|
|
|
|
{
|
|
|
|
WCHAR label[9];
|
|
|
|
|
|
|
|
if (IsEqualGUID(&didev.guidInstance, &lpdiaf->rgoAction[i].guidInstance) &&
|
|
|
|
lpdiaf->rgoAction[i].dwHow != DIAH_UNMAPPED)
|
|
|
|
{
|
2021-10-11 10:10:59 +02:00
|
|
|
swprintf( label, 9, L"%x", lpdiaf->rgoAction[i].dwSemantic );
|
2021-10-11 10:10:58 +02:00
|
|
|
RegSetValueExW( hkey, label, 0, REG_DWORD, (const BYTE *)&lpdiaf->rgoAction[i].dwObjID,
|
|
|
|
sizeof(DWORD) );
|
2012-08-24 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
CoTaskMemFree(guid_str);
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static BOOL load_mapping_settings( struct dinput_device *This, LPDIACTIONFORMATW lpdiaf, const WCHAR *username )
|
2012-08-24 19:04:52 +02:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
WCHAR *guid_str;
|
|
|
|
DIDEVICEINSTANCEW didev;
|
2012-08-28 07:23:03 +02:00
|
|
|
int i, mapped = 0;
|
2012-08-24 19:04:52 +02:00
|
|
|
|
|
|
|
didev.dwSize = sizeof(didev);
|
|
|
|
IDirectInputDevice8_GetDeviceInfo(&This->IDirectInputDevice8W_iface, &didev);
|
|
|
|
|
|
|
|
if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hkey = get_mapping_key(didev.tszInstanceName, username, guid_str);
|
|
|
|
|
|
|
|
if (!hkey)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(guid_str);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to read each action in the DIACTIONFORMAT from registry */
|
|
|
|
for (i = 0; i < lpdiaf->dwNumActions; i++)
|
|
|
|
{
|
|
|
|
DWORD id, size = sizeof(DWORD);
|
|
|
|
WCHAR label[9];
|
|
|
|
|
2021-10-11 10:10:59 +02:00
|
|
|
swprintf( label, 9, L"%x", lpdiaf->rgoAction[i].dwSemantic );
|
2012-08-24 19:04:52 +02:00
|
|
|
|
|
|
|
if (!RegQueryValueExW(hkey, label, 0, NULL, (LPBYTE) &id, &size))
|
|
|
|
{
|
|
|
|
lpdiaf->rgoAction[i].dwObjID = id;
|
|
|
|
lpdiaf->rgoAction[i].guidInstance = didev.guidInstance;
|
2012-08-28 07:23:03 +02:00
|
|
|
lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
|
|
|
|
mapped += 1;
|
2012-08-24 19:04:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
CoTaskMemFree(guid_str);
|
|
|
|
|
2012-08-28 07:23:03 +02:00
|
|
|
return mapped > 0;
|
2012-08-24 19:04:52 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static BOOL set_app_data( struct dinput_device *dev, int offset, UINT_PTR app_data )
|
2021-03-08 13:36:11 +01:00
|
|
|
{
|
|
|
|
int num_actions = dev->num_actions;
|
|
|
|
ActionMap *action_map = dev->action_map, *target_map = NULL;
|
|
|
|
|
|
|
|
if (num_actions == 0)
|
|
|
|
{
|
|
|
|
num_actions = 1;
|
2021-10-11 10:11:00 +02:00
|
|
|
action_map = malloc( sizeof(ActionMap) );
|
2021-03-08 13:36:11 +01:00
|
|
|
if (!action_map) return FALSE;
|
|
|
|
target_map = &action_map[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < num_actions; i++)
|
|
|
|
{
|
|
|
|
if (dev->action_map[i].offset != offset) continue;
|
|
|
|
target_map = &dev->action_map[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target_map)
|
|
|
|
{
|
|
|
|
num_actions++;
|
2021-10-11 10:11:00 +02:00
|
|
|
action_map = realloc( action_map, sizeof(ActionMap) * num_actions );
|
2021-03-08 13:36:11 +01:00
|
|
|
if (!action_map) return FALSE;
|
|
|
|
target_map = &action_map[num_actions-1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target_map->offset = offset;
|
|
|
|
target_map->uAppData = app_data;
|
|
|
|
|
|
|
|
dev->action_map = action_map;
|
|
|
|
dev->num_actions = num_actions;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-12-04 18:54:05 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* queue_event - add new event to the ring queue
|
|
|
|
*/
|
|
|
|
|
2021-05-25 18:48:53 +02:00
|
|
|
void queue_event( IDirectInputDevice8W *iface, int inst_id, DWORD data, DWORD time, DWORD seq )
|
2006-12-04 18:54:05 +01:00
|
|
|
{
|
2020-06-08 09:47:07 +02:00
|
|
|
static ULONGLONG notify_ms = 0;
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2021-10-29 09:40:39 +02:00
|
|
|
int next_pos, ofs = id_to_offset( This, inst_id );
|
2020-06-08 09:47:07 +02:00
|
|
|
ULONGLONG time_ms = GetTickCount64();
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2020-06-08 09:47:07 +02:00
|
|
|
if (time_ms - notify_ms > 1000)
|
|
|
|
{
|
|
|
|
PostMessageW(GetDesktopWindow(), WM_WINE_NOTIFY_ACTIVITY, 0, 0);
|
|
|
|
notify_ms = time_ms;
|
|
|
|
}
|
2018-07-03 00:04:47 +02:00
|
|
|
|
2006-12-04 18:54:05 +01:00
|
|
|
if (!This->queue_len || This->overflow || ofs < 0) return;
|
|
|
|
|
|
|
|
next_pos = (This->queue_head + 1) % This->queue_len;
|
|
|
|
if (next_pos == This->queue_tail)
|
|
|
|
{
|
|
|
|
TRACE(" queue overflowed\n");
|
|
|
|
This->overflow = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
|
|
|
|
data, ofs, This->queue_head, This->queue_len);
|
|
|
|
|
|
|
|
This->data_queue[This->queue_head].dwOfs = ofs;
|
|
|
|
This->data_queue[This->queue_head].dwData = data;
|
|
|
|
This->data_queue[This->queue_head].dwTimeStamp = time;
|
|
|
|
This->data_queue[This->queue_head].dwSequence = seq;
|
2021-03-08 13:36:09 +01:00
|
|
|
This->data_queue[This->queue_head].uAppData = -1;
|
2011-07-02 06:07:15 +02:00
|
|
|
|
|
|
|
/* Set uAppData by means of action mapping */
|
|
|
|
if (This->num_actions > 0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i < This->num_actions; i++)
|
|
|
|
{
|
|
|
|
if (This->action_map[i].offset == ofs)
|
|
|
|
{
|
|
|
|
TRACE("Offset %d mapped to uAppData %lu\n", ofs, This->action_map[i].uAppData);
|
|
|
|
This->data_queue[This->queue_head].uAppData = This->action_map[i].uAppData;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-04 18:54:05 +01:00
|
|
|
This->queue_head = next_pos;
|
2007-01-07 08:14:56 +01:00
|
|
|
/* Send event if asked */
|
2006-12-04 18:54:05 +01:00
|
|
|
}
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Acquire
|
|
|
|
*/
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface )
|
2006-12-01 18:54:42 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:17 +02:00
|
|
|
HRESULT hr = DI_OK;
|
2011-10-20 15:42:44 +02:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
TRACE( "iface %p.\n", iface );
|
2006-12-12 16:58:02 +01:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
EnterCriticalSection( &impl->crit );
|
2022-01-24 12:02:46 +01:00
|
|
|
if (impl->status == STATUS_ACQUIRED)
|
2021-10-13 09:21:17 +02:00
|
|
|
hr = DI_NOEFFECT;
|
2021-10-28 10:12:32 +02:00
|
|
|
else if (!impl->user_format)
|
2021-10-13 09:21:17 +02:00
|
|
|
hr = DIERR_INVALIDPARAM;
|
|
|
|
else if ((impl->dwCoopLevel & DISCL_FOREGROUND) && impl->win != GetForegroundWindow())
|
|
|
|
hr = DIERR_OTHERAPPHASPRIO;
|
|
|
|
else
|
|
|
|
{
|
2022-01-24 12:02:46 +01:00
|
|
|
impl->status = STATUS_ACQUIRED;
|
|
|
|
if (FAILED(hr = impl->vtbl->acquire( iface ))) impl->status = STATUS_UNACQUIRED;
|
2021-10-13 09:21:17 +02:00
|
|
|
}
|
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
if (hr != DI_OK) return hr;
|
2020-06-08 09:47:08 +02:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
dinput_hooks_acquire_device( iface );
|
|
|
|
check_dinput_hooks( iface, TRUE );
|
2006-12-01 18:54:42 +01:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
return hr;
|
2006-12-01 18:54:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Unacquire
|
|
|
|
*/
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_Unacquire( IDirectInputDevice8W *iface )
|
2006-12-01 18:54:42 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:17 +02:00
|
|
|
HRESULT hr = DI_OK;
|
2006-12-01 18:54:42 +01:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
TRACE( "iface %p.\n", iface );
|
2011-10-20 15:42:44 +02:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
EnterCriticalSection( &impl->crit );
|
2022-01-24 12:02:46 +01:00
|
|
|
if (impl->status != STATUS_ACQUIRED) hr = DI_NOEFFECT;
|
2021-10-13 09:21:17 +02:00
|
|
|
else hr = impl->vtbl->unacquire( iface );
|
2022-01-24 12:02:46 +01:00
|
|
|
impl->status = STATUS_UNACQUIRED;
|
2021-10-13 09:21:17 +02:00
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
if (hr != DI_OK) return hr;
|
2020-06-08 09:47:08 +02:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
dinput_hooks_unacquire_device( iface );
|
|
|
|
check_dinput_hooks( iface, FALSE );
|
2006-12-01 18:54:42 +01:00
|
|
|
|
2021-10-13 09:21:17 +02:00
|
|
|
return hr;
|
2006-12-01 18:54:42 +01:00
|
|
|
}
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* IDirectInputDeviceA
|
|
|
|
*/
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_SetDataFormat( IDirectInputDevice8W *iface, const DIDATAFORMAT *format )
|
2006-12-12 16:58:02 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2006-12-12 16:58:02 +01:00
|
|
|
HRESULT res = DI_OK;
|
2021-10-28 10:12:30 +02:00
|
|
|
ULONG i;
|
2006-12-12 16:58:02 +01:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
TRACE( "iface %p, format %p.\n", iface, format );
|
2006-12-12 16:58:02 +01:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if (!format) return E_POINTER;
|
2021-10-28 10:12:30 +02:00
|
|
|
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 ) );
|
|
|
|
}
|
2021-10-27 09:40:58 +02:00
|
|
|
|
|
|
|
if (format->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
|
|
|
|
if (format->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) return DIERR_INVALIDPARAM;
|
2022-01-24 12:02:46 +01:00
|
|
|
if (This->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
|
2006-12-12 16:58:02 +01:00
|
|
|
|
|
|
|
EnterCriticalSection(&This->crit);
|
|
|
|
|
2021-10-11 10:11:00 +02:00
|
|
|
free( This->action_map );
|
2021-03-08 13:36:09 +01:00
|
|
|
This->action_map = NULL;
|
|
|
|
This->num_actions = 0;
|
|
|
|
|
2021-10-28 10:12:32 +02:00
|
|
|
dinput_device_release_user_format( This );
|
|
|
|
res = dinput_device_init_user_format( This, format );
|
2006-12-12 16:58:02 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection(&This->crit);
|
|
|
|
return res;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2006-10-15 19:30:07 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* SetCooperativeLevel
|
|
|
|
*
|
|
|
|
* Set cooperative level and the source window for the events.
|
|
|
|
*/
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_SetCooperativeLevel( IDirectInputDevice8W *iface, HWND hwnd, DWORD flags )
|
2006-10-15 19:30:07 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2021-09-23 10:51:35 +02:00
|
|
|
HRESULT hr;
|
2006-10-15 19:30:07 +02:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
TRACE( "iface %p, hwnd %p, flags %#x.\n", iface, hwnd, flags );
|
|
|
|
|
|
|
|
_dump_cooperativelevel_DI( flags );
|
2006-10-15 19:30:07 +02:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if ((flags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
|
|
|
|
(flags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
|
|
|
|
(flags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
|
|
|
|
(flags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
|
2006-10-15 19:30:07 +02:00
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
2011-11-02 06:45:39 +01:00
|
|
|
if (hwnd && GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD) return E_HANDLE;
|
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if (!hwnd && flags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)) hwnd = GetDesktopWindow();
|
2006-10-15 19:30:07 +02:00
|
|
|
|
2015-11-24 21:25:58 +01:00
|
|
|
if (!IsWindow(hwnd)) return E_HANDLE;
|
2006-10-15 19:30:07 +02:00
|
|
|
|
|
|
|
/* For security reasons native does not allow exclusive background level
|
|
|
|
for mouse and keyboard only */
|
2021-10-27 09:40:58 +02:00
|
|
|
if (flags & DISCL_EXCLUSIVE && flags & DISCL_BACKGROUND &&
|
|
|
|
(IsEqualGUID( &This->guid, &GUID_SysMouse ) || IsEqualGUID( &This->guid, &GUID_SysKeyboard )))
|
2006-10-15 19:30:07 +02:00
|
|
|
return DIERR_UNSUPPORTED;
|
|
|
|
|
|
|
|
/* Store the window which asks for the mouse */
|
2006-12-01 18:56:00 +01:00
|
|
|
EnterCriticalSection(&This->crit);
|
2022-01-24 12:02:46 +01:00
|
|
|
if (This->status == STATUS_ACQUIRED) hr = DIERR_ACQUIRED;
|
2021-09-23 10:51:35 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
This->win = hwnd;
|
2021-10-27 09:40:58 +02:00
|
|
|
This->dwCoopLevel = flags;
|
2021-09-23 10:51:35 +02:00
|
|
|
hr = DI_OK;
|
|
|
|
}
|
2006-12-01 18:56:00 +01:00
|
|
|
LeaveCriticalSection(&This->crit);
|
2006-10-15 19:30:07 +02:00
|
|
|
|
2021-09-23 10:51:35 +02:00
|
|
|
return hr;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetDeviceInfo( IDirectInputDevice8W *iface, DIDEVICEINSTANCEW *instance )
|
2021-10-13 09:21:12 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:12 +02:00
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
TRACE( "iface %p, instance %p.\n", iface, instance );
|
|
|
|
|
|
|
|
if (!instance) return E_POINTER;
|
|
|
|
if (instance->dwSize != sizeof(DIDEVICEINSTANCE_DX3W) &&
|
|
|
|
instance->dwSize != sizeof(DIDEVICEINSTANCEW))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
size = instance->dwSize;
|
|
|
|
memcpy( instance, &impl->instance, size );
|
|
|
|
instance->dwSize = size;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-15 19:29:48 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* SetEventNotification : specifies event to be sent on state change
|
|
|
|
*/
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_SetEventNotification( IDirectInputDevice8W *iface, HANDLE event )
|
2006-10-15 19:29:48 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2006-10-15 19:29:48 +02:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
TRACE( "iface %p, event %p.\n", iface, event );
|
2006-10-15 19:29:48 +02:00
|
|
|
|
2006-12-01 18:56:00 +01:00
|
|
|
EnterCriticalSection(&This->crit);
|
2006-10-15 19:29:48 +02:00
|
|
|
This->hEvent = event;
|
2006-12-01 18:56:00 +01:00
|
|
|
LeaveCriticalSection(&This->crit);
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
void dinput_device_destroy( IDirectInputDevice8W *iface )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-20 11:29:33 +02:00
|
|
|
TRACE( "iface %p.\n", iface );
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-11-18 09:53:12 +01:00
|
|
|
free( This->object_properties );
|
2021-10-11 10:11:00 +02:00
|
|
|
free( This->data_queue );
|
2007-06-27 14:58:27 +02:00
|
|
|
|
|
|
|
/* Free data format */
|
2021-10-29 09:40:41 +02:00
|
|
|
free( This->device_format->rgodf );
|
|
|
|
free( This->device_format );
|
2021-10-28 10:12:32 +02:00
|
|
|
dinput_device_release_user_format( This );
|
2007-06-27 14:58:27 +02:00
|
|
|
|
2011-07-02 06:07:15 +02:00
|
|
|
/* Free action mapping */
|
2021-10-11 10:11:00 +02:00
|
|
|
free( This->action_map );
|
2011-07-02 06:07:15 +02:00
|
|
|
|
2011-01-09 23:43:09 +01:00
|
|
|
IDirectInput_Release(&This->dinput->IDirectInput7A_iface);
|
2007-06-27 14:58:27 +02:00
|
|
|
This->crit.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->crit);
|
|
|
|
|
2021-10-11 10:11:00 +02:00
|
|
|
free( This );
|
2021-10-20 11:29:33 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static ULONG WINAPI dinput_device_Release( IDirectInputDevice8W *iface )
|
2021-10-20 11:29:33 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-20 11:29:33 +02:00
|
|
|
ULONG ref = InterlockedDecrement( &impl->ref );
|
|
|
|
|
|
|
|
TRACE( "iface %p, ref %u.\n", iface, ref );
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
2021-11-12 09:49:38 +01:00
|
|
|
IDirectInputDevice_Unacquire( iface );
|
2021-10-20 11:29:33 +02:00
|
|
|
if (impl->vtbl->release) impl->vtbl->release( iface );
|
2021-10-27 09:40:59 +02:00
|
|
|
else dinput_device_destroy( iface );
|
2021-10-20 11:29:33 +02:00
|
|
|
}
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2019-06-07 07:37:18 +02:00
|
|
|
return ref;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetCapabilities( IDirectInputDevice8W *iface, DIDEVCAPS *caps )
|
2021-10-13 09:21:13 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:13 +02:00
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
TRACE( "iface %p, caps %p.\n", iface, caps );
|
|
|
|
|
|
|
|
if (!caps) return E_POINTER;
|
|
|
|
if (caps->dwSize != sizeof(DIDEVCAPS_DX3) &&
|
|
|
|
caps->dwSize != sizeof(DIDEVCAPS))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
size = caps->dwSize;
|
|
|
|
memcpy( caps, &impl->caps, size );
|
|
|
|
caps->dwSize = size;
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_QueryInterface( IDirectInputDevice8W *iface, const GUID *iid, void **out )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2011-01-19 05:06:48 +01:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
|
2021-05-25 18:48:53 +02:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if (IsEqualGUID( &IID_IDirectInputDeviceA, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDevice2A, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDevice7A, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDevice8A, iid ))
|
2011-01-19 05:06:48 +01:00
|
|
|
{
|
|
|
|
IDirectInputDevice2_AddRef(iface);
|
2021-10-27 09:40:58 +02:00
|
|
|
*out = IDirectInputDevice8A_from_impl( This );
|
2011-01-19 05:06:48 +01:00
|
|
|
return DI_OK;
|
2004-06-02 02:36:54 +02:00
|
|
|
}
|
2021-05-25 18:48:53 +02:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if (IsEqualGUID( &IID_IUnknown, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDeviceW, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDevice2W, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDevice7W, iid ) ||
|
|
|
|
IsEqualGUID( &IID_IDirectInputDevice8W, iid ))
|
2011-01-19 05:06:48 +01:00
|
|
|
{
|
|
|
|
IDirectInputDevice2_AddRef(iface);
|
2021-10-27 09:40:58 +02:00
|
|
|
*out = IDirectInputDevice8W_from_impl( This );
|
2011-01-19 05:06:48 +01:00
|
|
|
return DI_OK;
|
2005-11-28 10:38:59 +01:00
|
|
|
}
|
2011-01-19 05:06:48 +01:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
WARN( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) );
|
2019-05-04 07:30:47 +02:00
|
|
|
return E_NOINTERFACE;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static ULONG WINAPI dinput_device_AddRef( IDirectInputDevice8W *iface )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-20 11:29:33 +02:00
|
|
|
ULONG ref = InterlockedIncrement( &impl->ref );
|
|
|
|
TRACE( "iface %p, ref %u.\n", iface, ref );
|
2019-06-07 08:03:37 +02:00
|
|
|
return ref;
|
2011-01-09 23:43:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_EnumObjects( IDirectInputDevice8W *iface,
|
|
|
|
LPDIENUMDEVICEOBJECTSCALLBACKW callback,
|
|
|
|
void *context, DWORD flags )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-18 10:21:53 +02:00
|
|
|
static const DIPROPHEADER filter =
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(filter),
|
|
|
|
.dwHeaderSize = sizeof(filter),
|
|
|
|
.dwHow = DIPH_DEVICE,
|
|
|
|
};
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-18 10:21:53 +02:00
|
|
|
HRESULT hr;
|
2006-12-28 00:32:19 +01:00
|
|
|
|
2021-10-18 10:21:53 +02:00
|
|
|
TRACE( "iface %p, callback %p, context %p, flags %#x.\n", iface, callback, context, flags );
|
2021-05-25 18:48:56 +02:00
|
|
|
|
2021-10-18 10:21:53 +02:00
|
|
|
if (!callback) return DIERR_INVALIDPARAM;
|
|
|
|
if (flags & ~(DIDFT_AXIS | DIDFT_POV | DIDFT_BUTTON | DIDFT_NODATA | DIDFT_COLLECTION))
|
|
|
|
return DIERR_INVALIDPARAM;
|
2007-01-04 19:59:23 +01:00
|
|
|
|
2021-10-18 10:21:53 +02:00
|
|
|
if (flags == DIDFT_ALL || (flags & DIDFT_AXIS))
|
|
|
|
{
|
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, callback, context );
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr != DIENUM_CONTINUE) return DI_OK;
|
|
|
|
}
|
|
|
|
if (flags == DIDFT_ALL || (flags & DIDFT_POV))
|
|
|
|
{
|
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_POV, callback, context );
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr != DIENUM_CONTINUE) return DI_OK;
|
|
|
|
}
|
|
|
|
if (flags == DIDFT_ALL || (flags & DIDFT_BUTTON))
|
|
|
|
{
|
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_BUTTON, callback, context );
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr != DIENUM_CONTINUE) return DI_OK;
|
|
|
|
}
|
|
|
|
if (flags == DIDFT_ALL || (flags & (DIDFT_NODATA | DIDFT_COLLECTION)))
|
|
|
|
{
|
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_NODATA, callback, context );
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr != DIENUM_CONTINUE) return DI_OK;
|
2007-01-04 19:59:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT enum_object_filter_init( struct dinput_device *impl, DIPROPHEADER *filter )
|
2021-10-20 11:29:29 +02:00
|
|
|
{
|
2021-10-29 09:40:41 +02:00
|
|
|
DIDATAFORMAT *device_format = impl->device_format, *user_format = impl->user_format;
|
2021-10-29 09:40:39 +02:00
|
|
|
DIOBJECTDATAFORMAT *device_obj, *user_obj;
|
2021-10-20 11:29:29 +02:00
|
|
|
|
|
|
|
if (filter->dwHow > DIPH_BYUSAGE) return DIERR_INVALIDPARAM;
|
|
|
|
if (filter->dwHow == DIPH_BYUSAGE && !(impl->instance.dwDevType & DIDEVTYPE_HID)) return DIERR_UNSUPPORTED;
|
|
|
|
if (filter->dwHow != DIPH_BYOFFSET) return DI_OK;
|
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
if (!impl->user_format) return DIERR_NOTFOUND;
|
2021-10-20 11:29:29 +02:00
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
user_obj = user_format->rgodf + device_format->dwNumObjs;
|
|
|
|
device_obj = device_format->rgodf + device_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf && device_obj-- > device_format->rgodf)
|
|
|
|
{
|
|
|
|
if (!user_obj->dwType) continue;
|
|
|
|
if (user_obj->dwOfs == filter->dwObj) break;
|
|
|
|
}
|
|
|
|
if (user_obj < user_format->rgodf) return DIERR_NOTFOUND;
|
2021-10-20 11:29:29 +02:00
|
|
|
|
2021-10-29 09:40:39 +02:00
|
|
|
filter->dwObj = device_obj->dwOfs;
|
2021-10-20 11:29:29 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:53:15 +01:00
|
|
|
static HRESULT check_property( struct dinput_device *impl, const GUID *guid, const DIPROPHEADER *header, BOOL set )
|
|
|
|
{
|
2022-01-04 10:41:08 +01:00
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_VIDPID:
|
|
|
|
case (DWORD_PTR)DIPROP_TYPENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_USERNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_KEYNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_APPDATA:
|
|
|
|
if (impl->dinput->dwVersion < 0x0800) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:53:15 +01:00
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_INSTANCENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_KEYNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_PRODUCTNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_TYPENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_USERNAME:
|
|
|
|
if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
|
|
|
case (DWORD_PTR)DIPROP_AXISMODE:
|
|
|
|
case (DWORD_PTR)DIPROP_BUFFERSIZE:
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
2021-11-18 09:53:15 +01:00
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
case (DWORD_PTR)DIPROP_FFGAIN:
|
|
|
|
case (DWORD_PTR)DIPROP_FFLOAD:
|
|
|
|
case (DWORD_PTR)DIPROP_GRANULARITY:
|
|
|
|
case (DWORD_PTR)DIPROP_JOYSTICKID:
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
case (DWORD_PTR)DIPROP_SCANCODE:
|
|
|
|
case (DWORD_PTR)DIPROP_VIDPID:
|
|
|
|
if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_APPDATA:
|
|
|
|
if (header->dwSize != sizeof(DIPROPPOINTER)) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
2021-11-18 09:53:15 +01:00
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
if (header->dwSize != sizeof(DIPROPRANGE)) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_GUIDANDPATH:
|
|
|
|
if (header->dwSize != sizeof(DIPROPGUIDANDPATH)) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_PRODUCTNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_INSTANCENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_VIDPID:
|
|
|
|
case (DWORD_PTR)DIPROP_JOYSTICKID:
|
|
|
|
case (DWORD_PTR)DIPROP_GUIDANDPATH:
|
|
|
|
case (DWORD_PTR)DIPROP_BUFFERSIZE:
|
|
|
|
case (DWORD_PTR)DIPROP_FFGAIN:
|
|
|
|
case (DWORD_PTR)DIPROP_TYPENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_USERNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
|
|
|
case (DWORD_PTR)DIPROP_AXISMODE:
|
|
|
|
case (DWORD_PTR)DIPROP_FFLOAD:
|
|
|
|
if (header->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED;
|
|
|
|
if (header->dwObj) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
2021-11-18 09:53:15 +01:00
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
case (DWORD_PTR)DIPROP_GRANULARITY:
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
2021-11-18 09:53:15 +01:00
|
|
|
if (header->dwHow == DIPH_DEVICE && !set) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_KEYNAME:
|
|
|
|
if (header->dwHow == DIPH_DEVICE) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_SCANCODE:
|
|
|
|
case (DWORD_PTR)DIPROP_APPDATA:
|
|
|
|
if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
{
|
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
|
|
|
case (DWORD_PTR)DIPROP_AXISMODE:
|
|
|
|
case (DWORD_PTR)DIPROP_BUFFERSIZE:
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
2022-01-24 12:02:46 +01:00
|
|
|
if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
|
2021-11-18 09:53:15 +01:00
|
|
|
break;
|
|
|
|
case (DWORD_PTR)DIPROP_FFLOAD:
|
|
|
|
case (DWORD_PTR)DIPROP_GRANULARITY:
|
|
|
|
case (DWORD_PTR)DIPROP_VIDPID:
|
|
|
|
case (DWORD_PTR)DIPROP_TYPENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_USERNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_GUIDANDPATH:
|
|
|
|
return DIERR_READONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
{
|
|
|
|
const DIPROPRANGE *value = (const DIPROPRANGE *)header;
|
|
|
|
if (value->lMin > value->lMax) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
case (DWORD_PTR)DIPROP_FFGAIN:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
|
|
|
if (value->dwData > 10000) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
|
|
|
case (DWORD_PTR)DIPROP_AXISMODE:
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
2021-11-18 09:53:15 +01:00
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
|
|
|
if (value->dwData > 1) return DIERR_INVALIDPARAM;
|
|
|
|
break;
|
|
|
|
}
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
|
|
|
return DIERR_UNSUPPORTED;
|
2021-11-18 09:53:15 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-18 09:53:17 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_GRANULARITY:
|
|
|
|
if (!impl->caps.dwAxes) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_KEYNAME:
|
|
|
|
/* not supported on the mouse */
|
|
|
|
if (impl->caps.dwAxes && !(impl->caps.dwDevType & DIDEVTYPE_HID)) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
2021-11-18 09:53:17 +01:00
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
2021-11-18 09:53:17 +01:00
|
|
|
if (!impl->object_properties) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
|
2021-11-24 16:09:40 +01:00
|
|
|
case (DWORD_PTR)DIPROP_FFLOAD:
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
|
2022-01-24 12:02:45 +01:00
|
|
|
if (!is_exclusively_acquired( impl )) return DIERR_NOTEXCLUSIVEACQUIRED;
|
2021-11-24 16:09:40 +01:00
|
|
|
/* fallthrough */
|
2021-11-18 09:53:17 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PRODUCTNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_INSTANCENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_VIDPID:
|
|
|
|
case (DWORD_PTR)DIPROP_JOYSTICKID:
|
|
|
|
case (DWORD_PTR)DIPROP_GUIDANDPATH:
|
|
|
|
if (!impl->vtbl->get_property) return DIERR_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-18 09:53:15 +01:00
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-19 09:20:02 +02:00
|
|
|
static BOOL CALLBACK find_object( const DIDEVICEOBJECTINSTANCEW *instance, void *context )
|
|
|
|
{
|
|
|
|
*(DIDEVICEOBJECTINSTANCEW *)context = *instance;
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-11-18 09:53:17 +01:00
|
|
|
struct get_object_property_params
|
|
|
|
{
|
|
|
|
IDirectInputDevice8W *iface;
|
|
|
|
DIPROPHEADER *header;
|
|
|
|
DWORD property;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK get_object_property( const DIDEVICEOBJECTINSTANCEW *instance, void *context )
|
|
|
|
{
|
|
|
|
static const struct object_properties default_properties =
|
|
|
|
{
|
|
|
|
.range_min = DIPROPRANGE_NOMIN,
|
|
|
|
.range_max = DIPROPRANGE_NOMAX,
|
|
|
|
};
|
|
|
|
struct get_object_property_params *params = context;
|
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface );
|
|
|
|
const struct object_properties *properties = NULL;
|
|
|
|
|
|
|
|
if (!impl->object_properties) properties = &default_properties;
|
|
|
|
else properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
|
|
|
|
|
|
|
|
switch (params->property)
|
|
|
|
{
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
{
|
|
|
|
DIPROPRANGE *value = (DIPROPRANGE *)params->header;
|
|
|
|
value->lMin = properties->physical_min;
|
|
|
|
value->lMax = properties->physical_max;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
|
|
|
{
|
|
|
|
DIPROPRANGE *value = (DIPROPRANGE *)params->header;
|
|
|
|
value->lMin = properties->logical_min;
|
|
|
|
value->lMax = properties->logical_max;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2021-11-18 09:53:17 +01:00
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
{
|
|
|
|
DIPROPRANGE *value = (DIPROPRANGE *)params->header;
|
|
|
|
value->lMin = properties->range_min;
|
|
|
|
value->lMax = properties->range_max;
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)params->header;
|
|
|
|
value->dwData = properties->deadzone;
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)params->header;
|
|
|
|
value->dwData = properties->saturation;
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)params->header;
|
|
|
|
value->dwData = properties->calibration_mode;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2021-11-18 09:53:17 +01:00
|
|
|
case (DWORD_PTR)DIPROP_GRANULARITY:
|
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)params->header;
|
|
|
|
value->dwData = 1;
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_KEYNAME:
|
|
|
|
{
|
|
|
|
DIPROPSTRING *value = (DIPROPSTRING *)params->header;
|
|
|
|
lstrcpynW( value->wsz, instance->tszName, ARRAY_SIZE(value->wsz) );
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:53:14 +01:00
|
|
|
static HRESULT dinput_device_get_property( IDirectInputDevice8W *iface, const GUID *guid, DIPROPHEADER *header )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-11-18 09:53:17 +01:00
|
|
|
struct get_object_property_params params = {.iface = iface, .header = header, .property = LOWORD( guid )};
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-19 09:20:02 +02:00
|
|
|
DWORD object_mask = DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV;
|
2021-10-20 11:29:29 +02:00
|
|
|
DIPROPHEADER filter;
|
2021-10-19 09:20:02 +02:00
|
|
|
HRESULT hr;
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-20 11:29:29 +02:00
|
|
|
filter = *header;
|
|
|
|
if (FAILED(hr = enum_object_filter_init( impl, &filter ))) return hr;
|
2021-11-18 09:53:15 +01:00
|
|
|
if (FAILED(hr = check_property( impl, guid, header, FALSE ))) return hr;
|
2021-10-20 11:29:29 +02:00
|
|
|
|
2021-10-19 09:20:02 +02:00
|
|
|
switch (LOWORD( guid ))
|
2006-12-04 18:54:05 +01:00
|
|
|
{
|
2021-10-19 09:20:02 +02:00
|
|
|
case (DWORD_PTR)DIPROP_PRODUCTNAME:
|
|
|
|
case (DWORD_PTR)DIPROP_INSTANCENAME:
|
|
|
|
case (DWORD_PTR)DIPROP_VIDPID:
|
|
|
|
case (DWORD_PTR)DIPROP_JOYSTICKID:
|
|
|
|
case (DWORD_PTR)DIPROP_GUIDANDPATH:
|
2021-11-24 16:09:40 +01:00
|
|
|
case (DWORD_PTR)DIPROP_FFLOAD:
|
2021-10-19 09:20:02 +02:00
|
|
|
return impl->vtbl->get_property( iface, LOWORD( guid ), header, NULL );
|
|
|
|
|
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
2021-11-18 09:53:19 +01:00
|
|
|
case (DWORD_PTR)DIPROP_PHYSICALRANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_LOGICALRANGE:
|
2021-10-19 09:20:02 +02:00
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
case (DWORD_PTR)DIPROP_GRANULARITY:
|
|
|
|
case (DWORD_PTR)DIPROP_KEYNAME:
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
2021-11-18 09:53:17 +01:00
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, object_mask, get_object_property, ¶ms );
|
2021-10-19 09:20:02 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND;
|
2021-11-18 09:53:17 +01:00
|
|
|
return DI_OK;
|
2016-03-31 05:39:21 +02:00
|
|
|
|
2021-10-19 09:20:02 +02:00
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
2021-11-16 08:23:37 +01:00
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)header;
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
|
|
|
|
value->dwData = impl->autocenter;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2021-10-19 09:20:02 +02:00
|
|
|
case (DWORD_PTR)DIPROP_BUFFERSIZE:
|
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)header;
|
|
|
|
value->dwData = impl->buffersize;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_USERNAME:
|
|
|
|
{
|
|
|
|
DIPROPSTRING *value = (DIPROPSTRING *)header;
|
|
|
|
struct DevicePlayer *device_player;
|
|
|
|
LIST_FOR_EACH_ENTRY( device_player, &impl->dinput->device_players, struct DevicePlayer, entry )
|
|
|
|
{
|
|
|
|
if (IsEqualGUID( &device_player->instance_guid, &impl->guid ))
|
2017-03-02 19:51:40 +01:00
|
|
|
{
|
2021-10-19 09:20:02 +02:00
|
|
|
if (!*device_player->username) break;
|
|
|
|
lstrcpynW( value->wsz, device_player->username, ARRAY_SIZE(value->wsz) );
|
|
|
|
return DI_OK;
|
2017-03-02 19:51:40 +01:00
|
|
|
}
|
2016-03-31 05:39:21 +02:00
|
|
|
}
|
2021-10-19 09:20:02 +02:00
|
|
|
return S_FALSE;
|
|
|
|
}
|
2021-10-19 09:20:03 +02:00
|
|
|
case (DWORD_PTR)DIPROP_FFGAIN:
|
|
|
|
{
|
|
|
|
DIPROPDWORD *value = (DIPROPDWORD *)header;
|
2021-11-17 11:51:49 +01:00
|
|
|
value->dwData = impl->device_gain;
|
2021-10-19 09:20:03 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
2021-10-19 09:20:02 +02:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATION:
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
default:
|
|
|
|
FIXME( "Unknown property %s\n", debugstr_guid( guid ) );
|
|
|
|
return DIERR_UNSUPPORTED;
|
2006-12-04 18:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:53:14 +01:00
|
|
|
static HRESULT WINAPI dinput_device_GetProperty( IDirectInputDevice8W *iface, const GUID *guid, DIPROPHEADER *header )
|
|
|
|
{
|
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header );
|
|
|
|
|
|
|
|
if (!header) return DIERR_INVALIDPARAM;
|
|
|
|
if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM;
|
|
|
|
if (!IS_DIPROP( guid )) return DI_OK;
|
|
|
|
|
|
|
|
EnterCriticalSection( &impl->crit );
|
|
|
|
hr = dinput_device_get_property( iface, guid, header );
|
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-10-19 09:20:06 +02:00
|
|
|
struct set_object_property_params
|
|
|
|
{
|
|
|
|
IDirectInputDevice8W *iface;
|
|
|
|
const DIPROPHEADER *header;
|
|
|
|
DWORD property;
|
|
|
|
};
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-19 09:20:06 +02:00
|
|
|
static BOOL CALLBACK set_object_property( const DIDEVICEOBJECTINSTANCEW *instance, void *context )
|
2006-12-04 18:54:05 +01:00
|
|
|
{
|
2021-10-19 09:20:06 +02:00
|
|
|
struct set_object_property_params *params = context;
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface );
|
2021-11-18 09:53:16 +01:00
|
|
|
struct object_properties *properties = NULL;
|
|
|
|
|
|
|
|
if (!impl->object_properties) return DIENUM_STOP;
|
|
|
|
properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
|
|
|
|
|
|
|
|
switch (params->property)
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
{
|
|
|
|
const DIPROPRANGE *value = (const DIPROPRANGE *)params->header;
|
|
|
|
properties->range_min = value->lMin;
|
|
|
|
properties->range_max = value->lMax;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)params->header;
|
|
|
|
properties->deadzone = value->dwData;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)params->header;
|
|
|
|
properties->saturation = value->dwData;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
2021-11-18 09:53:18 +01:00
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)params->header;
|
|
|
|
properties->calibration_mode = value->dwData;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
2021-11-18 09:53:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return DIENUM_STOP;
|
2021-10-19 09:20:06 +02:00
|
|
|
}
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-11-18 09:53:13 +01:00
|
|
|
static BOOL CALLBACK reset_object_value( const DIDEVICEOBJECTINSTANCEW *instance, void *context )
|
|
|
|
{
|
|
|
|
struct dinput_device *impl = context;
|
|
|
|
struct object_properties *properties;
|
|
|
|
LONG tmp = -1;
|
|
|
|
|
|
|
|
if (!impl->object_properties) return DIENUM_STOP;
|
|
|
|
properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
|
|
|
|
|
|
|
|
if (instance->dwType & DIDFT_AXIS)
|
|
|
|
{
|
|
|
|
if (!properties->range_min) tmp = properties->range_max / 2;
|
|
|
|
else tmp = round( (properties->range_min + properties->range_max) / 2.0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
*(LONG *)(impl->device_state + instance->dwOfs) = tmp;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_device_state( IDirectInputDevice8W *iface )
|
|
|
|
{
|
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
|
|
|
DIPROPHEADER filter =
|
|
|
|
{
|
|
|
|
.dwHeaderSize = sizeof(DIPROPHEADER),
|
|
|
|
.dwSize = sizeof(DIPROPHEADER),
|
|
|
|
.dwHow = DIPH_DEVICE,
|
|
|
|
.dwObj = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS | DIDFT_POV, reset_object_value, impl );
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:53:14 +01:00
|
|
|
static HRESULT WINAPI dinput_device_set_property( IDirectInputDevice8W *iface, const GUID *guid,
|
|
|
|
const DIPROPHEADER *header )
|
2021-10-19 09:20:06 +02:00
|
|
|
{
|
|
|
|
struct set_object_property_params params = {.iface = iface, .header = header, .property = LOWORD( guid )};
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-28 10:12:33 +02:00
|
|
|
DWORD object_mask = DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV;
|
|
|
|
DIDEVICEOBJECTINSTANCEW instance;
|
2021-10-20 11:29:29 +02:00
|
|
|
DIPROPHEADER filter;
|
2021-10-19 09:20:06 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-10-20 11:29:29 +02:00
|
|
|
filter = *header;
|
|
|
|
if (FAILED(hr = enum_object_filter_init( impl, &filter ))) return hr;
|
2021-11-18 09:53:15 +01:00
|
|
|
if (FAILED(hr = check_property( impl, guid, header, TRUE ))) return hr;
|
2021-10-20 11:29:29 +02:00
|
|
|
|
2021-10-19 09:20:06 +02:00
|
|
|
switch (LOWORD( guid ))
|
|
|
|
{
|
|
|
|
case (DWORD_PTR)DIPROP_RANGE:
|
|
|
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
|
|
|
case (DWORD_PTR)DIPROP_SATURATION:
|
|
|
|
{
|
2021-10-20 11:29:29 +02:00
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms );
|
2021-11-18 09:53:18 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
reset_device_state( iface );
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_CALIBRATIONMODE:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
|
|
|
if (value->dwData > DIPROPCALIBRATIONMODE_RAW) return DIERR_INVALIDPARAM;
|
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms );
|
2021-10-19 09:20:06 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
2021-11-18 09:53:13 +01:00
|
|
|
reset_device_state( iface );
|
2021-10-19 09:20:06 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
2021-11-18 09:53:14 +01:00
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
|
|
|
|
|
|
|
|
FIXME( "DIPROP_AUTOCENTER stub!\n" );
|
|
|
|
impl->autocenter = value->dwData;
|
|
|
|
return DI_OK;
|
2021-10-19 09:20:06 +02:00
|
|
|
}
|
2021-11-17 11:51:49 +01:00
|
|
|
case (DWORD_PTR)DIPROP_FFGAIN:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
|
|
|
if (!impl->vtbl->send_device_gain) return DIERR_UNSUPPORTED;
|
|
|
|
impl->device_gain = value->dwData;
|
2022-01-24 12:02:45 +01:00
|
|
|
if (!is_exclusively_acquired( impl )) return DI_OK;
|
2021-11-18 09:53:14 +01:00
|
|
|
return impl->vtbl->send_device_gain( iface, impl->device_gain );
|
2021-11-17 11:51:49 +01:00
|
|
|
}
|
2021-10-19 09:20:06 +02:00
|
|
|
case (DWORD_PTR)DIPROP_AXISMODE:
|
2006-12-04 18:54:05 +01:00
|
|
|
{
|
2021-10-19 09:20:06 +02:00
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
|
|
|
|
|
|
|
TRACE( "Axis mode: %s\n", value->dwData == DIPROPAXISMODE_ABS ? "absolute" : "relative" );
|
2021-11-18 09:53:14 +01:00
|
|
|
if (impl->user_format)
|
2006-12-18 07:22:11 +01:00
|
|
|
{
|
2021-10-28 10:12:32 +02:00
|
|
|
impl->user_format->dwFlags &= ~DIDFT_AXIS;
|
|
|
|
impl->user_format->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS;
|
2006-12-18 07:22:11 +01:00
|
|
|
}
|
2021-11-18 09:53:14 +01:00
|
|
|
return DI_OK;
|
2021-10-19 09:20:06 +02:00
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_BUFFERSIZE:
|
|
|
|
{
|
|
|
|
const DIPROPDWORD *value = (const DIPROPDWORD *)header;
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-19 09:20:06 +02:00
|
|
|
TRACE( "buffersize = %d\n", value->dwData );
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-11-18 09:53:14 +01:00
|
|
|
impl->buffersize = value->dwData;
|
|
|
|
impl->queue_len = min( impl->buffersize, 1024 );
|
|
|
|
free( impl->data_queue );
|
2020-01-12 23:33:24 +01:00
|
|
|
|
2021-11-18 09:53:14 +01:00
|
|
|
impl->data_queue = impl->queue_len ? malloc( impl->queue_len * sizeof(DIDEVICEOBJECTDATA) ) : NULL;
|
|
|
|
impl->queue_head = impl->queue_tail = impl->overflow = 0;
|
|
|
|
return DI_OK;
|
2021-10-19 09:20:06 +02:00
|
|
|
}
|
|
|
|
case (DWORD_PTR)DIPROP_APPDATA:
|
|
|
|
{
|
|
|
|
const DIPROPPOINTER *value = (const DIPROPPOINTER *)header;
|
2021-10-28 10:12:33 +02:00
|
|
|
int user_offset;
|
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, object_mask, find_object, &instance );
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr == DIENUM_CONTINUE) return DIERR_OBJECTNOTFOUND;
|
2021-10-29 09:40:39 +02:00
|
|
|
if ((user_offset = id_to_offset( impl, instance.dwType )) < 0) return DIERR_OBJECTNOTFOUND;
|
2021-10-28 10:12:33 +02:00
|
|
|
if (!set_app_data( impl, user_offset, value->uData )) return DIERR_OUTOFMEMORY;
|
2021-10-19 09:20:06 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME( "Unknown property %s\n", debugstr_guid( guid ) );
|
|
|
|
return DIERR_UNSUPPORTED;
|
|
|
|
}
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-19 09:20:06 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
2016-03-31 05:39:21 +02:00
|
|
|
|
2021-11-18 09:53:14 +01:00
|
|
|
static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, const GUID *guid,
|
|
|
|
const DIPROPHEADER *header )
|
|
|
|
{
|
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header );
|
|
|
|
|
|
|
|
if (!header) return DIERR_INVALIDPARAM;
|
|
|
|
if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM;
|
|
|
|
if (!IS_DIPROP( guid )) return DI_OK;
|
|
|
|
|
|
|
|
EnterCriticalSection( &impl->crit );
|
|
|
|
hr = dinput_device_set_property( iface, guid, header );
|
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static void dinput_device_set_username( struct dinput_device *impl, const DIPROPSTRING *value )
|
2021-10-19 09:20:06 +02:00
|
|
|
{
|
|
|
|
struct DevicePlayer *device_player;
|
|
|
|
BOOL found = FALSE;
|
2016-03-31 05:39:21 +02:00
|
|
|
|
2021-10-19 09:20:06 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( device_player, &impl->dinput->device_players, struct DevicePlayer, entry )
|
|
|
|
{
|
|
|
|
if (IsEqualGUID( &device_player->instance_guid, &impl->guid ))
|
2021-03-08 13:36:11 +01:00
|
|
|
{
|
2021-10-19 09:20:06 +02:00
|
|
|
found = TRUE;
|
2021-03-08 13:36:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2006-12-04 18:54:05 +01:00
|
|
|
}
|
2021-10-19 09:20:06 +02:00
|
|
|
if (!found && (device_player = malloc( sizeof(struct DevicePlayer) )))
|
|
|
|
{
|
|
|
|
list_add_tail( &impl->dinput->device_players, &device_player->entry );
|
|
|
|
device_player->instance_guid = impl->guid;
|
|
|
|
}
|
|
|
|
if (device_player)
|
|
|
|
lstrcpynW( device_player->username, value->wsz, ARRAY_SIZE(device_player->username) );
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-18 10:21:56 +02:00
|
|
|
static BOOL CALLBACK get_object_info( const DIDEVICEOBJECTINSTANCEW *instance, void *data )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-18 10:21:56 +02:00
|
|
|
DIDEVICEOBJECTINSTANCEW *dest = data;
|
|
|
|
DWORD size = dest->dwSize;
|
2007-01-04 07:04:24 +01:00
|
|
|
|
2021-10-18 10:21:56 +02:00
|
|
|
memcpy( dest, instance, size );
|
|
|
|
dest->dwSize = size;
|
2007-01-04 07:04:24 +01:00
|
|
|
|
2021-10-18 10:21:56 +02:00
|
|
|
return DIENUM_STOP;
|
|
|
|
}
|
2007-01-04 07:04:24 +01:00
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetObjectInfo( IDirectInputDevice8W *iface,
|
|
|
|
DIDEVICEOBJECTINSTANCEW *instance, DWORD obj, DWORD how )
|
2021-10-18 10:21:56 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-20 11:29:29 +02:00
|
|
|
DIPROPHEADER filter =
|
2007-01-04 07:04:24 +01:00
|
|
|
{
|
2021-10-18 10:21:56 +02:00
|
|
|
.dwSize = sizeof(filter),
|
|
|
|
.dwHeaderSize = sizeof(filter),
|
|
|
|
.dwHow = how,
|
|
|
|
.dwObj = obj
|
|
|
|
};
|
|
|
|
HRESULT hr;
|
2007-01-04 07:04:24 +01:00
|
|
|
|
2021-10-18 10:21:56 +02:00
|
|
|
TRACE( "iface %p, instance %p, obj %#x, how %#x.\n", iface, instance, obj, how );
|
2007-01-04 07:04:24 +01:00
|
|
|
|
2021-10-18 10:21:56 +02:00
|
|
|
if (!instance) return E_POINTER;
|
|
|
|
if (instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W) && instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
if (how == DIPH_DEVICE) return DIERR_INVALIDPARAM;
|
2021-10-20 11:29:29 +02:00
|
|
|
if (FAILED(hr = enum_object_filter_init( impl, &filter ))) return hr;
|
2007-01-04 07:04:24 +01:00
|
|
|
|
2021-10-18 10:21:56 +02:00
|
|
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, get_object_info, instance );
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND;
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface, DWORD size, void *data )
|
2021-10-20 11:29:32 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-29 09:40:41 +02:00
|
|
|
DIDATAFORMAT *device_format = impl->device_format, *user_format;
|
2021-10-29 09:40:39 +02:00
|
|
|
DIOBJECTDATAFORMAT *device_obj, *user_obj;
|
|
|
|
BYTE *user_state = data;
|
2021-10-20 11:29:32 +02:00
|
|
|
DIPROPHEADER filter =
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(filter),
|
|
|
|
.dwHeaderSize = sizeof(filter),
|
|
|
|
.dwHow = DIPH_DEVICE,
|
|
|
|
.dwObj = 0,
|
|
|
|
};
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "iface %p, size %u, data %p.\n", iface, size, data );
|
|
|
|
|
|
|
|
if (!data) return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
IDirectInputDevice2_Poll( iface );
|
|
|
|
|
|
|
|
EnterCriticalSection( &impl->crit );
|
2022-01-24 12:02:47 +01:00
|
|
|
if (impl->status == STATUS_UNPLUGGED)
|
|
|
|
hr = DIERR_INPUTLOST;
|
|
|
|
else if (impl->status != STATUS_ACQUIRED)
|
2021-10-20 11:29:32 +02:00
|
|
|
hr = DIERR_NOTACQUIRED;
|
2021-10-29 09:40:39 +02:00
|
|
|
else if (!(user_format = impl->user_format))
|
|
|
|
hr = DIERR_INVALIDPARAM;
|
|
|
|
else if (size != user_format->dwDataSize)
|
2021-10-20 11:29:32 +02:00
|
|
|
hr = DIERR_INVALIDPARAM;
|
|
|
|
else
|
|
|
|
{
|
2021-10-29 09:40:39 +02:00
|
|
|
memset( user_state, 0, size );
|
|
|
|
|
|
|
|
user_obj = user_format->rgodf + device_format->dwNumObjs;
|
|
|
|
device_obj = device_format->rgodf + device_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf && device_obj-- > device_format->rgodf)
|
|
|
|
{
|
|
|
|
if (user_obj->dwType & DIDFT_BUTTON)
|
|
|
|
user_state[user_obj->dwOfs] = impl->device_state[device_obj->dwOfs];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset optional POVs to their default */
|
|
|
|
user_obj = user_format->rgodf + user_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf + device_format->dwNumObjs)
|
|
|
|
if (user_obj->dwType & DIDFT_POV) *(ULONG *)(user_state + user_obj->dwOfs) = 0xffffffff;
|
|
|
|
|
|
|
|
user_obj = user_format->rgodf + device_format->dwNumObjs;
|
|
|
|
device_obj = device_format->rgodf + device_format->dwNumObjs;
|
|
|
|
while (user_obj-- > user_format->rgodf && device_obj-- > device_format->rgodf)
|
|
|
|
{
|
|
|
|
if (user_obj->dwType & (DIDFT_POV | DIDFT_AXIS))
|
|
|
|
*(ULONG *)(user_state + user_obj->dwOfs) = *(ULONG *)(impl->device_state + device_obj->dwOfs);
|
|
|
|
if (!(user_format->dwFlags & DIDF_ABSAXIS) && (device_obj->dwType & DIDFT_RELAXIS))
|
|
|
|
*(ULONG *)(impl->device_state + device_obj->dwOfs) = 0;
|
|
|
|
}
|
|
|
|
|
2021-10-20 11:29:32 +02:00
|
|
|
hr = DI_OK;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetDeviceData( IDirectInputDevice8W *iface, DWORD size, DIDEVICEOBJECTDATA *data,
|
|
|
|
DWORD *count, DWORD flags )
|
2006-12-04 18:54:05 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This = impl_from_IDirectInputDevice8W( iface );
|
2006-12-04 18:54:05 +01:00
|
|
|
HRESULT ret = DI_OK;
|
|
|
|
int len;
|
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
TRACE( "iface %p, size %u, data %p, count %p, flags %#x.\n", iface, size, data, count, flags );
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if (This->dinput->dwVersion == 0x0800 || size == sizeof(DIDEVICEOBJECTDATA_DX3))
|
2011-10-16 20:36:50 +02:00
|
|
|
{
|
|
|
|
if (!This->queue_len) return DIERR_NOTBUFFERED;
|
2022-01-24 12:02:47 +01:00
|
|
|
if (This->status == STATUS_UNPLUGGED) return DIERR_INPUTLOST;
|
2022-01-24 12:02:46 +01:00
|
|
|
if (This->status != STATUS_ACQUIRED) return DIERR_NOTACQUIRED;
|
2011-10-16 20:36:50 +02:00
|
|
|
}
|
|
|
|
|
2006-12-04 18:54:05 +01:00
|
|
|
if (!This->queue_len)
|
2011-10-14 05:22:26 +02:00
|
|
|
return DI_OK;
|
2021-10-27 09:40:58 +02:00
|
|
|
if (size < sizeof(DIDEVICEOBJECTDATA_DX3)) return DIERR_INVALIDPARAM;
|
2006-12-04 18:54:05 +01:00
|
|
|
|
|
|
|
IDirectInputDevice2_Poll(iface);
|
|
|
|
EnterCriticalSection(&This->crit);
|
|
|
|
|
|
|
|
len = This->queue_head - This->queue_tail;
|
|
|
|
if (len < 0) len += This->queue_len;
|
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if ((*count != INFINITE) && (len > *count)) len = *count;
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
if (data)
|
2006-12-04 18:54:05 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
int n = (This->queue_tail + i) % This->queue_len;
|
2021-10-27 09:40:58 +02:00
|
|
|
memcpy( (char *)data + size * i, This->data_queue + n, size );
|
2006-12-04 18:54:05 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-27 09:40:58 +02:00
|
|
|
*count = len;
|
2006-12-04 18:54:05 +01:00
|
|
|
|
2011-10-16 20:36:48 +02:00
|
|
|
if (This->overflow && This->dinput->dwVersion == 0x0800)
|
2006-12-04 18:54:05 +01:00
|
|
|
ret = DI_BUFFEROVERFLOW;
|
|
|
|
|
|
|
|
if (!(flags & DIGDD_PEEK))
|
|
|
|
{
|
|
|
|
/* Advance reading position */
|
|
|
|
This->queue_tail = (This->queue_tail + len) % This->queue_len;
|
|
|
|
This->overflow = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->crit);
|
|
|
|
|
2021-10-27 09:40:58 +02:00
|
|
|
TRACE( "Returning %d events queued\n", *count );
|
2006-12-04 18:54:05 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_RunControlPanel( IDirectInputDevice8W *iface, HWND hwnd, DWORD flags )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, hwnd %p, flags %#x stub!\n", iface, hwnd, flags );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_Initialize( IDirectInputDevice8W *iface, HINSTANCE instance,
|
|
|
|
DWORD version, const GUID *guid )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, instance %p, version %#x, guid %s stub!\n", iface, instance, version,
|
|
|
|
debugstr_guid( guid ) );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_CreateEffect( IDirectInputDevice8W *iface, const GUID *guid,
|
|
|
|
const DIEFFECT *params, IDirectInputEffect **out,
|
|
|
|
IUnknown *outer )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-11-08 09:35:01 +01:00
|
|
|
DWORD flags;
|
2021-10-21 09:53:45 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "iface %p, guid %s, params %p, out %p, outer %p\n", iface, debugstr_guid( guid ),
|
|
|
|
params, out, outer );
|
2016-08-19 22:59:10 +02:00
|
|
|
|
2021-10-21 09:53:45 +02:00
|
|
|
if (!out) return E_POINTER;
|
|
|
|
*out = NULL;
|
|
|
|
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
|
|
|
|
if (!impl->vtbl->create_effect) return DIERR_UNSUPPORTED;
|
|
|
|
if (FAILED(hr = impl->vtbl->create_effect( iface, out ))) return hr;
|
|
|
|
|
|
|
|
hr = IDirectInputEffect_Initialize( *out, DINPUT_instance, impl->dinput->dwVersion, guid );
|
|
|
|
if (FAILED(hr)) goto failed;
|
|
|
|
if (!params) return DI_OK;
|
2021-11-08 09:35:01 +01:00
|
|
|
|
|
|
|
flags = params->dwSize == sizeof(DIEFFECT_DX6) ? DIEP_ALLPARAMS : DIEP_ALLPARAMS_DX5;
|
2022-01-24 12:02:45 +01:00
|
|
|
if (!is_exclusively_acquired( impl )) flags |= DIEP_NODOWNLOAD;
|
2021-10-21 09:53:45 +02:00
|
|
|
hr = IDirectInputEffect_SetParameters( *out, params, flags );
|
|
|
|
if (FAILED(hr)) goto failed;
|
2021-11-15 11:14:07 +01:00
|
|
|
return DI_OK;
|
2021-10-21 09:53:45 +02:00
|
|
|
|
|
|
|
failed:
|
|
|
|
IDirectInputEffect_Release( *out );
|
|
|
|
*out = NULL;
|
|
|
|
return hr;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_EnumEffects( IDirectInputDevice8W *iface, LPDIENUMEFFECTSCALLBACKW callback,
|
|
|
|
void *context, DWORD type )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-21 09:53:42 +02:00
|
|
|
DIEFFECTINFOW info = {.dwSize = sizeof(info)};
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "iface %p, callback %p, context %p, type %#x.\n", iface, callback, context, type );
|
|
|
|
|
|
|
|
if (!callback) return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
type = DIEFT_GETTYPE( type );
|
|
|
|
|
|
|
|
if (type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_ConstantForce );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_RampForce );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DIEFT_ALL || type == DIEFT_PERIODIC)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Square );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Sine );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Triangle );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_SawtoothUp );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_SawtoothDown );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DIEFT_ALL || type == DIEFT_CONDITION)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Spring );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Damper );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Inertia );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_GetEffectInfo( iface, &info, &GUID_Friction );
|
|
|
|
if (FAILED(hr) && hr != DIERR_DEVICENOTREG) return hr;
|
|
|
|
if (hr == DI_OK && callback( &info, context ) == DIENUM_STOP) return DI_OK;
|
|
|
|
}
|
2019-05-08 07:27:06 +02:00
|
|
|
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetEffectInfo( IDirectInputDevice8W *iface, DIEFFECTINFOW *info,
|
|
|
|
const GUID *guid )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-21 09:53:43 +02:00
|
|
|
|
|
|
|
TRACE( "iface %p, info %p, guid %s.\n", iface, info, debugstr_guid( guid ) );
|
|
|
|
|
|
|
|
if (!info) return E_POINTER;
|
|
|
|
if (info->dwSize != sizeof(DIEFFECTINFOW)) return DIERR_INVALIDPARAM;
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_DEVICENOTREG;
|
|
|
|
if (!impl->vtbl->get_effect_info) return DIERR_UNSUPPORTED;
|
|
|
|
return impl->vtbl->get_effect_info( iface, info, guid );
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetForceFeedbackState( IDirectInputDevice8W *iface, DWORD *out )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-11-24 16:09:41 +01:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-12-01 12:44:58 +01:00
|
|
|
HRESULT hr = DI_OK;
|
2021-11-24 16:09:41 +01:00
|
|
|
|
2021-12-02 10:47:47 +01:00
|
|
|
TRACE( "iface %p, out %p.\n", iface, out );
|
2021-11-24 16:09:41 +01:00
|
|
|
|
2021-10-21 09:53:44 +02:00
|
|
|
if (!out) return E_POINTER;
|
2021-11-24 16:09:41 +01:00
|
|
|
*out = 0;
|
|
|
|
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
|
|
|
|
|
2021-12-01 12:44:58 +01:00
|
|
|
EnterCriticalSection( &impl->crit );
|
2022-01-24 12:02:45 +01:00
|
|
|
if (!is_exclusively_acquired( impl )) hr = DIERR_NOTEXCLUSIVEACQUIRED;
|
|
|
|
else *out = impl->force_feedback_state;
|
2021-12-01 12:44:58 +01:00
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
|
|
|
|
return hr;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_SendForceFeedbackCommand( IDirectInputDevice8W *iface, DWORD command )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-21 09:53:46 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-11-12 09:49:39 +01:00
|
|
|
TRACE( "iface %p, command %#x.\n", iface, command );
|
2021-10-21 09:53:46 +02:00
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case DISFFC_RESET: break;
|
|
|
|
case DISFFC_STOPALL: break;
|
|
|
|
case DISFFC_PAUSE: break;
|
|
|
|
case DISFFC_CONTINUE: break;
|
|
|
|
case DISFFC_SETACTUATORSON: break;
|
|
|
|
case DISFFC_SETACTUATORSOFF: break;
|
|
|
|
default: return DIERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
|
|
|
|
if (!impl->vtbl->send_force_feedback_command) return DIERR_UNSUPPORTED;
|
|
|
|
|
|
|
|
EnterCriticalSection( &impl->crit );
|
2022-01-24 12:02:45 +01:00
|
|
|
if (!is_exclusively_acquired( impl )) hr = DIERR_NOTEXCLUSIVEACQUIRED;
|
2021-11-17 11:51:53 +01:00
|
|
|
else hr = impl->vtbl->send_force_feedback_command( iface, command, FALSE );
|
2021-10-21 09:53:46 +02:00
|
|
|
LeaveCriticalSection( &impl->crit );
|
|
|
|
|
|
|
|
return hr;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_EnumCreatedEffectObjects( IDirectInputDevice8W *iface,
|
|
|
|
LPDIENUMCREATEDEFFECTOBJECTSCALLBACK callback,
|
|
|
|
void *context, DWORD flags )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-21 09:53:47 +02:00
|
|
|
|
|
|
|
TRACE( "iface %p, callback %p, context %p, flags %#x.\n", iface, callback, context, flags );
|
|
|
|
|
|
|
|
if (!callback) return DIERR_INVALIDPARAM;
|
|
|
|
if (flags) return DIERR_INVALIDPARAM;
|
|
|
|
if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DI_OK;
|
|
|
|
if (!impl->vtbl->enum_created_effect_objects) return DIERR_UNSUPPORTED;
|
|
|
|
|
|
|
|
return impl->vtbl->enum_created_effect_objects( iface, callback, context, flags );
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_Escape( IDirectInputDevice8W *iface, DIEFFESCAPE *escape )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, escape %p stub!\n", iface, escape );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_Poll( IDirectInputDevice8W *iface )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-20 11:29:30 +02:00
|
|
|
HRESULT hr = DI_NOEFFECT;
|
2006-12-10 07:56:58 +01:00
|
|
|
|
2021-10-20 11:29:30 +02:00
|
|
|
EnterCriticalSection( &impl->crit );
|
2022-01-24 12:02:47 +01:00
|
|
|
if (impl->status == STATUS_UNPLUGGED) hr = DIERR_INPUTLOST;
|
|
|
|
else if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED;
|
2021-10-20 11:29:30 +02:00
|
|
|
LeaveCriticalSection( &impl->crit );
|
2021-11-12 14:42:33 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
2015-11-05 15:57:29 +01:00
|
|
|
|
2021-10-20 11:29:30 +02:00
|
|
|
if (impl->vtbl->poll) return impl->vtbl->poll( iface );
|
2021-11-08 09:34:57 +01:00
|
|
|
return hr;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_SendDeviceData( IDirectInputDevice8W *iface, DWORD size,
|
|
|
|
const DIDEVICEOBJECTDATA *data, DWORD *count, DWORD flags )
|
2011-01-09 23:43:55 +01:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, size %u, data %p, count %p, flags %#x stub!\n", iface, size, data, count, flags );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_EnumEffectsInFile( IDirectInputDevice8W *iface, const WCHAR *filename,
|
|
|
|
LPDIENUMEFFECTSINFILECALLBACK callback,
|
|
|
|
void *context, DWORD flags )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, filename %s, callback %p, context %p, flags %#x stub!\n", iface,
|
|
|
|
debugstr_w(filename), callback, context, flags );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_WriteEffectToFile( IDirectInputDevice8W *iface, const WCHAR *filename,
|
|
|
|
DWORD count, DIFILEEFFECT *effects, DWORD flags )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, filename %s, count %u, effects %p, flags %#x stub!\n", iface,
|
|
|
|
debugstr_w(filename), count, effects, flags );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_BuildActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format,
|
|
|
|
const WCHAR *username, DWORD flags )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:14 +02:00
|
|
|
BOOL load_success = FALSE, has_actions = FALSE;
|
|
|
|
DWORD genre, username_len = MAX_PATH;
|
|
|
|
WCHAR username_buf[MAX_PATH];
|
|
|
|
const DIDATAFORMAT *df;
|
|
|
|
DWORD devMask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
FIXME( "iface %p, format %p, username %s, flags %#x semi-stub!\n", iface, format,
|
|
|
|
debugstr_w(username), flags );
|
|
|
|
|
|
|
|
if (!format) return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
switch (GET_DIDEVICE_TYPE( impl->instance.dwDevType ))
|
|
|
|
{
|
|
|
|
case DIDEVTYPE_KEYBOARD:
|
|
|
|
case DI8DEVTYPE_KEYBOARD:
|
|
|
|
devMask = DIKEYBOARD_MASK;
|
|
|
|
df = &c_dfDIKeyboard;
|
|
|
|
break;
|
|
|
|
case DIDEVTYPE_MOUSE:
|
|
|
|
case DI8DEVTYPE_MOUSE:
|
|
|
|
devMask = DIMOUSE_MASK;
|
|
|
|
df = &c_dfDIMouse2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
devMask = DIGENRE_ANY;
|
2021-10-29 09:40:41 +02:00
|
|
|
df = impl->device_format;
|
2021-10-13 09:21:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unless asked the contrary by these flags, try to load a previous mapping */
|
|
|
|
if (!(flags & DIDBAM_HWDEFAULTS))
|
|
|
|
{
|
|
|
|
/* Retrieve logged user name if necessary */
|
|
|
|
if (username == NULL) GetUserNameW( username_buf, &username_len );
|
|
|
|
else lstrcpynW( username_buf, username, MAX_PATH );
|
|
|
|
load_success = load_mapping_settings( impl, format, username_buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_success) return DI_OK;
|
|
|
|
|
|
|
|
for (i = 0; i < format->dwNumActions; i++)
|
|
|
|
{
|
|
|
|
/* Don't touch a user configured action */
|
|
|
|
if (format->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
|
|
|
|
|
|
|
|
genre = format->rgoAction[i].dwSemantic & DIGENRE_ANY;
|
|
|
|
if (devMask == genre || (devMask == DIGENRE_ANY && genre != DIMOUSE_MASK && genre != DIKEYBOARD_MASK))
|
|
|
|
{
|
|
|
|
DWORD obj_id = semantic_to_obj_id( impl, format->rgoAction[i].dwSemantic );
|
|
|
|
DWORD type = DIDFT_GETTYPE( obj_id );
|
|
|
|
DWORD inst = DIDFT_GETINSTANCE( obj_id );
|
|
|
|
|
|
|
|
LPDIOBJECTDATAFORMAT odf;
|
|
|
|
|
|
|
|
if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
|
|
|
|
if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
|
|
|
|
|
|
|
|
/* Make sure the object exists */
|
|
|
|
odf = dataformat_to_odf_by_type( df, inst, type );
|
|
|
|
|
|
|
|
if (odf != NULL)
|
|
|
|
{
|
|
|
|
format->rgoAction[i].dwObjID = obj_id;
|
|
|
|
format->rgoAction[i].guidInstance = impl->guid;
|
|
|
|
format->rgoAction[i].dwHow = DIAH_DEFAULT;
|
|
|
|
has_actions = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(flags & DIDBAM_PRESERVE))
|
|
|
|
{
|
|
|
|
/* We must clear action data belonging to other devices */
|
|
|
|
memset( &format->rgoAction[i].guidInstance, 0, sizeof(GUID) );
|
|
|
|
format->rgoAction[i].dwHow = DIAH_UNMAPPED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_actions) return DI_NOEFFECT;
|
|
|
|
if (flags & (DIDBAM_DEFAULT|DIDBAM_PRESERVE|DIDBAM_INITIALIZE|DIDBAM_HWDEFAULTS))
|
|
|
|
FIXME("Unimplemented flags %#x\n", flags);
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format,
|
|
|
|
const WCHAR *username, DWORD flags )
|
2021-10-13 09:21:15 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:15 +02:00
|
|
|
DIDATAFORMAT data_format;
|
|
|
|
DIOBJECTDATAFORMAT *obj_df = NULL;
|
|
|
|
DIPROPDWORD dp;
|
|
|
|
DIPROPRANGE dpr;
|
|
|
|
DIPROPSTRING dps;
|
|
|
|
WCHAR username_buf[MAX_PATH];
|
|
|
|
DWORD username_len = MAX_PATH;
|
|
|
|
int i, action = 0, num_actions = 0;
|
|
|
|
unsigned int offset = 0;
|
|
|
|
const DIDATAFORMAT *df;
|
|
|
|
ActionMap *action_map;
|
|
|
|
|
|
|
|
FIXME( "iface %p, format %p, username %s, flags %#x semi-stub!\n", iface, format,
|
|
|
|
debugstr_w(username), flags );
|
|
|
|
|
|
|
|
if (!format) return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
switch (GET_DIDEVICE_TYPE( impl->instance.dwDevType ))
|
|
|
|
{
|
|
|
|
case DIDEVTYPE_KEYBOARD:
|
|
|
|
case DI8DEVTYPE_KEYBOARD:
|
|
|
|
df = &c_dfDIKeyboard;
|
|
|
|
break;
|
|
|
|
case DIDEVTYPE_MOUSE:
|
|
|
|
case DI8DEVTYPE_MOUSE:
|
|
|
|
df = &c_dfDIMouse2;
|
|
|
|
break;
|
|
|
|
default:
|
2021-10-29 09:40:41 +02:00
|
|
|
df = impl->device_format;
|
2021-10-13 09:21:15 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:02:46 +01:00
|
|
|
if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
|
2021-10-13 09:21:15 +02:00
|
|
|
|
|
|
|
data_format.dwSize = sizeof(data_format);
|
|
|
|
data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
|
|
|
|
data_format.dwFlags = DIDF_RELAXIS;
|
|
|
|
data_format.dwDataSize = format->dwDataSize;
|
|
|
|
|
|
|
|
/* Count the actions */
|
|
|
|
for (i = 0; i < format->dwNumActions; i++)
|
|
|
|
if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance ))
|
|
|
|
num_actions++;
|
|
|
|
|
|
|
|
if (num_actions == 0) return DI_NOEFFECT;
|
|
|
|
|
|
|
|
/* Construct the dataformat and actionmap */
|
|
|
|
obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions );
|
|
|
|
data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
|
|
|
|
data_format.dwNumObjs = num_actions;
|
|
|
|
|
|
|
|
action_map = malloc( sizeof(ActionMap) * num_actions );
|
|
|
|
|
|
|
|
for (i = 0; i < format->dwNumActions; i++)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance ))
|
|
|
|
{
|
|
|
|
DWORD inst = DIDFT_GETINSTANCE( format->rgoAction[i].dwObjID );
|
|
|
|
DWORD type = DIDFT_GETTYPE( format->rgoAction[i].dwObjID );
|
|
|
|
LPDIOBJECTDATAFORMAT obj;
|
|
|
|
|
|
|
|
if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
|
|
|
|
if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
|
|
|
|
|
|
|
|
obj = dataformat_to_odf_by_type( df, inst, type );
|
|
|
|
|
|
|
|
memcpy( &obj_df[action], obj, df->dwObjSize );
|
|
|
|
|
|
|
|
action_map[action].uAppData = format->rgoAction[i].uAppData;
|
|
|
|
action_map[action].offset = offset;
|
|
|
|
obj_df[action].dwOfs = offset;
|
|
|
|
offset += (type & DIDFT_BUTTON) ? 1 : 4;
|
|
|
|
|
|
|
|
action++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirectInputDevice8_SetDataFormat( iface, &data_format );
|
|
|
|
|
|
|
|
impl->action_map = action_map;
|
|
|
|
impl->num_actions = num_actions;
|
|
|
|
|
|
|
|
free( obj_df );
|
|
|
|
|
|
|
|
/* Set the device properties according to the action format */
|
|
|
|
dpr.diph.dwSize = sizeof(DIPROPRANGE);
|
|
|
|
dpr.lMin = format->lAxisMin;
|
|
|
|
dpr.lMax = format->lAxisMax;
|
|
|
|
dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
2021-11-18 09:53:15 +01:00
|
|
|
dpr.diph.dwObj = 0;
|
2021-10-13 09:21:15 +02:00
|
|
|
dpr.diph.dwHow = DIPH_DEVICE;
|
|
|
|
IDirectInputDevice8_SetProperty( iface, DIPROP_RANGE, &dpr.diph );
|
|
|
|
|
|
|
|
if (format->dwBufferSize > 0)
|
|
|
|
{
|
|
|
|
dp.diph.dwSize = sizeof(DIPROPDWORD);
|
|
|
|
dp.dwData = format->dwBufferSize;
|
|
|
|
dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
2021-11-18 09:53:15 +01:00
|
|
|
dp.diph.dwObj = 0;
|
2021-10-13 09:21:15 +02:00
|
|
|
dp.diph.dwHow = DIPH_DEVICE;
|
|
|
|
IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &dp.diph );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve logged user name if necessary */
|
|
|
|
if (username == NULL) GetUserNameW( username_buf, &username_len );
|
|
|
|
else lstrcpynW( username_buf, username, MAX_PATH );
|
|
|
|
|
|
|
|
dps.diph.dwSize = sizeof(dps);
|
|
|
|
dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
dps.diph.dwObj = 0;
|
|
|
|
dps.diph.dwHow = DIPH_DEVICE;
|
|
|
|
if (flags & DIDSAM_NOUSER) dps.wsz[0] = '\0';
|
|
|
|
else lstrcpynW( dps.wsz, username_buf, ARRAY_SIZE(dps.wsz) );
|
2021-10-19 09:20:06 +02:00
|
|
|
dinput_device_set_username( impl, &dps );
|
2021-10-13 09:21:15 +02:00
|
|
|
|
|
|
|
/* Save the settings to disk */
|
|
|
|
save_mapping_settings( iface, format, username_buf );
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
static HRESULT WINAPI dinput_device_GetImageInfo( IDirectInputDevice8W *iface, DIDEVICEIMAGEINFOHEADERW *header )
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2021-10-27 09:40:58 +02:00
|
|
|
FIXME( "iface %p, header %p stub!\n", iface, header );
|
2004-06-02 02:36:54 +02:00
|
|
|
return DI_OK;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
2021-05-28 11:41:27 +02:00
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
extern const IDirectInputDevice8AVtbl dinput_device_a_vtbl;
|
|
|
|
static const IDirectInputDevice8WVtbl dinput_device_w_vtbl =
|
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
2021-10-27 09:40:59 +02:00
|
|
|
dinput_device_QueryInterface,
|
|
|
|
dinput_device_AddRef,
|
|
|
|
dinput_device_Release,
|
2021-10-22 09:33:54 +02:00
|
|
|
/*** IDirectInputDevice methods ***/
|
2021-10-27 09:40:59 +02:00
|
|
|
dinput_device_GetCapabilities,
|
|
|
|
dinput_device_EnumObjects,
|
|
|
|
dinput_device_GetProperty,
|
|
|
|
dinput_device_SetProperty,
|
|
|
|
dinput_device_Acquire,
|
|
|
|
dinput_device_Unacquire,
|
|
|
|
dinput_device_GetDeviceState,
|
|
|
|
dinput_device_GetDeviceData,
|
|
|
|
dinput_device_SetDataFormat,
|
|
|
|
dinput_device_SetEventNotification,
|
|
|
|
dinput_device_SetCooperativeLevel,
|
|
|
|
dinput_device_GetObjectInfo,
|
|
|
|
dinput_device_GetDeviceInfo,
|
|
|
|
dinput_device_RunControlPanel,
|
|
|
|
dinput_device_Initialize,
|
2021-10-22 09:33:54 +02:00
|
|
|
/*** IDirectInputDevice2 methods ***/
|
2021-10-27 09:40:59 +02:00
|
|
|
dinput_device_CreateEffect,
|
|
|
|
dinput_device_EnumEffects,
|
|
|
|
dinput_device_GetEffectInfo,
|
|
|
|
dinput_device_GetForceFeedbackState,
|
|
|
|
dinput_device_SendForceFeedbackCommand,
|
|
|
|
dinput_device_EnumCreatedEffectObjects,
|
|
|
|
dinput_device_Escape,
|
|
|
|
dinput_device_Poll,
|
|
|
|
dinput_device_SendDeviceData,
|
2021-10-22 09:33:54 +02:00
|
|
|
/*** IDirectInputDevice7 methods ***/
|
2021-10-27 09:40:59 +02:00
|
|
|
dinput_device_EnumEffectsInFile,
|
|
|
|
dinput_device_WriteEffectToFile,
|
2021-10-22 09:33:54 +02:00
|
|
|
/*** IDirectInputDevice8 methods ***/
|
2021-10-27 09:40:59 +02:00
|
|
|
dinput_device_BuildActionMap,
|
|
|
|
dinput_device_SetActionMap,
|
|
|
|
dinput_device_GetImageInfo,
|
2021-10-22 09:33:54 +02:00
|
|
|
};
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl,
|
2021-05-28 11:41:28 +02:00
|
|
|
const GUID *guid, IDirectInputImpl *dinput, void **out )
|
2021-05-28 11:41:27 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *This;
|
2021-08-25 18:20:25 +02:00
|
|
|
DIDATAFORMAT *format;
|
|
|
|
|
2021-10-11 10:11:00 +02:00
|
|
|
if (!(This = calloc( 1, size ))) return DIERR_OUTOFMEMORY;
|
|
|
|
if (!(format = calloc( 1, sizeof(*format) )))
|
2021-08-25 18:20:25 +02:00
|
|
|
{
|
2021-10-11 10:11:00 +02:00
|
|
|
free( This );
|
2021-08-25 18:20:25 +02:00
|
|
|
return DIERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2021-05-28 11:41:28 +02:00
|
|
|
This->IDirectInputDevice8A_iface.lpVtbl = &dinput_device_a_vtbl;
|
2021-10-22 09:33:54 +02:00
|
|
|
This->IDirectInputDevice8W_iface.lpVtbl = &dinput_device_w_vtbl;
|
2021-05-28 11:41:27 +02:00
|
|
|
This->ref = 1;
|
|
|
|
This->guid = *guid;
|
2021-10-13 09:21:12 +02:00
|
|
|
This->instance.dwSize = sizeof(DIDEVICEINSTANCEW);
|
2021-10-13 09:21:13 +02:00
|
|
|
This->caps.dwSize = sizeof(DIDEVCAPS);
|
|
|
|
This->caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED;
|
2021-10-29 09:40:41 +02:00
|
|
|
This->device_format = format;
|
2021-11-17 11:51:49 +01:00
|
|
|
This->device_gain = 10000;
|
2021-12-01 12:44:58 +01:00
|
|
|
This->force_feedback_state = DIGFFS_STOPPED | DIGFFS_EMPTY;
|
2021-05-28 11:41:27 +02:00
|
|
|
InitializeCriticalSection( &This->crit );
|
|
|
|
This->dinput = dinput;
|
|
|
|
IDirectInput_AddRef( &dinput->IDirectInput7A_iface );
|
2021-10-22 09:33:54 +02:00
|
|
|
This->vtbl = vtbl;
|
2021-05-28 11:41:27 +02:00
|
|
|
|
|
|
|
*out = This;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2021-10-18 10:21:52 +02:00
|
|
|
|
|
|
|
static const GUID *object_instance_guid( const DIDEVICEOBJECTINSTANCEW *instance )
|
|
|
|
{
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_XAxis )) return &GUID_XAxis;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_YAxis )) return &GUID_YAxis;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_ZAxis )) return &GUID_ZAxis;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_RxAxis )) return &GUID_RxAxis;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_RyAxis )) return &GUID_RyAxis;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_RzAxis )) return &GUID_RzAxis;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_Slider )) return &GUID_Slider;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_Button )) return &GUID_Button;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_Key )) return &GUID_Key;
|
|
|
|
if (IsEqualGUID( &instance->guidType, &GUID_POV )) return &GUID_POV;
|
|
|
|
return &GUID_Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK enum_objects_init( const DIDEVICEOBJECTINSTANCEW *instance, void *data )
|
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( data );
|
2021-10-29 09:40:41 +02:00
|
|
|
DIDATAFORMAT *format = impl->device_format;
|
2021-10-18 10:21:52 +02:00
|
|
|
DIOBJECTDATAFORMAT *obj_format;
|
|
|
|
|
|
|
|
if (!format->rgodf)
|
|
|
|
{
|
|
|
|
format->dwDataSize = max( format->dwDataSize, instance->dwOfs + sizeof(LONG) );
|
|
|
|
if (instance->dwType & DIDFT_BUTTON) impl->caps.dwButtons++;
|
|
|
|
if (instance->dwType & DIDFT_AXIS) impl->caps.dwAxes++;
|
|
|
|
if (instance->dwType & DIDFT_POV) impl->caps.dwPOVs++;
|
|
|
|
if (instance->dwType & (DIDFT_BUTTON|DIDFT_AXIS|DIDFT_POV))
|
|
|
|
{
|
|
|
|
if (!impl->device_state_report_id)
|
|
|
|
impl->device_state_report_id = instance->wReportId;
|
|
|
|
else if (impl->device_state_report_id != instance->wReportId)
|
|
|
|
FIXME( "multiple device state reports found!\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obj_format = format->rgodf + format->dwNumObjs;
|
|
|
|
obj_format->pguid = object_instance_guid( instance );
|
|
|
|
obj_format->dwOfs = instance->dwOfs;
|
|
|
|
obj_format->dwType = instance->dwType;
|
|
|
|
obj_format->dwFlags = instance->dwFlags;
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:53:13 +01:00
|
|
|
if (impl->object_properties && (instance->dwType & (DIDFT_AXIS | DIDFT_POV)))
|
|
|
|
reset_object_value( instance, impl );
|
|
|
|
|
2021-10-18 10:21:52 +02:00
|
|
|
format->dwNumObjs++;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
HRESULT dinput_device_init( IDirectInputDevice8W *iface )
|
2021-10-18 10:21:52 +02:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-29 09:40:41 +02:00
|
|
|
DIDATAFORMAT *format = impl->device_format;
|
2021-10-28 10:12:30 +02:00
|
|
|
ULONG i, size;
|
2021-10-18 10:21:52 +02:00
|
|
|
|
|
|
|
IDirectInputDevice8_EnumObjects( iface, enum_objects_init, iface, DIDFT_ALL );
|
|
|
|
if (format->dwDataSize > DEVICE_STATE_MAX_SIZE)
|
|
|
|
{
|
|
|
|
FIXME( "unable to create device, state is too large\n" );
|
|
|
|
return DIERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = format->dwNumObjs * sizeof(*format->rgodf);
|
|
|
|
if (!(format->rgodf = calloc( 1, size ))) return DIERR_OUTOFMEMORY;
|
2021-11-18 09:53:12 +01:00
|
|
|
|
2021-10-18 10:21:52 +02:00
|
|
|
format->dwSize = sizeof(*format);
|
|
|
|
format->dwObjSize = sizeof(*format->rgodf);
|
|
|
|
format->dwFlags = DIDF_ABSAXIS;
|
|
|
|
format->dwNumObjs = 0;
|
|
|
|
IDirectInputDevice8_EnumObjects( iface, enum_objects_init, iface, DIDFT_ALL );
|
|
|
|
|
2021-10-28 10:12:30 +02:00
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:21:52 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|