MCPcopy Create free account
hub / github.com/diasurgical/devilution / DecryptMpqBlock

Function DecryptMpqBlock

3rdParty/StormLib/src/SBaseCommon.cpp:417–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417void DecryptMpqBlock(void * pvDataBlock, DWORD dwLength, DWORD dwKey1)
418{
419 LPDWORD DataBlock = (LPDWORD)pvDataBlock;
420 DWORD dwValue32;
421 DWORD dwKey2 = 0xEEEEEEEE;
422
423 // Round to DWORDs
424 dwLength >>= 2;
425
426 // Decrypt the data block at array of DWORDs
427 for(DWORD i = 0; i < dwLength; i++)
428 {
429 // Modify the second key
430 dwKey2 += StormBuffer[MPQ_HASH_KEY2_MIX + (dwKey1 & 0xFF)];
431
432 DataBlock[i] = DataBlock[i] ^ (dwKey1 + dwKey2);
433 dwValue32 = DataBlock[i];
434
435 dwKey1 = ((~dwKey1 << 0x15) + 0x11111111) | (dwKey1 >> 0x0B);
436 dwKey2 = dwValue32 + dwKey2 + (dwKey2 << 5) + 3;
437 }
438}
439
440/**
441 * Functions tries to get file decryption key. This comes from these facts

Callers 6

LoadExtTableFunction · 0.85
LoadSqpTableFunction · 0.85
LoadMpqTableFunction · 0.85
AllocateSectorOffsetsFunction · 0.85
ReadMpqSectorsFunction · 0.85
ReadMpqFileSingleUnitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected