MCPcopy Create free account
hub / github.com/Kenix3/libultraship / LoadFullFilePatch

Function LoadFullFilePatch

extern/StormLib/src/SFilePatchArchives.cpp:318–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318static PMPQ_PATCH_HEADER LoadFullFilePatch(TMPQFile * hf, MPQ_PATCH_HEADER & PatchHeader)
319{
320 PMPQ_PATCH_HEADER pFullPatch;
321 DWORD dwErrCode = ERROR_SUCCESS;
322
323 // BSWAP the entire header, if needed
324 BSWAP_ARRAY32_UNSIGNED(&PatchHeader, sizeof(DWORD) * 6);
325 BSWAP_ARRAY32_UNSIGNED(&PatchHeader.dwXFRM, sizeof(DWORD) * 3);
326
327 // Verify the signatures in the patch header
328 if(PatchHeader.dwSignature != PATCH_SIGNATURE_HEADER || PatchHeader.dwMD5 != PATCH_SIGNATURE_MD5 || PatchHeader.dwXFRM != PATCH_SIGNATURE_XFRM)
329 return NULL;
330
331 // Allocate space for patch header and compressed data
332 pFullPatch = (PMPQ_PATCH_HEADER)STORM_ALLOC(BYTE, PatchHeader.dwSizeOfPatchData);
333 if(pFullPatch != NULL)
334 {
335 // Copy the patch header
336 memcpy(pFullPatch, &PatchHeader, sizeof(MPQ_PATCH_HEADER));
337
338 // Read the patch, depending on patch type
339 if(dwErrCode == ERROR_SUCCESS)
340 {
341 switch(PatchHeader.dwPatchType)
342 {
343 case 0x59504f43: // 'COPY'
344 dwErrCode = LoadFilePatch_COPY(hf, pFullPatch);
345 break;
346
347 case 0x30445342: // 'BSD0'
348 dwErrCode = LoadFilePatch_BSD0(hf, pFullPatch);
349 break;
350
351 default:
352 dwErrCode = ERROR_FILE_CORRUPT;
353 break;
354 }
355 }
356
357 // If something failed, free the patch buffer
358 if(dwErrCode != ERROR_SUCCESS)
359 {
360 STORM_FREE(pFullPatch);
361 pFullPatch = NULL;
362 }
363 }
364
365 // Give the result to the caller
366 return pFullPatch;
367}
368
369static DWORD ApplyFilePatch(
370 TMPQPatcher * pPatcher,

Callers 1

Patch_ProcessFunction · 0.85

Calls 2

LoadFilePatch_COPYFunction · 0.85
LoadFilePatch_BSD0Function · 0.85

Tested by

no test coverage detected