diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index e639cf96c..1b19a2eb3 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -871,7 +871,7 @@ namespace PKHeX.Core result[0] = "Missing Ribbons: " + string.Join(", ", missingRibbons); if (invalidRibbons.Count > 0) result[1] = "Invalid Ribbons: " + string.Join(", ", invalidRibbons); - AddLine(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s=>!string.IsNullOrEmpty(s))), CheckIdentifier.Ribbon); + AddLine(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s => !string.IsNullOrEmpty(s))), CheckIdentifier.Ribbon); } private void verifyAbility() { @@ -2143,7 +2143,7 @@ namespace PKHeX.Core else reqBase = baseCt; - if (pkm.RelearnMoves.Where(m=>m != 0).Count() < Math.Min(4, baseMoves.Count)) + if (pkm.RelearnMoves.Where(m => m != 0).Count() < Math.Min(4, baseMoves.Count)) reqBase = Math.Min(4, unique); // Movepool finalized! Check validity. diff --git a/PKHeX/Legality/Data.cs b/PKHeX/Legality/Data.cs index a8522d078..f07fbd97a 100644 --- a/PKHeX/Legality/Data.cs +++ b/PKHeX/Legality/Data.cs @@ -1,5 +1,4 @@ using System; -using System.IO; namespace PKHeX.Core { @@ -10,41 +9,22 @@ namespace PKHeX.Core if (fileData == null || fileData.Length < 4) return null; - using (var s = new MemoryStream(fileData)) - using (var br = new BinaryReader(s)) + if (identifier[0] != fileData[0] || identifier[1] != fileData[1]) + return null; + + int count = BitConverter.ToUInt16(fileData, 2); int ctr = 4; + int start = BitConverter.ToInt32(fileData, ctr); ctr += 4; + byte[][] returnData = new byte[count][]; + for (int i = 0; i < count; i++) { - if (identifier != new string(br.ReadChars(2))) - return null; - - ushort count = br.ReadUInt16(); - byte[][] returnData = new byte[count][]; - - uint[] offsets = new uint[count + 1]; - for (int i = 0; i < count; i++) - offsets[i] = br.ReadUInt32(); - - uint length = br.ReadUInt32(); - offsets[offsets.Length - 1] = length; - - for (int i = 0; i < count; i++) - { - br.BaseStream.Seek(offsets[i], SeekOrigin.Begin); - using (MemoryStream dataout = new MemoryStream()) - { - byte[] data = new byte[0]; - s.CopyTo(dataout, (int)offsets[i]); - int len = (int)offsets[i + 1] - (int)offsets[i]; - - if (len != 0) - { - data = dataout.ToArray(); - Array.Resize(ref data, len); - } - returnData[i] = data; - } - } - return returnData; + int end = BitConverter.ToInt32(fileData, ctr); ctr += 4; + int len = end - start; + byte[] data = new byte[len]; + Buffer.BlockCopy(fileData, start, data, 0, len); + returnData[i] = data; + start = end; } + return returnData; } } } diff --git a/PKHeX/Legality/Tables1.cs b/PKHeX/Legality/Tables1.cs index 7a72c10ea..58028f8d0 100644 --- a/PKHeX/Legality/Tables1.cs +++ b/PKHeX/Legality/Tables1.cs @@ -183,7 +183,7 @@ namespace PKHeX.Core internal static readonly int[] FutureEvolutionsGen1_Gen2LevelUp = { - 169,196,197,242 + 169,196,197,242 }; //Crobat Espeon Umbreon Blissey } diff --git a/PKHeX/Legality/Tables3.cs b/PKHeX/Legality/Tables3.cs index b88dba389..ac1ccbed4 100644 --- a/PKHeX/Legality/Tables3.cs +++ b/PKHeX/Legality/Tables3.cs @@ -99,5 +99,6 @@ namespace PKHeX.Core // todo }; internal static readonly bool[] ReleasedHeldItems_3 = Enumerable.Range(0, MaxItemID_3+1).Select(i => HeldItems_RS.Contains((ushort)i) && !UnreleasedItems_3.Contains(i)).ToArray(); + internal static readonly int[] HM_3 = {15, 19, 57, 70, 148, 249, 127, 291}; } } diff --git a/PKHeX/Legality/Tables4.cs b/PKHeX/Legality/Tables4.cs index 8635fe473..5c22a0c3e 100644 --- a/PKHeX/Legality/Tables4.cs +++ b/PKHeX/Legality/Tables4.cs @@ -140,5 +140,6 @@ namespace PKHeX.Core // todo }; internal static readonly bool[] ReleasedHeldItems_4 = Enumerable.Range(0, MaxItemID_4_HGSS+1).Select(i => HeldItems_HGSS.Contains((ushort)i) && !UnreleasedItems_4.Contains(i)).ToArray(); + internal static readonly int[] CrownBeasts = {251, 243, 244, 245}; } } diff --git a/PKHeX/PKM/PK3.cs b/PKHeX/PKM/PK3.cs index bf565b4f9..c4f1cf2de 100644 --- a/PKHeX/PKM/PK3.cs +++ b/PKHeX/PKM/PK3.cs @@ -298,10 +298,9 @@ namespace PKHeX.Core } // Remove HM moves - int[] banned = { 15, 19, 57, 70, 148, 249, 127, 291 }; int[] newMoves = pk4.Moves; for (int i = 0; i < 4; i++) - if (banned.Contains(newMoves[i])) + if (Legal.HM_3.Contains(newMoves[i])) newMoves[i] = 0; pk4.Moves = newMoves; pk4.FixMoves(); diff --git a/PKHeX/PKM/PK4.cs b/PKHeX/PKM/PK4.cs index b69f5c010..3a3343e22 100644 --- a/PKHeX/PKM/PK4.cs +++ b/PKHeX/PKM/PK4.cs @@ -443,8 +443,6 @@ namespace PKHeX.Core // Apply new met date MetDate = moment }; - if (Legal.HeldItems_BW.Contains((ushort) HeldItem)) - pk5.HeldItem = HeldItem; // Arceus Type Changing -- Plate forcibly removed. if (pk5.Species == 493) @@ -452,6 +450,10 @@ namespace PKHeX.Core pk5.AltForm = 0; pk5.HeldItem = 0; } + else + { + pk5.HeldItem = Legal.HeldItems_BW.Contains((ushort) HeldItem) ? HeldItem : 0; + } // Fix PP pk5.Move1_PP = pk5.getMovePP(pk5.Move1, pk5.Move1_PPUps); @@ -459,14 +461,14 @@ namespace PKHeX.Core pk5.Move3_PP = pk5.getMovePP(pk5.Move3, pk5.Move3_PPUps); pk5.Move4_PP = pk5.getMovePP(pk5.Move4, pk5.Move4_PPUps); - // Disassociate Nature and PID - pk5.Nature = (int)(pk5.PID % 25); + // Disassociate Nature and PID, pk4 getter does PID%25 + pk5.Nature = Nature; // Delete Platinum/HGSS Met Location Data BitConverter.GetBytes((uint)0).CopyTo(pk5.Data, 0x44); // Met / Crown Data Detection - pk5.Met_Location = pk5.Gen4 && pk5.FatefulEncounter && Array.IndexOf(new[] {251, 243, 244, 245}, pk5.Species) >= 0 + pk5.Met_Location = pk5.Gen4 && pk5.FatefulEncounter && Array.IndexOf(Legal.CrownBeasts, pk5.Species) >= 0 ? (pk5.Species == 251 ? 30010 : 30012) // Celebi : Beast : 30001; // Pokétransfer (not Crown)