System.IO.BinaryReader.ReadByte()

Here are the examples of the csharp api System.IO.BinaryReader.ReadByte() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2235 Examples 7

19 View Source File : TextureMapChange.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            PartIndex   = reader.ReadByte();
            OldTexture  = reader.ReadAsDataIDOfKnownType(0x05000000);
            NewTexture  = reader.ReadAsDataIDOfKnownType(0x05000000);
        }

19 View Source File : Pack.cs
License : Apache License 2.0
Project Creator : aequabit

public object[] Deserialize(byte[] data)
    {
        MemoryStream Stream = new MemoryStream(data);
        BinaryReader Reader = new BinaryReader(Stream, Encoding.UTF8);
        List<object> Items = new List<object>();
        byte Current = 0;
        byte Count = Reader.ReadByte();

        for (int I = 0; I <= Count - 1; I++)
        {
            Current = Reader.ReadByte();

            switch (Current)
            {
                case 0:
                    Items.Add(Reader.ReadBoolean());
                    break;
                case 1:
                    Items.Add(Reader.ReadByte());
                    break;
                case 2:
                    Items.Add(Reader.ReadBytes(Reader.ReadInt32()));
                    break;
                case 3:
                    Items.Add(Reader.ReadChar());
                    break;
                case 4:
                    Items.Add(Reader.ReadString().ToCharArray());
                    break;
                case 5:
                    Items.Add(Reader.ReadDecimal());
                    break;
                case 6:
                    Items.Add(Reader.ReadDouble());
                    break;
                case 7:
                    Items.Add(Reader.ReadInt32());
                    break;
                case 8:
                    Items.Add(Reader.ReadInt64());
                    break;
                case 9:
                    Items.Add(Reader.ReadSByte());
                    break;
                case 10:
                    Items.Add(Reader.ReadInt16());
                    break;
                case 11:
                    Items.Add(Reader.ReadSingle());
                    break;
                case 12:
                    Items.Add(Reader.ReadString());
                    break;
                case 13:
                    Items.Add(Reader.ReadUInt32());
                    break;
                case 14:
                    Items.Add(Reader.ReadUInt64());
                    break;
                case 15:
                    Items.Add(Reader.ReadUInt16());
                    break;
                case 16:
                    Items.Add(DateTime.FromBinary(Reader.ReadInt64()));
                    break;
            }
        }

        Reader.Close();
        return Items.ToArray();
    }

19 View Source File : DidMapper.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            ClientIDNumberingType = (NumberingType)reader.ReadByte();
            uint numClientEnumToIDs = reader.ReadCompressedUInt32();
            for (var i = 0; i < numClientEnumToIDs; i++)
                ClientEnumToID.Add(reader.ReadUInt32(), reader.ReadUInt32());

            ClientNameNumberingType = (NumberingType)reader.ReadByte();
            uint numClientEnumToNames = reader.ReadCompressedUInt32();
            for (var i = 0; i < numClientEnumToNames; i++)
                ClientEnumToName.Add(reader.ReadUInt32(), reader.ReadPString(1));

            ServerIDNumberingType = (NumberingType)reader.ReadByte();
            uint numServerEnumToIDs = reader.ReadCompressedUInt32();
            for (var i = 0; i < numServerEnumToIDs; i++)
                ServerEnumToID.Add(reader.ReadUInt32(), reader.ReadUInt32());

            ServerNameNumberingType = (NumberingType)reader.ReadByte();
            uint numServerEnumToNames = reader.ReadCompressedUInt32();
            for (var i = 0; i < numServerEnumToNames; i++)
                ServerEnumToName.Add(reader.ReadUInt32(), reader.ReadPString(1));
        }

19 View Source File : HairStyleCG.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            IconImage       = reader.ReadUInt32();
            Bald            = (reader.ReadByte() == 1);
            AlternateSetup  = reader.ReadUInt32();

            ObjDesc.Unpack(reader);
        }

19 View Source File : SurfaceTexture.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();
            Unknown = reader.ReadInt32();
            UnknownByte = reader.ReadByte();
            Textures.Unpack(reader);
        }

19 View Source File : ReceivePacket.cs
License : MIT License
Project Creator : 499116344

protected virtual void ParseHeader()
        {
            Header = Reader.ReadByte();
            Version = Reader.BeReadUInt16();
            Command = (QQCommand) Reader.BeReadUInt16();
            Sequence = Reader.BeReadUInt16();
            QQ = Reader.BeReadInt32();
            Reader.ReadBytes(3);
        }

19 View Source File : CellLandblock.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            uint hasObjects = reader.ReadUInt32();
            if (hasObjects == 1)
                HasObjects = true;

            // Read in the terrain. 9x9 so 81 records.
            for (int i = 0; i < 81; i++)
            {
                var terrain = reader.ReadUInt16();
                Terrain.Add(terrain);
            }

            // Read in the height. 9x9 so 81 records
            for (int i = 0; i < 81; i++)
            {
                var height = reader.ReadByte();
                Height.Add(height);
            }

            reader.AlignBoundary();
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static int BeReadInt32(this BinaryReader br)
        {
            return (br.ReadByte() << 24) | (br.ReadByte() << 16) | (br.ReadByte() << 8) | br.ReadByte();
        }

19 View Source File : ROMManager.cs
License : GNU General Public License v3.0
Project Creator : aglab2

private byte ReadBParam1(int offset)
        {
            reader.BaseStream.Position = offset + 0x10;
            return reader.ReadByte();
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static long BeReadLong32(this BinaryReader br)
        {
            return ((long) br.ReadByte() << 24) | (br.ReadByte() << 16) | (br.ReadByte() << 8) | br.ReadByte();
        }

19 View Source File : DxtUtil.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private static void DecompressDxt5Block(BinaryReader imageReader, int x, int y, int blockCountX, int width, int height, byte[] imageData)
        {
            byte alpha0 = imageReader.ReadByte();
            byte alpha1 = imageReader.ReadByte();

            ulong alphaMask = (ulong)imageReader.ReadByte();
            alphaMask += (ulong)imageReader.ReadByte() << 8;
            alphaMask += (ulong)imageReader.ReadByte() << 16;
            alphaMask += (ulong)imageReader.ReadByte() << 24;
            alphaMask += (ulong)imageReader.ReadByte() << 32;
            alphaMask += (ulong)imageReader.ReadByte() << 40;

            ushort c0 = imageReader.ReadUInt16();
            ushort c1 = imageReader.ReadUInt16();

            byte r0, g0, b0;
            byte r1, g1, b1;
            ConvertRgb565ToRgb888(c0, out r0, out g0, out b0);
            ConvertRgb565ToRgb888(c1, out r1, out g1, out b1);

            uint lookupTable = imageReader.ReadUInt32();

            for (int blockY = 0; blockY < 4; blockY++)
            {
                for (int blockX = 0; blockX < 4; blockX++)
                {
                    byte r = 0, g = 0, b = 0, a = 255;
                    uint index = (lookupTable >> 2 * (4 * blockY + blockX)) & 0x03;

                    uint alphaIndex = (uint)((alphaMask >> 3 * (4 * blockY + blockX)) & 0x07);
                    if (alphaIndex == 0)
                    {
                        a = alpha0;
                    }
                    else if (alphaIndex == 1)
                    {
                        a = alpha1;
                    }
                    else if (alpha0 > alpha1)
                    {
                        a = (byte)(((8 - alphaIndex) * alpha0 + (alphaIndex - 1) * alpha1) / 7);
                    }
                    else if (alphaIndex == 6)
                    {
                        a = 0;
                    }
                    else if (alphaIndex == 7)
                    {
                        a = 0xff;
                    }
                    else
                    {
                        a = (byte)(((6 - alphaIndex) * alpha0 + (alphaIndex - 1) * alpha1) / 5);
                    }

                    switch (index)
                    {
                        case 0:
                            r = r0;
                            g = g0;
                            b = b0;
                            break;
                        case 1:
                            r = r1;
                            g = g1;
                            b = b1;
                            break;
                        case 2:
                            r = (byte)((2 * r0 + r1) / 3);
                            g = (byte)((2 * g0 + g1) / 3);
                            b = (byte)((2 * b0 + b1) / 3);
                            break;
                        case 3:
                            r = (byte)((r0 + 2 * r1) / 3);
                            g = (byte)((g0 + 2 * g1) / 3);
                            b = (byte)((b0 + 2 * b1) / 3);
                            break;
                    }

                    int px = (x << 2) + blockX;
                    int py = (y << 2) + blockY;
                    if ((px < width) && (py < height))
                    {
                        int offset = ((py * width) + px) << 2;
                        imageData[offset] = r;
                        imageData[offset + 1] = g;
                        imageData[offset + 2] = b;
                        imageData[offset + 3] = a;
                    }
                }
            }
        }

19 View Source File : Texture.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private List<int> GetImageColorArray()
        {
            List<int> colors = new List<int>();
            if (Length == 0) return colors;

            switch (Format)
            {
                case SurfacePixelFormat.PFID_R8G8B8: // RGB
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint i = 0; i < Height; i++)
                            for (uint j = 0; j < Width; j++)
                            {
                                byte b = reader.ReadByte();
                                byte g = reader.ReadByte();
                                byte r = reader.ReadByte();
                                int color = (r << 16) | (g << 8) | b;
                                colors.Add(color);
                            }
                    }
                    break;
                case SurfacePixelFormat.PFID_CUSTOM_LSCAPE_R8G8B8:
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint i = 0; i < Height; i++)
                            for (uint j = 0; j < Width; j++)
                            {
                                byte r = reader.ReadByte();
                                byte g = reader.ReadByte();
                                byte b = reader.ReadByte();
                                int color = (r << 16) | (g << 8) | b;
                                colors.Add(color);
                            }
                    }
                    break;
                case SurfacePixelFormat.PFID_A8R8G8B8: // ARGB format. Most UI textures fall into this category
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint i = 0; i < Height; i++)
                            for (uint j = 0; j < Width; j++)
                                colors.Add(reader.ReadInt32());
                    }
                    break;
                case SurfacePixelFormat.PFID_INDEX16: // 16-bit indexed colors. Index references position in a palette;
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint y = 0; y < Height; y++)
                            for (uint x = 0; x < Width; x++)
                                colors.Add(reader.ReadInt16());
                    }
                    break;
                case SurfacePixelFormat.PFID_A8: // Greyscale, also known as Cairo A8.
                case SurfacePixelFormat.PFID_CUSTOM_LSCAPE_ALPHA:
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint y = 0; y < Height; y++)
                            for (uint x = 0; x < Width; x++)
                                colors.Add(reader.ReadByte());
                    }
                    break;
                case SurfacePixelFormat.PFID_P8: // Indexed
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint y = 0; y < Height; y++)
                            for (uint x = 0; x < Width; x++)
                                colors.Add(reader.ReadByte());
                    }
                    break;
                case SurfacePixelFormat.PFID_R5G6B5: // 16-bit RGB
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint y = 0; y < Height; y++)
                            for (uint x = 0; x < Width; x++)
                            {
                                ushort val = reader.ReadUInt16();
                                List<int> color = get565RGB(val);
                                colors.Add(color[0]); // Red
                                colors.Add(color[1]); // Green
                                colors.Add(color[2]); // Blue
                            }
                    }
                    break;
                case SurfacePixelFormat.PFID_A4R4G4B4:
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
                    {
                        for (uint y = 0; y < Height; y++)
                            for (uint x = 0; x < Width; x++)
                            {
                                ushort val = reader.ReadUInt16();
                                int alpha = (val >> 12) / 0xF * 255;
                                int red = (val >> 8 & 0xF) / 0xF * 255;
                                int green = (val >> 4 & 0xF) / 0xF * 255;
                                int blue = (val & 0xF) / 0xF * 255;

                                colors.Add(alpha);
                                colors.Add(red);
                                colors.Add(green);
                                colors.Add(blue);
                            }
                    }
                    break;
                default:
                    Console.WriteLine("Unhandled SurfacePixelFormat (" + Format.ToString() + ") in RenderSurface " + Id.ToString("X8"));
                    break;
            }

            return colors;
        }

