-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add WinUSB Manager and Rez TranceVibrator support
Add WinUSB Device manager for handling devices that require WinUSB (Zadig) drivers. Add Rez TranceVibrator support on Windows 7 (Won't work on win 10 due to USB descriptor issues). Fixes #235
- Loading branch information
Showing
9 changed files
with
326 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Buttplug.Server.Managers.WinUSBManager/Buttplug.Server.Managers.WinUSBManager.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{0F5DAB4B-184B-4B7E-9F40-339C7F5E216F}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Buttplug.Server.Managers.WinUSBManager</RootNamespace> | ||
<AssemblyName>Buttplug.Server.Managers.WinUSBManager</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<CodeAnalysisRuleSet>..\Buttplug.ProjectFiles\ButtplugCodeAnalysisRules.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="WinUSBNet, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\WinUSBNet.1.0.3\lib\net35\WinUSBNet.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="RezTranceVibratorDevice.cs" /> | ||
<Compile Include="WinUSBManager.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Buttplug.Core\Buttplug.Core.csproj"> | ||
<Project>{fc4af8fe-8c21-4e07-8d24-7fb7791149d0}</Project> | ||
<Name>Buttplug.Core</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Buttplug.Server\Buttplug.Server.csproj"> | ||
<Project>{23d9ec18-2dba-4149-a951-b84786d4bfa6}</Project> | ||
<Name>Buttplug.Server</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<AdditionalFiles Include="..\Buttplug.ProjectFiles\stylecop.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.0-beta004\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" /> | ||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.0-beta004\analyzers\dotnet\cs\StyleCop.Analyzers.dll" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
39 changes: 39 additions & 0 deletions
39
Buttplug.Server.Managers.WinUSBManager/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using Buttplug.Core; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Buttplug.Server.Managers.WinUSBManager")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Buttplug.Server.Managers.WinUSBManager")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("0f5dab4b-184b-4b7e-9f40-339c7f5e216f")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
[assembly: AssemblyInformationalVersion("1.0.0.0-dev")] | ||
[assembly: AssemblyGitVersion("")] |
90 changes: 90 additions & 0 deletions
90
Buttplug.Server.Managers.WinUSBManager/RezTranceVibratorDevice.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Buttplug.Core; | ||
using Buttplug.Core.Messages; | ||
using MadWizard.WinUSBNet; | ||
|
||
namespace Buttplug.Server.Managers.WinUSBManager | ||
{ | ||
internal class RezTranceVibratorDevice : ButtplugDevice | ||
{ | ||
private static uint _vibratorCount = 1; | ||
private USBDevice _device; | ||
|
||
public RezTranceVibratorDevice(IButtplugLogManager aLogManager, USBDevice aDevice, uint aIndex) | ||
: base(aLogManager, "Trancevibrator " + aIndex, "Trancevibrator " + aIndex) | ||
{ | ||
_device = aDevice; | ||
MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd)); | ||
MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd)); | ||
MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd)); | ||
} | ||
|
||
public override void Disconnect() | ||
{ | ||
} | ||
|
||
private Task<ButtplugMessage> HandleStopDeviceCmd(ButtplugDeviceMessage aMsg) | ||
{ | ||
BpLogger.Debug("Stopping Device " + Name); | ||
return HandleSingleMotorVibrateCmd(new SingleMotorVibrateCmd(aMsg.DeviceIndex, 0, aMsg.Id)); | ||
} | ||
|
||
private Task<ButtplugMessage> HandleVibrateCmd(ButtplugDeviceMessage aMsg) | ||
{ | ||
if (!(aMsg is VibrateCmd cmdMsg)) | ||
{ | ||
return Task.FromResult<ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); | ||
} | ||
|
||
if (cmdMsg.Speeds.Count == 0 || cmdMsg.Speeds.Count > _vibratorCount) | ||
{ | ||
return Task.FromResult<ButtplugMessage>(new Error("VibrateCmd requires 1 speed for this device.", | ||
Error.ErrorClass.ERROR_DEVICE, | ||
cmdMsg.Id)); | ||
} | ||
|
||
foreach (var v in cmdMsg.Speeds) | ||
{ | ||
if (v.Index >= _vibratorCount) | ||
{ | ||
return Task.FromResult<ButtplugMessage>(new Error( | ||
$"Index {v.Index} is out of bounds for VibrateCmd for this device.", | ||
Error.ErrorClass.ERROR_DEVICE, | ||
cmdMsg.Id)); | ||
} | ||
|
||
var speed = (byte)Math.Floor(v.Speed * 255); | ||
_device.ControlOut( | ||
0x02 << 5 | // Vendor Type | ||
0x01 | // Interface Recipient | ||
0x00, // Out Enpoint | ||
1, | ||
speed, | ||
0); | ||
} | ||
|
||
return Task.FromResult<ButtplugMessage>(new Ok(aMsg.Id)); | ||
} | ||
|
||
private Task<ButtplugMessage> HandleSingleMotorVibrateCmd(ButtplugDeviceMessage aMsg) | ||
{ | ||
var cmdMsg = aMsg as SingleMotorVibrateCmd; | ||
if (cmdMsg is null) | ||
{ | ||
return Task.FromResult<ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")); | ||
} | ||
|
||
var speeds = new List<VibrateCmd.VibrateSubcommand>(); | ||
for (uint i = 0; i < _vibratorCount; i++) | ||
{ | ||
speeds.Add(new VibrateCmd.VibrateSubcommand(i, cmdMsg.Speed)); | ||
} | ||
|
||
return HandleVibrateCmd(new VibrateCmd(aMsg.DeviceIndex, speeds, aMsg.Id)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using Buttplug.Core; | ||
using MadWizard.WinUSBNet; | ||
using Microsoft.Win32; | ||
|
||
namespace Buttplug.Server.Managers.WinUSBManager | ||
{ | ||
public class WinUSBManager : DeviceSubtypeManager | ||
{ | ||
public WinUSBManager(IButtplugLogManager aLogManager) | ||
: base(aLogManager) | ||
{ | ||
BpLogger.Info("Loading WinUSB Manager"); | ||
} | ||
|
||
public override void StartScanning() | ||
{ | ||
BpLogger.Info("WinUSBManager start scanning"); | ||
var deviceKey = | ||
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB\VID_0B49&PID_064F"); | ||
if (deviceKey == null) | ||
{ | ||
BpLogger.Debug("No TranceVibrator Devices found in registry."); | ||
InvokeScanningFinished(); | ||
return; | ||
} | ||
|
||
var deviceKeyNames = deviceKey.GetSubKeyNames(); | ||
if (deviceKeyNames.Length == 0) | ||
{ | ||
BpLogger.Debug("No TranceVibrator Devices with drivers found in registry."); | ||
InvokeScanningFinished(); | ||
return; | ||
} | ||
|
||
var deviceSubKey = deviceKey.OpenSubKey(deviceKeyNames[0]); | ||
if (deviceSubKey == null) | ||
{ | ||
BpLogger.Debug("No TranceVibrator Devices with drivers subkeys found in registry."); | ||
InvokeScanningFinished(); | ||
return; | ||
} | ||
|
||
var deviceParameters = deviceSubKey.OpenSubKey("Device Parameters"); | ||
if (deviceParameters == null) | ||
{ | ||
BpLogger.Debug("No TranceVibrator Devices with drivers parameters found in registry."); | ||
InvokeScanningFinished(); | ||
return; | ||
} | ||
|
||
var deviceGUID = (string[])deviceParameters.GetValue("DeviceInterfaceGUIDs", string.Empty); | ||
if (deviceGUID == null || deviceGUID.ToString().Length == 0) | ||
{ | ||
BpLogger.Debug("No TranceVibrator Devices Driver GUIDs found in registry."); | ||
InvokeScanningFinished(); | ||
return; | ||
} | ||
|
||
// Only valid for our Trancevibrator install | ||
var devices = USBDevice.GetDevices(deviceGUID[0]); | ||
if (devices == null || devices.Length == 0) | ||
{ | ||
BpLogger.Error("No USB Device found!"); | ||
InvokeScanningFinished(); | ||
return; | ||
} | ||
|
||
uint index = 0; | ||
foreach (var deviceinfo in devices) | ||
{ | ||
var device = new USBDevice(deviceinfo); | ||
BpLogger.Debug($"Found TranceVibrator Device"); | ||
var tvDevice = new RezTranceVibratorDevice(LogManager, device, index); | ||
index += 1; | ||
InvokeDeviceAdded(new DeviceAddedEventArgs(tvDevice)); | ||
} | ||
|
||
InvokeScanningFinished(); | ||
} | ||
|
||
public override void StopScanning() | ||
{ | ||
// noop | ||
} | ||
|
||
public override bool IsScanning() | ||
{ | ||
// noop | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="WinUSBNet" version="1.0.3" targetFramework="net452" /> | ||
<package id="StyleCop.Analyzers" version="1.1.0-beta004" targetFramework="net452" developmentDependency="true" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters