Advertisement
RaWRCoder

Steam Workshop Skyrim: CKM 2 BSA+ESP

Mar 31st, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace ckmExtractor
  5. {
  6.     class Program
  7.     {
  8.         private static string FileName = "";
  9.  
  10.         private static void Main(string[] args)
  11.         {
  12.             if (args.Length > 0)
  13.                 FileName = args[0];
  14.  
  15.             while (string.IsNullOrWhiteSpace(FileName) || !FileName.EndsWith(".ckm"))
  16.             {
  17.                 Console.WriteLine("Specify CKM file (you may obtain it at http://steamworkshopdownloader.com/):");
  18.                 FileName = Console.ReadLine();
  19.             }
  20.             Console.WriteLine("Starting extraction ...");
  21.             Extract(FileName);
  22.             Console.WriteLine("OK!");
  23.             Console.ReadLine();
  24.         }
  25.  
  26.         public static void Extract(string fileName)
  27.         {
  28.             var fs = new StreamReader(fileName);
  29.             var br = new BinaryReader(fs.BaseStream);
  30.             var len = br.ReadInt32();
  31.             Console.WriteLine("BSA length is " + len);
  32.             Console.WriteLine("Extracting bsa ...");
  33.             cpyfile(br, Path.ChangeExtension(fileName, "bsa"), len);
  34.             len = br.ReadInt32();
  35.             if (len == 0)
  36.                 len = (int) (new FileInfo(FileName).Length - br.BaseStream.Position);
  37.             else
  38.                 Console.WriteLine("! Unexpected non-zero value. Don`t trust this program`s results, report author about this error !");
  39.            
  40.             Console.WriteLine("ESP length is " + len);
  41.             Console.WriteLine("Extracting esp ...");
  42.             cpyfile(br, Path.ChangeExtension(fileName, "esp"), len);
  43.  
  44.             fs.Close();
  45.         }
  46.  
  47.         public static void cpyfile(BinaryReader from, string fileName, int bytes)
  48.         {
  49.             var fs = new StreamWriter(fileName);
  50.             var bw = new BinaryWriter(fs.BaseStream);
  51.             int readBytes = 0;
  52.             do
  53.             {
  54.                 var bts = from.ReadBytes(Math.Min(4096, bytes - readBytes));
  55.                 readBytes += bts.Length;
  56.                 bw.Write(bts);
  57.             } while (readBytes < bytes);
  58.             fs.Close();
  59.         }
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement