예제 #1
0
        static DataCenterRegion ReadRegion(GameBinaryReader reader, uint elementSize)
        {
            var full = reader.ReadUInt32();
            var used = reader.ReadUInt32();
            var data = reader.ReadBytes((int)(full * elementSize));

            return(new DataCenterRegion(elementSize, full, used, data));
        }
예제 #2
0
        static DataCenterHeader ReadHeader(GameBinaryReader reader)
        {
            var version       = reader.ReadUInt32();
            var unk1          = reader.ReadInt32();
            var unk2          = reader.ReadInt16();
            var unk3          = reader.ReadInt16();
            var clientVersion = reader.ReadUInt32();
            var unk4          = reader.ReadInt32();
            var unk5          = reader.ReadInt32();
            var unk6          = reader.ReadInt32();
            var unk7          = reader.ReadInt32();

            return(new DataCenterHeader(version, unk1, unk2, unk3, clientVersion, unk4, unk5, unk6, unk7));
        }
예제 #3
0
        static DataCenterSegmentedRegion ReadSegmentedRegion(GameBinaryReader reader, uint elementSize)
        {
            var count    = reader.ReadUInt32();
            var segments = new List <DataCenterRegion>((int)count);

            for (var i = 0; i < count; i++)
            {
                segments.Add(ReadRegion(reader, elementSize));
            }

            return(new DataCenterSegmentedRegion(elementSize, segments));
        }
예제 #4
0
        static DataCenterSimpleRegion ReadSimpleRegion(GameBinaryReader reader, bool offByOne,
                                                       uint elementSize)
        {
            var count = reader.ReadUInt32();

            if (offByOne)
            {
                count--;
            }

            var data = reader.ReadBytes((int)(count * elementSize));

            return(new DataCenterSimpleRegion(elementSize, count, data));
        }
예제 #5
0
        public PacketLogReader(string fileName)
        {
            Stream stream = File.OpenRead(fileName);

            using var reader = new GameBinaryReader(stream, true);

            if (!reader.ReadBytes(PacketLogEntry.Magic.Count).SequenceEqual(PacketLogEntry.Magic))
            {
                throw new InvalidDataException("Invalid magic number.");
            }

            Version = reader.ReadUInt32();

            if (Version != PacketLogEntry.Version)
            {
                throw new InvalidDataException($"Unknown format version {Version}.");
            }

            Region = (Region)reader.ReadByte();

            if (!Enum.IsDefined(typeof(Region), Region))
            {
                throw new InvalidDataException($"Unknown region value {Region}.");
            }

            var clientVersion = reader.ReadUInt32();

            if (!DataCenter.ClientVersions.Values.Contains(clientVersion))
            {
                throw new InvalidDataException($"Unknown client version {clientVersion}.");
            }

            GameMessages   = new GameMessageTable(clientVersion);
            SystemMessages = new SystemMessageTable(clientVersion);

            var serverCount = (int)reader.ReadUInt32();
            var servers     = new Dictionary <int, ServerInfo>(serverCount);

            for (var i = 0; i < serverCount; i++)
            {
                var id = reader.ReadInt32();

                if (servers.ContainsKey(id))
                {
                    throw new InvalidDataException($"Duplicate server ID {id}.");
                }

                var name         = reader.ReadString();
                var size         = reader.ReadBoolean() ? 16 : 4;
                var realIPBytes  = reader.ReadBytes(size);
                var realPort     = reader.ReadUInt16();
                var proxyIPBytes = reader.ReadBytes(size);
                var proxyPort    = reader.ReadUInt16();

                IPEndPoint realEP;

                try
                {
                    realEP = new IPEndPoint(new IPAddress(realIPBytes), realPort);
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new InvalidDataException($"Invalid real port {realPort}.");
                }
                catch (ArgumentException)
                {
                    throw new InvalidDataException("Invalid real IP address.");
                }

                IPEndPoint proxyEP;

                try
                {
                    proxyEP = new IPEndPoint(new IPAddress(proxyIPBytes), proxyPort);
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new InvalidDataException($"Invalid proxy port {proxyPort}.");
                }
                catch (ArgumentException)
                {
                    throw new InvalidDataException("Invalid proxy IP address.");
                }

                servers.Add(id, new ServerInfo(id, name, realEP, proxyEP));
            }

            Servers          = servers;
            CompressionLevel = reader.ReadByte();

            _reader = new GameBinaryReader(CompressionLevel != 0 ?
                                           new FastDeflateStream(stream, CompressionMode.Decompress) : stream);
        }
예제 #6
0
        public PacketLogReader(string fileName)
        {
            Stream stream = File.OpenRead(fileName);

            var magic = new byte[PacketLogEntry.Magic.Count];

            if (stream.Read(magic, 0, magic.Length) != magic.Length)
            {
                throw new EndOfStreamException();
            }

            if (!magic.SequenceEqual(PacketLogEntry.Magic))
            {
                throw new InvalidDataException();
            }

            var level = stream.ReadByte();

            if (level == -1)
            {
                throw new EndOfStreamException();
            }

            if ((CompressionLevel = (byte)level) != 0)
            {
                stream = new DeflateStream(stream, CompressionMode.Decompress);
            }

            _reader = new GameBinaryReader(stream);
            Version = _reader.ReadUInt32();

            if (Version != PacketLogEntry.Version)
            {
                throw new InvalidDataException();
            }

            Region = (Region)_reader.ReadByte();

            if (!Enum.IsDefined(typeof(Region), Region))
            {
                throw new InvalidDataException();
            }

            var clientVersion = _reader.ReadUInt32();

            if (!DataCenter.Versions.Values.Contains(clientVersion))
            {
                throw new InvalidDataException();
            }

            GameMessages   = new GameMessageTable(clientVersion);
            SystemMessages = new SystemMessageTable(clientVersion);

            var serverCount = (int)_reader.ReadUInt32();

            if (serverCount < 0)
            {
                throw new InvalidDataException();
            }

            var servers = new Dictionary <int, ServerInfo>(serverCount);

            for (var i = 0; i < serverCount; i++)
            {
                var id = _reader.ReadInt32();

                if (servers.ContainsKey(id))
                {
                    throw new InvalidDataException();
                }

                var name         = _reader.ReadString();
                var size         = _reader.ReadBoolean() ? 16 : 4;
                var realIPBytes  = _reader.ReadBytes(size);
                var realPort     = _reader.ReadUInt16();
                var proxyIPBytes = _reader.ReadBytes(size);
                var proxyPort    = _reader.ReadUInt16();

                IPEndPoint realEP;
                IPEndPoint proxyEP;

                try
                {
                    realEP  = new IPEndPoint(new IPAddress(realIPBytes), realPort);
                    proxyEP = new IPEndPoint(new IPAddress(proxyIPBytes), proxyPort);
                }
                catch (ArgumentException)
                {
                    throw new InvalidDataException();
                }

                servers.Add(id, new ServerInfo(id, name, realEP, proxyEP));
            }

            Servers = servers;
        }