Ejemplo n.º 1
0
        public DotNetMultiFileResourceHeaderDataImpl(HexBufferSpan span, Bit7String?resourceTypeSpan, Bit7String?resourceSetTypeSpan, HexPosition versionPosition, HexSpan paddingSpan, Bit7String[] typeNames, int numResources)
            : base(span)
        {
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            MagicNum            = new StructField <UInt32Data>("MagicNum", new UInt32Data(buffer, pos));
            ResMgrHeaderVersion = new StructField <UInt32Data>("ResMgrHeaderVersion", new UInt32Data(buffer, pos + 4));
            HeaderSize          = new StructField <UInt32Data>("HeaderSize", new UInt32Data(buffer, pos + 8));

            if (resourceTypeSpan == null)
            {
                if (resourceSetTypeSpan != null)
                {
                    throw new ArgumentException();
                }
                UnknownHeader = new StructField <VirtualArrayData <ByteData> >("Header", ArrayData.CreateVirtualByteArray(new HexBufferSpan(buffer, HexSpan.FromBounds(pos + 0x0C, versionPosition))));
            }
            else
            {
                if (resourceSetTypeSpan == null)
                {
                    throw new ArgumentNullException(nameof(resourceSetTypeSpan));
                }
                ReaderType      = new StructField <Bit7EncodedStringData>("ReaderType", new Bit7EncodedStringData(buffer, resourceTypeSpan.Value.LengthSpan, resourceTypeSpan.Value.StringSpan, Encoding.UTF8));
                ResourceSetType = new StructField <Bit7EncodedStringData>("ResourceSetType", new Bit7EncodedStringData(buffer, resourceSetTypeSpan.Value.LengthSpan, resourceSetTypeSpan.Value.StringSpan, Encoding.UTF8));
            }

            pos          = versionPosition;
            Version      = new StructField <UInt32Data>("Version", new UInt32Data(buffer, pos));
            NumResources = new StructField <UInt32Data>("NumResources", new UInt32Data(buffer, pos + 4));
            NumTypes     = new StructField <UInt32Data>("NumTypes", new UInt32Data(buffer, pos + 8));
            pos         += 0x0C;

            var fields  = new ArrayField <Bit7EncodedStringData> [typeNames.Length];
            var currPos = pos;

            for (int i = 0; i < fields.Length; i++)
            {
                var info  = typeNames[i];
                var field = new ArrayField <Bit7EncodedStringData>(new Bit7EncodedStringData(buffer, info.LengthSpan, info.StringSpan, Encoding.UTF8), (uint)i);
                fields[i] = field;
                currPos   = field.Data.Span.End;
            }
            TypeNames = new StructField <VariableLengthArrayData <Bit7EncodedStringData> >("TypeNames", new VariableLengthArrayData <Bit7EncodedStringData>(string.Empty, new HexBufferSpan(buffer, HexSpan.FromBounds(pos, currPos)), fields));

            Alignment8 = new StructField <ArrayData <ByteData> >("Padding", ArrayData.CreateByteArray(buffer, paddingSpan.Start, (int)paddingSpan.Length.ToUInt64()));
            pos        = paddingSpan.End;

            NameHashes        = new StructField <VirtualArrayData <UInt32Data> >("NameHashes", ArrayData.CreateVirtualUInt32Array(new HexBufferSpan(buffer, new HexSpan(pos, (ulong)numResources * 4))));
            pos              += (ulong)numResources * 4;
            NamePositions     = new StructField <VirtualArrayData <UInt32Data> >("NamePositions", ArrayData.CreateVirtualUInt32Array(new HexBufferSpan(buffer, new HexSpan(pos, (ulong)numResources * 4))));
            pos              += (ulong)numResources * 4;
            DataSectionOffset = new StructField <FileOffsetData>("DataSectionOffset", new FileOffsetData(buffer, pos));
            pos              += 4;
            if (pos != span.Span.End)
            {
                throw new ArgumentOutOfRangeException(nameof(span));
            }

            var list = new List <BufferField>(13);

            list.Add(MagicNum);
            list.Add(ResMgrHeaderVersion);
            list.Add(HeaderSize);
            if (UnknownHeader != null)
            {
                list.Add(UnknownHeader);
            }
            if (ReaderType != null)
            {
                list.Add(ReaderType);
            }
            if (ResourceSetType != null)
            {
                list.Add(ResourceSetType);
            }
            list.Add(Version);
            list.Add(NumResources);
            list.Add(NumTypes);
            list.Add(TypeNames);
            list.Add(Alignment8);
            list.Add(NameHashes);
            list.Add(NamePositions);
            list.Add(DataSectionOffset);
            Fields = list.ToArray();
        }