19 View Source File : Receive_0x0195.cs
License : MIT License
Project Creator : 499116344

protected override void ParseBody()
        {
            Decrypt(User.TXProtocol.SessionKey);
            Reader.BeReadUInt16();
            var groupCategoryLength = Reader.BeReadUInt16();
            Reader.ReadBytes(3);
            Reader.ReadByte();
            Reader.BeReadUInt16();
            Reader.ReadByte();

            var itemLength = Reader.BeReadUInt16();
            while (itemLength > 0)
            {
                var item = Reader.ReadBytes(itemLength);

                var itemReader = new BinaryReader(new MemoryStream(item));
                itemReader.ReadByte();
                var indnex = itemReader.ReadByte();
                var cateName = Util.GetString(itemReader.ReadBytes(itemReader.ReadByte()));
                GroupCategory.Add(cateName);
                User.MessageLog($"群分组{indnex}:{cateName}");

                itemLength = Reader.BeReadUInt16();
            }
        }

19 View Source File : Polygon.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            NumPts      = reader.ReadByte();
            Stippling   = (StipplingType)reader.ReadByte();

            SidesType   = (CullMode)reader.ReadInt32();
            PosSurface  = reader.ReadInt16();
            NegSurface  = reader.ReadInt16();

            for (short i = 0; i < NumPts; i++)
                VertexIds.Add(reader.ReadInt16());

            if (!Stippling.HasFlag(StipplingType.NoPos))
            {
                for (short i = 0; i < NumPts; i++)
                    PosUVIndices.Add(reader.ReadByte());
            }

            if (SidesType == CullMode.Clockwise && !Stippling.HasFlag(StipplingType.NoNeg))
            {
                for (short i = 0; i < NumPts; i++)
                    NegUVIndices.Add(reader.ReadByte());
            }

            if (SidesType == CullMode.None)
            {
                NegSurface = PosSurface;
                NegUVIndices = PosUVIndices;
            }
        }

19 View Source File : Richtext.cs
License : MIT License
Project Creator : 499116344

public static Richtext Parse(BinaryReader reader)
        {
            var result = new Richtext();
            // TODO: 解析富文本
            try
            {
                var messageType = reader.ReadByte();
                var dataLength = reader.BeReadUInt16();
                var pos = reader.BaseStream.Position;
                while (pos + dataLength < reader.BaseStream.Length)
                {
                    reader.ReadByte();
                    switch (messageType)
                    {
                        case 0x01: // 纯文本消息、@
                        {
                            var messageStr = reader.BeReadString();
                            if (messageStr.StartsWith("@") && pos + dataLength - reader.BaseStream.Position == 16)
                            {
                                reader.ReadBytes(10);
                                result.Snippets.Add(new TextSnippet(messageStr, MessageType.At,
                                    ("Target", reader.BeReadLong32())));
                            }
                            else
                            {
                                result.Snippets.Add(messageStr);
                            }

                            break;
                        }
                        case 0x02: // Emoji(系统表情)
                        {
                            reader.BeReadUInt16(); // 这里的数字貌似总是1:系统表情只有208个。
                            result.Snippets.Add(new TextSnippet("", MessageType.Emoji, ("Type", reader.ReadByte())));
                            break;
                        }
                        case 0x03: // 图片
                        {
                            result.Snippets.Add(new TextSnippet(reader.BeReadString(), MessageType.Picture));
                            break;
                        }
                        case 0x0A: // 音频
                        {
                            result.Snippets.Add(new TextSnippet(reader.BeReadString(), MessageType.Audio));
                            break;
                        }
                        case 0x0E: // 未知
                        {
                            break;
                        }
                        case 0x12: // 群名片
                        {
                            break;
                        }
                        case 0x14: // XML
                        {
                            reader.ReadByte();
                            result.Snippets.Add(new TextSnippet(
                                GZipByteArray.DecompressString(reader.ReadBytes((int) (reader.BaseStream.Length - 1))),
                                MessageType.Xml));
                            break;
                        }
                        case 0x18: // 群文件
                        {
                            reader.ReadBytes(5);
                            var fileName = reader.BeReadString(); // 文件名称... 长度总是一个byte
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // 文件大小
                            result.Snippets.Add(new TextSnippet(fileName, MessageType.OfflineFile));
                            break;
                        }
                        case 0x19: // 红包秘钥段
                        {
                            if (reader.ReadByte() != 0xC2)
                            {
                                break;
                            }

                            reader.ReadBytes(19);
                            reader.ReadBytes(reader.ReadByte()); // 恭喜发财
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // 赶紧点击拆开吧
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // QQ红包
                            reader.ReadBytes(5);
                            reader.ReadBytes(reader.ReadByte()); // [QQ红包]恭喜发财
                            reader.ReadBytes(22);
                            var redId = Encoding.UTF8.GetString(reader.ReadBytes(32)); //redid
                            reader.ReadBytes(12);
                            reader.ReadBytes(reader.BeReadUInt16());
                            reader.ReadBytes(0x10);
                            var key1 = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte())); //Key1
                            reader.BeReadUInt16();
                            var key2 = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte())); //Key2
                            result.Snippets.Add(new TextSnippet("", MessageType.RedBag, ("RedId", redId),
                                ("Key1", key1), ("Key2", key2)));
                            break;
                        }
                    }

                    reader.ReadBytes((int) (pos + dataLength - reader.BaseStream.Position));
                    messageType = reader.ReadByte();
                    dataLength = reader.BeReadUInt16();
                    pos = reader.BaseStream.Position;
                }
            }
            catch (Exception ex)
            {
            }

            // 移除所有空白的片段
            result.Snippets.RemoveAll(s => s.Type == MessageType.Normal && string.IsNullOrEmpty(s.Content));

            // 若长度大于1,那么应该只含有普通文本、At、表情、图片。
            // 虽然我看着别人好像视频也能通过转发什么的弄进来,但是反正我们现在不支持接收音视频,所以不管了
            return result.Snippets.Count > 1 && result.Snippets.Any(s =>
                       s.Type != MessageType.Normal && s.Type != MessageType.At &&
                       s.Type != MessageType.Emoji && s.Type != MessageType.Picture)
                ? throw new NotSupportedException("富文本中包含多个非聊天代码")
                : result;
        }

