can now extract entities from foo.bsp to foo.ent

This commit is contained in:
Bill Currie 2004-04-30 21:51:00 +00:00
parent 9f4942cf6c
commit a12074c1a6
5 changed files with 87 additions and 37 deletions

View file

@ -247,6 +247,7 @@ qboolean FillOutside (node_t *node);
void LoadBSP (void);
void bsp2prt (void);
void extract_textures (void);
void extract_entities (void);
//=============================================================================

View file

@ -39,7 +39,9 @@ typedef struct {
qboolean noclip;
qboolean onlyents;
qboolean portal;
qboolean extract;
qboolean extract_textures;
qboolean extract_entities;
qboolean usehulls;
qboolean watervis;
int hullnum;

View file

@ -58,7 +58,8 @@ static struct option const long_options[] = {
{"noclip", no_argument, 0, 'c'},
{"onlyents", no_argument, 0, 'e'},
{"portal", no_argument, 0, 'p'},
{"extract-textures", no_argument, 0, 'E'},
{"extract-textures", no_argument, 0, 256},
{"extract-entities", no_argument, 0, 257},
{"usehulls", no_argument, 0, 'u'},
{"hullnum", required_argument, 0, 'H'},
{"subdivide", required_argument, 0, 's'},
@ -78,7 +79,6 @@ static const char *short_options =
"c" // noclip
"e" // onlyents
"p" // portal
"E" // extract-texures
"u" // usehulls
"H:" // hullnum
"s:" // subdivide
@ -155,11 +155,17 @@ DecodeArgs (int argc, char **argv)
options.onlyents = true;
break;
case 'p': // portal
options.extract = true;
options.portal = true;
break;
case 'E': // extract-textures
case 256: // extract-textures
options.extract = true;
options.extract_textures = true;
break;
case 257: // extract-entities
options.extract = true;
options.extract_entities = true;
break;
case 'u': // usehulls
options.usehulls = true;
break;
@ -179,22 +185,38 @@ DecodeArgs (int argc, char **argv)
usage (1);
}
}
if (argv[optind] && *(argv[optind])) {
options.mapfile = malloc (strlen(argv[optind]) + 5);
strcpy (options.mapfile, argv[optind++]);
} else {
usage (1);
}
if (argv[optind] && *(argv[optind])) {
if (options.extract) {
options.bspfile = strdup (argv[optind++]);
} else {
options.bspfile = malloc (strlen (options.mapfile) + 5);
QFS_StripExtension (options.mapfile, options.bspfile);
strcat (options.bspfile, ".bsp");
if (argv[optind] && *(argv[optind])) {
options.mapfile = malloc (strlen(argv[optind]) + 5);
strcpy (options.mapfile, argv[optind++]);
} else {
usage (1);
}
if (argv[optind] && *(argv[optind])) {
options.bspfile = strdup (argv[optind++]);
} else {
options.bspfile = malloc (strlen (options.mapfile) + 5);
QFS_StripExtension (options.mapfile, options.bspfile);
strcat (options.bspfile, ".bsp");
}
options.hullfile = malloc (strlen (options.bspfile) + 5);
options.portfile = malloc (strlen (options.bspfile) + 5);
options.pointfile = malloc (strlen (options.bspfile) + 5);
// create filenames
QFS_StripExtension (options.bspfile, options.hullfile);
strcat (options.hullfile, ".h0");
QFS_StripExtension (options.bspfile, options.portfile);
strcat (options.portfile, ".prt");
QFS_StripExtension (options.bspfile, options.pointfile);
strcat (options.pointfile, ".pts");
}
options.hullfile = malloc (strlen (options.bspfile) + 5);
options.portfile = malloc (strlen (options.bspfile) + 5);
options.pointfile = malloc (strlen (options.bspfile) + 5);
if (options.wadpath) {
char *t = malloc (strlen (options.wadpath) + 2);
strcpy (t, ";");

View file

@ -755,25 +755,16 @@ CreateHulls (void)
static void
ProcessFile (void)
{
// create filenames
QFS_StripExtension (options.bspfile, options.hullfile);
strcat (options.hullfile, ".h0");
QFS_StripExtension (options.bspfile, options.portfile);
strcat (options.portfile, ".prt");
QFS_StripExtension (options.bspfile, options.pointfile);
strcat (options.pointfile, ".pts");
bsp = BSP_New ();
if (options.portal) {
LoadBSP ();
bsp2prt ();
return;
}
if (options.extract_textures) {
if (options.extract) {
LoadBSP ();
extract_textures ();
if (options.portal)
bsp2prt ();
if (options.extract_textures)
extract_textures ();
if (options.extract_entities)
extract_entities ();
return;
}

View file

@ -220,7 +220,7 @@ LoadBSP (void)
{
QFile *f;
f = Qopen (options.bspfile, "rb");
f = Qopen (options.bspfile, "rbz");
if (!f)
Sys_Error ("couldn't open %s. %s", options.bspfile, strerror(errno));
bsp = LoadBSPFile (f, Qfilesize (f));
@ -241,11 +241,27 @@ LoadBSP (void)
load_textures ();
}
static char *
output_file (const char *ext)
{
char *name;
name = malloc (strlen (options.bspfile) + strlen (ext) + 1);
QFS_StripExtension (options.bspfile, name);
if (strcmp (QFS_FileExtension (options.bspfile), ".gz") == 0) {
QFS_StripExtension (name, name);
}
strcat (name, ext);
return name;
}
void
bsp2prt (void)
{
vec3_t ooo = {1, 1, 1};
options.portfile = output_file (".prt");
VectorSubtract (bsp->models[0].mins, ooo, bs.mins);
VectorAdd (bsp->models[0].maxs, ooo, bs.maxs);
brushset = &bs;
@ -329,9 +345,7 @@ extract_textures (void)
char *wadfile = malloc (strlen (options.bspfile) + 5);
wad_t *wad;
wadfile = malloc (strlen (options.bspfile) + 5);
QFS_StripExtension (options.bspfile, wadfile);
strcat (wadfile, ".wad");
wadfile = output_file (".wad");
wad = wad_create (wadfile);
@ -339,15 +353,35 @@ extract_textures (void)
sizeof (default_palette));
for (i = 0; i < miptexlump->nummiptex; i++) {
printf ("%3d %6d ", i, miptexlump->dataofs[i]);
miptex = (miptex_t *)(bsp->texdata + miptexlump->dataofs[i]);
pixels = miptex->width * miptex->height / 64 * 85;
mtsize = sizeof (miptex_t) + pixels;
#if 0
printf ("%3d %6d ", i, miptexlump->dataofs[i]);
printf ("%16s %3dx%-3d %d %d %d %d %d %d\n",
miptex->name, miptex->width,
miptex->height, miptex->offsets[0], miptex->offsets[1],
miptex->offsets[2], miptex->offsets[3], pixels, mtsize);
#endif
wad_add_data (wad, miptex->name, TYP_MIPTEX, miptex, mtsize);
}
wad_close (wad);
}
void
extract_entities (void)
{
char *entfile = malloc (strlen (options.bspfile) + 5);
int i;
QFile *ef;
entfile = output_file (".ent");
for (i = bsp->entdatasize; i > 0; i--)
if (bsp->entdata[i - 1])
break;
ef = Qopen (entfile, "wt");
Qwrite (ef, bsp->entdata, i);
Qclose (ef);
}