Beispiel #1
0
        private void handlePokeRead(object args_obj)
        {
            DataReadyWaiting args = (DataReadyWaiting)args_obj;

            if (Program.gCmdWindow.SAV.Generation == 6)
            {
                validator = new PK6(PKX.DecryptArray(args.data));
            }
            else
            {
                validator = new PK7(PKX.DecryptArray(args.data));
            }
        }
Beispiel #2
0
        private void DigWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker  = sender as BackgroundWorker;
            List <Result>    results = new List <Result>();

            byte[] source       = (byte[])e.Argument;
            int    length       = source.Length - POKEBYTES + 1;
            int    nextProgress = 0;
            int    progressStep = (int)((double)length / 100.0);
            bool   fullMode     = !FastModeCB.Checked;
            bool   gen7         = Program.gCmdWindow.SAV.Generation == 7;
            int    maxspecies   = Program.gCmdWindow.SAV.MaxSpeciesID;

            for (int i = 0; i < length; i++)
            {
                //Check sanity. Rejects ~50% of positions
                if (source[i + 4] == 0 && source[i + 5] == 0)
                {
                    uint seed = BitConverter.ToUInt32(source, i + 0);
                    //In fast mode skip if EC == 0. Rejects ~90% of positions
                    if (fullMode || seed != 0)
                    {
                        PKM    pkFound   = Program.gCmdWindow.SAV.BlankPKM;
                        byte[] dataFound = new byte[POKEBYTES];
                        Array.Copy(source, i, dataFound, 0, POKEBYTES);
                        dataFound    = PKX.DecryptArray(dataFound);
                        pkFound.Data = dataFound;
                        if (pkFound.ChecksumValid && pkFound.Species >= 1 && pkFound.Species <= maxspecies)
                        {
                            results.Add(new Result {
                                data = dataFound, offset = i
                            });
                        }
                        ////Decrypt partially, calculate checksum
                        ////We don't need to deshuffle, it won't affect the checksum
                        //ushort checksum = 0;
                        //for (int j = 8; j < POKEBYTES; j += 2)
                        //{
                        //    seed = seed * 0x41C64E6D + 0x00006073;
                        //    checksum += (ushort)(BitConverter.ToUInt16(source, i + j) ^ (ushort)(seed >> 16));
                        //}

                        ////Allows very few positions, but there's still some garbage
                        //if (checksum == BitConverter.ToUInt16(source, i + 6))
                        //{
                        //    byte[] dataFound = new byte[POKEBYTES];
                        //    Array.Copy(source, i, dataFound, 0, POKEBYTES);
                        //    //Decrypt it properly this time
                        //    dataFound = PKX.decryptArray(dataFound);
                        //    PKM pkFound = Program.gCmdWindow.SAV.BlankPKM;
                        //    pkFound.Data = dataFound;

                        //    if (pkFound.Species >= 1 && pkFound.Species <= 802)
                        //    {
                        //        //Almost certainly valid
                        //        results.Add(new Result { data = dataFound, offset = i });
                        //    }
                        //}
                    }
                }

                if (i >= nextProgress)
                {
                    //The condition will be checked every 1% of progress to improve performance
                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        break;
                    }

                    int progress = (int)((100.0 * (double)i) / (double)length);
                    worker.ReportProgress(progress);
                    nextProgress = i + progressStep;
                }
            }

            allResults.AddRange(results);
        }