├── .gitignore ├── App.config ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── packages.config ├── skybutt.csproj └── skybutt.sln /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using Buttplug.Client; 2 | using Buttplug.Core; 3 | using Buttplug.Core.Messages; 4 | using Buttplug.Client.Connectors.WebsocketConnector; 5 | using LanguageExt; 6 | using static LanguageExt.Prelude; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | using System.Threading; 12 | using System.IO; 13 | 14 | namespace skybutt 15 | { 16 | internal class Program 17 | { 18 | private static async Task WaitForKey() 19 | { 20 | Console.WriteLine("Press any key to continue."); 21 | while (!Console.KeyAvailable) 22 | { 23 | await Task.Delay(1); 24 | } 25 | Console.ReadKey(true); 26 | } 27 | 28 | private static async Task RunExample(string logFile) 29 | { 30 | // Now that we've seen all of the different parts of Buttplug, let's 31 | // put them together in a small program. 32 | // 33 | // This program will: 34 | // - Create an embedded (or possibly websocket) connector 35 | // - Scan, this time using real Managers, so we'll see devices 36 | // (assuming you have them hooked up) 37 | // - List the connected devices for the user 38 | // - Let the user select a device, and trigger some sort of event on 39 | // that device (vibration, thrusting, etc...). 40 | 41 | // As usual, we start off with our connector setup. We really don't 42 | // need access to the connector this time, so we can just pass the 43 | // created connector directly to the client. 44 | //var client = new ButtplugClient("skybutt client", 45 | // new ButtplugEmbeddedConnector("skybutt server")); 46 | 47 | // If you want to use a websocket client and talk to a websocket 48 | // server instead, uncomment the following line and comment the one 49 | // above out. Note you will need to turn off TLS/SSL on the server. 50 | 51 | var client = new ButtplugClient("skybutt client", new 52 | ButtplugWebsocketConnector(new Uri("ws://localhost:12345/buttplug"))); 53 | 54 | await client.ConnectAsync(); 55 | 56 | // At this point, if you want to see everything that's happening, 57 | // uncomment this block to turn on logging. Warning, it might be 58 | // pretty spammy. 59 | 60 | // void HandleLogMessage(object aObj, LogEventArgs aArgs) { 61 | // Console.WriteLine($"LOG: {aArgs.Message.LogMessage}"); } 62 | // client.Log += HandleLogMessage; await client.RequestLogAsync(ButtplugLogLevel.Debug); 63 | 64 | // Now we scan for devices. Since we didn't add any Subtype Managers 65 | // yet, this will go out and find them for us. They'll be reported in 66 | // the logs as they are found. 67 | // 68 | // We'll scan for devices, and print any time we find one. 69 | void HandleDeviceAdded(object aObj, DeviceAddedEventArgs aArgs) 70 | { 71 | Console.WriteLine($"Device connected: {aArgs.Device.Name}"); 72 | } 73 | 74 | client.DeviceAdded += HandleDeviceAdded; 75 | 76 | void HandleDeviceRemoved(object aObj, DeviceRemovedEventArgs aArgs) 77 | { 78 | Console.WriteLine($"Device connected: {aArgs.Device.Name}"); 79 | } 80 | 81 | client.DeviceRemoved += HandleDeviceRemoved; 82 | 83 | // The structure here is gonna get a little weird now, because I'm 84 | // using method scoped functions. We'll be defining our scanning 85 | // function first, then running it just to find any devices up front. 86 | // Then we'll define our command sender. Finally, with all of that 87 | // done, we'll end up in our main menu 88 | 89 | // Here's the scanning part. Pretty simple, just scan until the user 90 | // hits a button. Any time a new device is found, print it so the 91 | // user knows we found it. 92 | async Task ScanForDevices() 93 | { 94 | Console.WriteLine("Scanning for devices until key is pressed."); 95 | Console.WriteLine("Found devices will be printed to console."); 96 | await client.StartScanningAsync(); 97 | await WaitForKey(); 98 | 99 | // Stop scanning now, 'cause we don't want new devices popping up anymore. 100 | await client.StopScanningAsync(); 101 | } 102 | 103 | // Scan for devices before we get to the main menu. 104 | await ScanForDevices(); 105 | 106 | // Now we define the device control menus. After we've scanned for 107 | // devices, the user can use this menu to select a device, then 108 | // select an action for that device to take. 109 | async Task ControlDevice() 110 | { 111 | // Controlling a device has 2 steps: selecting the device to 112 | // control, and choosing which command to send. We'll just list 113 | // the devices the client has available, then search the device 114 | // message capabilities once that's done to figure out what we 115 | // can send. Note that this is using the Device Index, which is 116 | // assigned by the device manager and may not be sequential 117 | // (which is why we can't just use an array index). 118 | 119 | // Of course, if we don't have any devices yet, that's not gonna work. 120 | if (!client.Devices.Any()) 121 | { 122 | Console.WriteLine("No devices available. Please scan for a device."); 123 | return; 124 | } 125 | 126 | var options = new List(); 127 | 128 | foreach (var dev in client.Devices) 129 | { 130 | Console.WriteLine($"{dev.Index}. {dev.Name}"); 131 | options.Add(dev.Index); 132 | } 133 | uint vaginalDeviceChoice; 134 | if (options.Length() == 1) 135 | { 136 | vaginalDeviceChoice = client.Devices.Head().Index; 137 | } else 138 | { 139 | Console.WriteLine("Choose vaginal device: "); 140 | if (!uint.TryParse(Console.ReadLine(), out vaginalDeviceChoice) || 141 | !options.Contains(vaginalDeviceChoice)) 142 | { 143 | Console.WriteLine("Invalid choice"); 144 | return; 145 | } 146 | } 147 | uint analDeviceChoice; 148 | if (options.Length() == 1) 149 | { 150 | analDeviceChoice = client.Devices.Head().Index; 151 | } else 152 | { 153 | Console.WriteLine("Choose anal device: "); 154 | if (!uint.TryParse(Console.ReadLine(), out analDeviceChoice) || 155 | !options.Contains(analDeviceChoice)) 156 | { 157 | Console.WriteLine("Invalid choice"); 158 | return; 159 | } 160 | } 161 | 162 | var vaginalDevice = client.Devices.First(dev => dev.Index == vaginalDeviceChoice); 163 | foreach (var m in vaginalDevice.AllowedMessages) 164 | { 165 | Console.WriteLine($"Device message: {m.Key} -> {m.Value}"); 166 | } 167 | 168 | var analDevice = client.Devices.First(dev => dev.Index == analDeviceChoice); 169 | foreach (var m in analDevice.AllowedMessages) 170 | { 171 | Console.WriteLine($"Device message: {m.Key} -> {m.Value}"); 172 | } 173 | 174 | Console.WriteLine("Watching Controller Rumble log file"); 175 | await WatchLogFileAsync(logFile, client, vaginalDevice, analDevice); 176 | } 177 | 178 | async Task ControlDeviceRandom() 179 | { 180 | // Controlling a device has 2 steps: selecting the device to 181 | // control, and choosing which command to send. We'll just list 182 | // the devices the client has available, then search the device 183 | // message capabilities once that's done to figure out what we 184 | // can send. Note that this is using the Device Index, which is 185 | // assigned by the device manager and may not be sequential 186 | // (which is why we can't just use an array index). 187 | 188 | // Of course, if we don't have any devices yet, that's not gonna work. 189 | if (!client.Devices.Any()) 190 | { 191 | Console.WriteLine("No devices available. Please scan for a device."); 192 | return; 193 | } 194 | 195 | var options = new List(); 196 | 197 | foreach (var dev in client.Devices) 198 | { 199 | Console.WriteLine($"{dev.Index}. {dev.Name}"); 200 | options.Add(dev.Index); 201 | } 202 | uint deviceChoice; 203 | if (options.Length() == 1) 204 | { 205 | deviceChoice = client.Devices.Head().Index; 206 | } else 207 | { 208 | Console.WriteLine("Choose a device: "); 209 | if (!uint.TryParse(Console.ReadLine(), out deviceChoice) || 210 | !options.Contains(deviceChoice)) 211 | { 212 | Console.WriteLine("Invalid choice"); 213 | return; 214 | } 215 | } 216 | 217 | var device = client.Devices.First(dev => dev.Index == deviceChoice); 218 | 219 | await RunRandom(client, device); 220 | } 221 | 222 | // And finally, we arrive at the main menu. We give the user the 223 | // choice to scan for more devices (in case they forgot to turn them 224 | // on earlier or whatever), run a command on a device, or just quit. 225 | while (true) 226 | { 227 | Console.WriteLine("1. Scan For More Devices\n2. Run Skyrim vibrator\n3. Randomly vibrate\n4. Quit\nChoose an option: "); 228 | if (!uint.TryParse(Console.ReadLine(), out var choice) || 229 | (choice == 0 || choice > 4)) 230 | { 231 | Console.WriteLine("Invalid choice, try again."); 232 | continue; 233 | } 234 | 235 | switch (choice) 236 | { 237 | case 1: 238 | await ScanForDevices(); 239 | continue; 240 | case 2: 241 | await ControlDevice(); 242 | continue; 243 | case 3: 244 | await ControlDeviceRandom(); 245 | continue; 246 | case 4: 247 | return; 248 | 249 | default: 250 | // Due to the check above, we'll never hit this, but eh. 251 | continue; 252 | } 253 | } 254 | } 255 | 256 | static async Task RunRandom(ButtplugClient client, ButtplugClientDevice device) 257 | { 258 | var rnd = new Random(); 259 | while (true) 260 | { 261 | var delay = rnd.NextDouble() * 0.5 + rnd.NextDouble() * rnd.NextDouble() * 10.0; 262 | try 263 | { 264 | if (IsVorze(device)) 265 | { 266 | await device.SendVorzeA10CycloneCmd(Convert.ToUInt32(rnd.Next(101)), rnd.Next(2) == 0 ? true : false); 267 | } else 268 | { 269 | bool shouldStop = rnd.NextDouble() < 0.35; 270 | double strength = shouldStop ? 0 : rnd.NextDouble(); 271 | await device.SendVibrateCmd(strength); 272 | } 273 | } 274 | catch (ButtplugDeviceException e) 275 | { 276 | Console.WriteLine($"Device error: {e}"); 277 | device = await AttemptReconnect(client, device); 278 | } 279 | catch (Exception e) 280 | { 281 | Console.WriteLine("Unknown exception, attempting reconnect anyway. Exception: " + e); 282 | device = await AttemptReconnect(client, device); 283 | } 284 | await Task.Delay(TimeSpan.FromSeconds(delay)); 285 | } 286 | } 287 | 288 | static async Task AttemptReconnect(ButtplugClient client, ButtplugClientDevice device) 289 | { 290 | Console.WriteLine("Attempting to reconnect device" + device.Name); 291 | await client.StartScanningAsync(); 292 | return await _AttemptReconnect(client, device); 293 | } 294 | 295 | static async Task _AttemptReconnect(ButtplugClient client, ButtplugClientDevice device) 296 | { 297 | await Task.Delay(500); 298 | var deviceOption = client.Devices.Find(d => d.Name.Equals(device.Name)); 299 | return await deviceOption.Match((ButtplugClientDevice d) => 300 | { 301 | client.StopScanningAsync(); 302 | return Task.FromResult(d); 303 | }, async () => 304 | { 305 | return await _AttemptReconnect(client, device); 306 | }); 307 | } 308 | 309 | static async Task WatchLogFileAsync(string filename, ButtplugClient client, ButtplugClientDevice vaginalDevice, ButtplugClientDevice analDevice) 310 | { 311 | var wh = new AutoResetEvent(false); 312 | var fsw = new FileSystemWatcher("."); 313 | fsw.Filter = filename; 314 | fsw.EnableRaisingEvents = true; 315 | fsw.Changed += (s, e) => wh.Set(); 316 | 317 | var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 318 | fs.Seek(0, SeekOrigin.End); 319 | 320 | // Watch the file 321 | VibrateStatus currentSetting = VibrateStatus.Stopped(); 322 | using (var sr = new StreamReader(fs)) 323 | { 324 | while (true) 325 | { 326 | // Reset position for new file 327 | if (fs.Position > fs.Length) 328 | fs.Seek(0, SeekOrigin.Begin); 329 | 330 | string s = sr.ReadLine(); 331 | if (s != null) 332 | { 333 | bool isAnal = s.Contains("JNAnal"); 334 | bool isVaginal = s.Contains("JNVaginal"); 335 | if (isAnal || isVaginal) 336 | { 337 | var deviceToSendTo = isAnal ? analDevice : vaginalDevice; 338 | Either vlOrE = ParseVibrateLine(s); 339 | Console.WriteLine("[RumbleLog] " + vlOrE); 340 | await vlOrE.Match(async vl => 341 | { 342 | try 343 | { 344 | if (vl is VibrateStart) 345 | { 346 | currentSetting = await HandleVibrateStart(deviceToSendTo, vl as VibrateStart, currentSetting); 347 | } 348 | else if (vl is VibrateStop) 349 | { 350 | await HandleVibrateStop(deviceToSendTo); 351 | currentSetting = VibrateStatus.Stopped(); 352 | } 353 | } 354 | catch (ButtplugDeviceException e) 355 | { 356 | Console.WriteLine(e); 357 | Console.WriteLine("Device disconnected."); 358 | deviceToSendTo = await AttemptReconnect(client, deviceToSendTo); 359 | } 360 | catch (Exception e) 361 | { 362 | Console.WriteLine("Unknown exception, attempting reconnect anyway. Exception: " + e); 363 | deviceToSendTo = await AttemptReconnect(client, deviceToSendTo); 364 | } 365 | }, async e => Console.WriteLine(e)); 366 | } 367 | } 368 | else 369 | { 370 | wh.WaitOne(10); 371 | } 372 | } 373 | } 374 | 375 | // TODO end loop 376 | //wh.Close(); 377 | } 378 | 379 | private static async Task HandleVibrateStart(ButtplugClientDevice device, VibrateStart vs, VibrateStatus status) 380 | { 381 | if (IsVorze(device)) 382 | { 383 | var newDirection = random(2) == 0 ? true : false; 384 | await device.SendVorzeA10CycloneCmd(Convert.ToUInt32(vs.strength * 100), newDirection); 385 | return await vs.time.MatchAsync(async time => 386 | { 387 | await Task.Delay(time); 388 | await device.SendVorzeA10CycloneCmd(StrengthToVorzeRotation(status.strength), status.direction); 389 | return status; 390 | }, () => new VibrateStatus(vs.strength, newDirection)); 391 | } 392 | else 393 | { 394 | await device.SendVibrateCmd(vs.strength); 395 | // TODO handle intervals 396 | return await vs.time.MatchAsync(async time => 397 | { 398 | await Task.Delay(time); 399 | await device.SendVibrateCmd(status.strength); 400 | return status; 401 | }, () => new VibrateStatus(vs.strength, false)); 402 | } 403 | } 404 | 405 | private static bool IsVorze(ButtplugClientDevice device) 406 | { 407 | return device.AllowedMessages.ContainsKey(typeof(VorzeA10CycloneCmd)); 408 | } 409 | 410 | private static UInt32 StrengthToVorzeRotation(double strength) 411 | { 412 | return Convert.ToUInt32(Math.Pow(strength, 2) * 80); 413 | } 414 | 415 | private static async Task HandleVibrateStop(ButtplugClientDevice device) 416 | { 417 | await device.StopDeviceCmd(); 418 | } 419 | 420 | static Either ParseVibrateLine(string s) 421 | { 422 | Arr parts = new Arr(s.ToLower().Split(' ')); 423 | if (parts.Contains("start")) 424 | { 425 | Map dict = new Map(parts.Filter(s_ => s_.Contains("=")).Map(p => 426 | { 427 | string[] pp = p.Split('='); 428 | return (pp.First(), pp.Last()); 429 | })); 430 | try 431 | { 432 | return Right(new VibrateStart( 433 | dict["type"], dict.Find("time").Map(Double.Parse), dict.Find("interval").Map(Double.Parse), Double.Parse(dict["strength"]))); 434 | } 435 | catch (Exception e) 436 | { 437 | return Left(e); 438 | } 439 | } 440 | else if (parts.Contains("stop")) 441 | return Right(new VibrateStop()); 442 | else 443 | return Right(new VibrateNone()); 444 | } 445 | 446 | class VibrateStatus 447 | { 448 | public double strength; 449 | public bool direction; 450 | 451 | public VibrateStatus(double strength, bool direction) 452 | { 453 | this.strength = strength; 454 | this.direction = direction; 455 | } 456 | 457 | public static VibrateStatus Stopped() 458 | { 459 | return new VibrateStatus(0, true); 460 | } 461 | } 462 | 463 | interface VibrateCommand {} 464 | 465 | class VibrateStart : VibrateCommand 466 | { 467 | private const double StrengthFactor = 100; 468 | public string type; 469 | public Option time; 470 | public Option interval; 471 | public double strength; 472 | 473 | public VibrateStart(string type, Option time, Option interval, double strength) 474 | { 475 | this.type = type; 476 | this.time = time.Bind(t => t == -1 ? None : Some(TimeSpan.FromSeconds(t))); 477 | this.interval = interval.Bind(t => t == -1 ? None : Some(TimeSpan.FromSeconds(t))); 478 | this.strength = strength / StrengthFactor; 479 | } 480 | 481 | public override string ToString() 482 | { 483 | return "VibrateStart(type: " + type + ", time: " + time + ", strength: " + strength + ")"; 484 | } 485 | } 486 | 487 | class VibrateStop : VibrateCommand {} 488 | 489 | class VibrateNone : VibrateCommand {} 490 | 491 | // Since not everyone is probably going to want to run under C# 7.1+, 492 | // we'll use a non-async Main and call to a Wait()'d task. C# 8 can't 493 | // come soon enough. 494 | private static void Main() 495 | { 496 | string logFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), 497 | "My Games", "Skyrim", "Logs", "Script", "User", "Controller Rumble.0.log"); 498 | // Setup a client, and wait until everything is done before exiting. 499 | RunExample(logFile).Wait(); 500 | } 501 | } 502 | } -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("skybutt")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("skybutt")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7c01f517-b8a9-46f1-80a2-38acacf7f61b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /skybutt.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7C01F517-B8A9-46F1-80A2-38ACACF7F61B} 8 | Exe 9 | skybutt 10 | skybutt 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | false 16 | publish\ 17 | true 18 | Disk 19 | false 20 | Foreground 21 | 7 22 | Days 23 | false 24 | false 25 | true 26 | Me 27 | true 28 | 5 29 | 1.0.0.%2a 30 | false 31 | true 32 | true 33 | 34 | 35 | AnyCPU 36 | true 37 | full 38 | false 39 | bin\Debug\ 40 | DEBUG;TRACE 41 | prompt 42 | 4 43 | 44 | 45 | AnyCPU 46 | pdbonly 47 | true 48 | bin\Release\ 49 | TRACE 50 | prompt 51 | 4 52 | 53 | 54 | 9217B942AFB21195F74CD0504C1282DF029F7030 55 | 56 | 57 | skybutt_TemporaryKey.pfx 58 | 59 | 60 | true 61 | 62 | 63 | false 64 | 65 | 66 | 67 | packages\Buttplug.0.4.6\lib\net47\Buttplug.dll 68 | 69 | 70 | packages\Buttplug.Client.Connectors.WebsocketConnector.0.4.6\lib\net47\Buttplug.Client.Connectors.WebsocketConnector.dll 71 | 72 | 73 | packages\deniszykov.WebSocketListener.4.2.4\lib\net45\deniszykov.WebSocketListener.dll 74 | 75 | 76 | packages\JetBrains.Annotations.2019.1.1\lib\net20\JetBrains.Annotations.dll 77 | 78 | 79 | packages\LanguageExt.Core.3.1.24\lib\net45\LanguageExt.Core.dll 80 | 81 | 82 | packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll 83 | 84 | 85 | packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll 86 | 87 | 88 | packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll 89 | 90 | 91 | 92 | 93 | 94 | 95 | packages\System.Threading.Tasks.Dataflow.4.9.0\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll 96 | 97 | 98 | packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | packages\YamlDotNet.6.0.0\lib\net45\YamlDotNet.dll 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | False 122 | Microsoft .NET Framework 4.7.2 %28x86 and x64%29 123 | true 124 | 125 | 126 | False 127 | .NET Framework 3.5 SP1 128 | false 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /skybutt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29020.237 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "skybutt", "skybutt.csproj", "{7C01F517-B8A9-46F1-80A2-38ACACF7F61B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7C01F517-B8A9-46F1-80A2-38ACACF7F61B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {7C01F517-B8A9-46F1-80A2-38ACACF7F61B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {7C01F517-B8A9-46F1-80A2-38ACACF7F61B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {7C01F517-B8A9-46F1-80A2-38ACACF7F61B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {CEFA2BD9-E696-4E30-A036-3796F3869801} 24 | EndGlobalSection 25 | EndGlobal 26 | --------------------------------------------------------------------------------