add -dumptables arg to export generated translation tables to PWAD (#1052)

* add -dumptables arg to export generated translation tables to PWAD

Fixes #1033

* start messages on a new line

* Revert "start messages on a new line"

This reverts commit 3896f9d49fecd6a17862cd19ad7b76c4dcd29c34.

* proper new line in message output
This commit is contained in:
Fabian Greffrath 2023-05-12 13:48:44 +02:00 committed by GitHub
parent 4b0cb33234
commit c6735cb110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 11 deletions

View File

@ -2494,6 +2494,19 @@ void D_DoomMain(void)
printf("R_Init: Init DOOM refresh daemon - ");
R_Init();
//!
// @category mod
// @arg <wad>
//
// Allow writing generated lumps out as a WAD.
//
if ((p = M_CheckParm("-dumptables")) && p < myargc-1)
{
puts("\n");
WriteGeneratedLumpWad(myargv[p+1]);
}
puts("\nP_Init: Init Playloop state.");
P_Init();

View File

@ -75,6 +75,7 @@ static const char *params_with_args[] = {
"-deh",
"-dehout",
"-dumplumps",
"-dumptables",
"-fastdemo",
"-maxdemo",
"-playdemo",

View File

@ -30,6 +30,7 @@
#include "i_video.h"
#include "m_argv.h"
#include "m_swap.h"
#include "m_misc2.h"
// Each screen is [SCREENWIDTH*SCREENHEIGHT];
byte *screens[5];
@ -253,6 +254,28 @@ void V_InitColorTranslation(void)
}
}
void WriteGeneratedLumpWad(const char *filename)
{
int i;
const size_t num_lumps = arrlen(crdefs);
lumpinfo_t *lumps = calloc(num_lumps, sizeof(*lumps));
for (i = 0; i < num_lumps - 1; i++) // last entry is dummy
{
M_CopyLumpName(lumps[i].name, crdefs[i].name);
lumps[i].data = *crdefs[i].map2;
lumps[i].size = 256;
}
M_CopyLumpName(lumps[i].name, "TRANMAP");
lumps[i].data = main_tranmap;
lumps[i].size = 256 * 256;
WriteLumpWad(filename, lumps, num_lumps);
free(lumps);
}
//
// V_CopyRect
//

View File

@ -478,7 +478,7 @@ void *W_CacheLumpNum(int lump, pu_tag tag)
// killough 4/22/98: make endian-independent, remove tab chars
// haleyjd 01/21/05: rewritten to use stdio
//
void WritePredefinedLumpWad(const char *filename)
void WriteLumpWad(const char *filename, const lumpinfo_t *lumps, const size_t num_lumps)
{
FILE *file;
char *fn;
@ -495,40 +495,45 @@ void WritePredefinedLumpWad(const char *filename)
if((file = M_fopen(fn, "wb")))
{
wadinfo_t header = { "PWAD" };
size_t filepos = sizeof(wadinfo_t) + num_predefined_lumps * sizeof(filelump_t);
size_t filepos = sizeof(wadinfo_t) + num_lumps * sizeof(filelump_t);
int i;
header.numlumps = LONG(num_predefined_lumps);
header.numlumps = LONG(num_lumps);
header.infotableofs = LONG(sizeof(header));
// write header
fwrite(&header, 1, sizeof(header), file);
// write directory
for(i = 0; i < num_predefined_lumps; i++)
for(i = 0; i < num_lumps; i++)
{
filelump_t fileinfo = { 0 };
fileinfo.filepos = LONG(filepos);
fileinfo.size = LONG(predefined_lumps[i].size);
M_CopyLumpName(fileinfo.name, predefined_lumps[i].name);
fileinfo.size = LONG(lumps[i].size);
M_CopyLumpName(fileinfo.name, lumps[i].name);
fwrite(&fileinfo, 1, sizeof(fileinfo), file);
filepos += predefined_lumps[i].size;
filepos += lumps[i].size;
}
// write lumps
for(i = 0; i < num_predefined_lumps; i++)
fwrite(predefined_lumps[i].data, 1, predefined_lumps[i].size, file);
for(i = 0; i < num_lumps; i++)
fwrite(lumps[i].data, 1, lumps[i].size, file);
fclose(file);
I_Error("Predefined lumps wad, %s written, exiting\n", filename);
I_Error("Internal lumps wad, %s written, exiting\n", filename);
}
I_Error("Cannot open predefined lumps wad %s for output\n", filename);
I_Error("Cannot open internal lumps wad %s for output\n", filename);
free(fn);
}
void WritePredefinedLumpWad(const char *filename)
{
WriteLumpWad(filename, predefined_lumps, num_predefined_lumps);
}
// [FG] name of the WAD file that contains the lump
const char *W_WadNameForLump (const int lump)
{

View File

@ -109,7 +109,9 @@ unsigned W_LumpNameHash(const char *s); // killough 1/31/98
void I_BeginRead(unsigned int bytes), I_EndRead(void); // killough 10/98
// Function to write all predefined lumps to a PWAD if requested
extern void WriteLumpWad(const char *filename, const lumpinfo_t *lumps, const size_t num_lumps);
extern void WritePredefinedLumpWad(const char *filename); // jff 5/6/98
extern void WriteGeneratedLumpWad(const char *filename);
// [FG] name of the WAD file that contains the lump
const char *W_WadNameForLump (const int lump);