Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        public PGT(byte[] data = null)
        {
            Data = data ?? new byte[Size];
            byte[] ekdata = new byte[PK4.SIZE_PARTY];
            Array.Copy(Data, 8, ekdata, 0, ekdata.Length);
            // Decrypt PK4
            PK = new PK4(PKM.decryptArray(ekdata, BitConverter.ToUInt16(ekdata, 6)));

            Unknown = new byte[0x10];
            Array.Copy(Data, 0xF4, Unknown, 0, 0x10);
        }
Esempio n. 3
0
 public PGT(byte[] data = null)
 {
     Data = data ?? new byte[Size];
     byte[] ekdata = new byte[PK4.SIZE_PARTY];
     Array.Copy(Data, 8, ekdata, 0, ekdata.Length);
     // Decrypt PK4
     PK = new PK4(PKM.decryptArray(ekdata, BitConverter.ToUInt16(ekdata, 6)));
     
     Unknown = new byte[0x10];
     Array.Copy(Data, 0xF4, Unknown, 0, 0x10);
 }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        private void populateFieldsPK4()
        {
            PK4 pk4 = pkm as PK4;

            if (pk4 == null)
            {
                return;
            }

            // Do first
            pk4.Stat_Level = PKX.getLevel(pk4.Species, pk4.EXP);
            if (pk4.Stat_Level == 100)
            {
                pk4.EXP = PKX.getEXP(pk4.Stat_Level, pk4.Species);
            }

            CB_Species.SelectedValue = pk4.Species;
            TB_Level.Text            = pk4.Stat_Level.ToString();
            TB_EXP.Text = pk4.EXP.ToString();

            // Load rest
            CHK_Fateful.Checked      = pk4.FatefulEncounter;
            CHK_IsEgg.Checked        = pk4.IsEgg;
            CHK_Nicknamed.Checked    = pk4.IsNicknamed;
            Label_OTGender.Text      = gendersymbols[pk4.OT_Gender];
            Label_OTGender.ForeColor = pk4.OT_Gender == 1 ? Color.Red : Color.Blue;
            TB_PID.Text = pk4.PID.ToString("X8");
            CB_HeldItem.SelectedValue = pk4.HeldItem;
            setAbilityList();
            CB_Nature.SelectedValue = pk4.Nature;
            TB_TID.Text             = pk4.TID.ToString("00000");
            TB_SID.Text             = pk4.SID.ToString("00000");
            TB_Nickname.Text        = pk4.Nickname;
            TB_OT.Text                     = pk4.OT_Name;
            TB_Friendship.Text             = pk4.CurrentFriendship.ToString();
            GB_OT.BackgroundImage          = null;
            CB_Language.SelectedValue      = pk4.Language;
            CB_GameOrigin.SelectedValue    = pk4.Version;
            CB_EncounterType.SelectedValue = pk4.Gen4 ? pk4.EncounterType : 0;
            CB_Ball.SelectedValue          = pk4.Ball;

            if (pk4.MetDate.HasValue)
            {
                CAL_MetDate.Value = pk4.MetDate.Value;
            }
            else
            {
                CAL_MetDate.Value = new DateTime(2000, 1, 1);
            }

            if (pk4.Egg_Location != 0)
            {
                // Was obtained initially as an egg.
                CHK_AsEgg.Checked        = true;
                GB_EggConditions.Enabled = true;

                CB_EggLocation.SelectedValue = pk4.Egg_Location;
                if (pk4.EggMetDate.HasValue)
                {
                    CAL_EggDate.Value = pk4.EggMetDate.Value;
                }
                else
                {
                    CAL_EggDate.Value = new DateTime(2000, 1, 1);
                }
            }
            else
            {
                CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0;
            }

            CB_MetLocation.SelectedValue = pk4.Met_Location;

            TB_MetLevel.Text = pk4.Met_Level.ToString();

            // Reset Label and ComboBox visibility, as well as non-data checked status.
            Label_PKRS.Visible     = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk4.PKRS_Strain != 0;
            Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk4.PKRS_Days != 0;

            // Set SelectedIndexes for PKRS
            CB_PKRSStrain.SelectedIndex = pk4.PKRS_Strain;
            CHK_Cured.Checked           = pk4.PKRS_Strain > 0 && pk4.PKRS_Days == 0;
            CB_PKRSDays.SelectedIndex   = Math.Min(CB_PKRSDays.Items.Count - 1, pk4.PKRS_Days); // to strip out bad hacked 'rus

            TB_Cool.Text   = pk4.CNT_Cool.ToString();
            TB_Beauty.Text = pk4.CNT_Beauty.ToString();
            TB_Cute.Text   = pk4.CNT_Cute.ToString();
            TB_Smart.Text  = pk4.CNT_Smart.ToString();
            TB_Tough.Text  = pk4.CNT_Tough.ToString();
            TB_Sheen.Text  = pk4.CNT_Sheen.ToString();

            TB_HPIV.Text            = pk4.IV_HP.ToString();
            TB_ATKIV.Text           = pk4.IV_ATK.ToString();
            TB_DEFIV.Text           = pk4.IV_DEF.ToString();
            TB_SPEIV.Text           = pk4.IV_SPE.ToString();
            TB_SPAIV.Text           = pk4.IV_SPA.ToString();
            TB_SPDIV.Text           = pk4.IV_SPD.ToString();
            CB_HPType.SelectedValue = pk4.HPType;

            TB_HPEV.Text  = pk4.EV_HP.ToString();
            TB_ATKEV.Text = pk4.EV_ATK.ToString();
            TB_DEFEV.Text = pk4.EV_DEF.ToString();
            TB_SPEEV.Text = pk4.EV_SPE.ToString();
            TB_SPAEV.Text = pk4.EV_SPA.ToString();
            TB_SPDEV.Text = pk4.EV_SPD.ToString();

            CB_Move1.SelectedValue = pk4.Move1;
            CB_Move2.SelectedValue = pk4.Move2;
            CB_Move3.SelectedValue = pk4.Move3;
            CB_Move4.SelectedValue = pk4.Move4;
            CB_PPu1.SelectedIndex  = pk4.Move1_PPUps;
            CB_PPu2.SelectedIndex  = pk4.Move2_PPUps;
            CB_PPu3.SelectedIndex  = pk4.Move3_PPUps;
            CB_PPu4.SelectedIndex  = pk4.Move4_PPUps;
            TB_PP1.Text            = pk4.Move1_PP.ToString();
            TB_PP2.Text            = pk4.Move2_PP.ToString();
            TB_PP3.Text            = pk4.Move3_PP.ToString();
            TB_PP4.Text            = pk4.Move4_PP.ToString();

            // Set Form if count is enough, else cap.
            CB_Form.SelectedIndex = CB_Form.Items.Count > pk4.AltForm ? pk4.AltForm : CB_Form.Items.Count - 1;

            // Load Extrabyte Value
            TB_ExtraByte.Text = pk4.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();

            updateStats();

            TB_EXP.Text            = pk4.EXP.ToString();
            Label_Gender.Text      = gendersymbols[pk4.Gender];
            Label_Gender.ForeColor = pk4.Gender == 2 ? Label_Species.ForeColor : (pk4.Gender == 1 ? Color.Red : Color.Blue);

            if (HaX)
            {
                DEV_Ability.SelectedValue = pk4.Ability;
            }
            else
            {
                int[] abils = SAV.Personal.getAbilities(pk4.Species, pk4.AltForm);
                int   abil  = Array.IndexOf(abils, pk4.Ability);

                if (abil < 0)
                {
                    CB_Ability.SelectedIndex = 0;
                }
                else if (abil == 2)
                {
                    CB_Ability.SelectedIndex = 2;
                }
                else if (abils[0] == abils[1] || abils[1] == 0)
                {
                    CB_Ability.SelectedIndex = pk4.PIDAbility;
                }
                else
                {
                    CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
                }
            }
        }
