4 qboolean g_compress_pak;
5 qboolean g_release; // don't grab, copy output data to new tree
6 qboolean g_pak; // if true, copy to pak instead of release
7 char g_releasedir[1024]; // c:\quake2\baseq2, etc
8 qboolean g_archive; // don't grab, copy source data to new tree
10 char g_only[256]; // if set, only grab this cd
11 qboolean g_skipmodel; // set true when a cd is not g_only
13 char *ext_3ds = "3ds";
17 char game[64] = "quake2";
19 void InitPaths( int *argc, char **argv );
22 =======================================================
26 =======================================================
42 packfile_t pfiles[16384];
45 packheader_t pakheader;
54 void BeginPak (char *outname)
59 pakfile = SafeOpenWrite (outname);
61 // leave space for header
62 SafeWrite (pakfile, &pakheader, sizeof(pakheader));
72 Filename should be gamedir reletive.
73 Either copies the file to the release dir, or adds it to
77 void ReleaseFile (char *filename)
87 sprintf (source, "%s%s", gamedir, filename);
91 sprintf (dest, "%s/%s", g_releasedir, filename);
92 printf ("copying to %s\n", dest);
93 QCopyFile (source, dest);
98 printf ("paking %s\n", filename);
99 if (strlen(filename) >= sizeof(pf->name))
100 Error ("Filename too long for pak: %s", filename);
102 len = LoadFile (source, (void **)&buf);
104 if (g_compress_pak && len < 4096*1024 )
107 cblock_t Huffman (cblock_t in);
114 if (out.count < in.count)
116 printf (" compressed from %i to %i\n", in.count, out.count);
125 strcpy (pf->name, filename);
126 pf->filepos = LittleLong(ftell(pakfile));
127 pf->filelen = LittleLong(len);
130 SafeWrite (pakfile, buf, len);
141 void FinishPak (void)
150 pakheader.id[0] = 'P';
151 pakheader.id[1] = 'A';
152 pakheader.id[2] = 'C';
153 pakheader.id[3] = 'K';
154 dirlen = (byte *)pf - (byte *)pfiles;
155 pakheader.dirofs = LittleLong(ftell(pakfile));
156 pakheader.dirlen = LittleLong(dirlen);
158 SafeWrite (pakfile, pfiles, dirlen);
162 fseek (pakfile, 0, SEEK_SET);
163 SafeWrite (pakfile, &pakheader, sizeof(pakheader));
167 printf ("%i files packed in %i bytes\n",d, i);
175 This is only used to cause a file to be copied during a release
176 build (default.cfg, maps, etc)
193 void PackDirectory_r (char *dir)
195 struct _finddata_t fileinfo;
197 char dirstring[1024];
200 sprintf (dirstring, "%s%s/*.*", gamedir, dir);
202 handle = _findfirst (dirstring, &fileinfo);
208 sprintf (filename, "%s/%s", dir, fileinfo.name);
209 if (fileinfo.attrib & _A_SUBDIR)
211 if (fileinfo.name[0] != '.') // don't pak . and ..
212 PackDirectory_r (filename);
215 // copy or pack the file
216 ReleaseFile (filename);
217 } while (_findnext( handle, &fileinfo ) != -1);
223 #include <sys/types.h>
226 void PackDirectory_r (char *dir)
229 struct direct **namelist, *ent;
231 struct dirent **namelist, *ent;
238 char dirstring[1024];
241 sprintf (dirstring, "%s%s", gamedir, dir);
242 count = scandir(dirstring, &namelist, NULL, NULL);
244 for (i=0 ; i<count ; i++)
252 sprintf (fullname, "%s/%s", dir, name);
253 sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
255 if (stat (dirstring, &st) == -1)
256 Error ("fstating %s", pf->name);
257 if (st.st_mode & S_IFDIR)
259 PackDirectory_r (fullname);
263 // copy or pack the file
264 ReleaseFile (fullname);
274 This is only used to cause a directory to be copied during a
275 release build (sounds, etc)
281 PackDirectory_r (token);
284 //========================================================================
286 #define MAX_RTEX 16384
288 char rtex[MAX_RTEX][64];
290 void ReleaseTexture (char *name)
295 for (i=0 ; i<numrtex ; i++)
296 if (!Q_strncasecmp(name, rtex[i], strlen(name)))
299 if (numrtex == MAX_RTEX)
300 Error ("numrtex == MAX_RTEX");
302 strcpy (rtex[i], name);
305 sprintf (path, "textures/%s.wal", name);
313 Only relevent for release and pak files.
314 Releases the .bsp files for the maps, and scans all of the files to
315 build a list of all textures used, which are then released.
323 while (TokenAvailable ())
326 sprintf (map, "maps/%s.bsp", token);
332 // get all the texture references
333 sprintf (map, "%smaps/%s.bsp", gamedir, token);
334 LoadBSPFileTexinfo (map);
335 for (i=0 ; i<numtexinfo ; i++)
336 ReleaseTexture (texinfo[i].texture);
341 //==============================================================
348 void ParseScript (void)
353 { // look for a line starting with a $ command
359 while (TokenAvailable())
366 if (!strcmp (token, "$modelname"))
368 else if (!strcmp (token, "$base"))
370 else if (!strcmp (token, "$cd"))
372 else if (!strcmp (token, "$origin"))
374 else if (!strcmp (token, "$scale"))
376 else if (!strcmp (token, "$frame"))
378 else if (!strcmp (token, "$skin"))
380 else if (!strcmp (token, "$skinsize"))
385 else if (!strcmp (token, "$spritename"))
387 else if (!strcmp (token, "$load"))
389 else if (!strcmp (token, "$spriteframe"))
394 else if (!strcmp (token, "$grab"))
396 else if (!strcmp (token, "$raw"))
398 else if (!strcmp (token, "$colormap"))
400 else if (!strcmp (token, "$mippal"))
402 else if (!strcmp (token, "$mipdir"))
404 else if (!strcmp (token, "$mip"))
406 else if (!strcmp (token, "$environment"))
411 else if (!strcmp (token, "$video"))
416 else if (!strcmp (token, "$file"))
418 else if (!strcmp (token, "$dir"))
420 else if (!strcmp (token, "$maps"))
422 else if (!strcmp (token, "$alphalight"))
424 else if (!strcmp (token, "$inverse16table" ))
425 Cmd_Inverse16Table();
427 Error ("bad command %s\n", token);
431 //=======================================================
438 int main (int argc, char **argv)
440 static int i; // VC4.2 compiler bug if auto...
443 ExpandWildcards (&argc, &argv);
445 InitPaths( &argc, argv );
447 for (i=1 ; i<argc ; i++)
449 if (!strcmp(argv[i], "-archive"))
451 // -archive f:/quake2/release/dump_11_30
453 strcpy (archivedir, argv[i+1]);
454 printf ("Archiving source to: %s\n", archivedir);
457 else if (!strcmp(argv[i], "-release"))
460 strcpy (g_releasedir, argv[i+1]);
461 printf ("Copy output to: %s\n", g_releasedir);
464 else if (!strcmp(argv[i], "-compress"))
466 g_compress_pak = true;
467 printf ("Compressing pakfile\n");
469 else if (!strcmp(argv[i], "-pak"))
473 printf ("Building pakfile: %s\n", argv[i+1]);
474 BeginPak (argv[i+1]);
477 else if (!strcmp(argv[i], "-only"))
479 strcpy (g_only, argv[i+1]);
480 printf ("Only grabbing %s\n", g_only);
483 else if (!strcmp(argv[i], "-3ds"))
486 printf ("loading .3ds files\n");
488 else if (argv[i][0] == '-')
489 Error ("Unknown option \"%s\"", argv[i]);
495 Error ("usage: %s [-archive <directory>] [-release <directory>] [-only <model>] [-3ds] file.qgr", argv[ 0 ] );
498 trifileext = ext_3ds;
500 trifileext = ext_tri;
502 for ( ; i<argc ; i++)
504 printf ("--------------- %s ---------------\n", argv[i]);
506 strcpy (path, argv[i]);
507 DefaultExtension (path, ".qdt");
508 SetQdirFromPath (path);
509 LoadScriptFile (ExpandArg(path));
516 // write out the last model