From 4d80b5d4e895dd3489fbf21f601216c147528e0e Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 6 Jun 2020 17:17:50 -0500 Subject: [PATCH] Movie importers - fix importers, broken with recent movie refactors, fix bkm importer, most systems were broken due to contorller definition names changing over the years --- .../movie/import/BkmImport.cs | 2 +- .../movie/import/IMovieImport.cs | 9 +++-- .../movie/import/MovieImport.cs | 5 ++- .../movie/import/bkm/BkmControllerAdapter.cs | 38 ++++++++++++++----- .../movie/import/bkm/BkmMovie.cs | 10 ++--- src/BizHawk.Client.EmuHawk/MainForm.cs | 2 +- 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/import/BkmImport.cs b/src/BizHawk.Client.Common/movie/import/BkmImport.cs index 11baa89327..b382c8e112 100644 --- a/src/BizHawk.Client.Common/movie/import/BkmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/BkmImport.cs @@ -11,7 +11,7 @@ for (var i = 0; i < bkm.InputLogLength; i++) { - var input = bkm.GetInputState(i); + var input = bkm.GetInputState(i, Result.Movie.Emulator.ControllerDefinition, bkm.Header[HeaderKeys.Platform]); Result.Movie.AppendFrame(input); } diff --git a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs index 5d65aa6ee4..1ca52d87e8 100644 --- a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs +++ b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs @@ -1,4 +1,5 @@ -using System; +using BizHawk.Emulation.Common; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -7,7 +8,7 @@ namespace BizHawk.Client.Common { public interface IMovieImport { - ImportResult Import(IMovieSession session, string path, Config config); + ImportResult Import(IMovieSession session, IEmulator emulator, string path, Config config); } internal abstract class MovieImporter : IMovieImport @@ -16,7 +17,7 @@ namespace BizHawk.Client.Common protected const string Md5 = "MD5"; protected const string MovieOrigin = "MovieOrigin"; - public ImportResult Import(IMovieSession session, string path, Config config) + public ImportResult Import(IMovieSession session, IEmulator emulator, string path, Config config) { SourceFile = new FileInfo(path); Config = config; @@ -29,7 +30,7 @@ namespace BizHawk.Client.Common var newFileName = $"{SourceFile.FullName}.{Bk2Movie.Extension}"; Result.Movie = session.Get(newFileName); - + Result.Movie.Attach(emulator); RunImport(); if (!Result.Errors.Any()) diff --git a/src/BizHawk.Client.Common/movie/import/MovieImport.cs b/src/BizHawk.Client.Common/movie/import/MovieImport.cs index 5c0ad2ebc2..3cd0d0db96 100644 --- a/src/BizHawk.Client.Common/movie/import/MovieImport.cs +++ b/src/BizHawk.Client.Common/movie/import/MovieImport.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.IO; using System.Reflection; +using BizHawk.Emulation.Common; namespace BizHawk.Client.Common { @@ -30,7 +31,7 @@ namespace BizHawk.Client.Common ); // Attempt to import another type of movie file into a movie object. - public static ImportResult ImportFile(IMovieSession session, string path, Config config) + public static ImportResult ImportFile(IMovieSession session, IEmulator emulator, string path, Config config) { string ext = Path.GetExtension(path) ?? ""; var importerType = ImporterForExtension(ext); @@ -47,7 +48,7 @@ namespace BizHawk.Client.Common return importer == null ? ImportResult.Error($"No importer found for file type {ext}") - : importer.Import(session, path, config); + : importer.Import(session, emulator, path, config); } private static Type ImporterForExtension(string ext) diff --git a/src/BizHawk.Client.Common/movie/import/bkm/BkmControllerAdapter.cs b/src/BizHawk.Client.Common/movie/import/bkm/BkmControllerAdapter.cs index 17a2d5b212..462e4a6433 100644 --- a/src/BizHawk.Client.Common/movie/import/bkm/BkmControllerAdapter.cs +++ b/src/BizHawk.Client.Common/movie/import/bkm/BkmControllerAdapter.cs @@ -5,6 +5,34 @@ namespace BizHawk.Client.Common { internal class BkmControllerAdapter : IController { + public BkmControllerAdapter(ControllerDefinition definition, string systemId) + { + Definition = definition; + + // We do need to map the definition name to the legacy + // controller names that were used back in the bkm days + Definition.Name = systemId switch + { + "Lynx" => "Lynx Controller", + "SNES" => "SNES Controller", + "C64" => "Commodore 64 Controller", + "GBA" => "GBA Controller", + "A78" => "Atari 7800 ProLine Joystick Controller", + "DGB" => "Dual Gameboy Controller", + "WSWAN" => "WonderSwan Controller", + "N64" => "Nintendo 64 Controller", + "SAT" => "Saturn Controller", + "GEN" => "GPGX Genesis Controller", + "NES" => "NES Controller", + "GB" => "Gameboy Controller", + "A26" => "Atari 2600 Basic Controller", + "TI83" => "TI83 Controller", + "Coleco" => "ColecoVision Basic Controller", + "SMS Controller" => "SMS", + _ => "Null Controller", + }; + } + public ControllerDefinition Definition { get; set; } public bool IsPressed(string button) @@ -128,16 +156,6 @@ namespace BizHawk.Client.Common Force("Power", mnemonic[1] != '.'); } - if (ControlType == "Genesis 3-Button Controller") - { - if (mnemonic.Length < 2) - { - return; - } - - Force("Reset", mnemonic[1] != '.'); - } - if (ControlType == "SMS Controller" || ControlType == "TI83 Controller" || ControlType == "ColecoVision Basic Controller") { start = 1; diff --git a/src/BizHawk.Client.Common/movie/import/bkm/BkmMovie.cs b/src/BizHawk.Client.Common/movie/import/bkm/BkmMovie.cs index 026ba5f761..7b660a4e97 100644 --- a/src/BizHawk.Client.Common/movie/import/bkm/BkmMovie.cs +++ b/src/BizHawk.Client.Common/movie/import/bkm/BkmMovie.cs @@ -1,4 +1,5 @@ -using System; +using BizHawk.Emulation.Common; +using System; using System.Collections.Generic; using System.IO; @@ -12,14 +13,11 @@ namespace BizHawk.Client.Common public bool Loaded { get; private set; } public int InputLogLength => Loaded ? _log.Count : 0; - public BkmControllerAdapter GetInputState(int frame) + public BkmControllerAdapter GetInputState(int frame, ControllerDefinition definition, string sytemId) { if (frame < InputLogLength && frame >= 0) { - var adapter = new BkmControllerAdapter - { - Definition = Global.MovieSession.MovieController.Definition - }; + var adapter = new BkmControllerAdapter(definition, sytemId); adapter.SetControllersAsMnemonic(_log[frame]); return adapter; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 0262a21bfa..f983bfa6b0 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -3982,7 +3982,7 @@ namespace BizHawk.Client.EmuHawk private void ProcessMovieImport(string fn, bool start) { - var result = MovieImport.ImportFile(MovieSession, fn, Config); + var result = MovieImport.ImportFile(MovieSession, Emulator, fn, Config); if (result.Errors.Any()) {