19 View Source File : ObjDesc.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            reader.AlignBoundary();

            reader.ReadByte(); // ObjDesc always starts with 11.

            var numPalettes             = reader.ReadByte();
            var numTextureMapChanges    = reader.ReadByte();
            var numAnimPartChanges      = reader.ReadByte();

            if (numPalettes > 0)
                PaletteID = reader.ReadAsDataIDOfKnownType(0x04000000);

            SubPalettes.Unpack(reader, numPalettes);
            TextureChanges.Unpack(reader, numTextureMapChanges);
            AnimPartChanges.Unpack(reader, numAnimPartChanges);

            reader.AlignBoundary();
        }

19 View Source File : EndianBinaryReader.cs
License : MIT License
Project Creator : 91Act

public string ReadStringToNull()
        {
            var bytes = new List<byte>();
            byte b;
            while (BaseStream.Position != BaseStream.Length && (b = ReadByte()) != 0)
                bytes.Add(b);
            return Encoding.UTF8.GetString(bytes.ToArray());
        }

19 View Source File : NameFilterTable.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            ushort totalObjects = reader.ReadByte();
            reader.ReadByte(); // table size
            for (var i = 0; i < totalObjects; i++)
            {
                uint key = reader.ReadUInt32();
                NameFilterLanguageData val = new NameFilterLanguageData();
                val.Unpack(reader);
                LanguageData.Add(key, val);
            }
        }

19 View Source File : UEStructProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEStructProperty[] Read(BinaryReader reader, long valueLength, int count)
        {
            var type = reader.ReadUEString();
            var id = new Guid(reader.ReadBytes(16));
            if (id != Guid.Empty)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 16:x8}. Expected struct ID {Guid.Empty}, but was {id}");

            var terminator = reader.ReadByte();
            if (terminator != 0)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");

            var result = new UEStructProperty[count];
            for (var i = 0; i < count; i++)
                result[i] = ReadStructValue(type, reader);
            return result;
        }

19 View Source File : ROMManager.cs
License : GNU General Public License v3.0
Project Creator : aglab2

private byte ReadByte(int offset)
        {
            reader.BaseStream.Position = offset;
            return reader.ReadByte();
        }

19 View Source File : EnvCell.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            Flags = (EnvCellFlags)reader.ReadUInt32();

            reader.BaseStream.Position += 4; // Skip ahead 4 bytes, because this is the CellId. Again. Twice.

            byte numSurfaces    = reader.ReadByte();
            byte numPortals     = reader.ReadByte();    // Note that "portal" in this context does not refer to the swirly pink/purple thing, its basically connecting cells
            ushort numStabs     = reader.ReadUInt16();  // I believe this is what cells can be seen from this one. So the engine knows what else it needs to load/draw.

            // Read what surfaces are used in this cell
            for (uint i = 0; i < numSurfaces; i++)
                Surfaces.Add(0x08000000u | reader.ReadUInt16()); // these are stored in the dat as short values, so we'll make them a full dword

            EnvironmentId = (0x0D000000u | reader.ReadUInt16());

            CellStructure = reader.ReadUInt16();

            Position.Unpack(reader);

            CellPortals.Unpack(reader, numPortals);

            for (uint i = 0; i < numStabs; i++)
                VisibleCells.Add(reader.ReadUInt16());

            if ((Flags & EnvCellFlags.HreplacedtaticObjs) != 0)
                StaticObjects.Unpack(reader);

            if ((Flags & EnvCellFlags.HasRestrictionObj) != 0)
                RestrictionObj = reader.ReadUInt32();
        }

19 View Source File : StringTable.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            Language = reader.ReadUInt32();

            Unknown = reader.ReadByte();

            StringTableData.UnpackSmartArray(reader);
        }

