diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 6f72f514ab..c22266d752 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -30,6 +30,7 @@ namespace BizHawk.Client.Common { #region Duplicate code to mainform, need to refactor! + /* object __SyncSettingsHack = null; object GetCoreSyncSettings() @@ -42,6 +43,25 @@ namespace BizHawk.Client.Common return __SyncSettingsHack ?? Global.Config.GetCoreSyncSettings(); } + */ + + object GetCoreSettings() + where T : IEmulator + { + var e = new SettingsLoadArgs(typeof(T)); + if (OnLoadSettings != null) + OnLoadSettings(this, e); + return e.Settings; + } + + object GetCoreSyncSettings() + where T : IEmulator + { + var e = new SettingsLoadArgs(typeof(T)); + if (OnLoadSyncSettings != null) + OnLoadSyncSettings(this, e); + return e.Settings; + } #endregion #region SNES specific stuff - clean up or move elsewhere @@ -185,6 +205,21 @@ namespace BizHawk.Client.Common public string AttemptedCoreLoad { get; private set; } } + public class SettingsLoadArgs + { + public object Settings { get; set; } + public Type Core { get; private set; } + public SettingsLoadArgs(Type t) + { + Core = t; + Settings = null; + } + } + public delegate void SettingsLoadEventHandler(object sender, SettingsLoadArgs e); + public event SettingsLoadEventHandler OnLoadSettings; + public event SettingsLoadEventHandler OnLoadSyncSettings; + + public delegate void LoadErrorEventHandler(object sener, RomErrorArgs e); public event LoadErrorEventHandler OnLoadError; @@ -320,7 +355,7 @@ namespace BizHawk.Client.Common case "GEN": { var genesis = new GPGX( - nextComm, null, disc, "GEN", Global.Config.GetCoreSyncSettings()); + nextComm, null, disc, "GEN", GetCoreSettings()); nextEmulator = genesis; } break; @@ -390,7 +425,7 @@ namespace BizHawk.Client.Common } game.FirmwareHash = Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(rom.RomData)); - nextEmulator = new PCEngine(nextComm, game, disc, rom.RomData, Global.Config.GetCoreSettings()); + nextEmulator = new PCEngine(nextComm, game, disc, rom.RomData, GetCoreSettings()); break; } } @@ -410,7 +445,7 @@ namespace BizHawk.Client.Common var R = Database.GetGameInfo(XMLG.Assets["RightRom"], "right.gb"); var gbl = new GambatteLink(nextComm, L, XMLG.Assets["LeftRom"], R, XMLG.Assets["RightRom"], - Global.Config.GetCoreSettings(), + GetCoreSettings(), GetCoreSyncSettings()); nextEmulator = gbl; @@ -460,22 +495,22 @@ namespace BizHawk.Client.Common case "SMS": case "SG": case "GG": - nextEmulator = new SMS(nextComm, game, rom.RomData, Global.Config.GetCoreSettings(), Global.Config.GetCoreSyncSettings()); + nextEmulator = new SMS(nextComm, game, rom.RomData, GetCoreSettings(), GetCoreSyncSettings()); break; case "A26": nextEmulator = new Atari2600(nextComm, game, rom.FileData, - Global.Config.GetCoreSettings(), + GetCoreSettings(), GetCoreSyncSettings()); break; case "PCE": case "PCECD": case "SGX": - nextEmulator = new PCEngine(nextComm, game, rom.RomData, Global.Config.GetCoreSettings()); + nextEmulator = new PCEngine(nextComm, game, rom.RomData, GetCoreSettings()); break; case "GEN": { // nextEmulator = new Genesis(nextComm, game, rom.RomData); - nextEmulator = new GPGX(nextComm, rom.RomData, null, "GEN", Global.Config.GetCoreSyncSettings()); + nextEmulator = new GPGX(nextComm, rom.RomData, null, "GEN", GetCoreSyncSettings()); break; } case "TI83": @@ -483,7 +518,7 @@ namespace BizHawk.Client.Common break; case "NES": nextEmulator = new NES(nextComm, game, rom.FileData, - Global.Config.GetCoreSettings(), + GetCoreSettings(), Global.MovieSession.Movie.Header.BoardProperties); break; case "GB": @@ -491,7 +526,7 @@ namespace BizHawk.Client.Common if (!Global.Config.GB_AsSGB) { var gb = new Gameboy(nextComm, game, rom.FileData, - Global.Config.GetCoreSettings(), + GetCoreSettings(), GetCoreSyncSettings()); nextEmulator = gb; } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index e3eb730a07..a1945f85a1 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -1925,15 +1925,19 @@ namespace BizHawk.Client.EmuHawk object __SyncSettingsHack = null; - object GetCoreSyncSettings() - where T : IEmulator + void CoreSyncSettings(object sender, RomLoader.SettingsLoadArgs e) { // if movie 2.0 was finished, this is where you'd decide whether to get a settings object // from a config file or from the movie file // since all we have right now is movie 1.0, we get silly hacks instead - return __SyncSettingsHack ?? Global.Config.GetCoreSyncSettings(); + e.Settings = __SyncSettingsHack ?? Global.Config.GetCoreSyncSettings(e.Core); + } + + void CoreSettings(object sender, RomLoader.SettingsLoadArgs e) + { + e.Settings = Global.Config.GetCoreSettings(e.Core); } /// @@ -2879,6 +2883,9 @@ namespace BizHawk.Client.EmuHawk loader.OnLoadError += ShowLoadError; + loader.OnLoadSettings += CoreSettings; + loader.OnLoadSyncSettings += CoreSyncSettings; + var result = loader.LoadRom(path, hasmovie); if (result)