2003-12-15 05:01:18 +01:00
|
|
|
/*
|
|
|
|
* WAD support routines for PhysicsFS.
|
|
|
|
*
|
|
|
|
* This driver handles DOOM engine archives ("wads").
|
|
|
|
* This format (but not this driver) was designed by id Software for use
|
|
|
|
* with the DOOM engine.
|
|
|
|
* The specs of the format are from the unofficial doom specs v1.666
|
|
|
|
* found here: http://www.gamers.org/dhs/helpdocs/dmsp1666.html
|
|
|
|
* The format of the archive: (from the specs)
|
|
|
|
*
|
|
|
|
* A WAD file has three parts:
|
|
|
|
* (1) a twelve-byte header
|
|
|
|
* (2) one or more "lumps"
|
|
|
|
* (3) a directory or "info table" that contains the names, offsets, and
|
|
|
|
* sizes of all the lumps in the WAD
|
|
|
|
*
|
|
|
|
* The header consists of three four-byte parts:
|
|
|
|
* (a) an ASCII string which must be either "IWAD" or "PWAD"
|
2017-07-16 10:35:46 +02:00
|
|
|
* (b) a uint32 which is the number of lumps in the wad
|
|
|
|
* (c) a uint32 which is the file offset to the start of
|
2003-12-15 05:01:18 +01:00
|
|
|
* the directory
|
|
|
|
*
|
|
|
|
* The directory has one 16-byte entry for every lump. Each entry consists
|
|
|
|
* of three parts:
|
|
|
|
*
|
2017-07-16 10:35:46 +02:00
|
|
|
* (a) a uint32, the file offset to the start of the lump
|
|
|
|
* (b) a uint32, the size of the lump in bytes
|
2003-12-15 05:01:18 +01:00
|
|
|
* (c) an 8-byte ASCII string, the name of the lump, padded with zeros.
|
|
|
|
* For example, the "DEMO1" entry in hexadecimal would be
|
|
|
|
* (44 45 4D 4F 31 00 00 00)
|
|
|
|
*
|
|
|
|
* Note that there is no way to tell if an opened WAD archive is a
|
|
|
|
* IWAD or PWAD with this archiver.
|
|
|
|
* I couldn't think of a way to provide that information, without being too
|
|
|
|
* hacky.
|
|
|
|
* I don't think it's really that important though.
|
|
|
|
*
|
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2003-12-15 05:01:18 +01:00
|
|
|
*
|
|
|
|
* This file written by Travis Wells, based on the GRP archiver by
|
|
|
|
* Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
2012-03-23 05:52:32 +01:00
|
|
|
#if PHYSFS_SUPPORTS_WAD
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
static int wadLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 i;
|
|
|
|
for (i = 0; i < count; i++)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 location;
|
|
|
|
PHYSFS_uint32 size;
|
|
|
|
char name[9];
|
|
|
|
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &location, 4), 0);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 8), 0);
|
|
|
|
|
|
|
|
name[8] = '\0'; /* name might not be null-terminated in file. */
|
|
|
|
size = PHYSFS_swapULE32(size);
|
|
|
|
location = PHYSFS_swapULE32(location);
|
2017-07-22 04:01:51 +02:00
|
|
|
BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, location, size), 0);
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* for */
|
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
return 1;
|
2010-09-06 08:50:29 +02:00
|
|
|
} /* wadLoadEntries */
|
2003-12-15 05:01:18 +01:00
|
|
|
|
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
2003-12-15 05:01:18 +01:00
|
|
|
{
|
2010-08-30 09:01:57 +02:00
|
|
|
PHYSFS_uint8 buf[4];
|
2017-07-16 10:39:14 +02:00
|
|
|
PHYSFS_uint32 count;
|
|
|
|
PHYSFS_uint32 directoryOffset;
|
|
|
|
void *unpkarc;
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2010-08-30 09:01:57 +02:00
|
|
|
assert(io != NULL); /* shouldn't ever happen. */
|
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
|
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL);
|
2010-08-30 09:01:57 +02:00
|
|
|
if ((memcmp(buf, "IWAD", 4) != 0) && (memcmp(buf, "PWAD", 4) != 0))
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof (count)), NULL);
|
2012-03-09 10:50:27 +01:00
|
|
|
count = PHYSFS_swapULE32(count);
|
2003-12-15 05:01:18 +01:00
|
|
|
|
2017-07-16 10:39:14 +02:00
|
|
|
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &directoryOffset, 4), 0);
|
|
|
|
directoryOffset = PHYSFS_swapULE32(directoryOffset);
|
|
|
|
|
|
|
|
BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
|
|
|
|
|
2017-07-21 19:54:42 +02:00
|
|
|
unpkarc = UNPK_openArchive(io);
|
2017-07-16 10:39:14 +02:00
|
|
|
BAIL_IF_ERRPASS(!unpkarc, NULL);
|
|
|
|
|
|
|
|
if (!wadLoadEntries(io, count, unpkarc))
|
|
|
|
{
|
2017-07-22 01:01:41 +02:00
|
|
|
UNPK_abandonArchive(unpkarc);
|
2017-07-16 10:39:14 +02:00
|
|
|
return NULL;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return unpkarc;
|
2003-12-15 05:01:18 +01:00
|
|
|
} /* WAD_openArchive */
|
|
|
|
|
|
|
|
|
2004-09-29 08:18:04 +02:00
|
|
|
const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
|
|
|
|
{
|
2012-11-28 07:36:13 +01:00
|
|
|
CURRENT_PHYSFS_ARCHIVER_API_VERSION,
|
2012-03-25 23:17:56 +02:00
|
|
|
{
|
|
|
|
"WAD",
|
|
|
|
"DOOM engine format",
|
|
|
|
"Travis Wells <traviswells@mchsi.com>",
|
|
|
|
"http://www.3dmm2.com/doom/",
|
2012-11-30 06:04:52 +01:00
|
|
|
0, /* supportsSymlinks */
|
2012-03-25 23:17:56 +02:00
|
|
|
},
|
2012-11-30 20:06:21 +01:00
|
|
|
WAD_openArchive,
|
|
|
|
UNPK_enumerateFiles,
|
|
|
|
UNPK_openRead,
|
|
|
|
UNPK_openWrite,
|
|
|
|
UNPK_openAppend,
|
|
|
|
UNPK_remove,
|
|
|
|
UNPK_mkdir,
|
2012-11-30 20:09:56 +01:00
|
|
|
UNPK_stat,
|
|
|
|
UNPK_closeArchive
|
2004-09-29 08:18:04 +02:00
|
|
|
};
|
|
|
|
|
2003-12-15 05:01:18 +01:00
|
|
|
#endif /* defined PHYSFS_SUPPORTS_WAD */
|
|
|
|
|
2012-11-27 06:12:39 +01:00
|
|
|
/* end of archiver_wad.c ... */
|
2003-12-15 05:01:18 +01:00
|
|
|
|