Advertisement
C0BRA

Gmod Uncompress /cache/*.lua

Jan 8th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. using SevenZip;
  8. using SevenZip.Compression.LZMA;
  9.  
  10. namespace GMODDataPack
  11. {
  12.     class Program
  13.     {
  14.         static string ReadCString(BinaryReader r)
  15.         {
  16.             StringBuilder sb = new StringBuilder();
  17.             char c = r.ReadChar();
  18.             while (c != '\0')
  19.             {
  20.                 sb.Append(c);
  21.                 c = r.ReadChar();
  22.             }
  23.             return sb.ToString();
  24.         }
  25.  
  26.         static void Main(string[] args)
  27.         {
  28.             for( int i = 0; i < args.Length; i++ )
  29.             {
  30.                 byte[] bytes = File.ReadAllBytes( args[ i ] );
  31.                 BinaryReader r = new BinaryReader( new MemoryStream( bytes ) );
  32.  
  33.                 r.ReadBytes( 4 );
  34.                 byte[] lzma_props = r.ReadBytes( 5 );
  35.                 Int64 real_size = r.ReadInt64();
  36.  
  37.                 int size = bytes.Length - 5 - 4 - 4;
  38.  
  39.                 Console.WriteLine( "{0}: {1} bytes -> {2} bytes", args[i], size, real_size );
  40.  
  41.                 SevenZip.Compression.LZMA.Decoder dec = new SevenZip.Compression.LZMA.Decoder();
  42.                 dec.SetDecoderProperties( lzma_props );
  43.  
  44.                 MemoryStream msout = new MemoryStream();
  45.                 dec.Code( r.BaseStream, msout, size, real_size, null );
  46.  
  47.                 msout.Position = 0;
  48.                 byte[] output = msout.ToArray();
  49.                 byte[] no_null = new byte[output.Length - 1];
  50.                 Array.Copy( output, no_null, no_null.Length );
  51.  
  52.                 if( !Directory.Exists( "./uncompressed" ) )
  53.                     Directory.CreateDirectory( "./uncompressed" );
  54.  
  55.                 File.WriteAllBytes( "./uncompressed/" + args[ i ], no_null );
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement