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.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -96,18 +97,17 @@ namespace PKHeX.Core
public override bool IsNicknamed
{
get
{
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
{
if (!value)
SetNotNicknamed();
}
get => !nick.SequenceEqual(GetNonNickname());
set { if (!value) SetNotNicknamed(); }
}
public void SetNotNicknamed() => nick = GetNonNickname().ToArray();
private IEnumerable<byte> GetNonNickname()
{
var lang = 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
@ -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
public override int Species

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -127,29 +128,28 @@ namespace PKHeX.Core
public override byte[] DecryptedPartyData => Encrypt().ToArray();
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
{
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
{
if (!value)
SetNotNicknamed();
var spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return Nickname != spName;
}
}
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
public override int Species
{
@ -459,7 +459,7 @@ namespace PKHeX.Core
if (special)
pk7.FatefulEncounter = true;
else if (IsNicknamed)
else if (IsNicknamedBank)
{
pk7.IsNicknamed = true;
pk7.Nickname = Korean ? Nickname