From 4f9dc69504b25594637b997ac138aebd899eab8c Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 10 Sep 2017 22:30:41 -0700 Subject: [PATCH] misc kor improvements pk2 objects now detect if they are korean or not --- PKHeX.Core/Legality/Checks.cs | 5 +++++ PKHeX.Core/PKM/PK2.cs | 30 ++++++++++++++++++++++++++---- PKHeX.Core/PKM/StringConverter.cs | 3 ++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 4a1739d1b..5073e20c2 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -506,6 +506,11 @@ namespace PKHeX.Core if (str.Length > 5) AddLine(Severity.Invalid, V38, CheckIdentifier.Trainer); } + else if (pkm is PK2 pk2 && pk2.Korean) + { + if (str.Length > 5) + AddLine(Severity.Invalid, V38, CheckIdentifier.Trainer); + } else { AddLine(Severity.Invalid, V421, CheckIdentifier.Trainer); diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index 3716083ef..97f1b4cc7 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -20,9 +20,21 @@ namespace PKHeX.Core internal const int STRLEN_J = 6; internal const int STRLEN_U = 11; private int StringLength => Japanese ? STRLEN_J : STRLEN_U; + public bool Korean => otname[0] <= 0xB; - public override string GetString(int Offset, int Count) => StringConverter.GetString1(Data, Offset, Count, Japanese); - public override byte[] SetString(string value, int maxLength) => StringConverter.SetString1(value, maxLength, Japanese); + public override string GetString(int Offset, int Count) + { + if (Korean) + return StringConverter.GetString2KOR(Data, Offset, Count); + return StringConverter.GetString1(Data, Offset, Count, Japanese); + } + + public override byte[] SetString(string value, int maxLength) + { + if (Korean) + return StringConverter.SetString2KOR(value, maxLength); + return StringConverter.SetString1(value, maxLength, Japanese); + } // Trash Bytes public override byte[] Nickname_Trash { get => nick; set { if (value?.Length == nick.Length) nick = value; } } @@ -64,7 +76,12 @@ namespace PKHeX.Core } public override string Nickname { - get => StringConverter.GetString1(nick, 0, nick.Length, Japanese); + get + { + if (Korean) + return StringConverter.GetString2KOR(nick, 0, nick.Length); + return StringConverter.GetString1(nick, 0, nick.Length, Japanese); + } set { byte[] strdata = SetString(value, StringLength); @@ -82,7 +99,12 @@ namespace PKHeX.Core public override string OT_Name { - get => StringConverter.GetString1(otname, 0, otname.Length, Japanese); + get + { + if (Korean) + return StringConverter.GetString2KOR(otname, 0, otname.Length); + return StringConverter.GetString1(otname, 0, otname.Length, Japanese); + } set { byte[] strdata = SetString(value, StringLength); diff --git a/PKHeX.Core/PKM/StringConverter.cs b/PKHeX.Core/PKM/StringConverter.cs index 38560ca2c..978c4b4db 100644 --- a/PKHeX.Core/PKM/StringConverter.cs +++ b/PKHeX.Core/PKM/StringConverter.cs @@ -102,7 +102,7 @@ namespace PKHeX.Core { byte val = strdata[offset + i]; var dict = val <= 0xB ? GSC2U_KOR[val] : RBY2U_U; - if (val <= 0xB) + if (val <= 0xB && val != 0) val = strdata[offset + ++i]; if (!dict.TryGetValue(val, out string c)) // Take valid values break; @@ -477,6 +477,7 @@ namespace PKHeX.Core public static bool GetIsG1Japanese(string str) => str.All(z => U2RBY_J.ContainsKey(z.ToString())); public static bool GetIsG1English(string str) => str.All(z => U2RBY_U.ContainsKey(z.ToString())); + public static bool GetIsG2Korean(string str) => str.All(z => U2GSC_KOR.Any(x => x.ContainsKey(z.ToString()))); /// /// Converts a Unicode string to Generation 7 in-game chinese string.