19 View Source File : TLV_0104.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var data = buf.ReadBytes(length);
            var bufData = new BinaryReader(new MemoryStream(data));
            WSubVer = bufData.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var wCsCmd = bufData.BeReadUInt16();
                var errorCode = bufData.BeReadUInt32();

                bufData.ReadByte(); //0x00
                bufData.ReadByte(); //0x05
                PngData = bufData.ReadByte(); //是否需要验证码:0不需要,1需要
                int len;
                if (PngData == 0x00)
                {
                    len = bufData.ReadByte();
                    while (len == 0)
                    {
                        len = bufData.ReadByte();
                    }
                }
                else //ReplyCode != 0x01按下面走 兼容多版本
                {
                    bufData.BeReadInt32(); //需要验证码时为00 00 01 23,不需要时为全0
                    len = bufData.BeReadUInt16();
                }

                var buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufSigPic = buffer;
                if (PngData == 0x01) //有验证码数据
                {
                    len = bufData.BeReadUInt16();
                    buffer = bufData.ReadBytes(len);
                    user.QQPacket00BaVerifyCode = buffer;
                    Next = bufData.ReadByte();
                    bufData.ReadByte();
                    //var directory = Util.MapPath("Verify");
                    //var filename = Path.Combine(directory, user.QQ + ".png");
                    //if (!Directory.Exists(directory))
                    //{
                    //    Directory.CreateDirectory(directory);
                    //}

                    //var fs = Next == 0x00
                    //    ? new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)
                    //    : new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.Read);

                    ////fs.Seek(0, SeekOrigin.End);
                    //fs.Write(buffer, 0, buffer.Length);
                    //fs.Close();
                    len = bufData.BeReadUInt16();
                    buffer = bufData.ReadBytes(len);
                    user.TXProtocol.PngToken = buffer;
                    if (bufData.BaseStream.Length > bufData.BaseStream.Position)
                    {
                        bufData.BeReadUInt16();
                        len = bufData.BeReadUInt16();
                        buffer = bufData.ReadBytes(len);
                        user.TXProtocol.PngKey = buffer;
                    }
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TabooTable.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            // I don't actually know the structure of TabooTableEntries. It could be a Dictionary as I have it defined, or it could be a List where the key is just a variable in TabooTableEntry
            // I was unable to find the unpack code in the client. If someone can point me to it, I can make sure we match what the client is doing. - Mag

            /*var x01 = */reader.ReadByte();
            var length = reader.ReadByte();

            TabooTableEntries.Unpack(reader, length);
        }

19 View Source File : TLV_0105.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                buf.ReadByte(); //UNKNOWs
                var count = buf.ReadByte();
                for (var i = 0; i < count; i++)
                {
                    buf.ReadBytes(0x38); //buf
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : DxtUtil.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private static void DecompressDxt3Block(BinaryReader imageReader, int x, int y, int blockCountX, int width, int height, byte[] imageData)
        {
            byte a0 = imageReader.ReadByte();
            byte a1 = imageReader.ReadByte();
            byte a2 = imageReader.ReadByte();
            byte a3 = imageReader.ReadByte();
            byte a4 = imageReader.ReadByte();
            byte a5 = imageReader.ReadByte();
            byte a6 = imageReader.ReadByte();
            byte a7 = imageReader.ReadByte();

            ushort c0 = imageReader.ReadUInt16();
            ushort c1 = imageReader.ReadUInt16();

            byte r0, g0, b0;
            byte r1, g1, b1;
            ConvertRgb565ToRgb888(c0, out r0, out g0, out b0);
            ConvertRgb565ToRgb888(c1, out r1, out g1, out b1);

            uint lookupTable = imageReader.ReadUInt32();

            int alphaIndex = 0;
            for (int blockY = 0; blockY < 4; blockY++)
            {
                for (int blockX = 0; blockX < 4; blockX++)
                {
                    byte r = 0, g = 0, b = 0, a = 0;

                    uint index = (lookupTable >> 2 * (4 * blockY + blockX)) & 0x03;

                    switch (alphaIndex)
                    {
                        case 0:
                            a = (byte)((a0 & 0x0F) | ((a0 & 0x0F) << 4));
                            break;
                        case 1:
                            a = (byte)((a0 & 0xF0) | ((a0 & 0xF0) >> 4));
                            break;
                        case 2:
                            a = (byte)((a1 & 0x0F) | ((a1 & 0x0F) << 4));
                            break;
                        case 3:
                            a = (byte)((a1 & 0xF0) | ((a1 & 0xF0) >> 4));
                            break;
                        case 4:
                            a = (byte)((a2 & 0x0F) | ((a2 & 0x0F) << 4));
                            break;
                        case 5:
                            a = (byte)((a2 & 0xF0) | ((a2 & 0xF0) >> 4));
                            break;
                        case 6:
                            a = (byte)((a3 & 0x0F) | ((a3 & 0x0F) << 4));
                            break;
                        case 7:
                            a = (byte)((a3 & 0xF0) | ((a3 & 0xF0) >> 4));
                            break;
                        case 8:
                            a = (byte)((a4 & 0x0F) | ((a4 & 0x0F) << 4));
                            break;
                        case 9:
                            a = (byte)((a4 & 0xF0) | ((a4 & 0xF0) >> 4));
                            break;
                        case 10:
                            a = (byte)((a5 & 0x0F) | ((a5 & 0x0F) << 4));
                            break;
                        case 11:
                            a = (byte)((a5 & 0xF0) | ((a5 & 0xF0) >> 4));
                            break;
                        case 12:
                            a = (byte)((a6 & 0x0F) | ((a6 & 0x0F) << 4));
                            break;
                        case 13:
                            a = (byte)((a6 & 0xF0) | ((a6 & 0xF0) >> 4));
                            break;
                        case 14:
                            a = (byte)((a7 & 0x0F) | ((a7 & 0x0F) << 4));
                            break;
                        case 15:
                            a = (byte)((a7 & 0xF0) | ((a7 & 0xF0) >> 4));
                            break;
                    }
                    ++alphaIndex;

                    switch (index)
                    {
                        case 0:
                            r = r0;
                            g = g0;
                            b = b0;
                            break;
                        case 1:
                            r = r1;
                            g = g1;
                            b = b1;
                            break;
                        case 2:
                            r = (byte)((2 * r0 + r1) / 3);
                            g = (byte)((2 * g0 + g1) / 3);
                            b = (byte)((2 * b0 + b1) / 3);
                            break;
                        case 3:
                            r = (byte)((r0 + 2 * r1) / 3);
                            g = (byte)((g0 + 2 * g1) / 3);
                            b = (byte)((b0 + 2 * b1) / 3);
                            break;
                    }

                    int px = (x << 2) + blockX;
                    int py = (y << 2) + blockY;
                    if ((px < width) && (py < height))
                    {
                        int offset = ((py * width) + px) << 2;
                        imageData[offset] = r;
                        imageData[offset + 1] = g;
                        imageData[offset + 2] = b;
                        imageData[offset + 3] = a;
                    }
                }
            }
        }

19 View Source File : BinaryReaderExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static uint ReadCompressedUInt32(this BinaryReader reader)
        {
            var b0 = reader.ReadByte();
            if ((b0 & 0x80) == 0)
                return b0;

            var b1 = reader.ReadByte();
            if ((b0 & 0x40) == 0)
                return (uint)(((b0 & 0x7F) << 8) | b1);

            var s = reader.ReadUInt16();
            return (uint)(((((b0 & 0x3F) << 8) | b1) << 16) | s);
        }

19 View Source File : TLV_010C.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                user.TXProtocol.SessionKey = buf.ReadBytes(16);
                var dwUin = buf.BeReadInt32();
                var dwClientIP = Util.GetIpStringFromBytes(buf.ReadBytes(4)); //IP地址
                user.TXProtocol.WClientPort = buf.BeReadUInt16();
                var dwServerTime = Util.GetDateTimeFromMillis(buf.BeReadInt32());
                var unknow = buf.BeReadInt32();
                var cPreplacedSeqId = buf.ReadByte();
                var dwConnIP = buf.ReadBytes(4);
                var dwReLoginConnIP = buf.ReadBytes(4);
                var dwReLoginCtrlFlag = buf.BeReadInt32();

                int len = buf.BeReadUInt16();
                var bufComputerIdSig = buf.ReadBytes(len);

                len = buf.ReadByte();
                var unknow2 = buf.ReadBytes(len);

                len = buf.BeReadUInt16();
                var unknow3 = buf.ReadBytes(len);
                var a = new BinaryReader(new MemoryStream(unknow3));
                a.ReadByte();
                var dwConnIP2 = a.ReadBytes(4);
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : AnimationPartChange.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            PartIndex = reader.ReadByte();
            PartID    = reader.ReadAsDataIDOfKnownType(0x01000000);
        }

