2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "globaldefs.h"
26 #endif // GDEF_OS_WINDOWS
34 qboolean g_stripify = qtrue;
35 qboolean g_release; // don't grab, copy output data to new tree
36 char g_releasedir[1024]; // c:\quake2\baseq2, etc
37 qboolean g_archive; // don't grab, copy source data to new tree
38 char g_only[256]; // if set, only grab this cd
39 qboolean g_skipmodel; // set true when a cd is not g_only
41 // bogus externs for some TA hacks (common/ using them against q3map)
45 #define strlwr strlower
46 #endif // !GDEF_OS_WINDOWS
49 =======================================================
53 =======================================================
56 unsigned Com_BlockChecksum( void *buffer, int length );
71 packfile_t pfiles[16384];
74 packheader_t pakheader;
80 Filename should be gamedir reletive.
81 Either copies the file to the release dir, or adds it to
85 void ReleaseFile( char *filename ){
93 sprintf( source, "%s%s", gamedir, filename );
94 sprintf( dest, "%s/%s", g_releasedir, filename );
95 printf( "copying to %s\n", dest );
96 QCopyFile( source, dest );
111 ShaderFiles_t s_shaderFiles;
113 void FindShaderFiles( char *filename ){
116 char linebuffer[1024];
119 char *diffuseExtensions[] =
126 char *otherExtensions[] =
134 s_shaderFiles.num = 0;
136 strcpy( stripped, filename );
137 if ( strrchr( stripped, '.' ) ) {
138 *strrchr( stripped, '.' ) = 0;
140 strcat( stripped, ".shader" );
142 if ( FileExists( stripped ) ) {
144 char mapa[512], mapb[512];
146 strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );
150 len = LoadFile( stripped, (void **)&buf );
154 while ( p - buf < len )
159 while ( *p == ' ' || *p == '\n' || *p == '\t' )
162 // grab rest of the line
163 while ( *p != 0 && *p != '\n' )
174 strlwr( linebuffer );
176 // see if the line specifies an opaque map or blendmap
177 if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||
178 strstr( linebuffer, "blendmap" ) == linebuffer ) {
183 mapa[0] = mapb[0] = 0;
185 // skip past the keyword
186 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
189 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
192 // grab first map name
194 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
196 mapa[j] = linebuffer[i];
203 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
206 // grab second map name
208 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
210 mapb[j] = linebuffer[i];
217 if ( mapa[0] != 0 && mapa[0] != '-' ) {
218 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );
221 if ( mapb[0] != 0 && mapb[0] != '-' && mapb[0] != '^' && mapb[0] != '*' ) {
222 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapb );
230 if ( strrchr( stripped, '.' ) ) {
231 *strrchr( stripped, '.' ) = 0;
234 // look for diffuse maps
235 for ( i = 0; i < 3; i++ )
237 strcpy( buffer, stripped );
238 strcat( buffer, diffuseExtensions[i] );
239 if ( FileExists( buffer ) ) {
240 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
245 for ( i = 0; i < 3; i++ )
247 strcpy( buffer, stripped );
248 strcat( buffer, otherExtensions[i] );
249 if ( FileExists( buffer ) ) {
250 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
261 Copies all needed files for a shader to the release directory
264 void ReleaseShader( char *filename ){
270 sprintf( fullpath, "%s%s", gamedir, filename );
272 FindShaderFiles( fullpath );
274 for ( i = 0; i < s_shaderFiles.num; i++ )
276 strcpy( stripped, s_shaderFiles.names[i] );
277 if ( strstr( stripped, gamedir ) ) {
278 memmove( stripped, stripped + strlen( gamedir ), strlen( stripped ) );
280 sprintf( dest, "%s/%s", g_releasedir, stripped );
281 printf( "copying to %s\n", dest );
282 QCopyFile( s_shaderFiles.names[i], dest );
290 This is only used to cause a file to be copied during a release
291 build (default.cfg, maps, etc)
294 void Cmd_File( void ){
296 ReleaseFile( token );
307 void PackDirectory_r( char *dir ){
308 struct _finddata_t fileinfo;
310 char dirstring[1024];
313 sprintf( dirstring, "%s%s/*.*", gamedir, dir );
315 handle = _findfirst( dirstring, &fileinfo );
316 if ( handle == -1 ) {
322 sprintf( filename, "%s/%s", dir, fileinfo.name );
323 if ( fileinfo.attrib & _A_SUBDIR ) { // directory
324 if ( fileinfo.name[0] != '.' ) { // don't pak . and ..
325 PackDirectory_r( filename );
329 // copy or pack the file
330 ReleaseFile( filename );
331 } while ( _findnext( handle, &fileinfo ) != -1 );
333 _findclose( handle );
337 #include <sys/types.h>
341 #include <sys/dirent.h>
344 void PackDirectory_r( char *dir ){
346 struct direct **namelist, *ent;
348 struct dirent **namelist, *ent;
355 char dirstring[1024];
358 sprintf( dirstring, "%s%s", gamedir, dir );
359 count = scandir( dirstring, &namelist, NULL, NULL );
361 for ( i = 0 ; i < count ; i++ )
366 if ( name[0] == '.' ) {
370 sprintf( fullname, "%s/%s", dir, name );
371 sprintf( dirstring, "%s%s/%s", gamedir, dir, name );
373 if ( stat( dirstring, &st ) == -1 ) {
374 Error( "fstating %s", pf->name );
376 if ( st.st_mode & S_IFDIR ) { // directory
377 PackDirectory_r( fullname );
381 // copy or pack the file
382 ReleaseFile( fullname );
392 This is only used to cause a directory to be copied during a
393 release build (sounds, etc)
396 void Cmd_Dir( void ){
398 PackDirectory_r( token );
401 //========================================================================
403 #define MAX_RTEX 16384
405 char rtex[MAX_RTEX][64];
407 void ReleaseTexture( char *name ){
411 for ( i = 0 ; i < numrtex ; i++ )
412 if ( !Q_stricmp( name, rtex[i] ) ) {
416 if ( numrtex == MAX_RTEX ) {
417 Error( "numrtex == MAX_RTEX" );
420 strcpy( rtex[i], name );
423 sprintf( path, "textures/%s.wal", name );
431 Only relevent for release and pak files.
432 Releases the .bsp files for the maps, and scans all of the files to
433 build a list of all textures used, which are then released.
436 void Cmd_Maps( void ){
439 while ( TokenAvailable() )
442 sprintf( map, "maps/%s.bsp", token );
449 // get all the texture references
450 sprintf( map, "%smaps/%s.bsp", gamedir, token );
456 //==============================================================
463 void ParseScript( void ){
467 { // look for a line starting with a $ command
472 if ( token[0] == '$' ) {
475 while ( TokenAvailable() )
482 if ( !strcmp( token, "$modelname" ) ) {
485 else if ( !strcmp( token, "$base" ) ) {
488 else if ( !strcmp( token, "$exit" ) ) {
491 else if ( !strcmp( token, "$3dsconvert" ) ) {
494 else if ( !strcmp( token, "$spritebase" ) ) {
497 else if ( !strcmp( token, "$cd" ) ) {
500 else if ( !strcmp( token, "$origin" ) ) {
503 else if ( !strcmp( token, "$scale" ) ) {
506 else if ( !strcmp( token, "$frame" ) ) {
509 else if ( !strcmp( token, "$skin" ) ) {
512 else if ( !strcmp( token, "$spriteshader" ) ) {
515 else if ( !strcmp( token, "$aseconvert" ) ) {
516 Cmd_ASEConvert( qfalse );
518 else if ( !strcmp( token, "$aseanimconvert" ) ) {
519 Cmd_ASEConvert( qtrue );
525 else if ( !strcmp( token, "$grab" ) ) {
528 else if ( !strcmp( token, "$raw" ) ) {
531 else if ( !strcmp( token, "$colormap" ) ) {
534 else if ( !strcmp( token, "$environment" ) ) {
541 else if ( !strcmp( token, "$video" ) ) {
547 else if ( !strcmp( token, "$file" ) ) {
550 else if ( !strcmp( token, "$dir" ) ) {
553 else if ( !strcmp( token, "$maps" ) ) {
557 Error( "bad command %s\n", token );
562 //=======================================================
569 int main( int argc, char **argv ){
570 static int i; // VC4.2 compiler bug if auto...
573 // using GtkRadiant's versioning next to Id's versioning
574 printf( "Q3Data - (c) 1999 Id Software Inc.\n" );
575 printf( RADIANT_NAME " - v" RADIANT_VERSION " " __DATE__ "\n" );
577 ExpandWildcards( &argc, &argv );
579 for ( i = 1 ; i < argc ; i++ )
581 if ( !strcmp( argv[i], "-archive" ) ) {
583 strcpy( archivedir, argv[i + 1] );
584 printf( "Archiving source to: %s\n", archivedir );
587 else if ( !strcmp( argv[i], "-release" ) ) {
589 strcpy( g_releasedir, argv[i + 1] );
590 printf( "Copy output to: %s\n", g_releasedir );
593 else if ( !strcmp( argv[i], "-nostrips" ) ) {
595 printf( "Not optimizing for strips\n" );
597 else if ( !strcmp( argv[i], "-writedir" ) ) {
598 strcpy( writedir, argv[i + 1] );
599 printf( "Write output to: %s\n", writedir );
602 else if ( !strcmp( argv[i], "-verbose" ) ) {
605 else if ( !strcmp( argv[i], "-dump" ) ) {
606 printf( "Dumping contents of: '%s'\n", argv[i + 1] );
607 if ( strstr( argv[i + 1], ".md3" ) ) {
608 MD3_Dump( argv[i + 1] );
612 Error( "Do not know how to dump the contents of '%s'\n", argv[i + 1] );
616 else if ( !strcmp( argv[i], "-3dsconvert" ) ) {
617 // NOTE TTimo this is broken, tried on a sample .3ds
618 // what happens .. it calls the Convert3DStoMD3,
619 // which calls the scriptlib function in non initialized state .. and crashes
620 printf( "Converting %s.3DS to %s.MD3\n", argv[i + 1], argv[i + 1] );
621 SetQdirFromPath( argv[i + 1] );
622 vfsInitDirectory( gamedir );
623 Convert3DStoMD3( argv[i + 1] );
626 else if ( !strcmp( argv[i], "-only" ) ) {
627 strcpy( g_only, argv[i + 1] );
628 printf( "Only grabbing %s\n", g_only );
631 else if ( !strcmp( argv[i], "-gamedir" ) ) {
632 strcpy( gamedir, argv[i + 1] );
635 else if ( argv[i][0] == '-' ) {
636 Error( "Unknown option \"%s\"", argv[i] );
644 Error( "usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]" );
647 for ( ; i < argc ; i++ )
649 printf( "--------------- %s ---------------\n", argv[i] );
651 strcpy( path, argv[i] );
652 DefaultExtension( path, ".qdt" );
654 SetQdirFromPath( path );
657 // q3data went through a partial conversion to use the vfs
658 // it was never actually tested before 1.1.1
659 // the code is still mostly using direct file access calls
660 vfsInitDirectory( gamedir );
661 LoadScriptFile( ExpandArg( path ), -1 );
668 // write out the last model
669 FinishModel( TYPE_UNKNOWN );