internal static uint GetMtForValue(uint value) { if (ValueCache.ContainsKey(value) && ValueCache.TryGetValue(value, out var rtn)) { return(rtn); } var rng = new RNG2002(); for (uint i = 0; i < uint.MaxValue; i++) { rng.mti = 1; rng.mt[1] = i; var rVal = rng.genrand(); if (rVal == value) { if (!ValueCache.ContainsKey(value)) { ValueCache.TryAdd(value, i); } return(i); } } throw new Exception(); }
private void DynamicSearchRngDump(Action action) { ResetGridHighlighting(); try { var rng = new RNG2002(); (uint[] mt, int mti) = ZodiacMemory.GetMtAndMti(MemoryData.MtAddress); rng.LoadState(mti, in mt); _rngDump = rng.Dump(Config.SearchDepth); action.Invoke(); } catch (Exception ex) { if (ex is OutOfMemoryException) { MessageBox.Show("Ran out of memory, lower your search depth."); } } finally { _rngDump = Array.Empty <uint>(); if (_foundIndex < 0) { MessageBox.Show("Nothing found."); } else if (_foundIndex < dataGridView2.RowCount) { dataGridView2.Rows[_foundIndex].DefaultCellStyle.BackColor = HighlightBackColor; dataGridView2.Rows[_foundIndex].DefaultCellStyle.SelectionBackColor = SelectionHighlightBackColor; dataGridView2.FirstDisplayedScrollingRowIndex = _foundIndex; } } }
// 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(); (uint[] mt, int mti) = ZodiacMemory.GetMtAndMti(MemoryData.MtAddress); rng.LoadState(mti, in mt); _rngDump = rng.Dump(Config.SearchDepth); for (int i = 0; i < _rngDump.Length; i++) { uint pVal = _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 (SearchDump(percentages, i)) { return(i); } } } catch (Exception ex) { if (ex is OutOfMemoryException) { MessageBox.Show("Ran out of memory, lower your search depth."); } } finally { _rngDump = Array.Empty <uint>(); } return(-1); }