コード例 #1
0
        public void Write(BinaryWriter bw)
        {
            bw.Write((byte)BINUtilities.PackType(this.EntryType));
            bw.Write(GetContentSize());
            bw.Write(this.Values.Count);

            foreach (BINValue value in this.Values)
            {
                value.Write(bw, false);
            }
        }
コード例 #2
0
        public void Write(BinaryWriter bw)
        {
            bw.Write((byte)this.KeyType);
            bw.Write((byte)BINUtilities.PackType(this.ValueType));
            bw.Write(GetContentSize());
            bw.Write(this.Values.Count);

            foreach (KeyValuePair <BINValue, BINValue> pair in this.Values)
            {
                pair.Key.Write(bw, false);
                pair.Value.Write(bw, false);
            }
        }
コード例 #3
0
        public BINContainer(BinaryReader br, IBINValue parent)
        {
            this.Parent = parent;

            this.EntryType = BINUtilities.UnpackType((BINValueType)br.ReadByte());
            uint size       = br.ReadUInt32();
            uint valueCount = br.ReadUInt32();

            for (int i = 0; i < valueCount; i++)
            {
                this.Values.Add(new BINValue(br, this, this.EntryType));
            }
        }
コード例 #4
0
        public BINOptional(BinaryReader br, IBINValue parent)
        {
            this.Parent = parent;
            this.Type   = BINUtilities.UnpackType((BINValueType)br.ReadByte());
            byte valueCount = br.ReadByte(); //????

            if (valueCount > 1)
            {
                throw new Exception("Encountered an Optional value with Value Count: " + valueCount);
            }

            if (valueCount == 1)
            {
                this.Value = new BINValue(br, this, this.Type);
            }
        }
コード例 #5
0
        public void Write(BinaryWriter bw, bool writeType)
        {
            if (writeType)
            {
                bw.Write(this.Property);
                bw.Write((byte)BINUtilities.PackType(this.Type.Value));
            }

            if (this.Type == BINValueType.None)
            {
            }
            else if (this.Type == BINValueType.Boolean)
            {
                bw.Write((bool)this.Value);
            }
            else if (this.Type == BINValueType.SByte)
            {
                bw.Write((sbyte)this.Value);
            }
            else if (this.Type == BINValueType.Byte)
            {
                bw.Write((byte)this.Value);
            }
            else if (this.Type == BINValueType.Int16)
            {
                bw.Write((short)this.Value);
            }
            else if (this.Type == BINValueType.UInt16)
            {
                bw.Write((ushort)this.Value);
            }
            else if (this.Type == BINValueType.Int32)
            {
                bw.Write((int)this.Value);
            }
            else if (this.Type == BINValueType.UInt32)
            {
                bw.Write((uint)this.Value);
            }
            else if (this.Type == BINValueType.Int64)
            {
                bw.Write((long)this.Value);
            }
            else if (this.Type == BINValueType.UInt64)
            {
                bw.Write((ulong)this.Value);
            }
            else if (this.Type == BINValueType.Float)
            {
                bw.Write((float)this.Value);
            }
            else if (this.Type == BINValueType.FloatVector2)
            {
                ((Vector2)this.Value).Write(bw);
            }
            else if (this.Type == BINValueType.FloatVector3)
            {
                ((Vector2)this.Value).Write(bw);
            }
            else if (this.Type == BINValueType.FloatVector4)
            {
                (this.Value as Vector4).Write(bw);
            }
            else if (this.Type == BINValueType.Matrix44)
            {
                (this.Value as R3DMatrix44).Write(bw);
            }
            else if (this.Type == BINValueType.Color)
            {
                bw.WriteColor((Color)(this.Value), ColorFormat.RgbaU8);
            }
            else if (this.Type == BINValueType.String)
            {
                string value = this.Value as string;
                bw.Write((ushort)value.Length);
                bw.Write(Encoding.ASCII.GetBytes(value));
            }
            else if (this.Type == BINValueType.Hash)
            {
                bw.Write((uint)this.Value);
            }
            else if (this.Type == BINValueType.Container)
            {
                (this.Value as BINContainer).Write(bw);
            }
            else if (this.Type == BINValueType.Structure || this.Type == BINValueType.Embedded)
            {
                (this.Value as BINStructure).Write(bw);
            }
            else if (this.Type == BINValueType.LinkOffset)
            {
                bw.Write((uint)this.Value);
            }
            else if (this.Type == BINValueType.Optional)
            {
                (this.Value as BINOptional).Write(bw);
            }
            else if (this.Type == BINValueType.Map)
            {
                (this.Value as BINMap).Write(bw);
            }
            else if (this.Type == BINValueType.FlagsBoolean)
            {
                bw.Write((bool)this.Value);
            }
        }
