Beispiel #1
0
        public static bool VerifyMemePOKE(byte[] input, out byte[] output)
        {
            if (input.Length < 0x60)
            {
                throw new ArgumentException("Invalid POKE buffer!");
            }
            var memeLen   = input.Length - 8;
            var memeIndex = MemeKeyIndex.PokedexAndSaveFile;

            for (var i = input.Length - 8; i >= 0; i--)
            {
                if (BitConverter.ToUInt32(input, i) != POKE)
                {
                    continue;
                }

                var keyIndex = BitConverter.ToInt32(input, i + 4);
                if (!MemeKey.IsValidPokeKeyIndex(keyIndex))
                {
                    continue;
                }

                memeLen   = i;
                memeIndex = (MemeKeyIndex)keyIndex;
                break;
            }

            foreach (var len in new[] { memeLen, memeLen - 2 }) // Account for Pokédex QR Edge case
            {
                if (VerifyMemeData(input, out output, 0, len, memeIndex))
                {
                    return(true);
                }

                if (VerifyMemeData(input, out output, 0, len, MemeKeyIndex.PokedexAndSaveFile))
                {
                    return(true);
                }
            }

            output = input;
            return(false);
        }