Beispiel #1
0
        public void Read(BinaryReader file)
        {
            var mw = file.ReadBytes(4);

            if (!IDString.SequenceEqual(mw))
            {
                throw new InvalidFileTypeException("Invalid file type");
            }

            FileVersion = file.ReadUInt32();
            flags       = file.ReadUInt32();
            Datetime.Read(file, 0);
            buildversion = file.ReadUInt32();

            cr2wsize   = file.ReadUInt32();
            buffersize = file.ReadUInt32();

            crc32     = file.ReadUInt32();
            numchunks = file.ReadUInt32();

            headers = new List <CR2WHeaderData>();

            for (var i = 0; i < 10; i++)
            {
                var head = new CR2WHeaderData(file);
                headers.Add(head);

                if (head.size > 0 && i > 6)
                {
                    // Unhandled blocks
                    Debugger.Break();
                }
            }

            var string_buffer_start = headers[0].offset;

            // Read Strings
            {
                strings = new List <CR2WHeaderString>();

                var string_start = headers[1].offset;
                var string_count = headers[1].size;

                file.BaseStream.Seek(string_start, SeekOrigin.Begin);

                for (var i = 0; i < string_count; i++)
                {
                    var str = new CR2WHeaderString(file);
                    str.ReadString(file, string_buffer_start);
                    strings.Add(str);
                }
            }

            // Read Handles
            {
                handles = new List <CR2WHeaderHandle>();

                var handles_start = headers[2].offset;
                var handles_count = headers[2].size;

                file.BaseStream.Seek(handles_start, SeekOrigin.Begin);

                for (var i = 0; i < handles_count; i++)
                {
                    var handle = new CR2WHeaderHandle(file);
                    handle.ReadString(file, string_buffer_start);
                    handles.Add(handle);
                }
            }

            // TODO: Figure out where these things belong, possibly block 4 or 7?
            //file.BaseStream.Seek(handles[handles.Count - 1].offset + string_buffer_start, SeekOrigin.Begin);
            //file.ReadCR2WString();
            //unknownstrings = new List<string>();
            //while (file.BaseStream.Position < headers[1].offset)
            //{
            //   unknownstrings.Add(file.ReadCR2WString());
            //}

            // Read Unknown Block 4
            {
                block4 = new List <CR2WHeaderBlock4>();

                var block4_start = headers[3].offset;
                var block4_count = headers[3].size;

                file.BaseStream.Seek(block4_start, SeekOrigin.Begin);

                for (var i = 0; i < block4_count; i++)
                {
                    var block = new CR2WHeaderBlock4(file);
                    block4.Add(block);
                }
            }

            // Read Chunks
            {
                chunks = new List <CR2WChunk>();

                var chunk_start = headers[4].offset;
                var chunk_count = headers[4].size;

                file.BaseStream.Seek(chunk_start, SeekOrigin.Begin);

                for (var i = 0; i < chunk_count; i++)
                {
                    var chunktypeId = file.ReadUInt16();

                    var chunk = new CR2WChunk(this);
                    chunk.typeId = chunktypeId;
                    chunk.Read(file);
                    chunks.Add(chunk);
                }
            }

            // Read Unknown Block 6
            {
                block6 = new List <CR2WHeaderBlock6>();

                var block6_start = headers[5].offset;
                var block6_count = headers[5].size;

                file.BaseStream.Seek(block6_start, SeekOrigin.Begin);

                for (var i = 0; i < block6_count; i++)
                {
                    var block = new CR2WHeaderBlock6(file);
                    block6.Add(block);
                }
            }


            // Read Unknown Block 7
            {
                block7 = new List <CR2WHeaderBlock7>();

                var block7_start = headers[6].offset;
                var block7_count = headers[6].size;

                file.BaseStream.Seek(block7_start, SeekOrigin.Begin);

                for (var i = 0; i < block7_count; i++)
                {
                    var block = new CR2WHeaderBlock7(file);
                    block7.Add(block);
                }
            }

            // Read Chunk buffers
            {
                for (var i = 0; i < chunks.Count; i++)
                {
                    chunks[i].ReadData(file);
                }
            }

            // Read Block7 buffers
            {
                for (var i = 0; i < block7.Count; i++)
                {
                    block7[i].ReadString(file, string_buffer_start);
                    block7[i].ReadData(file);
                }
            }

            file.BaseStream.Seek(cr2wsize, SeekOrigin.Begin);

            var actualbuffersize = (int)(buffersize - cr2wsize);

            if (actualbuffersize > 0)
            {
                bufferdata = new byte[actualbuffersize];
                file.BaseStream.Read(bufferdata, 0, actualbuffersize);
            }
        }
