Beispiel #1
0
        static void BuildParseSwitches(string switches,
                                       out Collections.BitVector32 options,
                                       out Collections.BitVector32 builderOptions)
        {
            options        = new Collections.BitVector32();
            builderOptions = new Collections.BitVector32();
            bool dump_dbg_info = false, is_32bit = false, encrypt = false;

            if (switches == null)
            {
                switches = "";
            }

            int index = 0;

            ParseSwitch(switches, index++, ref dump_dbg_info);
            ParseSwitch(switches, index++, ref is_32bit);
            ParseSwitch(switches, index++, ref encrypt);

            if (encrypt)
            {
                Console.WriteLine("Era:Builder: Switch enabled - {0}", "ERA will be encrypted before saved to disk");
                builderOptions.Set(KSoft.Phoenix.Resource.EraFileBuilderOptions.Encrypt);
            }

            if (!is_32bit)
            {
                Console.WriteLine("Era:Builder: Treating ERA as 64-bit (Definitive Edition)");
                options.Set(KSoft.Phoenix.Resource.EraFileUtilOptions.x64);
            }
            else
            {
                Console.WriteLine("Era:Builder: Switch enabled - {0}", "Treat ERA as 32-bit (Xbox360)");
            }
            if (dump_dbg_info)
            {
                Console.WriteLine("Era:Builder: Switch enabled - {0}", "Dump debug info");
                options.Set(KSoft.Phoenix.Resource.EraFileUtilOptions.DumpDebugInfo);
            }
        }
        void Build(string path, string listingName, string outputPath)
        {
            if (string.IsNullOrWhiteSpace(outputPath))
            {
                outputPath = path;
            }

            var builderOptions = new Collections.BitVector32();
            {
                if (mBuildFlagAlwaysUseXmlOverXmb)
                {
                    Console.WriteLine("PKG:Builder: Switch enabled - {0}", "Use XML over XMB");
                    builderOptions.Set(KSoft.Phoenix.Resource.PKG.CaPackageFileBuilderOptions.AlwaysUseXmlOverXmb);
                }
            }

            StreamWriter debug_output = false            //options.Test(KSoft.Phoenix.Resource.EraFileUtilOptions.DumpDebugInfo)
                                ? new StreamWriter("debug_builder.txt")
                                : null;

            string listing_path = Path.Combine(path, listingName) + KSoft.Phoenix.Resource.EraFileBuilder.kNameExtension;

            using (var builder = new KSoft.Phoenix.Resource.PKG.CaPackageFileBuilder(listing_path))
            {
                builder.BuilderOptions = builderOptions;
                builder.ProgressOutput = Console.Out;
                builder.VerboseOutput  = Console.Out;
                builder.DebugOutput    = debug_output;

                if (builder.Read())
                {
#if false // #TODO
                    if (builder.Build(path, listingName, outputPath))
                    {
                        builder.ProgressOutput.WriteLine("Success!");
                    }
                    else
#endif
                    builder.ProgressOutput.WriteLine("Failed!");
                }
            }

            if (debug_output != null)
            {
                debug_output.Close();
            }
        }
        static void ExpandParseSwitches(string switches,
                                        out Collections.BitVector32 options,
                                        out Collections.BitVector32 expanderOptions)
        {
            options         = new Collections.BitVector32();
            expanderOptions = new Collections.BitVector32();
            bool only_dump_listing = false, dont_overwrite = false, dont_trans_xmb = false, decompress_ui_files = false,
                 trans_gfx = false, is_32bit = false, decrypt = false, dont_load_into_memory = false,
                 skip_verification = false, dump_dbg_info = false, dont_remove_xml_xmb = false;

            if (switches == null)
            {
                switches = "";
            }

            int index = 0;

            ParseSwitch(switches, index++, ref only_dump_listing);
            ParseSwitch(switches, index++, ref dont_overwrite);
            ParseSwitch(switches, index++, ref dont_trans_xmb);
            ParseSwitch(switches, index++, ref decompress_ui_files);
            ParseSwitch(switches, index++, ref trans_gfx);
            ParseSwitch(switches, index++, ref is_32bit);
            ParseSwitch(switches, index++, ref skip_verification);
            ParseSwitch(switches, index++, ref decrypt);
            ParseSwitch(switches, index++, ref dont_load_into_memory);
            ParseSwitch(switches, index++, ref dump_dbg_info);
            ParseSwitch(switches, index++, ref dont_remove_xml_xmb);

            if (only_dump_listing)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Only dumping listing file");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.OnlyDumpListing);
            }
            if (dont_overwrite)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Not overwriting existing files");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.DontOverwriteExistingFiles);
            }
            if (dont_trans_xmb)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Not translating XMB files");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.DontTranslateXmbFiles);
            }
            if (decompress_ui_files)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Decompressing Scaleform data");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.DecompressUIFiles);
            }
            if (trans_gfx)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Translate GFX files to SWF");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.TranslateGfxFiles);
            }
            if (decrypt)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "ERA will be loaded into memory and decrypted in place");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.Decrypt);
                dont_load_into_memory = false;
            }
            if (dont_load_into_memory)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Not loading entire ERA into memory");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.DontLoadEntireEraIntoMemory);
            }
            if (dont_remove_xml_xmb)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Not skipping XML or XMB counterparts");
                expanderOptions.Set(KSoft.Phoenix.Resource.EraFileExpanderOptions.DontRemoveXmlOrXmbFiles);
            }

            if (!is_32bit)
            {
                Console.WriteLine("Era:Expander: Treating ERA as 64-bit (Definitive Edition)");
                options.Set(KSoft.Phoenix.Resource.EraFileUtilOptions.x64);
            }
            else
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Treat ERA as 32-bit (Xbox360)");
            }

            if (skip_verification)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Skip verification");
                options.Set(KSoft.Phoenix.Resource.EraFileUtilOptions.SkipVerification);
            }
            if (dump_dbg_info)
            {
                Console.WriteLine("Era:Expander: Switch enabled - {0}", "Dump debug info");
                options.Set(KSoft.Phoenix.Resource.EraFileUtilOptions.DumpDebugInfo);
            }
        }
 public XmbFileBuilder()
 {
     BuilderOptions.Set(XmbFileBuilderOptions.AllowUnicode);
 }
        public void EraFile_ExpandAndBuildTest()
        {
            const string k_input_era =
                kEraCryptInputDir
                + kEraExpanderFileName
                + EraFileUtil.kExtensionEncrypted
            ;
            string       k_listing_path = System.IO.Path.Combine(kEraExpanderOutputDir, kEraExpanderFileName);
            const string k_rebuilt_name = kEraCryptTestFileName + "_rebuilt";
            const string k_rebuilt_era  =
                kEraCryptInputDir
                + k_rebuilt_name
                + EraFileUtil.kExtensionEncrypted
            ;

            bool result = false;

            #region Expand
            var expand = false;
            if (expand)
            {
                using (var expander = new EraFileExpander(k_input_era))
                {
                    expander.Options         = kEraUtilTestOptions;
                    expander.ExpanderOptions = kEraExpanderTestOptions
                                               //.Set(EraFileExpanderOptions.DontTranslateXmbFiles)
                                               .Set(EraFileExpanderOptions.Decrypt);
                    expander.ProgressOutput = Console.Out;
                    expander.VerboseOutput  = Console.Out;

                    result = expander.Read();
                    Assert.IsTrue(result, "Read failed");

                    result = expander.ExpandTo(kEraExpanderOutputDir, kEraExpanderFileName);
                    Assert.IsTrue(result, "Expansion failed");
                }
            }
            #endregion
            #region Build
            using (var builder = new EraFileBuilder(k_listing_path))
            {
                builder.Options        = kEraUtilTestOptions;
                builder.BuilderOptions = kEraBuilderTestOptions
                                         .Set(EraFileBuilderOptions.Encrypt);
                builder.ProgressOutput = Console.Out;
                builder.VerboseOutput  = Console.Out;

                result = builder.Read();
                Assert.IsTrue(result, "Read listing failed");

                result = builder.Build(kEraExpanderOutputDir, k_rebuilt_name, kEraBuilderOutputDir);
                Assert.IsTrue(result, "Build failed");
            }
            #endregion
            #region Verify
            using (var expander = new EraFileExpander(k_rebuilt_era))
            {
                expander.Options         = kEraUtilTestOptions;
                expander.ExpanderOptions = kEraExpanderTestOptions
                                           .Set(EraFileExpanderOptions.DontTranslateXmbFiles)
                                           .Set(EraFileExpanderOptions.Decrypt);
                expander.ProgressOutput = Console.Out;
                expander.VerboseOutput  = Console.Out;

                result = expander.Read();
                Assert.IsTrue(result, "Re-Read failed");

                //result = expander.ExpandTo(kTestResultsPath + @"assets2\", k_rebuilt_name);
                //Assert.IsTrue(result, "Re-Expansion failed");
            }
            #endregion
        }