コード例 #6
0
        public BINValue(BinaryReader br, IBINValue parent, BINValueType?type = null)
        {
            this.Parent = parent;
            this.Type   = type;
            if (this.Type == null)
            {
                this.Property  = br.ReadUInt32();
                this.Type      = BINUtilities.UnpackType((BINValueType)br.ReadByte());
                this._typeRead = true;
            }

            if (this.Type == BINValueType.None)
            {
                this.Value = null;
            }
            else if (this.Type == BINValueType.Boolean)
            {
                this.Value = br.ReadBoolean();
            }
            else if (this.Type == BINValueType.SByte)
            {
                this.Value = br.ReadSByte();
            }
            else if (this.Type == BINValueType.Byte)
            {
                this.Value = br.ReadByte();
            }
            else if (this.Type == BINValueType.Int16)
            {
                this.Value = br.ReadInt16();
            }
            else if (this.Type == BINValueType.UInt16)
            {
                this.Value = br.ReadUInt16();
            }
            else if (this.Type == BINValueType.Int32)
            {
                this.Value = br.ReadInt32();
            }
            else if (this.Type == BINValueType.UInt32)
            {
                this.Value = br.ReadUInt32();
            }
            else if (this.Type == BINValueType.Int64)
            {
                this.Value = br.ReadInt64();
            }
            else if (this.Type == BINValueType.UInt64)
            {
                this.Value = br.ReadUInt64();
            }
            else if (this.Type == BINValueType.Float)
            {
                this.Value = br.ReadSingle();
            }
            else if (this.Type == BINValueType.FloatVector2)
            {
                this.Value = new Vector2(br);
            }
            else if (this.Type == BINValueType.FloatVector3)
            {
                this.Value = new Vector3(br);
            }
            else if (this.Type == BINValueType.FloatVector4)
            {
                this.Value = new Vector4(br);
            }
            else if (this.Type == BINValueType.Matrix44)
            {
                this.Value = new R3DMatrix44(br);
            }
            else if (this.Type == BINValueType.Color)
            {
                this.Value = br.ReadColor(ColorFormat.RgbaU8);
            }
            else if (this.Type == BINValueType.String)
            {
                this.Value = Encoding.ASCII.GetString(br.ReadBytes(br.ReadUInt16()));
            }
            else if (this.Type == BINValueType.Hash)
            {
                this.Value = br.ReadUInt32();
            }
            else if (this.Type == BINValueType.Container)
            {
                this.Value = new BINContainer(br, this);
            }
            else if (this.Type == BINValueType.Structure || this.Type == BINValueType.Embedded)
            {
                this.Value = new BINStructure(br, this);
            }
            else if (this.Type == BINValueType.LinkOffset)
            {
                this.Value = br.ReadUInt32();
            }
            else if (this.Type == BINValueType.Optional)
            {
                this.Value = new BINOptional(br, this);
            }
            else if (this.Type == BINValueType.Map)
            {
                this.Value = new BINMap(br, this);
            }
            else if (this.Type == BINValueType.FlagsBoolean)
            {
                this.Value = br.ReadBoolean();
            }
            else
            {
                throw new Exception("An Unknown Value Type was encountered: " + (byte)this.Type);
            }
        }
コード例 #7
0
 public void Write(BinaryWriter bw)
 {
     bw.Write((byte)BINUtilities.PackType(this.Type));
     bw.Write(this.Value == null ? (byte)0 : (byte)1);
     this.Value?.Write(bw, false);
 }