private static void FindPaths(NavGrid nav_grid, ref PathFinderAbilities abilities, PotentialPath potential_path, PathFinderQuery query, PotentialList potentials, ref int result_cell, ref NavType result_nav_type)
    {
        potentials.Clear();
        PathGrid.ResetUpdate();
        PathGrid.BeginUpdate(potential_path.cell, false);
        bool is_cell_in_range;
        Cell cell_data = PathGrid.GetCell(potential_path, out is_cell_in_range);

        AddPotential(potential_path, Grid.InvalidCell, NavType.NumNavTypes, 0, 0, -1, potentials, PathGrid, ref cell_data);
        int num = 2147483647;

        while (potentials.Count > 0)
        {
            KeyValuePair <int, PotentialPath> keyValuePair = potentials.Next();
            cell_data = PathGrid.GetCell(keyValuePair.Value, out is_cell_in_range);
            if (cell_data.cost != keyValuePair.Key)
            {
                continue;
            }
            int num2;
            if (cell_data.navType != NavType.Tube)
            {
                PotentialPath value = keyValuePair.Value;
                if (query.IsMatch(value.cell, cell_data.parent, cell_data.cost))
                {
                    num2 = ((cell_data.cost < num) ? 1 : 0);
                    goto IL_00cc;
                }
            }
            num2 = 0;
            goto IL_00cc;
IL_00cc:
            if (num2 != 0)
            {
                PotentialPath value2 = keyValuePair.Value;
                result_cell     = value2.cell;
                num             = cell_data.cost;
                result_nav_type = cell_data.navType;
                break;
            }
            AddPotentials(nav_grid.potentialScratchPad, keyValuePair.Value, cell_data.cost, cell_data.underwaterCost, ref abilities, query, nav_grid.maxLinksPerCell, nav_grid.Links, potentials, PathGrid, cell_data.parent, cell_data.parentNavType);
        }
        PathGrid.EndUpdate(true);
    }
    public void UpdateProbe(NavGrid nav_grid, int cell, NavType nav_type, PathFinderAbilities abilities, PathFinder.PotentialPath.Flags flags)
    {
        if (scratchPad == null)
        {
            scratchPad = new PathFinder.PotentialScratchPad(nav_grid.maxLinksPerCell);
        }
        bool flag  = updateCount == -1;
        bool flag2 = Potentials.Count == 0 || flag;

        PathGrid.BeginUpdate(cell, !flag2);
        bool is_cell_in_range;

        if (flag2)
        {
            updateCount = 0;
            PathFinder.Cell          cell_data      = PathGrid.GetCell(cell, nav_type, out is_cell_in_range);
            PathFinder.PotentialPath potential_path = new PathFinder.PotentialPath(cell, nav_type, flags);
            PathFinder.AddPotential(potential_path, Grid.InvalidCell, NavType.NumNavTypes, 0, 0, -1, Potentials, PathGrid, ref cell_data);
        }
        int num = (potentialCellsPerUpdate > 0 && !flag) ? potentialCellsPerUpdate : 2147483647;

        updateCount++;
        while (Potentials.Count > 0 && num > 0)
        {
            KeyValuePair <int, PathFinder.PotentialPath> keyValuePair = Potentials.Next();
            num--;
            PathFinder.Cell cell2 = PathGrid.GetCell(keyValuePair.Value, out is_cell_in_range);
            if (cell2.cost == keyValuePair.Key)
            {
                PathFinder.AddPotentials(scratchPad, keyValuePair.Value, cell2.cost, cell2.underwaterCost, ref abilities, null, nav_grid.maxLinksPerCell, nav_grid.Links, Potentials, PathGrid, cell2.parent, cell2.parentNavType);
            }
        }
        bool flag3 = Potentials.Count == 0;

        PathGrid.EndUpdate(flag3);
        if (flag3 && updateCount > 25)
        {
            KProfiler.AddEvent("PathProberUpdateCountExceeded");
        }
    }