public MainForm(string[] args) { GlobalWin.MainForm = this; Global.Rewinder = new Rewinder { MessageCallback = GlobalWin.OSD.AddMessage }; Global.ControllerInputCoalescer = new ControllerInputCoalescer(); Global.FirmwareManager = new FirmwareManager(); Global.MovieSession = new MovieSession { Movie = MovieService.DefaultInstance, MovieControllerAdapter = MovieService.DefaultInstance.LogGeneratorInstance().MovieControllerAdapter, MessageCallback = GlobalWin.OSD.AddMessage, AskYesNoCallback = StateErrorAskUser, PauseCallback = PauseEmulator, ModeChangedCallback = SetMainformMovieInfo }; new AutoResetEvent(false); Icon = Properties.Resources.logo; InitializeComponent(); Global.Game = GameInfo.NullInstance; if (Global.Config.ShowLogWindow) { LogConsole.ShowConsole(); DisplayLogWindowMenuItem.Checked = true; } _throttle = new Throttle(); Global.CheatList = new CheatCollection(); Global.CheatList.Changed += ToolHelpers.UpdateCheatRelatedTools; UpdateStatusSlots(); UpdateKeyPriorityIcon(); // In order to allow late construction of this database, we hook up a delegate here to dearchive the data and provide it on demand // we could background thread this later instead if we wanted to be real clever NES.BootGodDB.GetDatabaseBytes = () => { using (var NesCartFile = new HawkFile(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z")).BindFirst()) { return NesCartFile .GetStream() .ReadAllBytes(); } }; // TODO - replace this with some kind of standard dictionary-yielding parser in a separate component string cmdRom = null; string cmdLoadState = null; string cmdMovie = null; string cmdDumpType = null; string cmdDumpName = null; bool startFullscreen = false; for (int i = 0; i < args.Length; i++) { // For some reason sometimes visual studio will pass this to us on the commandline. it makes no sense. if (args[i] == ">") { i++; var stdout = args[i]; Console.SetOut(new StreamWriter(stdout)); continue; } var arg = args[i].ToLower(); if (arg.StartsWith("--load-slot=")) { cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--movie=")) { cmdMovie = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--dump-type=")) { cmdDumpType = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--dump-frames=")) { var list = arg.Substring(arg.IndexOf('=') + 1); var items = list.Split(','); _currAviWriterFrameList = new HashSet<int>(); for (int j = 0; j < items.Length; j++) _currAviWriterFrameList.Add(int.Parse(items[j])); //automatically set dump length to maximum frame _autoDumpLength = _currAviWriterFrameList.OrderBy(x => x).Last(); } else if (arg.StartsWith("--dump-name=")) { cmdDumpName = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--dump-length=")) { int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out _autoDumpLength); } else if (arg.StartsWith("--dump-close")) { _autoCloseOnDump = true; } else if (arg.StartsWith("--chromeless")) { _chromeless = true; } else if (arg.StartsWith("--fullscreen")) { startFullscreen = true; } else { cmdRom = arg; } } Database.LoadDatabase(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt")); //TODO GL - a lot of disorganized wiring-up here PresentationPanel = new PresentationPanel(); GlobalWin.DisplayManager = new DisplayManager(PresentationPanel); Controls.Add(PresentationPanel); Controls.SetChildIndex(PresentationPanel, 0); //TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides Load += (o, e) => { AllowDrop = true; DragEnter += FormDragEnter; DragDrop += FormDragDrop; }; Closing += (o, e) => { if (GlobalWin.Tools.AskSave()) { CloseGame(); Global.MovieSession.Movie.Stop(); GlobalWin.Tools.Close(); SaveConfig(); } else { e.Cancel = true; } }; ResizeBegin += (o, e) => { _inResizeLoop = true; if (GlobalWin.Sound != null) { GlobalWin.Sound.StopSound(); } }; Resize += (o, e) => { SetWindowText(); }; ResizeEnd += (o, e) => { _inResizeLoop = false; SetWindowText(); if (PresentationPanel != null) { PresentationPanel.Resized = true; } if (GlobalWin.Sound != null) { GlobalWin.Sound.StartSound(); } }; Input.Initialize(); InitControls(); var comm = CreateCoreComm(); CoreFileProvider.SyncCoreCommInputSignals(comm); Global.Emulator = new NullEmulator(comm, Global.Config.GetCoreSettings<NullEmulator>()); Global.ActiveController = new Controller(NullEmulator.NullController); Global.AutoFireController = Global.AutofireNullControls; Global.AutofireStickyXORAdapter.SetOnOffPatternFromConfig(); try { GlobalWin.Sound = new Sound(Handle); } catch { string message = "Couldn't initialize sound device! Try changing the output method in Sound config."; if (Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound) message = "Couldn't initialize DirectSound! Things may go poorly for you. Try changing your sound driver to 44.1khz instead of 48khz in mmsys.cpl."; MessageBox.Show(message, "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.Dummy; GlobalWin.Sound = new Sound(Handle); } GlobalWin.Sound.StartSound(); InputManager.RewireInputChain(); GlobalWin.Tools = new ToolManager(this); RewireSound(); // Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved if (Global.Config.MainWndx == -32000) { Global.Config.MainWndx = 0; } if (Global.Config.MainWndy == -32000) { Global.Config.MainWndy = 0; } if (Global.Config.MainWndx != -1 && Global.Config.MainWndy != -1 && Global.Config.SaveWindowPosition) { Location = new Point(Global.Config.MainWndx, Global.Config.MainWndy); } if (cmdRom != null) { // Commandline should always override auto-load LoadRom(cmdRom); if (Global.Game == null) { MessageBox.Show("Failed to load " + cmdRom + " specified on commandline"); } } else if (Global.Config.RecentRoms.AutoLoad && !Global.Config.RecentRoms.Empty) { LoadRomFromRecent(Global.Config.RecentRoms.MostRecent); } if (cmdMovie != null) { if (Global.Game == null) { OpenRom(); } else { var movie = MovieService.Get(cmdMovie); Global.MovieSession.ReadOnly = true; // if user is dumping and didnt supply dump length, make it as long as the loaded movie if (_autoDumpLength == 0) { _autoDumpLength = movie.InputLogLength; } StartNewMovie(movie, false); Global.Config.RecentMovies.Add(cmdMovie); } } else if (Global.Config.RecentMovies.AutoLoad && !Global.Config.RecentMovies.Empty) { if (Global.Game.IsNullInstance) { OpenRom(); } // If user picked a game, then do the autoload logic if (!Global.Game.IsNullInstance) { if (File.Exists(Global.Config.RecentMovies.MostRecent)) { StartNewMovie(MovieService.Get(Global.Config.RecentMovies.MostRecent), false); } else { Global.Config.RecentMovies.HandleLoadError(Global.Config.RecentMovies.MostRecent); } } } if (startFullscreen || Global.Config.StartFullscreen) { ToggleFullscreen(); } if (cmdLoadState != null && !Global.Game.IsNullInstance) { LoadQuickSave("QuickSave" + cmdLoadState); } else if (Global.Config.AutoLoadLastSaveSlot && !Global.Game.IsNullInstance) { LoadQuickSave("QuickSave" + Global.Config.SaveSlot); } GlobalWin.Tools.AutoLoad(); if (Global.Config.RecentWatches.AutoLoad) { GlobalWin.Tools.LoadRamWatch(!Global.Config.DisplayRamWatch); } if (Global.Config.RecentCheats.AutoLoad) { GlobalWin.Tools.Load<Cheats>(); } if (Global.Config.DisplayStatusBar == false) { MainStatusBar.Visible = false; } else { DisplayStatusBarMenuItem.Checked = true; } if (Global.Config.StartPaused) { PauseEmulator(); } // start dumping, if appropriate if (cmdDumpType != null && cmdDumpName != null) { RecordAv(cmdDumpType, cmdDumpName); } SetMainformMovieInfo(); SynchChrome(); //TODO POOP PresentationPanel.Control.Paint += (o, e) => { GlobalWin.DisplayManager.NeedsToPaint = true; }; }
public Mainform(string[] args) { GLManager.CreateInstance(); InitializeComponent(); _throttle = new BizHawk.Client.EmuHawk.Throttle(); _inputManager = new InputManager(this); Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath); Global.Config.DispFixAspectRatio = false; // TODO: don't hardcode this Global.Config.ResolveDefaults(); GlobalWin.MainForm = this; Global.ControllerInputCoalescer = new ControllerInputCoalescer(); Global.FirmwareManager = new FirmwareManager(); Global.MovieSession = new MovieSession { Movie = MovieService.DefaultInstance, MovieControllerAdapter = MovieService.DefaultInstance.LogGeneratorInstance().MovieControllerAdapter, MessageCallback = AddMessage, AskYesNoCallback = StateErrorAskUser, PauseCallback = PauseEmulator, ModeChangedCallback = SetMainformMovieInfo }; new AutoResetEvent(false); // TODO //Icon = Properties.Resources.logo; Global.Game = GameInfo.NullInstance; // In order to allow late construction of this database, we hook up a delegate here to dearchive the data and provide it on demand // we could background thread this later instead if we wanted to be real clever NES.BootGodDB.GetDatabaseBytes = () => { using (var NesCartFile = new HawkFile(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z")).BindFirst()) { return NesCartFile .GetStream() .ReadAllBytes(); } }; Database.LoadDatabase(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt")); Input.Initialize(this.Handle); InitControls(); // TODO //CoreFileProvider.SyncCoreCommInputSignals(); Global.ActiveController = new Controller(NullEmulator.NullController); Global.AutoFireController = Global.AutofireNullControls; Global.AutofireStickyXORAdapter.SetOnOffPatternFromConfig(); Closing += (o, e) => { Global.MovieSession.Movie.Stop(); foreach (var ew in EmulatorWindows.ToList()) { ew.ShutDown(); } SaveConfig(); }; if (Global.Config.MainWndx != -1 && Global.Config.MainWndy != -1 && Global.Config.SaveWindowPosition) { Location = new Point(Global.Config.MainWndx, Global.Config.MainWndy); } }
public MainForm(string[] args) { GlobalWin.MainForm = this; Global.Rewinder = new Rewinder { MessageCallback = GlobalWin.OSD.AddMessage }; Global.ControllerInputCoalescer = new ControllerInputCoalescer(); Global.RAInterface = new RetroAchievementsInterface(); Global.FirmwareManager = new FirmwareManager(); Global.MovieSession = new MovieSession { Movie = MovieService.DefaultInstance, MovieControllerAdapter = MovieService.DefaultInstance.LogGeneratorInstance().MovieControllerAdapter, MessageCallback = GlobalWin.OSD.AddMessage, AskYesNoCallback = StateErrorAskUser, PauseCallback = PauseEmulator, ModeChangedCallback = SetMainformMovieInfo }; new AutoResetEvent(false); Icon = Properties.Resources.logo; InitializeComponent(); Global.Game = GameInfo.NullInstance; if (Global.Config.ShowLogWindow) { LogConsole.ShowConsole(); DisplayLogWindowMenuItem.Checked = true; } _throttle = new Throttle(); Global.CheatList = new CheatCollection(); Global.CheatList.Changed += ToolHelpers.UpdateCheatRelatedTools; UpdateStatusSlots(); UpdateKeyPriorityIcon(); // In order to allow late construction of this database, we hook up a delegate here to dearchive the data and provide it on demand // we could background thread this later instead if we wanted to be real clever NES.BootGodDB.GetDatabaseBytes = () => { using (var NesCartFile = new HawkFile(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z")).BindFirst()) { return NesCartFile .GetStream() .ReadAllBytes(); } }; Database.LoadDatabase(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt")); //TODO GL - a lot of disorganized wiring-up here GlobalWin.PresentationPanel = new PresentationPanel(); GlobalWin.DisplayManager = new DisplayManager(GlobalWin.PresentationPanel); Controls.Add(GlobalWin.PresentationPanel); Controls.SetChildIndex(GlobalWin.PresentationPanel, 0); //TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides Load += (o, e) => { AllowDrop = true; DragEnter += FormDragEnter; DragDrop += FormDragDrop; }; Closing += (o, e) => { if (GlobalWin.Tools.AskSave()) { Global.CheatList.SaveOnClose(); CloseGame(); Global.MovieSession.Movie.Stop(); GlobalWin.Tools.Close(); SaveConfig(); } else { e.Cancel = true; } }; ResizeBegin += (o, e) => { if (GlobalWin.Sound != null) { GlobalWin.Sound.StopSound(); } }; ResizeEnd += (o, e) => { if (GlobalWin.PresentationPanel != null) { GlobalWin.PresentationPanel.Resized = true; } if (GlobalWin.Sound != null) { GlobalWin.Sound.StartSound(); } }; Input.Initialize(); InitControls(); Global.CoreComm = CreateCoreComm(); CoreFileProvider.SyncCoreCommInputSignals(); Global.Emulator = new NullEmulator(Global.CoreComm); Global.ActiveController = Global.NullControls; Global.AutoFireController = Global.AutofireNullControls; Global.AutofireStickyXORAdapter.SetOnOffPatternFromConfig(); #if WINDOWS GlobalWin.Sound = new Sound(Handle, GlobalWin.DSound); #else Global.Sound = new Sound(); #endif GlobalWin.Sound.StartSound(); InputManager.RewireInputChain(); GlobalWin.Tools = new ToolManager(); RewireSound(); // TODO - replace this with some kind of standard dictionary-yielding parser in a separate component string cmdRom = null; string cmdLoadState = null; string cmdMovie = null; string cmdDumpType = null; string cmdDumpName = null; if (Global.Config.MainWndx >= 0 && Global.Config.MainWndy >= 0 && Global.Config.SaveWindowPosition) { Location = new Point(Global.Config.MainWndx, Global.Config.MainWndy); } bool startFullscreen = false; for (int i = 0; i < args.Length; i++) { // For some reason sometimes visual studio will pass this to us on the commandline. it makes no sense. if (args[i] == ">") { i++; var stdout = args[i]; Console.SetOut(new StreamWriter(stdout)); continue; } var arg = args[i].ToLower(); if (arg.StartsWith("--load-slot=")) { cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--movie=")) { cmdMovie = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--dump-type=")) { cmdDumpType = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--dump-name=")) { cmdDumpName = arg.Substring(arg.IndexOf('=') + 1); } else if (arg.StartsWith("--dump-length=")) { int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out _autoDumpLength); } else if (arg.StartsWith("--dump-close")) { _autoCloseOnDump = true; } else if (arg.StartsWith("--fullscreen")) { startFullscreen = true; } else { cmdRom = arg; } } if (cmdRom != null) { // Commandline should always override auto-load LoadRom(cmdRom); if (Global.Game == null) { MessageBox.Show("Failed to load " + cmdRom + " specified on commandline"); } } else if (Global.Config.RecentRoms.AutoLoad && !Global.Config.RecentRoms.Empty) { LoadRomFromRecent(Global.Config.RecentRoms.MostRecent); } if (cmdMovie != null) { if (Global.Game == null) { OpenRom(); } else { var movie = MovieService.Get(cmdMovie); Global.MovieSession.ReadOnly = true; // if user is dumping and didnt supply dump length, make it as long as the loaded movie if (_autoDumpLength == 0) { _autoDumpLength = movie.InputLogLength; } StartNewMovie(movie, false); Global.Config.RecentMovies.Add(cmdMovie); } } else if (Global.Config.RecentMovies.AutoLoad && !Global.Config.RecentMovies.Empty) { if (Global.Game == null) { OpenRom(); } else { StartNewMovie(MovieService.Get(Global.Config.RecentMovies.MostRecent), false); } } if (startFullscreen || Global.Config.StartFullscreen) { ToggleFullscreen(); } if (cmdLoadState != null && !Global.Game.IsNullInstance) { LoadQuickSave("QuickSave" + cmdLoadState); } else if (Global.Config.AutoLoadLastSaveSlot && !Global.Game.IsNullInstance) { LoadQuickSave("QuickSave" + Global.Config.SaveSlot); } if (Global.Config.RecentWatches.AutoLoad) { GlobalWin.Tools.LoadRamWatch(!Global.Config.DisplayRamWatch); } if (Global.Config.RecentSearches.AutoLoad) { GlobalWin.Tools.Load<RamSearch>(); } if (Global.Config.AutoLoadHexEditor) { GlobalWin.Tools.Load<HexEditor>(); } if (Global.Config.RecentCheats.AutoLoad) { GlobalWin.Tools.Load<Cheats>(); } if (Global.Config.AutoLoadNESPPU && Global.Emulator is NES) { GlobalWin.Tools.Load<NesPPU>(); } if (Global.Config.AutoLoadNESNameTable && Global.Emulator is NES) { GlobalWin.Tools.Load<NESNameTableViewer>(); } if (Global.Config.AutoLoadNESDebugger && Global.Emulator is NES) { GlobalWin.Tools.Load<NESDebugger>(); } if (Global.Config.NESGGAutoload && Global.Emulator.SystemId == "NES") { GlobalWin.Tools.LoadGameGenieEc(); } if (Global.Config.AutoLoadGBGPUView && Global.Emulator is Gameboy) { GlobalWin.Tools.Load<GBGPUView>(); } if (Global.Config.AutoloadTAStudio) { GlobalWin.Tools.Load<TAStudio>(); } if (Global.Config.AutoloadExperimentalTAStudio) { GlobalWin.Tools.Load<TasStudioExperiment>(); } if (Global.Config.AutoloadVirtualPad) { GlobalWin.Tools.Load<VirtualpadTool>(); } if (Global.Config.AutoLoadLuaConsole) { OpenLuaConsole(); } if (Global.Config.SmsVdpAutoLoad && Global.Emulator is SMS) { GlobalWin.Tools.Load<SmsVDPViewer>(); } if (Global.Config.PCEBGViewerAutoload && Global.Emulator is PCEngine) { GlobalWin.Tools.Load<PceBgViewer>(); } if (Global.Config.PceVdpAutoLoad && Global.Emulator is PCEngine) { GlobalWin.Tools.Load<PCETileViewer>(); } if (Global.Config.RecentPceCdlFiles.AutoLoad && Global.Emulator is PCEngine) { GlobalWin.Tools.Load<PCECDL>(); } if (Global.Config.PceSoundDebuggerAutoload && Global.Emulator is PCEngine) { GlobalWin.Tools.Load<PCESoundDebugger>(); } if (Global.Config.GenVdpAutoLoad && Global.Emulator is GPGX) { GlobalWin.Tools.Load<GenVDPViewer>(); } if (Global.Config.AutoLoadSNESGraphicsDebugger && Global.Emulator is LibsnesCore) { GlobalWin.Tools.Load<SNESGraphicsDebugger>(); } if (Global.Config.TraceLoggerAutoLoad) { GlobalWin.Tools.LoadTraceLogger(); } if (Global.Config.Atari2600DebuggerAutoload && Global.Emulator is Atari2600) { GlobalWin.Tools.Load<Atari2600Debugger>(); } if (Global.Config.DisplayStatusBar == false) { MainStatusBar.Visible = false; } else { DisplayStatusBarMenuItem.Checked = true; } if (Global.Config.StartPaused) { PauseEmulator(); } // start dumping, if appropriate if (cmdDumpType != null && cmdDumpName != null) { RecordAv(cmdDumpType, cmdDumpName); } UpdateStatusSlots(); SetMainformMovieInfo(); //TODO POOP GlobalWin.PresentationPanel.Control.Paint += (o, e) => { GlobalWin.DisplayManager.NeedsToPaint = true; }; // RA: // Test: RACore.Init(); RAWebInterface.PerformBackgroundLogin("qwe", "qwe"); RACore.EventService.RegisterHandler(RAEventType.Login, RAOnLogin); }