2014-07-08 13:46:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using BizHawk.Common.ReflectionExtensions;
|
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-07-19 23:24:43 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
2014-07-08 13:46:59 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common.MovieConversionExtensions
|
2014-06-17 01:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
public static class MovieConversionExtensions
|
|
|
|
|
{
|
2014-07-06 21:20:43 +00:00
|
|
|
|
public static TasMovie ToTasMovie(this IMovie old)
|
2014-06-17 01:24:44 +00:00
|
|
|
|
{
|
2014-07-06 21:20:43 +00:00
|
|
|
|
var newFilename = old.Filename + "." + TasMovie.Extension;
|
|
|
|
|
var tas = new TasMovie(newFilename);
|
2014-08-16 20:32:59 +00:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < old.InputLogLength; i++)
|
|
|
|
|
{
|
|
|
|
|
var input = old.GetInputState(i);
|
|
|
|
|
tas.AppendFrame(input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old.Truncate(0); // Trying to minimize ram usage
|
|
|
|
|
|
2014-07-06 21:20:43 +00:00
|
|
|
|
tas.HeaderEntries.Clear();
|
|
|
|
|
foreach (var kvp in old.HeaderEntries)
|
|
|
|
|
{
|
|
|
|
|
tas.HeaderEntries[kvp.Key] = kvp.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tas.SyncSettingsJson = old.SyncSettingsJson;
|
|
|
|
|
|
|
|
|
|
tas.Comments.Clear();
|
|
|
|
|
foreach (var comment in old.Comments)
|
|
|
|
|
{
|
|
|
|
|
tas.Comments.Add(comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tas.Subtitles.Clear();
|
|
|
|
|
foreach (var sub in old.Subtitles)
|
|
|
|
|
{
|
|
|
|
|
tas.Subtitles.Add(sub);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tas.TextSavestate = old.TextSavestate;
|
|
|
|
|
tas.BinarySavestate = old.BinarySavestate;
|
|
|
|
|
|
2014-08-16 20:32:59 +00:00
|
|
|
|
|
2014-07-06 21:20:43 +00:00
|
|
|
|
|
|
|
|
|
return tas;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 01:32:27 +00:00
|
|
|
|
public static Bk2Movie ToBk2(this IMovie old, bool copy = false)
|
2014-07-06 21:20:43 +00:00
|
|
|
|
{
|
|
|
|
|
var newFilename = old.Filename + "." + Bk2Movie.Extension;
|
2014-06-19 02:05:38 +00:00
|
|
|
|
var bk2 = new Bk2Movie(newFilename);
|
2014-08-16 20:32:59 +00:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < old.InputLogLength; i++)
|
|
|
|
|
{
|
|
|
|
|
var input = old.GetInputState(i);
|
|
|
|
|
bk2.AppendFrame(input);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 01:32:27 +00:00
|
|
|
|
if (!copy)
|
|
|
|
|
{
|
|
|
|
|
old.Truncate(0); // Trying to minimize ram usage
|
|
|
|
|
}
|
2014-08-16 20:32:59 +00:00
|
|
|
|
|
2014-06-17 01:24:44 +00:00
|
|
|
|
bk2.HeaderEntries.Clear();
|
2014-07-06 21:20:43 +00:00
|
|
|
|
foreach(var kvp in old.HeaderEntries)
|
2014-06-17 01:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
bk2.HeaderEntries[kvp.Key] = kvp.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-06 21:20:43 +00:00
|
|
|
|
bk2.SyncSettingsJson = old.SyncSettingsJson;
|
2014-06-17 01:24:44 +00:00
|
|
|
|
|
|
|
|
|
bk2.Comments.Clear();
|
2014-07-06 21:20:43 +00:00
|
|
|
|
foreach(var comment in old.Comments)
|
2014-06-17 01:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
bk2.Comments.Add(comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bk2.Subtitles.Clear();
|
2014-07-06 21:20:43 +00:00
|
|
|
|
foreach(var sub in old.Subtitles)
|
2014-06-17 01:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
bk2.Subtitles.Add(sub);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-06 21:20:43 +00:00
|
|
|
|
bk2.TextSavestate = old.TextSavestate;
|
|
|
|
|
bk2.BinarySavestate = old.BinarySavestate;
|
2014-06-19 02:05:38 +00:00
|
|
|
|
|
2014-07-16 23:22:30 +00:00
|
|
|
|
bk2.Save();
|
2014-06-17 01:24:44 +00:00
|
|
|
|
return bk2;
|
|
|
|
|
}
|
2014-07-08 13:46:59 +00:00
|
|
|
|
|
|
|
|
|
// TODO: This doesn't really belong here, but not sure where to put it
|
|
|
|
|
public static void PopulateWithDefaultHeaderValues(this IMovie movie, string author = null)
|
|
|
|
|
{
|
|
|
|
|
movie.Author = author ?? Global.Config.DefaultAuthor;
|
|
|
|
|
movie.EmulatorVersion = VersionInfo.GetEmuVersion();
|
2014-07-19 21:41:47 +00:00
|
|
|
|
movie.SystemID = Global.Emulator.SystemId;
|
2014-07-08 13:46:59 +00:00
|
|
|
|
|
2014-10-23 22:30:47 +00:00
|
|
|
|
var settable = Global.Emulator as ISettable;
|
2014-10-19 01:39:43 +00:00
|
|
|
|
if (settable != null)
|
|
|
|
|
{
|
|
|
|
|
movie.SyncSettingsJson = ConfigService.SaveWithType(settable.GetSyncSettings());
|
|
|
|
|
}
|
2014-07-08 13:46:59 +00:00
|
|
|
|
|
|
|
|
|
if (Global.Game != null)
|
|
|
|
|
{
|
|
|
|
|
movie.GameName = PathManager.FilesystemSafeName(Global.Game);
|
|
|
|
|
movie.Hash = Global.Game.Hash;
|
|
|
|
|
if (Global.Game.FirmwareHash != null)
|
|
|
|
|
{
|
|
|
|
|
movie.FirmwareHash = Global.Game.FirmwareHash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
movie.GameName = "NULL";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Global.Emulator.BoardName != null)
|
|
|
|
|
{
|
|
|
|
|
movie.BoardName = Global.Emulator.BoardName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Global.Emulator.HasPublicProperty("DisplayType"))
|
|
|
|
|
{
|
|
|
|
|
var region = Global.Emulator.GetPropertyValue("DisplayType");
|
|
|
|
|
if ((DisplayType)region == DisplayType.PAL)
|
|
|
|
|
{
|
|
|
|
|
movie.HeaderEntries.Add(HeaderKeys.PAL, "1");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 23:24:43 +00:00
|
|
|
|
if (Global.Emulator is Gameboy && (Global.Emulator as Gameboy).IsCGBMode())
|
|
|
|
|
{
|
|
|
|
|
movie.HeaderEntries.Add("IsCGBMode", "1");
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 13:46:59 +00:00
|
|
|
|
movie.Core = ((CoreAttributes)Attribute
|
|
|
|
|
.GetCustomAttribute(Global.Emulator.GetType(), typeof(CoreAttributes)))
|
|
|
|
|
.CoreName;
|
|
|
|
|
}
|
2014-06-17 01:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|