Exemplo n.º 1
0
 private void saveHeader(string path, HFile.HFileHeader header)
 {
     using (StreamWriter streamWriter = new StreamWriter(path + "\\header.txt"))
     {
         streamWriter.Write(BitConverter.ToInt32(header.Magic, 0));
         streamWriter.Write(",");
         streamWriter.Write(BitConverter.ToInt32(header.Version, 0));
         streamWriter.Write(",");
         streamWriter.Write(header.FileTypeOffset);
         streamWriter.Write(",");
         streamWriter.Write(header.FileNameOffset);
         streamWriter.Write(",");
         streamWriter.Write(header.FileTypeCount);
         streamWriter.Write(",");
         streamWriter.Write(header.FileNameLength);
         streamWriter.Write(",");
         streamWriter.Write(header.FileCount);
         streamWriter.Write(",");
         streamWriter.Write(BitConverter.ToInt32(header.Delim1, 0));
         streamWriter.Write(",");
         streamWriter.Write(header.UnknownOffset);
         streamWriter.Write(",");
         streamWriter.Write(header.DataFooterOffset);
         streamWriter.Write(",");
         streamWriter.Write(header.FileIndexOffset);
         streamWriter.Write(",");
         streamWriter.Write(header.FooterOffset1);
         streamWriter.Write(",");
         streamWriter.Write(header.FooterOffset2);
         streamWriter.Write(",");
         streamWriter.Write(header.UnknownCount);
         streamWriter.Write(",");
         streamWriter.Write(BitConverter.ToInt32(header.Delim2, 0));
     }
 }
Exemplo n.º 2
0
 private HFile.HFileHeader loadHeaderFile(string path)
 {
     HFile.HFileHeader hfileHeader = new HFile.HFileHeader();
     using (StreamReader streamReader = new StreamReader(path + "\\header.txt"))
     {
         string[] strArray = streamReader.ReadToEnd().Split(',');
         hfileHeader.Magic            = BitConverter.GetBytes(int.Parse(strArray[0]));
         hfileHeader.Version          = BitConverter.GetBytes(int.Parse(strArray[1]));
         hfileHeader.FileTypeOffset   = ulong.Parse(strArray[2]);
         hfileHeader.FileNameOffset   = ulong.Parse(strArray[3]);
         hfileHeader.FileTypeCount    = int.Parse(strArray[4]);
         hfileHeader.FileNameLength   = int.Parse(strArray[5]);
         hfileHeader.FileCount        = int.Parse(strArray[6]);
         hfileHeader.Delim1           = BitConverter.GetBytes(int.Parse(strArray[7]));
         hfileHeader.UnknownOffset    = ulong.Parse(strArray[8]);
         hfileHeader.DataFooterOffset = ulong.Parse(strArray[9]);
         hfileHeader.FileIndexOffset  = ulong.Parse(strArray[10]);
         hfileHeader.FooterOffset1    = ulong.Parse(strArray[11]);
         hfileHeader.FooterOffset2    = ulong.Parse(strArray[12]);
         hfileHeader.UnknownCount     = int.Parse(strArray[13]);
         hfileHeader.Delim2           = BitConverter.GetBytes(int.Parse(strArray[14]));
     }
     return(hfileHeader);
 }
Exemplo n.º 3
0
        public void Load(string path)
        {
            Hashtable section1 = ConfigurationManager.GetSection("FileTypeExtension") as Hashtable;
            Hashtable section2 = ConfigurationManager.GetSection("HasSizeHeader") as Hashtable;

            using (EnhancedBinaryReader enhancedBinaryReader = new EnhancedBinaryReader((Stream) new FileStream(path, FileMode.Open), Encoding.ASCII, Endian.BigEndian))
            {
                this.Header = new HFile.HFileHeader((BinaryReader)enhancedBinaryReader);
                enhancedBinaryReader.BaseStream.Seek((long)this.Header.FileTypeOffset, SeekOrigin.Begin);
                List <FileTypeIndex> source1 = new List <FileTypeIndex>();
                for (int index = 0; index < this.Header.FileTypeCount; ++index)
                {
                    source1.Add(new FileTypeIndex((BinaryReader)enhancedBinaryReader));
                }
                this.FileTypes = source1.ToArray <FileTypeIndex>();
                for (int index = 0; index < this.FileTypes.Length; ++index)
                {
                    if (section1.ContainsKey((object)this.FileTypes[index].Name))
                    {
                        this.FileTypes[index].Extension = (string)section1[(object)this.FileTypes[index].Name];
                    }
                    if (section2.ContainsKey((object)this.FileTypes[index].Name))
                    {
                        this.FileTypes[index].HasSizeHeader = true;
                    }
                }
                if (this.debug)
                {
                    File.Delete("debug.log");
                }
                enhancedBinaryReader.BaseStream.Seek((long)this.Header.FileIndexOffset, SeekOrigin.Begin);
                List <FileIndex> source2 = new List <FileIndex>();
                for (int index = 0; index < this.Header.FileCount; ++index)
                {
                    if ((int)this.Header.Version[0] == 5)
                    {
                        source2.Add((FileIndex) new StackingFileIndex((BinaryReader)enhancedBinaryReader));
                    }
                    else if ((int)this.Header.Version[0] == 2)
                    {
                        source2.Add((FileIndex) new CostumeQuestFileIndex((BinaryReader)enhancedBinaryReader));
                    }
                }
                this.Files = source2.ToArray <FileIndex>();
                for (int index = 0; index < this.Header.FileCount; ++index)
                {
                    enhancedBinaryReader.BaseStream.Seek((long)this.Header.FileNameOffset + (long)this.Files[index].FileNameOffset, SeekOrigin.Begin);
                    this.Files[index].FilePathString = this.getString((BinaryReader)enhancedBinaryReader);
                    int fileTypeIndex = (int)this.Files[index].FileTypeIndex;
                    if ((int)this.Header.Version[0] == 5)
                    {
                        fileTypeIndex >>= 1;
                    }
                    if (fileTypeIndex >= 0 && fileTypeIndex < this.FileTypes.Length)
                    {
                        this.Files[index].FileType = this.FileTypes[fileTypeIndex];
                    }
                }
                if (enhancedBinaryReader.BaseStream.Length - enhancedBinaryReader.BaseStream.Position > 0L)
                {
                    this.FooterData = enhancedBinaryReader.ReadBytes((int)(enhancedBinaryReader.BaseStream.Length - enhancedBinaryReader.BaseStream.Position));
                }
                else
                {
                    this.FooterData = new byte[0];
                }
            }
        }