Fix korean nickname detection

extracted the GetNonNicknamedBytes method (used in SetNotNicknamed and
GetIsNicknamed)
korean strings are variable byte width so using max string length is
insufficient
This commit is contained in:
Kurt 2017-09-22 20:34:29 -07:00
parent 6e579abfc3
commit 76adfd62bf
2 changed files with 31 additions and 40 deletions

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -96,18 +97,17 @@ namespace PKHeX.Core
public override bool IsNicknamed public override bool IsNicknamed
{ {
get get => !nick.SequenceEqual(GetNonNickname());
{ set { if (!value) SetNotNicknamed(); }
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return !nick.SequenceEqual(SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)));
} }
set public void SetNotNicknamed() => nick = GetNonNickname().ToArray();
private IEnumerable<byte> GetNonNickname()
{ {
if (!value) var lang = Japanese ? 1 : 2;
SetNotNicknamed(); var name = PKX.GetSpeciesNameGeneration(Species, lang, Format);
} var bytes = SetString(name, StringLength);
return bytes.Concat(Enumerable.Repeat((byte)0x50, nick.Length - bytes.Length))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)); // Decimal point<->period fix
} }
public bool IsNicknamedBank public bool IsNicknamedBank
@ -119,15 +119,6 @@ namespace PKHeX.Core
} }
} }
public void SetNotNicknamed()
{
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
nick = SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte)0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)) // Decimal point<->period fix
.ToArray();
}
#region Stored Attributes #region Stored Attributes
public override int Species public override int Species

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -127,27 +128,26 @@ namespace PKHeX.Core
public override byte[] DecryptedPartyData => Encrypt().ToArray(); public override byte[] DecryptedPartyData => Encrypt().ToArray();
public override bool IsNicknamed public override bool IsNicknamed
{
get => !nick.SequenceEqual(GetNonNickname());
set { if (!value) SetNotNicknamed(); }
}
public void SetNotNicknamed() => nick = GetNonNickname().ToArray();
private IEnumerable<byte> GetNonNickname()
{
var lang = Korean ? 8 : Japanese ? 1 : 2;
var name = PKX.GetSpeciesNameGeneration(Species, lang, Format);
var bytes = SetString(name, StringLength);
return bytes.Concat(Enumerable.Repeat((byte)0x50, nick.Length - bytes.Length))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)); // Decimal point<->period fix
}
public bool IsNicknamedBank
{ {
get get
{ {
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format); var spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return !nick.SequenceEqual(SetString(spName, StringLength) return Nickname != spName;
.Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)));
} }
set
{
if (!value)
SetNotNicknamed();
}
}
public void SetNotNicknamed()
{
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
nick = SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte)0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)) // Decimal point<->period fix
.ToArray();
} }
#region Stored Attributes #region Stored Attributes
@ -459,7 +459,7 @@ namespace PKHeX.Core
if (special) if (special)
pk7.FatefulEncounter = true; pk7.FatefulEncounter = true;
else if (IsNicknamed) else if (IsNicknamedBank)
{ {
pk7.IsNicknamed = true; pk7.IsNicknamed = true;
pk7.Nickname = Korean ? Nickname pk7.Nickname = Korean ? Nickname