示例#1
0
        /// <summary>
        /// Unpacks lsv files
        /// </summary>
        /// <param name="savegame">Savegame object</param>
        /// <param name="progress">Progress text to be updated in Progress Indicator UI</param>
        /// <returns>true for successful, otherwise fail</returns>
        private async Task <bool> UnpackSaveAsync(Savegame savegame, IProgress <string> progress)
        {
            try
            {
                Cursor = Cursors.Wait;
#if (!DEBUG || !AVOIDUNPACK)
                await savegame.UnpackSavegameAsync(progress);
#endif
                await savegame.ParseLsxAsync(progress);
            }
            catch (NotAPackageException)
            {
                MessageBox.Show(this, $"The specified package ({savegame.SavegameFullFile}) is not a savegame file.",
                                "Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(false);
            }
            catch (Exception ex)
            {
                var er = new ErrorReporting($"Internal error!\n\n{ex}", null);
                er.ShowDialog();
                return(false);
            }
            finally
            {
                Cursor = Cursors.Arrow;
                LoadButton.IsEnabled = true;
            }
            return(true);
        }
示例#2
0
        private void DebugButton_OnClick(object sender, RoutedEventArgs e)
        {
            switch (((Button)sender).Tag)
            {
            case "AllPlayer":
                Savegame.DumpSavegame();
                break;

            case "AllInv":
                Savegame.DumpAllInventory();
                break;

            case "AllMod":
                Savegame.DumpAllModifiers();
                break;

            case "AllPerBoost":
                Savegame.DumpAllPermanentBoosts();
                break;

            case "AllSkills":
                Savegame.DumpAllSkills();
                break;

            case "AllTalents":
                Savegame.DumpAllTalents();
                break;
            }

            MessageBox.Show("A dump file has been created. Thank you!");
        }
        public SaveEditor(Savegame savegame)
        {
            InitializeComponent();
            Savegame = savegame;

            Title = $"D-OS Save Editor: {savegame.SavegameName.Substring(0,savegame.SavegameName.Length-4)}";

            // make a copy of players
            try
            {
                EditingPlayers = Savegame.Players.Select(a => a?.DeepClone()).ToArray();
            }
            catch (Exception ex)
            {
                var er = new ErrorReporting($"Fail to clone players.\n\n{ex}", null);
                er.ShowDialog();
                throw;
            }

            foreach (var p in Savegame.Players)
            {
                PlayerSelectionComboBox.Items.Add(p.Name);
            }

            PlayerSelectionComboBox.SelectedIndex = 0;
        }
        private void SaveButton_OnClick(object sender, RoutedEventArgs e)
        {
            SaveButton.IsEnabled = false;
            try
            {
                Cursor = Cursors.Wait;
                StatsTab.SaveEdits();
                AbilitiesTab.SaveEdits();
                TraitsTab.SaveEdits();

                // apply changes
                Savegame.Players = EditingPlayers;
                Savegame.WriteEditsToLsx();
                // pack up files
                Savegame.PackSavegame();

                MessageBox.Show(this, "Successfuly saved Savegame file.");
                DialogResult = true;
            }
            catch (Exception ex)
            {
                SaveButton.IsEnabled = true;
                var er = new ErrorReporting($"Failed to save changes.\n\n{ex}", null);
                er.ShowDialog();
            }
            finally
            {
                Cursor = Cursors.Arrow;
                SaveButton.IsEnabled = true;
            }
        }
示例#5
0
        private async void SavegameListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0 || ((ListBox)sender).Items.Count < 1)
            {
                LoadButton.IsEnabled    = false;
                BackupButton.IsEnabled  = false;
                RestoreButton.IsEnabled = false;
                SavegameImage.Source    = null;
                return;
            }

            LoadButton.IsEnabled    = true;
            BackupButton.IsEnabled  = true;
            RestoreButton.IsEnabled = true;
            var saveGameName           = ((TextBlock)e.AddedItems[e.AddedItems.Count - 1]).Uid;
            var saveGameNameWithoutExt = DirectoryTextBox.Text + DirectorySeparatorChar + saveGameName + DirectorySeparatorChar +
                                         saveGameName;
            var imageDir = saveGameNameWithoutExt + ".png";

            if (File.Exists(imageDir))
            {
                SavegameImage.Source = new BitmapImage(new Uri(imageDir));
            }

            var savegameTemp = new Savegame(saveGameNameWithoutExt + ".lsv",
                                            GetTempPath() + "DOSSE" + DirectorySeparatorChar + "temp",
                                            (Game)GameEditionTextBlock.Tag);

            if (_getMetaBackgroundWorker == null)
            {
                _getMetaBackgroundWorker = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };
                _getMetaBackgroundWorker.RunWorkerCompleted += (o, args) =>
                {
                    if (args.Cancelled || args.Error != null || args.Result == null)
                    {
                        return;
                    }
                    MainWindowData.Meta = (Meta)args.Result;
                    _getMetaBackgroundWorker.Dispose();
                };
            }

            if (_getMetaBackgroundWorker.IsBusy)
            {
                _getMetaBackgroundWorker.CancelAsync();
            }
            while (_getMetaBackgroundWorker.IsBusy)
            {
                await Task.Delay(5);
            }

            _getMetaBackgroundWorker.DoWork += savegameTemp.GetMetaBackgroundWorker;
            MainWindowData.Meta              = new Meta();
            _getMetaBackgroundWorker.RunWorkerAsync();
        }