Esempio n. 7
0
        private PKM preparePK4()
        {
            PK4 pk4 = pkm as PK4;

            if (pk4 == null)
            {
                return(null);
            }

            pk4.Species  = Util.getIndex(CB_Species);
            pk4.HeldItem = Util.getIndex(CB_HeldItem);
            pk4.TID      = Util.ToInt32(TB_TID.Text);
            pk4.SID      = Util.ToInt32(TB_SID.Text);
            pk4.EXP      = Util.ToUInt32(TB_EXP.Text);
            pk4.PID      = Util.getHEXval(TB_PID.Text);
            pk4.Ability  = (byte)Array.IndexOf(abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4));

            pk4.FatefulEncounter = CHK_Fateful.Checked;
            pk4.Gender           = PKX.getGender(Label_Gender.Text);
            pk4.AltForm          = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F;
            pk4.EV_HP            = Util.ToInt32(TB_HPEV.Text);
            pk4.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk4.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk4.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk4.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk4.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk4.CNT_Cool   = Util.ToInt32(TB_Cool.Text);
            pk4.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk4.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk4.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk4.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk4.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk4.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk4.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            pk4.Nickname    = TB_Nickname.Text;
            pk4.Move1       = Util.getIndex(CB_Move1);
            pk4.Move2       = Util.getIndex(CB_Move2);
            pk4.Move3       = Util.getIndex(CB_Move3);
            pk4.Move4       = Util.getIndex(CB_Move4);
            pk4.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk4.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk4.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk4.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk4.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk4.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk4.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk4.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk4.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk4.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk4.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk4.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk4.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk4.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk4.IsEgg       = CHK_IsEgg.Checked;
            pk4.IsNicknamed = CHK_Nicknamed.Checked;

            pk4.OT_Name           = TB_OT.Text;
            pk4.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            pk4.Ball          = Util.getIndex(CB_Ball);
            pk4.Met_Level     = Util.ToInt32(TB_MetLevel.Text);
            pk4.OT_Gender     = PKX.getGender(Label_OTGender.Text);
            pk4.EncounterType = Util.getIndex(CB_EncounterType);
            pk4.Version       = Util.getIndex(CB_GameOrigin);
            pk4.Language      = Util.getIndex(CB_Language);

            // Default Dates
            DateTime?egg_date     = null;
            int      egg_location = 0;

            if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields.
            {
                egg_date     = CAL_EggDate.Value;
                egg_location = Util.getIndex(CB_EggLocation);
            }
            // Egg Met Data
            pk4.EggMetDate   = egg_date;
            pk4.Egg_Location = egg_location;
            // Met Data
            pk4.MetDate      = CAL_MetDate.Value;
            pk4.Met_Location = Util.getIndex(CB_MetLocation);

            if (pk4.IsEgg && pk4.Met_Location == 0)    // If still an egg, it has no hatch location/date. Zero it!
            {
                pk4.MetDate = null;
            }

            // Toss in Party Stats
            Array.Resize(ref pk4.Data, pk4.SIZE_PARTY);
            pk4.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk4.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk4.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk4.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk4.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk4.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk4.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk4.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk4.Ability    = (byte)Util.getIndex(DEV_Ability);
                pk4.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk4.FixMoves();

            pk4.RefreshChecksum();
            return(pk4);
        }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
        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;
        }
Esempio n. 10
0
        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;
        }
Esempio n. 11
0
        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);
        }
 /// <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;
     }
 }