// by declaring these only once you get a huge performance boost // This method ensures that an RNG is only created once, // and not every time a Generate function is called public List <Frame> Generate( FrameCompare frameCompare, uint id, uint sid) { frames = new List <Frame>(); if (FrameType == FrameType.ColoXD) { var rng = new XdRng((uint)InitialSeed); rngList = new List <uint>(); for (uint cnt = 1; cnt < InitialFrame; cnt++) { rng.GetNext32BitNumber(); } for (uint cnt = 0; cnt < 12; cnt++) { rngList.Add(rng.GetNext16BitNumber()); } for (uint cnt = 0; cnt < maxResults; cnt++, rngList.RemoveAt(0), rngList.Add(rng.GetNext16BitNumber())) { switch (FrameType) { case FrameType.ColoXD: frame = Frame.GenerateFrame( 0, FrameType.ColoXD, cnt + InitialFrame, rngList[0], rngList[4], rngList[3], rngList[0], rngList[1], id, sid); break; case FrameType.Channel: frame = Frame.GenerateFrame( 0, FrameType.Channel, cnt + InitialFrame, rngList[0], rngList[1], rngList[2], (rngList[6]) >> 11, (rngList[7]) >> 11, (rngList[8]) >> 11, (rngList[10]) >> 11, (rngList[11]) >> 11, (rngList[9]) >> 11, 40122, rngList[0]); break; } if (frameCompare.Compare(frame)) { frames.Add(frame); break; } } } else { // We are going to grab our initial set of rngs here and // then start our loop so that we can iterate as many // times as we have to. var rng = new PokeRng((uint)InitialSeed); rngList = new List <uint>(); for (uint cnt = 1; cnt < InitialFrame; cnt++) { rng.GetNext32BitNumber(); } for (uint cnt = 0; cnt < 20; cnt++) { rngList.Add(rng.GetNext16BitNumber()); } lastseed = rng.Seed; for (uint cnt = 0; cnt < maxResults; cnt++, rngList.RemoveAt(0), rngList.Add(rng.GetNext16BitNumber())) { switch (FrameType) { case FrameType.Method1: frame = Frame.GenerateFrame( 0, FrameType.Method1, cnt + InitialFrame, rngList[0], rngList[0], rngList[1], rngList[2], rngList[3], id, sid, cnt); break; case FrameType.Method1Reverse: frame = Frame.GenerateFrame( 0, FrameType.Method1Reverse, cnt + InitialFrame, rngList[0], rngList[1], rngList[0], rngList[2], rngList[3], id, sid, cnt); break; case FrameType.Method2: frame = Frame.GenerateFrame( 0, FrameType.Method2, cnt + InitialFrame, rngList[0], rngList[0], rngList[1], rngList[3], rngList[4], id, sid, cnt); break; case FrameType.Method4: frame = Frame.GenerateFrame( 0, FrameType.Method4, cnt + InitialFrame, rngList[0], rngList[0], rngList[1], rngList[2], rngList[4], id, sid, cnt); break; } // Now we need to filter and decide if we are going // to add this to our collection for display to the // user. if (frameCompare.Compare(frame)) { frames.Add(frame); break; } } } return(frames); }
private void Search(uint pid, uint ivs, int num1, int num2, uint initseed, uint minframes, uint maxframes) { uint pidl = pid & 0xFFFF; uint pidh = pid >> 16; uint ivsh = ivs >> 16; uint ivsl = ivs & 0xFFFF; uint[] seeds = new uint[5]; var rng = new PokeRng(initseed); rng.GetNext32BitNumber((int)minframes); for (int x = 0; x < 5; x++) { seeds[x] = rng.GetNext16BitNumber(); } int j = 4; int k; for (uint i = 1 + minframes; i < maxframes; i++, seeds[j] = rng.GetNext16BitNumber()) { if (++j > 4) { j = 0; } if (seeds[j] != pidl) { continue; } if (seeds[j >= 4 ? 0 : j + 1] != pidh) { continue; } k = j + num1; if (k > 4) { k -= 5; } if ((seeds[k] & 0x7FFF) != ivsl) { continue; } k = j + num2; if (k > 4) { k -= 5; } if ((seeds[k] & 0x7FFF) != ivsh) { continue; } string[] row = new string[] { i.ToString() }; dataGridView1.Rows.Add(row); dataGridView1.Refresh(); break; } }