public IEnumerable <IResult> DoImportWorld() { string fileName = null; var platform = Platform.Invalid; foreach (var result in this.SaveLoad.OpenFile(s => fileName = s, p => platform = p)) { yield return(result); } if (fileName == null) { yield break; } SaveFile saveFile = null; yield return(new DelegateResult(() => { using (var input = File.OpenRead(fileName)) { saveFile = SaveFile.Deserialize(input, platform, DeserializeSettings.None); } }) .Rescue <DllNotFoundException>().Execute( x => new MyMessageBox($"Failed to load save: {x.Message}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()) .Rescue <FileFormats.SaveFormatException>().Execute( x => new MyMessageBox($"Failed to load save: {x.Message}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()) .Rescue <FileFormats.SaveCorruptionException>().Execute( x => new MyMessageBox($"Failed to load save: {x.Message}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()) .Rescue().Execute( x => new MyMessageBox( $"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine())); if (saveFile != null) { // TODO: deep copy? this.Shell.SaveFile.SaveGame.RegionGameStages = saveFile.SaveGame.RegionGameStages; this.Shell.SaveFile.SaveGame.WorldDiscoveryList = saveFile.SaveGame.WorldDiscoveryList; this.Shell.SaveFile.SaveGame.FullyExploredAreas = saveFile.SaveGame.FullyExploredAreas; yield return (new MyMessageBox("Import successful.") .WithButton(MessageBoxButton.OK) .WithIcon(MessageBoxImage.Information)); } }
private void WriteSave(string savePath, SaveFile saveFile) { this.General.ExportData(saveFile.SaveGame, out var platform); this.Character.ExportData(saveFile.SaveGame); this.Vehicle.ExportData(saveFile.SaveGame); this.CurrencyOnHand.ExportData(saveFile.SaveGame); this.Backpack.ExportData(saveFile.SaveGame, platform); this.Bank.ExportData(saveFile.SaveGame, platform); this.FastTravel.ExportData(saveFile.SaveGame); if (saveFile.SaveGame != null && saveFile.SaveGame.WeaponData != null) { saveFile.SaveGame.WeaponData.RemoveAll( wd => Blacklisting.IsBlacklistedType(wd.Type) == true || Blacklisting.IsBlacklistedBalance(wd.Balance) == true); } if (saveFile.SaveGame != null && saveFile.SaveGame.ItemData != null) { saveFile.SaveGame.ItemData.RemoveAll( wd => Blacklisting.IsBlacklistedType(wd.Type) == true || Blacklisting.IsBlacklistedBalance(wd.Balance) == true); } using (var output = File.Create(savePath)) { FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData( saveFile.SaveGame); saveFile.Platform = platform; saveFile.Serialize(output); FileFormats.SaveExpansion .ExtractExpansionSavedataFromUnloadableItemData( saveFile.SaveGame); } }
private void DoNewSaveFromPlayerClass(PlayerClassDefinition playerClass) { var saveFile = new SaveFile() { Platform = Platform.PC, SaveGame = new ProtoBufFormats.WillowTwoSave.WillowTwoPlayerSaveGame() { SaveGameId = 1, SaveGuid = (GameGuid)SystemGuid.NewGuid(), PlayerClass = playerClass.ResourcePath, UIPreferences = new ProtoBufFormats.WillowTwoSave.UIPreferencesData() { CharacterName = Encoding.UTF8.GetBytes(playerClass.Name), }, AppliedCustomizations = new List <string>() { "None", "", "", "", "None", }, }, }; FileFormats.SaveExpansion.ExtractExpansionSavedataFromUnloadableItemData(saveFile.SaveGame); this.General.ImportData(saveFile.SaveGame, saveFile.Platform); this.Character.ImportData(saveFile.SaveGame); this.Vehicle.ImportData(saveFile.SaveGame); this.CurrencyOnHand.ImportData(saveFile.SaveGame); this.Backpack.ImportData(saveFile.SaveGame, saveFile.Platform); this.Bank.ImportData(saveFile.SaveGame, saveFile.Platform); this.FastTravel.ImportData(saveFile.SaveGame); this.SavePath = null; this.SaveFile = saveFile; this.MaybeSwitchToGeneral(); }
public IEnumerable <IResult> ReadSave() { string fileName = null; var platform = Platform.Invalid; foreach (var result in this.SaveLoad.OpenFile(s => fileName = s, p => platform = p)) { yield return(result); } if (fileName == null) { yield break; } SaveFile saveFile = null; yield return(new DelegateResult( () => { using (var input = File.OpenRead(fileName)) { saveFile = SaveFile.Deserialize(input, platform, DeserializeSettings.None); } try { FileFormats.SaveExpansion.ExtractExpansionSavedataFromUnloadableItemData( saveFile.SaveGame); this.General.ImportData(saveFile.SaveGame, saveFile.Platform); this.Character.ImportData(saveFile.SaveGame); this.Vehicle.ImportData(saveFile.SaveGame); this.CurrencyOnHand.ImportData(saveFile.SaveGame); this.Backpack.ImportData(saveFile.SaveGame, saveFile.Platform); this.Bank.ImportData(saveFile.SaveGame, saveFile.Platform); this.FastTravel.ImportData(saveFile.SaveGame); this.SaveFile = saveFile; this.MaybeSwitchToGeneral(); } catch (Exception) { this.SaveFile = null; throw; } }) .Rescue <DllNotFoundException>().Execute( x => new MyMessageBox($"Failed to load save: {x.Message}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()) .Rescue <FileFormats.SaveFormatException>().Execute( x => new MyMessageBox($"Failed to load save: {x.Message}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()) .Rescue <FileFormats.SaveCorruptionException>().Execute( x => new MyMessageBox($"Failed to load save: {x.Message}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()) .Rescue().Execute( x => new MyMessageBox( $"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine())); if (saveFile != null && saveFile.SaveGame.IsBadassModeSaveGame == true) { saveFile.SaveGame.IsBadassModeSaveGame = false; yield return (new MyMessageBox( "Your save file was set as 'Badass Mode', and this has now been cleared.\n\n" + "See http://bit.ly/graveyardsav for more details.", "Information") .WithIcon(MessageBoxImage.Information)); } if (this.SaveFile != null && this.Backpack.BrokenWeapons.Count > 0) { var result = MessageBoxResult.No; do { yield return (new MyMessageBox( "There were weapons in the backpack that failed to load. Do you want to remove them?\n\n" + "If you choose not to remove them, they will remain in your save but will not be editable." + (result != MessageBoxResult.Cancel ? "\n\nChoose Cancel to copy error information to the clipboard." : ""), "Warning") .WithButton(result != MessageBoxResult.Cancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo) .WithDefaultResult(MessageBoxResult.No) .WithResultDo(r => result = r) .WithIcon(MessageBoxImage.Warning)); if (result == MessageBoxResult.Yes) { this.Backpack.BrokenWeapons.Clear(); } else if (result == MessageBoxResult.Cancel) { var sb = new StringBuilder(); this.Backpack.BrokenWeapons.ForEach(kv => { sb.AppendLine(kv.Value.ToString()); sb.AppendLine(); }); if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success) { MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }while (result == MessageBoxResult.Cancel); } if (this.SaveFile != null && this.Backpack.BrokenItems.Count > 0) { var result = MessageBoxResult.No; do { yield return (new MyMessageBox( "There were items in the backpack that failed to load. Do you want to remove them?\n\n" + "If you choose not to remove them, they will remain in your save but will not be editable." + (result != MessageBoxResult.Cancel ? "\n\nChoose Cancel to copy error information to the clipboard." : ""), "Warning") .WithButton(result != MessageBoxResult.Cancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo) .WithDefaultResult(MessageBoxResult.No) .WithResultDo(r => result = r) .WithIcon(MessageBoxImage.Warning)); if (result == MessageBoxResult.Yes) { this.Backpack.BrokenItems.Clear(); } else if (result == MessageBoxResult.Cancel) { var sb = new StringBuilder(); this.Backpack.BrokenItems.ForEach(kv => { sb.AppendLine(kv.Value.ToString()); sb.AppendLine(); }); if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success) { MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }while (result == MessageBoxResult.Cancel); } if (this.SaveFile != null && this.Bank.BrokenSlots.Count > 0) { var result = MessageBoxResult.No; do { yield return (new MyMessageBox( "There were weapons or items in the bank that failed to load. Do you want to remove them?\n\n" + "If you choose not to remove them, they will remain in your save but will not be editable." + (result != MessageBoxResult.Cancel ? "\n\nChoose Cancel to copy error information to the clipboard." : ""), "Warning") .WithButton(result != MessageBoxResult.Cancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo) .WithDefaultResult(MessageBoxResult.No) .WithResultDo(r => result = r) .WithIcon(MessageBoxImage.Warning)); if (result == MessageBoxResult.Yes) { this.Bank.BrokenSlots.Clear(); } else if (result == MessageBoxResult.Cancel) { var sb = new StringBuilder(); this.Bank.BrokenSlots.ForEach(kv => { sb.AppendLine(kv.Value.ToString()); sb.AppendLine(); }); if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success) { MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }while (result == MessageBoxResult.Cancel); } }