Example #1
0
        /*
         *                 ObjectReaderState readerState = new ObjectReaderState(block, this);
         *      frontendObject = chunk.Read(Package, readerState, Reader);
         *
         *      if (Reader.BaseStream.Position - block.DataOffset != block.Size)
         *      {
         *          throw new ChunkReadingException($"ERROR: Expected '{chunk.GetType()}' to read {block.Size} bytes, but it read {Reader.BaseStream.Position - block.DataOffset} bytes instead.");
         *      }
         *
         *      Package.Objects.Add(frontendObject);
         */

        public IObject <ObjectData> ReadFrontendObjectChunks(IObject <ObjectData> frontendObject, long length)
        {
            var endPos = Reader.BaseStream.Position + length;

            while (Reader.BaseStream.Position < endPos)
            {
                var block = new FrontendChunkBlock
                {
                    Offset    = Reader.BaseStream.Position,
                    ChunkType = (FrontendChunkType)Reader.ReadUInt32(),
                    Size      = Reader.ReadInt32()
                };

                FrontendObjectChunk chunk = block.ChunkType switch
                {
                    FrontendChunkType.ObjectData => new ObjectDataChunk(frontendObject),
                    FrontendChunkType.ScriptData => new ScriptDataChunk(frontendObject),
                    FrontendChunkType.MessageResponses => new MessageResponsesDataChunk(frontendObject),
                    _ => throw new ChunkReadingException($"Unknown chunk type: 0x{(int) block.ChunkType:X8}")
                };

                var readerState = new ObjectReaderState(block, this);
                frontendObject = chunk.Read(Package, readerState, Reader);

                if (Reader.BaseStream.Position - block.DataOffset != block.Size)
                {
                    throw new ChunkReadingException(
                              $"ERROR: Expected '{chunk.GetType()}' to read {block.Size} bytes, but it read {Reader.BaseStream.Position - block.DataOffset} bytes instead.");
                }
            }

            return(frontendObject);
        }
    }
Example #2
0
 public abstract IObject <ObjectData> Read(Package package, ObjectReaderState readerState, BinaryReader reader);
Example #3
0
 public abstract FrontendObject Read(FrontendPackage package, ObjectReaderState readerState, BinaryReader reader);