Browse Source

Merge pull request #1252 from AJenbo/mpqapi.cpp

General clean up, mostly mpqapi.cpp
pull/133/head
Robin Eklind 7 years ago committed by GitHub
parent
commit
80b3483198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Source/control.cpp
  2. 45
      Source/mpqapi.cpp
  3. 15
      Source/mpqapi.h
  4. 7
      defs.h
  5. 2
      structs.h

2
Source/control.cpp

@ -2404,7 +2404,7 @@ void control_set_gold_curs(int pnum)
else
plr[pnum].HoldItem._iCurs = ICURS_GOLD_MEDIUM;
SetCursor_(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM);
NewCursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM);
}
void DrawTalkPan()

45
Source/mpqapi.cpp

@ -4,7 +4,7 @@
DWORD sgdwMpqOffset;
char mpq_buf[4096];
_HASHENTRY *sgpHashTbl;
BOOL save_archive_modified; // weak
BOOL save_archive_modified;
_BLOCKENTRY *sgpBlockTbl;
BOOLEAN save_archive_open; // weak
@ -29,7 +29,7 @@ BOOL mpqapi_set_hidden(const char *pszArchive, BOOL hidden)
return SetFileAttributes(pszArchive, dwFileAttributesToSet);
}
void mpqapi_store_creation_time(const char *pszArchive, int dwChar)
void mpqapi_store_creation_time(const char *pszArchive, DWORD dwChar)
{
HANDLE handle;
struct _WIN32_FIND_DATAA FindFileData;
@ -283,7 +283,7 @@ _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_i
return pBlk;
}
BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, int dwLen, _BLOCKENTRY *pBlk)
BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk)
{
const char *v4; // esi
const char *v5; // eax
@ -432,7 +432,7 @@ BOOL mpqapi_has_file(const char *pszName)
return FetchHandle(pszName) != -1;
}
BOOL OpenMPQ(const char *pszArchive, BOOL hidden, int dwChar)
BOOL OpenMPQ(const char *pszArchive, BOOL hidden, DWORD dwChar)
{
const char *v3; // ebp
BOOL v4; // esi
@ -457,11 +457,11 @@ BOOL OpenMPQ(const char *pszArchive, BOOL hidden, int dwChar)
if (sghArchive == INVALID_HANDLE_VALUE)
return 0;
save_archive_open = 1;
save_archive_modified = 1;
save_archive_modified = TRUE;
}
if (!sgpBlockTbl || !sgpHashTbl) {
memset(&fhdr, 0, sizeof(fhdr));
if (!ParseMPQHeader(&fhdr, (int *)&sgdwMpqOffset)) {
if (!ParseMPQHeader(&fhdr, &sgdwMpqOffset)) {
LABEL_15:
CloseMPQ(lpFileName, 1, dwChar);
return 0;
@ -489,11 +489,10 @@ BOOL OpenMPQ(const char *pszArchive, BOOL hidden, int dwChar)
}
return 1;
}
// 65AB0C: using guessed type int save_archive_modified;
// 65AB14: using guessed type char save_archive_open;
// 679660: using guessed type char gbMaxPlayers;
BOOL ParseMPQHeader(_FILEHEADER *pHdr, int *pdwNextFileStart)
BOOL ParseMPQHeader(_FILEHEADER *pHdr, DWORD *pdwNextFileStart)
{
DWORD size;
DWORD NumberOfBytesRead;
@ -526,14 +525,14 @@ BOOL ParseMPQHeader(_FILEHEADER *pHdr, int *pdwNextFileStart)
pHdr->sectorsizeid = 3;
pHdr->version = 0;
*pdwNextFileStart = 0x10068;
save_archive_modified = 1;
save_archive_modified = TRUE;
save_archive_open = 1;
}
return TRUE;
}
void CloseMPQ(const char *pszArchive, BOOL bFree, int dwChar)
void CloseMPQ(const char *pszArchive, BOOL bFree, DWORD dwChar)
{
if (bFree) {
MemFreeDbg(sgpBlockTbl);
@ -553,7 +552,7 @@ void CloseMPQ(const char *pszArchive, BOOL bFree, int dwChar)
}
}
void mpqapi_store_modified_time(const char *pszArchive, int dwChar)
void mpqapi_store_modified_time(const char *pszArchive, DWORD dwChar)
{
HANDLE handle;
struct _WIN32_FIND_DATAA FindFileData;
@ -564,30 +563,30 @@ void mpqapi_store_modified_time(const char *pszArchive, int dwChar)
handle = FindFirstFile(pszArchive, &FindFileData);
if (handle != INVALID_HANDLE_VALUE) {
FindClose(handle);
*((FILETIME*) (dst) + dwChar * 2 + 1) = FindFileData.ftLastWriteTime;
*((FILETIME *)(dst) + dwChar * 2 + 1) = FindFileData.ftLastWriteTime;
mpqapi_reg_store_modification_time(dst, 160);
}
}
}
BOOL mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, int dwChar)
BOOL mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, DWORD dwChar)
{
BOOL ret = FALSE;
if (sghArchive == INVALID_HANDLE_VALUE)
BOOL ret = FALSE;
if (sghArchive == INVALID_HANDLE_VALUE)
ret = TRUE;
else {
ret = FALSE;
if (!save_archive_modified)
ret = TRUE;
else if (mpqapi_can_seek() && WriteMPQHeader() && mpqapi_write_block_table()) {
if (mpqapi_write_hash_table())
ret = FALSE;
if (!save_archive_modified)
ret = TRUE;
else if (mpqapi_can_seek() && WriteMPQHeader() && mpqapi_write_block_table()) {
if (mpqapi_write_hash_table())
ret = TRUE;
else
ret = FALSE;
}
}
CloseMPQ(pszArchive, bFree, dwChar);
return ret;
}
CloseMPQ(pszArchive, bFree, dwChar);
return ret;
}
BOOL WriteMPQHeader()

