10 qboolean g_stripify = qtrue;
\r
11 qboolean g_release; // don't grab, copy output data to new tree
\r
12 char g_releasedir[1024]; // c:\quake2\baseq2, etc
\r
13 qboolean g_archive; // don't grab, copy source data to new tree
\r
14 char g_only[256]; // if set, only grab this cd
\r
15 qboolean g_skipmodel; // set true when a cd is not g_only
\r
17 // bogus externs for some TA hacks (common/ using them against q3map)
\r
18 char *moddir = NULL;
\r
19 // some old defined that was in cmdlib lost during merge
\r
20 char writedir[1024];
\r
22 #if defined (__linux__) || defined (__APPLE__)
\r
23 #define strlwr strlower
\r
27 =======================================================
\r
31 =======================================================
\r
37 int filepos, filelen;
\r
47 packfile_t pfiles[16384];
\r
50 packheader_t pakheader;
\r
56 Filename should be gamedir reletive.
\r
57 Either copies the file to the release dir, or adds it to
\r
61 void ReleaseFile (char *filename)
\r
69 sprintf (source, "%s%s", gamedir, filename);
\r
70 sprintf (dest, "%s/%s", g_releasedir, filename);
\r
71 printf ("copying to %s\n", dest);
\r
72 QCopyFile (source, dest);
\r
83 char names[5][1024];
\r
87 ShaderFiles_t s_shaderFiles;
\r
89 void FindShaderFiles( char *filename )
\r
92 char stripped[1024];
\r
93 char linebuffer[1024];
\r
96 char *diffuseExtensions[] =
\r
103 char *otherExtensions[] =
\r
111 s_shaderFiles.num = 0;
\r
113 strcpy( stripped, filename );
\r
114 if ( strrchr( stripped, '.' ) )
\r
115 *strrchr( stripped, '.' ) = 0;
\r
116 strcat( stripped, ".shader" );
\r
118 if ( FileExists( stripped ) )
\r
121 char mapa[512], mapb[512];
\r
123 strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );
\r
124 s_shaderFiles.num++;
\r
127 len = LoadFile( stripped, (void **)&buf);
\r
131 while ( p - buf < len )
\r
136 while ( *p == ' ' || *p == '\n' || *p == '\t' )
\r
139 // grab rest of the line
\r
140 while ( *p != 0 && *p != '\n' )
\r
142 linebuffer[i] = *p;
\r
150 strlwr( linebuffer );
\r
152 // see if the line specifies an opaque map or blendmap
\r
153 if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||
\r
154 strstr( linebuffer, "blendmap" ) == linebuffer )
\r
160 mapa[0] = mapb[0] = 0;
\r
162 // skip past the keyword
\r
163 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
\r
165 // skip past spaces
\r
166 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
\r
169 // grab first map name
\r
171 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
\r
173 mapa[j] = linebuffer[i];
\r
179 // skip past spaces
\r
180 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
\r
183 // grab second map name
\r
185 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
\r
187 mapb[j] = linebuffer[i];
\r
194 if ( mapa[0] != 0 && mapa[0] != '-' )
\r
196 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );
\r
197 s_shaderFiles.num++;
\r
199 if ( mapb[0] != 0 && mapb[0] != '-' && mapb[0] != '^' && mapb[0] != '*' )
\r
201 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapb );
\r
202 s_shaderFiles.num++;
\r
209 if ( strrchr( stripped, '.' ) )
\r
210 *strrchr( stripped, '.' ) = 0;
\r
212 // look for diffuse maps
\r
213 for ( i = 0; i < 3; i++ )
\r
215 strcpy( buffer, stripped );
\r
216 strcat( buffer, diffuseExtensions[i] );
\r
217 if ( FileExists( buffer ) )
\r
219 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
\r
220 s_shaderFiles.num++;
\r
224 for ( i = 0; i < 3; i++ )
\r
226 strcpy( buffer, stripped );
\r
227 strcat( buffer, otherExtensions[i] );
\r
228 if ( FileExists( buffer ) )
\r
230 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
\r
231 s_shaderFiles.num++;
\r
241 Copies all needed files for a shader to the release directory
\r
244 void ReleaseShader( char *filename )
\r
246 char fullpath[1024];
\r
248 char stripped[1024];
\r
251 sprintf( fullpath, "%s%s", gamedir, filename );
\r
253 FindShaderFiles( fullpath );
\r
255 for ( i = 0; i < s_shaderFiles.num; i++ )
\r
257 strcpy( stripped, s_shaderFiles.names[i] );
\r
258 if ( strstr( stripped, gamedir ) )
\r
260 memmove( stripped, stripped+ strlen( gamedir ), strlen( stripped ) );
\r
262 sprintf( dest, "%s/%s", g_releasedir, stripped );
\r
263 printf ("copying to %s\n", dest );
\r
264 QCopyFile( s_shaderFiles.names[i], dest );
\r
272 This is only used to cause a file to be copied during a release
\r
273 build (default.cfg, maps, etc)
\r
276 void Cmd_File (void)
\r
279 ReleaseFile (token);
\r
290 void PackDirectory_r (char *dir)
\r
292 struct _finddata_t fileinfo;
\r
294 char dirstring[1024];
\r
295 char filename[1024];
\r
297 sprintf (dirstring, "%s%s/*.*", gamedir, dir);
\r
299 handle = _findfirst (dirstring, &fileinfo);
\r
305 sprintf (filename, "%s/%s", dir, fileinfo.name);
\r
306 if (fileinfo.attrib & _A_SUBDIR)
\r
308 if (fileinfo.name[0] != '.') // don't pak . and ..
\r
309 PackDirectory_r (filename);
\r
312 // copy or pack the file
\r
313 ReleaseFile (filename);
\r
314 } while (_findnext( handle, &fileinfo ) != -1);
\r
316 _findclose (handle);
\r
320 #include <sys/types.h>
\r
322 #include <sys/dir.h>
\r
324 #include <sys/dirent.h>
\r
327 void PackDirectory_r (char *dir)
\r
330 struct direct **namelist, *ent;
\r
332 struct dirent **namelist, *ent;
\r
338 char fullname[1024];
\r
339 char dirstring[1024];
\r
342 sprintf (dirstring, "%s%s", gamedir, dir);
\r
343 count = scandir(dirstring, &namelist, NULL, NULL);
\r
345 for (i=0 ; i<count ; i++)
\r
347 ent = namelist[i];
\r
348 name = ent->d_name;
\r
350 if (name[0] == '.')
\r
353 sprintf (fullname, "%s/%s", dir, name);
\r
354 sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
\r
356 if (stat (dirstring, &st) == -1)
\r
357 Error ("fstating %s", pf->name);
\r
358 if (st.st_mode & S_IFDIR)
\r
360 PackDirectory_r (fullname);
\r
364 // copy or pack the file
\r
365 ReleaseFile (fullname);
\r
375 This is only used to cause a directory to be copied during a
\r
376 release build (sounds, etc)
\r
379 void Cmd_Dir (void)
\r
382 PackDirectory_r (token);
\r
385 //========================================================================
\r
387 #define MAX_RTEX 16384
\r
389 char rtex[MAX_RTEX][64];
\r
391 void ReleaseTexture (char *name)
\r
396 for (i=0 ; i<numrtex ; i++)
\r
397 if (!Q_stricmp(name, rtex[i]))
\r
400 if (numrtex == MAX_RTEX)
\r
401 Error ("numrtex == MAX_RTEX");
\r
403 strcpy (rtex[i], name);
\r
406 sprintf (path, "textures/%s.wal", name);
\r
407 ReleaseFile (path);
\r
414 Only relevent for release and pak files.
\r
415 Releases the .bsp files for the maps, and scans all of the files to
\r
416 build a list of all textures used, which are then released.
\r
419 void Cmd_Maps (void)
\r
423 while (TokenAvailable ())
\r
426 sprintf (map, "maps/%s.bsp", token);
\r
432 // get all the texture references
\r
433 sprintf (map, "%smaps/%s.bsp", gamedir, token);
\r
434 LoadBSPFile( map );
\r
439 //==============================================================
\r
446 void ParseScript (void)
\r
451 { // look for a line starting with a $ command
\r
455 if (token[0] == '$')
\r
457 while (TokenAvailable())
\r
464 if (!strcmp (token, "$modelname"))
\r
466 else if (!strcmp (token, "$base"))
\r
468 else if ( !strcmp( token, "$exit" ) )
\r
470 else if ( !strcmp( token, "$3dsconvert" ) )
\r
472 else if (!strcmp (token, "$spritebase"))
\r
474 else if (!strcmp (token, "$cd"))
\r
476 else if (!strcmp (token, "$origin"))
\r
478 else if (!strcmp (token, "$scale"))
\r
480 else if (!strcmp (token, "$frame"))
\r
482 else if (!strcmp (token, "$skin" ))
\r
484 else if (!strcmp (token, "$spriteshader"))
\r
485 Cmd_SpriteShader();
\r
486 else if (!strcmp( token, "$aseconvert" ))
\r
487 Cmd_ASEConvert( qfalse );
\r
488 else if (!strcmp( token, "$aseanimconvert" ) )
\r
489 Cmd_ASEConvert( qtrue );
\r
494 else if (!strcmp (token, "$grab"))
\r
496 else if (!strcmp (token, "$raw"))
\r
498 else if (!strcmp (token, "$colormap"))
\r
500 else if (!strcmp (token, "$environment"))
\r
501 Cmd_Environment ();
\r
506 else if (!strcmp (token, "$video"))
\r
511 else if (!strcmp (token, "$file"))
\r
513 else if (!strcmp (token, "$dir"))
\r
515 else if (!strcmp (token, "$maps"))
\r
518 Error ("bad command %s\n", token);
\r
522 //=======================================================
\r
524 #include "version.h"
\r
531 int main (int argc, char **argv)
\r
533 static int i; // VC4.2 compiler bug if auto...
\r
536 // using GtkRadiant's versioning next to Id's versioning
\r
537 printf ("Q3Data - (c) 1999 Id Software Inc.\n");
\r
538 printf ("GtkRadiant - v" RADIANT_VERSION " " __DATE__ "\n");
\r
540 ExpandWildcards (&argc, &argv);
\r
542 for (i=1 ; i<argc ; i++)
\r
544 if (!strcmp(argv[i], "-archive"))
\r
547 strcpy (archivedir, argv[i+1]);
\r
548 printf ("Archiving source to: %s\n", archivedir);
\r
551 else if (!strcmp(argv[i], "-release"))
\r
554 strcpy (g_releasedir, argv[i+1]);
\r
555 printf ("Copy output to: %s\n", g_releasedir);
\r
558 else if ( !strcmp( argv[i], "-nostrips" ) )
\r
560 g_stripify = qfalse;
\r
561 printf( "Not optimizing for strips\n" );
\r
563 else if ( !strcmp( argv[i], "-writedir" ) )
\r
565 strcpy( writedir, argv[i+1] );
\r
566 printf( "Write output to: %s\n", writedir );
\r
569 else if ( !strcmp( argv[i], "-verbose" ) )
\r
573 else if ( !strcmp( argv[i], "-dump" ) )
\r
575 printf( "Dumping contents of: '%s'\n", argv[i+1] );
\r
576 if ( strstr( argv[i+1], ".md3" ) )
\r
578 MD3_Dump( argv[i+1] );
\r
582 Error( "Do not know how to dump the contents of '%s'\n", argv[i+1] );
\r
586 else if ( !strcmp( argv[i], "-3dsconvert" ) )
\r
588 // NOTE TTimo this is broken, tried on a sample .3ds
\r
589 // what happens .. it calls the Convert3DStoMD3,
\r
590 // which calls the scriptlib function in non initialized state .. and crashes
\r
591 printf( "Converting %s.3DS to %s.MD3\n", argv[i+1], argv[i+1] );
\r
592 SetQdirFromPath( argv[i+1] );
\r
593 vfsInitDirectory( gamedir );
\r
594 Convert3DStoMD3( argv[i+1] );
\r
597 else if (!strcmp(argv[i], "-only"))
\r
599 strcpy (g_only, argv[i+1]);
\r
600 printf ("Only grabbing %s\n", g_only);
\r
603 else if (!strcmp(argv[i], "-gamedir"))
\r
605 strcpy(gamedir, argv[i+1]);
\r
608 else if (argv[i][0] == '-')
\r
609 Error ("Unknown option \"%s\"", argv[i]);
\r
615 Error ("usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]");
\r
617 for ( ; i<argc ; i++)
\r
619 printf ("--------------- %s ---------------\n", argv[i]);
\r
621 strcpy (path, argv[i]);
\r
622 DefaultExtension (path, ".qdt");
\r
624 SetQdirFromPath (path);
\r
626 // q3data went through a partial conversion to use the vfs
\r
627 // it was never actually tested before 1.1.1
\r
628 // the code is still mostly using direct file access calls
\r
629 vfsInitDirectory( gamedir );
\r
630 LoadScriptFile (ExpandArg(path), -1);
\r
637 // write out the last model
\r
638 FinishModel ( TYPE_UNKNOWN );
\r