From 15afd6f3bc8d24504b70da1a3b315c0ef7f5f7e4 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 22 May 2021 09:28:04 -0700 Subject: [PATCH] Move mail get to sav obj --- PKHeX.Core/Saves/SAV3.cs | 7 +++++ PKHeX.Core/Saves/SAV4.cs | 6 +++++ PKHeX.Core/Saves/SAV5.cs | 7 +++++ .../Subforms/Save Editors/SAV_MailBox.cs | 27 ++++++------------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/PKHeX.Core/Saves/SAV3.cs b/PKHeX.Core/Saves/SAV3.cs index 58dbc3a42..a7ba83335 100644 --- a/PKHeX.Core/Saves/SAV3.cs +++ b/PKHeX.Core/Saves/SAV3.cs @@ -562,6 +562,13 @@ namespace PKHeX.Core protected abstract int MailOffset { get; } public int GetMailOffset(int index) => (index * Mail3.SIZE) + MailOffset; + public Mail GetMail(int i) + { + var ofs = GetMailOffset(i); + var data = Large.Slice(ofs, Mail3.SIZE); + return new Mail3(data, ofs, Japanese); + } + public abstract string EBerryName { get; } public abstract bool IsEBerryEngima { get; } public abstract MysteryEvent3 MysteryEvent { get; set; } diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index 95e277466..4425b765b 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -544,5 +544,11 @@ namespace PKHeX.Core } public byte[] GetMailData(int ofs) => General.Slice(ofs, Mail4.SIZE); + + public Mail4 GetMail(int i) + { + int ofs = GetMailOffset(i); + return new Mail4(GetMailData(ofs), ofs); + } } } diff --git a/PKHeX.Core/Saves/SAV5.cs b/PKHeX.Core/Saves/SAV5.cs index 73fd511e5..7c3fa5670 100644 --- a/PKHeX.Core/Saves/SAV5.cs +++ b/PKHeX.Core/Saves/SAV5.cs @@ -207,5 +207,12 @@ namespace PKHeX.Core public static int GetMailOffset(int index) => (index * Mail5.SIZE) + 0x1DD00; public byte[] GetMailData(int offset) => GetData(offset, Mail5.SIZE); public int GetBattleBoxSlot(int slot) => BattleBoxOffset + (slot * SIZE_STORED); + + public Mail GetMail(int i) + { + int ofs = GetMailOffset(i); + var data = GetMailData(ofs); + return new Mail5(data, ofs); + } } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs index f27ba8220..ad426d5ae 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs @@ -68,13 +68,9 @@ namespace PKHeX.WinForms case SAV3 sav3: m = new Mail3[6 + 10]; for (int i = 0; i < m.Length; i++) - { - var ofs = sav3.GetMailOffset(i); - var data = sav3.Large.Slice(ofs, Mail3.SIZE); - m[i] = new Mail3(data, ofs, sav3.Japanese); - } + m[i] = sav3.GetMail(i); - MailItemID = Enumerable.Range(0x79, 12).ToArray(); + MailItemID = new[] {121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132}; PartyBoxCount = 6; break; case SAV4 sav4: @@ -82,14 +78,11 @@ namespace PKHeX.WinForms for (int i = 0; i < p.Count; i++) m[i] = new Mail4(((PK4)p[i]).GetHeldMailData()); for (int i = p.Count, j = 0; i < m.Length; i++, j++) - { - int ofs = sav4.GetMailOffset(j); - m[i] = new Mail4(sav4.GetMailData(ofs), ofs); - } - var l4 = (Mail4)m.Last(); + m[i] = sav4.GetMail(j); + var l4 = (Mail4)m[^1]; ResetVer = l4.AuthorVersion; ResetLang = l4.AuthorLanguage; - MailItemID = Enumerable.Range(0x89, 12).ToArray(); + MailItemID = new[] {137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148}; PartyBoxCount = p.Count; break; case SAV5 sav5: @@ -97,15 +90,11 @@ namespace PKHeX.WinForms for (int i = 0; i < p.Count; i++) m[i] = new Mail5(((PK5)p[i]).GetHeldMailData()); for (int i = p.Count, j = 0; i < m.Length; i++, j++) - { - int ofs = SAV5.GetMailOffset(j); - var data = sav5.GetMailData(ofs); - m[i] = new Mail5(data, ofs); - } - var l5 = (Mail5)m.Last(); + m[i] = sav5.GetMail(j); + var l5 = (Mail5)m[^1]; ResetVer = l5.AuthorVersion; ResetLang = l5.AuthorLanguage; - MailItemID = Enumerable.Range(0x89, 12).ToArray(); + MailItemID = new[] {137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148}; PartyBoxCount = p.Count; break; }