Beispiel #2
0
        public void Read(BinaryReader file)
        {
            var numArray = file.ReadBytes(4);

            if (!IDString.SequenceEqual(numArray))
            {
                throw new InvalidFileTypeException("Invalid file type");
            }
            FileVersion = file.ReadUInt32();
            unk2        = file.ReadUInt32();
            unk3        = file.ReadUInt32();
            unk4        = file.ReadUInt32();
            unk5        = file.ReadUInt32();
            cr2wsize    = file.ReadUInt32();
            buffersize  = file.ReadUInt32();
            unk6        = file.ReadUInt32();
            unk7        = file.ReadUInt32();
            headers     = new List <CR2WHeaderData>();
            for (var index = 0; index < 10; ++index)
            {
                var cr2WheaderData = new CR2WHeaderData(file);
                headers.Add(cr2WheaderData);
                if (cr2WheaderData.size > 0U && index > 6)
                {
                    Debugger.Break();
                }
            }

            var offset1 = headers[0].offset;

            strings = new List <CR2WHeaderString>();
            var offset2 = headers[1].offset;
            var size1   = headers[1].size;

            file.BaseStream.Seek(offset2, SeekOrigin.Begin);
            for (var index = 0; (long)index < (long)size1; ++index)
            {
                var cr2WheaderString = new CR2WHeaderString(file);
                cr2WheaderString.ReadString(file, offset1);
                strings.Add(cr2WheaderString);
            }

            handles = new List <CR2WHeaderHandle>();
            var offset3 = headers[2].offset;
            var size2   = headers[2].size;

            file.BaseStream.Seek(offset3, SeekOrigin.Begin);
            for (var index = 0; (long)index < (long)size2; ++index)
            {
                var cr2WheaderHandle = new CR2WHeaderHandle(file);
                cr2WheaderHandle.ReadString(file, offset1);
                handles.Add(cr2WheaderHandle);
            }

            block4 = new List <CR2WHeaderBlock4>();
            var offset4 = headers[3].offset;
            var size3   = headers[3].size;

            file.BaseStream.Seek(offset4, SeekOrigin.Begin);
            for (var index = 0; index < size3; ++index)
            {
                block4.Add(new CR2WHeaderBlock4(file));
            }
            chunks = new List <CR2WChunk>();
            var offset5 = headers[4].offset;
            var size4   = headers[4].size;

            file.BaseStream.Seek(offset5, SeekOrigin.Begin);
            for (var index = 0; index < size4; ++index)
            {
                var num       = file.ReadUInt16();
                var cr2Wchunk = new CR2WChunk(this);
                cr2Wchunk.typeId = num;
                cr2Wchunk.Read(file);
                chunks.Add(cr2Wchunk);
            }

            block6 = new List <CR2WHeaderBlock6>();
            var offset6 = headers[5].offset;
            var size5   = headers[5].size;

            file.BaseStream.Seek(offset6, SeekOrigin.Begin);
            for (var index = 0; index < size5; ++index)
            {
                block6.Add(new CR2WHeaderBlock6(file));
            }
            block7 = new List <CR2WHeaderBlock7>();
            var offset7 = headers[6].offset;
            var size6   = headers[6].size;

            file.BaseStream.Seek(offset7, SeekOrigin.Begin);
            for (var index = 0; index < size6; ++index)
            {
                block7.Add(new CR2WHeaderBlock7(file));
            }
            for (var index = 0; index < chunks.Count; ++index)
            {
                chunks[index].ReadData(file);
            }
            for (var index = 0; index < block7.Count; ++index)
            {
                block7[index].ReadString(file, offset1);
                block7[index].ReadData(file);
            }

            file.BaseStream.Seek(cr2wsize, SeekOrigin.Begin);
            var count = (int)buffersize - (int)cr2wsize;

            if (count <= 0)
            {
                return;
            }
            bufferdata = new byte[count];
            file.BaseStream.Read(bufferdata, 0, count);
        }