Example #1
0
        internal MpqFile(MpqArchive archive, uint index)
        {
            if (archive == null) throw new ArgumentNullException("archive");

            this.archive = archive;
            this.blockIndex = index;
        }
Example #2
0
            internal MpqFileCollection(MpqArchive archive)
            {
                if (archive == null)
                {
                    throw new ArgumentNullException("archive");
                }

                this.archive = archive;
            }
Example #3
0
        internal MpqFile(MpqArchive archive, uint index)
        {
            if (archive == null)
            {
                throw new ArgumentNullException("archive");
            }

            this.archive    = archive;
            this.blockIndex = index;
        }
Example #4
0
        private static unsafe bool TestPatchHeader(MpqArchive archive, long offset)
        {
            var sharedBuffer = CommonMethods.GetSharedBuffer(4);

            if (archive.ReadArchiveData(sharedBuffer, 0, offset, 4) != 4)
            {
                throw new EndOfStreamException();
            }

            return(sharedBuffer[0] == 0x50 && sharedBuffer[1] == 0x54 && sharedBuffer[2] == 0x43 && sharedBuffer[3] == 0x48);
        }
Example #5
0
 internal MpqUserDataStream(MpqArchive archive)
 {
     this.archive = archive;
 }
 internal MpqUserDataStream(MpqArchive archive)
 {
     this.archive = archive;
 }
Example #7
0
        private static unsafe bool TestPatchHeader(MpqArchive archive, long offset)
        {
            var sharedBuffer = CommonMethods.GetSharedBuffer(4);

            if (archive.ReadArchiveData(sharedBuffer, 0, offset, 4) != 4) throw new EndOfStreamException();

            return sharedBuffer[0] == 0x50 && sharedBuffer[1] == 0x54 && sharedBuffer[2] == 0x43 && sharedBuffer[3] == 0x48;
        }
Example #8
0
        private static unsafe PatchInfoHeader ReadPatchInfoHeader(MpqArchive archive, long offset)
        {
            // Always get a buffer big enough, even if the extra bytes are not present…
            // As of now (09/2011), the header should always be 28 bytes long, but this may change in the future…
            var sharedBuffer = CommonMethods.GetSharedBuffer(sizeof(PatchInfoHeader));

            // No buffer should ever be smaller than 28 bytes… right ?
            if (archive.ReadArchiveData(sharedBuffer, 0, offset, 28) != 28)
                throw new EndOfStreamException(ErrorMessages.GetString("PatchInfoHeaderEndOfStream")); // It's weird if we could not read the whole 28 bytes… (At worse, we should have read trash data)

            var patchInfoHeader = new PatchInfoHeader();

            patchInfoHeader.HeaderLength = (uint)sharedBuffer[0] | (uint)sharedBuffer[1] << 8 | (uint)sharedBuffer[2] << 16 | (uint)sharedBuffer[3] << 24;
            patchInfoHeader.Flags = (uint)sharedBuffer[4] | (uint)sharedBuffer[5] << 8 | (uint)sharedBuffer[6] << 16 | (uint)sharedBuffer[7] << 24;
            patchInfoHeader.PatchLength = (uint)sharedBuffer[8] | (uint)sharedBuffer[9] << 8 | (uint)sharedBuffer[10] << 16 | (uint)sharedBuffer[11] << 24;

            // Let's assume the MD5 is not mandatory…
            if (patchInfoHeader.HeaderLength >= 28)
                for (int i = 0; i < 16; i++) patchInfoHeader.PatchMD5[i] = sharedBuffer[12 + i];

            return patchInfoHeader;
        }
Example #9
0
        private static unsafe uint[] ReadBlockOffsets(MpqArchive archive, uint hash, long offset, int count)
        {
            int length = count * sizeof(uint);
            var sharedBuffer = CommonMethods.GetSharedBuffer(length);

            if (archive.ReadArchiveData(sharedBuffer, 0, offset, length) != length) throw new EndOfStreamException();

            var offsets = new uint[count];

            Buffer.BlockCopy(sharedBuffer, 0, offsets, 0, length);

            if (!BitConverter.IsLittleEndian) CommonMethods.SwapBytes(offsets);

            // If hash is valid, decode the header
            if (hash != 0) unchecked { CommonMethods.Decrypt(offsets, hash - 1); }

            return offsets;
        }