Пример #1
0
 public virtual byte[] ToArray(bool TryHashTableNormalize = false)
 {
     using (ByteStream ms = new ByteStream())
     {
         if (TryHashTableNormalize)
         {
             HashTable.Fill(BlockTable.Count.BitUpper());
         }
         Header.HashTableSize  = (uint)HashTable.Count;
         Header.BlockTableSize = (uint)BlockTable.Count;
         ms.WriteEmpty(0x20);
         foreach (var item in Files)
         {
             if ((item.Block.Flags & MPQ_FILE_FIX_KEY) != 0)
             {
                 item.Decrypt();
                 item.Block.FilePos = (int)ms.Length;
                 item.Encrypt(true);
             }
             else
             {
                 item.Block.FilePos = (int)ms.Length;
             }
             ms.Write(item.RawFile);
         }
         Header.HashTablePos = (int)ms.Length;
         byte[] Buffer = HashTable.ToArray();
         if (Buffer != null)
         {
             Buffer.EncryptBlock(MPQ_HASH_KEY);
             ms.Write(Buffer);
         }
         Header.BlockTablePos = (int)ms.Length;
         Buffer = BlockTable.ToArray();
         if (Buffer != null)
         {
             Buffer.EncryptBlock(MPQ_BLOCK_KEY);
             ms.Write(Buffer);
         }
         Header.ArchiveSize = (uint)ms.Length;
         ms.Seek(0, SeekOrigin.Begin);
         ms.Write(Header.ToArray());
         return(ms.ToArray());
     }
 }