misc kor improvements

pk2 objects now detect if they are korean or not
This commit is contained in:
Kurt 2017-09-10 22:30:41 -07:00
parent 4bff4a5e79
commit 4f9dc69504
3 changed files with 33 additions and 5 deletions

View file

@ -506,6 +506,11 @@ namespace PKHeX.Core
if (str.Length > 5) if (str.Length > 5)
AddLine(Severity.Invalid, V38, CheckIdentifier.Trainer); 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 else
{ {
AddLine(Severity.Invalid, V421, CheckIdentifier.Trainer); AddLine(Severity.Invalid, V421, CheckIdentifier.Trainer);

View file

@ -20,9 +20,21 @@ namespace PKHeX.Core
internal const int STRLEN_J = 6; internal const int STRLEN_J = 6;
internal const int STRLEN_U = 11; internal const int STRLEN_U = 11;
private int StringLength => Japanese ? STRLEN_J : STRLEN_U; 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 string GetString(int Offset, int Count)
public override byte[] SetString(string value, int maxLength) => StringConverter.SetString1(value, maxLength, Japanese); {
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 // Trash Bytes
public override byte[] Nickname_Trash { get => nick; set { if (value?.Length == nick.Length) nick = value; } } 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 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 set
{ {
byte[] strdata = SetString(value, StringLength); byte[] strdata = SetString(value, StringLength);
@ -82,7 +99,12 @@ namespace PKHeX.Core
public override string OT_Name 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 set
{ {
byte[] strdata = SetString(value, StringLength); byte[] strdata = SetString(value, StringLength);

View file

@ -102,7 +102,7 @@ namespace PKHeX.Core
{ {
byte val = strdata[offset + i]; byte val = strdata[offset + i];
var dict = val <= 0xB ? GSC2U_KOR[val] : RBY2U_U; var dict = val <= 0xB ? GSC2U_KOR[val] : RBY2U_U;
if (val <= 0xB) if (val <= 0xB && val != 0)
val = strdata[offset + ++i]; val = strdata[offset + ++i];
if (!dict.TryGetValue(val, out string c)) // Take valid values if (!dict.TryGetValue(val, out string c)) // Take valid values
break; 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 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 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())));
/// <summary> /// <summary>
/// Converts a Unicode string to Generation 7 in-game chinese string. /// Converts a Unicode string to Generation 7 in-game chinese string.