diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe8b35c --- /dev/null +++ b/.gitignore @@ -0,0 +1,353 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ \ No newline at end of file diff --git a/App.config b/App.config new file mode 100644 index 0000000..8324aa6 --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/GHL_HIDEmulator.csproj b/GHL_HIDEmulator.csproj new file mode 100644 index 0000000..b10af72 --- /dev/null +++ b/GHL_HIDEmulator.csproj @@ -0,0 +1,70 @@ + + + + + Debug + AnyCPU + {0D557714-9CE9-415E-893C-ED0277E6FD61} + Exe + GHL_HIDEmulator + GHL_HIDEmulator + v4.6 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\JetBrains.Annotations.2018.3.0\lib\net20\JetBrains.Annotations.dll + + + ..\packages\LibUsbDotNet.2.2.8\lib\LibUsbDotNet.dll + + + + + ..\packages\Nefarius.ViGEm.Client.1.16.150\lib\net452\Nefarius.ViGEm.Client.dll + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..552c40f --- /dev/null +++ b/Program.cs @@ -0,0 +1,119 @@ +using LibUsbDotNet; +using LibUsbDotNet.Main; +using LibUsbDotNet.WinUsb; +using System; +using System.Collections.Generic; +using System.Text; +using Nefarius; +using Nefarius.ViGEm.Client; +using Nefarius.ViGEm.Client.Targets; +using Nefarius.ViGEm.Client.Targets.Xbox360; + +namespace GHL_HIDEmulator +{ + class Program + { + public static void Main(string[] args) + { + Console.Title = "GHL HID Emulator"; + UsbDevice guitar = null; + foreach(WinUsbRegistry device in LibUsbDotNet.UsbDevice.AllWinUsbDevices) + { + // USB\VID_12BA&PID_074B + if (device.Vid == 0x12BA && device.Pid == 0x074B) + { + guitar = device.Device; + } + } + if (guitar == null) + { + Console.WriteLine("Could not find any Guitar Hero Live guitars."); + Console.WriteLine("Make sure you are using a PS3/Wii U Guitar Hero Live dongle with the WinUSB driver installed."); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(true); + return; + } + + // Set up Virtual Xbox 360 controller + ViGEmClient client; + try + { + client = new ViGEmClient(); + } catch (Exception) + { + Console.WriteLine("Failed to initialise ViGEm Client. Make sure you have the ViGEm bus driver installed."); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(true); + return; + } + + IXbox360Controller controller = client.CreateXbox360Controller(); + controller.Connect(); + Console.WriteLine($"Found a Guitar Hero Live guitar!"); + + var reader = guitar.OpenEndpointReader(ReadEndpointID.Ep01); + + byte[] readBuffer = new byte[27]; + int runner = 0; + while (true) + { + if (runner == 0) + { + // Send control packet (to enable strumming) + byte[] buffer = new byte[9] { 0x02, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + int bytesWrote; + UsbSetupPacket setupPacket = new UsbSetupPacket(0x21, 0x09, 0x0201, 0x0000, 0x0008); + guitar.ControlTransfer(ref setupPacket, buffer, 0x0008, out bytesWrote); + } + runner++; + if (runner > 500) runner = 0; + + int bytesRead; + reader.Read(readBuffer, 100, out bytesRead); + Console.SetCursorPosition(0, 1); + Console.WriteLine("Frets: " + BitConverter.ToString(new byte[] { readBuffer[0] })); + Console.WriteLine("Buttons: " + BitConverter.ToString(new byte[] { readBuffer[1] })); + Console.WriteLine("Tilt: " + BitConverter.ToString(new byte[] { readBuffer[19] })); + Console.WriteLine("Whammy: " + BitConverter.ToString(new byte[] { readBuffer[6] })); + Console.WriteLine("Strum: " + (readBuffer[4] == 0x00 || readBuffer[4] == 0xFF) + " "); + Console.WriteLine("Raw Data: " + BitConverter.ToString(readBuffer)); + + byte frets = readBuffer[0]; + controller.SetButtonState(Xbox360Button.A, (frets & 0x02) != 0x00); // B1 + controller.SetButtonState(Xbox360Button.B, (frets & 0x04) != 0x00); // B2 + controller.SetButtonState(Xbox360Button.Y, (frets & 0x08) != 0x00); // B3 + controller.SetButtonState(Xbox360Button.X, (frets & 0x01) != 0x00); // W1 + controller.SetButtonState(Xbox360Button.LeftShoulder, (frets & 0x10) != 0x00); // W2 + controller.SetButtonState(Xbox360Button.RightShoulder, (frets & 0x20) != 0x00); // W3 + + byte strum = readBuffer[4]; + if (strum == 0xFF) + { + // Strum Down + controller.SetButtonState(Xbox360Button.Down, true); + controller.SetButtonState(Xbox360Button.Up, false); + } else if (strum == 0x00) + { + // Strum Up + controller.SetButtonState(Xbox360Button.Down, false); + controller.SetButtonState(Xbox360Button.Up, true); + } else + { + // No Strum + controller.SetButtonState(Xbox360Button.Down, false); + controller.SetButtonState(Xbox360Button.Up, false); + } + + byte buttons = readBuffer[1]; + controller.SetButtonState(Xbox360Button.Start, (buttons & 0x02) != 0x00); // Pause + controller.SetButtonState(Xbox360Button.Back, (buttons & 0x01) != 0x00); // Hero Power + + // ViGEm isn't co-operating here - setting to some weird value causes an issue. + //controller.SetAxisValue(Xbox360Axis.RightThumbY, (short)(~readBuffer[6]-128)); + //controller.SetAxisValue(Xbox360Axis.RightThumbX, readBuffer[19]); + + Console.WriteLine("Emulating as Xbox 360 Controller " + (controller.UserIndex + 1)); + } + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..adb136a --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("GHL_HIDEmulator")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GHL_HIDEmulator")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[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("0d557714-9ce9-415e-893c-ed0277e6fd61")] + +// 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")] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ebb0c32 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# GHL_HIDEmulator + +Emulate an Xbox 360 Guitar Hero Live guitar using a PS3/Wii U GHL dongle to use in Clone Hero. This uses the [ViGEm Bus Driver](https://github.com/ViGEm/ViGEmBus/releases) to emulate an Xbox 360 controller. \ No newline at end of file diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..4a6148b --- /dev/null +++ b/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file