Skip to content

Commit

Permalink
Add functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCxyrtyx committed Jun 2, 2016
1 parent a60be79 commit bdba6fa
Showing 1 changed file with 122 additions and 3 deletions.
125 changes: 122 additions & 3 deletions AutoTOC/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace AutoTOC
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 1)
{
string gameDir = args[0];
prepareToCreateTOC(gameDir + @"\BIOGame\");
DirectoryInfo[] dlcFolders = (new DirectoryInfo(gameDir + @"\BIOGame\DLC\")).GetDirectories();
foreach (DirectoryInfo d in dlcFolders)
{
prepareToCreateTOC(d.FullName);
}
}
}

static void prepareToCreateTOC(string consoletocFile)
{
if (!consoletocFile.EndsWith("\\"))
{
consoletocFile = consoletocFile + "\\";
}
List<string> files = GetFiles(consoletocFile);
if (files.Count != 0)
{
string t = files[0];
int n = t.IndexOf("DLC_");
if (n > 0)
{
for (int i = 0; i < files.Count; i++)
files[i] = files[i].Substring(n);
string t2 = files[0];
n = t2.IndexOf("\\");
for (int i = 0; i < files.Count; i++)
files[i] = files[i].Substring(n + 1);
}
else
{
n = t.IndexOf("BIOGame");
if (n > 0)
{
for (int i = 0; i < files.Count; i++)
files[i] = files[i].Substring(n);
}
}
string pathbase;
string t3 = files[0];
int n2 = t3.IndexOf("BIOGame");
if (n2 >= 0)
{
pathbase = Path.GetDirectoryName(Path.GetDirectoryName(consoletocFile)) + "\\";
}
else
{
pathbase = consoletocFile;
}
CreateTOC(pathbase, consoletocFile + "PCConsoleTOC.bin", files.ToArray());
}
}

static void CreateTOC(string basepath, string tocFile, string[] files)
{
FileStream fs = new FileStream(tocFile, FileMode.Create, FileAccess.Write);
fs.Write(BitConverter.GetBytes((int)0x3AB70C13), 0, 4);
fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);
fs.Write(BitConverter.GetBytes((int)0x1), 0, 4);
fs.Write(BitConverter.GetBytes((int)0x8), 0, 4);
fs.Write(BitConverter.GetBytes((int)files.Length), 0, 4);
for (int i = 0; i < files.Length; i++)
{
string file = files[i];
if (i == files.Length - 1)//Entry Size
fs.Write(new byte[2], 0, 2);
else
fs.Write(BitConverter.GetBytes((ushort)(0x1D + file.Length)), 0, 2);
fs.Write(BitConverter.GetBytes((ushort)0), 0, 2);//Flags
if (Path.GetFileName(file).ToLower() != "pcconsoletoc.bin")
{
FileStream fs2 = new FileStream(basepath + file, FileMode.Open, FileAccess.Read);
fs.Write(BitConverter.GetBytes((int)fs2.Length), 0, 4);//Filesize
fs2.Close();
}
else
{
fs.Write(BitConverter.GetBytes((int)0), 0, 4);//Filesize
}
fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);//SHA1
fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);
fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);
fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);
fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);
foreach (char c in file)
fs.WriteByte((byte)c);
fs.WriteByte(0);
}
fs.Close();
}

static List<string> GetFiles(string basefolder)
{
List<string> res = new List<string>();
string test = Path.GetFileName(Path.GetDirectoryName(basefolder));
string[] files = DirFiles(basefolder);
res.AddRange(files);
DirectoryInfo folder = new DirectoryInfo(basefolder);
DirectoryInfo[] folders = folder.GetDirectories();
if (folders.Length != 0)
if (test != "BIOGame")
foreach (DirectoryInfo f in folders)
res.AddRange(GetFiles(basefolder + f.Name + "\\"));
else
foreach (DirectoryInfo f in folders)
if (f.Name == "CookedPCConsole" || f.Name == "Movies" || f.Name == "Splash")
res.AddRange(GetFiles(basefolder + f.Name + "\\"));
return res;
}

static string[] Pattern = { "*.pcc", "*.afc", "*.bik", "*.bin", "*.tlk", "*.txt", "*.cnd", "*.upk", "*.tfc" };

static string[] DirFiles(string path)
{
List<string> res = new List<string>();
foreach (string s in Pattern)
res.AddRange(Directory.GetFiles(path, s));
return res.ToArray();
}
}
}

0 comments on commit bdba6fa

Please sign in to comment.