public IEnumerable <IResult> OpenFile(Action <string> fileNameAction, Action <Platform> platformAction) { fileNameAction(null); platformAction(Platform.Invalid); string fileName = null; int filterIndex = -1; var ofr = new MyOpenFileResult() .FilterFiles( ffc => ffc.AddFilter("sav", this._FilterIndex == 1) .WithDescription("PC Save Files") .AddFilter("sav", this._FilterIndex == 2) .WithDescription("Xbox 360 Save Files") .AddFilter("sav", this._FilterIndex == 3) .WithDescription("PlayStation 3 Save Files") .AddFilter("sav", this._FilterIndex == 4) .WithDescription("PlayStation Vita Save Files") .AddFilter("sav", this._FilterIndex == 5) .WithDescription("NVIDIA SHIELD Save Files") .AddFilter("sav", this._FilterIndex == 6) .WithDescription("Nintendo Switch Save Files")) .WithFileDo(s => fileName = s) .WithFilterIndexDo(i => filterIndex = i); if (string.IsNullOrEmpty(this._SavePath) == false && Directory.Exists(this._SavePath) == true) { ofr = ofr.In(this._SavePath); } yield return(ofr); if (fileName == null) { yield break; } this._FilterIndex = filterIndex; var platforms = new[] { Platform.Invalid, Platform.PC, Platform.X360, Platform.PS3, Platform.PSVita, Platform.Shield, Platform.Switch, }; fileNameAction(fileName); platformAction(filterIndex < 1 || filterIndex > 6 ? Platform.PC : platforms[filterIndex]); }
public IEnumerable<IResult> ReadSave() { string fileName = null; MyOpenFileResult ofr; ofr = new MyOpenFileResult() .FilterFiles( ffc => ffc.AddFilter("sav", true) .WithDescription("Borderlands 2 Save Files") .AddAllFilesFilter()) .WithFileDo(s => fileName = s); if (string.IsNullOrEmpty(this._SavePath) == false && Directory.Exists(this._SavePath) == true) { ofr = ofr.In(this._SavePath); } yield return ofr; if (fileName == null) { yield break; } /////////////////////////////////////////// //SPITFIRE1337 MODS /////////////////////////////////////////// string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //using (FileStream fs = File.Create(path)) { } File.Delete(path + "/mytempsave.sav"); File.Delete(path + "/savegame.sav"); File.Copy(fileName, path + "/mytempsave.sav"); string profileid = ""; string deviceid = ""; string consoleid = ""; Stream input1 = new FileStream(fileName, FileMode.Open); // Ensure that the target does not exist. //Stream input = new Stream(fs); var check = input1.ReadValueU32(Endian.Big); input1.Close(); if (check == 0x434F4E20) { //MessageBox.Show("This is a xbox save"); yield return new DelegateResult(() => { DJsIO io = new DJsIO(fileName, DJFileMode.Open, true); io.Position = 0x371; profileid = io.ReadHexString(8); //Profile ID io.Close(); }) .Rescue().Execute( x => new MyMessageBox("An exception was thrown (press Ctrl+C to copy):\n\n" + x.ToString(), "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine()); STFSPackage xPackage = new STFSPackage(fileName, null); FileEntry xent = (FileEntry)xPackage.GetFile("savegame.sav"); if (!xent.Extract(path + "/savegame.sav")) { //MessageBoxEx.Show("Extraction Failed!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.[Error]) //xboxextract.ReportProgress(200, "Extraction Failed"); //Thread.Sleep(2000); //Return MessageBox.Show("Could not extract savegame.sav. Please use a program like modio or horizon to extract your savegame.sav"); } else { fileName = path + "/savegame.sav"; //MessageBox.Show("File extracted"); //Thread.Sleep(2000); //MessageBoxEx.Show("Extraction Complete!", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information) } } else { profileid = "0"; deviceid = "0"; consoleid = "0"; } yield return new DelegateResult(() => { FileFormats.SaveFile saveFile; using (var input = File.OpenRead(fileName)) { saveFile = FileFormats.SaveFile.Deserialize(input, FileFormats.SaveFile.DeserializeSettings.None); } this.SaveFile = saveFile; this.General.ImportData(saveFile.SaveGame, saveFile.Endian, profileid, deviceid, consoleid); this.CurrencyOnHand.ImportData(saveFile.SaveGame); this.Backpack.ImportData(saveFile.SaveGame); this.Bank.ImportData(saveFile.SaveGame); }) .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()); /////////////////////////////////////////// //END SPITFIRE1337 MODS /////////////////////////////////////////// }
public IEnumerable <IResult> ReadSave() { string fileName = null; MyOpenFileResult ofr; ofr = new MyOpenFileResult() .FilterFiles( ffc => ffc.AddFilter("sav", true) .WithDescription("Borderlands 2 Save Files") .AddAllFilesFilter()) .WithFileDo(s => fileName = s); if (string.IsNullOrEmpty(this._SavePath) == false && Directory.Exists(this._SavePath) == true) { ofr = ofr.In(this._SavePath); } yield return(ofr); if (fileName == null) { yield break; } /////////////////////////////////////////// //SPITFIRE1337 MODS /////////////////////////////////////////// string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //using (FileStream fs = File.Create(path)) { } File.Delete(path + "/mytempsave.sav"); File.Delete(path + "/savegame.sav"); File.Copy(fileName, path + "/mytempsave.sav"); string profileid = ""; string deviceid = ""; string consoleid = ""; Stream input1 = new FileStream(fileName, FileMode.Open); // Ensure that the target does not exist. //Stream input = new Stream(fs); var check = input1.ReadValueU32(Endian.Big); input1.Close(); if (check == 0x434F4E20) { //MessageBox.Show("This is a xbox save"); yield return(new DelegateResult(() => { DJsIO io = new DJsIO(fileName, DJFileMode.Open, true); io.Position = 0x371; profileid = io.ReadHexString(8); //Profile ID io.Close(); }) .Rescue().Execute( x => new MyMessageBox("An exception was thrown (press Ctrl+C to copy):\n\n" + x.ToString(), "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine())); STFSPackage xPackage = new STFSPackage(fileName, null); FileEntry xent = (FileEntry)xPackage.GetFile("savegame.sav"); if (!xent.Extract(path + "/savegame.sav")) { //MessageBoxEx.Show("Extraction Failed!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.[Error]) //xboxextract.ReportProgress(200, "Extraction Failed"); //Thread.Sleep(2000); //Return MessageBox.Show("Could not extract savegame.sav. Please use a program like modio or horizon to extract your savegame.sav"); } else { fileName = path + "/savegame.sav"; //MessageBox.Show("File extracted"); //Thread.Sleep(2000); //MessageBoxEx.Show("Extraction Complete!", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information) } } else { profileid = "0"; deviceid = "0"; consoleid = "0"; } yield return(new DelegateResult(() => { FileFormats.SaveFile saveFile; using (var input = File.OpenRead(fileName)) { saveFile = FileFormats.SaveFile.Deserialize(input, FileFormats.SaveFile.DeserializeSettings.None); } this.SaveFile = saveFile; this.General.ImportData(saveFile.SaveGame, saveFile.Endian, profileid, deviceid, consoleid); this.CurrencyOnHand.ImportData(saveFile.SaveGame); this.Backpack.ImportData(saveFile.SaveGame); this.Bank.ImportData(saveFile.SaveGame); }) .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())); /////////////////////////////////////////// //END SPITFIRE1337 MODS /////////////////////////////////////////// }