internal void Initialize(UInt32 deviceHandle, NativeDeviceInfo deviceInfo, NativeInputDeviceProfile deviceProfile) { Handle = deviceHandle; Info = deviceInfo; profile = deviceProfile; SortOrder = 1000 + (int)Handle; buttons = new Int16[Info.numButtons]; analogs = new Int16[Info.numAnalogs]; AnalogSnapshot = null; ClearInputState(); ClearControls(); if (IsKnown) { Name = profile.Name ?? Info.name; Meta = profile.Meta ?? Info.name; var analogMappingCount = profile.AnalogCount; for (int i = 0; i < analogMappingCount; i++) { var analogMapping = profile.AnalogMappings[i]; var analogControl = AddControl(analogMapping.Target, analogMapping.Handle); analogControl.Sensitivity = Mathf.Min(profile.Sensitivity, analogMapping.Sensitivity); analogControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, analogMapping.LowerDeadZone); analogControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, analogMapping.UpperDeadZone); analogControl.Raw = analogMapping.Raw; analogControl.Passive = analogMapping.Passive; } var buttonMappingCount = profile.ButtonCount; for (int i = 0; i < buttonMappingCount; i++) { var buttonMapping = profile.ButtonMappings[i]; var buttonControl = AddControl(buttonMapping.Target, buttonMapping.Handle); buttonControl.Passive = buttonMapping.Passive; } } else { Name = "Unknown Device"; Meta = Info.name; for (int i = 0; i < NumUnknownButtons; i++) { AddControl(InputControlType.Button0 + i, "Button " + i); } for (int i = 0; i < NumUnknownAnalogs; i++) { AddControl(InputControlType.Analog0 + i, "Analog " + i, 0.2f, 0.9f); } } skipUpdateFrames = 1; }
public bool HasSameSerialNumber(NativeDeviceInfo deviceInfo) { if (string.IsNullOrEmpty(serialNumber)) { return(false); } return(serialNumber == deviceInfo.serialNumber); }
public bool HasSameLocation(NativeDeviceInfo deviceInfo) { if (string.IsNullOrEmpty(location)) { return(false); } return(location == deviceInfo.location); }
private NativeInputDevice FindDetachedDevice(NativeDeviceInfo deviceInfo) { ReadOnlyCollection <NativeInputDevice> arg = new ReadOnlyCollection <NativeInputDevice>(detachedDevices); if (CustomFindDetachedDevice != null) { return(CustomFindDetachedDevice(deviceInfo, arg)); } return(SystemFindDetachedDevice(deviceInfo, arg)); }
private void DetectDevice(uint deviceHandle, NativeDeviceInfo deviceInfo) { NativeInputDeviceProfile nativeInputDeviceProfile = null; nativeInputDeviceProfile = (nativeInputDeviceProfile ?? customDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.Matches(deviceInfo))); nativeInputDeviceProfile = (nativeInputDeviceProfile ?? systemDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.Matches(deviceInfo))); nativeInputDeviceProfile = (nativeInputDeviceProfile ?? customDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.LastResortMatches(deviceInfo))); nativeInputDeviceProfile = (nativeInputDeviceProfile ?? systemDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.LastResortMatches(deviceInfo))); NativeInputDevice nativeInputDevice = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice(); nativeInputDevice.Initialize(deviceHandle, deviceInfo, nativeInputDeviceProfile); AttachDevice(nativeInputDevice); }
bool Matches(NativeDeviceInfo deviceInfo, NativeInputDeviceMatcher[] matchers) { if (Matchers != null) { int matchersCount = Matchers.Length; for (int i = 0; i < matchersCount; i++) { if (Matchers[i].Matches(deviceInfo)) { return(true); } } } return(false); }
static NativeInputDevice SystemFindDetachedDevice(NativeDeviceInfo deviceInfo, ReadOnlyCollection <NativeInputDevice> detachedDevices) { int detachedDevicesCount = detachedDevices.Count; for (int i = 0; i < detachedDevicesCount; i++) { var device = detachedDevices[i]; if (device.Info.HasSameVendorID(deviceInfo) && device.Info.HasSameProductID(deviceInfo) && device.Info.HasSameSerialNumber(deviceInfo)) { return(device); } } for (int i = 0; i < detachedDevicesCount; i++) { var device = detachedDevices[i]; if (device.Info.HasSameVendorID(deviceInfo) && device.Info.HasSameProductID(deviceInfo) && device.Info.HasSameLocation(deviceInfo)) { return(device); } } for (int i = 0; i < detachedDevicesCount; i++) { var device = detachedDevices[i]; if (device.Info.HasSameVendorID(deviceInfo) && device.Info.HasSameProductID(deviceInfo) && device.Info.HasSameVersionNumber(deviceInfo)) { return(device); } } for (int i = 0; i < detachedDevicesCount; i++) { var device = detachedDevices[i]; if (device.Info.HasSameLocation(deviceInfo)) { return(device); } } return(null); }
void DetectDevice(DeviceHandle deviceHandle, NativeDeviceInfo deviceInfo) { // Try to find a matching profile for this device. NativeInputDeviceProfile deviceProfile = null; deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); // Find a matching previously attached device or create a new one. var device = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice(); device.Initialize(deviceHandle, deviceInfo, deviceProfile); AttachDevice(device); }
private static NativeInputDevice SystemFindDetachedDevice(NativeDeviceInfo deviceInfo, ReadOnlyCollection <NativeInputDevice> detachedDevices) { int count = detachedDevices.Count; for (int i = 0; i < count; i++) { NativeInputDevice nativeInputDevice = detachedDevices[i]; if (nativeInputDevice.Info.HasSameVendorID(deviceInfo) && nativeInputDevice.Info.HasSameProductID(deviceInfo) && nativeInputDevice.Info.HasSameSerialNumber(deviceInfo)) { return(nativeInputDevice); } } for (int j = 0; j < count; j++) { NativeInputDevice nativeInputDevice2 = detachedDevices[j]; if (nativeInputDevice2.Info.HasSameVendorID(deviceInfo) && nativeInputDevice2.Info.HasSameProductID(deviceInfo) && nativeInputDevice2.Info.HasSameLocation(deviceInfo)) { return(nativeInputDevice2); } } for (int k = 0; k < count; k++) { NativeInputDevice nativeInputDevice3 = detachedDevices[k]; if (nativeInputDevice3.Info.HasSameVendorID(deviceInfo) && nativeInputDevice3.Info.HasSameProductID(deviceInfo) && nativeInputDevice3.Info.HasSameVersionNumber(deviceInfo)) { return(nativeInputDevice3); } } for (int l = 0; l < count; l++) { NativeInputDevice nativeInputDevice4 = detachedDevices[l]; if (nativeInputDevice4.Info.HasSameLocation(deviceInfo)) { return(nativeInputDevice4); } } return(null); }
public bool HasSameLocation(NativeDeviceInfo deviceInfo) { return(Info.HasSameLocation(deviceInfo)); }
public bool HasSameProductID(NativeDeviceInfo deviceInfo) { return(Info.HasSameProductID(deviceInfo)); }
internal void Initialize(DeviceHandle deviceHandle, NativeDeviceInfo deviceInfo) { Initialize(deviceHandle, deviceInfo, this.profile); }
internal bool Matches(NativeDeviceInfo deviceInfo) { return(Matches(deviceInfo, Matchers)); }
public static extern bool GetDeviceInfo(DeviceHandle handle, out NativeDeviceInfo deviceInfo);
internal void Initialize(uint deviceHandle, NativeDeviceInfo deviceInfo, NativeInputDeviceProfile deviceProfile) { Handle = deviceHandle; Info = deviceInfo; profile = deviceProfile; base.SortOrder = (int)(1000 + Handle); NativeDeviceInfo info = Info; numUnknownButtons = Math.Min((int)info.numButtons, 20); NativeDeviceInfo info2 = Info; numUnknownAnalogs = Math.Min((int)info2.numAnalogs, 20); NativeDeviceInfo info3 = Info; buttons = new short[info3.numButtons]; NativeDeviceInfo info4 = Info; analogs = new short[info4.numAnalogs]; base.AnalogSnapshot = null; ClearInputState(); ClearControls(); if (IsKnown) { string name = profile.Name; if (name == null) { NativeDeviceInfo info5 = Info; name = info5.name; } base.Name = name; string text = profile.Meta; if (text == null) { NativeDeviceInfo info6 = Info; text = info6.name; } base.Meta = text; base.DeviceClass = profile.DeviceClass; base.DeviceStyle = profile.DeviceStyle; int analogCount = profile.AnalogCount; for (int i = 0; i < analogCount; i++) { InputControlMapping inputControlMapping = profile.AnalogMappings[i]; InputControl inputControl = AddControl(inputControlMapping.Target, inputControlMapping.Handle); inputControl.Sensitivity = Mathf.Min(profile.Sensitivity, inputControlMapping.Sensitivity); inputControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, inputControlMapping.LowerDeadZone); inputControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, inputControlMapping.UpperDeadZone); inputControl.Raw = inputControlMapping.Raw; inputControl.Passive = inputControlMapping.Passive; } int buttonCount = profile.ButtonCount; for (int j = 0; j < buttonCount; j++) { InputControlMapping inputControlMapping2 = profile.ButtonMappings[j]; InputControl inputControl2 = AddControl(inputControlMapping2.Target, inputControlMapping2.Handle); inputControl2.Passive = inputControlMapping2.Passive; } } else { base.Name = "Unknown Device"; NativeDeviceInfo info7 = Info; base.Meta = info7.name; for (int k = 0; k < NumUnknownButtons; k++) { AddControl((InputControlType)(500 + k), "Button " + k); } for (int l = 0; l < NumUnknownAnalogs; l++) { AddControl((InputControlType)(400 + l), "Analog " + l, 0.2f, 0.9f); } } skipUpdateFrames = 1; }
internal void Initialize(uint deviceHandle, NativeDeviceInfo deviceInfo) { Initialize(deviceHandle, deviceInfo, profile); }
public static bool GetDeviceInfo(DeviceHandle handle, out NativeDeviceInfo deviceInfo) { deviceInfo = new NativeDeviceInfo(); return(false); }
public bool HasSameVendorID(NativeDeviceInfo deviceInfo) { return(vendorID == deviceInfo.vendorID); }
internal bool LastResortMatches(NativeDeviceInfo deviceInfo) { return(Matches(deviceInfo, LastResortMatchers)); }
public bool HasSameProductID(NativeDeviceInfo deviceInfo) { return(productID == deviceInfo.productID); }
private void OnGUI() { int num = Mathf.FloorToInt(Screen.width / Mathf.Max(1, InputManager.Devices.Count)); int num2 = 10; int num3 = 10; int num4 = 15; GUI.skin.font = font; SetColor(Color.white); string str = "Devices:"; str = str + " (Platform: " + InputManager.Platform + ")"; str = str + " " + InputManager.ActiveDevice.Direction.Vector; if (isPaused) { SetColor(Color.red); str = "+++ PAUSED +++"; } GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), str, style); SetColor(Color.white); foreach (InputDevice device in InputManager.Devices) { bool flag = InputManager.ActiveDevice == device; Color color = (!flag) ? Color.white : Color.yellow; num3 = 35; if (device.IsUnknown) { SetColor(Color.red); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "Unknown Device", style); } else { SetColor(color); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), device.Name, style); } num3 += num4; SetColor(color); if (device.IsUnknown) { GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), device.Meta, style); num3 += num4; } GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "Style: " + device.DeviceStyle, style); num3 += num4; GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "GUID: " + device.GUID, style); num3 += num4; GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "SortOrder: " + device.SortOrder, style); num3 += num4; GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "LastChangeTick: " + device.LastChangeTick, style); num3 += num4; NativeInputDevice nativeInputDevice = device as NativeInputDevice; if (nativeInputDevice != null) { NativeDeviceInfo info = nativeInputDevice.Info; object arg = info.vendorID; NativeDeviceInfo info2 = nativeInputDevice.Info; object arg2 = info2.productID; NativeDeviceInfo info3 = nativeInputDevice.Info; string text = $"VID = 0x{arg:x}, PID = 0x{arg2:x}, VER = 0x{info3.versionNumber:x}"; GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text, style); num3 += num4; } num3 += num4; foreach (InputControl control in device.Controls) { if (control != null && !Utility.TargetIsAlias(control.Target)) { string arg3 = (!device.IsKnown) ? control.Handle : $"{control.Target} ({control.Handle})"; SetColor((!control.State) ? color : Color.green); string text2 = string.Format("{0} {1}", arg3, (!control.State) ? string.Empty : ("= " + control.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text2, style); num3 += num4; } } num3 += num4; color = ((!flag) ? Color.white : new Color(1f, 0.7f, 0.2f)); if (device.IsKnown) { InputControl command = device.Command; SetColor((!command.State) ? color : Color.green); string text3 = string.Format("{0} {1}", "Command", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; command = device.LeftStickX; SetColor((!command.State) ? color : Color.green); text3 = string.Format("{0} {1}", "Left Stick X", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; command = device.LeftStickY; SetColor((!command.State) ? color : Color.green); text3 = string.Format("{0} {1}", "Left Stick Y", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; SetColor((!device.LeftStick.State) ? color : Color.green); text3 = string.Format("{0} {1}", "Left Stick A", (!device.LeftStick.State) ? string.Empty : ("= " + device.LeftStick.Angle)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; command = device.RightStickX; SetColor((!command.State) ? color : Color.green); text3 = string.Format("{0} {1}", "Right Stick X", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; command = device.RightStickY; SetColor((!command.State) ? color : Color.green); text3 = string.Format("{0} {1}", "Right Stick Y", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; SetColor((!device.RightStick.State) ? color : Color.green); text3 = string.Format("{0} {1}", "Right Stick A", (!device.RightStick.State) ? string.Empty : ("= " + device.RightStick.Angle)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; command = device.DPadX; SetColor((!command.State) ? color : Color.green); text3 = string.Format("{0} {1}", "DPad X", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; command = device.DPadY; SetColor((!command.State) ? color : Color.green); text3 = string.Format("{0} {1}", "DPad Y", (!command.State) ? string.Empty : ("= " + command.Value)); GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style); num3 += num4; } SetColor(Color.cyan); InputControl anyButton = device.AnyButton; if ((bool)anyButton) { GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "AnyButton = " + anyButton.Handle, style); } num2 += num; } Color[] array = new Color[3] { Color.gray, Color.yellow, Color.white }; SetColor(Color.white); num2 = 10; num3 = Screen.height - (10 + num4); for (int num5 = logMessages.Count - 1; num5 >= 0; num5--) { LogMessage logMessage = logMessages[num5]; if (logMessage.type != 0) { SetColor(array[(int)logMessage.type]); string[] array2 = logMessage.text.Split('\n'); foreach (string text4 in array2) { GUI.Label(new Rect(num2, num3, Screen.width, num3 + 10), text4, style); num3 -= num4; } } } }
public bool HasSameVersionNumber(NativeDeviceInfo deviceInfo) { return(versionNumber == deviceInfo.versionNumber); }
public bool HasSameVendorID(NativeDeviceInfo deviceInfo) { return(Info.HasSameVendorID(deviceInfo)); }
public static extern bool GetDeviceInfo(UInt32 handle, out NativeDeviceInfo deviceInfo);
public bool HasSameVersionNumber(NativeDeviceInfo deviceInfo) { return(Info.HasSameVersionNumber(deviceInfo)); }
internal bool Matches(NativeDeviceInfo deviceInfo) { var hasMatched = false; if (VendorID.HasValue) { if (VendorID.Value == deviceInfo.vendorID) { hasMatched = true; } else { return(false); } } if (ProductID.HasValue) { if (ProductID.Value == deviceInfo.productID) { hasMatched = true; } else { return(false); } } if (VersionNumber.HasValue) { if (VersionNumber.Value == deviceInfo.versionNumber) { hasMatched = true; } else { return(false); } } if (DriverType.HasValue) { if (DriverType.Value == deviceInfo.driverType) { hasMatched = true; } else { return(false); } } if (TransportType.HasValue) { if (TransportType.Value == deviceInfo.transportType) { hasMatched = true; } else { return(false); } } if (NameLiterals != null && NameLiterals.Length > 0) { var nameLiteralsCount = NameLiterals.Length; for (var i = 0; i < nameLiteralsCount; i++) { if (String.Equals(deviceInfo.name, NameLiterals[i], StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); } if (NamePatterns != null && NamePatterns.Length > 0) { var namePatternsCount = NamePatterns.Length; for (var i = 0; i < namePatternsCount; i++) { if (Regex.IsMatch(deviceInfo.name, NamePatterns[i], RegexOptions.IgnoreCase)) { return(true); } } return(false); } return(hasMatched); }
public bool HasSameSerialNumber(NativeDeviceInfo deviceInfo) { return(Info.HasSameSerialNumber(deviceInfo)); }
internal bool Matches(NativeDeviceInfo deviceInfo) { bool result = false; if (VendorID.HasValue) { if (VendorID.Value != deviceInfo.vendorID) { return(false); } result = true; } if (ProductID.HasValue) { if (ProductID.Value != deviceInfo.productID) { return(false); } result = true; } if (VersionNumber.HasValue) { if (VersionNumber.Value != deviceInfo.versionNumber) { return(false); } result = true; } if (DriverType.HasValue) { if (DriverType.Value != deviceInfo.driverType) { return(false); } result = true; } if (TransportType.HasValue) { if (TransportType.Value != deviceInfo.transportType) { return(false); } result = true; } if (NameLiterals != null && NameLiterals.Length > 0) { int num = NameLiterals.Length; for (int i = 0; i < num; i++) { if (string.Equals(deviceInfo.name, NameLiterals[i], StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); } if (NamePatterns != null && NamePatterns.Length > 0) { int num2 = NamePatterns.Length; for (int j = 0; j < num2; j++) { if (Regex.IsMatch(deviceInfo.name, NamePatterns[j], RegexOptions.IgnoreCase)) { return(true); } } return(false); } return(result); }