Advertisement
snake5

SGScript - GTA-VC .img extractor

Jun 3rd, 2013
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global Config =
  2. {
  3.     IMGFile = "models/gta3.img",
  4.     DIRFile = "models/gta3.dir",
  5.     OutputDir = "x_files",
  6. };
  7.  
  8. include_library( "fmt" );
  9. include_library( "io" );
  10. include_library( "string" );
  11.  
  12. function OpenGTA3Archive( img, dir )
  13. {
  14.     imgfile = io_file( img, FILE_READ );
  15.     dirfile = io_file( dir, FILE_READ );
  16.    
  17.     numentries = dirfile.size / 32;
  18.     println( "OpenGTA3Archive: " $ numentries $ " files found" );
  19.    
  20.     files = [];
  21.     for( i = 0; i < numentries; ++i )
  22.     {
  23.         fbit = dirfile.read( 32 );
  24.         data = fmt_unpack( "ll24s", fbit );
  25.         data[ 0 ] *= 2048;
  26.         data[ 1 ] *= 2048;
  27.         data[ 2 ] = string_part( data[ 2 ], 0, string_find( data[ 2 ], "\0" ) );
  28.         files.push( data );
  29.     }
  30.     println( "OpenGTA3Archive: loaded file table" );
  31.    
  32.     gta3archive = { img = imgfile, dir = dirfile, files = files };
  33.    
  34.     function gta3archive.loadfile( id )
  35.     {
  36.         if( this.files.size <= id )
  37.             return null;
  38.         this.img.seek( this.files[ id ][ 0 ] );
  39.         return this.img.read( this.files[ id ][ 1 ] );
  40.     }
  41.    
  42.     println( "Loaded archive!" );
  43.     return gta3archive;
  44. }
  45.  
  46. arch = OpenGTA3Archive( Config.IMGFile, Config.DIRFile );
  47.  
  48. println( "Extracting..." );
  49. for( i = 0; i < arch.files.size; ++i )
  50. {
  51.     data = arch.loadfile( i );
  52.     io_file_write( Config.OutputDir $ "/" $ arch.files[ i ][ 2 ], data );
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement