Exemplo n.º 1
0
        public override void Write(Stream destination)
        {
            var dataPool = new DataPool();

            dataPool.IsBigEndian       = true;
            dataPool.Alignment         = Alignment;
            dataPool.AlignmentNullByte = 0x78;

            DataStream.WriteCString(destination, IsCompressed ? "FArC" : "FArc", 4, Encoding.UTF8);
            DataStream.WriteUInt32BE(destination, 0u);
            DataStream.WriteUInt32BE(destination, Alignment);

            foreach (var entry in entries)
            {
                DataStream.WriteCString(destination, entry.FileName, Encoding.UTF8);
                dataPool.Add(destination, entry.FilePath, IsCompressed, false);

                if (IsCompressed)
                {
                    DataStream.WriteUInt32BE(destination, (uint)entry.Length);
                }
            }

            long headerEndPosition = destination.Position;

            DataStream.Pad(destination, Alignment, 0x78);

            dataPool.Write(destination);

            destination.Seek(4, SeekOrigin.Begin);
            DataStream.WriteUInt32BE(destination, (uint)(headerEndPosition - 8));
        }
Exemplo n.º 2
0
        private void Config(int num, CancellationToken ct)
        {
            while (_wordlist.HasNext && !_theEnd)
            {
                int    retry = 0;
                string data  = _wordlist.GetData();

Retry:

                if (ct.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    Proxy proxy = null;
                    if (!_proxylist.Less)
                    {
                        proxy = _proxylist.Get();
                        if (proxy == null)
                        {
                            goto Retry;
                        }
                    }

                    Status?status = Status.OK;
                    status = OnConfig?.Invoke(this, new DataEventArgs()
                    {
                        Retry = retry,
                        Data  = data,
                        Proxy = proxy,
                        Save  = _save,
                        Log   = _log
                    });

                    switch (status)
                    {
                    case Status.OK:
                        _datapool.Add();
                        break;

                    case Status.Retry:
                        retry++;
                        goto Retry;

                    case Status.TheEnd:
                        _theEnd = true;
                        break;

                    default:
                        _datapool.Add();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    OnException?.Invoke(this, new ExceptionEventArgs()
                    {
                        Location  = "OnConfig",
                        Exception = ex,
                        Log       = _log
                    });
                }
            }

            _threadList[num] = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// A* to generate path to nearest grey tile
        /// </summary>
        private void GetPathToGrey()
        {
            Point currentPos = CurrentPos;

            Fringe.Clear();
            Fringe.Add(CurrentPos, null, 0, NearestGrey(currentPos));

            Node  bestNode = Fringe.GetBestNode();
            Point pos      = bestNode.Value;
            Point childPos;

            Tile[,] map = HugeMap;
            TileStates state;
            int        width = map.GetLength(0);

            //while not goal state
            while ((map[pos.Row, pos.Col].State & GreyTileSign) == 0)
            {
                //adding neighbour tiles to Fringe if they are not walls
                if (pos.Row > 0)
                {
                    state = map[pos.Row - 1, pos.Col].State;
                    if ((state & TileStates.Wall) == 0 && (state & TileStates.Visited) != 0)
                    {
                        childPos = new Point(pos.Row - 1, pos.Col);
                        Fringe.Add(childPos, bestNode, bestNode.RealCost + 1, NearestGrey(childPos));
                    }
                }

                if (pos.Col < width - 1)
                {
                    state = map[pos.Row, pos.Col + 1].State;
                    if ((state & TileStates.Wall) == 0 && (state & TileStates.Visited) != 0)
                    {
                        childPos = new Point(pos.Row, pos.Col + 1);
                        Fringe.Add(childPos, bestNode, bestNode.RealCost + 1, NearestGrey(childPos));
                    }
                }

                if (pos.Row < width - 1)
                {
                    state = map[pos.Row + 1, pos.Col].State;
                    if ((state & TileStates.Wall) == 0 && (state & TileStates.Visited) != 0)
                    {
                        childPos = new Point(pos.Row + 1, pos.Col);
                        Fringe.Add(childPos, bestNode, bestNode.RealCost + 1, NearestGrey(childPos));
                    }
                }

                if (pos.Col > 0)
                {
                    state = map[pos.Row, pos.Col - 1].State;
                    if ((state & TileStates.Wall) == 0 && (state & TileStates.Visited) != 0)
                    {
                        childPos = new Point(pos.Row, pos.Col - 1);
                        Fringe.Add(childPos, bestNode, bestNode.RealCost + 1, NearestGrey(childPos));
                    }
                }

                bestNode = Fringe.GetBestNode();
                pos      = bestNode.Value;
            }

            //Reverse path
            Node temp1 = bestNode, temp2 = bestNode.Parent, temp3;

            while (temp2.Parent != null)
            {
                temp3        = temp2.Parent;
                temp2.Parent = temp1;
                temp1        = temp2;
                temp2        = temp3;
            }
            temp2.Parent    = temp1;
            bestNode.Parent = null;

            GoingToGrey = temp1;
        }