From: Claire Girka Subject: [PATCH v3 1/1] mmdevapi: Override product strings for DualSense controller audio devices Message-Id: Date: Thu, 30 Jun 2022 14:20:13 +0000 In-Reply-To: References: From: Claire Girka Some games expect the DualSense audio device (used for haptic feedback and controller speaker) to be called “Wireless Controller”. --- dlls/mmdevapi/devenum.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c index 053275cac45..bfeb3f3ecd8 100644 --- a/dlls/mmdevapi/devenum.c +++ b/dlls/mmdevapi/devenum.c @@ -255,6 +255,30 @@ static HRESULT set_driver_prop_value(GUID *id, const EDataFlow flow, const PROPE return hr; } +struct product_name_overrides +{ + const WCHAR *id; + const WCHAR *product; +}; + +static const struct product_name_overrides product_name_overrides[] = +{ + /* Sony controllers */ + { .id = L"VID_054C&PID_0CE6", .product = L"Wireless Controller" }, +}; + +static const WCHAR *find_product_name_override(const WCHAR *device_id) +{ + const WCHAR *match_id = wcschr( device_id, '\\' ) + 1; + DWORD i; + + for (i = 0; i < ARRAY_SIZE(product_name_overrides); ++i) + if (!wcsnicmp( product_name_overrides[i].id, match_id, 17 )) + return product_name_overrides[i].product; + + return NULL; +} + /* Creates or updates the state of a device * If GUID is null, a random guid will be assigned * and the device will be created @@ -321,6 +345,21 @@ static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD st pv.vt = VT_LPWSTR; pv.pwszVal = name; + + if (SUCCEEDED(set_driver_prop_value(id, flow, &devicepath_key))) { + PROPVARIANT pv2; + + PropVariantInit(&pv2); + + if (SUCCEEDED(MMDevice_GetPropValue(id, flow, &devicepath_key, &pv2)) && pv2.vt == VT_LPWSTR) { + const WCHAR *override; + if ((override = find_product_name_override(pv2.pwszVal)) != NULL) + pv.pwszVal = (WCHAR*) override; + } + + PropVariantClear(&pv2); + } + MMDevice_SetPropValue(id, flow, (const PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &pv); MMDevice_SetPropValue(id, flow, (const PROPERTYKEY*)&DEVPKEY_DeviceInterface_FriendlyName, &pv); MMDevice_SetPropValue(id, flow, (const PROPERTYKEY*)&DEVPKEY_Device_DeviceDesc, &pv); @@ -328,8 +367,6 @@ static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD st pv.pwszVal = guidstr; MMDevice_SetPropValue(id, flow, &deviceinterface_key, &pv); - set_driver_prop_value(id, flow, &devicepath_key); - if (FAILED(set_driver_prop_value(id, flow, &PKEY_AudioEndpoint_FormFactor))) { pv.vt = VT_UI4; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/338