2018-09-01 04:21:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2019-11-16 06:16:33 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
2018-09-01 04:21:34 +00:00
|
|
|
|
{
|
2018-12-22 18:40:30 +00:00
|
|
|
|
public sealed class MemorySaveStateApi : IMemorySaveState
|
2018-09-01 04:21:34 +00:00
|
|
|
|
{
|
2018-12-22 18:40:30 +00:00
|
|
|
|
public MemorySaveStateApi()
|
2018-09-04 02:31:01 +00:00
|
|
|
|
{ }
|
2018-09-01 04:21:34 +00:00
|
|
|
|
|
|
|
|
|
[RequiredService]
|
|
|
|
|
private IStatable StatableCore { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<Guid, byte[]> _memorySavestates = new Dictionary<Guid, byte[]>();
|
|
|
|
|
|
|
|
|
|
public string SaveCoreStateToMemory()
|
|
|
|
|
{
|
|
|
|
|
var guid = Guid.NewGuid();
|
|
|
|
|
var bytes = (byte[])StatableCore.SaveStateBinary().Clone();
|
|
|
|
|
|
|
|
|
|
_memorySavestates.Add(guid, bytes);
|
|
|
|
|
|
|
|
|
|
return guid.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadCoreStateFromMemory(string identifier)
|
|
|
|
|
{
|
|
|
|
|
var guid = new Guid(identifier);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var state = _memorySavestates[guid];
|
|
|
|
|
|
2019-11-15 23:29:38 +00:00
|
|
|
|
using var ms = new MemoryStream(state);
|
|
|
|
|
using var br = new BinaryReader(ms);
|
|
|
|
|
StatableCore.LoadStateBinary(br);
|
2018-09-01 04:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Unable to find the given savestate in memory");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteState(string identifier)
|
|
|
|
|
{
|
|
|
|
|
var guid = new Guid(identifier);
|
|
|
|
|
_memorySavestates.Remove(guid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearInMemoryStates()
|
|
|
|
|
{
|
|
|
|
|
_memorySavestates.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|