Example #1
0
 private static byte[] DecryptParty(byte[] data)
 {
     PokeCrypto.DecryptIfEncrypted67(ref data);
     if (data.Length != SIZE)
     {
         Array.Resize(ref data, SIZE);
     }
     return(data);
 }
Example #2
0
 public PB7(byte[] data)
 {
     PokeCrypto.DecryptIfEncrypted67(ref data);
     if (data.Length != SIZE)
     {
         Array.Resize(ref data, SIZE);
     }
     Data = data;
 }
Example #3
0
 public PK3(byte[] data)
 {
     PokeCrypto.DecryptIfEncrypted3(ref data);
     if (data.Length != PokeCrypto.SIZE_3PARTY)
     {
         Array.Resize(ref data, PokeCrypto.SIZE_3PARTY);
     }
     Data = data;
 }
Example #4
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;
 }
Example #5
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);
        }
Example #6
0
        public BK4(byte[] data)
        {
            Data = data;
            uint sv = ((PID & 0x3E000) >> 0xD) % 24;

            Data = PokeCrypto.ShuffleArray(Data, sv, PokeCrypto.SIZE_4BLOCK);
            if (Sanity != 0 && Species <= MaxSpeciesID && !ChecksumValid) // We can only hope
            {
                RefreshChecksum();
            }
            if (Valid && Sanity == 0)
            {
                Sanity = 0x4000;
            }
            ResetPartyStats();
        }
Example #7
0
 protected override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray6(data);
Example #8
0
        /// <summary>
        /// Gets the generation of the Pokemon data.
        /// </summary>
        /// <param name="data">Raw data representing a Pokemon.</param>
        /// <returns>An integer indicating the generation of the PKM file, or -1 if the data is invalid.</returns>
        public static int GetPKMDataFormat(byte[] data)
        {
            if (!PKX.IsPKM(data.Length))
            {
                return(-1);
            }

            switch (data.Length)
            {
            case PokeCrypto.SIZE_1JLIST or PokeCrypto.SIZE_1ULIST:
                return(1);

            case PokeCrypto.SIZE_2JLIST or PokeCrypto.SIZE_2ULIST:
            case PokeCrypto.SIZE_2STADIUM:
                return(2);

            case PokeCrypto.SIZE_3PARTY or PokeCrypto.SIZE_3STORED:
            case PokeCrypto.SIZE_3CSTORED:
            case PokeCrypto.SIZE_3XSTORED:
                return(3);

            case PokeCrypto.SIZE_4PARTY or PokeCrypto.SIZE_4STORED:
            case PokeCrypto.SIZE_5PARTY:
                if ((BitConverter.ToUInt16(data, 0x4) == 0) && (BitConverter.ToUInt16(data, 0x80) >= 0x3333 || data[0x5F] >= 0x10) && BitConverter.ToUInt16(data, 0x46) == 0)     // PK5
                {
                    return(5);
                }
                return(4);

            case PokeCrypto.SIZE_6STORED:
                return(6);

            case PokeCrypto.SIZE_6PARTY:                   // collision with PGT, same size.
                if (BitConverter.ToUInt16(data, 0x4) != 0) // Bad Sanity?
                {
                    return(-1);
                }
                if (BitConverter.ToUInt32(data, 0x06) == PokeCrypto.GetCHK(data, PokeCrypto.SIZE_6STORED))
                {
                    return(6);
                }
                if (BitConverter.ToUInt16(data, 0x58) != 0)                // Encrypted?
                {
                    for (int i = data.Length - 0x10; i < data.Length; i++) // 0x10 of 00's at the end != PK6
                    {
                        if (data[i] != 0)
                        {
                            return(6);
                        }
                    }

                    return(-1);
                }
                return(6);

            case PokeCrypto.SIZE_8PARTY or PokeCrypto.SIZE_8STORED:
                return(8);

            default:
                return(-1);
            }
        }
Example #9
0
 private static byte[] DecryptParty(byte[] data)
 {
     PokeCrypto.DecryptIfEncrypted45(ref data);
     Array.Resize(ref data, PokeCrypto.SIZE_5PARTY);
     return(data);
 }
Example #10
0
 public PK4(byte[] data)
 {
     PokeCrypto.DecryptIfEncrypted45(ref data);
     Array.Resize(ref data, PokeCrypto.SIZE_4PARTY);
     Data = data;
 }
Example #11
0
 public byte[] Write()
 {
     byte[] data = (byte[])Data.Clone();
     PokeCrypto.CryptArray(data, EncryptionSeed, 0, EncryptionSeedOffset);
     return(data);
 }
Example #12
0
 public EntreeForest(byte[] data)
 {
     Data = data;
     PokeCrypto.CryptArray(data, EncryptionSeed, 0, EncryptionSeedOffset);
 }
Example #13
0
 public EntreeForest(byte[] data)
 {
     Data = data;
     PokeCrypto.CryptArray(data.AsSpan(0, EncryptionSeedOffset), EncryptionSeed);
 }