19 View Source File : EncodingUtil.cs
License : MIT License
Project Creator : 404Lcc

public static SocketModel SocketModelDncode(byte[] bytes)
        {
            SocketModel model = new SocketModel();
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    model.type = reader.ReadByte();
                    model.area = reader.ReadInt32();
                    model.command = reader.ReadInt32();
                    if (stream.Length > stream.Position)
                    {
                        model.message = DeserializationDecode(reader.ReadBytes((int)(stream.Length - stream.Position)));
                    }
                }
            }
            return model;
        }

19 View Source File : MotionData.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            var numAnims    = reader.ReadByte();
            Bitfield        = reader.ReadByte();
            Flags           = (MotionDataFlags)reader.ReadByte();
            reader.AlignBoundary();

            Anims.Unpack(reader, numAnims);

            if ((Flags & MotionDataFlags.HasVelocity) != 0)
                Velocity = reader.ReadVector3();

            if ((Flags & MotionDataFlags.HasOmega) != 0)
                Omega = reader.ReadVector3();
        }

19 View Source File : ReceivePacket.cs
License : MIT License
Project Creator : 499116344

protected void ParseTail()
        {
            try
            {
                Reader.ReadByte();
            }
            catch
            {
            }
        }

19 View Source File : SubPalette.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            SubID       = reader.ReadAsDataIDOfKnownType(0x04000000);
            Offset      = (uint)(reader.ReadByte() * 8);
            NumColors   = reader.ReadByte();

            if (NumColors == 0)
                NumColors = 256;

            NumColors *= 8;
        }

19 View Source File : UEByteProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEByteProperty Read(BinaryReader reader, long valueLength)
        {
            var terminator = reader.ReadByte();
            if (terminator != 0)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");

            // valueLength starts here
            var arrayLength = reader.ReadInt32();
            var bytes = reader.ReadBytes(arrayLength);
            return new UEByteProperty {Value = bytes.AsHex()};
        }

19 View Source File : NameFilterLanguageData.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            MaximumVowelsInARow = reader.ReadUInt32();
            FirstNCharactersMustHaveAVowel = reader.ReadUInt32();
            VowelContainingSubstringLength = reader.ReadUInt32();
            ExtraAllowedCharacters = reader.ReadUInt32();

            Unknown = reader.ReadByte(); // Not sure what this is...

            uint numLetterGroup = reader.ReadUInt32();
            for (uint i = 0; i < numLetterGroup; i++)
                CompoundLetterGroups.Add(reader.ReadUnicodeString());
        }

19 View Source File : SimpleJSON.cs
License : MIT License
Project Creator : 734843327

