public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false) { var ret = new BinaryStateLoader(); using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { byte[] data = new byte[4]; fs.Read(data, 0, 4); if (!data.SequenceEqual(zipheader)) { return(null); } } try { ret._zip = new ZipFile(filename); ret.PopulateEntries(); if (!isMovieLoad && !ret.GetLump(BinaryStateLump.Versiontag, false, ret.ReadVersion)) { ret._zip.Close(); return(null); } return(ret); } catch (ZipException) { return(null); } }
public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false) { var ret = new BinaryStateLoader(); using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { byte[] data = new byte[4]; fs.Read(data, 0, 4); if (!data.SequenceEqual(zipheader)) return null; } try { ret._zip = new ZipFile(filename); ret.PopulateEntries(); if (!isMovieLoad && !ret.GetLump(BinaryStateLump.Versiontag, false, ret.ReadVersion)) { ret._zip.Close(); return null; } return ret; } catch (ZipException) { return null; } }
public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false) { var ret = new BinaryStateLoader(); // PORTABLE TODO - SKIP THIS.. FOR NOW // check whether its an archive before we try opening it bool isArchive; using (var archiveChecker = new SevenZipSharpArchiveHandler()) { int offset; bool isExecutable; isArchive = archiveChecker.CheckSignature(filename, out offset, out isExecutable); } if (!isArchive) { return(null); } try { ret._zip = new ZipFile(filename); ret.PopulateEntries(); if (!isMovieLoad && !ret.GetLump(BinaryStateLump.Versiontag, false, ret.ReadVersion)) { ret._zip.Close(); return(null); } return(ret); } catch (ZipException) { return(null); } }
public override bool Load() { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); ClearTasprojExtras(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { SyncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) // Note: ExtractInputLog will clear Lag and State data potentially, this must come before loading those { var errorMessage = string.Empty; IsCountingRerecords = false; ExtractInputLog(tr, out errorMessage); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } // TasMovie enhanced information if (bl.HasLump(BinaryStateLump.LagLog)) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length) { LagLog.Load(br); }); } bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr) { StateManager.Settings.PopulateFromString(tr.ReadToEnd()); }); if (StateManager.Settings.SaveStateHistory) { bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length) { StateManager.Load(br); }); } // Movie should always have a state at frame 0. if (!this.StartsFromSavestate) { StateManager.Capture(); } bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); if (GetClientSettingsOnLoad != null && bl.HasLump(BinaryStateLump.ClientSettings)) { string clientSettings = string.Empty; bl.GetLump(BinaryStateLump.ClientSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { clientSettings = line; } } }); GetClientSettingsOnLoad(clientSettings); } if (bl.HasLump(BinaryStateLump.VerificationLog)) { bl.GetLump(BinaryStateLump.VerificationLog, true, delegate(TextReader tr) { VerificationLog.Clear(); while (true) { var line = tr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } if (line.StartsWith("|")) { VerificationLog.Add(line); } } }); } } Changes = false; return(true); }
public virtual bool Load(bool preload) { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { if (!Header.ContainsKey(pair[0])) { Header.Add(pair[0], pair[1]); } } } } }); bl.GetLump(BinaryStateLump.Comments, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } Subtitles.Sort(); }); bl.GetLump(BinaryStateLump.SyncSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { _syncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { IsCountingRerecords = false; ExtractInputLog(tr, out _); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); bl.GetLump(BinaryStateLump.Framebuffer, false, delegate(BinaryReader br, long length) { SavestateFramebuffer = new int[length / sizeof(int)]; for (int i = 0; i < SavestateFramebuffer.Length; i++) { SavestateFramebuffer[i] = br.ReadInt32(); } }); } else if (StartsFromSaveRam) { bl.GetLump(BinaryStateLump.MovieSaveRam, false, delegate(BinaryReader br, long length) { SaveRam = br.ReadBytes((int)length); }); } } Changes = false; return(true); }
public static bool LoadStateFile(string path, string name) { var core = Global.Emulator.AsStatable(); // try to detect binary first var bl = BinaryStateLoader.LoadAndDetect(path); if (bl != null) { try { var succeed = false; if (Global.MovieSession.Movie.IsActive()) { bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep1(tr)); if (!succeed) { return(false); } bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep2(tr)); if (!succeed) { return(false); } } using (new SimpleTime("Load Core")) { bl.GetCoreState(br => core.LoadStateBinary(br), tr => core.LoadStateText(tr)); } bl.GetLump(BinaryStateLump.Framebuffer, false, PopulateFramebuffer); string userData = ""; bl.GetLump(BinaryStateLump.UserData, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { userData = line; } } }); if (!string.IsNullOrWhiteSpace(userData)) { Global.UserBag = (Dictionary <string, object>)ConfigService.LoadWithType(userData); } if (Global.MovieSession.Movie.IsActive() && Global.MovieSession.Movie is TasMovie) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr) { ((TasMovie)Global.MovieSession.Movie).TasLagLog.Load(tr); }); } } finally { bl.Dispose(); } return(true); } return(false); }
public void Load(BinaryStateLoader bl, TasMovie movie) { var nheader = new IndexedStateLump(BinaryStateLump.BranchHeader); var ncore = new IndexedStateLump(BinaryStateLump.BranchCoreData); var ninput = new IndexedStateLump(BinaryStateLump.BranchInputLog); var nframebuffer = new IndexedStateLump(BinaryStateLump.BranchFrameBuffer); var ncoreframebuffer = new IndexedStateLump(BinaryStateLump.BranchCoreFrameBuffer); var nmarkers = new IndexedStateLump(BinaryStateLump.BranchMarkers); var nusertext = new IndexedStateLump(BinaryStateLump.BranchUserText); Clear(); while (true) { var b = new TasBranch(); if (!bl.GetLump(nheader, false, delegate(TextReader tr) { var header = (dynamic)JsonConvert.DeserializeObject(tr.ReadLine()); b.Frame = (int)header.Frame; var timestamp = header.TimeStamp; if (timestamp != null) { b.TimeStamp = (DateTime)timestamp; } else { b.TimeStamp = DateTime.Now; } var identifier = header.UniqueIdentifier; if (identifier != null) { b.UniqueIdentifier = (Guid)identifier; } else { b.UniqueIdentifier = Guid.NewGuid(); } })) { return; } bl.GetLump(ncore, true, delegate(Stream s, long length) { b.CoreData = new byte[length]; s.Read(b.CoreData, 0, b.CoreData.Length); }); bl.GetLump(ninput, true, delegate(TextReader tr) { b.InputLog = StringLogUtil.MakeStringLog(); string line; while ((line = tr.ReadLine()) != null) { b.InputLog.Add(line); } }); bl.GetLump(nframebuffer, true, delegate(Stream s, long length) { var vp = new QuickBmpFile.LoadedBMP(); QuickBmpFile.Load(vp, s); b.OSDFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.VideoBuffer); }); bl.GetLump(ncoreframebuffer, false, delegate(Stream s, long length) { var vp = new QuickBmpFile.LoadedBMP(); QuickBmpFile.Load(vp, s); b.CoreFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.VideoBuffer); }); b.Markers = new TasMovieMarkerList(movie); bl.GetLump(nmarkers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { b.Markers.Add(new TasMovieMarker(line)); } } }); bl.GetLump(nusertext, false, delegate(TextReader tr) { string line; if ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { b.UserText = line; } } }); Add(b); nheader.Increment(); ncore.Increment(); ninput.Increment(); nframebuffer.Increment(); ncoreframebuffer.Increment(); nmarkers.Increment(); nusertext.Increment(); } }
public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false) { var ret = new BinaryStateLoader(); // PORTABLE TODO - SKIP THIS.. FOR NOW // check whether its an archive before we try opening it bool isArchive; using (var archiveChecker = new SevenZipSharpArchiveHandler()) { int offset; bool isExecutable; isArchive = archiveChecker.CheckSignature(filename, out offset, out isExecutable); } if (!isArchive) { return null; } try { ret._zip = new ZipFile(filename); ret.PopulateEntries(); if (!isMovieLoad && !ret.GetLump(BinaryStateLump.Versiontag, false, ret.ReadVersion)) { ret._zip.Close(); return null; } return ret; } catch (ZipException) { return null; } }
public override bool Load(bool preload) { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); ClearTasprojExtras(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { SyncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) // Note: ExtractInputLog will clear Lag and State data potentially, this must come before loading those { IsCountingRerecords = false; ExtractInputLog(tr, out _); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } else if (StartsFromSaveRam) { bl.GetLump(BinaryStateLump.MovieSaveRam, false, delegate(BinaryReader br, long length) { SaveRam = br.ReadBytes((int)length); }); } // TasMovie enhanced information bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr) { LagLog.Load(tr); }); bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { TasStateManager.Settings = JsonConvert.DeserializeObject <TasStateManagerSettings>(json); } catch { // Do nothing, and use default settings instead } }); bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); if (GetClientSettingsOnLoad != null) { string clientSettings = ""; bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { clientSettings = line; } } }); if (!string.IsNullOrWhiteSpace(clientSettings)) { GetClientSettingsOnLoad(clientSettings); } } bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr) { VerificationLog.Clear(); while (true) { var line = tr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } if (line.StartsWith("|")) { VerificationLog.Add(line); } } }); Branches.Load(bl, this); bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { Session = JsonConvert.DeserializeObject <TasSession>(json); } catch { // Do nothing, and use default settings instead } }); if (!preload) { if (TasStateManager.Settings.SaveStateHistory) { bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length) { TasStateManager.Load(br); }); } } } Changes = false; return(true); }
public static bool LoadStateFile(string path, string name) { var core = Global.Emulator.AsStatable(); // try to detect binary first var bl = BinaryStateLoader.LoadAndDetect(path); if (bl != null) { try { var succeed = false; if (Global.MovieSession.Movie.IsActive) { bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep1(tr)); if (!succeed) { return(false); } bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep2(tr)); if (!succeed) { return(false); } } using (new SimpleTime("Load Core")) { bl.GetCoreState(br => core.LoadStateBinary(br), tr => core.LoadStateText(tr)); } bl.GetLump(BinaryStateLump.Framebuffer, false, PopulateFramebuffer); if (bl.HasLump(BinaryStateLump.UserData)) { string userData = string.Empty; bl.GetLump(BinaryStateLump.UserData, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { userData = line; } } }); Global.UserBag = (Dictionary <string, object>)ConfigService.LoadWithType(userData); } if (bl.HasLump(BinaryStateLump.LagLog) && Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie is TasMovie) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length) { (Global.MovieSession.Movie as TasMovie).TasLagLog.Load(br); }); } } catch { return(false); } finally { bl.Dispose(); } return(true); } else // text mode { if (Global.MovieSession.HandleMovieLoadState(path)) { using (var reader = new StreamReader(path)) { core.LoadStateText(reader); while (true) { var str = reader.ReadLine(); if (str == null) { break; } if (str.Trim() == string.Empty) { continue; } var args = str.Split(' '); if (args[0] == "Framebuffer" && Global.Emulator.HasVideoProvider()) { Global.Emulator.AsVideoProvider().GetVideoBuffer().ReadFromHex(args[1]); } } } return(true); } else { return(false); } } }
public static bool LoadStateFile(IEmulator emulator, string path) { var core = emulator.AsStatable(); // try to detect binary first var bl = BinaryStateLoader.LoadAndDetect(path); if (bl != null) { try { var succeed = false; // Movie timeline check must happen before the core state is loaded if (Global.MovieSession.Movie.IsActive()) { bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.CheckSavestateTimeline(tr)); if (!succeed) { return(false); } } using (new SimpleTime("Load Core")) { bl.GetCoreState(br => core.LoadStateBinary(br), tr => core.LoadStateText(tr)); } // We must handle movie input AFTER the core is loaded to properly handle mode changes, and input latching if (Global.MovieSession.Movie.IsActive()) { bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleLoadState(tr)); if (!succeed) { return(false); } } bl.GetLump(BinaryStateLump.Framebuffer, false, PopulateFramebuffer); string userData = ""; bl.GetLump(BinaryStateLump.UserData, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { userData = line; } } }); if (!string.IsNullOrWhiteSpace(userData)) { Global.UserBag = (Dictionary <string, object>)ConfigService.LoadWithType(userData); } if (Global.MovieSession.Movie.IsActive() && Global.MovieSession.Movie is TasMovie) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr) { ((TasMovie)Global.MovieSession.Movie).LagLog.Load(tr); }); } } finally { bl.Dispose(); } return(true); } return(false); }
public override bool Load() { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); ClearTasprojExtrasBeforeLoad(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { SyncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { var errorMessage = string.Empty; ExtractInputLog(tr, out errorMessage); }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } // TasMovie enhanced information bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length) { LagLog = br.ReadBytes((int)length).ToBools().ToList(); }); bl.GetLump(BinaryStateLump.GreenzoneSettings, false, delegate(TextReader tr) { StateManager.Settings.PopulateFromString(tr.ReadToEnd()); }); if (StateManager.Settings.SaveGreenzone) { bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br, long length) { StateManager.FromArray(br.ReadBytes((int)length)); }); } bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); } Changes = false; return(true); }
public static bool LoadStateFile(string path, string name) { var core = Global.Emulator.AsStatable(); // try to detect binary first var bl = BinaryStateLoader.LoadAndDetect(path); if (bl != null) { try { var succeed = false; if (Global.MovieSession.Movie.IsActive) { bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep1(tr)); if (!succeed) { return(false); } bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep2(tr)); if (!succeed) { return(false); } } using (new SimpleTime("Load Core")) bl.GetCoreState(br => core.LoadStateBinary(br), tr => core.LoadStateText(tr)); bl.GetLump(BinaryStateLump.Framebuffer, false, PopulateFramebuffer); } catch { return(false); } finally { bl.Dispose(); } return(true); } else // text mode { if (Global.MovieSession.HandleMovieLoadState(path)) { using (var reader = new StreamReader(path)) { core.LoadStateText(reader); while (true) { var str = reader.ReadLine(); if (str == null) { break; } if (str.Trim() == string.Empty) { continue; } var args = str.Split(' '); if (args[0] == "Framebuffer") { Global.Emulator.VideoProvider().GetVideoBuffer().ReadFromHex(args[1]); } } } return(true); } else { return(false); } } }
public static bool LoadStateFile(string path, string name) { // try to detect binary first var bl = BinaryStateLoader.LoadAndDetect(path); if (bl != null) { try { var succeed = false; if (Global.MovieSession.Movie.IsActive) { bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep1(tr)); bl.GetLump(BinaryStateLump.Input, true, tr => succeed = Global.MovieSession.HandleMovieLoadState_HackyStep2(tr)); if (!succeed) { return(false); } } bl.GetCoreState(br => Global.Emulator.LoadStateBinary(br), tr => Global.Emulator.LoadStateText(tr)); bl.GetLump(BinaryStateLump.Framebuffer, false, delegate(BinaryReader br) { var buff = Global.Emulator.VideoProvider.GetVideoBuffer(); try { for (int i = 0; i < buff.Length; i++) { int j = br.ReadInt32(); buff[i] = j; } } catch (EndOfStreamException) { } }); } finally { bl.Dispose(); } return(true); } else // text mode { if (Global.MovieSession.HandleMovieLoadState(path)) { using (var reader = new StreamReader(path)) { Global.Emulator.LoadStateText(reader); while (true) { var str = reader.ReadLine(); if (str == null) { break; } if (str.Trim() == string.Empty) { continue; } var args = str.Split(' '); if (args[0] == "Framebuffer") { Global.Emulator.VideoProvider.GetVideoBuffer().ReadFromHex(args[1]); } } } return(true); } else { return(false); } } }
public void Load(BinaryStateLoader bl) { var nheader = new IndexedStateLump(BinaryStateLump.BranchHeader); var ncore = new IndexedStateLump(BinaryStateLump.BranchCoreData); var ninput = new IndexedStateLump(BinaryStateLump.BranchInputLog); var nframebuffer = new IndexedStateLump(BinaryStateLump.BranchFrameBuffer); var nlaglog = new IndexedStateLump(BinaryStateLump.BranchLagLog); Clear(); while (true) { var b = new TasBranch(); if (!bl.GetLump(nheader, false, delegate(TextReader tr) { var header = (dynamic)JsonConvert.DeserializeObject(tr.ReadLine()); b.Frame = (int)header.Frame; var timestamp = (dynamic)header.TImeStamp; if (timestamp != null) { b.TimeStamp = (DateTime)timestamp; } else { b.TimeStamp = DateTime.Now; } })) { return; } bl.GetLump(ncore, true, delegate(Stream s, long length) { b.CoreData = new byte[length]; s.Read(b.CoreData, 0, b.CoreData.Length); }); bl.GetLump(ninput, true, delegate(TextReader tr) { b.InputLog = new List <string>(); string line; while ((line = tr.ReadLine()) != null) { b.InputLog.Add(line); } }); bl.GetLump(nframebuffer, true, delegate(Stream s, long length) { var vp = new QuickBmpFile.LoadedBMP(); QuickBmpFile.Load(vp, s); b.OSDFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.VideoBuffer); }); bl.GetLump(nlaglog, true, delegate(BinaryReader br) { b.LagLog = new TasLagLog(); b.LagLog.Load(br); }); Add(b); nheader.Increment(); ncore.Increment(); ninput.Increment(); nframebuffer.Increment(); nlaglog.Increment(); } }
public virtual bool Load() { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { _syncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { var errorMessage = string.Empty; ExtractInputLog(tr, out errorMessage); }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } } Changes = false; return(true); }