From bf3f10d0aefa11b11a1e7bbf9083bc31b376dec3 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 18 Jan 2019 15:38:13 -0600 Subject: [PATCH 1/7] Apply proposed changes for HG v.1 support --- DS4Windows/DS4Control/ControlService.cs | 12 ++++++++++++ DS4Windows/DS4Control/ScpUtil.cs | 25 +++++++++++++++++++------ DS4Windows/DS4Forms/DS4Form.cs | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 3bb0c16..3d9c79b 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -155,6 +155,18 @@ namespace DS4Windows // Thread.SpinWait(500); //} + if (Global.IsHidGuardianInstalled()) + { + ProcessStartInfo startInfo = + new ProcessStartInfo(Global.exepath + "\\HidGuardHelper.exe"); + startInfo.Verb = "runas"; + startInfo.Arguments = Process.GetCurrentProcess().Id.ToString(); + startInfo.WorkingDirectory = Global.exepath; + try + { Process tempProc = Process.Start(startInfo); tempProc.Dispose(); } + catch { } + } + for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++) { processingData[i] = new X360Data(); diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 6959f53..b56d4f7 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -227,7 +227,7 @@ namespace DS4Windows { protected static BackingStore m_Config = new BackingStore(); protected static Int32 m_IdleTimeout = 600000; - public static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; + public static readonly string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; public static string appdatapath; public static bool firstRun = false; public static bool multisavespots = false; @@ -297,25 +297,28 @@ namespace DS4Windows return principal.IsInRole(WindowsBuiltInRole.Administrator); } - public static bool IsScpVBusInstalled() + private static bool CheckForSysDevice(string searchHardwareId) { bool result = false; Guid sysGuid = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}"); - NativeMethods.SP_DEVINFO_DATA deviceInfoData = new NativeMethods.SP_DEVINFO_DATA(); - deviceInfoData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData); + 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 sysGuid, null, 0, 0); for (int i = 0; !result && NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, i, ref deviceInfoData); i++) { - if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref NativeMethods.DEVPKEY_Device_HardwareIds, ref propertyType, + if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, + ref NativeMethods.DEVPKEY_Device_HardwareIds, ref propertyType, dataBuffer, dataBuffer.Length, ref requiredSize, 0)) { string hardwareId = dataBuffer.ToUTF16String(); //if (hardwareIds.Contains("Scp Virtual Bus Driver")) // result = true; - if (hardwareId.Equals(@"root\ScpVBus")) + if (hardwareId.Equals(searchHardwareId)) result = true; } } @@ -328,6 +331,16 @@ namespace DS4Windows return result; } + public static bool IsHidGuardianInstalled() + { + return CheckForSysDevice(@"Root\HidGuardian"); + } + + public static bool IsScpVBusInstalled() + { + return CheckForSysDevice(@"root\ScpVBus"); + } + public static void FindConfigLocation() { if (File.Exists(exepath + "\\Auto Profiles.xml") diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index b48dcbb..d89b20c 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -401,7 +401,7 @@ namespace DS4Windows if (btnStartStop.Enabled && start) { - TaskRunner.Delay(50).ContinueWith((t) => { + TaskRunner.Delay(100).ContinueWith((t) => { this.BeginInvoke((System.Action)(() => BtnStartStop_Clicked())); }); } From 1f9cf16397e16bbfb7703867b7d4f1bb0a553729 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 24 Jan 2019 03:38:21 -0600 Subject: [PATCH 2/7] Minor control search optimization --- DS4Windows/DS4Control/ScpUtil.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 6959f53..027f5ad 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -3543,16 +3543,18 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + if (shift) { - if (shift) - return dcs.shiftAction; - else - return dcs.action; + return dcs.shiftTrigger; + } + else + { + return dcs.action; } } From 1a6327ecdc48a15dbc1f11c3a6a2ee6319ee0c40 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 24 Jan 2019 04:54:40 -0600 Subject: [PATCH 3/7] Tweaked a couple of axis midpoint methods. Removed unused method. --- DS4Windows/DS4Control/Mapping.cs | 85 ++++---------------------------- 1 file changed, 9 insertions(+), 76 deletions(-) diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 3632319..d663640 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -3077,11 +3077,11 @@ namespace DS4Windows switch (control) { - case DS4Controls.LXNeg: result = cState.LX < 127 - 55; break; - case DS4Controls.LYNeg: result = cState.LY < 127 - 55; break; - case DS4Controls.RXNeg: result = cState.RX < 127 - 55; break; - case DS4Controls.RYNeg: result = cState.RY < 127 - 55; break; - default: result = axisValue > 127 + 55; break; + case DS4Controls.LXNeg: result = cState.LX < 128 - 55; break; + case DS4Controls.LYNeg: result = cState.LY < 128 - 55; break; + case DS4Controls.RXNeg: result = cState.RX < 128 - 55; break; + case DS4Controls.RYNeg: result = cState.RY < 128 - 55; break; + default: result = axisValue > 128 + 55; break; } } else if (controlType == DS4StateFieldMapping.ControlType.Trigger) @@ -3448,7 +3448,7 @@ namespace DS4Windows { byte result = 0; byte trueVal = 0; - byte falseVal = 127; + byte falseVal = 128; if (alt) trueVal = 255; @@ -3548,6 +3548,7 @@ namespace DS4Windows return result; } + /* TODO: Possibly remove usage of this version of the method */ public static byte getXYAxisMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool alt = false) { byte result = 0; @@ -3690,74 +3691,6 @@ namespace DS4Windows return result; } - /* TODO: Possibly remove usage of this version of the method */ - //Returns false for any bool, - //if control is one of the xy axis returns 127 - //if its a trigger returns 0 - public static void resetToDefaultValue(DS4Controls control, DS4State cState) - { - if (control >= DS4Controls.Square && control <= DS4Controls.Cross) - { - switch (control) - { - case DS4Controls.Cross: cState.Cross = false; break; - case DS4Controls.Square: cState.Square = false; break; - case DS4Controls.Triangle: cState.Triangle = false; break; - case DS4Controls.Circle: cState.Circle = false; break; - default: break; - } - } - else if (control >= DS4Controls.L1 && control <= DS4Controls.R3) - { - switch (control) - { - case DS4Controls.L1: cState.L1 = false; break; - case DS4Controls.L2: cState.L2 = 0; break; - case DS4Controls.L3: cState.L3 = false; break; - case DS4Controls.R1: cState.R1 = false; break; - case DS4Controls.R2: cState.R2 = 0; break; - case DS4Controls.R3: cState.R3 = false; break; - default: break; - } - } - else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft) - { - switch (control) - { - case DS4Controls.DpadUp: cState.DpadUp = false; break; - case DS4Controls.DpadDown: cState.DpadDown = false; break; - case DS4Controls.DpadLeft: cState.DpadLeft = false; break; - case DS4Controls.DpadRight: cState.DpadRight = false; break; - default: break; - } - } - else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos) - { - switch (control) - { - case DS4Controls.LXNeg: cState.LX = 127; break; - case DS4Controls.LYNeg: cState.LY = 127; break; - case DS4Controls.RXNeg: cState.RX = 127; break; - case DS4Controls.RYNeg: cState.RY = 127; break; - case DS4Controls.LXPos: cState.LX = 127; break; - case DS4Controls.LYPos: cState.LY = 127; break; - case DS4Controls.RXPos: cState.RX = 127; break; - case DS4Controls.RYPos: cState.RY = 127; break; - default: break; - } - } - else - { - switch (control) - { - case DS4Controls.Share: cState.Share = false; break; - case DS4Controls.Options: cState.Options = false; break; - case DS4Controls.PS: cState.PS = false; break; - default: break; - } - } - } - private static void resetToDefaultValue2(DS4Controls control, DS4State cState, DS4StateFieldMapping fieldMap) { @@ -3769,9 +3702,9 @@ namespace DS4Windows } else if (controlType == DS4StateFieldMapping.ControlType.AxisDir) { - fieldMap.axisdirs[controlNum] = 127; + fieldMap.axisdirs[controlNum] = 128; int controlRelation = (controlNum % 2 == 0 ? controlNum - 1 : controlNum + 1); - fieldMap.axisdirs[controlRelation] = 127; + fieldMap.axisdirs[controlRelation] = 128; } else if (controlType == DS4StateFieldMapping.ControlType.Trigger) { From 0d89170d9cae1f872ab6d18dc9030b8d3c9c147c Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 24 Jan 2019 06:20:55 -0600 Subject: [PATCH 4/7] Minor tweaks --- DS4Windows/DS4Control/ScpUtil.cs | 109 +++++++++++++------------------ 1 file changed, 47 insertions(+), 62 deletions(-) diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 027f5ad..5aef3ed 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -3475,15 +3475,12 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - { - dcs.UpdateSettings(shift, action, exts, kt, trigger); - break; - } + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + dcs.UpdateSettings(shift, action, exts, kt, trigger); } } @@ -3495,19 +3492,15 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - { - if (shift) - dcs.shiftExtras = exts; - else - dcs.extras = exts; - - break; - } + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + if (shift) + dcs.shiftExtras = exts; + else + dcs.extras = exts; } } @@ -3519,19 +3512,15 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - { - if (shift) - dcs.shiftKeyType = keyType; - else - dcs.keyType = keyType; - - break; - } + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + if (shift) + dcs.shiftKeyType = keyType; + else + dcs.keyType = keyType; } } @@ -3589,17 +3578,15 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - { - if (shift) - return dcs.shiftExtras; - else - return dcs.extras; - } + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + if (shift) + return dcs.shiftExtras; + else + return dcs.extras; } return null; @@ -3613,17 +3600,15 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - { - if (shift) - return dcs.shiftKeyType; - else - return dcs.keyType; - } + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + if (shift) + return dcs.shiftKeyType; + else + return dcs.keyType; } return DS4KeyType.None; @@ -3637,12 +3622,12 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - return dcs.shiftTrigger; + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + return dcs.shiftTrigger; } return 0; @@ -3669,12 +3654,12 @@ namespace DS4Windows else dc = (DS4Controls)Enum.Parse(typeof(DS4Controls), buttonName, true); - List ds4settingsList = ds4settings[deviceNum]; - for (int i = 0, settingsLen = ds4settingsList.Count; i < settingsLen; i++) + int temp = (int)dc; + if (temp > 0) { - DS4ControlSettings dcs = ds4settingsList[i]; - if (dcs.control == dc) - return dcs; + int index = temp - 1; + DS4ControlSettings dcs = ds4settings[deviceNum][index]; + return dcs; } return null; From 385c3f9b76dfdb1d9042778bbc679e7025280655 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 25 Jan 2019 06:12:12 -0600 Subject: [PATCH 5/7] Implement FILE_ATTRIBUTE_TEMPORARY use when opening DS4 device --- DS4Windows/HidLibrary/HidDevice.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DS4Windows/HidLibrary/HidDevice.cs b/DS4Windows/HidLibrary/HidDevice.cs index 7af84f2..0d9c894 100644 --- a/DS4Windows/HidLibrary/HidDevice.cs +++ b/DS4Windows/HidLibrary/HidDevice.cs @@ -450,11 +450,11 @@ namespace DS4Windows if (isExclusive) { - hidHandle = NativeMethods.CreateFile(devicePathName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, 0, IntPtr.Zero, NativeMethods.OpenExisting, 0x20000000 | 0x80000000 | NativeMethods.FILE_FLAG_OVERLAPPED, 0); + hidHandle = NativeMethods.CreateFile(devicePathName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, 0, IntPtr.Zero, NativeMethods.OpenExisting, 0x20000000 | 0x80000000 | 0x100 | NativeMethods.FILE_FLAG_OVERLAPPED, 0); } else { - hidHandle = NativeMethods.CreateFile(devicePathName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OpenExisting, 0x20000000 | 0x80000000 | NativeMethods.FILE_FLAG_OVERLAPPED, 0); + hidHandle = NativeMethods.CreateFile(devicePathName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OpenExisting, 0x20000000 | 0x80000000 | 0x100 | NativeMethods.FILE_FLAG_OVERLAPPED, 0); } return hidHandle; From 25991b22c6e6a2f53317a881518fd05bf18af74f Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 26 Jan 2019 20:26:41 -0600 Subject: [PATCH 6/7] Update newest text file --- DS4Windows/newest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DS4Windows/newest.txt b/DS4Windows/newest.txt index 400084b..d8c5e72 100644 --- a/DS4Windows/newest.txt +++ b/DS4Windows/newest.txt @@ -1 +1 @@ -1.6.7 +1.6.8 From e0138bdebacdfc610d8bd3c945b88553c9a54483 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 26 Jan 2019 20:26:53 -0600 Subject: [PATCH 7/7] Version 1.6.8 --- DS4Windows/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DS4Windows/Properties/AssemblyInfo.cs b/DS4Windows/Properties/AssemblyInfo.cs index 3ddc1a6..1497a9d 100644 --- a/DS4Windows/Properties/AssemblyInfo.cs +++ b/DS4Windows/Properties/AssemblyInfo.cs @@ -33,7 +33,7 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.7")] -[assembly: AssemblyFileVersion("1.6.7")] +[assembly: AssemblyVersion("1.6.8")] +[assembly: AssemblyFileVersion("1.6.8")] [assembly: NeutralResourcesLanguage("en")]