Skip to content

Commit 0cfc62a

Browse files
committed
mappack awareness.
1 parent 971067a commit 0cfc62a

3 files changed

Lines changed: 421 additions & 7 deletions

File tree

bsputil/bsputil.cc

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,27 @@ FindFaces(const mbsp_t *bsp, const vec3_t pos, const vec3_t normal)
546546
}
547547
}
548548

549+
void Util_PrintUsage(void)
550+
{
551+
printf("usage: bsputil <--command [args]> <bspfile>\n\n");
552+
553+
printf( " --extract-entities\n" " Extract the bsp's entity data as an .ent file\n"
554+
// " --replace-entities entfile\n" " Replaces the bsp's entity data with the specified .ent file\n"
555+
" --extract-textures\n" " Extract the bsp's texture data as an .wad file\n"
556+
// " --replace-texture mipfile texname\n" " Inject the specified .mip file into the bsp\n"
557+
// " --strip-textures\n" " Remove all mip data for copyright compliance.\n"
558+
" --convert bsp29|bsp2|bsp2rmq|q2bsp\n" " Convert between bsp formats\n"
559+
" --check\n" " Verifies indexes and offsets within the bsp.\n"
560+
" --modelinfo\n" " Prints some basic info about inline models.\n"
561+
" --compare otherbsp\n" " List any faces in one bsp not also in the other\n"
562+
" --findfaces x y z nx ny nz\n" " Lists surfaces matching the point+normal\n"
563+
" --settexinfo facenum texinfonum\n" " Change the texinfo entry for a specific surface.\n"
564+
" --decompile\n" " Decompile to .map\n"
565+
" --decompile-geomonly\n" " Decompile bsp tree without regard for actual faces\n"
566+
" --embed file1 [file2 ...]\n" " Embed a file within the bsp. The name will be embedded directly.\n"
567+
" --deembed file1 [file2 ...]\n" " Remove an embedded file by name.\n"
568+
);
569+
}
549570

550571
int
551572
main(int argc, char **argv)
@@ -558,9 +579,7 @@ main(int argc, char **argv)
558579

559580
printf("---- bsputil / ericw-tools " stringify(ERICWTOOLS_VERSION) " ----\n");
560581
if (argc == 1) {
561-
printf("usage: bsputil [--extract-entities] [--extract-textures] [--convert bsp29|bsp2|bsp2rmq|q2bsp] [--check] [--modelinfo]\n"
562-
"[--check] [--compare otherbsp] [--findfaces x y z nx ny nz] [--settexinfo facenum texinfonum]\n"
563-
"[--decompile] [--decompile-geomonly] bspfile\n");
582+
Util_PrintUsage();
564583
exit(1);
565584
}
566585

@@ -601,13 +620,25 @@ main(int argc, char **argv)
601620
}
602621

603622
int fmt;
604-
if (!strcmp(argv[i], "bsp29")) {
623+
const char *targ = argv[i];
624+
if (!strncmp(targ, "quake_", 6))
625+
{
626+
bspdata.hullcount = MAX_MAP_HULLS_Q1;
627+
targ += 6;
628+
}
629+
else if (!strncmp(targ, "hexen2_", 7))
630+
{
631+
bspdata.hullcount = MAX_MAP_HULLS_H2;
632+
targ += 7;
633+
}
634+
635+
if (!strcmp(targ, "bsp29")) {
605636
fmt = BSPVERSION;
606-
} else if (!strcmp(argv[i], "bsp2")) {
637+
} else if (!strcmp(targ, "bsp2")) {
607638
fmt = BSP2VERSION;
608-
} else if (!strcmp(argv[i], "bsp2rmq")) {
639+
} else if (!strcmp(targ, "bsp2rmq")) {
609640
fmt = BSP2RMQVERSION;
610-
} else if (!strcmp(argv[i], "q2bsp")) {
641+
} else if (!strcmp(targ, "q2bsp")) {
611642
fmt = Q2_BSPVERSION;
612643
} else {
613644
Error("Unsupported format %s", argv[i]);
@@ -640,6 +671,49 @@ main(int argc, char **argv)
640671
Error("%s", strerror(errno));
641672

642673
printf("done.\n");
674+
} else if (!strcmp(argv[i], "--deembed")) {
675+
Zip_StartUpdate(&bspdata);
676+
677+
if (i == argc-2)
678+
ZipRepack_RemoveFile(NULL);
679+
else for (; i < argc - 1; i++)
680+
{
681+
int n=i+1;
682+
if (argv[n][0] == '-' && argv[n][1] == '-')
683+
{
684+
if (!argv[n][2])
685+
i=n;
686+
break;
687+
}
688+
i=n;
689+
ZipRepack_RemoveFile(argv[n]);
690+
}
691+
Zip_FinishUpdate(&bspdata);
692+
693+
ConvertBSPFormat(bspdata.loadversion, &bspdata);
694+
WriteBSPFile(source, &bspdata);
695+
} else if (!strcmp(argv[i], "--embed")) {
696+
Zip_StartUpdate(&bspdata);
697+
698+
for (; i < argc - 1; i++)
699+
{
700+
int n=i+1;
701+
if (argv[n][0] == '-' && argv[n][1] == '-')
702+
{
703+
if (!argv[n][2])
704+
i=n;
705+
break;
706+
}
707+
i=n;
708+
709+
void *file_data;
710+
uint32_t flen = LoadFilePak(argv[i], &file_data);
711+
ZipRepack_AddFile(argv[i], file_data, flen);
712+
}
713+
Zip_FinishUpdate(&bspdata);
714+
715+
ConvertBSPFormat(bspdata.loadversion, &bspdata);
716+
WriteBSPFile(source, &bspdata);
643717
} else if (!strcmp(argv[i], "--extract-mips")) {
644718
ExportWad(NULL, bsp);
645719

0 commit comments

Comments
 (0)