private void LoadBlockOffsets() { int blockposcount = (int)((blockRecord.FileSize + blockSize - 1) / blockSize) + 1; blockPositions = new uint[blockposcount]; lock (mpq.fileStream) { mpq.fileStream.Seek(blockRecord.BlockOffset, SeekOrigin.Begin); var br = new BinaryReader(mpq.fileStream); for (int i = 0; i < blockposcount; i++) { blockPositions[i] = br.ReadUInt32(); } } uint blockpossize = (uint)blockposcount * 4; if (blockRecord.IsEncrypted) { MPQ.DecryptBlock(blockPositions, blockRecord.EncryptionSeed - 1); if (blockPositions[0] != blockpossize) { throw new OpenDiablo2Exception("Decryption failed"); } if (blockPositions[1] > blockSize + blockpossize) { throw new OpenDiablo2Exception("Decryption failed"); } } }
internal MPQStream(MPQ mpq, BlockRecord blockRecord) { this.mpq = mpq; this.blockRecord = blockRecord; this.blockSize = 0x200 << mpq.Header.BlockSize; if (blockRecord.IsCompressed && !blockRecord.SingleUnit) { LoadBlockOffsets(); } }