Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using SevenZip;
- using SevenZip.Compression.LZMA;
- namespace GMODDataPack
- {
- class Program
- {
- static string ReadCString(BinaryReader r)
- {
- StringBuilder sb = new StringBuilder();
- char c = r.ReadChar();
- while (c != '\0')
- {
- sb.Append(c);
- c = r.ReadChar();
- }
- return sb.ToString();
- }
- static void Main(string[] args)
- {
- if (args.Length == 0) return;
- byte[] bytes = File.ReadAllBytes(args[0]);
- BinaryReader r = new BinaryReader(new MemoryStream(bytes));
- string lzma = "" + r.ReadChar() + r.ReadChar() + r.ReadChar() + r.ReadChar();
- if(lzma != "LZMA")
- return;
- UInt32 size = r.ReadUInt32();
- UInt32 size_or = r.ReadUInt32();
- byte[] lzma_props = r.ReadBytes(5);
- byte[] dp = r.ReadBytes((int)size);
- SevenZip.Compression.LZMA.Decoder dec = new SevenZip.Compression.LZMA.Decoder();
- dec.SetDecoderProperties(lzma_props);
- MemoryStream ms = new MemoryStream(dp);
- MemoryStream msout = new MemoryStream();
- int readsize = int.MaxValue;
- while (true) // Fuck this shit, but it works
- {
- try
- {
- dec.Code(ms, msout, size,
- readsize, null);
- if (readsize < 1) break;
- }
- catch
- {
- readsize = readsize / 10;
- }
- }
- msout.Position = 0;
- r = new BinaryReader(msout);
- byte[] datapack = r.ReadBytes((int)msout.Length);//(int)size_or);
- r = new BinaryReader(new MemoryStream(datapack));
- string cats = "" + r.ReadChar() + r.ReadChar() + r.ReadChar() + r.ReadChar();
- if (cats != "CATS")
- return;
- UInt16 vers = r.ReadUInt16();
- UInt16 filecount = r.ReadUInt16();
- for (int i = 0; i < filecount; i++)
- {
- UInt32 fsizetotal = r.ReadUInt32();
- string fname = ReadCString(r);
- byte[] hash = r.ReadBytes(16);
- uint fsize = fsizetotal - (uint)(fname.Length + 1 + 16); /*+1 for \0*/
- if (fsize == 1)
- {
- Console.WriteLine("Not writing {0} (Null)", fname);
- r.ReadByte();
- }
- else
- {
- byte[] filecont = r.ReadBytes((int)fsize);
- string fnametowrite = Path.GetFileName(args[0]).Replace('.', '_') + "/" + fname;
- Directory.CreateDirectory(Path.GetDirectoryName(fnametowrite));
- File.WriteAllBytes(fnametowrite, filecont);
- Console.WriteLine("Writing {0}...", fname);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement