Beispiel #1
0
        public override PKM getPKM(byte[] data)
        {
            byte[] pkm = data.Take(SIZE_STORED).ToArray();
            PKM    bk  = new BK4(pkm);

            return(bk);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
 public static BK4 ReadUnshuffle(ReadOnlySpan<byte> data)
 {
     var PID = ReadUInt32BigEndian(data);
     uint sv = ((PID & 0x3E000) >> 0xD) % 24;
     var unshuffled = PokeCrypto.ShuffleArray(data, sv, PokeCrypto.SIZE_4BLOCK);
     var result = new BK4(unshuffled);
     result.RefreshChecksum();
     return result;
 }
Beispiel #4
0
        public static BK4 ReadUnshuffle(byte[] data)
        {
            var  PID    = BigEndian.ToUInt32(data, 0);
            uint sv     = ((PID & 0x3E000) >> 0xD) % 24;
            var  Data   = PokeCrypto.ShuffleArray(data, sv, PokeCrypto.SIZE_4BLOCK);
            var  result = new BK4(Data);

            result.RefreshChecksum();
            return(result);
        }
Beispiel #5
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>
        /// <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);
            }
        }
Beispiel #6
0
        public BK4 convertToBK4()
        {
            BK4 bk4 = new BK4();

            TransferPropertiesWithReflection(this, bk4);
            // Fix Non-Reflectable properties
            Array.Copy(Data, 0x78, bk4.Data, 0x78, 6); // Met Info
            // Preserve Trash Bytes
            for (int i = 0; i < 11; i++)               // Nickname
            {
                bk4.Data[0x48 + 2 * i]     = Data[0x48 + 2 * i + 1];
                bk4.Data[0x48 + 2 * i + 1] = Data[0x48 + 2 * i];
            }
            for (int i = 0; i < 8; i++) // OT_Name
            {
                bk4.Data[0x68 + 2 * i]     = Data[0x68 + 2 * i + 1];
                bk4.Data[0x68 + 2 * i + 1] = Data[0x68 + 2 * i];
            }
            bk4.Sanity = 0x4000;
            bk4.RefreshChecksum();
            return(bk4);
        }
Beispiel #7
0
 public BK4 convertToBK4()
 {
     BK4 bk4 = new BK4();
     TransferPropertiesWithReflection(this, bk4);
     // Fix Non-Reflectable properties
     Array.Copy(Data, 0x78, bk4.Data, 0x78, 6); // Met Info
     // Preserve Trash Bytes
     for (int i = 0; i < 11; i++) // Nickname
     {
         bk4.Data[0x48 + 2*i] = Data[0x48 + 2*i + 1];
         bk4.Data[0x48 + 2*i + 1] = Data[0x48 + 2*i];
     }
     for (int i = 0; i < 8; i++) // OT_Name
     {
         bk4.Data[0x68 + 2*i] = Data[0x68 + 2*i + 1];
         bk4.Data[0x68 + 2*i + 1] = Data[0x68 + 2*i];
     }
     bk4.Sanity = 0x4000;
     bk4.RefreshChecksum();
     return bk4;
 }
Beispiel #8
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;
     }
 }
Beispiel #9
0
 public override PKM getPKM(byte[] data)
 {
     byte[] pkm = data.Take(SIZE_STORED).ToArray();
     PKM bk = new BK4(pkm);
     return bk;
 }