15
Source/mpqapi.h

@ -7,12 +7,11 @@ extern BOOL save_archive_modified; // weak
extern BOOLEAN save_archive_open; // weak
BOOL mpqapi_set_hidden(const char *pszArchive, BOOL hidden);
void mpqapi_store_creation_time(const char *pszArchive, int dwChar);
void mpqapi_store_creation_time(const char *pszArchive, DWORD dwChar);
BOOL mpqapi_reg_load_modification_time(char *dst, int size);
void mpqapi_xor_buf(char *pbData);
void mpqapi_store_default_time(DWORD dwChar);
BOOLEAN mpqapi_reg_store_modification_time(char *pbData, DWORD dwLen);
_BLOCKENTRY *j_mpqapi_remove_hash_entry(char *pszName);
void mpqapi_remove_hash_entry(const char *pszName);
void mpqapi_alloc_block(int block_offset, int block_size);
_BLOCKENTRY *mpqapi_new_block(int *block_index);
@ -21,15 +20,15 @@ int mpqapi_get_hash_index(short index, int hash_a, int hash_b, int locale);
void mpqapi_remove_hash_entries(BOOL(__stdcall *fnGetName)(DWORD, char *));
BOOL mpqapi_write_file(const char *pszName, const BYTE *pbData, DWORD dwLen);
_BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index);
BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, int dwLen, _BLOCKENTRY *pBlk);
BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk);
int mpqapi_find_free_block(int size, int *block_size);
void mpqapi_rename(char *pszOld, char *pszNew);
BOOL mpqapi_has_file(const char *pszName);
BOOL OpenMPQ(const char *pszArchive, BOOL hidden, int dwChar);
BOOL ParseMPQHeader(_FILEHEADER *pHdr, int *pdwNextFileStart);
void CloseMPQ(const char *pszArchive, BOOL bFree, int dwChar);
void mpqapi_store_modified_time(const char *pszArchive, int dwChar);
BOOL mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, int dwChar);
BOOL OpenMPQ(const char *pszArchive, BOOL hidden, DWORD dwChar);
BOOL ParseMPQHeader(_FILEHEADER *pHdr, DWORD *pdwNextFileStart);
void CloseMPQ(const char *pszArchive, BOOL bFree, DWORD dwChar);
void mpqapi_store_modified_time(const char *pszArchive, DWORD dwChar);
BOOL mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, DWORD dwChar);
BOOL WriteMPQHeader();
BOOL mpqapi_write_block_table();
BOOL mpqapi_write_hash_table();

7
defs.h

@ -138,14 +138,7 @@
/////////////////////////////////////////////////////////////////////////
#ifndef IDA_GARBAGE
#define IDA_GARBAGE
// Partially defined types. They are used when the decompiler does not know
// anything about the type except its size.
#define _BYTE unsigned char
#define _DWORD unsigned int
#define _LOBYTE(x) (*((BYTE*)&(x)))
#endif /* IDA_GARBAGE */
// Typedef for the function pointer

2
structs.h

@ -1472,7 +1472,7 @@ typedef struct _FILEHEADER {
int signature;
int headersize;
int filesize;
short version;
WORD version;
short sectorsizeid;
int hashoffset;
int blockoffset;

Loading…
Cancel
Save