コード例 #1
0
ファイル: Form1.cs プロジェクト: lostlsend/FF12PCRNGHelper
        // TODO: Make searching better so it only generates the amount of random numbers needed for the current search and gets new every iteration instead of just dumping the whole thing.
        private int SearchPercentages(PSearch[] percentages)
        {
            try
            {
                var rng = new RNG2002();
                var(mt, mti) = RemoteMem.GetMtAndMti(MemoryData.MtAddress);

                rng.LoadState(mti, in mt);
                this._rngDump = rng.Dump(Config.SearchDepth);

                for (var i = 0; i < this._rngDump.Length; i++)
                {
                    var pVal = this._rngDump[i] % 100;
                    switch (percentages[0].CompareType)
                    {
                    case CompareType.Equal:
                        if (pVal != percentages[0].Percentage)
                        {
                            continue;
                        }

                        break;

                    case CompareType.LesserOrEqual:
                        if (pVal > percentages[0].Percentage)
                        {
                            continue;
                        }

                        break;

                    case CompareType.GreaterOrEqual:
                        if (pVal < percentages[0].Percentage)
                        {
                            continue;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    if (this.SearchDump(percentages, i))
                    {
                        return(i);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is OutOfMemoryException)
                {
                    MessageBox.Show("Ran out of memory, lower your search depth.");
                }
            }
            finally
            {
                this._rngDump = Array.Empty <uint>();
            }

            return(-1);
        }