1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 -------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
42 returns a pseudorandom number between 0 and 1
46 return (vec_t) rand() / RAND_MAX;
50 char *Q_strncpyz( char *dst, const char *src, size_t len ) {
55 strncpy( dst, src, len );
56 dst[ len - 1 ] = '\0';
61 char *Q_strcat( char *dst, size_t dlen, const char *src ) {
62 size_t n = strlen( dst );
65 abort(); /* buffer overflow */
68 return Q_strncpyz( dst + n, src, dlen - n );
72 char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
73 size_t n = strlen( dst );
76 abort(); /* buffer overflow */
79 return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
88 static void ExitQ3Map( void ){
90 if ( mapDrawSurfs != NULL ) {
98 shifts a map: for testing physics with huge coordinates
101 int ShiftBSPMain( int argc, char **argv ){
111 Sys_Printf( "Usage: q3map [-v] -shift [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
115 for ( i = 1; i < argc - 2; ++i )
117 if ( !strcmp( argv[i], "-tex" ) ) {
119 else if ( !strcmp( argv[i], "-spawn_ref" ) ) {
120 spawn_ref = atof( argv[i + 1] );
129 // if(argc-2 >= i) // always true
130 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
131 if ( argc - 3 >= i ) {
132 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
134 if ( argc - 4 >= i ) {
135 scale[0] = atof( argv[ argc - 4 ] );
139 /* do some path mangling */
140 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
141 StripExtension( source );
142 DefaultExtension( source, ".bsp" );
145 Sys_Printf( "Loading %s\n", source );
146 LoadBSPFile( source );
150 Sys_Printf( "--- ShiftBSP ---\n" );
151 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
153 /* shift entity keys */
154 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
157 GetVectorForKey( &entities[ i ], "origin", vec );
158 if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) {
159 if ( !!strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
165 if ( !!strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
168 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
169 SetKeyValue( &entities[ i ], "origin", str );
175 for ( i = 0; i < numBSPModels; i++ )
177 bspModels[ i ].mins[0] += scale[0];
178 bspModels[ i ].mins[1] += scale[1];
179 bspModels[ i ].mins[2] += scale[2];
180 bspModels[ i ].maxs[0] += scale[0];
181 bspModels[ i ].maxs[1] += scale[1];
182 bspModels[ i ].maxs[2] += scale[2];
186 for ( i = 0; i < numBSPNodes; i++ )
188 bspNodes[ i ].mins[0] += scale[0];
189 bspNodes[ i ].mins[1] += scale[1];
190 bspNodes[ i ].mins[2] += scale[2];
191 bspNodes[ i ].maxs[0] += scale[0];
192 bspNodes[ i ].maxs[1] += scale[1];
193 bspNodes[ i ].maxs[2] += scale[2];
197 for ( i = 0; i < numBSPLeafs; i++ )
199 bspLeafs[ i ].mins[0] += scale[0];
200 bspLeafs[ i ].mins[1] += scale[1];
201 bspLeafs[ i ].mins[2] += scale[2];
202 bspLeafs[ i ].maxs[0] += scale[0];
203 bspLeafs[ i ].maxs[1] += scale[1];
204 bspLeafs[ i ].maxs[2] += scale[2];
207 /* shift drawverts */
208 for ( i = 0; i < numBSPDrawVerts; i++ )
210 bspDrawVerts[i].xyz[0] += scale[0];
211 bspDrawVerts[i].xyz[1] += scale[1];
212 bspDrawVerts[i].xyz[2] += scale[2];
219 for ( i = 0; i < numBSPPlanes; i++ )
221 //find point on plane
222 for ( j=0; j<3; j++ ){
223 if ( fabs( bspPlanes[ i ].normal[j] ) > 0.5 ){
224 point[j] = bspPlanes[ i ].dist / bspPlanes[ i ].normal[j];
225 point[(j+1)%3] = point[(j+2)%3] = 0;
230 for ( j=0; j<3; j++ ){
231 point[j] += scale[j];
233 //calc new plane dist
234 bspPlanes[ i ].dist = DotProduct( point, bspPlanes[ i ].normal );
239 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
240 if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
241 VectorCopy( gridSize, vec );
246 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
247 SetKeyValue( &entities[ 0 ], "gridsize", str );
249 /* inject command line parameters */
250 InjectCommandLine( argv, 0, argc - 1 );
254 StripExtension( source );
255 DefaultExtension( source, "_sh.bsp" );
256 Sys_Printf( "Writing %s\n", source );
257 WriteBSPFile( source );
259 /* return to sender */
264 void FixDOSName( char *src ){
271 if ( *src == '\\' ) {
279 Check if newcoming texture is unique and not excluded
281 void tex2list( char* texlist, int *texnum, char* EXtex, int *EXtexnum ){
283 if ( token[0] == '\0') return;
284 StripExtension( token );
286 for ( i = 0; i < *texnum; i++ ){
287 if ( !Q_stricmp( texlist[i], token ) ) return;
289 for ( i = 0; i < *EXtexnum; i++ ){
290 if ( !Q_stricmp( EXtex[i], token ) ) return;
292 strcpy ( texlist + (*texnum)*65, token );
298 void tex2list2( char* texlist, int *texnum, char* EXtex, int *EXtexnum, char* rEXtex, int *rEXtexnum ){
300 if ( token[0] == '\0') return;
301 //StripExtension( token );
302 char* dot = strrchr( token, '.' );
304 if ( Q_stricmp( dot, ".tga" ) && Q_stricmp( dot, ".jpg" ) && Q_stricmp( dot, ".png" ) ){
305 Sys_Printf( "WARNING4: %s : weird or missing extension in shader\n", token );
312 strcpy ( texlist + (*texnum)*65, token );
313 strcat( token, ".tga" );
316 for ( i = 0; i < *texnum; i++ ){
317 if ( !Q_stricmp( texlist + i*65, texlist + (*texnum)*65 ) ) return;
319 for ( i = 0; i < *EXtexnum; i++ ){
320 if ( !Q_stricmp( EXtex + i*65, texlist + (*texnum)*65 ) ) return;
322 for ( i = 0; i < *rEXtexnum; i++ ){
323 if ( !Q_stricmp( rEXtex + i*65, texlist + (*texnum)*65 ) ) return;
331 Check if newcoming res is unique
333 void res2list( char* data, int *num ){
335 if ( strlen( data + (*num)*65 ) > 64 ){
336 Sys_Printf( "WARNING6: %s : path too long.\n", data + (*num)*65 );
338 while ( *( data + (*num)*65 ) == '\\' || *( data + (*num)*65 ) == '/' ){
339 char* cut = data + (*num)*65 + 1;
340 strcpy( data + (*num)*65, cut );
342 if ( *( data + (*num)*65 ) == '\0') return;
343 for ( i = 0; i < *num; i++ ){
344 if ( !Q_stricmp( data[i], data[*num] ) ) return;
350 void parseEXblock ( char* data, int *num, const char *exName ){
351 if ( !GetToken( qtrue ) || strcmp( token, "{" ) ) {
352 Error( "ReadExclusionsFile: %s, line %d: { not found", exName, scriptline );
356 if ( !GetToken( qtrue ) ) {
359 if ( !strcmp( token, "}" ) ) {
362 if ( token[0] == '{' ) {
363 Error( "ReadExclusionsFile: %s, line %d: brace, opening twice in a row.", exName, scriptline );
367 strcpy( data + (*num)*65, token );
373 char q3map2path[1024];
376 map autopackager, works for Q3 type of shaders and ents
379 int pk3BSPMain( int argc, char **argv ){
381 qboolean dbg = qfalse, png = qfalse, packFAIL = qfalse;
383 /* process arguments */
384 for ( i = 1; i < ( argc - 1 ); i++ ){
385 if ( !strcmp( argv[ i ], "-dbg" ) ) {
388 else if ( !strcmp( argv[ i ], "-png" ) ) {
393 /* do some path mangling */
394 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
395 StripExtension( source );
396 DefaultExtension( source, ".bsp" );
399 Sys_Printf( "Loading %s\n", source );
400 LoadBSPFile( source );
404 char packname[ 1024 ], packFailName[ 1024 ], base[ 1024 ], nameOFmap[ 1024 ], temp[ 1024 ];
407 strcpy( base, source );
408 StripExtension( base );
410 /* extract map name */
411 len = strlen( base ) - 1;
412 while ( len > 0 && base[ len ] != '/' && base[ len ] != '\\' )
414 strcpy( nameOFmap, &base[ len + 1 ] );
417 qboolean drawsurfSHs[1024] = { qfalse };
419 for ( i = 0; i < numBSPDrawSurfaces; i++ ){
420 /* can't exclude nodraw patches here (they want shaders :0!) */
421 //if ( !( bspDrawSurfaces[i].surfaceType == 2 && bspDrawSurfaces[i].numIndexes == 0 ) ) drawsurfSHs[bspDrawSurfaces[i].shaderNum] = qtrue;
422 drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = qtrue;
423 //Sys_Printf( "%s\n", bspShaders[bspDrawSurfaces[i].shaderNum].shader );
427 char* pk3Shaders = (char *)calloc( 1024*65, sizeof( char ) );
429 char* pk3Sounds = (char *)calloc( 1024*65, sizeof( char ) );
430 int pk3ShaderfilesN = 0;
431 char* pk3Shaderfiles = (char *)calloc( 1024*65, sizeof( char ) );
432 int pk3TexturesN = 0;
433 char* pk3Textures = (char *)calloc( 1024*65, sizeof( char ) );
435 char* pk3Videos = (char *)calloc( 1024*65, sizeof( char ) );
439 for ( i = 0; i < numBSPShaders; i++ ){
440 if ( drawsurfSHs[i] ){
441 strcpy( pk3Shaders + pk3ShadersN*65, bspShaders[i].shader );
442 res2list( pk3Shaders, &pk3ShadersN );
444 //Sys_Printf( "%s\n", bspShaders[i].shader );
450 for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
452 if ( !Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
453 sscanf( ep->value, "%*[^;] %*[;] %s", pk3Shaders + pk3ShadersN*65 );
454 res2list( pk3Shaders, &pk3ShadersN );
457 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[0], "music" ) );
458 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' ){
459 FixDOSName( pk3Sounds + pk3SoundsN*65 );
460 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
461 res2list( pk3Sounds, &pk3SoundsN );
464 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
466 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[i], "noise" ) );
467 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' && *( pk3Sounds + pk3SoundsN*65 ) != '*' ){
468 FixDOSName( pk3Sounds + pk3SoundsN*65 );
469 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
470 res2list( pk3Sounds, &pk3SoundsN );
473 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){
474 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_strt.wav");
475 res2list( pk3Sounds, &pk3SoundsN );
476 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_end.wav");
477 res2list( pk3Sounds, &pk3SoundsN );
479 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "target_push" ) ){
480 if ( !(IntForKey( &entities[i], "spawnflags") & 1) ){
481 strcpy( pk3Sounds + pk3SoundsN*65, "sound/misc/windfly.wav");
482 res2list( pk3Sounds, &pk3SoundsN );
485 strcpy( pk3Shaders + pk3ShadersN*65, ValueForKey( &entities[i], "targetShaderNewName" ) );
486 res2list( pk3Shaders, &pk3ShadersN );
490 sprintf( pk3Shaders + pk3ShadersN*65, "levelshots/%s", nameOFmap );
491 res2list( pk3Shaders, &pk3ShadersN );
495 Sys_Printf( "\n\tDrawsurface+ent calls....%i\n", pk3ShadersN );
496 for ( i = 0; i < pk3ShadersN; i++ ){
497 Sys_Printf( "%s\n", pk3Shaders + i*65 );
499 Sys_Printf( "\n\tSounds....%i\n", pk3SoundsN );
500 for ( i = 0; i < pk3SoundsN; i++ ){
501 Sys_Printf( "%s\n", pk3Sounds + i*65 );
505 vfsListShaderFiles( pk3Shaderfiles, &pk3ShaderfilesN );
508 Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3ShaderfilesN );
509 for ( i = 0; i < pk3ShaderfilesN; i++ ){
510 Sys_Printf( "%s\n", pk3Shaderfiles + i*65 );
515 /* load exclusions file */
517 char* ExTextures = (char *)calloc( 4096*65, sizeof( char ) );
519 char* ExShaders = (char *)calloc( 4096*65, sizeof( char ) );
521 char* ExSounds = (char *)calloc( 4096*65, sizeof( char ) );
522 int ExShaderfilesN = 0;
523 char* ExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
525 char* ExVideos = (char *)calloc( 4096*65, sizeof( char ) );
526 int ExPureTexturesN = 0;
527 char* ExPureTextures = (char *)calloc( 4096*65, sizeof( char ) );
529 char* ExReasonShader[4096] = { NULL };
530 char* ExReasonShaderFile[4096] = { NULL };
536 strcpy( exName, q3map2path );
537 char *cut = strrchr( exName, '\\' );
538 char *cut2 = strrchr( exName, '/' );
539 if ( cut == NULL && cut2 == NULL ){
540 Sys_Printf( "WARNING: Unable to load exclusions file.\n" );
543 if ( cut2 > cut ) cut = cut2;
545 strcat( exName, game->arg );
546 strcat( exName, ".exclude" );
548 Sys_Printf( "Loading %s\n", exName );
549 size = TryLoadFile( exName, (void**) &buffer );
551 Sys_Printf( "WARNING: Unable to find exclusions file %s.\n", exName );
556 ParseFromMemory( (char *) buffer, size );
561 /* test for end of file */
562 if ( !GetToken( qtrue ) ) {
567 if ( !Q_stricmp( token, "textures" ) ){
568 parseEXblock ( ExTextures, &ExTexturesN, exName );
570 else if ( !Q_stricmp( token, "shaders" ) ){
571 parseEXblock ( ExShaders, &ExShadersN, exName );
573 else if ( !Q_stricmp( token, "shaderfiles" ) ){
574 parseEXblock ( ExShaderfiles, &ExShaderfilesN, exName );
576 else if ( !Q_stricmp( token, "sounds" ) ){
577 parseEXblock ( ExSounds, &ExSoundsN, exName );
579 else if ( !Q_stricmp( token, "videos" ) ){
580 parseEXblock ( ExVideos, &ExVideosN, exName );
583 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
587 /* free the buffer */
590 for ( i = 0; i < ExTexturesN; i++ ){
591 for ( j = 0; j < ExShadersN; j++ ){
592 if ( !Q_stricmp( ExTextures + i*65, ExShaders + j*65 ) ){
596 if ( j == ExShadersN ){
597 strcpy ( ExPureTextures + ExPureTexturesN*65, ExTextures + i*65 );
605 Sys_Printf( "\n\tExTextures....%i\n", ExTexturesN );
606 for ( i = 0; i < ExTexturesN; i++ ) Sys_Printf( "%s\n", ExTextures + i*65 );
607 Sys_Printf( "\n\tExPureTextures....%i\n", ExPureTexturesN );
608 for ( i = 0; i < ExPureTexturesN; i++ ) Sys_Printf( "%s\n", ExPureTextures + i*65 );
609 Sys_Printf( "\n\tExShaders....%i\n", ExShadersN );
610 for ( i = 0; i < ExShadersN; i++ ) Sys_Printf( "%s\n", ExShaders + i*65 );
611 Sys_Printf( "\n\tExShaderfiles....%i\n", ExShaderfilesN );
612 for ( i = 0; i < ExShaderfilesN; i++ ) Sys_Printf( "%s\n", ExShaderfiles + i*65 );
613 Sys_Printf( "\n\tExSounds....%i\n", ExSoundsN );
614 for ( i = 0; i < ExSoundsN; i++ ) Sys_Printf( "%s\n", ExSounds + i*65 );
615 Sys_Printf( "\n\tExVideos....%i\n", ExVideosN );
616 for ( i = 0; i < ExVideosN; i++ ) Sys_Printf( "%s\n", ExVideos + i*65 );
619 /* can exclude pure textures right now, shouldn't create shaders for them anyway */
620 for ( i = 0; i < pk3ShadersN ; i++ ){
621 for ( j = 0; j < ExPureTexturesN ; j++ ){
622 if ( !Q_stricmp( pk3Shaders + i*65, ExPureTextures + j*65 ) ){
623 *( pk3Shaders + i*65 ) = '\0';
633 for ( i = 0; i < pk3ShaderfilesN; i++ ){
634 qboolean wantShader = qfalse, wantShaderFile = qfalse, ShaderFileExcluded = qfalse;
636 char* reasonShader = NULL;
637 char* reasonShaderFile = NULL;
639 /* load the shader */
640 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
641 SilentLoadScriptFile( temp, 0 );
642 if( dbg ) Sys_Printf( "\n\tentering %s\n", pk3Shaderfiles + i*65 );
644 /* do wanna le shader file? */
645 for ( j = 0; j < ExShaderfilesN; j++ ){
646 if ( !Q_stricmp( ExShaderfiles + j*65, pk3Shaderfiles + i*65 ) ){
647 ShaderFileExcluded = qtrue;
648 reasonShaderFile = ExShaderfiles + j*65;
653 /* check if shader file has to be excluded */
654 while ( !ShaderFileExcluded )
656 /* test for end of file */
657 if ( !GetToken( qtrue ) ) {
661 /* does it contain restricted shaders/textures? */
662 for ( j = 0; j < ExShadersN; j++ ){
663 if ( !Q_stricmp( ExShaders + j*65, token ) ){
664 ShaderFileExcluded = qtrue;
665 reasonShader = ExShaders + j*65;
669 if ( ShaderFileExcluded )
671 for ( j = 0; j < ExPureTexturesN; j++ ){
672 if ( !Q_stricmp( ExPureTextures + j*65, token ) ){
673 ShaderFileExcluded = qtrue;
674 reasonShader = ExPureTextures + j*65;
678 if ( ShaderFileExcluded )
681 /* handle { } section */
682 if ( !GetToken( qtrue ) ) {
685 if ( strcmp( token, "{" ) ) {
686 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s",
687 temp, scriptline, token );
692 /* get the next token */
693 if ( !GetToken( qtrue ) ) {
696 if ( !strcmp( token, "}" ) ) {
699 /* parse stage directives */
700 if ( !strcmp( token, "{" ) ) {
703 if ( !GetToken( qtrue ) ) {
706 if ( !strcmp( token, "}" ) ) {
714 /* tokenize it again */
715 SilentLoadScriptFile( temp, 0 );
718 /* test for end of file */
719 if ( !GetToken( qtrue ) ) {
723 if( dbg ) Sys_Printf( "%s\n", token );
725 /* do wanna le shader? */
727 for ( j = 0; j < pk3ShadersN; j++ ){
728 if ( !Q_stricmp( pk3Shaders + j*65, token) ){
735 /* handle { } section */
736 if ( !GetToken( qtrue ) ) {
739 if ( strcmp( token, "{" ) ) {
740 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s",
741 temp, scriptline, token );
746 /* get the next token */
747 if ( !GetToken( qtrue ) ) {
750 if ( !strcmp( token, "}" ) ) {
755 /* -----------------------------------------------------------------
756 shader stages (passes)
757 ----------------------------------------------------------------- */
759 /* parse stage directives */
760 if ( !strcmp( token, "{" ) ) {
763 if ( !GetToken( qtrue ) ) {
766 if ( !strcmp( token, "}" ) ) {
769 /* skip the shader */
770 if ( !wantShader ) continue;
772 /* digest any images */
773 if ( !Q_stricmp( token, "map" ) ||
774 !Q_stricmp( token, "clampMap" ) ) {
778 if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
779 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
782 else if ( !Q_stricmp( token, "animMap" ) ||
783 !Q_stricmp( token, "clampAnimMap" ) ) {
784 GetToken( qfalse );// skip num
785 while ( TokenAvailable() ){
787 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
790 else if ( !Q_stricmp( token, "videoMap" ) ){
793 if ( strchr( token, '/' ) == NULL && strchr( token, '\\' ) == NULL ){
794 sprintf( temp, "video/%s", token );
795 strcpy( token, temp );
798 for ( j = 0; j < pk3VideosN; j++ ){
799 if ( !Q_stricmp( pk3Videos + j*65, token ) ){
803 for ( j = 0; j < ExVideosN; j++ ){
804 if ( !Q_stricmp( ExVideos + j*65, token ) ){
808 strcpy ( pk3Videos + pk3VideosN*65, token );
815 /* skip the shader */
816 else if ( !wantShader ) continue;
818 /* -----------------------------------------------------------------
819 surfaceparm * directives
820 ----------------------------------------------------------------- */
822 /* match surfaceparm */
823 else if ( !Q_stricmp( token, "surfaceparm" ) ) {
825 if ( !Q_stricmp( token, "nodraw" ) ) {
827 *( pk3Shaders + shader*65 ) = '\0';
831 /* skyparms <outer image> <cloud height> <inner image> */
832 else if ( !Q_stricmp( token, "skyParms" ) ) {
836 /* ignore bogus paths */
837 if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) {
838 strcpy ( temp, token );
839 sprintf( token, "%s_up", temp );
840 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
841 sprintf( token, "%s_dn", temp );
842 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
843 sprintf( token, "%s_lf", temp );
844 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
845 sprintf( token, "%s_rt", temp );
846 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
847 sprintf( token, "%s_bk", temp );
848 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
849 sprintf( token, "%s_ft", temp );
850 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
852 /* skip rest of line */
860 for ( j = 0; j < ExShadersN; j++ ){
861 if ( !Q_stricmp( ExShaders + j*65, pk3Shaders + shader*65 ) ){
863 *( pk3Shaders + shader*65 ) = '\0';
868 if ( ShaderFileExcluded ){
869 if ( reasonShaderFile != NULL ){
870 ExReasonShaderFile[ shader ] = reasonShaderFile;
873 ExReasonShaderFile[ shader ] = ( char* ) calloc( 65, sizeof( char ) );
874 strcpy( ExReasonShaderFile[ shader ], pk3Shaderfiles + i*65 );
876 ExReasonShader[ shader ] = reasonShader;
879 wantShaderFile = qtrue;
880 *( pk3Shaders + shader*65 ) = '\0';
885 if ( !wantShaderFile ){
886 *( pk3Shaderfiles + i*65 ) = '\0';
893 //wanted shaders from excluded .shaders
895 for ( i = 0; i < pk3ShadersN; i++ ){
896 if ( *( pk3Shaders + i*65 ) != '\0' && ( ExReasonShader[i] != NULL || ExReasonShaderFile[i] != NULL ) ){
897 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
899 if ( ExReasonShader[i] != NULL ){
900 Sys_Printf( " reason: is located in %s,\n containing restricted shader %s\n", ExReasonShaderFile[i], ExReasonShader[i] );
903 Sys_Printf( " reason: is located in restricted %s\n", ExReasonShaderFile[i] );
905 *( pk3Shaders + i*65 ) = '\0';
908 //pure textures (shader ones are done)
909 for ( i = 0; i < pk3ShadersN; i++ ){
910 if ( *( pk3Shaders + i*65 ) != '\0' ){
911 FixDOSName( pk3Shaders + i*65 );
912 for ( j = 0; j < pk3TexturesN; j++ ){
913 if ( !Q_stricmp( pk3Shaders + i*65, pk3Textures + j*65 ) ){
914 *( pk3Shaders + i*65 ) = '\0';
918 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
919 for ( j = 0; j < ExTexturesN; j++ ){
920 if ( !Q_stricmp( pk3Shaders + i*65, ExTextures + j*65 ) ){
921 *( pk3Shaders + i*65 ) = '\0';
929 for ( i = 0; i < pk3SoundsN; i++ ){
930 for ( j = 0; j < ExSoundsN; j++ ){
931 if ( !Q_stricmp( pk3Sounds + i*65, ExSounds + j*65 ) ){
932 *( pk3Sounds + i*65 ) = '\0';
939 sprintf( packname, "%s/%s_autopacked.pk3", EnginePath, nameOFmap );
941 sprintf( packFailName, "%s/%s_FAILEDpack.pk3", EnginePath, nameOFmap );
942 remove( packFailName );
944 Sys_Printf( "\n--- ZipZip ---\n" );
946 Sys_Printf( "\n\tShader referenced textures....\n" );
948 for ( i = 0; i < pk3TexturesN; i++ ){
950 sprintf( temp, "%s.png", pk3Textures + i*65 );
951 if ( vfsPackFile( temp, packname, 10 ) ){
952 Sys_Printf( "++%s\n", temp );
956 sprintf( temp, "%s.tga", pk3Textures + i*65 );
957 if ( vfsPackFile( temp, packname, 10 ) ){
958 Sys_Printf( "++%s\n", temp );
961 sprintf( temp, "%s.jpg", pk3Textures + i*65 );
962 if ( vfsPackFile( temp, packname, 10 ) ){
963 Sys_Printf( "++%s\n", temp );
966 Sys_Printf( " !FAIL! %s\n", pk3Textures + i*65 );
970 Sys_Printf( "\n\tPure textures....\n" );
972 for ( i = 0; i < pk3ShadersN; i++ ){
973 if ( *( pk3Shaders + i*65 ) != '\0' ){
975 sprintf( temp, "%s.png", pk3Shaders + i*65 );
976 if ( vfsPackFile( temp, packname, 10 ) ){
977 Sys_Printf( "++%s\n", temp );
981 sprintf( temp, "%s.tga", pk3Shaders + i*65 );
982 if ( vfsPackFile( temp, packname, 10 ) ){
983 Sys_Printf( "++%s\n", temp );
986 sprintf( temp, "%s.jpg", pk3Shaders + i*65 );
987 if ( vfsPackFile( temp, packname, 10 ) ){
988 Sys_Printf( "++%s\n", temp );
991 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
992 if ( i != pk3ShadersN - 1 ) packFAIL = qtrue; //levelshot typically
996 Sys_Printf( "\n\tShaizers....\n" );
998 for ( i = 0; i < pk3ShaderfilesN; i++ ){
999 if ( *( pk3Shaderfiles + i*65 ) != '\0' ){
1000 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
1001 if ( vfsPackFile( temp, packname, 10 ) ){
1002 Sys_Printf( "++%s\n", temp );
1005 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
1010 Sys_Printf( "\n\tSounds....\n" );
1012 for ( i = 0; i < pk3SoundsN; i++ ){
1013 if ( *( pk3Sounds + i*65 ) != '\0' ){
1014 if ( vfsPackFile( pk3Sounds + i*65, packname, 10 ) ){
1015 Sys_Printf( "++%s\n", pk3Sounds + i*65 );
1018 Sys_Printf( " !FAIL! %s\n", pk3Sounds + i*65 );
1023 Sys_Printf( "\n\tVideos....\n" );
1025 for ( i = 0; i < pk3VideosN; i++ ){
1026 if ( vfsPackFile( pk3Videos + i*65, packname, 10 ) ){
1027 Sys_Printf( "++%s\n", pk3Videos + i*65 );
1030 Sys_Printf( " !FAIL! %s\n", pk3Videos + i*65 );
1034 Sys_Printf( "\n\t.bsp and stuff\n" );
1036 sprintf( temp, "maps/%s.bsp", nameOFmap );
1037 if ( vfsPackFile( temp, packname, 10 ) ){
1038 Sys_Printf( "++%s\n", temp );
1041 Sys_Printf( " !FAIL! %s\n", temp );
1045 sprintf( temp, "maps/%s.aas", nameOFmap );
1046 if ( vfsPackFile( temp, packname, 10 ) ){
1047 Sys_Printf( "++%s\n", temp );
1050 Sys_Printf( " !FAIL! %s\n", temp );
1053 sprintf( temp, "scripts/%s.arena", nameOFmap );
1054 if ( vfsPackFile( temp, packname, 10 ) ){
1055 Sys_Printf( "++%s\n", temp );
1058 Sys_Printf( " !FAIL! %s\n", temp );
1061 sprintf( temp, "scripts/%s.defi", nameOFmap );
1062 if ( vfsPackFile( temp, packname, 10 ) ){
1063 Sys_Printf( "++%s\n", temp );
1066 Sys_Printf( " !FAIL! %s\n", temp );
1070 Sys_Printf( "\nSaved to %s\n", packname );
1073 rename( packname, packFailName );
1074 Sys_Printf( "\nSaved to %s\n", packFailName );
1076 /* return to sender */
1083 repack multiple maps, strip only required shaders
1084 works for Q3 type of shaders and ents
1087 int repackBSPMain( int argc, char **argv ){
1088 int i, j, len, compLevel = 0;
1089 qboolean dbg = qfalse, png = qfalse;
1091 /* process arguments */
1092 for ( i = 1; i < ( argc - 1 ); i++ ){
1093 if ( !strcmp( argv[ i ], "-dbg" ) ) {
1096 else if ( !strcmp( argv[ i ], "-png" ) ) {
1099 else if ( !strcmp( argv[ i ], "-complevel" ) ) {
1100 compLevel = atoi( argv[ i + 1 ] );
1102 if ( compLevel < -1 ) compLevel = -1;
1103 if ( compLevel > 10 ) compLevel = 10;
1104 Sys_Printf( "Compression level set to %i\n", compLevel );
1108 /* load exclusions file */
1109 int ExTexturesN = 0;
1110 char* ExTextures = (char *)calloc( 4096*65, sizeof( char ) );
1112 char* ExShaders = (char *)calloc( 4096*65, sizeof( char ) );
1114 char* ExSounds = (char *)calloc( 4096*65, sizeof( char ) );
1115 int ExShaderfilesN = 0;
1116 char* ExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
1118 char* ExVideos = (char *)calloc( 4096*65, sizeof( char ) );
1119 int ExPureTexturesN = 0;
1120 char* ExPureTextures = (char *)calloc( 4096*65, sizeof( char ) );
1123 char exName[ 1024 ];
1127 strcpy( exName, q3map2path );
1128 char *cut = strrchr( exName, '\\' );
1129 char *cut2 = strrchr( exName, '/' );
1130 if ( cut == NULL && cut2 == NULL ){
1131 Sys_Printf( "WARNING: Unable to load exclusions file.\n" );
1134 if ( cut2 > cut ) cut = cut2;
1136 strcat( exName, game->arg );
1137 strcat( exName, ".exclude" );
1139 Sys_Printf( "Loading %s\n", exName );
1140 size = TryLoadFile( exName, (void**) &buffer );
1142 Sys_Printf( "WARNING: Unable to find exclusions file %s.\n", exName );
1146 /* parse the file */
1147 ParseFromMemory( (char *) buffer, size );
1152 /* test for end of file */
1153 if ( !GetToken( qtrue ) ) {
1158 if ( !Q_stricmp( token, "textures" ) ){
1159 parseEXblock ( ExTextures, &ExTexturesN, exName );
1161 else if ( !Q_stricmp( token, "shaders" ) ){
1162 parseEXblock ( ExShaders, &ExShadersN, exName );
1164 else if ( !Q_stricmp( token, "shaderfiles" ) ){
1165 parseEXblock ( ExShaderfiles, &ExShaderfilesN, exName );
1167 else if ( !Q_stricmp( token, "sounds" ) ){
1168 parseEXblock ( ExSounds, &ExSoundsN, exName );
1170 else if ( !Q_stricmp( token, "videos" ) ){
1171 parseEXblock ( ExVideos, &ExVideosN, exName );
1174 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
1178 /* free the buffer */
1181 for ( i = 0; i < ExTexturesN; i++ ){
1182 for ( j = 0; j < ExShadersN; j++ ){
1183 if ( !Q_stricmp( ExTextures + i*65, ExShaders + j*65 ) ){
1187 if ( j == ExShadersN ){
1188 strcpy ( ExPureTextures + ExPureTexturesN*65, ExTextures + i*65 );
1196 Sys_Printf( "\n\tExTextures....%i\n", ExTexturesN );
1197 for ( i = 0; i < ExTexturesN; i++ ) Sys_Printf( "%s\n", ExTextures + i*65 );
1198 Sys_Printf( "\n\tExPureTextures....%i\n", ExPureTexturesN );
1199 for ( i = 0; i < ExPureTexturesN; i++ ) Sys_Printf( "%s\n", ExPureTextures + i*65 );
1200 Sys_Printf( "\n\tExShaders....%i\n", ExShadersN );
1201 for ( i = 0; i < ExShadersN; i++ ) Sys_Printf( "%s\n", ExShaders + i*65 );
1202 Sys_Printf( "\n\tExShaderfiles....%i\n", ExShaderfilesN );
1203 for ( i = 0; i < ExShaderfilesN; i++ ) Sys_Printf( "%s\n", ExShaderfiles + i*65 );
1204 Sys_Printf( "\n\tExSounds....%i\n", ExSoundsN );
1205 for ( i = 0; i < ExSoundsN; i++ ) Sys_Printf( "%s\n", ExSounds + i*65 );
1206 Sys_Printf( "\n\tExVideos....%i\n", ExVideosN );
1207 for ( i = 0; i < ExVideosN; i++ ) Sys_Printf( "%s\n", ExVideos + i*65 );
1213 /* load repack.exclude */
1214 int rExTexturesN = 0;
1215 char* rExTextures = (char *)calloc( 65536*65, sizeof( char ) );
1216 int rExShadersN = 0;
1217 char* rExShaders = (char *)calloc( 32768*65, sizeof( char ) );
1219 char* rExSounds = (char *)calloc( 8192*65, sizeof( char ) );
1220 int rExShaderfilesN = 0;
1221 char* rExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
1223 char* rExVideos = (char *)calloc( 4096*65, sizeof( char ) );
1225 strcpy( exName, q3map2path );
1226 cut = strrchr( exName, '\\' );
1227 cut2 = strrchr( exName, '/' );
1228 if ( cut == NULL && cut2 == NULL ){
1229 Sys_Printf( "WARNING: Unable to load repack exclusions file.\n" );
1232 if ( cut2 > cut ) cut = cut2;
1234 strcat( exName, "repack.exclude" );
1236 Sys_Printf( "Loading %s\n", exName );
1237 size = TryLoadFile( exName, (void**) &buffer );
1239 Sys_Printf( "WARNING: Unable to find repack exclusions file %s.\n", exName );
1243 /* parse the file */
1244 ParseFromMemory( (char *) buffer, size );
1249 /* test for end of file */
1250 if ( !GetToken( qtrue ) ) {
1255 if ( !Q_stricmp( token, "textures" ) ){
1256 parseEXblock ( rExTextures, &rExTexturesN, exName );
1258 else if ( !Q_stricmp( token, "shaders" ) ){
1259 parseEXblock ( rExShaders, &rExShadersN, exName );
1261 else if ( !Q_stricmp( token, "shaderfiles" ) ){
1262 parseEXblock ( rExShaderfiles, &rExShaderfilesN, exName );
1264 else if ( !Q_stricmp( token, "sounds" ) ){
1265 parseEXblock ( rExSounds, &rExSoundsN, exName );
1267 else if ( !Q_stricmp( token, "videos" ) ){
1268 parseEXblock ( rExVideos, &rExVideosN, exName );
1271 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
1275 /* free the buffer */
1281 Sys_Printf( "\n\trExTextures....%i\n", rExTexturesN );
1282 for ( i = 0; i < rExTexturesN; i++ ) Sys_Printf( "%s\n", rExTextures + i*65 );
1283 Sys_Printf( "\n\trExShaders....%i\n", rExShadersN );
1284 for ( i = 0; i < rExShadersN; i++ ) Sys_Printf( "%s\n", rExShaders + i*65 );
1285 Sys_Printf( "\n\trExShaderfiles....%i\n", rExShaderfilesN );
1286 for ( i = 0; i < rExShaderfilesN; i++ ) Sys_Printf( "%s\n", rExShaderfiles + i*65 );
1287 Sys_Printf( "\n\trExSounds....%i\n", rExSoundsN );
1288 for ( i = 0; i < rExSoundsN; i++ ) Sys_Printf( "%s\n", rExSounds + i*65 );
1289 Sys_Printf( "\n\trExVideos....%i\n", rExVideosN );
1290 for ( i = 0; i < rExVideosN; i++ ) Sys_Printf( "%s\n", rExVideos + i*65 );
1297 char* bspList = (char *)calloc( 8192*1024, sizeof( char ) );
1299 /* do some path mangling */
1300 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
1301 if ( !Q_stricmp( strrchr( source, '.' ), ".bsp" ) ){
1302 strcpy( bspList, source );
1306 /* load bsps paths list */
1307 Sys_Printf( "Loading %s\n", source );
1308 size = TryLoadFile( source, (void**) &buffer );
1310 Sys_Printf( "WARNING: Unable to open bsps paths list file %s.\n", source );
1313 /* parse the file */
1314 ParseFromMemory( (char *) buffer, size );
1319 /* test for end of file */
1320 if ( !GetToken( qtrue ) ) {
1323 strcpy( bspList + bspListN * 1024 , token );
1327 /* free the buffer */
1331 char packname[ 1024 ], nameOFrepack[ 1024 ], nameOFmap[ 1024 ], temp[ 1024 ];
1333 /* copy input file name */
1334 strcpy( temp, source );
1335 StripExtension( temp );
1337 /* extract input file name */
1338 len = strlen( temp ) - 1;
1339 while ( len > 0 && temp[ len ] != '/' && temp[ len ] != '\\' )
1341 strcpy( nameOFrepack, &temp[ len + 1 ] );
1345 int pk3ShadersN = 0;
1346 char* pk3Shaders = (char *)calloc( 65536*65, sizeof( char ) );
1348 char* pk3Sounds = (char *)calloc( 4096*65, sizeof( char ) );
1349 int pk3ShaderfilesN = 0;
1350 char* pk3Shaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
1351 int pk3TexturesN = 0;
1352 char* pk3Textures = (char *)calloc( 65536*65, sizeof( char ) );
1354 char* pk3Videos = (char *)calloc( 1024*65, sizeof( char ) );
1356 for( j = 0; j < bspListN; j++ ){
1358 int pk3SoundsNold = pk3SoundsN;
1359 int pk3ShadersNold = pk3ShadersN;
1361 strcpy( source, bspList + j*1024 );
1362 StripExtension( source );
1363 DefaultExtension( source, ".bsp" );
1366 Sys_Printf( "\nLoading %s\n", source );
1367 PartialLoadBSPFile( source );
1371 strcpy( temp, source );
1372 StripExtension( temp );
1374 /* extract map name */
1375 len = strlen( temp ) - 1;
1376 while ( len > 0 && temp[ len ] != '/' && temp[ len ] != '\\' )
1378 strcpy( nameOFmap, &temp[ len + 1 ] );
1381 qboolean drawsurfSHs[1024] = { qfalse };
1383 for ( i = 0; i < numBSPDrawSurfaces; i++ ){
1384 drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = qtrue;
1387 for ( i = 0; i < numBSPShaders; i++ ){
1388 if ( drawsurfSHs[i] ){
1389 strcpy( pk3Shaders + pk3ShadersN*65, bspShaders[i].shader );
1390 res2list( pk3Shaders, &pk3ShadersN );
1396 for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
1398 if ( !!Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
1399 sscanf( ep->value, "%*[^;] %*[;] %s", pk3Shaders + pk3ShadersN*65 );
1400 res2list( pk3Shaders, &pk3ShadersN );
1403 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[0], "music" ) );
1404 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' ){
1405 FixDOSName( pk3Sounds + pk3SoundsN*65 );
1406 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
1407 res2list( pk3Sounds, &pk3SoundsN );
1410 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
1412 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[i], "noise" ) );
1413 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' && *( pk3Sounds + pk3SoundsN*65 ) != '*' ){
1414 FixDOSName( pk3Sounds + pk3SoundsN*65 );
1415 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
1416 res2list( pk3Sounds, &pk3SoundsN );
1419 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){
1420 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_strt.wav");
1421 res2list( pk3Sounds, &pk3SoundsN );
1422 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_end.wav");
1423 res2list( pk3Sounds, &pk3SoundsN );
1425 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "target_push" ) ){
1426 if ( !(IntForKey( &entities[i], "spawnflags") & 1) ){
1427 strcpy( pk3Sounds + pk3SoundsN*65, "sound/misc/windfly.wav");
1428 res2list( pk3Sounds, &pk3SoundsN );
1431 strcpy( pk3Shaders + pk3ShadersN*65, ValueForKey( &entities[i], "targetShaderNewName" ) );
1432 res2list( pk3Shaders, &pk3ShadersN );
1436 sprintf( pk3Shaders + pk3ShadersN*65, "levelshots/%s", nameOFmap );
1437 res2list( pk3Shaders, &pk3ShadersN );
1441 Sys_Printf( "\n\t+Drawsurface+ent calls....%i\n", pk3ShadersN - pk3ShadersNold );
1442 for ( i = pk3ShadersNold; i < pk3ShadersN; i++ ){
1443 Sys_Printf( "%s\n", pk3Shaders + i*65 );
1445 Sys_Printf( "\n\t+Sounds....%i\n", pk3SoundsN - pk3SoundsNold );
1446 for ( i = pk3SoundsNold; i < pk3SoundsN; i++ ){
1447 Sys_Printf( "%s\n", pk3Sounds + i*65 );
1451 if ( bspDrawVerts != 0 ) {
1452 free( bspDrawVerts );
1453 bspDrawVerts = NULL;
1454 //numBSPDrawVerts = 0;
1455 Sys_Printf( "freed BSPDrawVerts\n" );
1457 */ if ( bspDrawSurfaces != 0 ) {
1458 free( bspDrawSurfaces );
1459 bspDrawSurfaces = NULL;
1460 //numBSPDrawSurfaces = 0;
1461 //Sys_Printf( "freed bspDrawSurfaces\n" );
1463 /* if ( bspLightBytes != 0 ) {
1464 free( bspLightBytes );
1465 bspLightBytes = NULL;
1466 //numBSPLightBytes = 0;
1467 Sys_Printf( "freed BSPLightBytes\n" );
1469 if ( bspGridPoints != 0 ) {
1470 free( bspGridPoints );
1471 bspGridPoints = NULL;
1472 //numBSPGridPoints = 0;
1473 Sys_Printf( "freed BSPGridPoints\n" );
1475 if ( bspPlanes != 0 ) {
1478 Sys_Printf( "freed bspPlanes\n" );
1480 //allocatedBSPPlanes = 0;
1482 if ( bspBrushes != 0 ) {
1485 Sys_Printf( "freed bspBrushes\n" );
1486 //numBSPBrushes = 0;
1487 //allocatedBSPBrushes = 0;
1489 */ if ( entities != 0 ) {
1491 for ( i = 0; i < numBSPEntities && i < numEntities; i++ ){
1492 ep = entities[i].epairs;
1501 //Sys_Printf( "freed entities\n" );
1504 allocatedEntities = 0;
1506 /* if ( bspModels != 0 ) {
1509 Sys_Printf( "freed bspModels\n" );
1511 //allocatedBSPModels = 0;
1513 */ if ( bspShaders != 0 ) {
1516 //Sys_Printf( "freed bspShaders\n" );
1517 //numBSPShaders = 0;
1518 //allocatedBSPShaders = 0;
1520 if ( bspEntData != 0 ) {
1523 //Sys_Printf( "freed bspEntData\n" );
1524 //bspEntDataSize = 0;
1525 //allocatedBSPEntData = 0;
1527 /* if ( bspNodes != 0 ) {
1530 Sys_Printf( "freed bspNodes\n" );
1532 //allocatedBSPNodes = 0;
1534 if ( bspDrawIndexes != 0 ) {
1535 free( bspDrawIndexes );
1536 bspDrawIndexes = NULL;
1537 Sys_Printf( "freed bspDrawIndexes\n" );
1538 //numBSPDrawIndexes = 0;
1539 //allocatedBSPDrawIndexes = 0;
1541 if ( bspLeafSurfaces != 0 ) {
1542 free( bspLeafSurfaces );
1543 bspLeafSurfaces = NULL;
1544 Sys_Printf( "freed bspLeafSurfaces\n" );
1545 //numBSPLeafSurfaces = 0;
1546 //allocatedBSPLeafSurfaces = 0;
1548 if ( bspLeafBrushes != 0 ) {
1549 free( bspLeafBrushes );
1550 bspLeafBrushes = NULL;
1551 Sys_Printf( "freed bspLeafBrushes\n" );
1552 //numBSPLeafBrushes = 0;
1553 //allocatedBSPLeafBrushes = 0;
1555 if ( bspBrushSides != 0 ) {
1556 free( bspBrushSides );
1557 bspBrushSides = NULL;
1558 Sys_Printf( "freed bspBrushSides\n" );
1559 numBSPBrushSides = 0;
1560 allocatedBSPBrushSides = 0;
1562 if ( numBSPFogs != 0 ) {
1563 Sys_Printf( "freed numBSPFogs\n" );
1566 if ( numBSPAds != 0 ) {
1567 Sys_Printf( "freed numBSPAds\n" );
1570 if ( numBSPLeafs != 0 ) {
1571 Sys_Printf( "freed numBSPLeafs\n" );
1574 if ( numBSPVisBytes != 0 ) {
1575 Sys_Printf( "freed numBSPVisBytes\n" );
1582 vfsListShaderFiles( pk3Shaderfiles, &pk3ShaderfilesN );
1585 Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3ShaderfilesN );
1586 for ( i = 0; i < pk3ShaderfilesN; i++ ){
1587 Sys_Printf( "%s\n", pk3Shaderfiles + i*65 );
1593 /* can exclude pure *base* textures right now, shouldn't create shaders for them anyway */
1594 for ( i = 0; i < pk3ShadersN ; i++ ){
1595 for ( j = 0; j < ExPureTexturesN ; j++ ){
1596 if ( !Q_stricmp( pk3Shaders + i*65, ExPureTextures + j*65 ) ){
1597 *( pk3Shaders + i*65 ) = '\0';
1602 /* can exclude repack.exclude shaders, assuming they got all their images */
1603 for ( i = 0; i < pk3ShadersN ; i++ ){
1604 for ( j = 0; j < rExShadersN ; j++ ){
1605 if ( !Q_stricmp( pk3Shaders + i*65, rExShaders + j*65 ) ){
1606 *( pk3Shaders + i*65 ) = '\0';
1612 //Parse Shader Files
1613 Sys_Printf( "\t\nParsing shaders....\n\n" );
1614 char shaderText[ 8192 ];
1615 char* allShaders = (char *)calloc( 16777216, sizeof( char ) );
1617 endofscript = qtrue;
1619 for ( i = 0; i < pk3ShaderfilesN; i++ ){
1620 qboolean wantShader = qfalse;
1623 /* load the shader */
1624 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
1625 if ( dbg ) Sys_Printf( "\n\tentering %s\n", pk3Shaderfiles + i*65 );
1626 SilentLoadScriptFile( temp, 0 );
1631 int line = scriptline;
1632 /* test for end of file */
1633 if ( !GetToken( qtrue ) ) {
1637 if( dbg ) Sys_Printf( "%s\n", token );
1639 strcpy( shaderText, token );
1641 if ( strchr( token, '\\') != NULL ){
1642 Sys_Printf( "WARNING1: %s : %s : shader name with backslash\n", pk3Shaderfiles + i*65, token );
1645 /* do wanna le shader? */
1646 wantShader = qfalse;
1647 for ( j = 0; j < pk3ShadersN; j++ ){
1648 if ( !Q_stricmp( pk3Shaders + j*65, token) ){
1655 for ( j = 0; j < rExTexturesN ; j++ ){
1656 if ( !Q_stricmp( pk3Shaders + shader*65, rExTextures + j*65 ) ){
1657 Sys_Printf( "WARNING3: %s : about to include shader for excluded texture\n", pk3Shaders + shader*65 );
1663 /* handle { } section */
1664 if ( !GetToken( qtrue ) ) {
1667 if ( strcmp( token, "{" ) ) {
1668 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s",
1669 temp, scriptline, token );
1671 strcat( shaderText, "\n{" );
1672 qboolean hasmap = qfalse;
1677 /* get the next token */
1678 if ( !GetToken( qtrue ) ) {
1681 if ( !strcmp( token, "}" ) ) {
1682 strcat( shaderText, "\n}\n\n" );
1685 /* parse stage directives */
1686 if ( !strcmp( token, "{" ) ) {
1687 qboolean tokenready = qfalse;
1688 strcat( shaderText, "\n\t{" );
1691 /* detour of TokenAvailable() '~' */
1692 if ( tokenready ) tokenready = qfalse;
1693 else line = scriptline;
1694 if ( !GetToken( qtrue ) ) {
1697 if ( !strcmp( token, "}" ) ) {
1698 strcat( shaderText, "\n\t}" );
1701 /* skip the shader */
1702 if ( !wantShader ) continue;
1704 /* digest any images */
1705 if ( !Q_stricmp( token, "map" ) ||
1706 !Q_stricmp( token, "clampMap" ) ) {
1707 strcat( shaderText, "\n\t\t" );
1708 strcat( shaderText, token );
1713 if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
1714 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1716 strcat( shaderText, " " );
1717 strcat( shaderText, token );
1719 else if ( !Q_stricmp( token, "animMap" ) ||
1720 !Q_stricmp( token, "clampAnimMap" ) ) {
1721 strcat( shaderText, "\n\t\t" );
1722 strcat( shaderText, token );
1725 GetToken( qfalse );// skip num
1726 strcat( shaderText, " " );
1727 strcat( shaderText, token );
1728 while ( TokenAvailable() ){
1730 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1731 strcat( shaderText, " " );
1732 strcat( shaderText, token );
1736 else if ( !Q_stricmp( token, "videoMap" ) ){
1737 strcat( shaderText, "\n\t\t" );
1738 strcat( shaderText, token );
1741 strcat( shaderText, " " );
1742 strcat( shaderText, token );
1743 FixDOSName( token );
1744 if ( strchr( token, '/' ) == NULL && strchr( token, '\\' ) == NULL ){
1745 sprintf( temp, "video/%s", token );
1746 strcpy( token, temp );
1748 FixDOSName( token );
1749 for ( j = 0; j < pk3VideosN; j++ ){
1750 if ( !Q_stricmp( pk3Videos + j*65, token ) ){
1754 for ( j = 0; j < ExVideosN; j++ ){
1755 if ( !Q_stricmp( ExVideos + j*65, token ) ){
1759 for ( j = 0; j < rExVideosN; j++ ){
1760 if ( !Q_stricmp( rExVideos + j*65, token ) ){
1764 strcpy ( pk3Videos + pk3VideosN*65, token );
1769 else if ( !Q_stricmp( token, "mapComp" ) || !Q_stricmp( token, "mapNoComp" ) || !Q_stricmp( token, "animmapcomp" ) || !Q_stricmp( token, "animmapnocomp" ) ){
1770 Sys_Printf( "WARNING7: %s : %s shader\n", pk3Shaders + shader*65, token );
1772 if ( line == scriptline ){
1773 strcat( shaderText, " " );
1774 strcat( shaderText, token );
1777 strcat( shaderText, "\n\t\t" );
1778 strcat( shaderText, token );
1781 else if ( line == scriptline ){
1782 strcat( shaderText, " " );
1783 strcat( shaderText, token );
1786 strcat( shaderText, "\n\t\t" );
1787 strcat( shaderText, token );
1791 /* skip the shader */
1792 else if ( !wantShader ) continue;
1794 /* -----------------------------------------------------------------
1795 surfaceparm * directives
1796 ----------------------------------------------------------------- */
1798 /* match surfaceparm */
1799 else if ( !Q_stricmp( token, "surfaceparm" ) ) {
1800 strcat( shaderText, "\n\tsurfaceparm " );
1802 strcat( shaderText, token );
1803 if ( !Q_stricmp( token, "nodraw" ) ) {
1804 wantShader = qfalse;
1805 *( pk3Shaders + shader*65 ) = '\0';
1809 /* skyparms <outer image> <cloud height> <inner image> */
1810 else if ( !Q_stricmp( token, "skyParms" ) ) {
1811 strcat( shaderText, "\n\tskyParms " );
1813 /* get image base */
1815 strcat( shaderText, token );
1817 /* ignore bogus paths */
1818 if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) {
1819 strcpy ( temp, token );
1820 sprintf( token, "%s_up", temp );
1821 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1822 sprintf( token, "%s_dn", temp );
1823 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1824 sprintf( token, "%s_lf", temp );
1825 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1826 sprintf( token, "%s_rt", temp );
1827 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1828 sprintf( token, "%s_bk", temp );
1829 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1830 sprintf( token, "%s_ft", temp );
1831 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
1833 /* skip rest of line */
1835 strcat( shaderText, " " );
1836 strcat( shaderText, token );
1838 strcat( shaderText, " " );
1839 strcat( shaderText, token );
1841 else if ( !!Q_strncasecmp( token, "implicit", 8 ) ){
1842 Sys_Printf( "WARNING5: %s : %s shader\n", pk3Shaders + shader*65, token );
1844 if ( line == scriptline ){
1845 strcat( shaderText, " " );
1846 strcat( shaderText, token );
1849 strcat( shaderText, "\n\t" );
1850 strcat( shaderText, token );
1853 else if ( !Q_stricmp( token, "fogparms" ) ){
1855 if ( line == scriptline ){
1856 strcat( shaderText, " " );
1857 strcat( shaderText, token );
1860 strcat( shaderText, "\n\t" );
1861 strcat( shaderText, token );
1864 else if ( line == scriptline ){
1865 strcat( shaderText, " " );
1866 strcat( shaderText, token );
1869 strcat( shaderText, "\n\t" );
1870 strcat( shaderText, token );
1875 if ( wantShader && !hasmap ){
1876 Sys_Printf( "WARNING8: %s : shader has no known maps\n", pk3Shaders + shader*65 );
1877 wantShader = qfalse;
1878 *( pk3Shaders + shader*65 ) = '\0';
1881 for ( j = 0; j < ExShadersN; j++ ){
1882 if ( !Q_stricmp( ExShaders + j*65, pk3Shaders + shader*65 ) ){
1883 wantShader = qfalse;
1884 *( pk3Shaders + shader*65 ) = '\0';
1889 strcat( allShaders, shaderText );
1890 *( pk3Shaders + shader*65 ) = '\0';
1895 /* TODO: RTCW's mapComp, mapNoComp, animmapcomp, animmapnocomp; nocompress?; ET's implicitmap, implicitblend, implicitmask */
1900 //pure textures (shader ones are done)
1901 for ( i = 0; i < pk3ShadersN; i++ ){
1902 if ( *( pk3Shaders + i*65 ) != '\0' ){
1903 if ( strchr( pk3Shaders + i*65, '\\') != NULL ){
1904 Sys_Printf( "WARNING2: %s : bsp shader path with backslash\n", pk3Shaders + i*65 );
1905 FixDOSName( pk3Shaders + i*65 );
1906 //what if theres properly slashed one in the list?
1907 for ( j = 0; j < pk3ShadersN; j++ ){
1908 if ( !Q_stricmp( pk3Shaders + i*65, pk3Shaders + j*65 ) && (i != j) ){
1909 *( pk3Shaders + i*65 ) = '\0';
1914 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
1915 for ( j = 0; j < pk3TexturesN; j++ ){
1916 if ( !Q_stricmp( pk3Shaders + i*65, pk3Textures + j*65 ) ){
1917 *( pk3Shaders + i*65 ) = '\0';
1921 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
1922 for ( j = 0; j < ExTexturesN; j++ ){
1923 if ( !Q_stricmp( pk3Shaders + i*65, ExTextures + j*65 ) ){
1924 *( pk3Shaders + i*65 ) = '\0';
1928 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
1929 for ( j = 0; j < rExTexturesN; j++ ){
1930 if ( !Q_stricmp( pk3Shaders + i*65, rExTextures + j*65 ) ){
1931 *( pk3Shaders + i*65 ) = '\0';
1939 for ( i = 0; i < pk3SoundsN; i++ ){
1940 for ( j = 0; j < ExSoundsN; j++ ){
1941 if ( !Q_stricmp( pk3Sounds + i*65, ExSounds + j*65 ) ){
1942 *( pk3Sounds + i*65 ) = '\0';
1946 if ( *( pk3Sounds + i*65 ) == '\0' ) continue;
1947 for ( j = 0; j < rExSoundsN; j++ ){
1948 if ( !Q_stricmp( pk3Sounds + i*65, rExSounds + j*65 ) ){
1949 *( pk3Sounds + i*65 ) = '\0';
1956 sprintf( temp, "%s/%s_strippedBYrepacker.shader", EnginePath, nameOFrepack );
1958 f = fopen( temp, "wb" );
1959 fwrite( allShaders, sizeof( char ), strlen( allShaders ), f );
1961 Sys_Printf( "Shaders saved to %s\n", temp );
1964 sprintf( packname, "%s/%s_repacked.pk3", EnginePath, nameOFrepack );
1967 Sys_Printf( "\n--- ZipZip ---\n" );
1969 Sys_Printf( "\n\tShader referenced textures....\n" );
1971 for ( i = 0; i < pk3TexturesN; i++ ){
1973 sprintf( temp, "%s.png", pk3Textures + i*65 );
1974 if ( vfsPackFile( temp, packname, compLevel ) ){
1975 Sys_Printf( "++%s\n", temp );
1979 sprintf( temp, "%s.tga", pk3Textures + i*65 );
1980 if ( vfsPackFile( temp, packname, compLevel ) ){
1981 Sys_Printf( "++%s\n", temp );
1984 sprintf( temp, "%s.jpg", pk3Textures + i*65 );
1985 if ( vfsPackFile( temp, packname, compLevel ) ){
1986 Sys_Printf( "++%s\n", temp );
1989 Sys_Printf( " !FAIL! %s\n", pk3Textures + i*65 );
1992 Sys_Printf( "\n\tPure textures....\n" );
1994 for ( i = 0; i < pk3ShadersN; i++ ){
1995 if ( *( pk3Shaders + i*65 ) != '\0' ){
1997 sprintf( temp, "%s.png", pk3Shaders + i*65 );
1998 if ( vfsPackFile( temp, packname, compLevel ) ){
1999 Sys_Printf( "++%s\n", temp );
2003 sprintf( temp, "%s.tga", pk3Shaders + i*65 );
2004 if ( vfsPackFile( temp, packname, compLevel ) ){
2005 Sys_Printf( "++%s\n", temp );
2008 sprintf( temp, "%s.jpg", pk3Shaders + i*65 );
2009 if ( vfsPackFile( temp, packname, compLevel ) ){
2010 Sys_Printf( "++%s\n", temp );
2013 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
2017 Sys_Printf( "\n\tSounds....\n" );
2019 for ( i = 0; i < pk3SoundsN; i++ ){
2020 if ( *( pk3Sounds + i*65 ) != '\0' ){
2021 if ( vfsPackFile( pk3Sounds + i*65, packname, compLevel ) ){
2022 Sys_Printf( "++%s\n", pk3Sounds + i*65 );
2025 Sys_Printf( " !FAIL! %s\n", pk3Sounds + i*65 );
2029 Sys_Printf( "\n\tVideos....\n" );
2031 for ( i = 0; i < pk3VideosN; i++ ){
2032 if ( vfsPackFile( pk3Videos + i*65, packname, compLevel ) ){
2033 Sys_Printf( "++%s\n", pk3Videos + i*65 );
2036 Sys_Printf( " !FAIL! %s\n", pk3Videos + i*65 );
2039 Sys_Printf( "\nSaved to %s\n", packname );
2041 /* return to sender */
2052 int main( int argc, char **argv ){
2055 extern qboolean werror;
2058 /* we want consistent 'randomness' */
2062 start = I_FloatTime();
2064 /* this was changed to emit version number over the network */
2065 printf( Q3MAP_VERSION "\n" );
2068 atexit( ExitQ3Map );
2070 /* read general options first */
2071 for ( i = 1; i < argc; i++ )
2074 if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" )
2075 || !strcmp( argv[ i ], "-help" ) ) {
2076 HelpMain( ( i + 1 < argc ) ? argv[ i + 1 ] : NULL );
2081 if ( !strcmp( argv[ i ], "-connect" ) ) {
2082 if ( ++i >= argc || !argv[ i ] ) {
2083 Error( "Out of arguments: No address specified after %s", argv[ i - 1 ] );
2085 argv[ i - 1 ] = NULL;
2086 Broadcast_Setup( argv[ i ] );
2091 else if ( !strcmp( argv[ i ], "-v" ) ) {
2099 else if ( !strcmp( argv[ i ], "-force" ) ) {
2104 /* make all warnings into errors */
2105 else if ( !strcmp( argv[ i ], "-werror" ) ) {
2110 /* patch subdivisions */
2111 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
2112 if ( ++i >= argc || !argv[ i ] ) {
2113 Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
2115 argv[ i - 1 ] = NULL;
2116 patchSubdivisions = atoi( argv[ i ] );
2118 if ( patchSubdivisions <= 0 ) {
2119 patchSubdivisions = 1;
2124 else if ( !strcmp( argv[ i ], "-threads" ) ) {
2125 if ( ++i >= argc || !argv[ i ] ) {
2126 Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
2128 argv[ i - 1 ] = NULL;
2129 numthreads = atoi( argv[ i ] );
2133 else if( !strcmp( argv[ i ], "-nocmdline" ) )
2135 Sys_Printf( "noCmdLine\n" );
2142 /* init model library */
2144 PicoSetMallocFunc( safe_malloc );
2145 PicoSetFreeFunc( free );
2146 PicoSetPrintFunc( PicoPrintFunc );
2147 PicoSetLoadFileFunc( PicoLoadFileFunc );
2148 PicoSetFreeFileFunc( free );
2150 /* set number of threads */
2153 /* generate sinusoid jitter table */
2154 for ( i = 0; i < MAX_JITTERS; i++ )
2156 jitters[ i ] = sin( i * 139.54152147 );
2157 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
2160 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
2161 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
2163 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
2164 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
2165 Sys_Printf( RADIANT_NAME " - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
2166 Sys_Printf( "%s\n", Q3MAP_MOTD );
2167 Sys_Printf( "%s\n", argv[0] );
2169 strcpy( q3map2path, argv[0] );//fuer autoPack func
2171 /* ydnar: new path initialization */
2172 InitPaths( &argc, argv );
2174 /* set game options */
2175 if ( !patchSubdivisions ) {
2176 patchSubdivisions = game->patchSubdivisions;
2179 /* check if we have enough options left to attempt something */
2181 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
2185 if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
2186 r = FixAASMain( argc - 1, argv + 1 );
2190 else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
2191 r = AnalyzeBSPMain( argc - 1, argv + 1 );
2195 else if ( !strcmp( argv[ 1 ], "-info" ) ) {
2196 r = BSPInfoMain( argc - 2, argv + 2 );
2200 else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
2201 r = VisMain( argc - 1, argv + 1 );
2205 else if ( !strcmp( argv[ 1 ], "-light" ) ) {
2206 r = LightMain( argc - 1, argv + 1 );
2210 else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
2211 Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
2212 argv[ 1 ] = "-fast"; /* eek a hack */
2213 r = LightMain( argc, argv );
2216 /* QBall: export entities */
2217 else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
2218 r = ExportEntitiesMain( argc - 1, argv + 1 );
2221 /* ydnar: lightmap export */
2222 else if ( !strcmp( argv[ 1 ], "-export" ) ) {
2223 r = ExportLightmapsMain( argc - 1, argv + 1 );
2226 /* ydnar: lightmap import */
2227 else if ( !strcmp( argv[ 1 ], "-import" ) ) {
2228 r = ImportLightmapsMain( argc - 1, argv + 1 );
2231 /* ydnar: bsp scaling */
2232 else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
2233 r = ScaleBSPMain( argc - 1, argv + 1 );
2237 else if ( !strcmp( argv[ 1 ], "-shift" ) ) {
2238 r = ShiftBSPMain( argc - 1, argv + 1 );
2242 else if ( !strcmp( argv[ 1 ], "-pk3" ) ) {
2243 r = pk3BSPMain( argc - 1, argv + 1 );
2247 else if ( !strcmp( argv[ 1 ], "-repack" ) ) {
2248 r = repackBSPMain( argc - 1, argv + 1 );
2251 /* ydnar: bsp conversion */
2252 else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
2253 r = ConvertBSPMain( argc - 1, argv + 1 );
2257 else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
2258 r = MiniMapBSPMain( argc - 1, argv + 1 );
2261 /* ydnar: otherwise create a bsp */
2263 /* used to write Smokin'Guns like tex file */
2264 compile_map = qtrue;
2266 r = BSPMain( argc, argv );
2270 end = I_FloatTime();
2271 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
2273 /* shut down connection */
2274 Broadcast_Shutdown();
2276 /* return any error code */