示例#1
0
        void ISerializable <BinaryStream> .SerializeObject(BinaryStream s)
        {
            if (s.State == StreamState.Read)
            {
                long offset = s.BaseStream.Position;

                // chunk signature is actually an int32
                var signatureBytes = BitConverter.GetBytes(s.Reader.ReadInt32());
                if (BitConverter.IsLittleEndian && s.Reader.Endianness != ByteOrder.LittleEndian)
                {
                    Array.Reverse(signatureBytes);
                }
                _signature = Encoding.UTF8.GetString(signatureBytes, 0, 4);

                int length = s.Reader.ReadInt32();
                _version = s.Reader.ReadInt16();
                _flags   = s.Reader.ReadInt16();

                byte[] buffer = new byte[length - 12];
                s.BaseStream.Read(buffer, 0, buffer.Length);

                using (var ms = new MemoryStream(buffer))
                    using (var bufferStream = new BinaryStream(ms, StreamState.Read, s.Reader.Endianness, leaveOpen: true))
                        _payload.SerializeObject(bufferStream);

                s.BaseStream.Position = offset + length;
            }
            else if (s.State == StreamState.Write)
            {
                int    length;
                byte[] buffer;
                using (var ms = new MemoryStream())
                {
                    using (var bufferStream = new BinaryStream(ms, StreamState.Write, s.Writer.Endianness, leaveOpen: true))
                        _payload.SerializeObject(bufferStream);

                    length = (int)(ms.Length);
                    buffer = ms.ToArray();
                }

                // chunk signature is actually an int32
                byte[] signature = Encoding.UTF8.GetBytes(_signature);
                if (BitConverter.IsLittleEndian && s.Reader.Endianness != ByteOrder.LittleEndian)
                {
                    Array.Reverse(signature);
                }
                s.Writer.Write(BitConverter.ToInt32(signature, 0));

                s.Writer.Write(length + 12);
                s.Writer.Write(_version);
                s.Writer.Write(_flags);

                s.BaseStream.Write(buffer, 0, length);
            }
        }
示例#2
0
        void ISerializable <BitStream> .SerializeObject(BitStream s)
        {
            s.SerializeObject(_metadata);
            s.Stream(ref _unknownFlag1);
            s.Stream(ref _unknownFlag2);
            s.SerializeObject(_general);
            s.SerializeObject(_prototype);
            s.SerializeObject(_respawn);
            s.SerializeObject(_social);
            s.SerializeObject(_mapOverrides);
            s.SerializeObject(_requisition);
            s.SerializeObject(_teams);
            s.SerializeObject(_loadouts);
            s.SerializeObject(_ordnance);

            switch (_metadata.Engine)
            {
            case GameEngine.PVP:
            case GameEngine.Forge:
                if (_engineData == null)
                {
                    _engineData = new Megalo.MegaloData();
                }
                break;
            }

            if (_engineData != null)
            {
                _engineData.SerializeObject(s);
            }
        }
示例#3
0
        void ISerializable <BitStream> .SerializeObject(BitStream s)
        {
            s.Serialize(_metadata);
            s.Stream(ref _unknownFlag1);
            s.Stream(ref _unknownFlag2);
            s.Serialize(_general);
            s.Serialize(_prototype);
            s.Serialize(_respawn);
            s.Serialize(_social);
            s.Serialize(_mapOverrides);
            s.Serialize(_requisition);
            s.Serialize(_teams);
            s.Serialize(_loadouts);
            s.Serialize(_ordnance);

            if (_engineData != null)
            {
                _engineData.SerializeObject(s);
            }
        }