Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BizHawk.Client.Common/FilesystemFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public FilesystemFilter(

public static readonly FilesystemFilter PNGs = new FilesystemFilter("PNG Files", new[] { "png" });

public static readonly FilesystemFilter SaveRams = new FilesystemFilter("SaveRAM Files", new[] { "SaveRAM", "bin" });

public static readonly FilesystemFilter TAStudioProjects = new FilesystemFilter("TAS Project Files", new[] { MovieService.TasMovieExtension });

public static readonly FilesystemFilter TextFiles = new FilesystemFilter("Text Files", new[] { "txt" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ public static string SaveRamAbsolutePath(this PathEntryCollection collection, IG
return $"{Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name)}.SaveRAM";
}

public static string SaveRamAbsolutePath(this PathEntryCollection collection, string system)
{
var pathEntry = collection[system, "Save RAM"]
?? collection[system, "Base"];

return collection.AbsolutePathFor(pathEntry.Path, system);
}

// Shenanigans
public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, string coreName)
{
Expand Down
12 changes: 12 additions & 0 deletions src/BizHawk.Client.Common/savestates/Savestate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#nullable enable

using BizHawk.Bizware.Graphics;

namespace BizHawk.Client.Common
{
public class Savestate
{
public required byte[] coreData;
public BitmapBuffer? screenshot;
}
}
50 changes: 43 additions & 7 deletions src/BizHawk.Client.Common/savestates/SavestateFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ public FileWriteResult Create(string filename, SaveStateConfig config, bool make
return bs.CloseAndDispose(makeBackup ? $"{filename}.bak" : null);
}

public bool Load(string path, IDialogParent dialogParent)
private ZipStateLoader/*?*/ OpenAndValidate(string path, IDialogParent dialogParent)
{
// try to detect binary first
using var bl = ZipStateLoader.LoadAndDetect(path);
if (bl is null) return false;
var succeed = false;
var bl = ZipStateLoader.LoadAndDetect(path);
if (bl is null) return null;

// check EmuHawk version
if (!VersionInfo.DeveloperBuild)
{
bool succeed = false;
bl.GetLump(BinaryStateLump.BizVersion, true, tr => succeed = tr.ReadLine() == VersionInfo.GetEmuVersion());
if (!succeed)
{
Expand All @@ -153,7 +153,7 @@ public bool Load(string path, IDialogParent dialogParent)
"Savestate version mismatch",
EMsgBoxIcon.Question,
useOKCancel: true);
if (!result) return false;
if (!result) return null;
}
}

Expand Down Expand Up @@ -183,10 +183,46 @@ loadedSyncSettings is null
: "This savestate was made with a different core or different sync settings.\nLoadstate cancelled.",
"Savestate sync settings mismatch",
EMsgBoxIcon.Info);
return false;
return null;
}
}

return bl;
}

public Savestate/*?*/ GetSavestate(string path, IDialogParent dialogParent)
{
using ZipStateLoader/*?*/ bl = OpenAndValidate(path, dialogParent);
if (bl == null) return null;

byte[] coreData = null;
bl.GetLump(BinaryStateLump.Corestate, true, br =>
{
using MemoryStream ms = new();
br.BaseStream.CopyTo(ms);
coreData = ms.ToArray();
});
if (coreData == null) throw new Exception("Could not find or read binary savestate data in file.");

BitmapBuffer screenshot = null;
bl.GetLump(BinaryStateLump.Framebuffer, false, br =>
{
screenshot = new BitmapBuffer(br.BaseStream, new());
});

return new()
{
coreData = coreData,
screenshot = screenshot,
};
}

public bool Load(string path, IDialogParent dialogParent)
{
using ZipStateLoader bl = OpenAndValidate(path, dialogParent);
if (bl is null) return false;
var succeed = false;

// Movie timeline check must happen before the core state is loaded
if (_movieSession.Movie.IsActive())
{
Expand Down
Loading
Loading