2014-03-28 02:50:40 +01:00
using System ;
using System.Collections.Generic ;
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
using System.Diagnostics ;
2014-03-28 02:50:40 +01:00
using System.Linq ;
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
using System.Runtime.InteropServices ;
using System.Security.Principal ;
2015-02-08 22:51:52 +01:00
namespace DS4Windows
2014-03-28 02:50:40 +01:00
{
2017-10-29 02:34:04 +01:00
public class VidPidInfo
{
public readonly int vid ;
public readonly int pid ;
2019-09-07 15:29:25 +02:00
public readonly string name ;
internal VidPidInfo ( int vid , int pid , string name = "Generic DS4" )
2017-10-29 02:34:04 +01:00
{
this . vid = vid ;
this . pid = pid ;
2019-09-07 15:29:25 +02:00
this . name = name ;
2017-10-29 02:34:04 +01:00
}
}
2020-02-14 00:01:14 +01:00
public class RequestElevationArgs : EventArgs
{
public const int STATUS_SUCCESS = 0 ;
public const int STATUS_INIT_FAILURE = - 1 ;
private int statusCode = STATUS_INIT_FAILURE ;
private string instanceId ;
public int StatusCode
{
get = > statusCode ;
set = > statusCode = value ;
}
public string InstanceId { get = > instanceId ; }
public RequestElevationArgs ( string instanceId )
{
this . instanceId = instanceId ;
}
}
public delegate void RequestElevationDelegate ( RequestElevationArgs args ) ;
2014-03-28 02:50:40 +01:00
public class DS4Devices
{
2017-10-05 07:24:53 +02:00
// (HID device path, DS4Device)
2014-03-28 02:50:40 +01:00
private static Dictionary < string , DS4Device > Devices = new Dictionary < string , DS4Device > ( ) ;
2017-10-05 07:24:53 +02:00
private static HashSet < string > deviceSerials = new HashSet < string > ( ) ;
2017-06-08 02:52:09 +02:00
private static HashSet < string > DevicePaths = new HashSet < string > ( ) ;
// Keep instance of opened exclusive mode devices not in use (Charging while using BT connection)
private static List < HidDevice > DisabledDevices = new List < HidDevice > ( ) ;
2017-08-04 13:10:48 +02:00
private static Stopwatch sw = new Stopwatch ( ) ;
2020-02-14 00:01:14 +01:00
public static event RequestElevationDelegate RequestElevation ;
2014-03-28 02:50:40 +01:00
public static bool isExclusiveMode = false ;
2017-10-29 02:34:04 +01:00
internal const int SONY_VID = 0x054C ;
internal const int RAZER_VID = 0x1532 ;
2017-11-05 16:20:10 +01:00
internal const int NACON_VID = 0x146B ;
2018-04-22 04:52:46 +02:00
internal const int HORI_VID = 0x0F0D ;
2017-10-29 02:34:04 +01:00
2019-10-20 16:25:18 +02:00
// https://support.steampowered.com/kb_article.php?ref=5199-TOKV-4426&l=english web site has a list of other PS4 compatible device VID/PID values and brand names.
// However, not all those are guaranteed to work with DS4Windows app so support is added case by case when users of DS4Windows app tests non-official DS4 gamepads.
2017-10-29 02:34:04 +01:00
private static VidPidInfo [ ] knownDevices =
{
2019-09-07 15:29:25 +02:00
new VidPidInfo ( SONY_VID , 0xBA0 , "Sony WA" ) ,
new VidPidInfo ( SONY_VID , 0x5C4 , "DS4 v.1" ) ,
new VidPidInfo ( SONY_VID , 0x09CC , "DS4 v.2" ) ,
2019-10-20 16:25:18 +02:00
new VidPidInfo ( RAZER_VID , 0x1000 , "Razer Raiju PS4" ) ,
new VidPidInfo ( NACON_VID , 0x0D01 , "Nacon Revol Pro v.1" ) ,
new VidPidInfo ( NACON_VID , 0x0D02 , "Nacon Revol Pro v.2" ) ,
2019-09-07 15:29:25 +02:00
new VidPidInfo ( HORI_VID , 0x00EE , "Hori PS4 Mini" ) , // Hori PS4 Mini Wired Gamepad
2019-10-20 16:25:18 +02:00
new VidPidInfo ( 0x7545 , 0x0104 , "Armor 3 LU Cobra" ) , // Armor 3 Level Up Cobra
2019-09-07 15:29:25 +02:00
new VidPidInfo ( 0x2E95 , 0x7725 , "Scuf Vantage" ) , // Scuf Vantage gamepad
new VidPidInfo ( 0x11C0 , 0x4001 , "PS4 Fun" ) , // PS4 Fun Controller
new VidPidInfo ( RAZER_VID , 0x1007 , "Razer Raiju TE" ) , // Razer Raiju Tournament Edition
new VidPidInfo ( RAZER_VID , 0x1004 , "Razer Raiju UE USB" ) , // Razer Raiju Ultimate Edition (wired)
new VidPidInfo ( RAZER_VID , 0x1009 , "Razer Raiju UE BT" ) , // Razer Raiju Ultimate Edition (BT). Doesn't work yet for some reason even when non-steam Razer driver lists the BT Razer Ultimate with this ID.
new VidPidInfo ( SONY_VID , 0x05C5 , "CronusMax (PS4 Mode)" ) , // CronusMax (PS4 Output Mode)
new VidPidInfo ( 0x0C12 , 0x57AB , "Warrior Joypad JS083" ) , // Warrior Joypad JS083 (wired). Custom lightbar color doesn't work, but everything else works OK (except touchpad and gyro because the gamepad doesnt have those).
2019-09-07 16:23:03 +02:00
new VidPidInfo ( 0x0C12 , 0x0E16 , "Steel Play MetalTech" ) , // Steel Play Metaltech P4 (wired)
2019-10-20 16:25:18 +02:00
new VidPidInfo ( NACON_VID , 0x0D08 , "Nacon Revol U Pro" ) , // Nacon Revolution Unlimited Pro
2019-12-15 19:03:53 +01:00
new VidPidInfo ( NACON_VID , 0x0D10 , "Nacon Revol Infinite" ) , // Nacon Revolution Infinite (sometimes known as Revol Unlimited Pro v2?). Touchpad, gyro, rumble, "led indicator" lightbar.
2019-10-20 16:25:18 +02:00
new VidPidInfo ( HORI_VID , 0x0084 , "Hori Fighting Cmd" ) , // Hori Fighting Commander (special kind of gamepad without touchpad or sticks. There is a hardware switch to alter d-pad type between dpad and LS/RS)
2019-11-19 07:39:23 +01:00
new VidPidInfo ( NACON_VID , 0x0D13 , "Nacon Revol Pro v.3" ) ,
2017-10-29 02:34:04 +01:00
} ;
2014-03-28 02:50:40 +01:00
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
private static string devicePathToInstanceId ( string devicePath )
{
string deviceInstanceId = devicePath ;
deviceInstanceId = deviceInstanceId . Remove ( 0 , deviceInstanceId . LastIndexOf ( '\\' ) + 1 ) ;
deviceInstanceId = deviceInstanceId . Remove ( deviceInstanceId . LastIndexOf ( '{' ) ) ;
deviceInstanceId = deviceInstanceId . Replace ( '#' , '\\' ) ;
if ( deviceInstanceId . EndsWith ( "\\" ) )
{
deviceInstanceId = deviceInstanceId . Remove ( deviceInstanceId . Length - 1 ) ;
}
2017-05-01 11:29:19 +02:00
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
return deviceInstanceId ;
}
2019-04-18 04:29:16 +02:00
private static bool IsRealDS4 ( HidDevice hDevice )
{
string deviceInstanceId = devicePathToInstanceId ( hDevice . DevicePath ) ;
string temp = Global . GetDeviceProperty ( deviceInstanceId ,
NativeMethods . DEVPKEY_Device_UINumber ) ;
return string . IsNullOrEmpty ( temp ) ;
}
2017-06-08 02:52:09 +02:00
// Enumerates ds4 controllers in the system
2014-03-28 02:50:40 +01:00
public static void findControllers ( )
{
lock ( Devices )
{
2017-10-29 02:34:04 +01:00
IEnumerable < HidDevice > hDevices = HidDevices . EnumerateDS4 ( knownDevices ) ;
2019-04-18 04:29:16 +02:00
hDevices = hDevices . Where ( dev = > IsRealDS4 ( dev ) ) . Select ( dev = > dev ) ;
//hDevices = from dev in hDevices where IsRealDS4(dev) select dev;
2014-03-29 06:29:08 +01:00
// Sort Bluetooth first in case USB is also connected on the same controller.
hDevices = hDevices . OrderBy < HidDevice , ConnectionType > ( ( HidDevice d ) = > { return DS4Device . HidConnectionType ( d ) ; } ) ;
2014-03-28 02:50:40 +01:00
2017-04-30 06:37:28 +02:00
List < HidDevice > tempList = hDevices . ToList ( ) ;
2017-06-08 02:52:09 +02:00
purgeHiddenExclusiveDevices ( ) ;
tempList . AddRange ( DisabledDevices ) ;
2017-04-30 06:37:28 +02:00
int devCount = tempList . Count ( ) ;
2017-04-26 05:07:02 +02:00
string devicePlural = "device" + ( devCount = = 0 | | devCount > 1 ? "s" : "" ) ;
//Log.LogToGui("Found " + devCount + " possible " + devicePlural + ". Examining " + devicePlural + ".", false);
2017-08-04 13:10:48 +02:00
for ( int i = 0 ; i < devCount ; i + + )
2017-04-24 11:43:56 +02:00
//foreach (HidDevice hDevice in hDevices)
2014-03-28 02:50:40 +01:00
{
2017-04-30 06:37:28 +02:00
HidDevice hDevice = tempList [ i ] ;
2017-05-12 01:57:02 +02:00
if ( hDevice . Description = = "HID-compliant vendor-defined device" )
continue ; // ignore the Nacon Revolution Pro programming interface
else if ( DevicePaths . Contains ( hDevice . DevicePath ) )
2014-03-29 06:29:08 +01:00
continue ; // BT/USB endpoint already open once
2017-04-24 11:43:56 +02:00
2019-09-07 15:29:25 +02:00
VidPidInfo metainfo = knownDevices . Single ( x = > x . vid = = hDevice . Attributes . VendorId & &
x . pid = = hDevice . Attributes . ProductId ) ;
2014-03-28 02:50:40 +01:00
if ( ! hDevice . IsOpen )
2014-03-29 06:29:08 +01:00
{
2014-03-28 02:50:40 +01:00
hDevice . OpenDevice ( isExclusiveMode ) ;
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
if ( ! hDevice . IsOpen & & isExclusiveMode )
{
try
{
2020-02-14 00:01:14 +01:00
// Check if running with elevated permissions
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
WindowsIdentity identity = WindowsIdentity . GetCurrent ( ) ;
WindowsPrincipal principal = new WindowsPrincipal ( identity ) ;
bool elevated = principal . IsInRole ( WindowsBuiltInRole . Administrator ) ;
if ( ! elevated )
{
2020-02-14 00:01:14 +01:00
// Tell the client to launch routine to re-enable a device
RequestElevationArgs eleArgs =
new RequestElevationArgs ( devicePathToInstanceId ( hDevice . DevicePath ) ) ;
RequestElevation ? . Invoke ( eleArgs ) ;
if ( eleArgs . StatusCode = = RequestElevationArgs . STATUS_SUCCESS )
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
{
hDevice . OpenDevice ( isExclusiveMode ) ;
}
}
else
{
reEnableDevice ( devicePathToInstanceId ( hDevice . DevicePath ) ) ;
hDevice . OpenDevice ( isExclusiveMode ) ;
}
}
catch ( Exception ) { }
}
2014-03-29 06:29:08 +01:00
// TODO in exclusive mode, try to hold both open when both are connected
if ( isExclusiveMode & & ! hDevice . IsOpen )
hDevice . OpenDevice ( false ) ;
}
2017-04-23 04:46:50 +02:00
2014-03-28 02:50:40 +01:00
if ( hDevice . IsOpen )
{
2017-04-06 03:37:38 +02:00
string serial = hDevice . readSerial ( ) ;
2017-05-25 11:51:28 +02:00
bool validSerial = ! serial . Equals ( DS4Device . blankSerial ) ;
2017-10-05 07:24:53 +02:00
if ( validSerial & & deviceSerials . Contains ( serial ) )
2017-06-08 02:52:09 +02:00
{
// happens when the BT endpoint already is open and the USB is plugged into the same host
if ( isExclusiveMode & & hDevice . IsExclusive & &
! DisabledDevices . Contains ( hDevice ) )
{
// Grab reference to exclusively opened HidDevice so device
// stays hidden to other processes
DisabledDevices . Add ( hDevice ) ;
2017-06-08 22:52:47 +02:00
//DevicePaths.Add(hDevice.DevicePath);
2017-06-08 02:52:09 +02:00
}
continue ;
}
2014-03-28 02:50:40 +01:00
else
{
2019-09-07 15:29:25 +02:00
DS4Device ds4Device = new DS4Device ( hDevice , metainfo . name ) ;
2017-05-09 12:11:50 +02:00
//ds4Device.Removal += On_Removal;
2018-03-26 06:36:46 +02:00
if ( ! ds4Device . ExitOutputThread )
{
Devices . Add ( hDevice . DevicePath , ds4Device ) ;
DevicePaths . Add ( hDevice . DevicePath ) ;
deviceSerials . Add ( serial ) ;
}
2014-03-28 02:50:40 +01:00
}
}
}
}
}
2017-06-08 02:52:09 +02:00
// Returns DS4 controllers that were found and are running
2014-03-28 02:50:40 +01:00
public static IEnumerable < DS4Device > getDS4Controllers ( )
{
2014-03-29 06:29:08 +01:00
lock ( Devices )
{
DS4Device [ ] controllers = new DS4Device [ Devices . Count ] ;
Devices . Values . CopyTo ( controllers , 0 ) ;
return controllers ;
}
2014-03-28 02:50:40 +01:00
}
public static void stopControllers ( )
2014-03-29 06:29:08 +01:00
{
lock ( Devices )
2014-03-28 02:50:40 +01:00
{
2014-03-29 06:29:08 +01:00
IEnumerable < DS4Device > devices = getDS4Controllers ( ) ;
2017-04-24 11:43:56 +02:00
//foreach (DS4Device device in devices)
2019-02-16 09:50:53 +01:00
//for (int i = 0, devCount = devices.Count(); i < devCount; i++)
for ( var devEnum = devices . GetEnumerator ( ) ; devEnum . MoveNext ( ) ; )
2014-03-29 06:29:08 +01:00
{
2019-02-16 09:50:53 +01:00
DS4Device device = devEnum . Current ;
//DS4Device device = devices.ElementAt(i);
2014-03-29 06:29:08 +01:00
device . StopUpdate ( ) ;
2017-05-01 12:40:37 +02:00
//device.runRemoval();
2014-03-29 06:29:08 +01:00
device . HidDevice . CloseDevice ( ) ;
}
2017-04-24 11:43:56 +02:00
2014-03-29 06:29:08 +01:00
Devices . Clear ( ) ;
DevicePaths . Clear ( ) ;
2017-10-05 07:24:53 +02:00
deviceSerials . Clear ( ) ;
2017-06-08 02:52:09 +02:00
DisabledDevices . Clear ( ) ;
2014-03-28 02:50:40 +01:00
}
}
2017-06-08 02:52:09 +02:00
// Called when devices is diconnected, timed out or has input reading failure
2014-03-28 02:50:40 +01:00
public static void On_Removal ( object sender , EventArgs e )
2018-02-21 19:46:08 +01:00
{
DS4Device device = ( DS4Device ) sender ;
RemoveDevice ( device ) ;
}
public static void RemoveDevice ( DS4Device device )
2014-03-28 02:50:40 +01:00
{
lock ( Devices )
{
2017-05-25 11:51:28 +02:00
if ( device ! = null )
{
device . HidDevice . CloseDevice ( ) ;
2017-10-05 07:24:53 +02:00
Devices . Remove ( device . HidDevice . DevicePath ) ;
2017-05-25 11:51:28 +02:00
DevicePaths . Remove ( device . HidDevice . DevicePath ) ;
2017-10-05 07:24:53 +02:00
deviceSerials . Remove ( device . MacAddress ) ;
2017-06-08 22:52:47 +02:00
//purgeHiddenExclusiveDevices();
2017-05-25 11:51:28 +02:00
}
}
}
public static void UpdateSerial ( object sender , EventArgs e )
{
lock ( Devices )
{
DS4Device device = ( DS4Device ) sender ;
if ( device ! = null )
{
2017-10-05 07:24:53 +02:00
string devPath = device . HidDevice . DevicePath ;
2017-05-25 11:51:28 +02:00
string serial = device . getMacAddress ( ) ;
2017-10-05 07:24:53 +02:00
if ( Devices . ContainsKey ( devPath ) )
2017-05-25 11:51:28 +02:00
{
2017-10-05 07:24:53 +02:00
deviceSerials . Remove ( serial ) ;
2017-05-25 11:51:28 +02:00
device . updateSerial ( ) ;
serial = device . getMacAddress ( ) ;
2017-10-05 07:24:53 +02:00
if ( DS4Device . isValidSerial ( serial ) )
{
deviceSerials . Add ( serial ) ;
}
2017-10-12 01:55:15 +02:00
2018-07-10 07:57:55 +02:00
if ( device . ShouldRunCalib ( ) )
2018-07-10 08:18:27 +02:00
device . RefreshCalibration ( ) ;
2017-05-25 11:51:28 +02:00
}
}
2014-03-28 02:50:40 +01:00
}
}
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
2017-06-08 02:52:09 +02:00
private static void purgeHiddenExclusiveDevices ( )
{
int disabledDevCount = DisabledDevices . Count ;
if ( disabledDevCount > 0 )
{
List < HidDevice > disabledDevList = new List < HidDevice > ( ) ;
2019-02-16 09:41:13 +01:00
for ( var devEnum = DisabledDevices . GetEnumerator ( ) ; devEnum . MoveNext ( ) ; )
//for (int i = 0, arlen = disabledDevCount; i < arlen; i++)
2017-06-08 02:52:09 +02:00
{
2019-02-16 09:41:13 +01:00
//HidDevice tempDev = DisabledDevices.ElementAt(i);
HidDevice tempDev = devEnum . Current ;
2017-06-08 02:52:09 +02:00
if ( tempDev ! = null )
{
if ( tempDev . IsOpen & & tempDev . IsConnected )
{
disabledDevList . Add ( tempDev ) ;
}
else if ( tempDev . IsOpen )
{
if ( ! tempDev . IsConnected )
{
try
{
tempDev . CloseDevice ( ) ;
}
catch { }
}
if ( DevicePaths . Contains ( tempDev . DevicePath ) )
{
DevicePaths . Remove ( tempDev . DevicePath ) ;
}
}
}
}
DisabledDevices . Clear ( ) ;
DisabledDevices . AddRange ( disabledDevList ) ;
2014-03-28 02:50:40 +01:00
}
}
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
public static void reEnableDevice ( string deviceInstanceId )
{
bool success ;
Guid hidGuid = new Guid ( ) ;
NativeMethods . HidD_GetHidGuid ( ref hidGuid ) ;
IntPtr deviceInfoSet = NativeMethods . SetupDiGetClassDevs ( ref hidGuid , deviceInstanceId , 0 , NativeMethods . DIGCF_PRESENT | NativeMethods . DIGCF_DEVICEINTERFACE ) ;
NativeMethods . SP_DEVINFO_DATA deviceInfoData = new NativeMethods . SP_DEVINFO_DATA ( ) ;
deviceInfoData . cbSize = Marshal . SizeOf ( deviceInfoData ) ;
success = NativeMethods . SetupDiEnumDeviceInfo ( deviceInfoSet , 0 , ref deviceInfoData ) ;
if ( ! success )
{
throw new Exception ( "Error getting device info data, error code = " + Marshal . GetLastWin32Error ( ) ) ;
}
success = NativeMethods . SetupDiEnumDeviceInfo ( deviceInfoSet , 1 , ref deviceInfoData ) ; // Checks that we have a unique device
if ( success )
{
throw new Exception ( "Can't find unique device" ) ;
}
NativeMethods . SP_PROPCHANGE_PARAMS propChangeParams = new NativeMethods . SP_PROPCHANGE_PARAMS ( ) ;
propChangeParams . classInstallHeader . cbSize = Marshal . SizeOf ( propChangeParams . classInstallHeader ) ;
propChangeParams . classInstallHeader . installFunction = NativeMethods . DIF_PROPERTYCHANGE ;
propChangeParams . stateChange = NativeMethods . DICS_DISABLE ;
propChangeParams . scope = NativeMethods . DICS_FLAG_GLOBAL ;
propChangeParams . hwProfile = 0 ;
success = NativeMethods . SetupDiSetClassInstallParams ( deviceInfoSet , ref deviceInfoData , ref propChangeParams , Marshal . SizeOf ( propChangeParams ) ) ;
if ( ! success )
{
throw new Exception ( "Error setting class install params, error code = " + Marshal . GetLastWin32Error ( ) ) ;
}
success = NativeMethods . SetupDiCallClassInstaller ( NativeMethods . DIF_PROPERTYCHANGE , deviceInfoSet , ref deviceInfoData ) ;
2018-01-10 22:27:39 +01:00
// TEST: If previous SetupDiCallClassInstaller fails, just continue
// otherwise device will likely get permanently disabled.
/ * if ( ! success )
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
{
throw new Exception ( "Error disabling device, error code = " + Marshal . GetLastWin32Error ( ) ) ;
}
2018-01-10 22:27:39 +01:00
* /
2017-03-29 16:26:07 +02:00
2018-03-05 22:53:40 +01:00
//System.Threading.Thread.Sleep(50);
sw . Restart ( ) ;
while ( sw . ElapsedMilliseconds < 50 )
{
// Use SpinWait to keep control of current thread. Using Sleep could potentially
// cause other events to get run out of order
System . Threading . Thread . SpinWait ( 100 ) ;
}
sw . Stop ( ) ;
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
propChangeParams . stateChange = NativeMethods . DICS_ENABLE ;
success = NativeMethods . SetupDiSetClassInstallParams ( deviceInfoSet , ref deviceInfoData , ref propChangeParams , Marshal . SizeOf ( propChangeParams ) ) ;
if ( ! success )
{
throw new Exception ( "Error setting class install params, error code = " + Marshal . GetLastWin32Error ( ) ) ;
}
success = NativeMethods . SetupDiCallClassInstaller ( NativeMethods . DIF_PROPERTYCHANGE , deviceInfoSet , ref deviceInfoData ) ;
if ( ! success )
{
throw new Exception ( "Error enabling device, error code = " + Marshal . GetLastWin32Error ( ) ) ;
}
2018-02-28 22:09:29 +01:00
//System.Threading.Thread.Sleep(50);
sw . Restart ( ) ;
while ( sw . ElapsedMilliseconds < 50 )
{
// Use SpinWait to keep control of current thread. Using Sleep could potentially
// cause other events to get run out of order
System . Threading . Thread . SpinWait ( 100 ) ;
}
sw . Stop ( ) ;
Version 1.4.5
Added support for the New DS4 USB Adapater (Thanks to boganhobo and
Chamilsaan)
Implemented teokp's amazing fix for hide ds4 not working on the
anniversary update of Windows 10: when a controller fails to enter
exclusive mode, DS4Windows will ask for admin privilages to fix the
issue.
Now (near)unlimited Special Actions can be made from the previous limit
of 50
Special Action Xbox Game DVR is now no longer limited to Windows 10,
renamed multi action button: Assign a macro to single tap, double tap,
and holding down a button
Added option for White DS4Windows Icon in the notification tray (While
not merged from, thanks to tehmantra)
Added option to temporarily turn off DS4Windows when using a certain
program (togglable in the Auto Profiles Tab) (Same case as above but
thanks to dedChar to bring to light)
Fixed Options crashes in certain locales where decimal points are
repesented with commas, such as German (Thanks to kiliansch)
Added/Updated translations for many languauges, now including Japanese,
Slovenian, Hungarian, Greek, Finnish, Czech, Indonesian, and Ukrainian
2016-09-22 03:38:38 +02:00
NativeMethods . SetupDiDestroyDeviceInfoList ( deviceInfoSet ) ;
}
2014-03-28 02:50:40 +01:00
}
}