From 3d7b2a2b29664428d53d8ef4e337f35e172a1eae Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 4 Dec 2017 16:26:26 -0800 Subject: [PATCH] Misc tweaks RNG frame mismatch -> fishy (for now) fix xmldoc copypaste clean up some resharper warnings --- .../Legality/Encounters/EncounterFinder.cs | 2 +- .../Legality/Encounters/EncounterGenerator.cs | 1 - PKHeX.Core/Saves/SAV4.cs | 3 +-- PKHeX.Core/Saves/SaveUtil.cs | 2 +- PKHeX.Core/Saves/Substructures/Mail/Mail3.cs | 10 +++++++--- PKHeX.Core/Saves/Substructures/Mail/Mail4.cs | 18 +++++++++++------- PKHeX.Core/Saves/Substructures/Mail/Mail5.cs | 18 +++++++++++------- .../Subforms/Save Editors/Gen4/SAV_Misc4.cs | 16 ++++++++-------- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterFinder.cs b/PKHeX.Core/Legality/Encounters/EncounterFinder.cs index 1c1fe76bd..544de7775 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterFinder.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterFinder.cs @@ -47,7 +47,7 @@ public static LegalInfo FindVerifiedEncounter(PKM pkm) } if (!info.FrameMatches && info.EncounterMatch is EncounterSlot && pkm.Version != (int)GameVersion.CXD) // if false, all valid RNG frame matches have already been consumed - info.Parse.Add(new CheckResult(Severity.Invalid, V400, CheckIdentifier.PID)); + info.Parse.Add(new CheckResult(Severity.Fishy, V400, CheckIdentifier.PID)); // todo for further confirmation if (!info.PIDIVMatches) // if false, all valid PIDIV matches have already been consumed info.Parse.Add(new CheckResult(Severity.Invalid, V411, CheckIdentifier.PID)); diff --git a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs index cb1549848..207b5c85c 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs @@ -1397,7 +1397,6 @@ private static bool GetIsMatchWC7(PKM pkm, WC7 wc, IEnumerable vs) return true; } - // EncounterEgg private static IEnumerable GenerateEggs(PKM pkm) { diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index 950f2bfb6..51ff567af 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -132,9 +132,8 @@ public override string ChecksumInfo private int storageBlock = -1; // Big Block private int hofBlock = -1; // Hall of Fame Block private int SBO => 0x40000 * storageBlock; - private int GBO => 0x40000 * generalBlock; + public int GBO => 0x40000 * generalBlock; private int HBO => 0x40000 * hofBlock; - public int GetGBO => GBO; private void GetActiveGeneralBlock() { if (Version < 0) diff --git a/PKHeX.Core/Saves/SaveUtil.cs b/PKHeX.Core/Saves/SaveUtil.cs index 200e79e45..7f06bcb3e 100644 --- a/PKHeX.Core/Saves/SaveUtil.cs +++ b/PKHeX.Core/Saves/SaveUtil.cs @@ -647,7 +647,7 @@ public static ushort CRC16(byte[] data, int start, int length, ushort initial = chk = (ushort) (crc16[(data[i] ^ chk) & 0xFF] ^ chk >> 8); return (ushort)~chk; } - /// Calculates the 32bit checksum over an input byte array. Used in GBA save files. + /// Calculates the 16bit checksum over an input byte array. Used in Gen7 save files. /// Input byte array /// Initial value for checksum /// Checksum diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs index 140f9605f..863c8fde5 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs @@ -10,12 +10,16 @@ public class Mail3 : Mail public Mail3(SAV3 sav, int index) { DataOffset = index * SIZE + sav.GetBlockOffset(3) + 0xCE0; - Data = sav.GetData(DataOffset, 0x24); + Data = sav.GetData(DataOffset, SIZE); } public Mail3() { - Data = new byte[0x24]; + Data = new byte[SIZE]; DataOffset = -1; + ResetData(); + } + private void ResetData() + { for (int y = 0; y < 3; y++) for (int x = 0; x < 3; x++) SetMessage(y, x, 0xFFFF); @@ -37,7 +41,7 @@ public override string AuthorName else { Data[0x18] = Data[0x19] = 0xFF; - StringConverter.SetString3(value, 7, false, 6, 0).CopyTo(Data, 0x12); + StringConverter.SetString3(value, 7, false, 6).CopyTo(Data, 0x12); } } } diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs index e3b7c0151..42df7bb59 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs @@ -10,9 +10,9 @@ public Mail4(SAV4 sav, int index) { switch (sav.Version) { - case GameVersion.DP: DataOffset = index * SIZE + 0x4BEC + sav.GetGBO; break; - case GameVersion.Pt: DataOffset = index * SIZE + 0x4E80 + sav.GetGBO; break; - case GameVersion.HGSS: DataOffset = index * SIZE + 0x3FA8 + sav.GetGBO; break; + case GameVersion.DP: DataOffset = index * SIZE + 0x4BEC + sav.GBO; break; + case GameVersion.Pt: DataOffset = index * SIZE + 0x4E80 + sav.GBO; break; + case GameVersion.HGSS: DataOffset = index * SIZE + 0x3FA8 + sav.GBO; break; } Data = sav.GetData(DataOffset, SIZE); } @@ -25,11 +25,15 @@ public Mail4(byte? lang = null, byte? ver = null) { Data = new byte[SIZE]; DataOffset = -1; + if (lang != null) AuthorLanguage = (byte)lang; + if (ver != null) AuthorVersion = (byte)ver; + ResetData(); + } + private void ResetData() + { AuthorTID = 0; AuthorSID = 0; AuthorGender = 0; - if (lang != null) AuthorLanguage = (byte)lang; - if (ver != null) AuthorVersion = (byte)ver; MailType = 0xFF; AuthorName = ""; for (int i = 0; i < 3; i++) @@ -59,7 +63,7 @@ public Mail4(byte? lang = null, byte? ver = null) return null; } } - public override void SetBlank() => SetBlank(); - public void SetBlank(byte? lang = null, byte? ver = null) => (new Mail4(lang: lang, ver: ver)).Data.CopyTo(Data, 0); + public override void SetBlank() => SetBlank(null, null); + public void SetBlank(byte? lang, byte? ver) => new Mail4(lang: lang, ver: ver).Data.CopyTo(Data, 0); } } \ No newline at end of file diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs index 27a1dfd76..7c56d8054 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs @@ -20,19 +20,23 @@ public Mail5(byte? lang = null, byte? ver = null) { Data = new byte[SIZE]; DataOffset = -1; + if (lang != null) AuthorLanguage = (byte)lang; + if (ver != null) AuthorVersion = (byte)ver; + ResetData(); + } + private void ResetData() + { AuthorTID = 0; AuthorSID = 0; AuthorGender = 0; - if (lang != null) AuthorLanguage = (byte)lang; - if (ver != null) AuthorVersion = (byte)ver; MailType = 0xFF; AuthorName = ""; for (int i = 0; i < 3; i++) SetMisc(i, 0); MessageEnding = 0xFFFF; for (int y = 0; y < 3; y++) - for (int x = 0; x < 4; x++) - SetMessage(y, x, (ushort)(x == 1 ? 0 : 0xFFFF)); + for (int x = 0; x < 4; x++) + SetMessage(y, x, (ushort)(x == 1 ? 0 : 0xFFFF)); } public override void CopyTo(PK5 pk5) => pk5.HeldMailData = Data; public override ushort AuthorTID { get => BitConverter.ToUInt16(Data, 0); set => BitConverter.GetBytes(value).CopyTo(Data, 0); } @@ -41,7 +45,7 @@ public Mail5(byte? lang = null, byte? ver = null) public byte AuthorLanguage { get => Data[5]; set => Data[5] = value; } public byte AuthorVersion { get => Data[6]; set => Data[6] = value; } public override int MailType { get => Data[7]; set => Data[7] = (byte)value; } - public override string AuthorName { get => StringConverter.GetString5(Data, 8, 0x10); set => StringConverter.SetString5(value, 7, 8, 0).CopyTo(Data, 8); } + public override string AuthorName { get => StringConverter.GetString5(Data, 8, 0x10); set => StringConverter.SetString5(value, 7, 8).CopyTo(Data, 8); } public int GetMisc(int index) => BitConverter.ToUInt16(Data, 0x1C - index * 2); public void SetMisc(int index, int value) => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1C - index * 2); public ushort MessageEnding { get => BitConverter.ToUInt16(Data, 0x1E); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1E); } @@ -56,7 +60,7 @@ public Mail5(byte? lang = null, byte? ver = null) return null; } } - public override void SetBlank() => SetBlank(); - public void SetBlank(byte? lang = null, byte? ver = null) => (new Mail5(lang: lang, ver: ver)).Data.CopyTo(Data, 0); + public override void SetBlank() => SetBlank(null, null); + public void SetBlank(byte? lang, byte? ver) => new Mail5(lang: lang, ver: ver).Data.CopyTo(Data, 0); } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs index 7b1f2f232..520e9e255 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs @@ -18,7 +18,7 @@ public SAV_Misc4(SaveFile sav) SAV = (SAV4)(Origin = sav).Clone(); InitializeComponent(); - int GBO = SAV.GetGBO; + int GBO = SAV.GBO; switch (SAV.Version) { case GameVersion.D: @@ -573,8 +573,8 @@ private void StatAddrControl(int SetValToSav = -2, bool SetSavToVal = false) int Facility = CB_Stats1.SelectedIndex; int BattleType = CB_Stats2.SelectedIndex; int RBi = StatRBA[1].Checked ? 1 : 0; - int addrVal = SAV.GetGBO + BFF[Facility][2] + BFF[Facility][3] * BattleType + (RBi << 3); - int addrFlag = SAV.GetGBO + BFF[Facility][4]; + int addrVal = SAV.GBO + BFF[Facility][2] + BFF[Facility][3] * BattleType + (RBi << 3); + int addrFlag = SAV.GBO + BFF[Facility][4]; byte maskFlag = (byte)(1 << BattleType + (RBi << 2)); int TowerContinueCountOfs = SAV.DP ? 3 : 1; @@ -657,7 +657,7 @@ private void ChangeSpecies(object sender, EventArgs e) } private void GetCastleStat() { - int ofs = SAV.GetGBO + BFF[3][2] + BFF[3][3] * CB_Stats2.SelectedIndex + 0x0A; + int ofs = SAV.GBO + BFF[3][2] + BFF[3][3] * CB_Stats2.SelectedIndex + 0x0A; NumericUpDown[] na = { NUD_CastleRankRcv, NUD_CastleRankItem, NUD_CastleRankInfo }; for (int i = 0; i < na.Length; i++) { @@ -671,11 +671,11 @@ private void NUD_CastleRank_ValueChanged(object sender, EventArgs e) NumericUpDown[] na = new[] { NUD_CastleRankRcv, NUD_CastleRankItem, NUD_CastleRankInfo }; int i = Array.IndexOf(na, sender); if (i < 0) return; - BitConverter.GetBytes((int)na[i].Value).CopyTo(SAV.Data, SAV.GetGBO + BFF[3][2] + BFF[3][3] * CB_Stats2.SelectedIndex + 0x0A + (i << 1)); + BitConverter.GetBytes((int)na[i].Value).CopyTo(SAV.Data, SAV.GBO + BFF[3][2] + BFF[3][3] * CB_Stats2.SelectedIndex + 0x0A + (i << 1)); } private void GetHallStat() { - int ofscur = SAV.GetGBO + BFF[2][2] + BFF[2][3] * CB_Stats2.SelectedIndex; + int ofscur = SAV.GBO + BFF[2][2] + BFF[2][3] * CB_Stats2.SelectedIndex; int curspe = BitConverter.ToInt16(SAV.Data, ofscur + 4); bool c = curspe == species; CHK_HallCurrent.Checked = c; @@ -703,7 +703,7 @@ private void GetHallStat() private void CHK_HallCurrent_CheckedChanged(object sender, EventArgs e) { if (editing) return; - BitConverter.GetBytes((ushort)(CHK_HallCurrent.Checked ? species : 0)).CopyTo(SAV.Data, SAV.GetGBO + BFF[2][2] + BFF[2][3] * CB_Stats2.SelectedIndex + 4); + BitConverter.GetBytes((ushort)(CHK_HallCurrent.Checked ? species : 0)).CopyTo(SAV.Data, SAV.GBO + BFF[2][2] + BFF[2][3] * CB_Stats2.SelectedIndex + 4); editing = true; GetHallStat(); editing = false; @@ -714,7 +714,7 @@ private void NUD_HallType_ValueChanged(object sender, EventArgs e) if (editing) return; int i = Array.IndexOf(HallNUDA, sender); if (i < 0) return; - int ofs = SAV.GetGBO + BFF[2][2] + BFF[2][3] * CB_Stats2.SelectedIndex + 6 + (i >> 1 << 1); + int ofs = SAV.GBO + BFF[2][2] + BFF[2][3] * CB_Stats2.SelectedIndex + 6 + (i >> 1 << 1); SAV.Data[ofs] = (byte)(SAV.Data[ofs] & ~(0xF << ((i & 1) << 2)) | (int)HallNUDA[i].Value << ((i & 1) << 2)); L_SumHall.Text = HallNUDA.Sum(x => x.Value).ToString(); }