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);
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        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);
        }
Example #4
0
        public bool Load(string path)
        {
            // try to detect binary first
            var bl = ZipStateLoader.LoadAndDetect(path);

            if (bl != null)
            {
                try
                {
                    var succeed = false;

                    // Movie timeline check must happen before the core state is loaded
                    if (_movieSession.Movie.IsActive())
                    {
                        bl.GetLump(BinaryStateLump.Input, true, tr => succeed = _movieSession.CheckSavestateTimeline(tr));
                        if (!succeed)
                        {
                            return(false);
                        }
                    }

                    using (new SimpleTime("Load Core"))
                    {
                        bl.GetCoreState(br => _statable.LoadStateBinary(br), tr => _statable.LoadStateText(tr));
                    }

                    // We must handle movie input AFTER the core is loaded to properly handle mode changes, and input latching
                    if (_movieSession.Movie.IsActive())
                    {
                        bl.GetLump(BinaryStateLump.Input, true, tr => succeed = _movieSession.HandleLoadState(tr));
                        if (!succeed)
                        {
                            return(false);
                        }
                    }

                    if (_videoProvider != null)
                    {
                        bl.GetLump(BinaryStateLump.Framebuffer, false, br => PopulateFramebuffer(br, _videoProvider, _quickBmpFile));
                    }

                    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))
                    {
                        var bag = (Dictionary <string, object>)ConfigService.LoadWithType(userData);
                        _userBag.Clear();
                        foreach (var(k, v) in bag)
                        {
                            _userBag.Add(k, v);
                        }
                    }

                    if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
                    {
                        bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
                        {
                            ((ITasMovie)_movieSession.Movie).LagLog.Load(tr);
                        });
                    }
                }
                finally
                {
                    bl.Dispose();
                }

                return(true);
            }

            return(false);
        }
Example #5
0
        public bool Load(string path, IDialogParent dialogParent)
        {
            // try to detect binary first
            using var bl = ZipStateLoader.LoadAndDetect(path);
            if (bl is null)
            {
                return(false);
            }
            var succeed = false;

            if (!VersionInfo.DeveloperBuild)
            {
                bl.GetLump(BinaryStateLump.BizVersion, true, tr => succeed = tr.ReadLine() == VersionInfo.GetEmuVersion());
                if (!succeed)
                {
                    var result = dialogParent.ModalMessageBox2(
                        "This savestate was made with a different version, so it's unlikely to work.\nChoose OK to try loading it anyway.",
                        "Savestate version mismatch",
                        EMsgBoxIcon.Question,
                        useOKCancel: true);
                    if (!result)
                    {
                        return(false);
                    }
                }
            }

            // Movie timeline check must happen before the core state is loaded
            if (_movieSession.Movie.IsActive())
            {
                bl.GetLump(BinaryStateLump.Input, true, tr => succeed = _movieSession.CheckSavestateTimeline(tr));
                if (!succeed)
                {
                    return(false);
                }
            }

            using (new SimpleTime("Load Core"))
            {
                bl.GetCoreState(br => _statable.LoadStateBinary(br), tr => _statable.LoadStateText(tr));
            }

            // We must handle movie input AFTER the core is loaded to properly handle mode changes, and input latching
            if (_movieSession.Movie.IsActive())
            {
                bl.GetLump(BinaryStateLump.Input, true, tr => succeed = _movieSession.HandleLoadState(tr));
                if (!succeed)
                {
                    return(false);
                }
            }

            if (_videoProvider != null)
            {
                bl.GetLump(BinaryStateLump.Framebuffer, false, br => PopulateFramebuffer(br, _videoProvider, _quickBmpFile));
            }

            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))
            {
                var bag = (Dictionary <string, object>)ConfigService.LoadWithType(userData);
                _userBag.Clear();
                foreach (var(k, v) in bag)
                {
                    _userBag.Add(k, v);
                }
            }

            if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
            {
                bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
                {
                    ((ITasMovie)_movieSession.Movie).LagLog.Load(tr);
                });
            }

            return(true);
        }