Example #1
0
        public override void Update(ulong updateTick, float deltaTime)
        {
            IntPtr data;
            var    size = Native.GetDeviceEvents(out data);

            if (size > 0)
            {
                Utility.ArrayExpand(ref deviceEvents, size);
                MarshalUtility.Copy(data, deviceEvents, size);

                var index = 0;
                var attachedEventCount = deviceEvents[index++];
                for (var i = 0; i < attachedEventCount; i++)
                {
                    var deviceHandle  = deviceEvents[index++];
                    var stringBuilder = new StringBuilder(256);
                    stringBuilder.Append("Attached native device with handle " + deviceHandle + ":\n");

                    InputDeviceInfo deviceInfo;
                    if (Native.GetDeviceInfo(deviceHandle, out deviceInfo))
                    {
                        stringBuilder.AppendFormat("Name: {0}\n", deviceInfo.name);
                        stringBuilder.AppendFormat("Driver Type: {0}\n", deviceInfo.driverType);
                        stringBuilder.AppendFormat("Location ID: {0}\n", deviceInfo.location);
                        stringBuilder.AppendFormat("Serial Number: {0}\n", deviceInfo.serialNumber);
                        stringBuilder.AppendFormat("Vendor ID: 0x{0:x}\n", deviceInfo.vendorID);
                        stringBuilder.AppendFormat("Product ID: 0x{0:x}\n", deviceInfo.productID);
                        stringBuilder.AppendFormat("Version Number: 0x{0:x}\n", deviceInfo.versionNumber);
                        stringBuilder.AppendFormat("Buttons: {0}\n", deviceInfo.numButtons);
                        stringBuilder.AppendFormat("Analogs: {0}\n", deviceInfo.numAnalogs);

                        DetectDevice(deviceHandle, deviceInfo);
                    }

                    Logger.LogInfo(stringBuilder.ToString());
                }

                var detachedEventCount = deviceEvents[index++];
                for (var i = 0; i < detachedEventCount; i++)
                {
                    var deviceHandle = deviceEvents[index++];
                    Logger.LogInfo("Detached native device with handle " + deviceHandle + ":");

                    var device = FindAttachedDevice(deviceHandle);
                    if (device != null)
                    {
                        DetachDevice(device);
                    }
                    else
                    {
                        Logger.LogWarning("Couldn't find device to detach with handle: " + deviceHandle);
                    }
                }
            }
        }
        public override void Update(ulong updateTick, float deltaTime)
        {
            IntPtr source;
            int    num = Native.GetDeviceEvents(out source);

            if (num <= 0)
            {
                return;
            }
            Utility.ArrayExpand(ref deviceEvents, num);
            MarshalUtility.Copy(source, deviceEvents, num);
            int  num2 = 0;
            uint num3 = deviceEvents[num2++];

            for (int i = 0; i < num3; i++)
            {
                uint          num4          = deviceEvents[num2++];
                StringBuilder stringBuilder = new StringBuilder(256);
                stringBuilder.Append("Attached native device with handle " + num4 + ":\n");
                if (Native.GetDeviceInfo(num4, out NativeDeviceInfo deviceInfo))
                {
                    stringBuilder.AppendFormat("Name: {0}\n", deviceInfo.name);
                    stringBuilder.AppendFormat("Driver Type: {0}\n", deviceInfo.driverType);
                    stringBuilder.AppendFormat("Location ID: {0}\n", deviceInfo.location);
                    stringBuilder.AppendFormat("Serial Number: {0}\n", deviceInfo.serialNumber);
                    stringBuilder.AppendFormat("Vendor ID: 0x{0:x}\n", deviceInfo.vendorID);
                    stringBuilder.AppendFormat("Product ID: 0x{0:x}\n", deviceInfo.productID);
                    stringBuilder.AppendFormat("Version Number: 0x{0:x}\n", deviceInfo.versionNumber);
                    stringBuilder.AppendFormat("Buttons: {0}\n", deviceInfo.numButtons);
                    stringBuilder.AppendFormat("Analogs: {0}\n", deviceInfo.numAnalogs);
                    DetectDevice(num4, deviceInfo);
                }
                Logger.LogInfo(stringBuilder.ToString());
            }
            uint num5 = deviceEvents[num2++];

            for (int j = 0; j < num5; j++)
            {
                uint num6 = deviceEvents[num2++];
                Logger.LogInfo("Detached native device with handle " + num6 + ":");
                NativeInputDevice nativeInputDevice = FindAttachedDevice(num6);
                if (nativeInputDevice != null)
                {
                    DetachDevice(nativeInputDevice);
                }
                else
                {
                    Logger.LogWarning("Couldn't find device to detach with handle: " + num6);
                }
            }
        }