/// <summary> /// Creates an instance of <see cref="PKM"/> from the given data. /// </summary> /// <param name="data">Raw data of the Pokemon file.</param> /// <param name="ident">Optional identifier for the Pokemon. Usually the full path of the source file.</param> /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns> public static PKM getPKMfromBytes(byte[] data, string ident = null) { checkEncrypted(ref data); switch (getPKMDataFormat(data)) { case 1: var PL1 = new PokemonList1(data, PokemonList1.CapacityType.Single, data.Length == PKX.SIZE_1JLIST); if (ident != null) { PL1[0].Identifier = ident; } return(PL1[0]); case 2: var PL2 = new PokemonList2(data, PokemonList2.CapacityType.Single, data.Length == PKX.SIZE_2JLIST); if (ident != null) { PL2[0].Identifier = ident; } return(PL2[0]); case 3: switch (data.Length) { case PKX.SIZE_3CSTORED: return(new CK3(data, ident)); case PKX.SIZE_3XSTORED: return(new XK3(data, ident)); default: return(new PK3(data, ident)); } case 4: var pk = new PK4(data, ident); if (!pk.Valid || pk.Sanity != 0) { var bk = new BK4(data, ident); if (bk.Valid) { return(bk); } } return(pk); case 5: return(new PK5(data, ident)); case 6: PKM pkx = new PK6(data, ident); if (pkx.SM) { pkx = new PK7(data, ident); } return(pkx); default: return(null); } }
/// <summary> /// Creates an instance of <see cref="PKM"/> from the given data. /// </summary> /// <param name="data">Raw data of the Pokemon file.</param> /// <param name="ident">Optional identifier for the Pokemon. Usually the full path of the source file.</param> /// <param name="prefer">Optional identifier for the preferred generation. Usually the generation of the destination save file.</param> /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns> public static PKM GetPKMfromBytes(byte[] data, string ident = null, int prefer = 7) { int format = GetPKMDataFormat(data); switch (format) { case 1: var PL1 = new PokeList1(data); if (ident != null) { PL1[0].Identifier = ident; } return(PL1[0]); case 2: var PL2 = new PokeList2(data); if (ident != null) { PL2[0].Identifier = ident; } return(PL2[0]); case 3: switch (data.Length) { case PKX.SIZE_3CSTORED: return(new CK3(data, ident)); case PKX.SIZE_3XSTORED: return(new XK3(data, ident)); default: return(new PK3(data, ident)); } case 4: var pk = new PK4(data, ident); if (!pk.Valid || pk.Sanity != 0) { var bk = new BK4(data, ident); if (bk.Valid) { return(bk); } } return(pk); case 5: return(new PK5(data, ident)); case 6: var pkx = new PK6(data, ident); return(CheckPKMFormat7(pkx, prefer)); default: return(null); } }
private void refreshData(byte[] data) { byte[] ekdata = new byte[PKX.SIZE_4PARTY]; Array.Copy(data, 8, ekdata, 0, ekdata.Length); bool empty = ekdata.SequenceEqual(new byte[ekdata.Length]); PK = new PK4(empty ? ekdata : PKX.decryptArray45(ekdata)); Unknown = new byte[0x10]; Array.Copy(data, 0xF4, Unknown, 0, 0x10); RAW = data; }
public PK4 convertToPK4() { PK4 pk4 = new PK4(); TransferPropertiesWithReflection(this, pk4); // Fix Non-Reflectable properties Array.Copy(Data, 0x78, pk4.Data, 0x78, 6); // Met Info // Preserve Trash Bytes for (int i = 0; i < 11; i++) // Nickname { pk4.Data[0x48 + 2 * i] = Data[0x48 + 2 * i + 1]; pk4.Data[0x48 + 2 * i + 1] = Data[0x48 + 2 * i]; } for (int i = 0; i < 8; i++) // OT_Name { pk4.Data[0x68 + 2 * i] = Data[0x68 + 2 * i + 1]; pk4.Data[0x68 + 2 * i + 1] = Data[0x68 + 2 * i]; } pk4.Sanity = 0; pk4.RefreshChecksum(); return(pk4); }
public override void CopyTo(PK4 pk4) => pk4.SetHeldMailData(Data);
private static bool GetIsMatchPCD(PKM pkm, PK4 wc, IEnumerable <DexLevel> vs) { if (!wc.IsEgg) { if (wc.TID != pkm.TID) { return(false); } if (wc.SID != pkm.SID) { return(false); } if (wc.OT_Name != pkm.OT_Name) { return(false); } if (wc.OT_Gender != pkm.OT_Gender) { return(false); } if (wc.Language != 0 && wc.Language != pkm.Language) { return(false); } if (pkm.Format != 4) // transferred { // met location: deferred to general transfer check if (wc.CurrentLevel > pkm.Met_Level) { return(false); } } else { if (wc.Egg_Location + 3000 != pkm.Met_Location) { return(false); } if (wc.CurrentLevel != pkm.Met_Level) { return(false); } } } else // Egg { if (wc.Egg_Location + 3000 != pkm.Egg_Location && pkm.Egg_Location != 2002) // traded { return(false); } if (wc.CurrentLevel != pkm.Met_Level) { return(false); } if (pkm.IsEgg && !pkm.IsNative) { return(false); } } if (wc.AltForm != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species))) { return(false); } if (wc.Ball != pkm.Ball) { return(false); } if (wc.OT_Gender < 3 && wc.OT_Gender != pkm.OT_Gender) { return(false); } if (wc.PID == 1 && pkm.IsShiny) { return(false); } if (wc.Gender != 3 && wc.Gender != pkm.Gender) { return(false); } if (pkm is IContestStats s && s.IsContestBelow(wc)) { return(false); } return(true); }
public override void CopyTo(PK4 pk4) => pk4.HeldMailData = Data;
/// <summary> /// Creates an instance of <see cref="PKM"/> from the given data. /// </summary> /// <param name="data">Raw data of the Pokemon file.</param> /// <param name="ident">Optional identifier for the Pokemon. Usually the full path of the source file.</param> /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns> public static PKM getPKMfromBytes(byte[] data, string ident = null) { checkEncrypted(ref data); switch (getPKMDataFormat(data)) { case 1: var PL1 = new PokemonList1(data, PokemonList1.CapacityType.Single, data.Length == PKX.SIZE_1JLIST); if (ident != null) PL1[0].Identifier = ident; return PL1[0]; case 2: var PL2 = new PokemonList2(data, PokemonList2.CapacityType.Single, data.Length == PKX.SIZE_2JLIST); if (ident != null) PL2[0].Identifier = ident; return PL2[0]; case 3: switch (data.Length) { case PKX.SIZE_3CSTORED: return new CK3(data, ident); case PKX.SIZE_3XSTORED: return new XK3(data, ident); default: return new PK3(data, ident); } case 4: var pk = new PK4(data, ident); if (!pk.Valid || pk.Sanity != 0) { var bk = new BK4(data, ident); if (bk.Valid) return bk; } return pk; case 5: return new PK5(data, ident); case 6: PKM pkx = new PK6(data, ident); if (pkx.SM) pkx = new PK7(data, ident); return pkx; default: return null; } }
public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) { return(null); } PK4 pk4 = new PK4(PK.Data); if (!IsHatched && Detail == 0) { pk4.OT_Name = SAV.OT; pk4.TID = SAV.TID; pk4.SID = SAV.SID; pk4.OT_Gender = SAV.Gender; } if (IsManaphyEgg) { // Since none of this data is populated, fill in default info. pk4.Species = 490; // Level 1 Moves pk4.Move1 = 294; pk4.Move2 = 145; pk4.Move3 = 346; pk4.FatefulEncounter = true; pk4.Ball = 4; pk4.Version = 10; // Diamond pk4.Language = 2; // English pk4.Nickname = "MANAPHY"; pk4.Egg_Location = 1; // Ranger (will be +3000 later) } // Generate IV uint seed = Util.rnd32(); if (pk4.PID == 1 || IsManaphyEgg) // Create Nonshiny { uint pid1 = PKX.LCRNG(ref seed) >> 16; uint pid2 = PKX.LCRNG(ref seed) >> 16; while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8) { uint testPID = pid1 | pid2 << 16; // Call the ARNG to change the PID testPID = testPID * 0x6c078965 + 1; pid1 = testPID & 0xFFFF; pid2 = testPID >> 16; } pk4.PID = pid1 | (pid2 << 16); } // Generate IVs if (pk4.IV32 == 0) { uint iv1 = PKX.LCRNG(ref seed) >> 16; uint iv2 = PKX.LCRNG(ref seed) >> 16; pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF; } // Generate Met Info if (IsPokémon) { pk4.Met_Location = pk4.Egg_Location + 3000; pk4.Egg_Location = 0; pk4.MetDate = DateTime.Now; pk4.IsEgg = false; } else { pk4.Egg_Location = pk4.Egg_Location + 3000; pk4.MetDate = DateTime.Now; pk4.IsEgg = false; // Met Location is modified when transferred to pk5; don't worry about it. } if (pk4.Species == 201) // Never will be true; Unown was never distributed. { pk4.AltForm = PKX.getUnownForm(pk4.PID); } if (IsEgg || IsManaphyEgg) { pk4.IsEgg = true; } pk4.RefreshChecksum(); return(pk4); }
public PK4 convertToPK4() { PK4 pk4 = new PK4(); TransferPropertiesWithReflection(this, pk4); // Fix Non-Reflectable properties Array.Copy(Data, 0x78, pk4.Data, 0x78, 6); // Met Info // Preserve Trash Bytes for (int i = 0; i < 11; i++) // Nickname { pk4.Data[0x48 + 2*i] = Data[0x48 + 2*i + 1]; pk4.Data[0x48 + 2*i + 1] = Data[0x48 + 2*i]; } for (int i = 0; i < 8; i++) // OT_Name { pk4.Data[0x68 + 2*i] = Data[0x68 + 2*i + 1]; pk4.Data[0x68 + 2*i + 1] = Data[0x68 + 2*i]; } pk4.Sanity = 0; pk4.RefreshChecksum(); return pk4; }
public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) return null; PK4 pk4 = new PK4(PK.Data); if (!IsHatched && Detail == 0) { pk4.OT_Name = SAV.OT; pk4.TID = SAV.TID; pk4.SID = SAV.SID; pk4.OT_Gender = SAV.Gender; } if (IsManaphyEgg) { // Since none of this data is populated, fill in default info. pk4.Species = 490; // Level 1 Moves pk4.Move1 = 294; pk4.Move2 = 145; pk4.Move3 = 346; pk4.FatefulEncounter = true; pk4.Ball = 4; pk4.Version = 10; // Diamond pk4.Language = 2; // English pk4.Nickname = "MANAPHY"; pk4.Egg_Location = 1; // Ranger (will be +3000 later) } // Generate IV uint seed = Util.rnd32(); if (pk4.PID == 1 || IsManaphyEgg) // Create Nonshiny { uint pid1 = PKX.LCRNG(ref seed) >> 16; uint pid2 = PKX.LCRNG(ref seed) >> 16; while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8) { uint testPID = pid1 | pid2 << 16; // Call the ARNG to change the PID testPID = testPID * 0x6c078965 + 1; pid1 = testPID & 0xFFFF; pid2 = testPID >> 16; } pk4.PID = pid1 | (pid2 << 16); } // Generate IVs if (pk4.IV32 == 0) { uint iv1 = PKX.LCRNG(ref seed) >> 16; uint iv2 = PKX.LCRNG(ref seed) >> 16; pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF; } // Generate Met Info if (IsPokémon) { pk4.Met_Location = pk4.Egg_Location + 3000; pk4.Egg_Location = 0; pk4.MetDate = DateTime.Now; pk4.IsEgg = false; } else { pk4.Egg_Location = pk4.Egg_Location + 3000; pk4.MetDate = DateTime.Now; pk4.IsEgg = false; // Met Location is modified when transferred to pk5; don't worry about it. } if (pk4.Species == 201) // Never will be true; Unown was never distributed. pk4.AltForm = PKX.getUnownForm(pk4.PID); if (IsEgg || IsManaphyEgg) pk4.IsEgg = true; pk4.RefreshChecksum(); return pk4; }
public override void CopyTo(PK4 pk4) => Data.CopyTo(pk4.HeldMail);