diff --git a/PKHeX.Core/PKM/PKMConverter.cs b/PKHeX.Core/PKM/PKMConverter.cs
index 3a4fc0488..ce581380d 100644
--- a/PKHeX.Core/PKM/PKMConverter.cs
+++ b/PKHeX.Core/PKM/PKMConverter.cs
@@ -200,7 +200,7 @@ namespace PKHeX.Core
/// Converted PKM
public static PKM ConvertToType(PKM pk, Type PKMType, out string comment)
{
- if (pk == null || pk.Species == 0)
+ if (pk == null)
{
comment = $"Bad {nameof(pk)} input. Aborting.";
return null;
@@ -392,6 +392,35 @@ namespace PKHeX.Core
}
}
+ ///
+ /// Checks if the input is compatible with the target .
+ ///
+ /// Input to check -> update/sanitize
+ /// Target type PKM with misc properties accessible for checking.
+ /// Comment output
+ /// Output compatible PKM
+ /// Indication if the input is (now) compatible with the target.
+ public static bool TryMakePKMCompatible(PKM pk, PKM target, out string c, out PKM pkm)
+ {
+ if (!IsConvertibleToFormat(pk, target.Format))
+ {
+ pkm = null;
+ c = $"Can't load {pk.GetType().Name}s to Gen{target.Format} saves.";
+ return false;
+ }
+ if (target.Format < 3 && pk.Japanese != target.Japanese)
+ {
+ pkm = null;
+ var strs = new[] { "International", "Japanese" };
+ var val = target.Japanese ? 0 : 1;
+ c = $"Cannot load {strs[val]} {pk.GetType().Name}s to {strs[val ^ 1]} saves.";
+ return false;
+ }
+ pkm = ConvertToType(pk, target.GetType(), out c);
+ Debug.WriteLine(c);
+ return pkm != null;
+ }
+
///
/// Gets a Blank object of the specified type.
///
diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs
index 37b648203..6e17e795a 100644
--- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs
+++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs
@@ -172,12 +172,16 @@ namespace PKHeX.WinForms.Controls
if (GB_ExtraBytes.Enabled)
CB_ExtraBytes.SelectedIndex = 0;
}
- public void PopulateFields(PKM pk, bool focus = true)
+ public void PopulateFields(PKM pk, bool focus = true, bool skipConversionCheck = false) => LoadFieldsFromPKM(pk, focus, skipConversionCheck);
+ private void LoadFieldsFromPKM(PKM pk, bool focus = true, bool skipConversionCheck = true)
{
if (pk == null) { WinFormsUtil.Error("Attempted to load a null file."); return; }
if (focus)
Tab_Main.Focus();
+ if (!skipConversionCheck && !PKMConverter.TryMakePKMCompatible(pk, CurrentPKM, out string c, out pk))
+ { WinFormsUtil.Alert(c); return; }
+
bool oldInit = fieldsInitialized;
fieldsInitialized = fieldsLoaded = false;
diff --git a/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs b/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs
index 87fb4b0b8..339885c03 100644
--- a/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs
+++ b/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs
@@ -33,7 +33,7 @@ namespace PKHeX.WinForms.Controls
if ((sender as PictureBox)?.Image == null)
{ System.Media.SystemSounds.Asterisk.Play(); return; }
- m.SE.PKME_Tabs.PopulateFields(m.GetPKM(info), false);
+ m.SE.PKME_Tabs.PopulateFields(m.GetPKM(info), false, true);
m.SetColor(info.Box, info.Slot, Resources.slotView);
}
private static void ClickSet(object sender, EventArgs e)
diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs
index c77cc0789..69836a043 100644
--- a/PKHeX.WinForms/MainWindow/Main.cs
+++ b/PKHeX.WinForms/MainWindow/Main.cs
@@ -575,27 +575,11 @@ namespace PKHeX.WinForms
}
private bool TryLoadPKM(byte[] input, string path, string ext, SaveFile SAV)
{
- var temp = PKMConverter.GetPKMfromBytes(input, prefer: ext.Length > 0 ? (ext.Last() - '0') & 0xF : C_SAV.SAV.Generation);
- if (temp == null)
- return false;
-
- var type = PKME_Tabs.CurrentPKM.GetType();
- PKM pk = PKMConverter.ConvertToType(temp, type, out string c);
+ var pk = PKMConverter.GetPKMfromBytes(input, prefer: ext.Length > 0 ? (ext.Last() - '0') & 0xF : C_SAV.SAV.Generation);
if (pk == null)
- {
- WinFormsUtil.Alert("Conversion failed.", c);
- return true;
- }
- if (SAV.Generation < 3 && pk.Japanese != SAV.Japanese)
- {
- var strs = new[] { "International", "Japanese" };
- var val = SAV.Japanese ? 0 : 1;
- WinFormsUtil.Alert($"Cannot load {strs[val]} {pk.GetType().Name}s to {strs[val ^ 1]} saves.");
- return true;
- }
+ return false;
PKME_Tabs.PopulateFields(pk);
- Debug.WriteLine(c);
return true;
}
private bool TryLoadPCBoxBin(byte[] input)