WadExt WAD extraction tool

Any utility that assists in the creation of mods, assets, etc, go here. For example: Ultimate Doom Builder, Slade, WadSmoosh, Oblige, etc.
Forum rules
The Projects forums are ONLY for YOUR PROJECTS! If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Kappes Buur
 
 
Posts: 4251
Joined: Thu Jul 17, 2003 12:19 am
Graphics Processor: nVidia (Legacy GZDoom)
Location: British Columbia, Canada

Re: WadExt WAD extraction tool

Post by Kappes Buur »

Graf Zahl wrote: Tue Feb 07, 2023 1:05 pm Extraction to a folder has been a thing for a long time. What version are you using?
Just yesterday I was directed to the github page with release version 1.0, and today, upon a new search, I found version 2.1, which indeed creates the new folder.

Great utility :thumb:
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: WadExt WAD extraction tool

Post by Graf Zahl »

I updated the link in the first post so this won't happen again.
User avatar
MartinHowe
Posts: 2112
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Linux Mint
Graphics Processor: nVidia with Vulkan support
Location: East Suffolk (UK)

Re: WadExt WAD extraction tool

Post by MartinHowe »

Warning: group file extract is broken, depending on platform and compiler; this is on Linux Mint with GCC. Posting details here as the GitHub project seems to be abandoned.

In the code below, the fwrite call uses the union member fileinfo Size, which is corrupted by the assignment to NameWithZero; recall that they share the same storage area. On little-endian platforms, this effectively zeros the LSB of the lump size DWORD. Thus the lump is not written out in full. If you compile this yourself, remember to store the fileinfo size in a separate variable before setting the string terminator in the name.

Original:

Code: Select all

void GrpExtract(const char* filename, FILE* f)
{
	TArray<GrpLump> fileinfo;

	GrpInfo header;

	if (1 != fread(&header, sizeof(header), 1, f)) return;

	fileinfo.Resize(header.NumLumps);
	if (header.NumLumps != fread(&fileinfo[0], sizeof(GrpLump), header.NumLumps, f)) return;
	if (memcmp(header.Magic, "KenSilverman", 12))
	{
		return;
	}

	auto name = ExtractFileBase(filename, false);
	mkdir(name.c_str());
	chdir(name.c_str());

	TArray<char> buffer;
	for (uint32_t i = 0; i < header.NumLumps; i++)
	{
		buffer.Resize(fileinfo[i].Size);
		fileinfo[i].NameWithZero[12] = '\0';	// Be sure filename is null-terminated
		if (buffer.Size() != fread(&buffer[0], 1, buffer.Size(), f)) return;
		FILE* fout = fopen(fileinfo[i].NameWithZero, "wb");
		if (fout)
		{
			fwrite(&buffer[0], 1, fileinfo[i].Size, fout);
			fclose(fout);
		}
	}
	exit(1);
}
Fixed:

Code: Select all

void GrpExtract(const char* filename, FILE* f)
{
	TArray<GrpLump> fileinfo;

	GrpInfo header;

	if (1 != fread(&header, sizeof(header), 1, f)) return;

	fileinfo.Resize(header.NumLumps);
	if (header.NumLumps != fread(&fileinfo[0], sizeof(GrpLump), header.NumLumps, f)) return;
	if (memcmp(header.Magic, "KenSilverman", 12))
	{
		return;
	}

	auto name = ExtractFileBase(filename, false);
	mkdir(name.c_str());
	chdir(name.c_str());

	TArray<char> buffer;
	for (uint32_t i = 0; i < header.NumLumps; i++)
	{
	        uint32_t lumpsize = fileinfo[i].Size;	
		buffer.Resize(lumpsize);
		fileinfo[i].NameWithZero[12] = '\0';	// Be sure filename is null-terminated
		if (lumpsize != fread(&buffer[0], 1, lumpsize, f)) return;
		FILE* fout = fopen(fileinfo[i].NameWithZero, "wb");
		if (fout)
		{
			fwrite(&buffer[0], 1, lumpsize, fout);
			fclose(fout);
		}
	}
	exit(1);
}

Return to “Creation, Conversion, and Editing”