Exemple #1
0
        public static void Main(string[] args)
        {
            int  logLevelOrdinal = 3;
            bool noPatch         = false;
            bool noCatch         = false;
            bool showHelp        = false;

            var options = new OptionSet()
            {
                { "no-patch", "don't use patch data", v => noPatch = v != null },
                { "no-catch", "don't catch exceptions when loading data", v => noCatch = v != null },
                { "v|verbose", "increase log level (-v/-vv/-vvv)", v => IncreaseLogLevel(v, ref logLevelOrdinal) },
                { "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;
            }

            LogHelper.SetConfiguration(NLog.LogLevel.FromOrdinal(logLevelOrdinal));

            var inputPath      = extras[0];
            var outputBasePath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_ebx_unpack";

            string superbundleName;
            var    dataBasePath = Discovery.FindBasePath(inputPath, out superbundleName);

            if (string.IsNullOrEmpty(dataBasePath) == true)
            {
                Logger.Error("Failed to discover base game path.");
                return;
            }

            var dataManager = DataManager.Initialize(dataBasePath, noPatch);

            if (dataManager == null)
            {
                Logger.Fatal("Could not initialize superbundle manager.");
                return;
            }

            var superbundle = dataManager.MountSuperbundle(superbundleName);

            foreach (var ebxInfo in superbundle.Bundles
                     .Where(bi => bi.Ebx != null)
                     .SelectMany(bi => bi.Ebx)
                     .OrderBy(bi => bi.Name))
            {
                using (var data = new MemoryStream())
                {
                    Logger.Info(ebxInfo.Name);

                    if (noCatch == true)
                    {
                        dataManager.LoadData(ebxInfo, data);
                        data.Position = 0;
                    }
                    else
                    {
                        try
                        {
                            dataManager.LoadData(ebxInfo, data);
                            data.Position = 0;
                        }
                        catch (ChunkCryptoKeyMissingException e)
                        {
                            Logger.Warn("Cannot decrypt '{0}' without crypto key '{1}'.",
                                        ebxInfo.Name,
                                        e.KeyId);
                            continue;
                        }
                        catch (Exception e)
                        {
                            Logger.Warn(e, "Exception while loading '{0}':", ebxInfo.Name);
                            continue;
                        }
                    }

                    var outputName       = Helpers.FilterPath(ebxInfo.Name);
                    var outputPath       = Path.Combine(outputBasePath, outputName + ".dummy");
                    var outputParentPath = Path.GetDirectoryName(outputPath);
                    if (string.IsNullOrEmpty(outputParentPath) == false)
                    {
                        Directory.CreateDirectory(outputParentPath);
                    }

                    bool wasConverted = false;
                    outputPath   = Path.Combine(outputBasePath, outputName + ".entity");
                    wasConverted = ConvertEntity(data, outputPath, dataManager);

                    if (wasConverted == false)
                    {
                        outputPath = Path.Combine(outputBasePath, outputName + ".ebx");
                        using (var output = File.Create(outputPath))
                        {
                            data.Position = 0;
                            output.WriteFromStream(data, data.Length);
                        }
                    }
                }
            }

            dataManager.Dispose();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            bool noPatch         = false;
            bool noCatch         = false;
            int  logLevelOrdinal = 3;
            bool showHelp        = false;

            var options = new OptionSet()
            {
                { "no-catch", "don't catch exceptions when loading data", v => noCatch = v != null },
                { "v|verbose", "increase log level (-v/-vv/-vvv)", v => IncreaseLogLevel(v, ref logLevelOrdinal) },
                { "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]+ game_dir [output_dir]", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            LogHelper.SetConfiguration(NLog.LogLevel.FromOrdinal(logLevelOrdinal));

            var outputBasePath = extras.Count > 1 ? extras[1] : "res_unpack";

            List <string> files = Directory.GetFiles(extras[0], "*.*",
                                                     SearchOption.AllDirectories).Where(s => s.EndsWith(".toc", StringComparison.OrdinalIgnoreCase)).ToList();

            for (int i = 0; i < files.Count; i++)
            {
                var    inputPath = files[i];
                string superbundleName;
                var    dataBasePath = Discovery.FindBasePath(inputPath, out superbundleName);
                if (string.IsNullOrEmpty(dataBasePath) == true)
                {
                    Logger.Error("Failed to discover base game path.");
                    continue;
                }
                Console.WriteLine("----- " + (i + 1) + " of " + files.Count + " - " + Path.GetFileName(inputPath) + " ----");
                Thread.Sleep(1000);
                var dataManager = DataManager.Initialize(dataBasePath, noPatch);
                if (dataManager == null)
                {
                    Logger.Fatal("Could not initialize superbundle manager.");
                    continue;
                }

                var extensionsById = ResourceTypes.GetExtensions();

                VfsFormats.SuperbundleFile superbundle = null;
                try
                {
                    superbundle = dataManager.MountSuperbundle(superbundleName);
                }
                catch
                {
                    superbundle = null;
                }
                if (superbundle == null)
                {
                    continue;
                }

                foreach (var resourceInfo in superbundle.Bundles
                         .Where(bi => bi.Resources != null)
                         .SelectMany(bi => bi.Resources)
                         .OrderBy(bi => bi.Name))
                {
                    using (var data = new MemoryStream())
                    {
                        Logger.Info(resourceInfo.Name);

                        if (noCatch == true)
                        {
                            dataManager.LoadData(resourceInfo, data);
                            data.Position = 0;
                        }
                        else
                        {
                            try
                            {
                                dataManager.LoadData(resourceInfo, data);
                                data.Position = 0;
                            }
                            catch (ChunkCryptoKeyMissingException e)
                            {
                                Logger.Warn("Cannot decrypt '{0}' without crypto key '{1}'.",
                                            resourceInfo.Name,
                                            e.KeyId);
                                continue;
                            }
                            catch (Exception e)
                            {
                                Logger.Warn(e, "Exception while loading '{0}':", resourceInfo.Name);
                                continue;
                            }
                        }

                        if (resourceInfo.ResourceType != ResourceTypes.Texture)
                        {
                            continue;
                        }

                        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);
                        }

                        outputPath = Path.Combine(outputBasePath, outputName + ".dds");
                        Console.WriteLine(outputPath);
                        ConvertTexture(data, outputPath, dataManager);
                    }
                }

                dataManager.Dispose();
            }
        }