static void Main(string[] args) { if (args.Length == 1) { //Console.WriteLine("FullAutoTOC by FemShep (based on AutoTOC.exe & ME3Explorer code)"); //Console.WriteLine("Usage: FullAutoTOC.exe <ME3 Directory>"); if (Directory.Exists(args[0])) { RunFullGameTOC(args[0]); EndProgram(0); } } Options options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { if (options.GamePath != null) { RunFullGameTOC(options.GamePath); EndProgram(0); } if (options.TOCFolders != null && options.TOCFolders.Length > 0) { //precheck foreach (string folder in options.TOCFolders) { if (!Directory.Exists(folder)) { Console.WriteLine("One of the specified folders to make a TOC for does not exist: " + folder); EndProgram(1); } } Parallel.ForEach(options.TOCFolders, folder => { CreateUnpackedTOC(folder); }); EndProgram(0); } if (options.TOCFile != null) { if (!File.Exists(options.TOCFile)) { Console.WriteLine("TOC file to operate on doesn't exist: " + options.TOCFile); EndProgram(1); } TOCBinFile tbf = new TOCBinFile(options.TOCFile); if (options.DumpTOC) { int index = 0; Console.WriteLine("Index\tOffset\tFilesize\tFilename"); foreach (TOCBinFile.Entry e in tbf.Entries) { Console.WriteLine(index + "\t0x" + e.offset.ToString("X6") + "\t" + e.size + "\t" + e.name); index++; } EndProgram(0); } if (options.TOCUpdates == null || options.TOCUpdates.Length == 0 || options.TOCUpdates.Length % 2 != 0) { Console.WriteLine("--tocfile without --dumptoc requires --tocupdates followed by an even number of arguments repeating in a <filepath filesize> pattern."); EndProgram(1); } Dictionary <string, int> updates = new Dictionary <string, int>(); int getindex = 0; for (int i = 0; i < options.TOCUpdates.Length; i++, getindex++) { string path = options.TOCUpdates[i]; i++; try { int size = Convert.ToInt32(options.TOCUpdates[i]); updates.Add(path, size); } catch (FormatException e) { Console.WriteLine("ERROR READING ARGUMENT (" + options.TOCUpdates[i] + ") - cannot parse integer for size update."); EndProgram(1); } } //ITERATE OVER EACH ENTRY, USE LINQ TO FIND INDEX, UPDATE ENTRY. bool needssaving = false; foreach (KeyValuePair <string, int> update in updates) { bool found = false; for (int i = 0; i < tbf.Entries.Count; i++) { TOCBinFile.Entry entry = tbf.Entries[i]; if (entry.name.Contains(update.Key)) { { found = true; if (entry.size != update.Value || true) { Console.WriteLine("Updating entry " + update.Key); tbf.UpdateEntry(i, update.Value); //tbf.UpdateEntry(i, 5000); //Console.WriteLine("Readback: " + tbf.Entries[i].size); needssaving = true; } break; } } } if (!found) { Console.WriteLine("The entry " + update.Key + " was not found in this TOC file."); EndProgram(1); } } if (needssaving) { File.WriteAllBytes(options.TOCFile, tbf.Save().ToArray()); } //RunFullGameTOC(args[0]); EndProgram(0); } Console.WriteLine("No options were specified! Please see documentation (run FullAutoTOC.exe with no arguments) for info on how to use this product."); EndProgram(1); } }
public List <TOCBinFile.Entry> UpdateTOCbin(bool Rebuild = false) { //DebugOutput.PrintLn("File opened\nSearching TOCbin..."); int f = -1; for (int i = 0; i < Files.Length; i++) { if (Files[i].FileName.Contains("PCConsoleTOC.bin")) { f = i; } } if (f == -1) { //DebugOutput.PrintLn("Couldnt Find PCConsoleTOC.bin"); return(null); } int IndexTOC = f; //DebugOutput.PrintLn("Found PCConsoleTOC.bin(" + f + ")!\nLoading Entries..."); TOCBinFile TOC = new TOCBinFile(new MemoryStream(DecompressEntry(f).ToArray())); //DebugOutput.PrintLn("Checking Entries..."); int count = 0; //if (TOC.Entries == null) // DebugOutput.PrintLn("No TOC entries found. Oh dear..."); for (int i = 0; i < TOC.Entries.Count; i++) { TOCBinFile.Entry e = TOC.Entries[i]; f = -1; for (int j = 0; j < Files.Length; j++) { if (Files[j].FileName.Replace('/', '\\').Contains(e.name)) { f = j; } } if (f == -1) { List <string> parts = new List <string>(this.FileName.Split('\\')); parts.RemoveAt(parts.Count - 1); parts.RemoveAt(parts.Count - 1); string path = string.Join("\\", parts) + "\\" + e.name; if (File.Exists(path)) { FileInfo fi = new FileInfo(path); if (fi.Length != e.size) { e.size = (int)fi.Length; //DebugOutput.PrintLn((count++) + " : Entry will be updated " + e.name); TOC.Entries[i] = e; } } //else // DebugOutput.PrintLn((count++) + " : Entry not found " + e.name); } else { //if (Files[f].UncompressedSize == e.size) // DebugOutput.PrintLn((count++) + " : Entry is correct " + e.name); //else if (Files[f].UncompressedSize != e.size) { e.size = (int)Files[f].UncompressedSize; //DebugOutput.PrintLn((count++) + " : Entry will be updated " + e.name); TOC.Entries[i] = e; } } } //DebugOutput.PrintLn("Replacing TOC back..."); ReplaceEntry(TOC.Save().ToArray(), IndexTOC); if (Rebuild) { //DebugOutput.PrintLn("Reopening SFAR..."); Load(FileName); Console.WriteLine("Rebuilding SFAR"); ReBuild(); } return(TOC.Entries); }