diff --git a/Misc/SAV6.cs b/Misc/SAV6.cs index 371e3b8ea..23104eec5 100644 --- a/Misc/SAV6.cs +++ b/Misc/SAV6.cs @@ -516,6 +516,8 @@ public bool DaycareOccupied2 public byte[] getWondercard(int i) { return Data.Skip(WondercardData + i*WC6.Size).Take(WC6.Size).ToArray(); } public void setWondercard(int i, byte[] data) { data.CopyTo(data, WondercardData + i * WC6.Size); } + public string JPEGTitle => JPEG > -1 ? null : Util.TrimFromZero(Encoding.Unicode.GetString(Data, JPEG, 0x1A)); + public byte[] JPEGData => JPEG > -1 || Data[JPEG + 0x54] != 0xFF ? null : Data.Skip(JPEG + 0x54).Take(0xE004).ToArray(); // Data Accessing public byte[] getData(int Offset, int Length) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 7caa4e620..1d898c99f 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -3278,29 +3278,13 @@ private void B_OpenSecretBase_Click(object sender, EventArgs e) } private void B_JPEG_Click(object sender, EventArgs e) { - int offset = SAV.JPEG; - string filename = Encoding.Unicode.GetString(SAV.Data, offset, 0x1A).Trim(); - filename += "'s picture"; - offset += 0x54; - if (SAV.Data[offset] != 0xFF) - { - Util.Alert("No PGL picture data found in the save file!"); - return; - } - const int length = 0xE004; - - byte[] jpeg = new byte[length]; - Array.Copy(SAV.Data, offset, jpeg, 0, length); - SaveFileDialog savejpeg = new SaveFileDialog {FileName = filename, Filter = "JPEG|*.jpeg"}; - if (savejpeg.ShowDialog() != DialogResult.OK) return; - string path = savejpeg.FileName; - if (File.Exists(path)) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - File.WriteAllBytes(path, jpeg); + byte[] jpeg = SAV.JPEGData; + if (SAV.JPEGData == null) + { Util.Alert("No PGL picture data found in the save file!"); return; } + string filename = SAV.JPEGTitle + "'s picture"; + SaveFileDialog sfd = new SaveFileDialog {FileName = filename, Filter = "JPEG|*.jpeg"}; + if (sfd.ShowDialog() != DialogResult.OK) return; + File.WriteAllBytes(sfd.FileName, jpeg); } // Save Folder Related private void clickSaveFileName(object sender, EventArgs e)