示例#6
0
        public SaveEditor(Savegame savegame)
        {
            InitializeComponent();

            ShowMeta = savegame.Meta;
            // check number of game version and inform user
            if (ShowMeta.GameVersion.Count > 1)
            {
                string formatedVersions = "";
                foreach (string gameVersion in ShowMeta.GameVersion)
                {
                    formatedVersions += "\n  " + gameVersion;
                }
                MessageBox.Show("DOS EE Editor found " + ShowMeta.GameVersion.Count + " game versions for this savegame\nDOS EE Editor and this modified savegame may be unstable: keep play on latest version you have.\nGame Version:" + formatedVersions, "Too many game version", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            if (ShowMeta.ModsName.Count > 1)
            {
                string formatedMods = "";
                foreach (string modName in ShowMeta.ModsName)
                {
                    if (modName != "Shared")
                    {
                        formatedMods += "\n  " + modName;
                    }
                }
                MessageBox.Show("DOS EE Editor found " + (ShowMeta.ModsName.Count - 1) + " mod" + ((ShowMeta.ModsName.Count - 1) > 1 ? "s" : "") + " for this savegame\nDOS EE Editor and this modified savegame may be unstable.\nThe savegame will be mostly corrupted if it's edited by DOS EE Editor\nMods name:" + formatedMods, "Mod" + (ShowMeta.ModsName.Count > 1 ? "s" : "") + " found", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            Savegame = savegame;
            // make a copy of players
            try
            {
                EditingPlayers = Savegame.Players.Select(a => a?.DeepClone()).ToArray();
            }
            catch (Exception ex)
            {
                var er = new ErrorReporting($"Fail to clone players.\n\n{ex}", null);
                er.ShowDialog();
                throw;
            }

            foreach (var p in Savegame.Players)
            {
                PlayerSelectionComboBox.Items.Add(p.Name);
            }

            PlayerSelectionComboBox.SelectedIndex = 0;

            CheckUnlisted();
        }
        public SaveEditor(string jsonFile)
        {
            InitializeComponent();

            Savegame = Savegame.GetSavegameFromJson(jsonFile);
            // make a copy of players
            EditingPlayers = Savegame.Players.Select(a => a?.DeepClone()).ToArray();

            foreach (var p in Savegame.Players)
            {
                PlayerSelectionComboBox.Items.Add(p.Name);
            }

            PlayerSelectionComboBox.SelectedIndex = 0;
        }
示例#8
0
        private async void SaveButton_OnClick(object sender, RoutedEventArgs e)
        {
            SaveButton.IsEnabled = false;
            try
            {
                Cursor = Cursors.Wait;
                StatsTab.SaveEdits();
                AbilitiesTab.SaveEdits();
                TraitsTab.SaveEdits();
                TalentTab.SaveEdits();

                // progress indicator
                var progressIndicator = new ProgressIndicator("Saving", false)
                {
                    Owner = Application.Current.MainWindow
                };
                var progress = new Progress <string>();
                progress.ProgressChanged += (o, s) =>
                {
                    progressIndicator.ProgressText = s;
                };
                progressIndicator.Show();

                // apply changes
                Savegame.Players = EditingPlayers;
                await Savegame.WriteEditsToLsxAsync(progress);

                // pack up files
                await Savegame.PackSavegameAsync(progress);

                progressIndicator.ProgressText     = "Successful.";
                progressIndicator.CanCancel        = true;
                progressIndicator.CancelButtonText = "Close";

                DialogResult = true;
            }
            catch (Exception ex)
            {
                SaveButton.IsEnabled = true;
                var er = new ErrorReporting($"Failed to save changes.\n\n{ex}", null);
                er.ShowDialog();
            }
            finally
            {
                Cursor = Cursors.Arrow;
                SaveButton.IsEnabled = true;
            }
        }
        public SaveEditor(Savegame savegame)
        {
            InitializeComponent();

            Savegame = savegame;
            // make a copy of players
            EditingPlayers = Savegame.Players.Select(a => a?.DeepClone()).ToArray();

            foreach (var p in Savegame.Players)
            {
                PlayerSelectionComboBox.Items.Add(p.Name);
            }

            PlayerSelectionComboBox.SelectedIndex = 0;

            CheckUnlisted();
        }
示例#10
0
        public SaveEditor(string jsonFile)
        {
            InitializeComponent();

            Savegame = Savegame.GetSavegameFromJson(jsonFile);
            // make a copy of players
            try
            {
                EditingPlayers = Savegame.Players.Select(a => a?.DeepClone()).ToArray();
            }
            catch (Exception ex)
            {
                var er = new ErrorReporting($"Fail to clone players.\n\n{ex}", null);
                er.ShowDialog();
                throw;
            }

            foreach (var p in Savegame.Players)
            {
                PlayerSelectionComboBox.Items.Add(p.Name);
            }

            PlayerSelectionComboBox.SelectedIndex = 0;
        }
示例#11
0
        private async Task LoadSavegame()
        {
            LoadButton.IsEnabled = false;

            if (SavegameListBox.SelectedItem == null)
            {
                return;
            }

            var unpackDir    = GetTempPath() + "DOSSE" + DirectorySeparatorChar + "unpackaged";
            var saveGameName = ((TextBlock)SavegameListBox.SelectedItem).Uid;

            // check backup
            switch (IsBackedUp(saveGameName))
            {
            case BackupStatus.None:
                var dlgResult = MessageBox.Show(this, "The savegame is not backed up. Do you want to make a backup first?",
                                                "No backup found.", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Yes)
                {
                    BackupSavegame(saveGameName);
                }
                break;

            case BackupStatus.Current:
                break;

            case BackupStatus.Old:
                dlgResult = MessageBox.Show(this,
                                            "The backup seems to be old because it failed checksum validation. Do you want to make a new backup?",
                                            "Old backup found", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Yes)
                {
                    BackupSavegame(saveGameName);
                }
                break;

            case BackupStatus.NoChecksum:
                dlgResult = MessageBox.Show(this,
                                            "The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
                                            "No checksum file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    break;
                }

            case BackupStatus.NoImage:
                dlgResult = MessageBox.Show(this,
                                            "The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
                                            "No image file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    break;
                }
            }

            var savegame = new Savegame(
                DirectoryTextBox.Text + DirectorySeparatorChar + saveGameName + DirectorySeparatorChar + saveGameName + ".lsv",
                unpackDir,
                (Game)GameEditionTextBlock.Tag);

            // unpack
            var progressIndicator = new ProgressIndicator($"Loading {saveGameName}", false)
            {
                Owner = Application.Current.MainWindow
            };
            var progress = new Progress <string>();

            progress.ProgressChanged += (o, s) =>
            {
                progressIndicator.ProgressText = s;
            };

            if (_getMetaBackgroundWorker.IsBusy)
            {
                progressIndicator.ProgressText = "Waiting for meta info...";
            }

            progressIndicator.Show();

            while (_getMetaBackgroundWorker.IsBusy)
            {
                await Task.Delay(5);
            }

            // TODO DNSA (Do Not Show Again) message box
            // version check
            if (MainWindowData.Meta.IsOutdatedVersion)
            {
                var dlgResult = MessageBox.Show(this,
                                                $"It appears that the version of your game is different from what this SE is purposely created for (ver. {DataTable.SupportedGameVersion}). As a result, changes made to your savegame may corrupt the savegame.\n\nMake sure you make a backup before continuing.",
                                                "Game version incompatible", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Cancel)
                {
                    progressIndicator.Close();
                    return;
                }
            }
            // mod check
            if (MainWindowData.Meta.IsModWarning)
            {
                var dlgResult = MessageBox.Show(this,
                                                "It appears that you have used mods. As a result, changes made to your savegame may corrupt the savegame.\n\nMake sure you make a backup before continuing.",
                                                "Mods found", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Cancel)
                {
                    progressIndicator.Close();
                    return;
                }
            }

            var unpackTask = await UnpackSaveAsync(savegame, progress);

            progressIndicator.Close();
            if (!unpackTask)
            {
                return;
            }

            SaveEditor se;

            try
            {
                se = new SaveEditor(savegame)
                {
                    Owner = Application.Current.MainWindow
                };
            }
            catch
            {
                return;
            }
            se.ShowDialog();
        }
示例#12
0
        private async void LoadButton_OnClick(object sender, RoutedEventArgs e)
        {
            LoadButton.IsEnabled = false;

            if (SavegameListBox.SelectedItem == null)
            {
                return;
            }

            var unpackDir    = GetTempPath() + "DOSSE" + DirectorySeparatorChar + "unpackaged";
            var saveGameName = ((TextBlock)SavegameListBox.SelectedItem).Uid;

            // check backup
            switch (IsBackedUp(saveGameName))
            {
            case BackupStatus.None:
                var dlgResult = MessageBox.Show(this, "The savegame is not backed up. Do you want to make a backup first?",
                                                "No backup found.", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Yes)
                {
                    BackupSavegame(saveGameName);
                }
                break;

            case BackupStatus.Current:
                break;

            case BackupStatus.Old:
                dlgResult = MessageBox.Show(this,
                                            "The backup seems to be old because it failed checksum validation. Do you want to make a new backup?",
                                            "Old backup found", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Yes)
                {
                    BackupSavegame(saveGameName);
                }
                break;

            case BackupStatus.NoChecksum:
                dlgResult = MessageBox.Show(this,
                                            "The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
                                            "No checksum file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    break;
                }

            case BackupStatus.NoImage:
                dlgResult = MessageBox.Show(this,
                                            "The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
                                            "No image file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    break;
                }
            }

            var savegame = new Savegame(
                DirectoryTextBox.Text + DirectorySeparatorChar + saveGameName + DirectorySeparatorChar + saveGameName + ".lsv",
                unpackDir,
                (Game)GameEditionTextBlock.Tag);

            // unpack
            var progressIndicator = new ProgressIndicator($"Loading {saveGameName}", false)
            {
                Owner = Application.Current.MainWindow
            };
            var progress = new Progress <string>();

            progress.ProgressChanged += (o, s) =>
            {
                progressIndicator.ProgressText = s;
            };
            progressIndicator.Show();
            var unpackTask = await UnpackSaveAsync(savegame, progress);

            progressIndicator.Close();
            if (!unpackTask)
            {
                return;
            }

            SaveEditor se;

            try
            {
                se = new SaveEditor(savegame)
                {
                    Owner = Application.Current.MainWindow
                };
            }
            catch (Exception exception)
            {
                return;
            }
            se.ShowDialog();
        }
示例#13
0
        private void LoadButton_OnClick(object sender, RoutedEventArgs e)
        {
            LoadButton.IsEnabled = false;

            if (SavegameListBox.SelectedItem == null)
            {
                return;
            }

            var unpackDir    = GetTempPath() + "DOSSE" + DirectorySeparatorChar + "unpackaged";
            var saveGameName = ((TextBlock)SavegameListBox.SelectedItem).Uid;

            // check backup
            switch (IsBackedUp(saveGameName))
            {
            case BackupStatus.None:
                var dlgResult = MessageBox.Show(this, "The savegame is not backed up. Do you want to make a backup first?",
                                                "No backup found.", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Yes)
                {
                    BackupSavegame(saveGameName);
                }
                break;

            case BackupStatus.Current:
                break;

            case BackupStatus.Old:
                dlgResult = MessageBox.Show(this,
                                            "The backup seems to be old because it failed checksum validation. Do you want to make a new backup?",
                                            "Old backup found", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.Yes)
                {
                    BackupSavegame(saveGameName);
                }
                break;

            case BackupStatus.NoChecksum:
                dlgResult = MessageBox.Show(this,
                                            "The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
                                            "No checksum file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    break;
                }

            case BackupStatus.NoImage:
                dlgResult = MessageBox.Show(this,
                                            "The backup may be old because it does not have a checksum file. Do you want to make a new backup?",
                                            "No image file", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (dlgResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    break;
                }
            }

            var savegame = new Savegame(
                DirectoryTextBox.Text + DirectorySeparatorChar + saveGameName + DirectorySeparatorChar + saveGameName + ".lsv",
                unpackDir,
                (Game)GameEditionTextBlock.Tag);

            // unpack
            if (!UnpackSave(savegame))
            {
                return;
            }

            var se = new SaveEditor(savegame);

            se.ShowDialog();
        }