Пример #1
0
        private void Parse(DatReader reader, List <DatFile> allFiles)
        {
            reader.Seek(Offset); // actual directories are 2 DWORDS over, but validate those 2 DWORDS are 0
            uint word1 = reader.ReadUInt32();
            uint word2 = reader.ReadUInt32();

            if (word1 != 0 || word2 != 0)
            {
                return;
            }

            byte[] buffer = new byte[DatConstants.DIR_BLOCK_SIZE];
            reader.Read(buffer, 0, buffer.Length);

            // directories
            for (int i = 0; i < DatConstants.MAX_DIRS; i++)
            {
                uint newDirSize   = BitConverter.ToUInt32(buffer, (i * 2) * sizeof(uint));
                uint newDirOffset = BitConverter.ToUInt32(buffer, (i * 2) * sizeof(uint) + 4);

                if (Size != newDirSize)
                {
                    break;
                }
                if (newDirOffset == 0x00)
                {
                    break;
                }
                if (newDirOffset == 0xCDCDCDCD)
                {
                    break;
                }

                var subDir = new DatDirectory(newDirOffset, newDirSize);
                Directories.Add(subDir);
            }

            buffer = new byte[DatConstants.FILE_BLOCK_SIZE];
            reader.Read(buffer, 0, buffer.Length);

            // files
            for (int i = 0; i < DatConstants.MAX_FILES; i++)
            {
                // each file is 8 DWORDS
                int     thisFile = i * 8 * sizeof(uint);
                DatFile df       = DatFile.FromDirectoryBuffer(buffer, thisFile);

                if (df != null)
                {
                    Files.Add(df);
                    allFiles.Add(df);
                }
                else
                {
                    break; // null file means end of listing
                }
            }

            Directories.ForEach(d => d.Parse(reader, allFiles));
        }
Пример #2
0
        public byte[] GetData(uint offset, int length)
        {
            try
            {
                byte[] buffer = new byte[length];

                using (var dr = new DatReader(_filename))
                {
                    dr.Seek(offset, SeekOrigin.Begin);
                    dr.Read(buffer, 0, length);
                }

                return(buffer);
            }
            catch (OutOfMemoryException)
            {
                return(System.Text.ASCIIEncoding.ASCII.GetBytes("Not enough memory."));
            }
        }