[Mac] Fixed joystick Guid calculation
authorthefiddler <stapostol@gmail.com>
Thu, 11 Sep 2014 11:18:29 +0000 (13:18 +0200)
committerthefiddler <stapostol@gmail.com>
Wed, 17 Sep 2014 23:16:40 +0000 (01:16 +0200)
The result now matches the output of SDL2 as well as the entries in the
GamePad configuration database.

Source/OpenTK/Platform/MacOS/HIDInput.cs

index e4a4614d6279a536054cbbc0baa8cd5e53bd3e64..08223aa9e48fd5bd67f01f543c5a287849bc9b2d 100755 (executable)
@@ -558,7 +558,18 @@ namespace OpenTK.Platform.MacOS
                 guid_bytes.AddRange(name_bytes);
             }
 
-            return new Guid(guid_bytes.ToArray());
+            // The Guid(byte[]) constructor performs byte-swapping on the first 4+2+2 bytes, while
+            // the Guid(string) constructor does not. Since our database is using the string
+            // constructor, we need to compensate for this difference or the database lookups
+            // will fail.
+            byte[] guid_array = guid_bytes.ToArray();
+            if (BitConverter.IsLittleEndian)
+            {
+                Array.Reverse(guid_array, 0, 4);
+                Array.Reverse(guid_array, 4, 2);
+                Array.Reverse(guid_array, 6, 2);
+            }
+            return new Guid(guid_array);
         }
 
         JoystickData CreateJoystick(IntPtr sender, IntPtr device)