Example #1
0
        protected void ReadPrototypeEntry(BinaryStream stream)
        {
            long uid = 0;

            if (Use64Bit)
            {
                uid = stream.ReadInt64();
            }
            else
            {
                uid = stream.ReadUInt32();
            }

            var buffer = (Use64Bit)
                ? BitConverter.GetBytes(uid)
                : BitConverter.GetBytes((uint)uid);

            var lookup = new EntityPrototypeInfo(stream, 8);
            var obj    = Context.GetRefByPtr(lookup.Offset) as NomadObject;

            if (obj == null)
            {
                throw new InvalidDataException($"Couldn't find library '{uid:X8}' at offset {lookup.Offset:X8}!");
            }

            // remove before writing
            var libId = new NomadValue("UID", DataType.BinHex, buffer);

            obj.Attributes.Add(libId);

            Prototypes.Add(uid, obj);
        }
Example #2
0
        public void Deserialize(BinaryStream stream)
        {
            var baseOffset = stream.Position;

            var magic = stream.ReadInt32();

            if (magic != Signature)
            {
                throw new FormatException();
            }

            Version = stream.ReadInt32();

            if (Version != 1)
            {
                throw new FormatException();
            }

            uint offsetData       = stream.ReadUInt32();
            uint offsetHeader     = stream.ReadUInt32();
            uint offsetDescriptor = stream.ReadUInt32();

            if (offsetData != 20)
            {
                throw new FormatException();
            }

            Data = new FCXCompressedData();
            Data.Deserialize(stream);

            if (baseOffset + offsetHeader != stream.Position)
            {
                throw new FormatException();
            }

            Header = new FCXCompressedData();
            Header.Deserialize(stream);

            if (baseOffset + offsetDescriptor != stream.Position)
            {
                throw new FormatException();
            }

            Descriptor = new FCXCompressedData();
            Descriptor.Deserialize(stream);
        }
Example #3
0
        public void Deserialize(BinaryStream stream)
        {
            var offset = stream.ReadInt32();
            var length = offset - 4;

            Data = new byte[length];

            if (stream.Read(Data, 0, length) != length)
            {
                throw new FormatException();
            }

            var blockCount = stream.ReadInt32();

            Blocks = new List <Block>();

            for (int i = 0; i < blockCount; i++)
            {
                var block = new Block()
                {
                    VirtualOffset = stream.ReadUInt32(),
                    FileOffset    = stream.ReadUInt32(),
                };

                block.IsCompressed = (block.FileOffset & 0x80000000) != 0;
                block.FileOffset  &= 0x7FFFFFFF;

                Blocks.Add(block);
            }

            if (Blocks.Count == 0)
            {
                throw new FormatException();
            }

            if (Blocks.First().FileOffset != 4)
            {
                throw new FormatException();
            }

            if (Blocks.Last().FileOffset != (4 + length))
            {
                throw new FormatException();
            }
        }
Example #4
0
        public void Deserialize(BinaryStream stream)
        {
            if (Use32Bit)
            {
                UID = stream.ReadUInt32();
            }
            else
            {
                UID = stream.ReadInt64();
            }

            Offset     = stream.ReadInt32() + 8;
            TotalCount = stream.ReadUInt16();
            NodesCount = stream.ReadUInt16();
        }
Example #5
0
        public static DescriptorTag Read(BinaryStream stream, ReferenceType refType = ReferenceType.None)
        {
            var ptr = (int)stream.Position;

            var value = stream.ReadByte();
            var type  = GetDescriptorType(value);

            if ((type == DescriptorType.Reference) && (refType == ReferenceType.None))
            {
                throw new InvalidOperationException("ID:10T error while reading a descriptor -- consumed a reference with no type defined!");
            }

            var isOffset = (type == DescriptorType.Reference) &&
                           (refType == ReferenceType.Offset);

            if (type != DescriptorType.None)
            {
                if (GlobalFlags.HasFlag(DescriptorFlags.Use24Bit))
                {
                    // move back
                    stream.Position -= 1;

                    // read in value without control code
                    value = (int)(stream.ReadUInt32() >> 8);
                }
                else
                {
                    value = stream.ReadInt32();
                }

                if (isOffset)
                {
                    // make offset absolute
                    value = (ptr - value);
                }
            }

            return(new DescriptorTag(value, type, refType));
        }