diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs index b549dd1f09..804a7f6bcb 100755 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs @@ -55,8 +55,9 @@ namespace BizHawk.Client.Common public void SetFrom(IController source) { - foreach (var button in Definition.BoolButtons) + for (int index = 0; index < Definition.BoolButtons.Count; index++) { + string button = Definition.BoolButtons[index]; _myBoolButtons[button] = source.IsPressed(button); } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 9d8940d1d1..1ca8f90489 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -6,15 +6,25 @@ using BizHawk.Emulation.Common; namespace BizHawk.Client.Common { + // Designed to be able to last the lifetime of an IMovie internal class Bk2LogEntryGenerator : ILogEntryGenerator { private readonly string _systemId; private readonly IController _source; + private readonly Dictionary _mnemonics = new(); + public Bk2LogEntryGenerator(string systemId, IController source) { _systemId = systemId; _source = source; + foreach (var group in _source.Definition.ControlsOrdered.Where(static c => c.Count is not 0)) + { + foreach (var button in group) + { + _mnemonics.Add(button, Bk2MnemonicLookup.Lookup(button, _systemId)); + } + } } public bool IsEmpty => EmptyEntry == GenerateLogEntry(); @@ -76,7 +86,7 @@ namespace BizHawk.Client.Common else if (_source.Definition.BoolButtons.Contains(button)) { sb.Append(!createEmpty && _source.IsPressed(button) - ? Bk2MnemonicLookup.Lookup(button, _systemId) + ? _mnemonics[button] : '.'); } } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index 2208c9efeb..c0c803b0a0 100755 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -6,7 +6,7 @@ namespace BizHawk.Client.Common public partial class Bk2Movie : BasicMovieInfo, IMovie { private Bk2Controller _adapter; - + private Bk2LogEntryGenerator _logGenerator; public Bk2Movie(IMovieSession session, string filename) : base(filename) { Session = session; @@ -34,7 +34,14 @@ namespace BizHawk.Client.Common public ILogEntryGenerator LogGeneratorInstance(IController source) { - return new Bk2LogEntryGenerator(Emulator?.SystemId ?? SystemID, source); + // Hack because initial movie loading is a mess, and you will immediate create a file with an undefined controller + if (!source.Definition.Any()) + { + return new Bk2LogEntryGenerator(Emulator?.SystemId ?? SystemID, source); + } + + _logGenerator ??= new Bk2LogEntryGenerator(Emulator?.SystemId ?? SystemID, source); + return _logGenerator; } public override int FrameCount => Log.Count;