public static JSONNode Deserialize(System.IO.BinaryReader aReader)
		{
			JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();
			switch(type)
			{
			case JSONBinaryTag.Array:
			{
				int count = aReader.ReadInt32();
				JSONArray tmp = new JSONArray();
				for(int i = 0; i < count; i++)
					tmp.Add(Deserialize(aReader));
				return tmp;
			}
			case JSONBinaryTag.Clreplaced:
			{
				int count = aReader.ReadInt32();				
				JSONClreplaced tmp = new JSONClreplaced();
				for(int i = 0; i < count; i++)
				{
					string key = aReader.ReadString();
					var val = Deserialize(aReader);
					tmp.Add(key, val);
				}
				return tmp;
			}
			case JSONBinaryTag.Value:
			{
				return new JSONData(aReader.ReadString());
			}
			case JSONBinaryTag.IntValue:
			{
				return new JSONData(aReader.ReadInt32());
			}
			case JSONBinaryTag.DoubleValue:
			{
				return new JSONData(aReader.ReadDouble());
			}
			case JSONBinaryTag.BoolValue:
			{
				return new JSONData(aReader.ReadBoolean());
			}
			case JSONBinaryTag.FloatValue:
			{
				return new JSONData(aReader.ReadSingle());
			}
				
			default:
			{
				throw new Exception("Error deserializing JSON. Unknown tag: " + type);
			}
			}
		}

19 View Source File : StringTableData.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            var num_varnames = reader.ReadUInt16();
            for (uint i = 0; i < num_varnames; i++)
                VarNames.Add(reader.ReadUnicodeString());

            var num_vars = reader.ReadUInt16();
            for (uint i = 0; i < num_vars; i++)
                Vars.Add(reader.ReadUnicodeString());

            var num_strings = reader.ReadUInt32();
            for (uint i = 0; i < num_strings; i++)
                Strings.Add(reader.ReadUnicodeString());

            var num_comments = reader.ReadUInt32();
            for (uint i = 0; i < num_comments; i++)
                Comments.Add(reader.ReadUInt32());

            Unknown = reader.ReadByte();
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static ushort BeReadUInt16(this BinaryReader br)
        {
            return (ushort) ((br.ReadByte() << 8) + br.ReadByte());
        }

19 View Source File : LanguageInfo.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private List<char> UnpackList(BinaryReader reader)
        {
            List<char> l = new List<char>();

            byte numElements = reader.ReadByte();
            for (int i = 0; i < numElements; i++)
            {
                ushort c = reader.ReadUInt16();
                l.Add((char)c);
            }

            return l;
        }

19 View Source File : FontCharDesc.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Unpack(BinaryReader reader)
        {
            Unicode = reader.ReadUInt16();
            OffsetX = reader.ReadUInt16();
            OffsetY = reader.ReadUInt16();
            Width = reader.ReadByte();
            Height = reader.ReadByte();
            HorizontalOffsetBefore = reader.ReadByte();
            HorizontalOffsetAfter = reader.ReadByte();
            VerticalOffsetBefore = reader.ReadByte();
        }

19 View Source File : HttpHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin

static string GetFileClreplaced(Stream stream)
      {
         string fileclreplaced = "";
         try
         {
            using (BinaryReader r = new BinaryReader(stream))
            {
               byte buffer = r.ReadByte();
               fileclreplaced = buffer.ToString();
               buffer = r.ReadByte();
               fileclreplaced += buffer.ToString();
            }
         }
         catch { }
         return fileclreplaced;
      }

19 View Source File : ParamSfoEntry.cs
License : MIT License
Project Creator : 13xforever

public static ParamSfoEntry Read(BinaryReader reader, ParamSfo paramSfo, int itemNumber)
        {
            const int indexOffset = 0x14;
            const int indexEntryLength = 0x10;
            reader.BaseStream.Seek(indexOffset + indexEntryLength * itemNumber, SeekOrigin.Begin);
            var result = new ParamSfoEntry();
            result.KeyOffset = reader.ReadUInt16();
            result.ValueFormat = (EntryFormat)reader.ReadUInt16();
            result.ValueLength = reader.ReadInt32();
            result.ValueMaxLength = reader.ReadInt32();
            result.ValueOffset = reader.ReadInt32();

            reader.BaseStream.Seek(paramSfo.KeysOffset + result.KeyOffset, SeekOrigin.Begin);
            byte tmp;
            var sb = new StringBuilder(32);
            while ((tmp = reader.ReadByte()) != 0)
                sb.Append((char)tmp);
            result.Key = sb.ToString();

            reader.BaseStream.Seek(paramSfo.ValuesOffset + result.ValueOffset, SeekOrigin.Begin);
            result.BinaryValue = reader.ReadBytes(result.ValueMaxLength);

            return result;
        }

19 View Source File : ROMManager.cs
License : GNU General Public License v3.0
Project Creator : aglab2

private byte ReadByte()
        {
            return reader.ReadByte();
        }

19 View Source File : EnumMapper.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();
            BaseEnumMap = reader.ReadUInt32();

            NumberingType = (NumberingType)reader.ReadByte();

            uint num_enums = reader.ReadCompressedUInt32();
            for (var i = 0; i < num_enums; i++)
                IdToStringMap.Add(reader.ReadUInt32(), reader.ReadPString(1));
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static uint BeReadUInt32(this BinaryReader br)
        {
            return (uint) ((br.ReadByte() << 24) | (br.ReadByte() << 16) | (br.ReadByte() << 8) | br.ReadByte());
        }

19 View Source File : UEStructProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEStructProperty Read(BinaryReader reader, long valueLength)
        {
            var type = reader.ReadUEString();
            var id = new Guid(reader.ReadBytes(16));
            if (id != Guid.Empty)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 16:x8}. Expected struct ID {Guid.Empty}, but was {id}");

            var terminator = reader.ReadByte();
            if (terminator != 0)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");

            return ReadStructValue(type, reader);
        }

19 View Source File : IrdParser.cs
License : MIT License
Project Creator : 13xforever

