From d2c39767e3620ff088844ae00dbee28337175d9e Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 26 Jan 2020 23:29:21 +0000 Subject: [PATCH] mpqapi: Fix open MPQs getting cleared on exit --- Source/mpqapi.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index c26a488ec..ef381ba07 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -366,8 +366,11 @@ BOOL OpenMPQ(const char *pszArchive, DWORD dwChar) key = Hash("(hash table)", 3); Decrypt(sgpHashTbl, 0x8000, key); } - return TRUE; } + // Set output position to the end to ensure the file is not cleared if the MPQ + // is closed without having anything written to it. + if (exists) + GOTO_IF_FAIL(on_error, archive, seekp, 0, std::ios::end); return TRUE; on_error: CloseMPQ(pszArchive, TRUE, dwChar);