From 337f58504e7dd01f81313b45a18bd85b042b9fd9 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 3 Oct 2016 22:24:03 -0700 Subject: [PATCH] Fix Gen II Held Item bug, Gen II JP<->EN bugs, many Gen I<->Gen II conversion bugs. --- PKHeX/MainWindow/Main.cs | 24 +++++++++++++++++------- PKHeX/PKM/PK2.cs | 2 +- PKHeX/PKM/PKMConverter.cs | 12 ++++++------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 8f5e0a741..8d87644a9 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -676,8 +676,8 @@ private void openFile(byte[] input, string path, string ext) PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); if (pk == null) Util.Alert("Conversion failed.", c); - else if (SAV.Generation == 1 && ((PK1) pk).Japanese != SAV.GetJapanese) - Util.Alert($"Cannot load {(SAV.GetJapanese ? "an International" : "a Japanese")} PK1 in {(SAV.GetJapanese ? "a Japanese" : "an International")} save file."); + else if (SAV.Generation < 3 && (pk is PK1 ? ((PK1)pk).Japanese : ((PK2)pk).Japanese) != SAV.GetJapanese) + Util.Alert($"Cannot load {(SAV.GetJapanese ? "an International" : "a Japanese")} {pk.GetType().Name} in {(SAV.GetJapanese ? "a Japanese" : "an International")} save file."); else populateFields(pk); Console.WriteLine(c); @@ -1130,6 +1130,8 @@ private void loadSAV(SaveFile sav, string path) bool init = fieldsInitialized; fieldsInitialized = fieldsLoaded = false; pkm = pkm.GetType() != SAV.PKMType ? SAV.BlankPKM : pk; + if (pkm.Format < 3) + pkm = SAV.BlankPKM; populateFilteredDataSources(); populateFields(pkm); fieldsInitialized |= init; @@ -2896,14 +2898,22 @@ public static string[] verifyPKMtoSAV(PKM pk) List errata = new List(); if (SAV.Generation > 1) { - if (pk.HeldItem > itemlist.Length) - errata.Add($"Item Index beyond range: {pk.HeldItem}"); + ushort held; + if (SAV.Generation == 2) + held = (ushort)(((PK2) pk).G2Item); + else if (SAV.Generation == 3) + held = (ushort)(((PK3) pk).G3Item); + else + held = (ushort)(pk.HeldItem); + + if (held > itemlist.Length) + errata.Add($"Item Index beyond range: {held}"); else { - if (pk.HeldItem > SAV.MaxItemID) - errata.Add($"Game can't obtain item: {itemlist[pk.HeldItem]}"); + if (held > SAV.MaxItemID) + errata.Add($"Game can't obtain item: {itemlist[held]}"); if (!pk.CanHoldItem(SAV.HeldItems)) - errata.Add($"Game can't hold item: {itemlist[pk.HeldItem]}"); + errata.Add($"Game can't hold item: {itemlist[held]}"); } } diff --git a/PKHeX/PKM/PK2.cs b/PKHeX/PKM/PK2.cs index bc3ab8d22..9917a5c86 100644 --- a/PKHeX/PKM/PK2.cs +++ b/PKHeX/PKM/PK2.cs @@ -274,7 +274,7 @@ public override int Gender public override bool CanHoldItem(ushort[] ValidArray) { - return ValidArray.Contains((ushort)HeldItem); + return ValidArray.Contains((ushort)G2Item); } #region Future, Unused Attributes diff --git a/PKHeX/PKM/PKMConverter.cs b/PKHeX/PKM/PKMConverter.cs index 76174a14f..71782823d 100644 --- a/PKHeX/PKM/PKMConverter.cs +++ b/PKHeX/PKM/PKMConverter.cs @@ -132,7 +132,7 @@ internal static PKM convertToFormat(PKM pk, Type PKMType, out string comment) comment = "No need to convert, current format matches requested format."; return pk; } - if (fromFormat <= toFormat) + if (fromFormat <= toFormat || fromFormat == 2) { pkm = pk.Clone(); if (pkm.IsEgg) // force hatch @@ -150,21 +150,21 @@ internal static PKM convertToFormat(PKM pk, Type PKMType, out string comment) switch (fromType.Name) { case "PK1": - if (PKMType == typeof(PK2)) + pkm = (PKMType == typeof (PK2)) ? ((PK1) pk).convertToPK2() : null; + break; + case "PK2": + if (PKMType == typeof (PK1)) { if (pk.Species > 151) { comment = $"Cannot convert a {PKX.getSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}"; return null; } - pkm = ((PK2)pk).convertToPK1(); + pkm = ((PK2) pk).convertToPK1(); } else pkm = null; break; - case "PK2": - pkm = PKMType == typeof(PK1) ? ((PK1)pkm).convertToPK2() : null; - break; case "CK3": case "XK3": // interconverting C/XD needs to visit main series format