From e2158a210250dee36442086e61a0788fcc656b94 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 30 Mar 2021 23:54:47 +0100 Subject: [PATCH] Storm: Fix reading local files See https://github.com/ladislav-zezula/StormLib/issues/203 --- 3rdParty/StormLib/src/SFileReadFile.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/3rdParty/StormLib/src/SFileReadFile.cpp b/3rdParty/StormLib/src/SFileReadFile.cpp index bd7eafb30..f8eb9d50e 100644 --- a/3rdParty/StormLib/src/SFileReadFile.cpp +++ b/3rdParty/StormLib/src/SFileReadFile.cpp @@ -711,7 +711,12 @@ bool STORMAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWO // If the file is local file, read the data directly from the stream if(hf->pStream != NULL) { - nError = ReadMpqFileLocalFile(hf, pvBuffer, hf->dwFilePos, dwToRead, &dwBytesRead); + ULONGLONG pos; + if (!FileStream_GetPos(hf->pStream, &pos)) { + SetLastError(ERROR_CAN_NOT_COMPLETE); + return false; + } + nError = ReadMpqFileLocalFile(hf, pvBuffer, pos, dwToRead, &dwBytesRead); } #ifdef FULL // If the file is a patch file, we have to read it special way @@ -739,7 +744,8 @@ bool STORMAPI SFileReadFile(HANDLE hFile, void * pvBuffer, DWORD dwToRead, LPDWO } // Increment the file position - hf->dwFilePos += dwBytesRead; + if(hf->pStream == NULL) + hf->dwFilePos += dwBytesRead; // Give the caller the number of bytes read if(pdwRead != NULL)