public static Ird Parse(byte[] content)
        {
            if (content == null)
                throw new ArgumentNullException(nameof(content));

            if (content.Length < 200)
                throw new ArgumentException("Data is too small to be a valid IRD structure", nameof(content));

            if (BitConverter.ToInt32(content, 0) != Ird.Magic)
                using (var compressedStream = new MemoryStream(content, false))
                using (var gzip = new GZipStream(compressedStream, CompressionMode.Decompress))
                using (var decompressedStream = new MemoryStream())
                {
                    gzip.CopyTo(decompressedStream);
                    content = decompressedStream.ToArray();
                }
            if (BitConverter.ToInt32(content, 0) != Ird.Magic)
                throw new FormatException("Not a valid IRD file");

            var result = new Ird();
            using (var stream = new MemoryStream(content, false))
            using (var reader = new BinaryReader(stream, Encoding.UTF8))
            {
                reader.ReadInt32(); // magic
                result.Version = reader.ReadByte();
                result.ProductCode = Encoding.ASCII.GetString(reader.ReadBytes(9));
                result.replacedleLength = reader.ReadByte();
                result.replacedle = Encoding.UTF8.GetString(reader.ReadBytes(result.replacedleLength));
                result.UpdateVersion = Encoding.ASCII.GetString(reader.ReadBytes(4)).Trim();
                result.GameVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
                result.AppVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
                if (result.Version == 7)
                    result.Id = reader.ReadInt32();
                result.HeaderLength = reader.ReadInt32();
                result.Header = reader.ReadBytes(result.HeaderLength);
                result.FooterLength = reader.ReadInt32();
                result.Footer = reader.ReadBytes(result.FooterLength);
                result.RegionCount = reader.ReadByte();
                result.RegionMd5Checksums = new List<byte[]>(result.RegionCount);
                for (var i = 0; i < result.RegionCount; i++)
                    result.RegionMd5Checksums.Add(reader.ReadBytes(16));
                result.FileCount = reader.ReadInt32();
                result.Files = new List<IrdFile>(result.FileCount);
                for (var i = 0; i < result.FileCount; i++)
                {
                    var file = new IrdFile();
                    file.Offset = reader.ReadInt64();
                    file.Md5Checksum = reader.ReadBytes(16);
                    result.Files.Add(file);
                }
                result.Unknown = reader.ReadInt32();
                if (result.Version == 9)
                    result.Pic = reader.ReadBytes(115);
                result.Data1 = reader.ReadBytes(16);
                result.Data2 = reader.ReadBytes(16);
                if (result.Version < 9)
                    result.Pic = reader.ReadBytes(115);
                result.Uid = reader.ReadInt32();
                var dataLength = reader.BaseStream.Position;
                result.Crc32 = reader.ReadUInt32();

                var crc32 = Crc32Algorithm.Compute(content, 0, (int)dataLength);
                if (result.Crc32 != crc32)
                    throw new InvalidDataException($"Corrupted IRD data, expected {result.Crc32:x8}, but was {crc32:x8}");
            }
            return result;
        }

19 View Source File : TLV_0108.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var bufAccountBasicInfo = new BinaryReader(new MemoryStream(buffer));

                len = bufAccountBasicInfo.BeReadUInt16();
                buffer = bufAccountBasicInfo.ReadBytes(len);
                var info = new BinaryReader(new MemoryStream(buffer));
                var wSsoAccountWFaceIndex = info.BeReadUInt16();
                len = info.ReadByte();
                if (len > 0)
                {
                    user.NickName = Encoding.UTF8.GetString(info.ReadBytes(len));
                }

                user.Gender = info.ReadByte();
                var dwSsoAccountDwUinFlag = info.BeReadUInt32();
                user.Age = info.ReadByte();

                var bufStOther =
                    bufAccountBasicInfo.ReadBytes(
                        (int) (bufAccountBasicInfo.BaseStream.Length - bufAccountBasicInfo.BaseStream.Position));
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0107.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var bufTickStatus = new BinaryReader(new MemoryStream(buffer));
                var dwTgtServiceId = bufTickStatus.BeReadInt32();
                var dwTgtPriority = bufTickStatus.BeReadInt32();
                var dwTgtRefreshInterval = bufTickStatus.BeReadInt32();
                var dwTgtValidInterval = bufTickStatus.BeReadInt32();
                var dwTgtTryInterval = bufTickStatus.BeReadInt32();
                var wTgtTryCount = bufTickStatus.BeReadUInt16();

                buffer = buf.ReadBytes(16);
                user.TXProtocol.BufTgtGtKey = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                user.TXProtocol.BufTgt = buffer;

                buffer = buf.ReadBytes(16);
                user.TXProtocol.Buf16BytesGtKeySt = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                user.TXProtocol.BufServiceTicket = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                var bufStHttp = new BinaryReader(new MemoryStream(buffer));
                var bAllowPtlogin = bufStHttp.ReadByte();
                buffer = bufStHttp.ReadBytes(16);
                user.TXProtocol.Buf16BytesGtKeyStHttp = buffer;

                len = bufStHttp.BeReadUInt16();
                buffer = bufStHttp.ReadBytes(len);
                user.TXProtocol.BufServiceTicketHttp = buffer;

                buffer = buf.ReadBytes(16);
                user.TXProtocol.BufGtKeyTgtPwd = buffer;
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : BinaryReaderExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static string ReadPString(this BinaryReader reader, uint sizeOfLength = 2)
        {
            int stringlength;
            switch (sizeOfLength)
            {
                case 1:
                    stringlength = reader.ReadByte();
                    break;
                case 2:
                default:
                    stringlength = reader.ReadUInt16();
                    break;
            }

            byte[] thestring = reader.ReadBytes(stringlength);

            return System.Text.Encoding.Default.GetString(thestring);
        }

See More Examples