Fix Gen II Held Item bug, Gen II JP<->EN bugs, many Gen I<->Gen II conversion bugs.

This commit is contained in:
Michael Scire
2016-10-03 22:24:03 -07:00
parent 10fbcfcd74
commit 337f58504e
3 changed files with 24 additions and 14 deletions

View File

@@ -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<string> errata = new List<string>();
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]}");
}
}

View File

@@ -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

View File

@@ -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