Skip to content

Instantly share code, notes, and snippets.

@fnky
Last active January 10, 2017 20:54
Show Gist options
  • Save fnky/af1cbfff3731d1c279a213d570f68c13 to your computer and use it in GitHub Desktop.
Save fnky/af1cbfff3731d1c279a213d570f68c13 to your computer and use it in GitHub Desktop.
010 Editor Template for Parsing Half-Life WAD3
//------------------------------------------------
//--- 010 Editor v7.0.2 Binary Template
//
// File: WAD3
// Authors: @fnky
// Purpose: Parsing Half-Life WAD3 File
// Category: Archive
// File Mask: *.wad
// ID Bytes: 57 41 44 33, 57 41 44 32
//------------------------------------------------
#define MAXTEXTURENAME 16
#define MIPLEVELS 4
typedef enum <byte> {
none = 0, // none
decal = 0x40, // tempdecal.wad
cached = 0x42, // cached.wad
miptex = 0x43, // regular wad
font = 0x46 // font, gfx.wad
} COMPTYPE;
typedef enum <ubyte> {
no, // false
yes // true
} bool;
typedef struct {
char whMagic[4] <name = "Magic", comment = "The magic number tag">;
unsigned int whDir <name = "Directory Size", comment = "The number of directory listings">;
unsigned int whDirOffset <name = "Directory Offset", comment = "The offset of directory">;
} WADHEADER; // 12
typedef struct {
int32 wdTextureOffset <name = "File Position", comment = "Position of lump entry">;
int32 wdDiskSize <name = "Disk Size", comment = "Disk size of lump entry">;
int32 wdSize <name = "Size", comment = "Data size of lump entry">;
COMPTYPE wdType <name = "Type", comment = "Type of lump entry">;
bool wdCompression <name = "Compression", comment = "Whether lump entry is compressed or not">;
char wdPadding[2] <name = "Padding", comment = "Texture padding">;
char wdName[MAXTEXTURENAME] <name = "Texture Names", comment = "Name of textures">;
} WADDIRENTRY; // 32 (WADLUMP)
typedef struct {
char wtName[MAXTEXTURENAME];
unsigned int wtWidth;
unsigned int wtHeight;
unsigned int wtOffsetImage;
unsigned int wtOffsetMipMap1;
unsigned int wtOffsetMipMap2;
unsigned int wtOffsetMipMap3;
unsigned char wtData;
unsigned char wtDataMipMap1;
unsigned char wtDataMipMap2;
unsigned char wtDataMipMap3;
short wtColors;
unsigned char wtPalette[256 * 3];
char wtPadding[2];
} WADTEXTURE;
LittleEndian();
SetBackColor( cLtGray );
WADHEADER wadh;
if (wadh.whMagic != "WAD3") {
Warning("File is not a WAD. Template stopped.");
return -1;
}
local uint dirSize = wadh.whDir;
local uint dirOffset = wadh.whDirOffset;
// Go to dir offset and read textures.
FSeek(dirOffset);
// Read until end of file to read all entries
while (!FEof())
{
SetBackColor( cLtGreen );
WADDIRENTRY wadd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment