From c0b6bf61b1a06db2ce5287bfc74a7ab2fffbf4ef Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 14 Jan 2021 03:48:45 +1000 Subject: [PATCH] Pass through queued movie's Core header to RomLoader and load only it --- src/BizHawk.Client.Common/RomLoader.cs | 52 +++++++++++-------- .../movie/MovieSession.cs | 2 + .../movie/interfaces/IMovieSession.cs | 3 ++ src/BizHawk.Client.EmuHawk/MainForm.cs | 2 +- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 95d751df9d..a55715cdf6 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -373,28 +373,36 @@ namespace BizHawk.Client.Common nextEmulator = MakeCoreFromCoreInventory(cip); } - private IEmulator MakeCoreFromCoreInventory(CoreInventoryParameters cip) + private IEmulator MakeCoreFromCoreInventory(CoreInventoryParameters cip, string forcedCoreName = null) { - _config.PreferredCores.TryGetValue(cip.Game.System, out var preferredCore); - var forcedCore = cip.Game.ForcedCore; - var cores = CoreInventory.Instance.GetCores(cip.Game.System) - .OrderBy(c => - { - if (c.Name == preferredCore) + IReadOnlyCollection cores; + if (forcedCoreName != null) + { + var singleCore = CoreInventory.Instance.GetCores(cip.Game.System).SingleOrDefault(c => c.Name == forcedCoreName); + cores = singleCore != null ? new[] { singleCore } : Array.Empty(); + } + else + { + _config.PreferredCores.TryGetValue(cip.Game.System, out var preferredCore); + var dbForcedCoreName = cip.Game.ForcedCore; + cores = CoreInventory.Instance.GetCores(cip.Game.System) + .OrderBy(c => { - return (int)CorePriority.UserPreference; - } + if (c.Name == preferredCore) + { + return (int)CorePriority.UserPreference; + } - if (string.Equals(c.Name, forcedCore, StringComparison.InvariantCultureIgnoreCase)) - { - return (int)CorePriority.GameDbPreference; - } + if (string.Equals(c.Name, dbForcedCoreName, StringComparison.InvariantCultureIgnoreCase)) + { + return (int)CorePriority.GameDbPreference; + } - return (int)c.Priority; - }) - .ToList(); - if (cores.Count == 0) - throw new InvalidOperationException("No core was found to try on the game"); + return (int)c.Priority; + }) + .ToList(); + if (cores.Count == 0) throw new InvalidOperationException("No core was found to try on the game"); + } var exceptions = new List(); foreach (var core in cores) { @@ -412,7 +420,7 @@ namespace BizHawk.Client.Common throw new AggregateException("No core could load the game", exceptions); } - private void LoadOther(CoreComm nextComm, HawkFile file, out IEmulator nextEmulator, out RomGame rom, out GameInfo game, out bool cancel) + private void LoadOther(CoreComm nextComm, HawkFile file, string forcedCoreName, out IEmulator nextEmulator, out RomGame rom, out GameInfo game, out bool cancel) { cancel = false; rom = new RomGame(file); @@ -490,7 +498,7 @@ namespace BizHawk.Client.Common } }, }; - nextEmulator = MakeCoreFromCoreInventory(cip); + nextEmulator = MakeCoreFromCoreInventory(cip, forcedCoreName); } private void LoadPSF(string path, CoreComm nextComm, HawkFile file, out IEmulator nextEmulator, out RomGame rom, out GameInfo game) @@ -586,7 +594,7 @@ namespace BizHawk.Client.Common } } - public bool LoadRom(string path, CoreComm nextComm, string launchLibretroCore, int recursiveCount = 0) + public bool LoadRom(string path, CoreComm nextComm, string launchLibretroCore, string forcedCoreName = null, int recursiveCount = 0) { if (path == null) return false; @@ -701,7 +709,7 @@ namespace BizHawk.Client.Common } else { - LoadOther(nextComm, file, out nextEmulator, out rom, out game, out cancel); // must be called after LoadXML because of SNES hacks + LoadOther(nextComm, file, forcedCoreName, out nextEmulator, out rom, out game, out cancel); // must be called after LoadXML because of SNES hacks } break; } diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs index 9841d4f49a..3ebbcdc415 100644 --- a/src/BizHawk.Client.Common/movie/MovieSession.cs +++ b/src/BizHawk.Client.Common/movie/MovieSession.cs @@ -46,6 +46,8 @@ namespace BizHawk.Client.Common public bool NewMovieQueued => _queuedMovie != null; public string QueuedSyncSettings => _queuedMovie.SyncSettingsJson; + public string QueuedCoreName => _queuedMovie?.Core; + public IDictionary UserBag { get; set; } = new Dictionary(); public IInputAdapter MovieIn { private get; set; } diff --git a/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs b/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs index eba0ff5544..2f7a4a45cb 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs @@ -20,6 +20,9 @@ namespace BizHawk.Client.Common /// string QueuedSyncSettings { get; } + /// The Core header of the queued movie iff one is queued, else + string QueuedCoreName { get; } + IDictionary UserBag { get; set; } IMovieController MovieController { get; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 68af3bc783..f592e554c8 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -3657,7 +3657,7 @@ namespace BizHawk.Client.EmuHawk } var oldGame = Game; - var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath); + var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath, forcedCoreName: MovieSession.QueuedCoreName); Game = result ? loader.Game : oldGame;