From c9199f1229eba9f6202b985f96ba3e20bc5ff886 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 11 May 2019 16:10:49 +0200 Subject: [PATCH] Clean up mpqapi_find_free_block --- Source/mpqapi.cpp | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index abdc8c89a..3107875d8 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -429,36 +429,33 @@ BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, int dwL int mpqapi_find_free_block(int size, int *block_size) { - _BLOCKENTRY *v2; // eax - signed int v3; // esi - int result; // eax - int v5; // esi - BOOLEAN v6; // zf - - v2 = sgpBlockTbl; - v3 = 2048; + _BLOCKENTRY *pBlockTbl; + int i, result; + + pBlockTbl = sgpBlockTbl; + i = 2048; while (1) { - --v3; - if (v2->offset) { - if (!v2->flags && !v2->sizefile && v2->sizealloc >= (unsigned int)size) - break; - } - ++v2; - if (!v3) { + i--; + if (pBlockTbl->offset && !pBlockTbl->flags && !pBlockTbl->sizefile && (DWORD)pBlockTbl->sizealloc >= size) + break; + pBlockTbl++; + if (!i) { *block_size = size; result = sgdwMpqOffset; sgdwMpqOffset += size; return result; } } - v5 = v2->offset; + + result = pBlockTbl->offset; *block_size = size; - v2->offset += size; - v6 = v2->sizealloc == size; - v2->sizealloc -= size; - if (v6) - memset(v2, 0, 0x10u); - return v5; + pBlockTbl->offset += size; + pBlockTbl->sizealloc -= size; + + if (!pBlockTbl->sizealloc) + memset(pBlockTbl, 0, 0x10u); + + return result; } void mpqapi_rename(char *pszOld, char *pszNew) @@ -477,7 +474,6 @@ void mpqapi_rename(char *pszOld, char *pszNew) save_archive_modified = TRUE; } } -// 65AB0C: using guessed type int save_archive_modified; BOOL mpqapi_has_file(const char *pszName) {