CrystalMpq.MpqFileStream.ReadPatchInfoHeader C# (CSharp) Method

ReadPatchInfoHeader() private static method

private static ReadPatchInfoHeader ( MpqArchive archive, long offset ) : PatchInfoHeader
archive MpqArchive
offset long
return PatchInfoHeader
        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;
        }