private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { sendThread.Dispose(); bus.Unplug(1); bus.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
static void Main(string[] args) { string newInputEndpoint = "http://127.0.0.1:5000/gbmode_input_request_bizhawk"; string doneInputEndpoint = "http://127.0.0.1:5000/gbmode_input_complete"; int controller = 1; int minHeldFrames = 1; int maxSleepFrames = 100; int maxHeldFrames = 100; int maxHoldFrames = 0; //24; bool toggleTriggers = false; bool eternalHolds = true; //false; string forceFocusProgram = null; int forceSaveBackupSeconds = 0; string saveBackupEndpoint = "http://127.0.0.1:5000/back_up_savestate"; try { for (var i = 0; i < args.Length; i++) { switch (args[i].ToLower()) { case "-h": case "-help": PrintHelpText(); return; case "-inputendpoint": newInputEndpoint = args[i + 1]; ConsoleLogger.Info($"Input endpoint: {newInputEndpoint}"); break; case "-doneendpoint": doneInputEndpoint = args[i + 1]; ConsoleLogger.Info($"Done endpoint: {doneInputEndpoint}"); break; case "-savebackupendpoint": saveBackupEndpoint = args[i + 1]; ConsoleLogger.Info($"Save Backup endpoint: {saveBackupEndpoint}"); break; case "-controller": controller = int.Parse(args[i + 1]); ConsoleLogger.Info($"Simulating controller #{controller}"); break; case "-lstickthrow": TPPInput.LThrowGlobalMult = double.Parse(args[i + 1]); ConsoleLogger.Info($"Left Stick max throw set to {(TPPInput.LThrowGlobalMult * 100).ToString("0")}%"); break; case "-rstickthrow": TPPInput.RThrowGlobalMult = double.Parse(args[i + 1]); ConsoleLogger.Info($"Right Stick max throw set to {(TPPInput.RThrowGlobalMult * 100).ToString("0")}%"); break; case "-toggletriggers": toggleTriggers = true; ConsoleLogger.Info("Left and Right Triggers will be toggled"); break; case "-eternalholds": eternalHolds = true; maxHoldFrames = 0; ConsoleLogger.Info("Held inputs will last until the next held input"); break; case "-minheldframes": minHeldFrames = int.Parse(args[i + 1]); ConsoleLogger.Info($"Minimum Held Frames: {minHeldFrames}"); break; case "-maxsleepframes": maxSleepFrames = int.Parse(args[i + 1]); ConsoleLogger.Info($"Maximum Sleep Frames: {maxSleepFrames}"); break; case "-maxheldframes": maxHeldFrames = int.Parse(args[i + 1]); ConsoleLogger.Info($"Maximum Held Frames: {maxHeldFrames}"); break; case "-maxholdframes": maxHoldFrames = int.Parse(args[i + 1]); ConsoleLogger.Info($"Maximum Hold Input Frames: {maxHoldFrames}"); break; case "-forcefocus": forceFocusProgram = args[i + 1]; ConsoleLogger.Info($"Forcing {forceFocusProgram} to have focus for each input"); break; case "-forcesavebackup": forceSaveBackupSeconds = int.Parse(args[i + 1]); ConsoleLogger.Info($"Forcing save backup every {forceSaveBackupSeconds} seconds"); break; } } } catch (Exception e) { ConsoleLogger.Critical(e.Message); PrintHelpText(); return; } ScpBus scpBus; try { scpBus = new ScpBus(); } catch { ConsoleLogger.Critical("Could not create virtual controller. Please make sure the SCP Virtual Bus Driver is installed."); return; } scpBus.PlugIn(1); ConsoleLogger.Info("Virtual controller connected."); Console.CancelKeyPress += delegate { scpBus.UnplugAll(); ConsoleLogger.Info("Virtual controller(s) disconnected."); scpBus.Dispose(); }; var inputFetcher = new FetchInput(scpBus, controller, minHeldFrames, maxHeldFrames, maxSleepFrames, maxHoldFrames, toggleTriggers, eternalHolds, newInputEndpoint, doneInputEndpoint, forceFocusProgram); var worker = new Worker(() => inputFetcher.Frame()); worker.Start(); var willBackupSave = forceSaveBackupSeconds > 0 && !string.IsNullOrWhiteSpace(saveBackupEndpoint); while (true) { for (var i = 0; i < forceSaveBackupSeconds; i += forceSaveBackupSeconds / 10) { if (willBackupSave) { ConsoleLogger.Info($"{forceSaveBackupSeconds - i} seconds until save backup..."); } Thread.Sleep(forceSaveBackupSeconds * 100); } if (willBackupSave) { using (var webClient = new ImpatientWebClient(forceSaveBackupSeconds * 1000)) { ConsoleLogger.Info("Backing up save..."); webClient.DownloadStringAsync(new Uri(saveBackupEndpoint)); } } } }