From 09c6359e3a795a7940d4f32e147e0609b72e5f2f Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 4 Oct 2020 10:25:34 -0700 Subject: [PATCH] Add flexibility for SK2 imports Check language character table for English vs Japanese when loading for a destination --- PKHeX.Core/PKM/SK2.cs | 2 ++ PKHeX.Core/PKM/Strings/StringConverter12.cs | 9 +++------ PKHeX.Core/PKM/Util/PKMConverter.cs | 4 ++-- PKHeX.Core/Saves/Util/SaveExtensions.cs | 2 +- PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/PKHeX.Core/PKM/SK2.cs b/PKHeX.Core/PKM/SK2.cs index b93792be5..cdddfc308 100644 --- a/PKHeX.Core/PKM/SK2.cs +++ b/PKHeX.Core/PKM/SK2.cs @@ -175,5 +175,7 @@ namespace PKHeX.Core } private static bool IsJapanese(byte[] data) => StringConverter12.GetIsG1Japanese(data, 0x24, StringLength) && StringConverter12.GetIsG1Japanese(data, 0x30, StringLength); + private static bool IsEnglish(byte[] data) => StringConverter12.GetIsG1English(data, 0x24, StringLength) && StringConverter12.GetIsG1English(data, 0x30, StringLength); + public bool IsPossible(bool japanese) => japanese ? IsJapanese(Data) : IsEnglish(Data); } } diff --git a/PKHeX.Core/PKM/Strings/StringConverter12.cs b/PKHeX.Core/PKM/Strings/StringConverter12.cs index c651679c3..1059fd35b 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter12.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter12.cs @@ -11,13 +11,10 @@ namespace PKHeX.Core { public static bool GetIsG1Japanese(string str) => AllCharsInDictionary(str, U2RBY_J); public static bool GetIsG1English(string str) => AllCharsInDictionary(str, U2RBY_U); - private static bool AllCharsInDictionary(IEnumerable c, IReadOnlyDictionary d) => c.All(d.ContainsKey); + public static bool GetIsG1Japanese(byte[] data, int start, int length) => AllCharsInDictionary(data, start, length, RBY2U_J); + public static bool GetIsG1English(byte[] data, int start, int length) => AllCharsInDictionary(data, start, length, RBY2U_U); - public static bool GetIsG1Japanese(byte[] data, int start, int length) - { - var d = RBY2U_J; - return AllCharsInDictionary(data, start, length, d); - } + private static bool AllCharsInDictionary(IEnumerable c, IReadOnlyDictionary d) => c.All(d.ContainsKey); private static bool AllCharsInDictionary(IReadOnlyList data, int start, int length, IReadOnlyDictionary d) { diff --git a/PKHeX.Core/PKM/Util/PKMConverter.cs b/PKHeX.Core/PKM/Util/PKMConverter.cs index be1a23ea0..c6ce006ce 100644 --- a/PKHeX.Core/PKM/Util/PKMConverter.cs +++ b/PKHeX.Core/PKM/Util/PKMConverter.cs @@ -408,7 +408,7 @@ namespace PKHeX.Core if (!AllowIncompatibleConversion) return false; } - if (IsIncompatibleGB(target.Format, target.Japanese, pk.Japanese)) + if (IsIncompatibleGB(target, target.Japanese, pk.Japanese)) { pkm = target; c = GetIncompatibleGBMessage(pk, target.Japanese); @@ -433,7 +433,7 @@ namespace PKHeX.Core return string.Format(MsgPKMConvertIncompatible, src, pk.GetType().Name, dest); } - public static bool IsIncompatibleGB(int format, bool destJapanese, bool srcJapanese) => format <= 2 && destJapanese != srcJapanese; + public static bool IsIncompatibleGB(PKM pk, bool destJapanese, bool srcJapanese) => pk.Format <= 2 && destJapanese != srcJapanese && !(pk is SK2 sk2 && sk2.IsPossible(srcJapanese)); /// /// Gets a Blank object of the specified type. diff --git a/PKHeX.Core/Saves/Util/SaveExtensions.cs b/PKHeX.Core/Saves/Util/SaveExtensions.cs index dbd4ef233..ac26caf69 100644 --- a/PKHeX.Core/Saves/Util/SaveExtensions.cs +++ b/PKHeX.Core/Saves/Util/SaveExtensions.cs @@ -165,7 +165,7 @@ namespace PKHeX.Core continue; } - if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk.Format, il.Japanese, pk.Japanese)) + if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk, il.Japanese, pk.Japanese)) { c = PKMConverter.GetIncompatibleGBMessage(pk, il.Japanese); Debug.WriteLine(c); diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs index 7fda57e30..8a52db779 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs @@ -286,7 +286,7 @@ namespace PKHeX.WinForms.Controls if (badDest && (pk.Species == 0 || pk.IsEgg)) return false; - if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk.Format, il.Japanese, pk.Japanese)) + if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk, il.Japanese, pk.Japanese)) { c = PKMConverter.GetIncompatibleGBMessage(pk, il.Japanese); WinFormsUtil.Error(c);