Skip to content

Instantly share code, notes, and snippets.

@lunasorcery
Created January 3, 2014 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunasorcery/8245899 to your computer and use it in GitHub Desktop.
Save lunasorcery/8245899 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Text;
namespace FtlDat
{
class Program
{
static void Main(string[] args)
{
string dir = @"E:\Steam\steamapps\common\FTL Faster Than Light\resources\";
foreach (string path in Directory.GetFiles(dir, "*.dat"))
{
using (BinaryReader br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read)))
{
int num_files = br.ReadInt32();
byte[] table = br.ReadBytes(num_files * 4);
for (int i = 0; i < num_files; i++)
{
int offset = BitConverter.ToInt32(table, i * 4);
if (offset == 0)
{
continue;
}
br.BaseStream.Position = offset;
int file_len = br.ReadInt32();
int name_len = br.ReadInt32();
string name = Encoding.ASCII.GetString(br.ReadBytes(name_len));
byte[] file = br.ReadBytes(file_len);
string outputPath = Path.Combine(dir, name);
FileInfo fi = new FileInfo(outputPath);
if (fi.Directory.Exists == false)
{
fi.Directory.Create();
}
using (BinaryWriter bw = new BinaryWriter(new FileStream(outputPath, FileMode.Create, FileAccess.Write)))
{
bw.Write(file);
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment