Created
January 3, 2014 20:25
-
-
Save lunasorcery/8245899 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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