public PokemonList2(byte[] d, CapacityType c = CapacityType.Single, bool jp = false) { Japanese = jp; Data = d ?? getEmptyList(c, Japanese); Capacity = getCapacity(c); Entry_Size = getEntrySize(c); 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; byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray(); Pokemon[i] = new PK2(dat, null, jp) { IsEgg = Data[1 + i] == 0xFD, otname = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * i).Take(StringLength).ToArray(), nick = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * Capacity + StringLength * i) .Take(StringLength).ToArray() }; } }
public override PKM Clone() { PK2 new_pk2 = new PK2(Data, Identifier, Japanese); Array.Copy(otname, 0, new_pk2.otname, 0, otname.Length); Array.Copy(nick, 0, new_pk2.nick, 0, nick.Length); new_pk2.IsEgg = IsEgg; return new_pk2; }
public override PKM Clone() { PK2 new_pk2 = new PK2(Data, Identifier, Japanese); Array.Copy(otname, 0, new_pk2.otname, 0, otname.Length); Array.Copy(nick, 0, new_pk2.nick, 0, nick.Length); new_pk2.IsEgg = IsEgg; return(new_pk2); }
public override PKM Clone() { var clone = new PK2((byte[])Data.Clone(), Japanese) { IsEgg = IsEgg }; OT_Trash.CopyTo(clone.OT_Trash); Nickname_Trash.CopyTo(clone.Nickname_Trash); return(clone); }
public PK2 convertToPK2() { PK2 pk2 = new PK2(null, Identifier, Japanese) { Species = Species }; Array.Copy(Data, 0x7, pk2.Data, 0x1, 0x1A); // https://github.com/pret/pokecrystal/blob/master/engine/link.asm#L1132 if (!Legal.HeldItems_GSC.Contains((ushort)pk2.HeldItem)) { switch (pk2.HeldItem) { case 0x19: pk2.HeldItem = 0x92; // Leftovers break; case 0x2D: pk2.HeldItem = 0x53; // Bitter Berry break; case 0x32: pk2.HeldItem = 0xAE; // Leftovers break; case 0x5A: case 0x64: case 0x78: case 0x87: case 0xBE: case 0xC3: case 0xDC: case 0xFA: case 0xFF: pk2.HeldItem = 0xAD; // Berry break; } } pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship; // Pokerus = 0 // Caught Data = 0 pk2.Stat_Level = PKX.getLevel(Species, EXP); Array.Copy(otname, 0, pk2.otname, 0, otname.Length); Array.Copy(nick, 0, pk2.nick, 0, nick.Length); return(pk2); }
protected override byte[] GetFinalData() { int splitAtIndex = (Japanese ? 6 : 7); for (int i = 0; i < BoxCount; i++) { var boxPL = new PokeList2(Japanese ? PokeListType.StoredJP : PokeListType.Stored, Japanese); int slot = 0; for (int j = 0; j < boxPL.Pokemon.Length; j++) { PK2 boxPK = (PK2)GetPKM(GetData(GetBoxOffset(i) + (j * SIZE_STORED), SIZE_STORED)); if (boxPK.Species > 0) { boxPL[slot++] = boxPK; } } int src = GetBoxRawDataOffset(i, splitAtIndex); boxPL.Write().CopyTo(Data, src); if (i == CurrentBox) { boxPL.Write().CopyTo(Data, Offsets.CurrentBox); } } var partyPL = new PokeList2(PokeListType.Party, Japanese); int pSlot = 0; for (int i = 0; i < 6; i++) { PK2 partyPK = (PK2)GetPKM(GetData(GetPartyOffset(i), SIZE_STORED)); if (partyPK.Species > 0) { partyPL[pSlot++] = partyPK; } } partyPL.Write().CopyTo(Data, Offsets.Party); SetChecksums(); if (Japanese) { switch (Version) { case GameVersion.GS: Array.Copy(Data, Offsets.Trainer1, Data, 0x7209, 0xC83); break; case GameVersion.C: Array.Copy(Data, Offsets.Trainer1, Data, 0x7209, 0xADA); break; } } else if (Korean) { // Calculate oddball checksum ushort sum = 0; ushort[][] offsetpairs = { new ushort[] { 0x106B, 0x1533 }, new ushort[] { 0x1534, 0x1A12 }, new ushort[] { 0x1A13, 0x1C38 }, new ushort[] { 0x3DD8, 0x3F79 }, new ushort[] { 0x7E39, 0x7E6A }, }; foreach (ushort[] p in offsetpairs) { for (int i = p[0]; i < p[1]; i++) { sum += Data[i]; } } BitConverter.GetBytes(sum).CopyTo(Data, 0x7E6B); } else { switch (Version) { case GameVersion.GS: Array.Copy(Data, 0x2009, Data, 0x15C7, 0x222F - 0x2009); Array.Copy(Data, 0x222F, Data, 0x3D69, 0x23D9 - 0x222F); Array.Copy(Data, 0x23D9, Data, 0x0C6B, 0x2856 - 0x23D9); Array.Copy(Data, 0x2856, Data, 0x7E39, 0x288A - 0x2856); Array.Copy(Data, 0x288A, Data, 0x10E8, 0x2D69 - 0x288A); break; case GameVersion.C: Array.Copy(Data, 0x2009, Data, 0x1209, 0xB7A); break; } } byte[] outData = new byte[Data.Length - SIZE_RESERVED]; Array.Copy(Data, outData, outData.Length); return(outData); }
private const int SIZE_RESERVED = 0x8000; // unpacked box data protected override byte[] Write(bool DSV) { for (int i = 0; i < BoxCount; i++) { PokemonList2 boxPL = new PokemonList2(Japanese ? PokemonList2.CapacityType.StoredJP : PokemonList2.CapacityType.Stored, Japanese); int slot = 0; for (int j = 0; j < boxPL.Pokemon.Length; j++) { PK2 boxPK = (PK2)GetPKM(GetData(GetBoxOffset(i) + j * SIZE_STORED, SIZE_STORED)); if (boxPK.Species > 0) { boxPL[slot++] = boxPK; } } if (i < (Japanese ? 6 : 7)) { boxPL.GetBytes().CopyTo(Data, 0x4000 + i * (SIZE_STOREDBOX + 2)); } else { boxPL.GetBytes().CopyTo(Data, 0x6000 + (i - (Japanese ? 6 : 7)) * (SIZE_STOREDBOX + 2)); } if (i == CurrentBox) { boxPL.GetBytes().CopyTo(Data, CurrentBoxOffset); } } PokemonList2 partyPL = new PokemonList2(PokemonList2.CapacityType.Party, Japanese); int pSlot = 0; for (int i = 0; i < 6; i++) { PK2 partyPK = (PK2)GetPKM(GetData(GetPartyOffset(i), SIZE_STORED)); if (partyPK.Species > 0) { partyPL[pSlot++] = partyPK; } } partyPL.GetBytes().CopyTo(Data, PartyOffset); SetChecksums(); if (Version == GameVersion.C && !Japanese) { Array.Copy(Data, 0x2009, Data, 0x1209, 0xB7A); } if (Version == GameVersion.C && Japanese) { Array.Copy(Data, 0x2009, Data, 0x7209, 0xADA); } if (Version == GameVersion.GS && !Japanese) { Array.Copy(Data, 0x2009, Data, 0x15C7, 0x222F - 0x2009); Array.Copy(Data, 0x222F, Data, 0x3D69, 0x23D9 - 0x222F); Array.Copy(Data, 0x23D9, Data, 0x0C6B, 0x2856 - 0x23D9); Array.Copy(Data, 0x2856, Data, 0x7E39, 0x288A - 0x2856); Array.Copy(Data, 0x288A, Data, 0x10E8, 0x2D69 - 0x288A); } if (Version == GameVersion.GS && Japanese) { Array.Copy(Data, 0x2009, Data, 0x7209, 0xC83); } byte[] outData = new byte[Data.Length - SIZE_RESERVED]; Array.Copy(Data, outData, outData.Length); return(outData); }
public PokemonList2(PK2 pk) : this(CapacityType.Single, pk.Japanese) { this[0] = pk; Count = 1; }
public PK2 convertToPK2() { PK2 pk2 = new PK2(null, Identifier, Japanese) {Species = Species}; Array.Copy(Data, 0x7, pk2.Data, 0x1, 0x1A); // https://github.com/pret/pokecrystal/blob/master/engine/link.asm#L1132 if (!Legal.HeldItems_GSC.Contains((ushort)pk2.HeldItem)) switch (pk2.HeldItem) { case 0x19: pk2.HeldItem = 0x92; // Leftovers break; case 0x2D: pk2.HeldItem = 0x53; // Bitter Berry break; case 0x32: pk2.HeldItem = 0xAE; // Leftovers break; case 0x5A: case 0x64: case 0x78: case 0x87: case 0xBE: case 0xC3: case 0xDC: case 0xFA: case 0xFF: pk2.HeldItem = 0xAD; // Berry break; } pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship; // Pokerus = 0 // Caught Data = 0 pk2.Stat_Level = PKX.getLevel(Species, EXP); Array.Copy(otname, 0, pk2.otname, 0, otname.Length); Array.Copy(nick, 0, pk2.nick, 0, nick.Length); return pk2; }
public PokemonList2(byte[] d, CapacityType c = CapacityType.Single, bool jp = false) { Japanese = jp; Data = d ?? getEmptyList(c, Japanese); Capacity = getCapacity(c); Entry_Size = getEntrySize(c); 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; byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray(); Pokemon[i] = new PK2(dat, null, jp) { IsEgg = Data[1 + i] == 0xFD, otname = Data.Skip(base_ofs + Capacity*Entry_Size + StringLength*i).Take(StringLength).ToArray(), nick = Data.Skip(base_ofs + Capacity*Entry_Size + StringLength*Capacity + StringLength*i) .Take(StringLength).ToArray() }; } }