diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 4fc630f..fb9405e 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -358,7 +358,7 @@ namespace DS4Windows if (showlog) LogDebug(Properties.Resources.Starting); - LogDebug("Connection to ViGEmBus established"); + LogDebug($"Connection to ViGEmBus {Global.vigembusVersion} established"); DS4Devices.isExclusiveMode = getUseExclusiveMode(); uiContext = tempui as SynchronizationContext; diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 112ee29..cc76496 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -245,6 +245,8 @@ namespace DS4Windows public static OutContType[] outDevTypeTemp = new OutContType[5] { DS4Windows.OutContType.X360, DS4Windows.OutContType.X360, DS4Windows.OutContType.X360, DS4Windows.OutContType.X360, DS4Windows.OutContType.X360 }; + public static bool vigemInstalled = IsViGEmBusInstalled(); + public static string vigembusVersion = ViGEmBusVersion(); public static X360Controls[] defaultButtonMapping = { X360Controls.None, X360Controls.LXNeg, X360Controls.LXPos, X360Controls.LYNeg, X360Controls.LYPos, X360Controls.RXNeg, X360Controls.RXPos, X360Controls.RYNeg, X360Controls.RYPos, @@ -388,14 +390,50 @@ namespace DS4Windows return result; } + private static string GetViGEmDriverProperty(NativeMethods.DEVPROPKEY prop) + { + string result = string.Empty; + Guid deviceGuid = Guid.Parse(VIGEMBUS_GUID); + NativeMethods.SP_DEVINFO_DATA deviceInfoData = + new NativeMethods.SP_DEVINFO_DATA(); + deviceInfoData.cbSize = + System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData); + + var dataBuffer = new byte[4096]; + ulong propertyType = 0; + var requiredSize = 0; + + IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref deviceGuid, null, 0, + NativeMethods.DIGCF_DEVICEINTERFACE); + NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, 0, ref deviceInfoData); + if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref prop, ref propertyType, + dataBuffer, dataBuffer.Length, ref requiredSize, 0)) + { + result = dataBuffer.ToUTF16String(); + } + + if (deviceInfoSet.ToInt64() != NativeMethods.INVALID_HANDLE_VALUE) + { + NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet); + } + + return result; + } + public static bool IsHidGuardianInstalled() { return CheckForSysDevice(@"Root\HidGuardian"); } + const string VIGEMBUS_GUID = "{96E42B22-F5E9-42F8-B043-ED0F932F014F}"; public static bool IsViGEmBusInstalled() { - return CheckForDevice("{96E42B22-F5E9-42F8-B043-ED0F932F014F}"); + return CheckForDevice(VIGEMBUS_GUID); + } + + public static string ViGEmBusVersion() + { + return GetViGEmDriverProperty(NativeMethods.DEVPKEY_Device_DriverVersion); } public static void FindConfigLocation() diff --git a/DS4Windows/HidLibrary/NativeMethods.cs b/DS4Windows/HidLibrary/NativeMethods.cs index 1fca5dd..0b6de8a 100644 --- a/DS4Windows/HidLibrary/NativeMethods.cs +++ b/DS4Windows/HidLibrary/NativeMethods.cs @@ -237,6 +237,9 @@ namespace DS4Windows internal static DEVPROPKEY DEVPKEY_Device_UINumber = new DEVPROPKEY { fmtid = new Guid(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0), pid = 18 }; + internal static DEVPROPKEY DEVPKEY_Device_DriverVersion = + new DEVPROPKEY { fmtid = new Guid(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6), pid = 3 }; + [DllImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceRegistryProperty")] public static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, int propertyVal, ref int propertyRegDataType, byte[] propertyBuffer, int propertyBufferSize, ref int requiredSize);