private LayoutFile AddLayout(string name) { var dataPath = Path.Combine(this._BasePath, name); var layoutPath = Path.Combine(dataPath, "layout.toc"); if (File.Exists(layoutPath) == false) { Logger.Debug("Could not load superbundle layout for '{0}'.", name); return(null); } var layout = LayoutFile.Read(layoutPath); // superbundles listed in the layout, but not associated with any install chunk? /* * var badSuperbundles = layout.Superbundles * .Select(sbi => sbi.Name) * .Except(layout.InstallManifest.InstallChunks * .Where(ic => ic.Superbundles != null) * .SelectMany(ic => ic.Superbundles)) * .ToArray(); */ var index = this._Sources.FindLastIndex(s => s.Layout.Head > layout.Head); this._Sources.Insert(index < 0 ? 0 : (index + 1), new DataSource(layout, dataPath)); return(layout); }
public static void Main(string[] args) { bool verbose = false; bool showHelp = false; var options = new OptionSet() { { "v|verbose", "be verbose", v => verbose = v != null }, { "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 < 1 || extras.Count > 2 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+ input_[sb|toc] [output_dir]", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } Paths paths; if (Paths.Discover(extras[0], extras.Count > 1 ? extras[1] : null, out paths) == false) { Console.WriteLine("Failed to discover data paths."); return; } var superbundleName = Path.ChangeExtension(paths.Superbundle.Substring(paths.Data.Length + 1), null); superbundleName = Helpers.FilterName(superbundleName).ToLowerInvariant(); var layout = LayoutFile.Read(Path.Combine(paths.Data, "layout.toc")); var chunkLookup = new ChunkLookup(layout, paths.Data); var chunkLoader = new ChunkLoader(chunkLookup); var superbundle = chunkLookup.AddBundle(superbundleName); // add common chunk bundles (chunks*.toc/sb) foreach (var superbundleInfo in layout.Superbundles.Where( sbi => ChunkLookup.IsChunkBundle(sbi.Name) == true)) { if (chunkLookup.AddBundle(superbundleInfo.Name.ToLowerInvariant()) == null) { Console.WriteLine("Failed to load catalog for '{0}'.", superbundleInfo.Name); } } foreach (var bundleInfo in superbundle.Bundles) { if (bundleInfo.Ebx == null) { continue; } foreach (var ebxInfo in bundleInfo.Ebx) { using (var data = new MemoryStream()) { try { chunkLoader.Load(ebxInfo, data); data.Position = 0; } catch (ChunkCryptoKeyMissingException e) { Console.WriteLine("Cannot decrypt '{0}' without crypto key '{1}'.", ebxInfo.Name, e.KeyId); continue; } catch (Exception e) { Console.WriteLine("Exception while loading '{0}':", ebxInfo.Name); Console.WriteLine(e); continue; } var outputName = Helpers.FilterPath(ebxInfo.Name); var outputPath = Path.Combine(paths.Output, outputName + ".dummy"); var outputParentPath = Path.GetDirectoryName(outputPath); if (string.IsNullOrEmpty(outputParentPath) == false) { Directory.CreateDirectory(outputParentPath); } if (verbose == true) { Console.WriteLine("{0}", resourceInfo.Name); } bool wasConverted = false; outputPath = Path.Combine(paths.Output, outputName + ".entity"); wasConverted = ConvertEntity(data, outputPath, chunkLookup, chunkLoader); if (wasConverted == false) { outputPath = Path.Combine(paths.Output, outputName + ".ebx"); using (var output = File.Create(outputPath)) { output.WriteFromStream(data, data.Length); } } } } } }
public static void Main(string[] args) { bool convertTextures = false; bool showHelp = false; var options = new OptionSet() { { "convert-textures", "convert textures", v => convertTextures = v != null }, { "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 < 1 || extras.Count > 2 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+ input_[sb|toc] [output_dir]", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } string bundlePath, superbundlePath, layoutPath, outputBasePath; if (Path.GetExtension(extras[0]) == ".sb") { superbundlePath = Path.GetFullPath(extras[0]); bundlePath = Path.ChangeExtension(superbundlePath, ".toc"); layoutPath = Helpers.FindLayoutPath(superbundlePath); outputBasePath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(superbundlePath, null) + "_unpack"; } else { bundlePath = Path.GetFullPath(extras[0]); superbundlePath = Path.ChangeExtension(bundlePath, ".sb"); layoutPath = Helpers.FindLayoutPath(bundlePath); outputBasePath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(bundlePath, null) + "_unpack"; } if (string.IsNullOrEmpty(layoutPath) == true) { Console.WriteLine("Could not find layout file."); return; } var dataPath = Path.GetDirectoryName(layoutPath) ?? ""; var bundle = TableOfContentsFile.Read(bundlePath); var superbundle = SuperbundleFile.Read(superbundlePath); var extensionsById = ResourceTypes.GetExtensions(); if (bundle.IsCas == false) { throw new NotImplementedException(); } else { var commonBundlePaths = Directory.GetFiles(dataPath, "chunks*.toc", SearchOption.AllDirectories); var commonBundles = new List <TableOfContentsFile>(); foreach (var commonBundlePath in commonBundlePaths) { var commonBundle = TableOfContentsFile.Read(commonBundlePath); commonBundles.Add(commonBundle); } var superbundleName = Path.ChangeExtension(superbundlePath.Substring(dataPath.Length + 1), null); superbundleName = Helpers.FilterName(superbundleName).ToLowerInvariant(); var layout = LayoutFile.Read(layoutPath); var installChunks = GetSuperbundleInstallChunks(layout, superbundleName); var catalogLookup = new CatalogLookup(dataPath); foreach (var installChunk in installChunks) { if (catalogLookup.Add(installChunk.InstallBundle) == false) { Console.WriteLine("Failed to load catalog for '{0}'.", installChunk.Name); } } foreach (var bundleInfo in superbundle.Bundles) { if (bundleInfo.Resources == null) { continue; } foreach (var resourceInfo in bundleInfo.Resources) { var entry = catalogLookup.GetEntry(resourceInfo); if (entry == null) { Console.WriteLine("Could not find catalog entry for '{0}'.", resourceInfo.Name); continue; } if (entry.CompressedSize != resourceInfo.Size) { throw new FormatException(); } var outputName = Helpers.FilterPath(resourceInfo.Name); var outputPath = Path.Combine(outputBasePath, outputName + ".dummy"); var outputParentPath = Path.GetDirectoryName(outputPath); if (string.IsNullOrEmpty(outputParentPath) == false) { Directory.CreateDirectory(outputParentPath); } Console.WriteLine("{0}", resourceInfo.Name); bool wasConverted = false; if (convertTextures == true && resourceInfo.ResourceType == ResourceTypes.Texture) { wasConverted = ConvertTexture(bundleInfo, resourceInfo, entry, outputPath, catalogLookup, commonBundles); } if (wasConverted == false) { string extension; if (extensionsById.TryGetValue(resourceInfo.ResourceType, out extension) == true) { extension = "." + extension; } else { extension = ".#" + resourceInfo.ResourceType.ToString("X8"); } outputPath = Path.Combine(outputBasePath, outputName + extension); using (var output = File.Create(outputPath)) { Extraction.Extract(resourceInfo, entry, output); } } } } } }