2016-08-31 20:52:30 +00:00
|
|
|
|
using System;
|
2017-09-23 03:34:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary> Generation 2 <see cref="PKM"/> format. </summary>
|
2017-12-16 22:11:41 +00:00
|
|
|
|
public sealed class PK2 : PKM
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
2017-12-16 22:11:41 +00:00
|
|
|
|
internal byte[] otname;
|
|
|
|
|
internal byte[] nick;
|
2016-10-24 05:01:39 +00:00
|
|
|
|
public override PersonalInfo PersonalInfo => PersonalTable.C[Species];
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
|
|
|
|
public byte[] OT_Name_Raw => (byte[])otname.Clone();
|
|
|
|
|
public byte[] Nickname_Raw => (byte[])nick.Clone();
|
2016-09-15 05:04:22 +00:00
|
|
|
|
public override bool Valid => Species <= 252;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2017-12-16 22:11:41 +00:00
|
|
|
|
public override int SIZE_PARTY => PKX.SIZE_2PARTY;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_2STORED;
|
|
|
|
|
internal const int STRLEN_J = 6;
|
|
|
|
|
internal const int STRLEN_U = 11;
|
|
|
|
|
private int StringLength => Japanese ? STRLEN_J : STRLEN_U;
|
2017-09-24 15:36:10 +00:00
|
|
|
|
public override bool Korean => !Japanese && otname[0] <= 0xB;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2017-10-04 01:15:15 +00:00
|
|
|
|
private string GetString(int Offset, int Count)
|
2017-09-11 05:30:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (Korean)
|
|
|
|
|
return StringConverter.GetString2KOR(Data, Offset, Count);
|
|
|
|
|
return StringConverter.GetString1(Data, Offset, Count, Japanese);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 01:15:15 +00:00
|
|
|
|
private byte[] SetString(string value, int maxLength)
|
2017-09-11 05:30:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (Korean)
|
2018-01-01 19:27:45 +00:00
|
|
|
|
return StringConverter.SetString2KOR(value, maxLength - 1);
|
|
|
|
|
return StringConverter.SetString1(value, maxLength - 1, Japanese);
|
2017-09-11 05:30:41 +00:00
|
|
|
|
}
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
|
|
|
|
// Trash Bytes
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override byte[] Nickname_Trash { get => nick; set { if (value?.Length == nick.Length) nick = value; } }
|
|
|
|
|
public override byte[] OT_Trash { get => otname; set { if (value?.Length == otname.Length) otname = value; } }
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int Format => 2;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2017-09-23 18:46:10 +00:00
|
|
|
|
public override bool Japanese => otname.Length == STRLEN_J;
|
2016-12-21 01:24:41 +00:00
|
|
|
|
public override string FileName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-26 18:01:18 +00:00
|
|
|
|
string form = AltForm > 0 ? $"-{AltForm:00}" : "";
|
2016-12-21 01:24:41 +00:00
|
|
|
|
string star = IsShiny ? " ★" : "";
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return $"{Species:000}{form}{star} - {Nickname} - {SaveUtil.CRC16_CCITT(Encrypt()):X4}.{Extension}";
|
2016-12-21 01:24:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
|
|
|
|
public PK2(byte[] decryptedData = null, string ident = null, bool jp = false)
|
|
|
|
|
{
|
2017-12-27 05:38:19 +00:00
|
|
|
|
Data = decryptedData ?? new byte[SIZE_PARTY];
|
2016-08-31 20:52:30 +00:00
|
|
|
|
Identifier = ident;
|
|
|
|
|
if (Data.Length != SIZE_PARTY)
|
|
|
|
|
Array.Resize(ref Data, SIZE_PARTY);
|
2016-09-04 06:54:11 +00:00
|
|
|
|
int strLen = jp ? STRLEN_J : STRLEN_U;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
|
|
|
|
|
nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 00:36:24 +00:00
|
|
|
|
public override PKM Clone() => new PK2((byte[])Data.Clone(), Identifier, Japanese)
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
2017-12-28 00:36:24 +00:00
|
|
|
|
otname = (byte[])otname.Clone(),
|
|
|
|
|
nick = (byte[])nick.Clone(),
|
|
|
|
|
IsEgg = IsEgg,
|
|
|
|
|
};
|
2016-08-31 20:52:30 +00:00
|
|
|
|
public override string Nickname
|
|
|
|
|
{
|
2017-09-11 05:30:41 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Korean)
|
|
|
|
|
return StringConverter.GetString2KOR(nick, 0, nick.Length);
|
|
|
|
|
return StringConverter.GetString1(nick, 0, nick.Length, Japanese);
|
|
|
|
|
}
|
2016-08-31 20:52:30 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2018-02-18 01:42:00 +00:00
|
|
|
|
if (!IsNicknamed && Nickname == value)
|
2017-10-03 06:13:40 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
byte[] strdata = SetString(value, StringLength);
|
2016-08-31 20:52:30 +00:00
|
|
|
|
if (nick.Any(b => b == 0) && nick[StringLength - 1] == 0x50 && Array.FindIndex(nick, b => b == 0) == strdata.Length - 1) // Handle JP Mew event with grace
|
|
|
|
|
{
|
|
|
|
|
int firstInd = Array.FindIndex(nick, b => b == 0);
|
|
|
|
|
for (int i = firstInd; i < StringLength - 1; i++)
|
|
|
|
|
if (nick[i] != 0)
|
|
|
|
|
break;
|
|
|
|
|
strdata = strdata.Take(strdata.Length - 1).ToArray();
|
|
|
|
|
}
|
|
|
|
|
strdata.CopyTo(nick, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string OT_Name
|
|
|
|
|
{
|
2017-09-11 05:30:41 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Korean)
|
|
|
|
|
return StringConverter.GetString2KOR(otname, 0, otname.Length);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
return StringConverter.GetString1(otname, 0, otname.Length, Japanese);
|
2017-09-11 05:30:41 +00:00
|
|
|
|
}
|
2016-08-31 20:52:30 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
byte[] strdata = SetString(value, StringLength);
|
2016-08-31 20:52:30 +00:00
|
|
|
|
if (otname.Any(b => b == 0) && otname[StringLength - 1] == 0x50 && Array.FindIndex(otname, b => b == 0) == strdata.Length - 1) // Handle JP Mew event with grace
|
|
|
|
|
{
|
|
|
|
|
int firstInd = Array.FindIndex(otname, b => b == 0);
|
|
|
|
|
for (int i = firstInd; i < StringLength - 1; i++)
|
|
|
|
|
if (otname[i] != 0)
|
|
|
|
|
break;
|
|
|
|
|
strdata = strdata.Take(strdata.Length - 1).ToArray();
|
|
|
|
|
}
|
|
|
|
|
strdata.CopyTo(otname, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override byte[] Encrypt() => new PokemonList2(this).GetBytes();
|
2017-10-06 05:37:45 +00:00
|
|
|
|
public override byte[] EncryptedPartyData => Encrypt();
|
|
|
|
|
public override byte[] EncryptedBoxData => Encrypt();
|
|
|
|
|
public override byte[] DecryptedBoxData => Encrypt();
|
|
|
|
|
public override byte[] DecryptedPartyData => Encrypt();
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2017-10-03 06:13:40 +00:00
|
|
|
|
private bool? _isnicknamed;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
public override bool IsNicknamed
|
2017-09-23 03:34:29 +00:00
|
|
|
|
{
|
2017-10-03 06:13:40 +00:00
|
|
|
|
get => (bool)(_isnicknamed ?? (_isnicknamed = !nick.SequenceEqual(GetNonNickname())));
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isnicknamed = value;
|
|
|
|
|
if (_isnicknamed == false)
|
|
|
|
|
SetNotNicknamed();
|
|
|
|
|
}
|
2017-09-23 03:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
public void SetNotNicknamed() => nick = GetNonNickname().ToArray();
|
|
|
|
|
private IEnumerable<byte> GetNonNickname()
|
|
|
|
|
{
|
2017-10-22 23:52:46 +00:00
|
|
|
|
var name = PKX.GetSpeciesNameGeneration(Species, GuessedLanguage(), Format);
|
2017-09-23 03:34:29 +00:00
|
|
|
|
var bytes = SetString(name, StringLength);
|
2017-10-27 03:18:32 +00:00
|
|
|
|
var data = bytes.Concat(Enumerable.Repeat((byte) 0x50, nick.Length - bytes.Length));
|
|
|
|
|
if (!Korean)
|
|
|
|
|
data = data.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)); // Decimal point<->period fix
|
|
|
|
|
return data;
|
2017-09-23 03:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
public bool IsNicknamedBank
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-10-22 23:52:46 +00:00
|
|
|
|
var spName = PKX.GetSpeciesNameGeneration(Species, GuessedLanguage(), Format);
|
2017-09-23 03:34:29 +00:00
|
|
|
|
return Nickname != spName;
|
2017-03-05 01:19:57 +00:00
|
|
|
|
}
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
2017-10-22 23:52:46 +00:00
|
|
|
|
public override int Language
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Japanese)
|
2017-10-23 04:01:08 +00:00
|
|
|
|
return (int)LanguageID.Japanese;
|
2017-10-22 23:52:46 +00:00
|
|
|
|
if (Korean)
|
2017-10-25 01:57:28 +00:00
|
|
|
|
return (int)LanguageID.Korean;
|
2017-10-22 23:52:46 +00:00
|
|
|
|
if (StringConverter.IsG12German(otname))
|
2017-10-23 04:01:08 +00:00
|
|
|
|
return (int)LanguageID.German; // german
|
2017-10-22 23:52:46 +00:00
|
|
|
|
int lang = PKX.GetSpeciesNameLanguage(Species, Nickname, Format);
|
|
|
|
|
if (lang > 0)
|
|
|
|
|
return lang;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
set { }
|
|
|
|
|
}
|
2017-10-23 04:01:08 +00:00
|
|
|
|
private int GuessedLanguage(int fallback = (int)LanguageID.English)
|
2017-10-22 23:52:46 +00:00
|
|
|
|
{
|
|
|
|
|
int lang = Language;
|
|
|
|
|
if (lang > 0)
|
|
|
|
|
return lang;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
if (fallback == (int)LanguageID.French || fallback == (int)LanguageID.German) // only other permitted besides English
|
2017-10-22 23:52:46 +00:00
|
|
|
|
return fallback;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
return (int)LanguageID.English;
|
2017-10-22 23:52:46 +00:00
|
|
|
|
}
|
2017-09-23 03:34:29 +00:00
|
|
|
|
|
2016-08-31 20:52:30 +00:00
|
|
|
|
#region Stored Attributes
|
|
|
|
|
public override int Species
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[0];
|
|
|
|
|
set => Data[0] = (byte)value;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
2017-08-01 06:03:51 +00:00
|
|
|
|
public override int SpriteItem => ItemConverter.GetG4Item((byte)HeldItem);
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int HeldItem { get => Data[0x1]; set => Data[0x1] = (byte)value; }
|
|
|
|
|
public override int Move1 { get => Data[2]; set => Data[2] = (byte)value; }
|
|
|
|
|
public override int Move2 { get => Data[3]; set => Data[3] = (byte)value; }
|
|
|
|
|
public override int Move3 { get => Data[4]; set => Data[4] = (byte)value; }
|
|
|
|
|
public override int Move4 { get => Data[5]; set => Data[5] = (byte)value; }
|
|
|
|
|
public override int TID { get => BigEndian.ToUInt16(Data, 6); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 6); }
|
2016-08-31 20:52:30 +00:00
|
|
|
|
public override uint EXP
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (BigEndian.ToUInt32(Data, 8) >> 8) & 0x00FFFFFF;
|
|
|
|
|
set => Array.Copy(BigEndian.GetBytes((value << 8) & 0xFFFFFF00), 0, Data, 8, 3);
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int EV_HP { get => BigEndian.ToUInt16(Data, 0xB); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0xB); }
|
|
|
|
|
public override int EV_ATK { get => BigEndian.ToUInt16(Data, 0xD); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0xD); }
|
|
|
|
|
public override int EV_DEF { get => BigEndian.ToUInt16(Data, 0xF); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0xF); }
|
|
|
|
|
public override int EV_SPE { get => BigEndian.ToUInt16(Data, 0x11); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x11); }
|
|
|
|
|
public int EV_SPC { get => BigEndian.ToUInt16(Data, 0x13); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x13); }
|
|
|
|
|
public override int EV_SPA { get => EV_SPC; set => EV_SPC = value; }
|
|
|
|
|
public override int EV_SPD { get => EV_SPC; set { } }
|
|
|
|
|
public ushort DV16 { get => BigEndian.ToUInt16(Data, 0x15); set => BigEndian.GetBytes(value).CopyTo(Data, 0x15); }
|
|
|
|
|
public override int IV_HP { get => ((IV_ATK & 1) << 3) | ((IV_DEF & 1) << 2) | ((IV_SPE & 1) << 1) | ((IV_SPC & 1) << 0); set { } }
|
|
|
|
|
public override int IV_ATK { get => (DV16 >> 12) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 12)) | (ushort)((value > 0xF ? 0xF : value) << 12)); }
|
|
|
|
|
public override int IV_DEF { get => (DV16 >> 8) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 8)) | (ushort)((value > 0xF ? 0xF : value) << 8)); }
|
|
|
|
|
public override int IV_SPE { get => (DV16 >> 4) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 4)) | (ushort)((value > 0xF ? 0xF : value) << 4)); }
|
|
|
|
|
public int IV_SPC { get => (DV16 >> 0) & 0xF; set => DV16 = (ushort)((DV16 & ~(0xF << 0)) | (ushort)((value > 0xF ? 0xF : value) << 0)); }
|
|
|
|
|
public override int IV_SPA { get => IV_SPC; set => IV_SPC = value; }
|
|
|
|
|
public override int IV_SPD { get => IV_SPC; set { } }
|
2017-05-19 16:22:12 +00:00
|
|
|
|
public override int Move1_PP { get => Data[0x17] & 0x3F; set => Data[0x17] = (byte)((Data[0x17] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
|
public override int Move2_PP { get => Data[0x18] & 0x3F; set => Data[0x18] = (byte)((Data[0x18] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
|
public override int Move3_PP { get => Data[0x19] & 0x3F; set => Data[0x19] = (byte)((Data[0x19] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
|
public override int Move4_PP { get => Data[0x1A] & 0x3F; set => Data[0x1A] = (byte)((Data[0x1A] & 0xC0) | Math.Min(63, value)); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Move1_PPUps { get => (Data[0x17] & 0xC0) >> 6; set => Data[0x17] = (byte)((Data[0x17] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int Move2_PPUps { get => (Data[0x18] & 0xC0) >> 6; set => Data[0x18] = (byte)((Data[0x18] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int Move3_PPUps { get => (Data[0x19] & 0xC0) >> 6; set => Data[0x19] = (byte)((Data[0x19] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int Move4_PPUps { get => (Data[0x1A] & 0xC0) >> 6; set => Data[0x1A] = (byte)((Data[0x1A] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int CurrentFriendship { get => Data[0x1B]; set => Data[0x1B] = (byte)value; }
|
|
|
|
|
private byte PKRS { get => Data[0x1C]; set => Data[0x1C] = value; }
|
|
|
|
|
public override int PKRS_Days { get => PKRS & 0xF; set => PKRS = (byte)(PKRS & ~0xF | value); }
|
|
|
|
|
public override int PKRS_Strain { get => PKRS >> 4; set => PKRS = (byte)(PKRS & 0xF | value << 4); }
|
2016-08-31 20:52:30 +00:00
|
|
|
|
// Crystal only Caught Data
|
2018-07-02 00:07:29 +00:00
|
|
|
|
public int CaughtData { get => BigEndian.ToUInt16(Data, 0x1D); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x1D); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int Met_TimeOfDay { get => (CaughtData >> 14) & 0x3; set => CaughtData = (CaughtData & 0x3FFF) | ((value & 0x3) << 14); }
|
|
|
|
|
public override int Met_Level { get => (CaughtData >> 8) & 0x3F; set => CaughtData = (CaughtData & 0xC0FF) | ((value & 0x3F) << 8); }
|
2017-05-28 23:56:51 +00:00
|
|
|
|
public override int OT_Gender { get => (CaughtData >> 7) & 1; set => CaughtData = (CaughtData & 0xFF7F) | ((value & 1) << 7); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Met_Location { get => CaughtData & 0x7F; set => CaughtData = (CaughtData & 0xFF80) | (value & 0x7F); }
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-10-23 03:07:03 +00:00
|
|
|
|
public override int Stat_Level
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[0x1F];
|
|
|
|
|
set => Data[0x1F] = (byte)value;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Party Attributes
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int Status_Condition { get => Data[0x20]; set => Data[0x20] = (byte)value; }
|
|
|
|
|
|
|
|
|
|
public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x22); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x22); }
|
|
|
|
|
public override int Stat_HPMax { get => BigEndian.ToUInt16(Data, 0x24); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x24); }
|
|
|
|
|
public override int Stat_ATK { get => BigEndian.ToUInt16(Data, 0x26); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x26); }
|
|
|
|
|
public override int Stat_DEF { get => BigEndian.ToUInt16(Data, 0x28); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x28); }
|
|
|
|
|
public override int Stat_SPE { get => BigEndian.ToUInt16(Data, 0x2A); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x2A); }
|
|
|
|
|
public override int Stat_SPA { get => BigEndian.ToUInt16(Data, 0x2C); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x2C); }
|
|
|
|
|
public override int Stat_SPD { get => BigEndian.ToUInt16(Data, 0x2E); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x2E); }
|
2016-08-31 20:52:30 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetMovePP(int move, int ppup) => Math.Min(61, base.GetMovePP(move, ppup));
|
|
|
|
|
public override ushort[] GetStats(PersonalInfo p)
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
|
|
|
|
ushort[] Stats = new ushort[6];
|
|
|
|
|
for (int i = 0; i < Stats.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
ushort L = (ushort)Stat_Level;
|
|
|
|
|
ushort B = (ushort)p.Stats[i];
|
|
|
|
|
ushort I = (ushort)IVs[i];
|
|
|
|
|
ushort E = // Fixed formula via http://www.smogon.com/ingame/guides/rby_gsc_stats
|
|
|
|
|
(ushort)Math.Floor(Math.Min(255, Math.Floor(Math.Sqrt(Math.Max(0, EVs[i] - 1)) + 1)) / 4.0);
|
|
|
|
|
Stats[i] = (ushort)Math.Floor((2 * (B + I) + E) * L / 100.0 + 5);
|
|
|
|
|
}
|
|
|
|
|
Stats[0] += (ushort)(5 + Stat_Level); // HP
|
|
|
|
|
|
|
|
|
|
return Stats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsEgg { get; set; }
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
|
|
|
|
public override int Gender
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-29 16:39:11 +00:00
|
|
|
|
int gv = PersonalInfo.Gender;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
if (gv == 255)
|
|
|
|
|
return 2;
|
|
|
|
|
if (gv == 254)
|
|
|
|
|
return 1;
|
2016-09-05 22:50:09 +00:00
|
|
|
|
if (gv == 0)
|
|
|
|
|
return 0;
|
2018-06-28 01:31:24 +00:00
|
|
|
|
return IV_ATK > gv >> 4 ? 0 : 1;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
set { }
|
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-03-21 00:50:35 +00:00
|
|
|
|
public override bool HasOriginalMetLocation => CaughtData != 0;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
|
|
|
|
#region Future, Unused Attributes
|
2017-10-08 03:42:51 +00:00
|
|
|
|
public override bool IsGenderValid() => true; // not a separate property, derived via IVs
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override uint EncryptionConstant { get => 0; set { } }
|
|
|
|
|
public override uint PID { get => 0; set { } }
|
|
|
|
|
public override int Nature { get => 0; set { } }
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
|
|
|
|
public override int AltForm
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Species != 201) // Unown
|
|
|
|
|
return 0;
|
2017-10-03 06:13:40 +00:00
|
|
|
|
|
|
|
|
|
uint formeVal = 0;
|
|
|
|
|
formeVal |= (uint)((IV_ATK & 0x6) << 5);
|
|
|
|
|
formeVal |= (uint)((IV_DEF & 0x6) << 3);
|
|
|
|
|
formeVal |= (uint)((IV_SPE & 0x6) << 1);
|
|
|
|
|
formeVal |= (uint)((IV_SPC & 0x6) >> 1);
|
|
|
|
|
return (int)(formeVal / 10);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2017-10-03 06:13:40 +00:00
|
|
|
|
set { }
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private int HPVal => GetHiddenPowerBitVal(new[] {IV_SPC, IV_SPE, IV_DEF, IV_ATK});
|
2017-03-05 01:19:57 +00:00
|
|
|
|
public override int HPPower => (5 * HPVal + IV_SPC % 4) / 2 + 31;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int HPType
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => ((IV_ATK & 3) << 2) | (IV_DEF & 3); set
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2017-03-05 01:19:57 +00:00
|
|
|
|
IV_DEF = ((IV_DEF >> 2) << 2) | (value & 3);
|
|
|
|
|
IV_DEF = ((IV_ATK >> 2) << 2) | ((value >> 2) & 3);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-15 05:04:22 +00:00
|
|
|
|
public override bool IsShiny => IV_DEF == 10 && IV_SPE == 10 && IV_SPC == 10 && (IV_ATK & 2) == 2;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override ushort Sanity { get => 0; set { } }
|
2016-08-31 20:52:30 +00:00
|
|
|
|
public override bool ChecksumValid => true;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override ushort Checksum { get => 0; set { } }
|
|
|
|
|
public override bool FatefulEncounter { get => false; set { } }
|
2016-08-31 20:52:30 +00:00
|
|
|
|
public override int TSV => 0x0000;
|
|
|
|
|
public override int PSV => 0xFFFF;
|
|
|
|
|
public override int Characteristic => -1;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int MarkValue { get => 0; protected set { } }
|
2018-04-26 01:45:31 +00:00
|
|
|
|
public override int Ability { get => -1; set { } }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int CurrentHandler { get => 0; set { } }
|
|
|
|
|
public override int Egg_Location { get => 0; set { } }
|
|
|
|
|
public override int OT_Friendship { get => 0; set { } }
|
|
|
|
|
public override int Ball { get => 0; set { } }
|
2018-06-11 14:23:48 +00:00
|
|
|
|
public override int Version { get => HasOriginalMetLocation ? (int)GameVersion.C : (int)GameVersion.GSC; set { } }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int SID { get => 0; set { } }
|
2016-08-31 20:52:30 +00:00
|
|
|
|
#endregion
|
2016-09-04 22:03:40 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Maximums
|
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_2;
|
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_2;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_2;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_2;
|
|
|
|
|
public override int MaxBallID => -1;
|
|
|
|
|
public override int MaxGameID => -1;
|
|
|
|
|
public override int MaxIV => 15;
|
|
|
|
|
public override int MaxEV => ushort.MaxValue;
|
|
|
|
|
public override int OTLength => Japanese ? 5 : 7;
|
|
|
|
|
public override int NickLength => Japanese ? 5 : 10;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public PK1 ConvertToPK1()
|
2016-09-04 22:03:40 +00:00
|
|
|
|
{
|
2017-08-24 17:08:01 +00:00
|
|
|
|
PK1 pk1 = new PK1(null, Identifier, Japanese) {TradebackStatus = TradebackType.WasTradeback};
|
2016-09-04 22:03:40 +00:00
|
|
|
|
Array.Copy(Data, 0x1, pk1.Data, 0x7, 0x1A);
|
|
|
|
|
pk1.Species = Species; // This will take care of Typing :)
|
|
|
|
|
pk1.Stat_HPCurrent = Stat_HPCurrent;
|
|
|
|
|
pk1.Stat_Level = Stat_Level;
|
|
|
|
|
// Status = 0
|
|
|
|
|
Array.Copy(otname, 0, pk1.otname, 0, otname.Length);
|
|
|
|
|
Array.Copy(nick, 0, pk1.nick, 0, nick.Length);
|
|
|
|
|
|
2018-06-05 04:28:14 +00:00
|
|
|
|
pk1.ClearInvalidMoves();
|
2016-09-04 22:33:53 +00:00
|
|
|
|
|
2016-09-04 22:03:40 +00:00
|
|
|
|
return pk1;
|
|
|
|
|
}
|
2017-06-10 22:48:12 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public PK7 ConvertToPK7()
|
2017-06-10 22:48:12 +00:00
|
|
|
|
{
|
|
|
|
|
var pk7 = new PK7
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
EncryptionConstant = Util.Rand32(),
|
2017-06-10 22:48:12 +00:00
|
|
|
|
Species = Species,
|
|
|
|
|
TID = TID,
|
|
|
|
|
CurrentLevel = CurrentLevel,
|
|
|
|
|
EXP = EXP,
|
|
|
|
|
Met_Level = CurrentLevel,
|
|
|
|
|
Nature = (int)(EXP % 25),
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PID = Util.Rand32(),
|
2017-06-10 22:48:12 +00:00
|
|
|
|
Ball = 4,
|
|
|
|
|
MetDate = DateTime.Now,
|
2017-11-25 02:12:30 +00:00
|
|
|
|
Version = CaughtData != 0 ? (int)GameVersion.C : (int)GameVersion.SV,
|
2017-06-10 22:48:12 +00:00
|
|
|
|
Move1 = Move1,
|
|
|
|
|
Move2 = Move2,
|
|
|
|
|
Move3 = Move3,
|
|
|
|
|
Move4 = Move4,
|
|
|
|
|
Move1_PPUps = Move1_PPUps,
|
|
|
|
|
Move2_PPUps = Move2_PPUps,
|
|
|
|
|
Move3_PPUps = Move3_PPUps,
|
|
|
|
|
Move4_PPUps = Move4_PPUps,
|
|
|
|
|
Move1_PP = Move1_PP,
|
|
|
|
|
Move2_PP = Move2_PP,
|
|
|
|
|
Move3_PP = Move3_PP,
|
|
|
|
|
Move4_PP = Move4_PP,
|
2017-11-24 18:13:42 +00:00
|
|
|
|
Met_Location = Legal.Transfer2, // "Johto region", hardcoded.
|
2017-09-06 16:12:56 +00:00
|
|
|
|
Gender = Gender,
|
2017-06-10 22:48:12 +00:00
|
|
|
|
IsNicknamed = false,
|
2017-09-22 22:38:17 +00:00
|
|
|
|
AltForm = AltForm,
|
2017-06-10 22:48:12 +00:00
|
|
|
|
|
|
|
|
|
Country = PKMConverter.Country,
|
|
|
|
|
Region = PKMConverter.Region,
|
|
|
|
|
ConsoleRegion = PKMConverter.ConsoleRegion,
|
|
|
|
|
CurrentHandler = 1,
|
|
|
|
|
HT_Name = PKMConverter.OT_Name,
|
|
|
|
|
HT_Gender = PKMConverter.OT_Gender,
|
|
|
|
|
Geo1_Country = PKMConverter.Country,
|
|
|
|
|
Geo1_Region = PKMConverter.Region
|
|
|
|
|
};
|
2017-10-22 23:52:46 +00:00
|
|
|
|
pk7.Language = GuessedLanguage(PKMConverter.Language);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk7.Nickname = PKX.GetSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
|
2018-07-10 23:45:24 +00:00
|
|
|
|
if (otname[0] == StringConverter.G1TradeOTCode) // Ingame Trade
|
|
|
|
|
pk7.OT_Name = Encounters1.TradeOTG1[pk7.Language];
|
2017-06-10 22:48:12 +00:00
|
|
|
|
pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship;
|
|
|
|
|
|
|
|
|
|
// IVs
|
|
|
|
|
var special = Species == 151 || Species == 251;
|
|
|
|
|
var new_ivs = new int[6];
|
|
|
|
|
int flawless = special ? 5 : 3;
|
2018-07-04 18:30:43 +00:00
|
|
|
|
for (var i = 0; i < new_ivs.Length; i++) new_ivs[i] = Util.Rand.Next(pk7.MaxIV + 1);
|
2017-06-10 22:48:12 +00:00
|
|
|
|
for (var i = 0; i < flawless; i++) new_ivs[i] = 31;
|
|
|
|
|
Util.Shuffle(new_ivs);
|
|
|
|
|
pk7.IVs = new_ivs;
|
|
|
|
|
|
|
|
|
|
if (IsShiny)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk7.SetShinyPID();
|
2017-06-10 22:48:12 +00:00
|
|
|
|
|
|
|
|
|
int abil = 2; // Hidden
|
|
|
|
|
if (Legal.TransferSpeciesDefaultAbility_2.Contains(Species))
|
|
|
|
|
abil = 0; // Reset
|
|
|
|
|
pk7.RefreshAbility(abil); // 0/1/2 (not 1/2/4)
|
|
|
|
|
|
|
|
|
|
if (special)
|
|
|
|
|
pk7.FatefulEncounter = true;
|
2017-09-23 03:34:29 +00:00
|
|
|
|
else if (IsNicknamedBank)
|
2017-06-10 22:48:12 +00:00
|
|
|
|
{
|
|
|
|
|
pk7.IsNicknamed = true;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
pk7.Nickname = Korean ? Nickname
|
2017-09-23 00:54:43 +00:00
|
|
|
|
: StringConverter.GetG1ConvertedString(nick, Japanese);
|
2017-06-10 22:48:12 +00:00
|
|
|
|
}
|
2017-09-23 00:54:43 +00:00
|
|
|
|
pk7.OT_Name = Korean ? OT_Name
|
|
|
|
|
: StringConverter.GetG1ConvertedString(otname, Japanese);
|
2017-11-23 05:45:30 +00:00
|
|
|
|
pk7.OT_Gender = OT_Gender; // Crystal
|
2017-06-10 22:48:12 +00:00
|
|
|
|
|
|
|
|
|
pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm
|
|
|
|
|
|
2018-01-26 03:17:42 +00:00
|
|
|
|
// Dizzy Punch cannot be transferred
|
|
|
|
|
{
|
|
|
|
|
var moves = pk7.Moves;
|
|
|
|
|
var index = Array.IndexOf(moves, 146); // Dizzy Punch
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
moves[index] = 0;
|
|
|
|
|
pk7.Moves = moves;
|
|
|
|
|
pk7.FixMoves();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-10 22:48:12 +00:00
|
|
|
|
pk7.RefreshChecksum();
|
|
|
|
|
return pk7;
|
|
|
|
|
}
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-04 06:54:11 +00:00
|
|
|
|
public class PokemonList2
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
2016-09-04 06:54:11 +00:00
|
|
|
|
private const int CAPACITY_DAYCARE = 1;
|
|
|
|
|
private const int CAPACITY_PARTY = 6;
|
|
|
|
|
private const int CAPACITY_STORED = 20;
|
|
|
|
|
private const int CAPACITY_STORED_JP = 30;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2016-09-04 06:54:11 +00:00
|
|
|
|
private readonly bool Japanese;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
|
|
|
|
private int StringLength => Japanese ? PK2.STRLEN_J : PK2.STRLEN_U;
|
|
|
|
|
|
|
|
|
|
public enum CapacityType
|
|
|
|
|
{
|
|
|
|
|
Daycare = CAPACITY_DAYCARE,
|
|
|
|
|
Party = CAPACITY_PARTY,
|
|
|
|
|
Stored = CAPACITY_STORED,
|
|
|
|
|
StoredJP = CAPACITY_STORED_JP,
|
|
|
|
|
Single
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int GetEntrySize(CapacityType c) => c == CapacityType.Single || c == CapacityType.Party
|
2017-05-13 03:32:36 +00:00
|
|
|
|
? PKX.SIZE_2PARTY
|
|
|
|
|
: PKX.SIZE_2STORED;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static byte GetCapacity(CapacityType c) => c == CapacityType.Single ? (byte)1 : (byte)c;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static byte[] GetEmptyList(CapacityType c, bool is_JP = false)
|
2016-08-31 20:52:30 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int cap = GetCapacity(c);
|
|
|
|
|
return new[] { (byte)0 }.Concat(Enumerable.Repeat((byte)0xFF, cap + 1)).Concat(Enumerable.Repeat((byte)0, GetEntrySize(c) * cap)).Concat(Enumerable.Repeat((byte)0x50, (is_JP ? PK2.STRLEN_J : PK2.STRLEN_U) * 2 * cap)).ToArray();
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PokemonList2(byte[] d, CapacityType c = CapacityType.Single, bool jp = false)
|
|
|
|
|
{
|
|
|
|
|
Japanese = jp;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data = d ?? GetEmptyList(c, Japanese);
|
|
|
|
|
Capacity = GetCapacity(c);
|
|
|
|
|
Entry_Size = GetEntrySize(c);
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
|
|
|
|
if (Data.Length != DataSize)
|
|
|
|
|
{
|
|
|
|
|
Array.Resize(ref Data, DataSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pokemon = new PK2[Capacity];
|
|
|
|
|
for (int i = 0; i < Capacity; i++)
|
|
|
|
|
{
|
|
|
|
|
int base_ofs = 2 + Capacity;
|
2017-10-06 05:37:45 +00:00
|
|
|
|
byte[] dat = new byte[Entry_Size];
|
|
|
|
|
byte[] otname = new byte[StringLength];
|
|
|
|
|
byte[] nick = new byte[StringLength];
|
|
|
|
|
Buffer.BlockCopy(Data, base_ofs + Entry_Size * i, dat, 0, Entry_Size);
|
|
|
|
|
Buffer.BlockCopy(Data, base_ofs + Capacity * Entry_Size + StringLength * i, otname, 0, StringLength);
|
|
|
|
|
Buffer.BlockCopy(Data, base_ofs + Capacity * Entry_Size + StringLength * (i + Capacity), nick, 0, StringLength);
|
|
|
|
|
Pokemon[i] = new PK2(dat, null, jp) {IsEgg = Data[1 + i] == 0xFD, otname = otname, nick = nick};
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PokemonList2(CapacityType c = CapacityType.Single, bool jp = false)
|
2017-05-13 03:32:36 +00:00
|
|
|
|
: this(null, c, jp) => Count = 1;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
|
|
|
|
|
public PokemonList2(PK2 pk)
|
|
|
|
|
: this(CapacityType.Single, pk.Japanese)
|
|
|
|
|
{
|
|
|
|
|
this[0] = pk;
|
|
|
|
|
Count = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly byte[] Data;
|
|
|
|
|
private readonly byte Capacity;
|
|
|
|
|
private readonly int Entry_Size;
|
|
|
|
|
|
|
|
|
|
public byte Count
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[0];
|
|
|
|
|
set => Data[0] = value > Capacity ? Capacity : value;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public readonly PK2[] Pokemon;
|
|
|
|
|
|
|
|
|
|
public PK2 this[int i]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (i > Capacity || i < 0) throw new ArgumentOutOfRangeException($"Invalid PokemonList Access: {i}");
|
2016-08-31 20:52:30 +00:00
|
|
|
|
return Pokemon[i];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null) return;
|
2016-09-04 06:54:11 +00:00
|
|
|
|
Pokemon[i] = (PK2)value.Clone();
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2017-10-06 05:37:45 +00:00
|
|
|
|
int count = Array.FindIndex(Pokemon, pk => pk.Species == 0);
|
|
|
|
|
Count = count < 0 ? Capacity : (byte)count;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
for (int i = 0; i < Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Data[1 + i] = Pokemon[i].IsEgg ? (byte)0xFD : (byte)Pokemon[i].Species;
|
|
|
|
|
Array.Copy(Pokemon[i].Data, 0, Data, 2 + Capacity + Entry_Size * i, Entry_Size);
|
|
|
|
|
Array.Copy(Pokemon[i].OT_Name_Raw, 0, Data, 2 + Capacity + Capacity * Entry_Size + StringLength * i, StringLength);
|
|
|
|
|
Array.Copy(Pokemon[i].Nickname_Raw, 0, Data, 2 + Capacity + Capacity * Entry_Size + StringLength * Capacity + StringLength * i, StringLength);
|
|
|
|
|
}
|
|
|
|
|
Data[1 + Count] = byte.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] GetBytes()
|
|
|
|
|
{
|
|
|
|
|
Update();
|
|
|
|
|
return Data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int DataSize => Capacity * (Entry_Size + 1 + 2 * StringLength) + 2;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static int GetDataLength(CapacityType c, bool jp = false) => GetCapacity(c) * (GetEntrySize(c) + 1 + 2 * (jp ? PK2.STRLEN_J : PK2.STRLEN_U)) + 2;
|
2016-08-31 20:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|