Exemplo n.º 1
0
        public AfterBurnerMapEntry(ShockwaveReader input)
        {
            int id = input.Read7BitEncodedInt();

            Offset             = input.Read7BitEncodedInt();
            CompressedLength   = input.Read7BitEncodedInt();
            DecompressedLength = input.Read7BitEncodedInt();
            CompressionType    = (EntryCompressionType)input.Read7BitEncodedInt();

            Header = new ChunkHeader(input.ReadReversedString(4))
            {
                Id     = id,
                Length = DecompressedLength
            };
        }
Exemplo n.º 2
0
        private void ReadInitialLoadSegment(ref ShockwaveReader input, AfterBurnerMapEntry[] entries, Dictionary <int, ChunkItem> chunks)
        {
            //First entry in the AfterBurnerMap must be ILS.
            AfterBurnerMapEntry ilsEntry = entries[0];

            input.Advance(ilsEntry.Offset);

            //TODO: this shouldn't be here
            ReadOnlySpan <byte> compressedData = input.ReadBytes(ilsEntry.Length);

            Span <byte> decompressedData = ilsEntry.DecompressedLength <= 1024 ?
                                           stackalloc byte[ilsEntry.DecompressedLength] : new byte[ilsEntry.DecompressedLength];

            ZLib.Decompress(compressedData, decompressedData);

            ShockwaveReader ilsReader = new ShockwaveReader(decompressedData, input.IsBigEndian);

            while (ilsReader.IsDataAvailable)
            {
                int id = ilsReader.Read7BitEncodedInt();

                AfterBurnerMapEntry entry = entries.FirstOrDefault(e => e.Id == id); //TODO: Chunk entries as dictionary
                if (entry == null)
                {
                    break;
                }

                chunks.Add(id, Read(ref ilsReader, entry.Header));
            }
        }
Exemplo n.º 3
0
 public ChunkHeader(ShockwaveReader input)
     : this(input.ReadReversedString(4))
 {
     Length = (IsVariableLength ?
               input.Read7BitEncodedInt() : input.ReadInt32());
     Offset = input.Position;
 }
Exemplo n.º 4
0
        public AfterburnerMapChunk(ref ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            input.ReadByte();
            Remnants.Enqueue(input.Read7BitEncodedInt());

            using var deflaterInput = CreateDeflateReader(ref input);
            Remnants.Enqueue(deflaterInput.Read7BitEncodedInt());
            Remnants.Enqueue(deflaterInput.Read7BitEncodedInt());

            Entries = new AfterBurnerMapEntry[deflaterInput.Read7BitEncodedInt()];
            for (int i = 0; i < Entries.Length; i++)
            {
                Entries[i] = new AfterBurnerMapEntry(deflaterInput);
            }
        }
Exemplo n.º 5
0
        public AfterburnerMapChunk(ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            input.ReadByte();
            Remnants.Enqueue(input.Read7BitEncodedInt());

            var decompressedInput = WrapDecompressor(input);

            Remnants.Enqueue(decompressedInput.Read7BitEncodedInt());
            Remnants.Enqueue(decompressedInput.Read7BitEncodedInt());

            Entries = new List <AfterBurnerMapEntry>(decompressedInput.Read7BitEncodedInt());
            for (int i = 0; i < Entries.Capacity; i++)
            {
                Entries.Add(new AfterBurnerMapEntry(decompressedInput));
            }
        }
Exemplo n.º 6
0
        public void ReadChunks(List <AfterBurnerMapEntry> entries, Action <ChunkItem> callback)
        {
            int ilsChunkCount = entries.Count(e => e.Offset == -1);

            for (int i = 0; i < ilsChunkCount; i++)
            {
                if (_input.Position >= Header.Length)
                {
                    break;
                }

                int id = _input.Read7BitEncodedInt();

                AfterBurnerMapEntry entry = entries.FirstOrDefault(e => e.Header.Id == id);
                if (entry == null)
                {
                    break;                //TODO:
                }
                entry.Header.Offset = _input.Position;
                callback?.Invoke(Read(_input, entry.Header));
            }
        }
Exemplo n.º 7
0
 public ChunkHeader(ref ShockwaveReader input)
     : this((ChunkKind)input.ReadBEInt32())
 {
     Length = IsVariableLength ?
              input.Read7BitEncodedInt() : input.ReadBEInt32();
 }