From 084fac36066aa22a8422a012f5d036ed3e23ed37 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sat, 26 Nov 2022 05:34:05 +0400 Subject: [PATCH] engine: common: hpak: fixed rest of bugs in HPAK_AddLump --- engine/common/hpak.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/engine/common/hpak.c b/engine/common/hpak.c index 9264061a..a949fe5b 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -226,7 +226,7 @@ void HPAK_AddLump( qboolean bUseQueue, const char *name, resource_t *pResource, memset( &ctx, 0, sizeof( MD5Context_t )); MD5Init( &ctx ); - if( pData == NULL ) + if( !pData ) { byte *temp; @@ -327,9 +327,10 @@ void HPAK_AddLump( qboolean bUseQueue, const char *name, resource_t *pResource, dstpak.entries = Z_Malloc( sizeof( hpak_lump_t ) * dstpak.count ); memcpy( dstpak.entries, srcpak.entries, sizeof( hpak_lump_t ) * srcpak.count ); + // check is there are entry with same hash for( i = 0; i < srcpak.count; i++ ) { - if( memcmp( md5, srcpak.entries[i].resource.rgucMD5_hash, 16 )) + if( memcmp( md5, srcpak.entries[i].resource.rgucMD5_hash, 16 ) == 0 ) { pCurrentEntry = &dstpak.entries[i]; @@ -347,8 +348,10 @@ void HPAK_AddLump( qboolean bUseQueue, const char *name, resource_t *pResource, pCurrentEntry->filepos = FS_Tell( file_dst ); pCurrentEntry->disksize = pResource->nDownloadSize; - if( !pData ) FS_FileCopy( file_dst, file_src, pCurrentEntry->disksize ); - else FS_Write( file_dst, pData, pCurrentEntry->disksize ); + if( !pData ) + FS_FileCopy( file_dst, pFile, pCurrentEntry->disksize ); + else + FS_Write( file_dst, pData, pCurrentEntry->disksize ); hash_pack_header.infotableofs = FS_Tell( file_dst ); FS_Write( file_dst, &dstpak.count, sizeof( dstpak.count ));