Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MTEMP.TMP map header file + related CA_LoadFile changes #63

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ck4_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ bool CK4_IsPresent()
return false;
if (!FS_IsOmniFilePresent("GFXINFOE.CK4"))
return false;
if (!FS_IsOmniFilePresent("MAPHEAD.CK4"))
// MTEMP.TMP was actually the header originally used for compressed maps
if (!FS_IsOmniFilePresent("MAPHEAD.CK4") && !FS_IsOmniFilePresent("MTEMP.TMP"))
return false;
// Map header file may include the tile info
//if (!FS_IsOmniFilePresent("TILEINFO.CK4"))
Expand Down
3 changes: 2 additions & 1 deletion src/ck5_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ bool CK5_IsPresent()
return false;
if (!FS_IsOmniFilePresent("GFXINFOE.CK5"))
return false;
if (!FS_IsOmniFilePresent("MAPHEAD.CK5"))
// MTEMP.TMP was actually the header originally used for compressed maps
if (!FS_IsOmniFilePresent("MAPHEAD.CK5") && !FS_IsOmniFilePresent("MTEMP.TMP"))
return false;
// Map header file may include the tile info
//if (!FS_IsOmniFilePresent("TILEINFO.CK5"))
Expand Down
3 changes: 2 additions & 1 deletion src/ck6_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ bool CK6_IsPresent()
return false;
if (!FS_IsOmniFilePresent("GFXINFOE.CK6"))
return false;
if (!FS_IsOmniFilePresent("MAPHEAD.CK6"))
// MTEMP.TMP was actually the header originally used for compressed maps
if (!FS_IsOmniFilePresent("MAPHEAD.CK6") && !FS_IsOmniFilePresent("MTEMP.TMP"))
return false;
// Map header file may include the tile info
//if (!FS_IsOmniFilePresent("TILEINFO.CK6"))
Expand Down
19 changes: 13 additions & 6 deletions src/id_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ void (*ca_beginCacheBox)(const char *title, int numcache);
void (*ca_updateCacheBox)(void);
void (*ca_finishCacheBox)(void);

bool CA_LoadFile(const char *filename, mm_ptr_t *ptr, int *memsize)
static bool CAL_LoadFile_Int(const char *filename, mm_ptr_t *ptr, int *memsize, bool adjustExt)
{
FS_File f = FS_OpenOmniFile(FS_AdjustExtension(filename));
FS_File f = FS_OpenOmniFile(adjustExt ? FS_AdjustExtension(filename) :
filename);

if (!FS_IsFileValid(f))
return false;
Expand All @@ -190,10 +191,18 @@ bool CA_LoadFile(const char *filename, mm_ptr_t *ptr, int *memsize)
FS_CloseFile(f);

if (amountRead != length)
{
MM_FreePtr(ptr);
return false;
}
return true;
}

bool CA_LoadFile(const char *filename, mm_ptr_t *ptr, int *memsize)
{
return CAL_LoadFile_Int(filename, ptr, memsize, true);
}

//
// Huffman Decompression Code
//
Expand Down Expand Up @@ -951,7 +960,8 @@ void CAL_SetupMapFile(void)
CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "CAL_SetupMapFile: Loading map headers...\n");

int mapHeadFileSize = 0;
CA_LoadFile("MAPHEAD.EXT", (void **)(&ca_MapHead), &mapHeadFileSize);
if (!CAL_LoadFile_Int("MTEMP.TMP", (void **)(&ca_MapHead), &mapHeadFileSize, false))
CA_LoadFile("MAPHEAD.EXT", (void **)(&ca_MapHead), &mapHeadFileSize);
#ifdef CK_CROSS_IS_BIGENDIAN
ca_MapHead->rleTag = CK_Cross_SwapLE16(ca_MapHead->rleTag);
for (int i = 0; i < CA_NUMMAPS; ++i)
Expand All @@ -964,9 +974,6 @@ void CAL_SetupMapFile(void)
ti_tileInfo = NULL;
if (!CA_LoadFile("TILEINFO.EXT", (void **)(&ti_tileInfo), 0))
{
if (ti_tileInfo) // CA_LoadFile may leave a memory leak
MM_FreePtr((void **)&ti_tileInfo);

if (mapHeadFileSize <= sizeof(*ca_MapHead))
Quit("Can't open TILEINFO file, and MAPHEAD file lacks tileinfo data!");

Expand Down