View Single Post
  #36  
Unread 01-14-2005, 05:49 PM
mixer343 mixer343 is offline
A Young Mystail Rat
 
Join Date: Dec 2004
Server: Antonia Bayle
Posts: 2
Talking perl

heres a perl script by thelxepeia that extracts VPK files
copy this code and rename to decompress.pl
put the perl script and the *.vpk in the main perl folder (usually C:\Perl\)
from the command line example: "perl decompress.pl antonica.vpk unpacked"
and it will extract everything into the C:\Perl\unpacked\ folder

Code:
use Compress::Zlib; 

$in = $ARGV[0]; 
$path = $ARGV[1]; 

die "Missing input file name.\n" unless $in; 
die "Missing input file name.\n" unless $path; 

mkdir $path; 

open (VPK, "< $in"); 
binmode(VPK); 

$chunk_count = 0; 

read(VPK,$packed_len,4); 

while (length($packed_len) == 4) 
{ 
   $unpacked_len = unpack("L", $packed_len); 
   read(VPK,$data_seg,$unpacked_len); 
   read(VPK,$packed_len,4); 
   if (length($packed_len) != 4) 
   { 
      $file_block = uncompress($data_seg); 
      unless (defined($file_block)) 
      { 
         $file_block = $data_seg; 
      } 
  
      ($fnblocksize, $fncount) = unpack("LL", $file_block); 
      $file_block = substr($file_block, 8); 

      for ($i = 1; $i <= $fncount; $i++) 
      { 
         ($block_start, $block_len, $fnlen) = unpack("LLL", $file_block); 
         $file_name = substr($file_block,12,$fnlen); 
         $file_name =~ /(.*)\/(.*)/; 
         @paths = split(/\//,$1); 
         $path = $ARGV[1]; 
         foreach $dir(@paths) 
         { 
            $path = $path . '/' . $dir; 
            mkdir $path; 
         } 
         $out = "> " . $ARGV[1] . "/" . $file_name; 
         open(OUT, $out); 
         binmode(OUT); 

         seek(VPK, $block_start + 4, SEEK_SET); 
         read(VPK, $bin_data, $block_len); 
         $u_bin_data = uncompress($bin_data); 
         unless (defined($u_bin_data)) 
         { 
            $u_bin_data = $bin_data; 
         } 
         print(OUT substr($u_bin_data, 9 + length($file_name))); 
         close(OUT); 
         $file_block = substr($file_block, 12 + $fnlen); 
      } 
   } 
} 

close (VPK);
have fun
Reply With Quote