Skip to content

Commit

Permalink
Merge branch 'jay' of https://github.com/mika-n/DS4Windows into mika-…
Browse files Browse the repository at this point in the history
…n-jay
  • Loading branch information
Ryochan7 committed Oct 25, 2019
2 parents 1bf4642 + cc15bc0 commit 402bda1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
13 changes: 9 additions & 4 deletions DS4Windows/DS4Library/DS4Devices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ public class DS4Devices
internal const int NACON_VID = 0x146B;
internal const int HORI_VID = 0x0F0D;

// 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.

private static VidPidInfo[] knownDevices =
{
new VidPidInfo(SONY_VID, 0xBA0, "Sony WA"),
new VidPidInfo(SONY_VID, 0x5C4, "DS4 v.1"),
new VidPidInfo(SONY_VID, 0x09CC, "DS4 v.2"),
new VidPidInfo(RAZER_VID, 0x1000),
new VidPidInfo(NACON_VID, 0x0D01),
new VidPidInfo(NACON_VID, 0x0D02),
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"),
new VidPidInfo(HORI_VID, 0x00EE, "Hori PS4 Mini"), // Hori PS4 Mini Wired Gamepad
new VidPidInfo(0x7545, 0x0104),
new VidPidInfo(0x7545, 0x0104, "Armor 3 LU Cobra"), // Armor 3 Level Up Cobra
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
Expand All @@ -53,6 +56,8 @@ public class DS4Devices
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).
new VidPidInfo(0x0C12, 0x0E16, "Steel Play MetalTech"), // Steel Play Metaltech P4 (wired)
new VidPidInfo(NACON_VID, 0x0D08, "Nacon Revol U Pro"), // Nacon Revolution Unlimited Pro
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)
};

private static string devicePathToInstanceId(string devicePath)
Expand Down
24 changes: 18 additions & 6 deletions DS4Windows/HidLibrary/HidDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,19 @@ public string readSerial()
if (serial != null)
return serial;

// Some devices don't have MAC address (especially gamepads with USB only suports in PC). If the serial number reading fails
// then use dummy zero MAC address, because there is a good chance the gamepad stll works in DS4Windows app (the code would throw
// an index out of bounds exception anyway without IF-THEN-ELSE checks after trying to read a serial number).

if (Capabilities.InputReportByteLength == 64)
{
byte[] buffer = new byte[16];
buffer[0] = 18;
readFeatureData(buffer);
serial = String.Format("{0:X02}:{1:X02}:{2:X02}:{3:X02}:{4:X02}:{5:X02}", buffer[6], buffer[5], buffer[4], buffer[3], buffer[2], buffer[1]);
if (readFeatureData(buffer))
serial = String.Format("{0:X02}:{1:X02}:{2:X02}:{3:X02}:{4:X02}:{5:X02}", buffer[6], buffer[5], buffer[4], buffer[3], buffer[2], buffer[1]);
else
serial = "00:00:00:00:00:00";

return serial;
}
else
Expand All @@ -491,10 +498,15 @@ public string readSerial()
#else
uint bufferLen = 126;
#endif
NativeMethods.HidD_GetSerialNumberString(safeReadHandle.DangerousGetHandle(), buffer, bufferLen);
string MACAddr = System.Text.Encoding.Unicode.GetString(buffer).Replace("\0", string.Empty).ToUpper();
MACAddr = $"{MACAddr[0]}{MACAddr[1]}:{MACAddr[2]}{MACAddr[3]}:{MACAddr[4]}{MACAddr[5]}:{MACAddr[6]}{MACAddr[7]}:{MACAddr[8]}{MACAddr[9]}:{MACAddr[10]}{MACAddr[11]}";
serial = MACAddr;
if (NativeMethods.HidD_GetSerialNumberString(safeReadHandle.DangerousGetHandle(), buffer, bufferLen))
{
string MACAddr = System.Text.Encoding.Unicode.GetString(buffer).Replace("\0", string.Empty).ToUpper();
MACAddr = $"{MACAddr[0]}{MACAddr[1]}:{MACAddr[2]}{MACAddr[3]}:{MACAddr[4]}{MACAddr[5]}:{MACAddr[6]}{MACAddr[7]}:{MACAddr[8]}{MACAddr[9]}:{MACAddr[10]}{MACAddr[11]}";
serial = MACAddr;
}
else
serial = "00:00:00:00:00:00";

return serial;
}
}
Expand Down

0 comments on commit 402bda1

Please sign in to comment.