Exemplo n.º 1
0
        private static void OnCompressedGump(PacketReader p, PacketHandlerEventArgs e)
        {
            p.Seek(7, SeekOrigin.Begin);
            if (p.ReadUInt32() != 0x776CCCC1)
            {
                return;
            }
            p.Seek(19, SeekOrigin.Begin);
            p.Seek(p.ReadInt32(), SeekOrigin.Current);
            int lines = p.ReadInt32(), cLen = p.ReadInt32(), dLen = p.ReadInt32();

            byte[] buffer = new byte[dLen];
            ZLib.uncompress(buffer, ref dLen, p.CopyBytes(p.Position, cLen - 4), cLen - 4);

            for (int i = 0, pos = 0; i < lines; i++)
            {
                int    strLen = (buffer[pos++] << 8) | buffer[pos++];
                string str    = Encoding.BigEndianUnicode.GetString(buffer, pos, strLen * 2);
                if (str.Trim() == "a sea horse")
                {
                    WorldEx.SendMessage("Sea Horse!!! " + World.Player.Position);
                }
                pos += strLen * 2;
            }
        }
Exemplo n.º 2
0
        public void CopyBytes_array_int_NonEmptyBuffer_CanReadReturnsFalse()
        {
            // Arrange
            byte[] buffer = { 1, 2, 3, 4, 5 };

            var target = new PacketReader(buffer);

            // Act
            var destination = new byte[buffer.Length];

            target.CopyBytes(destination, 0);

            // Assert
            var actual = target.CanRead();

            Assert.IsFalse(actual);
        }
Exemplo n.º 3
0
        private static void OnCompressedGump(PacketReader p, PacketHandlerEventArgs e)
        {
            p.MoveToData();
            uint sender = p.ReadUInt32();
            uint id     = p.ReadUInt32();

            if (id == responseID)
            {
                _responseSender = sender;
            }
            if (id != compressedID)
            {
                return;
            }
            p.Seek(19, SeekOrigin.Begin);
            p.Seek(p.ReadInt32(), SeekOrigin.Current);
            int lines = p.ReadInt32(), cLen = p.ReadInt32(), dLen = p.ReadInt32();

            if (cLen < 5)
            {
                return;
            }
            byte[] buffer = new byte[dLen];
            ZLib.uncompress(buffer, ref dLen, p.CopyBytes(p.Position, cLen - 4), cLen - 4);
            string afk = string.Empty;

            for (int i = 0, pos = 0; i < lines; i++)
            {
                int    strLen = (buffer[pos++] << 8) | buffer[pos++];
                string str    = Encoding.BigEndianUnicode.GetString(buffer, pos, strLen * 2);
                int    index  = str.IndexOf('>');
                if (index != -1 && index < str.Length - 1)
                {
                    afk += str[index + 1].ToString().ToUpper().Normalize(NormalizationForm.FormD)[0];
                }
                pos += strLen * 2;
            }
            afk = afk.Trim();
            if (afk.Length == 5 && _responseSender != 0)
            {
                /*ClientCommunication.SendToClient(new CloseGump(responseID));
                 * WorldEx.SendToServer(new GumpResponse(responseSender, responseID, 0x310, new int[0], new[] { new GumpTextEntry(0x310, afk) }));
                 * responseSender = 0;*/
                WorldEx.OverHeadMessage(afk);
            }
        }
Exemplo n.º 4
0
        private async Task <ICollection <Zone> > HandleZoneListRequest()
        {
            var zones   = new List <Zone>();
            var builder = new PacketBuilder();

            builder.AddInt16(0x0005);
            builder.AddBytes(new byte[26]);

            var buffer = builder.GetBytes();

            await this.networkClient.SendAsync(buffer, buffer.Length);

            int chunkBufferLength;
            int chunk;
            int offset = 0;

            byte[]       chunkBuffer = null;
            PacketReader reader;

            do
            {
                buffer = await this.networkClient.ReceiveAsync();

                reader = new PacketReader(buffer);

                reader.ReadInt16();
                reader.ReadInt16();
                chunk = reader.ReadByte();
                reader.ReadBytes(7);
                chunkBufferLength = reader.ReadLittleEndianInt16();
                reader.ReadInt16();

                if (chunkBuffer == null)
                {
                    chunkBuffer = new byte[chunkBufferLength];
                }

                offset += reader.CopyBytes(chunkBuffer, offset);

                builder = new PacketBuilder();
                builder.AddInt16(0x000b);
                builder.AddInt16(0);
                builder.AddByte((byte)chunk);
                builder.AddPadding(3);

                buffer = builder.GetBytes();

                await this.networkClient.SendAsync(buffer, buffer.Length);

                chunk++;
            } while (offset < (chunkBufferLength));

            reader = new PacketReader(chunkBuffer);

            // Discard the 0x01 at the beginning
            reader.ReadByte();

            while (reader.CanRead())
            {
                var zone = new Zone();

                zone.ServerAddress = reader.ReadIPAddress();
                zone.ServerPort    = reader.ReadUInt16();
                reader.ReadBytes(6);
                zone.Name = reader.ReadString(32);
                reader.ReadInt16();
                zone.IsAdvanced = reader.ReadBoolean();
                reader.ReadBytes(29);
                zone.Description = reader.ReadString();

                zones.Add(zone);
            }

            return(zones);
        }
Exemplo n.º 5
0
        private static void OnCompressedGump(PacketReader p, PacketHandlerEventArgs e)
        {
            p.Seek(7, SeekOrigin.Begin);
            if (p.ReadUInt32() != 0x1105B263)
            {
                return;
            }

            p.Seek(19, SeekOrigin.Begin);
            p.Seek(p.ReadInt32() + 4, SeekOrigin.Current);
            int cLen = p.ReadInt32(), dLen = p.ReadInt32();

            byte[] buffer = new byte[dLen];
            ZLib.uncompress(buffer, ref dLen, p.CopyBytes(p.Position, cLen - 4), cLen - 4);
            int strLen = (buffer[0] << 8) | buffer[1];

            string[] str = Encoding.BigEndianUnicode.GetString(buffer, 2, strLen * 2).Split(',');

            string[] lat    = str[0].Split('°');
            int      yLat   = int.Parse(lat[0]);
            int      yMins  = int.Parse(lat[1].Split('\'')[0]);
            bool     ySouth = lat[1][lat[1].Length - 1] == 'S';

            string[] lon   = str[1].Split('°');
            int      xLong = int.Parse(lon[0]);
            int      xMins = int.Parse(lon[1].Split('\'')[0]);
            bool     xEast = lon[1][lon[1].Length - 1] == 'E';

            const int xWidth  = 5120;
            const int yHeight = 4096;
            const int xCenter = 1323;
            const int yCenter = 1624;

            double absLong = xLong + ((double)xMins / 60);
            double absLat  = yLat + ((double)yMins / 60);

            if (!xEast)
            {
                absLong = 360.0 - absLong;
            }

            if (!ySouth)
            {
                absLat = 360.0 - absLat;
            }

            int x = xCenter + (int)((absLong * xWidth) / 360);
            int y = yCenter + (int)((absLat * yHeight) / 360);

            if (x < 0)
            {
                x += xWidth;
            }
            else if (x >= xWidth)
            {
                x -= xWidth;
            }

            if (y < 0)
            {
                y += yHeight;
            }
            else if (y >= yHeight)
            {
                y -= yHeight;
            }

            onGump(x, y);
        }