public static void Main(string[] args) { bool showHelp = false; OptionSet options = new OptionSet() { { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (extras.Count != 0 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } Console.WriteLine("Loading project..."); var manager = ProjectData.Manager.Load(); if (manager.ActiveProject == null) { Console.WriteLine("Nothing to do: no active project loaded."); return; } var project = manager.ActiveProject; var fileNames = manager.LoadListsFileNames(); var columnNames = manager.LoadListsColumnNames(); var installPath = project.InstallPath; var listsPath = project.ListsPath; if (installPath == null) { Console.WriteLine("Could not detect install path."); return; } else if (listsPath == null) { Console.WriteLine("Could not detect lists path."); return; } var inputPath = Path.Combine(installPath, @"packages\core\data\2da.rim"); Console.WriteLine("Processing..."); var results = new Dictionary <uint, string>(); var erf = new EncapsulatedResourceFile(); using (var input = File.OpenRead(inputPath)) { erf.Deserialize(input); var loader = new Loader(erf); foreach (var entry in loader) { if (entry.TypeHash != EXT) { continue; } string inputName = entry.Name; if (inputName == null) { if (fileNames.Contains(entry.NameHash) == false) { continue; } inputName = fileNames[entry.NameHash]; } var outputPath = GetListPath(inputName); outputPath = Path.Combine(listsPath, outputPath); var data = loader.Load(input, entry); var localResults = new Dictionary <uint, string>(); var gff = new GenericFile_Data(); gff.Deserialize(data); var root = gff.Export(); var columns = root[10002].As <List <KeyValue> >(null); if (columns != null) { foreach (var column in columns) { var id = column[10001].As <uint>(); var name = columnNames[id]; localResults.Add(id, name); results[id] = name; } } Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); using (var output = new StreamWriter(outputPath)) { var breakdown = new Breakdown(); breakdown.Known = localResults.Where(r => r.Value != null).Count(); breakdown.Total = localResults.Count; output.WriteLine("; {0}", breakdown.ToString()); foreach (var kvp in localResults) { if (kvp.Value == null) { output.WriteLine("; {0:X8}", kvp.Key); } else { output.WriteLine("{0}", kvp.Value); } } } } } using (var output = new StreamWriter(Path.Combine(Path.Combine(listsPath, "columns"), "status.txt"))) { var breakdown = new Breakdown(); breakdown.Known = results.Where(r => r.Value != null).Count(); breakdown.Total = results.Count; output.WriteLine("{0}", breakdown.ToString()); } using (var output = new StreamWriter(Path.Combine(Path.Combine(listsPath, "columns"), "master.columnlist"))) { foreach (var result in results.Where(r => r.Value != null).OrderBy(r => r.Value)) { output.WriteLine(result.Value); } } }
public static void Main(string[] args) { var exportType = ExportType.CSV; bool showHelp = false; bool pauseOnError = true; OptionSet options = new OptionSet() { { "np|nopause", "don't pause on errors", v => pauseOnError = v == null }, { "csv", "set output type to CSV", v => exportType = v != null ? ExportType.CSV : exportType }, { "xslx", "set output type to XSLX", v => exportType = v != null ? ExportType.XLSX : exportType }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); Pause(pauseOnError); return; } if (extras.Count < 1 || extras.Count > 2 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+ input_tlk [output_tlk]", GetExecutableName()); Console.WriteLine("Decompile GDA files to their 2DA counterparts."); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); Pause(pauseOnError); return; } string inputPath = extras[0]; string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, "." + exportType.ToString().ToLowerInvariant()); /* * var manager = Setup.Manager.Load(); * if (manager.ActiveProject != null) * { * manager.ActiveProject.Load(); * Names = manager.ActiveProject.ColumnHashLookup; * } * else * { * Console.WriteLine("Warning: no active project loaded."); * } */ using (var gff = new GenericFile_Data()) { using (var input = File.OpenRead(inputPath)) { gff.Deserialize(input); } if (gff.FormatType != GFF.FormatType.G2DA) { Console.WriteLine("'{0}' is not a GDA file.", Path.GetFileName(outputPath)); Pause(pauseOnError); return; } else if (gff.FormatVersion != 0x56302E32) { Console.WriteLine("'{0}' has an unexpected version (wanted V0.2).", Path.GetFileName(outputPath)); Pause(pauseOnError); return; } Console.WriteLine("Importing GDA..."); var root = gff.Export(); var columnDefinitions = root[10002].As <List <KeyValue> >(); var rows = root[10003].As <List <KeyValue> >(); Console.WriteLine("Validating GDA..."); if (rows != null) { foreach (var kv in rows) { if (kv.Values.Count != columnDefinitions.Count) { throw new FormatException("mismatching column count for row"); } for (int i = 0; i < kv.Values.Count; i++) { var columnDefinition = columnDefinitions[i]; var type = columnDefinition[10999].As <byte>(0xFF); var column = kv[10005 + i]; if (type > 4) { throw new FormatException("bad variable type"); } } } } using (var output = File.Create(outputPath)) { string name = Path.GetFileNameWithoutExtension(inputPath); switch (exportType) { case ExportType.XLSX: ExportXSLT(name, output, root); break; case ExportType.CSV: ExportCSV(name, output, root); break; default: { throw new InvalidOperationException(); } } } } }