#!/usr/bin/perl ## Author: Dan Barrett a.k.a. wily duck ## Date: 5-2-2006 ## Version: 1.1 - Added ignore filter ## Version: 1.0 ## Purpose: Reads a quake3 formatted map file (i.e. urban terror), outputs a new file ## that swaps all texture locations into one central location. Wrote this ## to clean up superman_b3 as there are textures and shaders in all sorts ## of places, so this brings them into one neat home. Also probably good ## for cleaning up the source directory cause if you're like me you have ## gobs of unneeded textures and don't want to accidentally put them in the ## final .pk3! Runs in perl 5.8. It will not overwrite the original .map ## file. It will not perform copy of move functions, the final output can ## be copy-pasted to do that. Error handling is decent, main code isn't ## commented. Simple program though, took about an hour to write and debug. ## ## Bugs: None, but I did have to pull a cheap manuever in the copy output. Since ## all textures/shaders are stored without an extension, I output a copy for ## both .tga and .jpg. If the source file doesn't exist, it won't copy, easy ## enough. $default_map = "superman_b4.map"; ## what map source file to read, or specify as arg on cmd line $replace = "supersoldier"; ## string to replace within the map source file $map_out = "supersoldier.map"; ## what file to write the output to ## Final output gives you a quick paste batch run to copy all required textures to their ## new home. $dosunix = "\\"; # "\\" for dos, "\/" for unix $copy = "copy"; # "copy" for dos, "cp" for unix ## List of things to ignore @ignore = ("urban_terror", "common"); ##### Main program ##### $file = $ARGV[0] || $default_map; open (FILE, "$file") || die("couldn't open $file"); open (OUT, ">$map_out") || die("couldn't write $map_out"); while ($line = ) { if ($line !~ /\/\// && $line =~ /\S+/) { ($inc) = $line =~ /\(.+\)\s\(.+\)\s\(.+\)\s(\S+)\s+/; $skip = 0; foreach $list (@ignore) { $skip = 1 if $inc =~ /$list/; } if ($inc =~ /\S+\/\S+/ && $skip == 0) { ($dir,$img) = split(/\//,$inc); $found{"$inc"} = "$copy $inc $replace/$img"; #print "$dir $replace\n"; $line =~ s/$dir\//$replace\//; } } print OUT $line; } close OUT; close FILE; ## print copy lines foreach $line (sort keys %found) { $count++; if ($dosunix eq "\\") { $found{$line} =~ s/\//\\/g; } ($copy, $left, $right) = split (/\s+/, $found{$line}); print "$copy $left.jpg $right.jpg\n"; print "$copy $left.tga $right.tga\n"; } print "\n$count textures/shaders found\n";