public static void UpdateXml(Arrangement arr, DLCPackageData info)
        {
            // update xml with user modified DLCPackageData info
            var songXml = Song2014.LoadFromFile(arr.SongXml.File);
            arr.SongFile = new RocksmithToolkitLib.DLCPackage.AggregateGraph.SongFile { File = "" };
            arr.Id = IdGenerator.Guid();
            arr.MasterId = RandomGenerator.NextInt();

            songXml.AlbumName = info.SongInfo.Album;
            songXml.AlbumYear = info.SongInfo.SongYear.ToString();
            songXml.ArtistName = info.SongInfo.Artist;
            songXml.ArtistNameSort = info.SongInfo.ArtistSort;
            songXml.AverageTempo = info.SongInfo.AverageTempo;
            songXml.Title = info.SongInfo.SongDisplayName;
            songXml.ToneBase = arr.ToneBase;
            songXml.ToneA = arr.ToneA;
            songXml.ToneB = arr.ToneB;
            songXml.ToneC = arr.ToneC;
            songXml.ToneD = arr.ToneD;

            File.Delete(arr.SongXml.File);
            using (var stream = File.OpenWrite(arr.SongXml.File))
            {
                songXml.Serialize(stream, true);
            }
        }
        public static void RemoveDifficulty(string filename, int overlap = -1)
        {
            var data = new DLCPackageData(filename);

            foreach (var arrangement in data.Arrangements)
            {
                RemoveDifficulty(arrangement.Sng2014, overlap);
            }
            DLCPackageCreator.Generate(data);
        }
        private static DLCPackageData ConvertAlbumArt(string cdlcFilePath, DLCPackageData info)
        {
            var unpackedDirPath = Path.Combine(Path.GetDirectoryName(cdlcFilePath), String.Format("{0}_Pc", Path.GetFileNameWithoutExtension(cdlcFilePath)));
            //D:\Temp\Test\RS001SONG0000005_Pc\MoreThanAFeeling\GRAssets\AlbumArt
            // iterate through unpacked cdlc folder and find artwork
            var ddsFilesPath = Directory.GetFiles(unpackedDirPath, "*.dds", SearchOption.AllDirectories);

            if (!ddsFilesPath.Any())
            {
                Console.WriteLine(@"Using default album artwork");
                Console.ReadLine();
                return info;
            }

            try
            {
                var albumArtPath = ddsFilesPath[0];
                Console.WriteLine(@"Converting album artwork using: " + Path.GetFileName(albumArtPath));
                var ddsFiles = new List<DDSConvertedFile>();

                ddsFiles.Add(new DDSConvertedFile() { sizeX = 64, sizeY = 64, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                ddsFiles.Add(new DDSConvertedFile() { sizeX = 128, sizeY = 128, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                ddsFiles.Add(new DDSConvertedFile() { sizeX = 256, sizeY = 256, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });

                // Convert to correct dds file sizes
                DLCPackageCreator.ToDDS(ddsFiles);

                var albumArtDir = Path.GetDirectoryName(albumArtPath);
                var albumArtName = String.Format("album_{0}", info.Name.ToLower().Replace("_", "").GetValidName());
                var ddsPartialPath = Path.Combine(albumArtDir, albumArtName);

                foreach (var dds in ddsFiles)
                {
                    var destAlbumArtPath = String.Format("{0}_{1}.dds", ddsPartialPath, dds.sizeX);
                    if (!File.Exists(dds.destinationFile))
                        Console.WriteLine(@"Could not convert: " + destAlbumArtPath);

                    File.Copy(dds.destinationFile, destAlbumArtPath);
                    // delete temp artwork file
                    File.Delete(dds.destinationFile);
                    dds.destinationFile = destAlbumArtPath;
                }

                // update package info with album art files
                info.ArtFiles = ddsFiles;
            }
            catch (Exception ex)
            {
                Console.WriteLine(@"Could not convert album artwork in " + Path.GetFileName(cdlcFilePath) + @": " + ex.Message);
            }

            return info;
        }
Exemplo n.º 4
0
        private static void ConvertPackageRebuilding(string unpackedDir, string targetFileName, Platform targetPlatform, string appId)
        {
            var data = DLCPackageData.LoadFromFile(unpackedDir, targetPlatform);

            if (!targetPlatform.IsConsole)
            {
                data.AppId = appId;
            }

            //Build
            RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(targetFileName, data, new Platform(targetPlatform.platform, GameVersion.RS2014));
        }
        public void WritePackage(string destPath, DLCPackageData packageData, string srcPath = "")
        {
            // if the srcPath does not exist GetPlatform returns 'None'
            // this generates an error condition so need to check platform of srcPath
            Platform platform;
            if (String.IsNullOrEmpty(srcPath))
                platform = destPath.GetPlatform();
            else
                platform = srcPath.GetPlatform();

            DLCPackageCreator.Generate(destPath, packageData, platform);
        }
        private static void ConvertPackageRebuilding(string unpackedDir, string targetFileName, Platform sourcePlatform, Platform targetPlatform, string appId)
        {
            var data = DLCPackageData.LoadFromFolder(unpackedDir, targetPlatform, sourcePlatform);

            // Update AppID
            if (!targetPlatform.IsConsole)
            {
                data.AppId = appId;
            }

            // Build
            DLCPackageCreator.Generate(targetFileName, data, new Platform(targetPlatform.platform, GameVersion.RS2014));
        }
 private static void FixPaths(DLCPackageData info, string templateDir, GameVersion gameVersion)
 {
     foreach (var arr in info.Arrangements) {
         arr.SongXml.File = Path.Combine(Path.GetDirectoryName(templateDir), arr.SongXml.File);
         if (gameVersion == GameVersion.RS2014)
             UpdateTones(arr);
     }
     info.AlbumArtPath = Path.Combine(Path.GetDirectoryName(templateDir), info.AlbumArtPath);
     if (!String.IsNullOrEmpty(info.OggPath))
         info.OggPath = Path.Combine(Path.GetDirectoryName(templateDir), info.OggPath);
     if (!String.IsNullOrEmpty(info.OggPreviewPath))
         info.OggPreviewPath = Path.Combine(Path.GetDirectoryName(templateDir), info.OggPreviewPath);
 }
 public static bool LevelsAreAllStrictSubset(DLCPackageData package)
 {
     //foreach (var arrangement in package.Arrangements)
         //{
         //    if (arrangement.Sng2014.Vocals.Count > 0)
         //        continue;
         //    foreach (var pi in arrangement.Sng2014.Phrases.Phrases)
         //    {
         //        foreach (var l in pi.)
         //    }
         //}
       return false;
 }
        public static void BuildXBox360Package(string songFileName, DLCPackageData info, IEnumerable<string> xboxFiles, GameVersion gameVersion, DLCPackageType dlcType = DLCPackageType.Song)
        {
            LogRecord x = new LogRecord();
            RSAParams xboxRSA = info.SignatureType == PackageMagic.CON ? new RSAParams(new DJsIO(Resources.XBox360_KV, true)) : new RSAParams(StrongSigned.LIVE);
            CreateSTFS xboxSTFS = new CreateSTFS();
            xboxSTFS.HeaderData = info.GetSTFSHeader(gameVersion, dlcType);
            foreach (string file in xboxFiles)
                xboxSTFS.AddFile(file, Path.GetFileName(file));

            STFSPackage xboxPackage = new STFSPackage(xboxSTFS, xboxRSA, songFileName, x);
            var generated = xboxPackage.RebuildPackage(xboxRSA);
            if (!generated)
                throw new InvalidOperationException("Error on create XBox360 package, details: \n" + x.Log);

            xboxPackage.FlushPackage(xboxRSA);
            xboxPackage.CloseIO();

            DirectoryExtension.SafeDelete(XBOX_WORKDIR);
        }
        /// <summary>
        /// Fixes missing and updates showlights to current standards
        /// </summary>
        private static void UpdateShowlights(string songDirectory, Platform targetPlatform)
        {
            bool hasShowlights = true;
            // TODO: provide some pb feedback for long process
            var info              = DLCPackageData.LoadFromFolder(songDirectory, targetPlatform);
            var showlightsArr     = info.Arrangements.Where(x => x.ArrangementType == ArrangementType.ShowLight).FirstOrDefault();
            var showlightFilePath = showlightsArr.SongXml.File;

            if (String.IsNullOrEmpty(showlightFilePath))
            {
                var xmlFilePath = info.Arrangements[0].SongXml.File;
                var xmlName     = Path.GetFileNameWithoutExtension(xmlFilePath);
                showlightFilePath = Path.Combine(Path.GetDirectoryName(xmlFilePath), xmlName.Split('_')[0] + "_showlights.xml");
                hasShowlights     = false;
            }

            // Generate Showlights
            var showlight = new Showlights();

            showlight.CreateShowlights(info);
            // need at least two showlight elements to be valid
            if (showlight.ShowlightList.Count > 1)
            {
                var showlightStream = new MemoryStream();
                showlight.Serialize(showlightStream);

                using (FileStream file = new FileStream(showlightFilePath, FileMode.Create, FileAccess.Write))
                    showlightStream.WriteTo(file);

                // write xml comments
                Song2014.WriteXmlComments(showlightFilePath);
            }
            else
            {
                // insufficient showlight changes may crash game
                throw new InvalidOperationException("Detected insufficient showlight changes: " + showlight.ShowlightList.Count);
            }

            if (!hasShowlights)
            {
                UpdateAggegrateGraph(songDirectory, targetPlatform, info);
            }
        }
        public DLCPackageData ReadPackage(string inputPath, bool ignoreMultitoneEx = false)
        {
            // UNPACK
            packageDir = Packer.Unpack(inputPath, Path.GetTempPath(), true);

            // REORGANIZE
            packageDir = DLCPackageData.DoLikeProject(packageDir);

            // LOAD DATA
            DLCPackageData info = new DLCPackageData();
            var packagePlatform = inputPath.GetPlatform();
            info = DLCPackageData.LoadFromFolder(packageDir, packagePlatform, packagePlatform, ignoreMultitoneEx);
            var foundShowlights = Directory.EnumerateFiles(packageDir, "*_showlights.xml", SearchOption.AllDirectories).Any();

            // toolkit will generate showlights if none was found
            if (!foundShowlights)
                info.Showlights = true;

            return info;
        }
        public InlayNif(DLCPackageData info)
        {
            string nFileName, n1, n2, n2a, n2b;

            // CRITICAL - naming dependencies
            nFileName = String.Format("inlay_{0}.dds", info.Inlay.DLCSixName);

            // HEX strings to make the nif file
            if (info.Inlay.Frets24)
            {
                if (info.Inlay.Colored)
                {
                    n1 = "47616D656272796F2046696C6520466F726D61742C2056657273696F6E2033302E312E302E330A0300011E01000000006D000000000000000B00110000004E694461746153747265616D0131013138110000004E694461746153747265616D0130013138120000004E694D6174657269616C50726F7065727479060000004E694D657368110000004E69537472696E67457874726144617461150000004E69566572746578436F6C6F7250726F70657274790F0000004E69416C70686150726F70657274790F0000004E69536F7572636554657874757265130000004E69546578747572696E6750726F7065727479110000004E695A42756666657250726F7065727479060000004E694E6F64650000010002000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010002000500060007000800090004000300050009000A00710000002900000044000000B4000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC0000007100000029000000440000000E0000000F00000024000000280000000E00000008000000BC0000000E0000000E000000BE00000022000000170000000A0000005363656E6520526F6F7408000000696E6C61795F32300E0000005573657250726F704275666665720B0000000D0A7A4D6F646531300D0A17000000";
                    n2a = "05000000696E6C617905000000494E44455808000000504F534954494F4E08000000544558434F4F524407000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F303008000000696E6C61795F30300E0000006D6174657269616C686F6C64657209000000686967686C69676874000000005000000000000000010000000000000004000000020000003704030036040200E43615BFA0843A3F000000000000000000000000E43615BFA0843ABF00000000000000000000803FE436153FA0843A3F000000000000803F00000000E436153FA0843ABF000000000000803F0000803F010C000000000000000100000000000000060000000100000015020100030002000100000001000200012100000000000000FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000803F0000803F0000803F000020413333B33E2000000000000000FFFFFFFF100000000000A2203E4251C79AC1000000B400000080FFFF7FBF000000000000803F00000000FFFF7F3F00000000000000B40000803F0400000002000000660000006400000063000000FFFFFFFF00000000FFFFFFFF000000000001000000000000000000000000000012DC6E3F0200000001000000000100000001000000060000000000000000000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402002D0FD2C28AB224C030BA4D37ED427F3F71CE5C3F2D0FD2C294B22440663A5037EE427F3F9E820C3F6E35CDC2ED678240043C4B37BE46733F3E29EA3E6D35CDC2EB6782C00A3C4B37B746733F703C743F010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000001F0000000100000006000000FFFFFFFF1000CC7F51B7B8C850C261865ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100004DA2CFC20000003535BB4D37990E88400200000005000000000100000001000000060000000000000004000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402006857C6C2A9CB50C036C543371A185E3F5F8E673FFD6DCCC2A9CB50C025D24937F259713F5F8E673FFE6DCCC2E7783D40F26C4B37F259713F8E78063F6957C6C2E7783D40056045371A185E3F8E78063F010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000001E000000010000000A000000FFFFFFFF1000BC8A4BB7B8C850C229875ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000B362C9C210961ABE14994737D7AE5D40020000000900000000010000000100000006000000000000000800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BC75BFC29FAD3BC0C2A83C3719304E3F8C68623FF88FC5C2EB6782C04AAC43374F2B5C3F703C743FF98FC5C2ED67824045AC43374F2B5C3F3E29EA3EBD75BFC2A2C42D4036BE3E3719304E3F924C0A3F010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000001D000000010000000E000000FFFFFFFF100030B044B7B8C850C205885ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000DA82C2C200000035862A4037AA3E8B40020000000D00000000010000000100000006000000000000000C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200D856B8C2EB6782C0C1893637EB263E3F703C743F4CAEBEC29FAD3BC0A8E23B374F434C3F8C68623F4DAEBEC2A2C42D4019F83D3754434C3F924C0A3FD956B8C209256C40E4DB3637EF263E3FF42FF63E010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000001C0000000100000012000000FFFFFFFF10005BC93CB7B8C850C29C7421BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100009282BBC2685645BEED403A37C6328640020000001100000000010000000100000006000000000000001000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200716AA9C2EB6782C060B82737481E1C3F5BDB753F973CB0C2957645C009AB2D3791DE2B3FEAC9643F983CB0C2726A754047B12E3769342C3F9296F13E726AA9C2ED67824060B827374D1E1C3F1467ED3E010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000001B0000000100000016000000FFFFFFFF100067742EB7B8C850C2BB8A5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000084D3ACC200000035D4342B37BC5C8D400200000015000000000100000001000000060000000000000014000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402008EDBA1C2EB6782C049382037C8B70A3F703C743F01A3A8C2EB6782C06CF226371F531A3F5BDB753F02A3A8C2ED6782406CF2263725531A3F1467ED3E8FDBA1C2ED67824049382037C8B70A3F3E29EA3E010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000001A000000010000001A000000FFFFFFFF10009C2727B7B8C850C2AD8B5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000483FA5C2000000355A952337CB3B8D400200000019000000000100000001000000060000000000000018000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402002DF799C2EB6782C0AF631837EB18F13E703C743F1E14A1C2EB6782C065721F37A1EC083F703C743F1F14A1C2ED67824065721F37A3EC083F3E29EA3E2EF799C2A8BF644077CE1837EB18F13E0CCBF93E010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000019000000010000001E000000FFFFFFFF100021431FB7B8C850C2A48C5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000A6859DC2000000350AEB1B37E5478E40020000001D00000000010000000100000006000000000000001C000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402001E1A92C2EB6782C060971037F0E3CC3E703C743FBD2F99C2EB6782C0DC9D17379B82ED3E703C743FBE2F99C2A8BF6440A50818379B82ED3E0CCBF93E1E1A92C2ED67824060971037F0E3CC3E3E29EA3E010C000000000000000100000000000000060000000100000015020100000001000200020003000000010200000003000000180000000100000022000000FFFFFFFF1000E6C516B7B8C850C2A08D5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000EEA495C2000000350250143783308E40020000002100000000010000000100000006000000000000002000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200C6D489C2EB6782C0E4630837D0CEA63E703C743FAE5291C2EB6782C09DD10F37A54DC93E703C743FAE5291C2ED6782409ED10F37A54DC93E3E29EA3EC6D489C2ED678240E6630837D0CEA63E3E29EA3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000170000000100000026000000FFFFFFFF1000F5290FB7B8C850C2A38E5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000BA938DC200000035C11A0C3702858F40020000002500000000010000000100000006000000000000002400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200B88581C2075E73C068DBFF36FB8C803ED0FB6F3F560D89C2EB6782C0319E07378538A33E703C743F560D89C2ED678240339E07378538A33E3E29EA3EB88581C2FEB97640B6560037FB8C803E3C07F13E010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000016000000010000002A000000FFFFFFFF1000ECE906B7B8C850C2AC8F5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000874985C200000035F4C5033784A58F40020000002900000000010000000100000006000000000000002800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE0372C2EB6782C04E70EF361CB0323E703C743F48BE80C2075E73C02C50FE365EED793ED0FB6F3F48BE80C2FEB976403022FF365EED793E3C07F13EC00372C2ED6782405170EF361CB0323E3E29EA3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000015000000010000002E000000FFFFFFFF1000302CFCB6B8C850C2B9905ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000027C079C2000000353F49F7369E589040020000002D00000000010000000100000006000000000000002C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200FC9160C21F2276C0C0C7DD36CEBBC43D6DA8703FE07470C2EB6782C036E5ED3694832B3E703C743FE27470C2ED67824039E5ED3694832B3E3E29EA3EFE9160C2C98D7440D295DE36EDBBC43D6816F23E010C000000000000000100000000000000060000000100000015020100000001000200020003000000010200000003000000140000000100000032000000FFFFFFFF10008441EBB6B8C850C2CD915ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100006F8368C2000000357CD6E536841091400200000031000000000100000001000000060000000000000030000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402008F854EC2EB6782C0D54ACC36B738743C703C743F1E035FC2212276C0C73CDC36BD62B63D6DA8703F20035FC2C78D7440DB0ADD36CD62B63D6816F23E92854EC2F56068403B08CD36E539743CFA05F83E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000130000000100000036000000FFFFFFFF1000290FD9B6B8C850C24019FABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000058C456C2781002BED8AAD43631868E40020000003500000000010000000100000006000000000000003400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE1E3CC2EB6782C0A514BA36CCC5683F8A6AF53EB1F64CC2EB6782C001C0CA3628ED7C3F8A6AF53EB4F64CC2F5606840657DCB362DED7C3F706E053DC21E3CC2ED678240A914BA36D1C5683F007BDF3B010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000012000000010000003A000000FFFFFFFF10006E79C6B6B8C850C20C945ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000B98A44C20000003505C9C2363FC89240020000003900000000010000000100000006000000000000003800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200873A29C2EB6782C02E64A736282B523F8A6AF53EE08F3AC2C0624BC07A0BB7368CE8663F50C8DA3EE48F3AC2A24F794099D6B83691E8663FC0368D3C8B3A29C2A24F7940CDB0A7362B2B523FC0368D3C010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000011000000010000003E000000FFFFFFFF1000F7B1B3B6B8C850C290E6D0BC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000036E531C24003B8BD641DB036D3289140020000003D00000000010000000100000006000000000000003C0000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020041CC15C23E885FC0A734933650EB3A3F4E20E43EA9AB27C2EB6782C0A9D9A536E54D503F8A6AF53EADAB27C2EB166F405D6AA636EB4D503F8010D93C44CC15C2B078664011F7943652EB3A3F10820C3D010C000000000000000100000000000000060000000100000015020100000001000200020003000000010200000003000000100000000100000042000000FFFFFFFF10003596A0B6B8C850C248B714BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000F7BB1EC258C72DBE82CF9C367CFA8F400200000041000000000100000001000000060000000000000040000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402005E8201C2EB6782C0B01D8036B4A4223F8A6AF53E633D14C23E885FC03FAA9136100E393F4E20E43E663D14C2B0786640AA6C9336B9793A3FE0D4063D618201C274AC6C407BBE8036B6A4223FE0FDEA3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000F0000000100000046000000FFFFFFFF1000F6038CB6B8C850C2E02D1FBD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000E2DF0AC2101B41BE2DC58936EE319140020000004500000000010000000100000006000000000000004400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200EF68DAC1EB6782C0141C58364B590A3F8A6AF53E00E7FFC188E147C03CFB793673C7203F3028D93E06E7FFC174AC6C4083687E3677C7203FE0FDEA3CF368DAC1ED6782401A1C58364E590A3F007BDF3B010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000E000000010000004A000000FFFFFFFF10003E326EB6B8C850C2EC985ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000FA27EDC1000000354C426B36786D964002000000490000000001000000010000000600000000000000480000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020077C6AFC16F2355C038832B3629AFE13E404EDF3E334BD7C16D2355C0E68C52360A7C083F404EDF3E374BD7C1472E68406A8556360C7C083F802A063D7AC6AFC1452E6840BC7B2F3629AFE13E802A063D010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000D000000010000004E000000FFFFFFFF10009BBC45B6B8C850C2A07FDE3B000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000D788C3C1C056183E5104413661888840020000004D00000000010000000100000006000000000000004C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E4E083C131742BC0DBFEFB351F29AD3E06F9CB3EBBA8ACC131742BC00A442636A5F4DD3E06F9CB3EBEA8ACC186136A409C4E2C36AAF4DD3E2044FE3CE8E083C186136A40FB0904362829AD3E2044FE3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000C0000000100000052000000FFFFFFFF10008C1B1AB6B8C850C2F088583D000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000D14498C1547DFA3E05271536301E8240020000005100000000010000000100000006000000000000005000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E61B2DC178F85CC072ACA735DEDB6D3E2AF0E23E28C380C178F85CC004FFFA359E6EA93E2AF0E23E2CC380C12CAA3440F3BD0336A46EA93E50A7A23DE81B2DC19CDC4E40536FB135DEDB6D3E901B643D010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000B0000000100000056000000FFFFFFFF10003A83D8B5B8C850C20481E7BC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100001F5157C1C0BDE1BD2C94D735E04188400200000055000000000100000001000000060000000000000054000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402009A57A3C03C8C5EC0E54A1B358173003E6EABE33E6EE026C14CD067C016A7A235D566663E92F7E73E6EE026C19CDC4E401349";
                    n2b = "AB35D566663E901B643D9A57A3C0DE7E2940C34336358173003ED05FB73D010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000000A000000010000005A000000FFFFFFFF1000D4EE7DB5B8C850C2A0B522BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100003B8CF8C0809D47BE86EE7835E8E08A40020000005900000000010000000100000006000000000000005800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200927EA63F3E8C5EC080DEFEB2F67EBA3B6EABE33EA8E096C03C8C5EC0E6371035E2FCF13D6EABE33EA8E096C0DE7E2940C4302B35E2FCF13DD05FB73D907EA63F07E92B40F2099433FD7EBA3B00E5B23D010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000009000000010000005E000000FFFFFFFF1000D09F0EB4B8C850C2B8F888BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100000782DABFDC8CCABED039A334F2CC8940020000005D00000000010000000100000006000000000000005C000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402000704B1C2967645C0AB222E376E9D2D3F2ECB643F688FB7C2EC6782C0285C3537223A3C3F703C743F698FB7C208256C4093733637223A3C3FF42FF63E0804B1C2716A7540B8D82F37739D2D3FD2AAF13E010C000000000000000100000000000000060000000100000015020100000001000200020003000000010500000000000000FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000803F0000803F0000803F000020410000803FFFFFFFFF00000000FFFFFFFF0000FFFFFFFF00000000FFFFFFFFED1000FFFFFFFF00000000FFFFFFFF0104000000FFFFFFFF060000000100000003000000010000FFFFFFFF00000000FFFFFFFF04000900000001650000000032010000000000000000000000000000FFFFFFFF00000000FFFFFFFF0D000200000003000000010000000100000068000000FFFFFFFF10007D1136B7B8C850C2D4A3F2BC000080B400000000000080BF000080BF0000000000008034000000000000803F000000000000803F050000006200000063000000640000006600000067000000FFFFFFFF00000000FFFFFFFF0000000000010000B849B4C27056F6BD1F4B32377CF5884002000000610000000001000000010000000600000000000000600000000001000000020000000700000000000000080000000000000000000000FFFFFFFF00000000FFFFFFFF0800FFFFFFFF00000000FFFFFFFF0F000000000000000000FFFFFFFF10010000000000000000000000000000803F0000000000000000000000000000803F0000000000000000000000000000803F0000803F020000006A0000006B000000FFFFFFFF19000000690000005F0000005B00000057000000530000004F0000004B00000047000000430000003F0000003B00000037000000330000002F0000002B00000027000000230000001F0000001B00000017000000130000000F0000000B000000070000000300000000000000010000006C000000";
                    n2 = n2a + n2b;
                }
                else
                {
                    n1 = "47616D656272796F2046696C6520466F726D61742C2056657273696F6E2033302E312E302E330A0300011E01000000006D000000000000000B00110000004E694461746153747265616D0131013138110000004E694461746153747265616D0130013138120000004E694D6174657269616C50726F7065727479060000004E694D657368110000004E69537472696E67457874726144617461150000004E69566572746578436F6C6F7250726F70657274790F0000004E69416C70686150726F70657274790F0000004E69536F7572636554657874757265130000004E69546578747572696E6750726F7065727479110000004E695A42756666657250726F7065727479060000004E694E6F64650000010002000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010004000300000001000400030000000100040003000000010002000500060007000800090004000300050009000A00710000002900000044000000B4000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC0000007100000029000000440000000E0000000F00000024000000280000000E00000008000000BC0000000E0000000E000000BE00000022000000170000000A0000005363656E6520526F6F7408000000696E6C61795F32300E0000005573657250726F704275666665720B0000000D0A7A4D6F646531300D0A17000000";
                    n2a = "05000000696E6C617905000000494E44455808000000504F534954494F4E08000000544558434F4F524407000000696E6C61795F3107000000696E6C61795F3207000000696E6C61795F3307000000696E6C61795F3407000000696E6C61795F3507000000696E6C61795F3607000000696E6C61795F3707000000696E6C61795F3807000000696E6C61795F3908000000696E6C61795F313008000000696E6C61795F313108000000696E6C61795F313208000000696E6C61795F313308000000696E6C61795F313408000000696E6C61795F313508000000696E6C61795F313608000000696E6C61795F313708000000696E6C61795F313808000000696E6C61795F313908000000696E6C61795F323108000000696E6C61795F323208000000696E6C61795F323308000000696E6C61795F32340E0000006D6174657269616C686F6C64657209000000686967686C69676874000000005000000000000000010000000000000004000000020000003704030036040200E43615BFA0843A3F000000000000000000000000E43615BFA0843ABF00000000000000000000803FE436153FA0843A3F000000000000803F00000000E436153FA0843ABF000000000000803F0000803F010C000000000000000100000000000000060000000100000015020100030002000100000001000200012100000000000000FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000803F0000803F0000803F000020413333B33E2000000000000000FFFFFFFF100000000000A2203E4251C79AC1000000B400000080FFFF7FBF000000000000803F00000000FFFF7F3F00000000000000B40000803F0400000002000000660000006400000063000000FFFFFFFF00000000FFFFFFFF000000000001000000000000000000000000000012DC6E3F0200000001000000000100000001000000060000000000000000000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402002D0FD2C28AB224C030BA4D37ED427F3F71CE5C3F2D0FD2C294B22440663A5037EE427F3F9E820C3F6E35CDC2ED678240043C4B37BE46733F3E29EA3E6D35CDC2EB6782C00A3C4B37B746733F703C743F010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000001F0000000100000006000000FFFFFFFF1000CC7F51B7B8C850C261865ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100004DA2CFC20000003535BB4D37990E88400200000005000000000100000001000000060000000000000004000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402006857C6C2A9CB50C036C543371A185E3F5F8E673FFD6DCCC2A9CB50C025D24937F259713F5F8E673FFE6DCCC2E7783D40F26C4B37F259713F8E78063F6957C6C2E7783D40056045371A185E3F8E78063F010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000001E000000010000000A000000FFFFFFFF1000BC8A4BB7B8C850C229875ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000B362C9C210961ABE14994737D7AE5D40020000000900000000010000000100000006000000000000000800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BC75BFC29FAD3BC0C2A83C3719304E3F8C68623FF88FC5C2EB6782C04AAC43374F2B5C3F703C743FF98FC5C2ED67824045AC43374F2B5C3F3E29EA3EBD75BFC2A2C42D4036BE3E3719304E3F924C0A3F010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000001D000000010000000E000000FFFFFFFF100030B044B7B8C850C205885ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000DA82C2C200000035862A4037AA3E8B40020000000D00000000010000000100000006000000000000000C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200D856B8C2EB6782C0C1893637EB263E3F703C743F4CAEBEC29FAD3BC0A8E23B374F434C3F8C68623F4DAEBEC2A2C42D4019F83D3754434C3F924C0A3FD956B8C209256C40E4DB3637EF263E3FF42FF63E010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000001C0000000100000012000000FFFFFFFF10005BC93CB7B8C850C29C7421BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100009282BBC2685645BEED403A37C6328640020000001100000000010000000100000006000000000000001000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200716AA9C2EB6782C060B82737481E1C3F5BDB753F973CB0C2957645C009AB2D3791DE2B3FEAC9643F983CB0C2726A754047B12E3769342C3F9296F13E726AA9C2ED67824060B827374D1E1C3F1467ED3E010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000001B0000000100000016000000FFFFFFFF100067742EB7B8C850C2BB8A5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000084D3ACC200000035D4342B37BC5C8D400200000015000000000100000001000000060000000000000014000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402008EDBA1C2EB6782C049382037C8B70A3F703C743F01A3A8C2EB6782C06CF226371F531A3F5BDB753F02A3A8C2ED6782406CF2263725531A3F1467ED3E8FDBA1C2ED67824049382037C8B70A3F3E29EA3E010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000001A000000010000001A000000FFFFFFFF10009C2727B7B8C850C2AD8B5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000483FA5C2000000355A952337CB3B8D400200000019000000000100000001000000060000000000000018000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402002DF799C2EB6782C0AF631837EB18F13E703C743F1E14A1C2EB6782C065721F37A1EC083F703C743F1F14A1C2ED67824065721F37A3EC083F3E29EA3E2EF799C2A8BF644077CE1837EB18F13E0CCBF93E010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000019000000010000001E000000FFFFFFFF100021431FB7B8C850C2A48C5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000A6859DC2000000350AEB1B37E5478E40020000001D00000000010000000100000006000000000000001C000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402001E1A92C2EB6782C060971037F0E3CC3E703C743FBD2F99C2EB6782C0DC9D17379B82ED3E703C743FBE2F99C2A8BF6440A50818379B82ED3E0CCBF93E1E1A92C2ED67824060971037F0E3CC3E3E29EA3E010C000000000000000100000000000000060000000100000015020100000001000200020003000000010200000003000000180000000100000022000000FFFFFFFF1000E6C516B7B8C850C2A08D5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000EEA495C2000000350250143783308E40020000002100000000010000000100000006000000000000002000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200C6D489C2EB6782C0E4630837D0CEA63E703C743FAE5291C2EB6782C09DD10F37A54DC93E703C743FAE5291C2ED6782409ED10F37A54DC93E3E29EA3EC6D489C2ED678240E6630837D0CEA63E3E29EA3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000170000000100000026000000FFFFFFFF1000F5290FB7B8C850C2A38E5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000BA938DC200000035C11A0C3702858F40020000002500000000010000000100000006000000000000002400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200B88581C2075E73C068DBFF36FB8C803ED0FB6F3F560D89C2EB6782C0319E07378538A33E703C743F560D89C2ED678240339E07378538A33E3E29EA3EB88581C2FEB97640B6560037FB8C803E3C07F13E010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000016000000010000002A000000FFFFFFFF1000ECE906B7B8C850C2AC8F5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000874985C200000035F4C5033784A58F40020000002900000000010000000100000006000000000000002800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE0372C2EB6782C04E70EF361CB0323E703C743F48BE80C2075E73C02C50FE365EED793ED0FB6F3F48BE80C2FEB976403022FF365EED793E3C07F13EC00372C2ED6782405170EF361CB0323E3E29EA3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000015000000010000002E000000FFFFFFFF1000302CFCB6B8C850C2B9905ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000027C079C2000000353F49F7369E589040020000002D00000000010000000100000006000000000000002C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200FC9160C21F2276C0C0C7DD36CEBBC43D6DA8703FE07470C2EB6782C036E5ED3694832B3E703C743FE27470C2ED67824039E5ED3694832B3E3E29EA3EFE9160C2C98D7440D295DE36EDBBC43D6816F23E010C000000000000000100000000000000060000000100000015020100000001000200020003000000010200000003000000140000000100000032000000FFFFFFFF10008441EBB6B8C850C2CD915ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100006F8368C2000000357CD6E536841091400200000031000000000100000001000000060000000000000030000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402008F854EC2EB6782C0D54ACC36B738743C703C743F1E035FC2212276C0C73CDC36BD62B63D6DA8703F20035FC2C78D7440DB0ADD36CD62B63D6816F23E92854EC2F56068403B08CD36E539743CFA05F83E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000130000000100000036000000FFFFFFFF1000290FD9B6B8C850C24019FABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000058C456C2781002BED8AAD43631868E40020000003500000000010000000100000006000000000000003400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE1E3CC2EB6782C0A514BA36CCC5683F8A6AF53EB1F64CC2EB6782C001C0CA3628ED7C3F8A6AF53EB4F64CC2F5606840657DCB362DED7C3F706E053DC21E3CC2ED678240A914BA36D1C5683F007BDF3B010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000012000000010000003A000000FFFFFFFF10006E79C6B6B8C850C20C945ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000B98A44C20000003505C9C2363FC89240020000003900000000010000000100000006000000000000003800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200873A29C2EB6782C02E64A736282B523F8A6AF53EE08F3AC2C0624BC07A0BB7368CE8663F50C8DA3EE48F3AC2A24F794099D6B83691E8663FC0368D3C8B3A29C2A24F7940CDB0A7362B2B523FC0368D3C010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000011000000010000003E000000FFFFFFFF1000F7B1B3B6B8C850C290E6D0BC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF000000000001000036E531C24003B8BD641DB036D3289140020000003D00000000010000000100000006000000000000003C0000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020041CC15C23E885FC0A734933650EB3A3F4E20E43EA9AB27C2EB6782C0A9D9A536E54D503F8A6AF53EADAB27C2EB166F405D6AA636EB4D503F8010D93C44CC15C2B078664011F7943652EB3A3F10820C3D010C000000000000000100000000000000060000000100000015020100000001000200020003000000010200000003000000100000000100000042000000FFFFFFFF10003596A0B6B8C850C248B714BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000F7BB1EC258C72DBE82CF9C367CFA8F400200000041000000000100000001000000060000000000000040000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402005E8201C2EB6782C0B01D8036B4A4223F8A6AF53E633D14C23E885FC03FAA9136100E393F4E20E43E663D14C2B0786640AA6C9336B9793A3FE0D4063D618201C274AC6C407BBE8036B6A4223FE0FDEA3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000F0000000100000046000000FFFFFFFF1000F6038CB6B8C850C2E02D1FBD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000E2DF0AC2101B41BE2DC58936EE319140020000004500000000010000000100000006000000000000004400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200EF68DAC1EB6782C0141C58364B590A3F8A6AF53E00E7FFC188E147C03CFB793673C7203F3028D93E06E7FFC174AC6C4083687E3677C7203FE0FDEA3CF368DAC1ED6782401A1C58364E590A3F007BDF3B010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000E000000010000004A000000FFFFFFFF10003E326EB6B8C850C2EC985ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000FA27EDC1000000354C426B36786D964002000000490000000001000000010000000600000000000000480000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020077C6AFC16F2355C038832B3629AFE13E404EDF3E334BD7C16D2355C0E68C52360A7C083F404EDF3E374BD7C1472E68406A8556360C7C083F802A063D7AC6AFC1452E6840BC7B2F3629AFE13E802A063D010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000D000000010000004E000000FFFFFFFF10009BBC45B6B8C850C2A07FDE3B000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000D788C3C1C056183E5104413661888840020000004D00000000010000000100000006000000000000004C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E4E083C131742BC0DBFEFB351F29AD3E06F9CB3EBBA8ACC131742BC00A442636A5F4DD3E06F9CB3EBEA8ACC186136A409C4E2C36AAF4DD3E2044FE3CE8E083C186136A40FB0904362829AD3E2044FE3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000C0000000100000052000000FFFFFFFF10008C1B1AB6B8C850C2F088583D000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF0000000000010000D14498C1547DFA3E05271536301E8240020000005100000000010000000100000006000000000000005000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E61B2DC178F85CC072ACA735DEDB6D3E2AF0E23E28C380C178F85CC004FFFA359E6EA93E2AF0E23E2CC380C12CAA3440F3BD0336A46EA93E50A7A23DE81B2DC19CDC4E40536FB135DEDB6D3E901B643D010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000B0000000100000056000000FFFFFFFF10003A83D8B5B8C850C20481E7BC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100001F5157C1C0BDE1BD2C94D735E04188400200000055000000000100000001000000060000000000000054000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402009A57A3C03C8C5EC0E54A1B358173003E6EABE33E6EE026C14CD067C016A7A235D566663E92F7E73E6EE026C19CDC4E401349";
                    n2b = "AB35D566663E901B643D9A57A3C0DE7E2940C34336358173003ED05FB73D010C0000000000000001000000000000000600000001000000150201000000010002000200030000000102000000030000000A000000010000005A000000FFFFFFFF1000D4EE7DB5B8C850C2A0B522BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100003B8CF8C0809D47BE86EE7835E8E08A40020000005900000000010000000100000006000000000000005800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200927EA63F3E8C5EC080DEFEB2F67EBA3B6EABE33EA8E096C03C8C5EC0E6371035E2FCF13D6EABE33EA8E096C0DE7E2940C4302B35E2FCF13DD05FB73D907EA63F07E92B40F2099433FD7EBA3B00E5B23D010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000009000000010000005E000000FFFFFFFF1000D09F0EB4B8C850C2B8F888BD000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000006600000064000000630000006200000067000000FFFFFFFF00000000FFFFFFFF00000000000100000782DABFDC8CCABED039A334F2CC8940020000005D00000000010000000100000006000000000000005C000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402000704B1C2967645C0AB222E376E9D2D3F2ECB643F688FB7C2EC6782C0285C3537223A3C3F703C743F698FB7C208256C4093733637223A3C3FF42FF63E0804B1C2716A7540B8D82F37739D2D3FD2AAF13E010C000000000000000100000000000000060000000100000015020100000001000200020003000000010500000000000000FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000803F0000803F0000803F000020410000803FFFFFFFFF00000000FFFFFFFF0000FFFFFFFF00000000FFFFFFFFED1000FFFFFFFF00000000FFFFFFFF0104000000FFFFFFFF060000000100000003000000010000FFFFFFFF00000000FFFFFFFF04000900000001650000000032010000000000000000000000000000FFFFFFFF00000000FFFFFFFF0D000200000003000000010000000100000068000000FFFFFFFF10007D1136B7B8C850C2D4A3F2BC000080B400000000000080BF000080BF0000000000008034000000000000803F000000000000803F050000006200000063000000640000006600000067000000FFFFFFFF00000000FFFFFFFF0000000000010000B849B4C27056F6BD1F4B32377CF5884002000000610000000001000000010000000600000000000000600000000001000000020000000700000000000000080000000000000000000000FFFFFFFF00000000FFFFFFFF0800FFFFFFFF00000000FFFFFFFF0F000000000000000000FFFFFFFF10010000000000000000000000000000803F0000000000000000000000000000803F0000000000000000000000000000803F0000803F020000006A0000006B000000FFFFFFFF19000000690000005F0000005B00000057000000530000004F0000004B00000047000000430000003F0000003B00000037000000330000002F0000002B00000027000000230000001F0000001B00000017000000130000000F0000000B000000070000000300000000000000010000006C000000";
                    n2 = n2a + n2b;
                }
            }
            else
            {
                if (!info.Inlay.Colored)
                {
                    n1 = "47616D656272796F2046696C6520466F726D61742C2056657273696F6E2033302E312E302E330A0300011E010000000049000000000000000B00110000004E694461746153747265616D0131013138110000004E694461746153747265616D0130013138110000004E69537472696E67457874726144617461060000004E694D657368120000004E694D6174657269616C50726F7065727479150000004E69566572746578436F6C6F7250726F70657274790F0000004E69416C70686150726F70657274790F0000004E69536F7572636554657874757265130000004E69546578747572696E6750726F7065727479110000004E695A42756666657250726F7065727479060000004E694E6F64650000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010004000500060007000800090002000300050009000A00710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC0000007100000029000000440000000E0000000F00000024000000280000000E00000008000000BC0000000E0000000E0000009A00000018000000100000000A0000005363656E6520526F6F7407000000696E6C61795F330E0000005573657250726F704275666665720B0000000D0A7A4D6F646531300D0A10000000";
                    n2 = "0B0000004D6174657269616C20233205000000494E44455808000000504F534954494F4E08000000544558434F4F524407000000696E6C61795F3407000000696E6C61795F3507000000696E6C61795F3607000000696E6C61795F3707000000696E6C61795F3807000000696E6C61795F3908000000696E6C61795F313008000000696E6C61795F313108000000696E6C61795F313208000000696E6C61795F313308000000696E6C61795F313408000000696E6C61795F313508000000696E6C61795F313608000000696E6C61795F313708000000696E6C61795F31380000000050000000000000000100000000000000040000000200000037040300360402008EDBA1C2D26F80C049382037B18A633FEA6B6F3F01A3A8C2D26F80C06CF22637E7077B3FEA6B6F3F02A3A8C2D36F80406CF22637EB077B3F3A04FB3E8FDBA1C2D36F804049382037B98A633F3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000170000000100000002000000FFFFFFFF10009C2727B7B8C850C2A68B5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000483FA5C2000080345A952337DC6A8B400200000001000000000100000001000000060000000000000000000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402002DF799C2D26F80C0AF6318374532483FEA6B6F3F1E14A1C2D26F80C065721F37A7D7603FEA6B6F3F1F14A1C2D36F804065721F37AFD7603F3A04FB3E2EF799C2D36F8040AF6318374932483F3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000160000000100000006000000FFFFFFFF100021431FB7B8C850C29D8C5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000A6859DC2000080340AEB1B376F7A8C400200000005000000000100000001000000060000000000000004000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402001E1A92C2D26F80C0609710372BF32C3FEA6B6F3FBD2F99C2D26F80C0DC9D17373B7F453FEA6B6F3FBE2F99C2D36F8040DD9D17373B7F453F3A04FB3E1E1A92C2D36F80406097103727F32C3F3A04FB3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000015000000010000000A000000FFFFFFFF1000E64517B7B8C850C29A8D5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000EEA495C2000080349E1A1437C0628C40020000000900000000010000000100000006000000000000000800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200C6D489C2D26F80C0E4630837C34A103FEA6B6F3FAE5291C2D26F80C09DD10F3729402A3FEA6B6F3FAE5291C2D36F80409ED10F3725402A3F3A04FB3EC6D489C2D36F8040E6630837BF4A103F3A04FB3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000014000000010000000E000000FFFFFFFF1000F5290FB7B8C850C29C8E5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000BA938DC200008034C11A0C3794BB8D40020000000D00000000010000000100000006000000000000000C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200B88581C2D26F80C0CD2700376301E73EEA6B6F3F560D89C2D26F80C0319E0737B9970D3FEA6B6F3F560D89C2D36F8040339E0737B7970D3F3A04FB3EB88581C2D36F8040CE2700376001E73E3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000130000000100000012000000FFFFFFFF1000ECE906B7B8C850C2A58F5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000874985C20000803400E303377FDC8D40020000001100000000010000000100000006000000000000001000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE0372C2D26F80C04E70EF3668FFAB3EEA6B6F3F48BE80C2D26F80C05EC4FE364F9BE13EEA6B6F3F48BE80C2D36F804060C4FE364F9BE13E3A04FB3EC00372C2D36F80405170EF3661FFAB3E3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000120000000100000016000000FFFFFFFF1000302CFCB6B8C850C2B2905ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF000000000001000027C079C200008034571AF736D6918E40020000001500000000010000000100000006000000000000001400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200FC9160C2D26F80C08529DE3681D8693E903B6F3FE07470C2D26F80C036E5ED367D6BA73E8E3B6F3FE27470C2D36F804039E5ED36816BA73E82A3FA3EFE9160C2D36F80408929DE368FD8693E82A3FA3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000011000000010000001A000000FFFFFFFF10008441EBB6B8C850C2C6915ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF00000000000100006F8368C2000080345F07E636054C8F400200000019000000000100000001000000060000000000000018000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402008F854EC2D26F80C0D54ACC362E36EE3D903B6F3F1E035FC2D26F80C08D9EDC36C6F05F3E903B6F3F20035FC2D36F8040919EDC36CDF05F3E82A3FA3E92854EC2D36F8040D94ACC365A36EE3D82A3FA3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000010000000010000001E000000FFFFFFFF10004604D9B6B8C850C2E2925ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF000000000001000058C456C200008034B374D43689629040020000001D00000000010000000100000006000000000000001C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE1E3CC2D26F80C0A514BA366CC2073B903B6F3FB1F64CC2D26F80C001C0CA36C666DA3D903B6F3FB4F64CC2D36F804005C0CA36E366DA3D82A3FA3EC21E3CC2D36F8040A914BA36E4C7073B82A3FA3E010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000F0000000100000022000000FFFFFFFF10006E79C6B6B8C850C205945ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000B98A44C200008034556AC2361C099140020000002100000000010000000100000006000000000000002000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200873A29C2D26F80C02E64A7369CE45E3FA2AFEC3EE08F3AC2D26F80C0FA89B83640387D3FA2AFEC3EE48F3AC2D36F8040FE89B83647387D3F40C08D3C8B3A29C2D36F80403264A736A1E45E3F40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000E0000000100000026000000FFFFFFFF100043AAB3B6B8C850C230955ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF000000000001000036E531C20000803416F7AF36C6F4914002000000250000000001000000010000000600000000000000240000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020041CC15C2D26F80C0F72C94368DE53C3FA2AFEC3EA9AB27C2D26F80C0A9D9A536BE2A5C3FA2AFEC3EADAB27C2D36F8040ADD9A536C62A5C3F40C08D3C44CC15C2D36F8040FA2C943693E53C3F40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000D000000010000002A000000FFFFFFFF1000A987A0B6B8C850C262965ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000F7BB1EC20000803452039D363BFE92400200000029000000000100000001000000060000000000000028000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402005E8201C2D26F80C0B01D80364366193FA2AFEC3E633D14C2D26F80C08FA29236B02B3A3FA2AFEC3E663D14C2D36F804092A29236B62B3A3F40C08D3C618201C2D36F8040B41D80364566193F40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000C000000010000002E000000FFFFFFFF1000CCF38BB6B8C850C2A0975ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000E2DF0AC2000080342160893634B19440020000002D00000000010000000100000006000000000000002C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200EF68DAC1D26F80C0141C5836E4BFEB3EA2AFEC3E00E7FFC1D26F80C0EE267D3664AC163FA2AFEC3E06E7FFC1D36F8040F5267D366BAC163F40C08D3CF368DAC1D36F80401A1C5836EBBFEB3E40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000B0000000100000032000000FFFFFFFF10003E3270B6B8C850C2E5985ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000FA27EDC10000803484A16A364DB9944002000000310000000001000000010000000600000000000000300000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020077C6AFC1D26F80C04DFE2D36C627A13EA2AFEC3E334BD7C1D26F80C0FC075536294CE63EA2AFEC3E374BD7C1D36F8040010855362F4CE63E40C08D3C7AC6AFC1D36F804052FE2D36C627A13E40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000A0000000100000036000000FFFFFFFF10001CD645B6B8C850C2329A5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000D788C3C10000803427834136B2CE9640020000003500000000010000000100000006000000000000003400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E4E083C1D26F80C0D1A50236AEB4283EA2AFEC3EBBA8ACC1D26F80C06EEA2A3609B49B3EA2AFEC3EBEA8ACC1D36F804073EA2A360FB49B3E40C08D3CE8E083C1D36F8040D2A50236C6B4283E80C08D3C010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000009000000010000003A000000FFFFFFFF10006A6F1AB6B8C850C28C9B5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000D14498C10000803422C8163642259840020000003900000000010000000100000006000000000000003800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E61B2DC1D26F80C0F2D1AB353AB6213CA2AFEC3E28C380C1D26F80C08424FF3540CD1D3EA2AFEC3E2CC380C1D36F80408624FF354CCD1D3E80C08D3CE81B2DC1D36F8040ECD1AB353AB6213C80C08D3C010C000000000000000100000000000000060000000100000015020100020003000000000001000200010500000000000000FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000803F0000803F0000803F000020410000803FFFFFFFFF00000000FFFFFFFF0000FFFFFFFF00000000FFFFFFFFED1000FFFFFFFF00000000FFFFFFFF0104000000FFFFFFFF060000000100000003000000010000FFFFFFFF00000000FFFFFFFF04000900000001410000000032010000000000000000000000000000FFFFFFFF00000000FFFFFFFF0D000200000003000000010000000100000044000000FFFFFFFF1000705DD8B5B8C850C2F19C5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000003E0000003F000000400000004200000043000000FFFFFFFF00000000FFFFFFFF00000000000100001F5157C100008034397BD535D3B19940020000003D00000000010000000100000006000000000000003C0000000001000000020000000700000000000000080000000000000000000000FFFFFFFF00000000FFFFFFFF0800FFFFFFFF00000000FFFFFFFF0F000000000000000000FFFFFFFF10010000000000000000000000000000803F0000000000000000000000000000803F0000000000000000000000000000803F0000803F020000004600000047000000FFFFFFFF10000000450000003B00000037000000330000002F0000002B00000027000000230000001F0000001B00000017000000130000000F0000000B0000000700000003000000000000000100000048000000";
                }
                else
                {
                    n1 = "47616D656272796F2046696C6520466F726D61742C2056657273696F6E2033302E312E302E330A0300011E010000000049000000000000000B00110000004E694461746153747265616D0131013138110000004E694461746153747265616D0130013138110000004E69537472696E67457874726144617461060000004E694D657368120000004E694D6174657269616C50726F7065727479150000004E69566572746578436F6C6F7250726F70657274790F0000004E69416C70686150726F70657274790F0000004E69536F7572636554657874757265130000004E69546578747572696E6750726F7065727479110000004E695A42756666657250726F7065727479060000004E694E6F64650000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010002000300000001000200030000000100020003000000010004000500060007000800090002000300050009000A0008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC000000710000002900000008000000BC00000071000000290000000F00000024000000280000000E00000008000000BC0000000E0000000E0000009A00000018000000100000000A0000005363656E6520526F6F7407000000696E6C61795F300E0000005573657250726F704275666665720B0000000D0A7A4D6F646531300D0A10000000";
                    n2 = "0B0000004D6174657269616C20233205000000494E44455808000000504F534954494F4E08000000544558434F4F524407000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F3007000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300800000000696E6C61795F300000000050000000000000000100000000000000040000000200000037040300360402008EDBA1C2D26F80C049382037B18A633FEA6B6F3F01A3A8C2D26F80C06CF22637E7077B3FEA6B6F3F02A3A8C2D36F80406CF22637EB077B3F3A04FB3E8FDBA1C2D36F804049382037B98A633F3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000170000000100000002000000FFFFFFFF10009C2727B7B8C850C2A68B5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000483FA5C2000080345A952337DC6A8B400200000001000000000100000001000000060000000000000000000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402002DF799C2D26F80C0AF6318374532483FEA6B6F3F1E14A1C2D26F80C065721F37A7D7603FEA6B6F3F1F14A1C2D36F804065721F37AFD7603F3A04FB3E2EF799C2D36F8040AF6318374932483F3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000160000000100000006000000FFFFFFFF100021431FB7B8C850C29D8C5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000A6859DC2000080340AEB1B376F7A8C400200000005000000000100000001000000060000000000000004000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402001E1A92C2D26F80C0609710372BF32C3FEA6B6F3FBD2F99C2D26F80C0DC9D17373B7F453FEA6B6F3FBE2F99C2D36F8040DD9D17373B7F453F3A04FB3E1E1A92C2D36F80406097103727F32C3F3A04FB3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000015000000010000000A000000FFFFFFFF1000E64517B7B8C850C29A8D5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000EEA495C2000080349E1A1437C0628C40020000000900000000010000000100000006000000000000000800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200C6D489C2D26F80C0E4630837C34A103FEA6B6F3FAE5291C2D26F80C09DD10F3729402A3FEA6B6F3FAE5291C2D36F80409ED10F3725402A3F3A04FB3EC6D489C2D36F8040E6630837BF4A103F3A04FB3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000014000000010000000E000000FFFFFFFF1000F5290FB7B8C850C29C8E5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000BA938DC200008034C11A0C3794BB8D40020000000D00000000010000000100000006000000000000000C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200B88581C2D26F80C0CD2700376301E73EEA6B6F3F560D89C2D26F80C0319E0737B9970D3FEA6B6F3F560D89C2D36F8040339E0737B7970D3F3A04FB3EB88581C2D36F8040CE2700376001E73E3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000130000000100000012000000FFFFFFFF1000ECE906B7B8C850C2A58F5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000874985C20000803400E303377FDC8D40020000001100000000010000000100000006000000000000001000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE0372C2D26F80C04E70EF3668FFAB3EEA6B6F3F48BE80C2D26F80C05EC4FE364F9BE13EEA6B6F3F48BE80C2D36F804060C4FE364F9BE13E3A04FB3EC00372C2D36F80405170EF3661FFAB3E3A04FB3E010C000000000000000100000000000000060000000100000015020100020003000000000001000200010200000003000000120000000100000016000000FFFFFFFF1000302CFCB6B8C850C2B2905ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF000000000001000027C079C200008034571AF736D6918E40020000001500000000010000000100000006000000000000001400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200FC9160C2D26F80C08529DE3681D8693E903B6F3FE07470C2D26F80C036E5ED367D6BA73E8E3B6F3FE27470C2D36F804039E5ED36816BA73E82A3FA3EFE9160C2D36F80408929DE368FD8693E82A3FA3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000011000000010000001A000000FFFFFFFF10008441EBB6B8C850C2C6915ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF00000000000100006F8368C2000080345F07E636054C8F400200000019000000000100000001000000060000000000000018000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402008F854EC2D26F80C0D54ACC362E36EE3D903B6F3F1E035FC2D26F80C08D9EDC36C6F05F3E903B6F3F20035FC2D36F8040919EDC36CDF05F3E82A3FA3E92854EC2D36F8040D94ACC365A36EE3D82A3FA3E010C00000000000000010000000000000006000000010000001502010002000300000000000100020001020000000300000010000000010000001E000000FFFFFFFF10004604D9B6B8C850C2E2925ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF000000000001000058C456C200008034B374D43689629040020000001D00000000010000000100000006000000000000001C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200BE1E3CC2D26F80C0A514BA366CC2073B903B6F3FB1F64CC2D26F80C001C0CA36C666DA3D903B6F3FB4F64CC2D36F804005C0CA36E366DA3D82A3FA3EC21E3CC2D36F8040A914BA36E4C7073B82A3FA3E010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000F0000000100000022000000FFFFFFFF10006E79C6B6B8C850C205945ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000B98A44C200008034556AC2361C099140020000002100000000010000000100000006000000000000002000000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200873A29C2D26F80C02E64A7369CE45E3FA2AFEC3EE08F3AC2D26F80C0FA89B83640387D3FA2AFEC3EE48F3AC2D36F8040FE89B83647387D3F40C08D3C8B3A29C2D36F80403264A736A1E45E3F40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000E0000000100000026000000FFFFFFFF100043AAB3B6B8C850C230955ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF000000000001000036E531C20000803416F7AF36C6F4914002000000250000000001000000010000000600000000000000240000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020041CC15C2D26F80C0F72C94368DE53C3FA2AFEC3EA9AB27C2D26F80C0A9D9A536BE2A5C3FA2AFEC3EADAB27C2D36F8040ADD9A536C62A5C3F40C08D3C44CC15C2D36F8040FA2C943693E53C3F40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000D000000010000002A000000FFFFFFFF1000A987A0B6B8C850C262965ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000F7BB1EC20000803452039D363BFE92400200000029000000000100000001000000060000000000000028000000000100000002000000070000000000000008000000000000000000000050000000000000000100000000000000040000000200000037040300360402005E8201C2D26F80C0B01D80364366193FA2AFEC3E633D14C2D26F80C08FA29236B02B3A3FA2AFEC3E663D14C2D36F804092A29236B62B3A3F40C08D3C618201C2D36F8040B41D80364566193F40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000C000000010000002E000000FFFFFFFF1000CCF38BB6B8C850C2A0975ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000E2DF0AC2000080342160893634B19440020000002D00000000010000000100000006000000000000002C00000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200EF68DAC1D26F80C0141C5836E4BFEB3EA2AFEC3E00E7FFC1D26F80C0EE267D3664AC163FA2AFEC3E06E7FFC1D36F8040F5267D366BAC163F40C08D3CF368DAC1D36F80401A1C5836EBBFEB3E40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000B0000000100000032000000FFFFFFFF10003E3270B6B8C850C2E5985ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000FA27EDC10000803484A16A364DB9944002000000310000000001000000010000000600000000000000300000000001000000020000000700000000000000080000000000000000000000500000000000000001000000000000000400000002000000370403003604020077C6AFC1D26F80C04DFE2D36C627A13EA2AFEC3E334BD7C1D26F80C0FC075536294CE63EA2AFEC3E374BD7C1D36F8040010855362F4CE63E40C08D3C7AC6AFC1D36F804052FE2D36C627A13E40C08D3C010C0000000000000001000000000000000600000001000000150201000200030000000000010002000102000000030000000A0000000100000036000000FFFFFFFF10001CD645B6B8C850C2329A5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000D788C3C10000803427834136B2CE9640020000003500000000010000000100000006000000000000003400000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E4E083C1D26F80C0D1A50236AEB4283EA2AFEC3EBBA8ACC1D26F80C06EEA2A3609B49B3EA2AFEC3EBEA8ACC1D36F804073EA2A360FB49B3E40C08D3CE8E083C1D36F8040D2A50236C6B4283E80C08D3C010C00000000000000010000000000000006000000010000001502010000000100020002000300000001020000000300000009000000010000003A000000FFFFFFFF10006A6F1AB6B8C850C28C9B5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F0500000042000000400000003F0000003E00000043000000FFFFFFFF00000000FFFFFFFF0000000000010000D14498C10000803422C8163642259840020000003900000000010000000100000006000000000000003800000000010000000200000007000000000000000800000000000000000000005000000000000000010000000000000004000000020000003704030036040200E61B2DC1D26F80C0F2D1AB353AB6213CA2AFEC3E28C380C1D26F80C08424FF3540CD1D3EA2AFEC3E2CC380C1D36F80408624FF354CCD1D3E80C08D3CE81B2DC1D36F8040ECD1AB353AB6213C80C08D3C010C000000000000000100000000000000060000000100000015020100020003000000000001000200010500000000000000FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000803F0000803F0000803F000020410000803FFFFFFFFF00000000FFFFFFFF0000FFFFFFFF00000000FFFFFFFFED1000FFFFFFFF00000000FFFFFFFF0104000000FFFFFFFF060000000100000003000000010000FFFFFFFF00000000FFFFFFFF04000900000001410000000032010000000000000000000000000000FFFFFFFF00000000FFFFFFFF0D000200000003000000010000000100000044000000FFFFFFFF1000705DD8B5B8C850C2F19C5ABC000080B4000080B3000080BF000080BF0000000000004034000080330000803F000000B40000803F050000003E0000003F000000400000004200000043000000FFFFFFFF00000000FFFFFFFF00000000000100001F5157C100008034397BD535D3B19940020000003D00000000010000000100000006000000000000003C0000000001000000020000000700000000000000080000000000000000000000FFFFFFFF00000000FFFFFFFF0800FFFFFFFF00000000FFFFFFFF0F000000000000000000FFFFFFFF10010000000000000000000000000000803F0000000000000000000000000000803F0000000000000000000000000000803F0000803F020000004600000047000000FFFFFFFF10000000450000003B00000037000000330000002F0000002B00000027000000230000001F0000001B00000017000000130000000F0000000B0000000700000003000000000000000100000048000000";
                }
            }

            nifHex = n1 + nFileName.ToHex() + n2;
        }
        public static void BuildXBox360Package(string packagePath, DLCPackageData info, IEnumerable<string> xboxFiles, PackageMagic? xboxPackageType)
        {
            LogRecord x = new LogRecord();
            RSAParams xboxRSA = xboxPackageType == PackageMagic.CON ? new RSAParams(new DJsIO(Resources.XBox360_KV, true)) : new RSAParams(StrongSigned.LIVE);
            CreateSTFS xboxSTFS = new CreateSTFS();
            xboxSTFS.HeaderData = info.GetSTFSHeader();
            foreach (string file in xboxFiles)
                xboxSTFS.AddFile(file, Path.GetFileName(file));

            STFSPackage xboxPackage = new STFSPackage(xboxSTFS, xboxRSA, packagePath, x);
            var generated = xboxPackage.RebuildPackage(xboxRSA);
            if (!generated)
                throw new InvalidOperationException("Error on create XBox360 package, details: \n\r" + x.Log);

            xboxPackage.FlushPackage(xboxRSA);
            xboxPackage.CloseIO();

            try
            {
                if (Directory.Exists(xboxWorkDir))
                    Directory.Delete(xboxWorkDir, true);
            }
            catch { /*Have no problem if don't delete*/ }
        }
        private static void GenerateRS2014SongPsarc(MemoryStream output, DLCPackageData info, Platform platform)
        {
            var dlcName = info.Name.ToLower();

            {
                var packPsarc = new PSARC.PSARC();

                // Stream objects
                Stream soundStream = null,
                       soundPreviewStream = null,
                       rsenumerableRootStream = null,
                       rsenumerableSongStream = null;

                try {
                    // ALBUM ART
                    var ddsfiles = info.ArtFiles;

                    if (ddsfiles == null) {
                        string albumArtPath;
                        if (File.Exists(info.AlbumArtPath)) {
                            albumArtPath = info.AlbumArtPath;
                        } else {
                            using (var albumArtStream = new MemoryStream(Resources.albumart2014_256))
                            {
                                albumArtPath = GeneralExtensions.GetTempFileName(".dds");
                                albumArtStream.WriteFile(albumArtPath);
                                TMPFILES_ART.Add(albumArtPath);
                            }
                        }

                        ddsfiles = new List<DDSConvertedFile>();
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 64, sizeY = 64, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 128, sizeY = 128, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 256, sizeY = 256, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });

                        // Convert to DDS
                        ToDDS(ddsfiles);

                        // Save for reuse
                        info.ArtFiles = ddsfiles;
                    }

                    foreach (var dds in ddsfiles)
                        packPsarc.AddEntry(String.Format("gfxassets/album_art/album_{0}_{1}.dds", dlcName, dds.sizeX), new FileStream(dds.destinationFile, FileMode.Open, FileAccess.Read, FileShare.Read));

                    //Lyrics Font Texture
                    if (File.Exists(info.LyricsTex))
                        packPsarc.AddEntry(String.Format("assets/ui/lyrics/{0}/lyrics_{0}.dds", dlcName), new FileStream(info.LyricsTex, FileMode.Open, FileAccess.Read, FileShare.Read));

                    // AUDIO
                    var audioFile = info.OggPath;
                    if (File.Exists(audioFile))
                        if (platform.IsConsole != audioFile.GetAudioPlatform().IsConsole)
                            soundStream = OggFile.ConvertAudioPlatform(audioFile);
                        else
                            soundStream = File.OpenRead(audioFile);
                    else
                        throw new InvalidOperationException(String.Format("Audio file '{0}' not found.", audioFile));

                    // AUDIO PREVIEW
                    var previewAudioFile = info.OggPreviewPath;
                    if (File.Exists(previewAudioFile))
                        if (platform.IsConsole != previewAudioFile.GetAudioPlatform().IsConsole)
                            soundPreviewStream = OggFile.ConvertAudioPlatform(previewAudioFile);
                        else
                            soundPreviewStream = File.OpenRead(previewAudioFile);
                    else
                        soundPreviewStream = soundStream;

                    // FLAT MODEL
                    rsenumerableRootStream = new MemoryStream(Resources.rsenumerable_root);
                    packPsarc.AddEntry("flatmodels/rs/rsenumerable_root.flat", rsenumerableRootStream);
                    rsenumerableSongStream = new MemoryStream(Resources.rsenumerable_song);
                    packPsarc.AddEntry("flatmodels/rs/rsenumerable_song.flat", rsenumerableSongStream);

                    using (var toolkitVersionStream = new MemoryStream())
                    using (var appIdStream = new MemoryStream())
                    using (var packageListStream = new MemoryStream())
                    using (var soundbankStream = new MemoryStream())
                    using (var soundbankPreviewStream = new MemoryStream())
                    using (var aggregateGraphStream = new MemoryStream())
                    using (var manifestHeaderHSANStream = new MemoryStream())
                    using (var manifestHeaderHSONStreamList = new DisposableCollection<Stream>())
                    using (var manifestStreamList = new DisposableCollection<Stream>())
                    using (var arrangementStream = new DisposableCollection<Stream>())
                    using (var showlightStream = new MemoryStream())
                    using (var xblockStream = new MemoryStream())
                    {
                        // TOOLKIT VERSION
                        GenerateToolkitVersion(toolkitVersionStream, info.PackageVersion);
                        packPsarc.AddEntry("toolkit.version", toolkitVersionStream);

                        // APP ID
                        if (!platform.IsConsole)
                        {
                            GenerateAppId(appIdStream, info.AppId, platform);
                            packPsarc.AddEntry("appid.appid", appIdStream);
                        }

                        if (platform.platform == GamePlatform.XBox360) {
                            var packageListWriter = new StreamWriter(packageListStream);
                            packageListWriter.Write(dlcName);
                            packageListWriter.Flush();
                            packageListStream.Seek(0, SeekOrigin.Begin);
                            string packageList = "PackageList.txt";
                            packageListStream.WriteTmpFile(packageList, platform);
                        }

                        // SOUNDBANK
                        var soundbankFileName = String.Format("song_{0}", dlcName);
                        var audioFileNameId = SoundBankGenerator2014.GenerateSoundBank(info.Name, soundStream, soundbankStream, info.Volume, platform);
                        packPsarc.AddEntry(String.Format("audio/{0}/{1}.bnk", platform.GetPathName()[0].ToLower(), soundbankFileName), soundbankStream);
                        packPsarc.AddEntry(String.Format("audio/{0}/{1}.wem", platform.GetPathName()[0].ToLower(), audioFileNameId), soundStream);

                        // SOUNDBANK PREVIEW
                        var soundbankPreviewFileName = String.Format("song_{0}_preview", dlcName);
                        dynamic audioPreviewFileNameId;
                        var previewVolume = (info.PreviewVolume != null) ? (float)info.PreviewVolume : info.Volume;
                        if (!soundPreviewStream.Equals(soundStream))
                            audioPreviewFileNameId = SoundBankGenerator2014.GenerateSoundBank(info.Name + "_Preview", soundPreviewStream, soundbankPreviewStream, previewVolume, platform, true);
                        else
                            audioPreviewFileNameId = SoundBankGenerator2014.GenerateSoundBank(info.Name + "_Preview", soundPreviewStream, soundbankPreviewStream, info.Volume, platform, true, true);
                        packPsarc.AddEntry(String.Format("audio/{0}/{1}.bnk", platform.GetPathName()[0].ToLower(), soundbankPreviewFileName), soundbankPreviewStream);
                        if (!soundPreviewStream.Equals(soundStream)) packPsarc.AddEntry(String.Format("audio/{0}/{1}.wem", platform.GetPathName()[0].ToLower(), audioPreviewFileNameId), soundPreviewStream);

                        // AGGREGATE GRAPH
                        var aggregateGraphFileName = String.Format("{0}_aggregategraph.nt", dlcName);
                        var aggregateGraph = new AggregateGraph2014(info, platform);
                        aggregateGraph.Serialize(aggregateGraphStream);
                        aggregateGraphStream.Flush();
                        aggregateGraphStream.Seek(0, SeekOrigin.Begin);
                        packPsarc.AddEntry(aggregateGraphFileName, aggregateGraphStream);

                        var manifestHeader = new ManifestHeader2014<AttributesHeader2014>(platform);
                        var songPartition = new SongPartition();
                        var songPartitionCount = new SongPartition();

                        foreach (var arrangement in info.Arrangements)
                        {
                            var arrangementFileName = songPartition.GetArrangementFileName(arrangement.Name, arrangement.ArrangementType).ToLower();

                            // GAME SONG (SNG)
                            UpdateToneDescriptors(info);
                            GenerateSNG(arrangement, platform);
                            var sngSongFile = File.OpenRead(arrangement.SongFile.File);
                            arrangementStream.Add(sngSongFile);
                            packPsarc.AddEntry(String.Format("songs/bin/{0}/{1}_{2}.sng", platform.GetPathName()[1].ToLower(), dlcName, arrangementFileName), sngSongFile);

                            // XML SONG
                            var xmlSongFile = File.OpenRead(arrangement.SongXml.File);
                            arrangementStream.Add(xmlSongFile);
                            packPsarc.AddEntry(String.Format("songs/arr/{0}_{1}.xml", dlcName, arrangementFileName), xmlSongFile);

                            // MANIFEST
                            var manifest = new Manifest2014<Attributes2014>();
                            var attribute = new Attributes2014(arrangementFileName, arrangement, info, platform);
                            if (arrangement.ArrangementType != Sng.ArrangementType.Vocal)
                            {
                                attribute.SongPartition = songPartitionCount.GetSongPartition(arrangement.Name, arrangement.ArrangementType);
                                if (attribute.SongPartition > 1)
                                { // Make the second arrangement with the same arrangement type as ALTERNATE arrangement ingame
                                    attribute.Representative = 0;
                                    attribute.ArrangementProperties.Represent = 0;
                                }
                            }
                            var attributeDictionary = new Dictionary<string, Attributes2014> { { "Attributes", attribute } };
                            manifest.Entries.Add(attribute.PersistentID, attributeDictionary);
                            var manifestStream = new MemoryStream();
                            manifestStreamList.Add(manifestStream);
                            manifest.Serialize(manifestStream);
                            manifestStream.Seek(0, SeekOrigin.Begin);

                            var jsonPathPC = "manifests/songs_dlc_{0}/{0}_{1}.json";
                            var jsonPathConsole = "manifests/songs_dlc/{0}_{1}.json";
                            packPsarc.AddEntry(String.Format((platform.IsConsole ? jsonPathConsole : jsonPathPC), dlcName, arrangementFileName), manifestStream);

                            // MANIFEST HEADER
                            var attributeHeaderDictionary = new Dictionary<string, AttributesHeader2014> { { "Attributes", new AttributesHeader2014(attribute) } };

                            if (platform.IsConsole) {
                                // One for each arrangements (Xbox360/PS3)
                                manifestHeader = new ManifestHeader2014<AttributesHeader2014>(platform);
                                manifestHeader.Entries.Add(attribute.PersistentID, attributeHeaderDictionary);
                                var manifestHeaderStream = new MemoryStream();
                                manifestHeaderHSONStreamList.Add(manifestHeaderStream);
                                manifestHeader.Serialize(manifestHeaderStream);
                                manifestStream.Seek(0, SeekOrigin.Begin);
                                packPsarc.AddEntry(String.Format("manifests/songs_dlc/{0}_{1}.hson", dlcName, arrangementFileName), manifestHeaderStream);
                            } else {
                                // One for all arrangements (PC/Mac)
                                manifestHeader.Entries.Add(attribute.PersistentID, attributeHeaderDictionary);
                            }
                        }

                        if (!platform.IsConsole) {
                            manifestHeader.Serialize(manifestHeaderHSANStream);
                            manifestHeaderHSANStream.Seek(0, SeekOrigin.Begin);
                            packPsarc.AddEntry(String.Format("manifests/songs_dlc_{0}/songs_dlc_{0}.hsan", dlcName), manifestHeaderHSANStream);
                        }

                        // SHOWLIGHT
                        Showlights showlight = new Showlights(info);
                        showlight.Serialize(showlightStream);
                        if(showlightStream.CanRead)
                            packPsarc.AddEntry(String.Format("songs/arr/{0}_showlights.xml", dlcName), showlightStream);

                        // XBLOCK
                        GameXblock<Entity2014> game = GameXblock<Entity2014>.Generate2014(info, platform);
                        game.SerializeXml(xblockStream);
                        xblockStream.Flush();
                        xblockStream.Seek(0, SeekOrigin.Begin);
                        packPsarc.AddEntry(String.Format("gamexblocks/nsongs/{0}.xblock", dlcName), xblockStream);

                        // WRITE PACKAGE
                        packPsarc.Write(output, !platform.IsConsole);
                        output.Flush();
                        output.Seek(0, SeekOrigin.Begin);
                        output.WriteTmpFile(String.Format("{0}.psarc", dlcName), platform);
                    }
                } catch (Exception ex) {
                    throw ex;
                } finally {
                    // Dispose all objects
                    if (soundStream != null)
                        soundStream.Dispose();
                    if (soundPreviewStream != null)
                        soundPreviewStream.Dispose();
                    if (rsenumerableRootStream != null)
                        rsenumerableRootStream.Dispose();
                    if (rsenumerableSongStream != null)
                        rsenumerableSongStream.Dispose();
                    DeleteTmpFiles(TMPFILES_SNG);
                    DeleteTmpFiles(TMPFILES_ART);
                }
            }
        }
Exemplo n.º 15
0
        public static DLCPackageData LoadFromFile(string unpackedDir, Platform targetPlatform)
        {
            //Load files
            var jsonFiles = Directory.GetFiles(unpackedDir, "*.json", SearchOption.AllDirectories);
            var data      = new DLCPackageData();

            data.GameVersion   = GameVersion.RS2014;
            data.SignatureType = PackageMagic.CON;

            //Get Arrangements / Tones
            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();

            foreach (var json in jsonFiles)
            {
                Attributes2014 attr = Manifest2014 <Attributes2014> .LoadFromFile(json).Entries.ToArray()[0].Value.ToArray()[0].Value;

                var xmlName = attr.SongXml.Split(':')[3];
                var xmlFile = Directory.GetFiles(unpackedDir, xmlName + ".xml", SearchOption.AllDirectories)[0];

                if (attr.Phrases != null)
                {
                    if (data.SongInfo == null)
                    {
                        // Fill Package Data
                        data.Name          = attr.DLCKey;
                        data.Volume        = attr.SongVolume;
                        data.PreviewVolume = (attr.PreviewVolume != null) ? (float)attr.PreviewVolume : data.Volume;

                        // Fill SongInfo
                        data.SongInfo = new SongInfo();
                        data.SongInfo.SongDisplayName     = attr.SongName;
                        data.SongInfo.SongDisplayNameSort = attr.SongNameSort;
                        data.SongInfo.Album        = attr.AlbumName;
                        data.SongInfo.SongYear     = attr.SongYear ?? 0;
                        data.SongInfo.Artist       = attr.ArtistName;
                        data.SongInfo.ArtistSort   = attr.ArtistNameSort;
                        data.SongInfo.AverageTempo = (int)attr.SongAverageTempo;
                    }

                    // Adding Tones
                    foreach (var jsonTone in attr.Tones)
                    {
                        if (jsonTone == null)
                        {
                            continue;
                        }
                        if (!data.TonesRS2014.OfType <Tone2014>().Any(t => t.Key == jsonTone.Key))
                        {
                            data.TonesRS2014.Add(jsonTone);
                        }
                    }

                    // Adding Arrangement
                    data.Arrangements.Add(new Arrangement(attr, xmlFile));
                }
                else
                {
                    var voc = new Arrangement();
                    voc.Name            = ArrangementName.Vocals;
                    voc.ArrangementType = ArrangementType.Vocal;
                    voc.SongXml         = new SongXML {
                        File = xmlFile
                    };
                    voc.SongFile = new SongFile {
                        File = ""
                    };
                    voc.Sng2014     = Sng2014HSL.Sng2014File.ConvertXML(xmlFile, ArrangementType.Vocal);
                    voc.ScrollSpeed = 20;

                    // Adding Arrangement
                    data.Arrangements.Add(voc);
                }
            }

            //Get Files
            var ddsFiles = Directory.GetFiles(unpackedDir, "*_256.dds", SearchOption.AllDirectories);

            if (ddsFiles.Length > 0)
            {
                data.AlbumArtPath = ddsFiles[0];
            }

            var sourceAudioFiles = Directory.GetFiles(unpackedDir, "*.wem", SearchOption.AllDirectories);

            var targetAudioFiles = new List <string>();

            foreach (var file in sourceAudioFiles)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(file), String.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)));
                if (targetPlatform.IsConsole != file.GetAudioPlatform().IsConsole)
                {
                    OggFile.ConvertAudioPlatform(file, newFile);
                    targetAudioFiles.Add(newFile);
                }
                else
                {
                    targetAudioFiles.Add(file);
                }
            }

            if (targetAudioFiles.Count() <= 0)
            {
                throw new InvalidDataException("Audio files not found.");
            }

            string   audioPath = null, audioPreviewPath = null;
            FileInfo a = new FileInfo(targetAudioFiles[0]);
            FileInfo b = null;

            if (targetAudioFiles.Count() == 2)
            {
                b = new FileInfo(targetAudioFiles[1]);

                if (a.Length > b.Length)
                {
                    audioPath        = a.FullName;
                    audioPreviewPath = b.FullName;
                }
                else
                {
                    audioPath        = b.FullName;
                    audioPreviewPath = a.FullName;
                }
            }
            else
            {
                audioPath = a.FullName;
            }

            data.OggPath = audioPath;

            //Make Audio preview with expected name when rebuild
            if (!String.IsNullOrEmpty(audioPreviewPath))
            {
                var newPreviewFileName = Path.Combine(Path.GetDirectoryName(audioPath), String.Format("{0}_preview{1}", Path.GetFileNameWithoutExtension(audioPath), Path.GetExtension(audioPath)));
                File.Move(audioPreviewPath, newPreviewFileName);
                data.OggPreviewPath = newPreviewFileName;
            }

            var appidFile = Directory.GetFiles(unpackedDir, "*.appid", SearchOption.AllDirectories);

            if (appidFile.Length > 0)
            {
                data.AppId = File.ReadAllText(appidFile[0]);
            }

            return(data);
        }
        /// <summary>
        /// Loads required DLC info from folder.
        /// </summary>
        /// <returns>The DLCPackageData info.</returns>
        /// <param name="unpackedDir">Unpacked dir.</param>
        /// <param name="targetPlatform">Target platform.</param>
        /// <param name = "sourcePlatform"></param>
        public static DLCPackageData LoadFromFolder(string unpackedDir, Platform targetPlatform, Platform sourcePlatform = null)
        {
            var data = new DLCPackageData();
            data.GameVersion = GameVersion.RS2014;
            data.SignatureType = PackageMagic.CON;
            if (sourcePlatform == null)
                sourcePlatform = unpackedDir.GetPlatform();

            //Arrangements / Tones
            data.Arrangements = new List<Arrangement>();
            data.TonesRS2014 = new List<Tone2014>();

            //Load files
            var jsonFiles = Directory.EnumerateFiles(unpackedDir, "*.json", SearchOption.AllDirectories).ToArray();
            foreach (var json in jsonFiles)
            {
                var attr = Manifest2014<Attributes2014>.LoadFromFile(json).Entries.ToArray()[0].Value.ToArray()[0].Value;
                var xmlName = attr.SongXml.Split(':')[3];
                var xmlFile = Directory.EnumerateFiles(unpackedDir, xmlName + ".xml", SearchOption.AllDirectories).FirstOrDefault();

                if (attr.Phrases != null)
                {
                    if (data.SongInfo == null)
                    {
                        // Fill Package Data
                        data.Name = attr.DLCKey;
                        data.Volume = (attr.SongVolume == 0 ? -12 : attr.SongVolume); //FIXME: too low song volume issue, revert to -6 to fix.
                        data.PreviewVolume = (attr.PreviewVolume ?? data.Volume);

                        // Fill SongInfo
                        data.SongInfo = new SongInfo
                        {
                            SongDisplayName = attr.SongName,
                            SongDisplayNameSort = attr.SongNameSort,
                            Album = attr.AlbumName,
                            SongYear = attr.SongYear ?? 0,
                            Artist = attr.ArtistName,
                            ArtistSort = attr.ArtistNameSort,
                            AverageTempo = (int) attr.SongAverageTempo
                        };
                    }

                    // Adding Tones
                    foreach (var jsonTone in attr.Tones)
                    {
                        if (jsonTone == null) continue;
                        var key = jsonTone.Key;
                        if (data.TonesRS2014.All(t => t.Key != key))
                        {
                            // fix tones names that do not have the correct alphacase for cross matching
                            if (attr.Tone_Base.ToLower() == jsonTone.Name.ToLower() && attr.Tone_Base != jsonTone.Name)
                                jsonTone.Name = attr.Tone_Base;
                            if (attr.Tone_A != null && attr.Tone_A.ToLower() == jsonTone.Name.ToLower() && attr.Tone_A != jsonTone.Name)
                                jsonTone.Name = attr.Tone_A;
                            if (attr.Tone_B != null && attr.Tone_B.ToLower() == jsonTone.Name.ToLower() && attr.Tone_B != jsonTone.Name)
                                jsonTone.Name = attr.Tone_B;
                            if (attr.Tone_C != null && attr.Tone_C.ToLower() == jsonTone.Name.ToLower() && attr.Tone_C != jsonTone.Name)
                                jsonTone.Name = attr.Tone_C;
                            if (attr.Tone_D != null && attr.Tone_D.ToLower() == jsonTone.Name.ToLower() && attr.Tone_D != jsonTone.Name)
                                jsonTone.Name = attr.Tone_D;

                            data.TonesRS2014.Add(jsonTone);
                        }
                    }

                    // Adding Arrangement
                    data.Arrangements.Add(new Arrangement(attr, xmlFile));
                }
                else if (xmlFile.ToLower().Contains("_vocals"))
                {
                    var voc = new Arrangement
                    {
                        Name = attr.JapaneseVocal == true ? ArrangementName.JVocals : ArrangementName.Vocals,
                        ArrangementType = ArrangementType.Vocal,
                        ScrollSpeed = 20,
                        SongXml = new SongXML {File = xmlFile},
                        SongFile = new SongFile {File = ""},
                        CustomFont = attr.JapaneseVocal == true
                    };

                    // Get symbols stuff from _vocals.xml
                    var fontSng = Path.Combine(unpackedDir, xmlName + ".sng");
                    var vocSng = Sng2014FileWriter.ReadVocals(xmlFile);

                    if (vocSng.IsCustomFont())
                    {
                        voc.CustomFont = true;
                        voc.FontSng = fontSng;
                        vocSng.WriteChartData(fontSng, new Platform(GamePlatform.Pc, GameVersion.None));
                    }

                    voc.Sng2014 = Sng2014File.ConvertXML(xmlFile, ArrangementType.Vocal, voc.FontSng);

                    // Adding Arrangement
                    data.Arrangements.Add(voc);
                }
            }

            //ShowLights XML
            var xmlShowLights = Directory.EnumerateFiles(unpackedDir, "*_showlights.xml", SearchOption.AllDirectories).FirstOrDefault();
            if (!String.IsNullOrEmpty(xmlShowLights))
            {
                var shl = new Arrangement
                {
                    ArrangementType = ArrangementType.ShowLight,
                    Name = ArrangementName.ShowLights,
                    SongXml = new SongXML { File = xmlShowLights },
                    SongFile = new SongFile { File = "" }
                };

                // Adding ShowLights
                data.Arrangements.Add(shl);
            }

            //Get DDS Files
            var ddsFiles = Directory.EnumerateFiles(unpackedDir, "album_*.dds", SearchOption.AllDirectories).ToArray();
            if (ddsFiles.Any())
            {
                var ddsFilesC = new List<DDSConvertedFile>();
                foreach (var file in ddsFiles)
                    switch (Path.GetFileNameWithoutExtension(file).Split('_')[2])
                    {

                        case "256":
                            data.AlbumArtPath = file;
                            ddsFilesC.Add(new DDSConvertedFile() { sizeX = 256, sizeY = 256, sourceFile = file, destinationFile = file.CopyToTempFile(".dds") });
                            break;
                        case "128":
                            ddsFilesC.Add(new DDSConvertedFile() { sizeX = 128, sizeY = 128, sourceFile = file, destinationFile = file.CopyToTempFile(".dds") });
                            break;
                        case "64":
                            ddsFilesC.Add(new DDSConvertedFile() { sizeX = 64, sizeY = 64, sourceFile = file, destinationFile = file.CopyToTempFile(".dds") });
                            break;
                    } data.ArtFiles = ddsFilesC;
            }

            // Lyric Art
            var lyricArt = Directory.EnumerateFiles(unpackedDir, "lyrics_*.dds", SearchOption.AllDirectories).ToArray();
            if (lyricArt.Any())
                data.LyricArtPath = lyricArt.FirstOrDefault();

            //Get other files
            //Audio files
            var targetAudioFiles = new List<string>();
            var sourceAudioFiles = Directory.EnumerateFiles(unpackedDir, "*.wem", SearchOption.AllDirectories).ToArray();

            foreach (var file in sourceAudioFiles)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(file), String.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)));
                if (targetPlatform.IsConsole != (sourcePlatform = file.GetAudioPlatform()).IsConsole)
                {
                    OggFile.ConvertAudioPlatform(file, newFile);
                    targetAudioFiles.Add(newFile);
                }
                else targetAudioFiles.Add(file);
            }

            if (!targetAudioFiles.Any())
                throw new InvalidDataException("Audio files not found.");

            string audioPath = null, audioPreviewPath = null;
            var a = new FileInfo(targetAudioFiles[0]);

            if (targetAudioFiles.Count == 2)
            {
                var b = new FileInfo(targetAudioFiles[1]);

                if (a.Length > b.Length)
                {
                    audioPath = a.FullName;
                    audioPreviewPath = b.FullName;
                }
                else
                {
                    audioPath = b.FullName;
                    audioPreviewPath = a.FullName;
                }
            }
            else
                audioPath = a.FullName;

            data.OggPath = audioPath;

            //Make Audio preview with expected name when rebuild
            if (!String.IsNullOrEmpty(audioPreviewPath))
            {
                var newPreviewFileName = Path.Combine(Path.GetDirectoryName(audioPath), String.Format("{0}_preview{1}", Path.GetFileNameWithoutExtension(audioPath), Path.GetExtension(audioPath)));
                File.Move(audioPreviewPath, newPreviewFileName);
                data.OggPreviewPath = newPreviewFileName;
            }

            //AppID
            var appidFile = Directory.EnumerateFiles(unpackedDir, "*.appid", SearchOption.AllDirectories).FirstOrDefault();
            if (appidFile != null)
                data.AppId = File.ReadAllText(appidFile);

            //Package version
            var versionFile = Directory.EnumerateFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories).FirstOrDefault();
            if (versionFile != null)
                data.PackageVersion = GeneralExtensions.ReadPackageVersion(versionFile);
            else data.PackageVersion = "1";

            return data;
        }
Exemplo n.º 17
0
        // Load RS1 CDLC into PackageCreator
        public static DLCPackageData RS1LoadFromFolder(string unpackedDir, Platform targetPlatform, bool convert)
        {
            var data = new DLCPackageData();

            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();
            data.Tones        = new List <Tone>();

            data.GameVersion   = (convert ? GameVersion.RS2014 : GameVersion.RS2012);
            data.SignatureType = PackageMagic.CON;
            // set default volumes
            data.Volume        = -6.5F; // default maybe too quite
            data.PreviewVolume = data.Volume;

            //Load song manifest
            var songsManifestJson = Directory.GetFiles(unpackedDir, "songs.manifest.json", SearchOption.AllDirectories);

            if (songsManifestJson.Length < 1)
            {
                throw new DataException("No songs.manifest.json file found.");
            }
            if (songsManifestJson.Length > 1)
            {
                throw new DataException("More than one songs.manifest.json file found.");
            }

            var attr          = new List <Attributes>();
            var songsManifest = Manifest.Manifest.LoadFromFile(songsManifestJson[0]).Entries.ToArray();

            for (int smIndex = 0; smIndex < songsManifest.Count(); smIndex++)
            {
                var smData = songsManifest[smIndex].Value.ToArray()[0].Value;
                attr.Add(smData);
            }

            if (attr.FirstOrDefault() == null)
            {
                throw new DataException("songs.manifest.json file did not parse correctly.");
            }

            // Fill SongInfo
            data.SongInfo = new SongInfo();
            data.SongInfo.SongDisplayName     = attr.FirstOrDefault().SongName;
            data.SongInfo.SongDisplayNameSort = attr.FirstOrDefault().SongNameSort;
            data.SongInfo.Album      = attr.FirstOrDefault().AlbumName;
            data.SongInfo.SongYear   = (attr.FirstOrDefault().SongYear == 0 ? 2012 : attr.FirstOrDefault().SongYear);
            data.SongInfo.Artist     = attr.FirstOrDefault().ArtistName;
            data.SongInfo.ArtistSort = attr.FirstOrDefault().ArtistNameSort;
            data.Name = attr.FirstOrDefault().SongKey;

            //Load tone manifest, even poorly formed tone_bass.manifest.json
            var toneManifestJson = Directory.GetFiles(unpackedDir, "*tone*.manifest.json", SearchOption.AllDirectories);

            if (toneManifestJson.Length < 1)
            {
                throw new DataException("No tone.manifest.json file found.");
            }

            // toolkit produces multiple tone.manifest.json files when packing RS1 CDLC files
            // rather than change toolkit behavior just merge manifest files for now
            if (toneManifestJson.Length > 1)
            {
                var mergeSettings = new JsonMergeSettings {
                    MergeArrayHandling = MergeArrayHandling.Union
                };
                JObject toneObject1 = new JObject();

                foreach (var tone in toneManifestJson)
                {
                    JObject toneObject2 = JObject.Parse(File.ReadAllText(tone));
                    //(toneObject1.SelectToken("Entries") as JArray).Merge(toneObject2.SelectToken("Entries"));
                    toneObject1.Merge(toneObject2, mergeSettings);
                }

                toneManifestJson    = new string[1];
                toneManifestJson[0] = Path.Combine(unpackedDir, "merged.tone.manifest.json");
                string json = JsonConvert.SerializeObject(toneObject1, Formatting.Indented);
                File.WriteAllText(toneManifestJson[0], json);
            }

            var tones2014    = new List <Tone2014>();
            var tones        = new List <Tone>();
            var toneManifest = Manifest.Tone.Manifest.LoadFromFile(toneManifestJson[0]);

            for (int tmIndex = 0; tmIndex < toneManifest.Entries.Count(); tmIndex++)
            {
                var tmData = toneManifest.Entries[tmIndex];
                tones.Add(tmData);
            }

            data.Tones = tones;

            // Load AggregateGraph.nt
            var songDir = Path.Combine(unpackedDir, data.Name);

            if (targetPlatform.platform == GamePlatform.XBox360)
            {
                songDir = Path.Combine(unpackedDir, "Root", data.Name);
            }

            var aggFile      = Directory.GetFiles(songDir, "*.nt", SearchOption.TopDirectoryOnly)[0];
            var aggGraphData = AggregateGraph.AggregateGraph.ReadFromFile(aggFile);

            // Load Exports\Songs\*.xblock
            var xblockDir  = Path.Combine(songDir, "Exports\\Songs");
            var xblockFile = Directory.GetFiles(xblockDir, "*.xblock", SearchOption.TopDirectoryOnly)[0];
            // xblockFile = "D:\\Temp\\Mapping\\songs.xblock";
            var songsXblock = XblockX.LoadFromFile(xblockFile);

            // create project map for cross referencing arrangements with tones
            var projectMap = AggregateGraph.AggregateGraph.ProjectMap(aggGraphData, songsXblock, toneManifest);

            // Load xml arrangements
            var xmlFiles = Directory.GetFiles(unpackedDir, "*.xml", SearchOption.AllDirectories);

            if (xmlFiles.Length <= 0)
            {
                throw new DataException("Can not find any XML arrangement files");
            }

            foreach (var xmlFile in xmlFiles)
            {
                if (xmlFile.ToLower().Contains("metadata"))
                {
                    continue;
                }

                // some poorly formed RS1 CDLC use just "vocal"
                if (xmlFile.ToLower().Contains("vocal"))
                {
                    // Add Vocal Arrangement
                    data.Arrangements.Add(new Arrangement
                    {
                        Name            = ArrangementName.Vocals,
                        ArrangementType = ArrangementType.Vocal,
                        ScrollSpeed     = 20,
                        SongXml         = new SongXML {
                            File = xmlFile
                        },
                        SongFile = new SongFile {
                            File = ""
                        },
                        CustomFont = false
                    });
                }
                else
                {
                    var attr2014   = new Attributes2014();
                    var rsSong     = new Song();
                    var rsSong2014 = new Song2014();

                    // optimized tone matching effort using project mapping algo
                    var result = projectMap.First(m => String.Equals(Path.GetFileName(m.SongXmlPath), Path.GetFileName(xmlFile), StringComparison.CurrentCultureIgnoreCase));
                    if (result.Tones.Count != 1)
                    {
                        throw new DataException("Invalid RS1 CDLC Tones Data");
                    }

                    var arrangement = attr.First(s => s.SongXml.ToLower().Contains(result.LLID));//FIXME: Sequence contains no matching element issue
                    var tone        = tones.First(t => t.Key == result.Tones[0]);

                    using (var obj1 = new Rs1Converter())
                    {
                        rsSong = obj1.XmlToSong(xmlFile);
                        data.SongInfo.AverageTempo = (int)obj1.AverageBPM(rsSong);
                    }

                    if (arrangement.Tuning == "E Standard")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        }
                    }
                    ;
                    else if (arrangement.Tuning == "DropD")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = -2, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        }
                    }
                    ;
                    else if (arrangement.Tuning == "OpenG")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = -2, String1 = -2, String2 = 0, String3 = 0, String4 = 0, String5 = -2
                        }
                    }
                    ;
                    else if (arrangement.Tuning == "EFlat")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = -1, String1 = -1, String2 = -1, String3 = -1, String4 = -1, String5 = -1
                        }
                    }
                    ;
                    else // default to standard tuning
                    {
                        arrangement.Tuning = "E Standard";
                        rsSong.Tuning      = new TuningStrings {
                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        };
                    }

                    // save/write the changes to xml file
                    using (var obj1 = new Rs1Converter())
                        obj1.SongToXml(rsSong, xmlFile, true);

                    if (convert)
                    {
                        using (var obj1 = new Rs1Converter())
                            tones2014.Add(obj1.ToneToTone2014(tone, rsSong));
                    }

                    // load attr2014 with RS1 mapped values for use by Arrangement()
                    attr2014.Tone_Base            = tone.Name;
                    attr2014.ArrangementName      = arrangement.ArrangementName;
                    attr2014.CentOffset           = 0;
                    attr2014.DynamicVisualDensity = new List <float>()
                    {
                        2
                    };
                    attr2014.SongPartition         = arrangement.SongPartition;
                    attr2014.PersistentID          = IdGenerator.Guid().ToString();
                    attr2014.MasterID_RDV          = RandomGenerator.NextInt();
                    attr2014.ArrangementProperties = new SongArrangementProperties2014();

                    // processing order is important - CAREFUL
                    // RouteMask  None = 0, Lead = 1, Rhythm = 2, Any = 3, Bass = 4
                    // XML file names are usually meaningless to arrangement determination

                    if (arrangement.ArrangementName.ToLower().Contains("lead") ||
                        rsSong.Arrangement.ToLower().Contains("lead"))
                    {
                        attr2014.ArrangementName = "Lead";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Lead;
                        attr2014.ArrangementProperties.PathLead   = 1;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass   = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("rhythm") ||
                             rsSong.Arrangement.ToLower().Contains("rhythm"))
                    // || rsSong.Arrangement.ToLower().Contains("guitar"))
                    {
                        attr2014.ArrangementName = "Rhythm";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Rhythm;
                        attr2014.ArrangementProperties.PathLead   = 0;
                        attr2014.ArrangementProperties.PathRhythm = 1;
                        attr2014.ArrangementProperties.PathBass   = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("combo") ||
                             rsSong.Arrangement.ToLower().Contains("combo"))
                    {
                        attr2014.ArrangementName = "Combo";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = arrangement.EffectChainName.ToLower().Contains("lead") ? (int)RouteMask.Lead : (int)RouteMask.Rhythm;
                        attr2014.ArrangementProperties.PathLead   = arrangement.EffectChainName.ToLower().Contains("lead") ? 1 : 0;
                        attr2014.ArrangementProperties.PathRhythm = arrangement.EffectChainName.ToLower().Contains("lead") ? 0 : 1;
                        attr2014.ArrangementProperties.PathBass   = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("bass") ||
                             rsSong.Arrangement.ToLower().Contains("bass"))
                    {
                        attr2014.ArrangementName = "Bass";
                        attr2014.ArrangementType = (int)ArrangementType.Bass;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Bass;
                        attr2014.ArrangementProperties.PathLead   = 0;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass   = 1;
                    }
                    else
                    {
                        // default to Lead arrangement
                        attr2014.ArrangementName = "Lead";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Lead;
                        attr2014.ArrangementProperties.PathLead   = 1;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass   = 0;

                        Console.WriteLine("RS1->RS2 CDLC Conversion defaulted to 'Lead' arrangement");
                    }

                    if (convert) // RS1 -> RS2 magic
                    {
                        using (var obj1 = new Rs1Converter())
                            rsSong2014 = obj1.SongToSong2014(rsSong);

                        // update ArrangementProperties
                        rsSong2014.ArrangementProperties.RouteMask      = attr2014.ArrangementProperties.RouteMask;
                        rsSong2014.ArrangementProperties.PathLead       = attr2014.ArrangementProperties.PathLead;
                        rsSong2014.ArrangementProperties.PathRhythm     = attr2014.ArrangementProperties.PathRhythm;
                        rsSong2014.ArrangementProperties.PathBass       = attr2014.ArrangementProperties.PathBass;
                        rsSong2014.ArrangementProperties.StandardTuning = (arrangement.Tuning == "E Standard" ? 1 : 0);

                        // <note time="58.366" linkNext="0" accent="0" bend="0" fret="7" hammerOn="0" harmonic="0" hopo="0" ignore="0" leftHand="-1" mute="0" palmMute="0" pluck="-1" pullOff="0" slap="-1" slideTo="-1" string="3" sustain="0.108" tremolo="0" harmonicPinch="0" pickDirection="0" rightHand="-1" slideUnpitchTo="-1" tap="0" vibrato="0" />
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Bend != 0)))
                        {
                            rsSong2014.ArrangementProperties.Bends = 1;
                        }
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Hopo != 0)))
                        {
                            rsSong2014.ArrangementProperties.Hopo = 1;
                        }
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.SlideTo != -1)))
                        {
                            rsSong2014.ArrangementProperties.Slides = 1;
                        }
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Sustain > 0)))
                        {
                            rsSong2014.ArrangementProperties.Sustain = 1;
                        }

                        // fixing times that are off
                        var lastEbeatsTime           = rsSong2014.Ebeats[rsSong2014.Ebeats.Length - 1].Time;
                        var lastPhraseIterationsTime = rsSong2014.PhraseIterations[rsSong2014.PhraseIterations.Length - 1].Time;

                        // tested ... not source of in game hangs
                        // confirm last PhraseIterations time is less than last Ebeats time
                        if (lastPhraseIterationsTime > lastEbeatsTime)
                        {
                            rsSong2014.PhraseIterations[rsSong2014.PhraseIterations.Length - 1].Time = lastEbeatsTime;
                            rsSong2014.Sections[rsSong2014.Sections.Length - 1].StartTime            = lastEbeatsTime;
                        }

                        // tested ... not source of in game hangs
                        // confirm SongLength at least equals last Ebeats time
                        if (rsSong2014.SongLength < lastEbeatsTime)
                        {
                            rsSong2014.SongLength = lastEbeatsTime;
                        }

                        using (var obj2 = new Rs2014Converter())
                            obj2.Song2014ToXml(rsSong2014, xmlFile, true);
                    }

                    // Adding Song Arrangement
                    try
                    {
                        data.Arrangements.Add(new Arrangement(attr2014, xmlFile));
                    }
                    catch (Exception ex)
                    {
                        // mainly for the benefit of convert2012 CLI users
                        Console.WriteLine(@"This CDLC could not be auto converted." + Environment.NewLine + "You can still try manually adding the arrangements and assets." + Environment.NewLine + ex.Message);
                    }
                }
            }
            if (convert)
            {
                // get rid of duplicate tone names
                tones2014 = tones2014.Where(p => p.Name != null)
                            .GroupBy(p => p.Name).Select(g => g.First()).ToList();
                data.TonesRS2014 = tones2014;
            }

            //Get Album Artwork DDS Files
            var artFiles = Directory.GetFiles(unpackedDir, "*.dds", SearchOption.AllDirectories);

            if (artFiles.Length < 1)
            {
                throw new DataException("No Album Artwork file found.");
            }
            if (artFiles.Length > 1)
            {
                throw new DataException("More than one Album Artwork file found.");
            }

            var targetArtFiles = new List <DDSConvertedFile>();

            data.AlbumArtPath = artFiles[0];
            targetArtFiles.Add(new DDSConvertedFile()
            {
                sizeX = 256, sizeY = 256, sourceFile = artFiles[0], destinationFile = artFiles[0].CopyToTempFile(".dds")
            });
            data.ArtFiles = targetArtFiles;

            //Audio files
            var targetAudioFiles = new List <string>();
            var audioFiles       = Directory.GetFiles(unpackedDir, "*.ogg", SearchOption.AllDirectories);

            if (audioFiles.Length < 1)
            {
                throw new DataException("No Audio file found.");
            }
            if (audioFiles.Length > 2)
            {
                throw new DataException("Too many Audio files found.");
            }

            int i;

            for (i = 0; i < audioFiles.Length; i++)
            {
                if (convert && audioFiles[i].Contains("_fixed.ogg")) // use it
                {
                    break;
                }
                if (!convert && !audioFiles[i].Contains("_fixed.ogg"))
                {
                    break;
                }
            }
            // FIXME: platform specific decode is broken
            var sourcePlatform = unpackedDir.GetPlatform();

            if (targetPlatform.IsConsole != (sourcePlatform = audioFiles[i].GetAudioPlatform()).IsConsole)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(audioFiles[i]), String.Format("{0}_cap.ogg", Path.GetFileNameWithoutExtension(audioFiles[i])));
                OggFile.ConvertAudioPlatform(audioFiles[i], newFile);
                audioFiles[i] = newFile;
            }

            targetAudioFiles.Add(audioFiles[i]);

            if (!targetAudioFiles.Any())
            {
                throw new DataException("Audio file not found.");
            }

            var a = new FileInfo(audioFiles[i]);

            data.OggPath = a.FullName;

            //AppID
            if (!sourcePlatform.IsConsole)
            {
                if (!convert)
                {
                    var appidFile = Directory.GetFiles(unpackedDir, "*APP_ID*", SearchOption.AllDirectories);
                    if (appidFile.Length > 0)
                    {
                        data.AppId = File.ReadAllText(appidFile[0]);
                    }
                }
                else
                {
                    data.AppId = "248750";
                }
            }

            try
            {
                // Package Info
                var versionFile = Directory.EnumerateFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories).FirstOrDefault();
                if (versionFile != null)
                {
                    var tkInfo = GeneralExtensions.ReadToolkitInfo(versionFile);
                    data.PackageVersion = tkInfo.PackageVersion;
                    data.PackageComment = tkInfo.PackageComment;
                }
                else
                {
                    data.PackageVersion = "1";
                    data.PackageComment = "";
                }
            }
            catch { }

            if (convert)
            {
                data.Tones = null;
            }

            return(data);
        }
        public static void Generate(string packagePath, DLCPackageData info, GamePlatform platform, PackageMagic? xboxPackageType)
        {
            switch (platform)
            {
                case GamePlatform.XBox360:
                    if (!Directory.Exists(xboxWorkDir))
                        Directory.CreateDirectory(xboxWorkDir);
                    break;
                case GamePlatform.PS3:
                    if (!Directory.Exists(ps3WorkDir))
                        Directory.CreateDirectory(ps3WorkDir);
                    break;
                }

            using (var packPsarcStream = new MemoryStream())
            {
                GeneratePackagePsarc(packPsarcStream, info, platform);
                switch (platform) {
                    case GamePlatform.Pc:
                        using (var fl = File.Create(packagePath))
                            RijndaelEncryptor.Encrypt(packPsarcStream, fl, RijndaelEncryptor.DLCKey);
                        break;
                    case GamePlatform.XBox360:
                        BuildXBox360Package(packagePath, info, XBox360Files, xboxPackageType);
                        break;
                    case GamePlatform.PS3:
                        EncryptPS3EdatFiles(packagePath);
                        break;
                }
            }

            try {
                foreach (var sngTmpFile in SNGTmpFiles)
                {
                    if (File.Exists(sngTmpFile))
                        File.Delete(sngTmpFile);
                }
            } catch { /*Have no problem if don't delete*/ }

            XBox360Files.Clear();
            PS3Files.Clear();
            SNGTmpFiles.Clear();
        }
 private static string GetOgg(this GamePlatform platform, DLCPackageData info)
 {
     switch (platform) {
         case GamePlatform.Pc:
             return info.OggPath;
         case GamePlatform.XBox360:
             return info.OggXBox360Path;
         case GamePlatform.PS3:
             return info.OggPS3Path;
         default:
             throw new InvalidOperationException("Unexpected game platform value");
     }
 }
        private static void GeneratePackagePsarc(Stream output, DLCPackageData info, GamePlatform platform)
        {
            IList<Stream> toneStreams = new List<Stream>();
            using (var appIdStream = new MemoryStream())
            using (var packageListStream = new MemoryStream())
            using (var songPsarcStream = new MemoryStream())
            {
                try
                {
                    var packPsarc = new PSARC.PSARC();
                    var packageListWriter = new StreamWriter(packageListStream);

                    if (platform == GamePlatform.Pc)
                    {
                        GenerateAppId(appIdStream, info.AppId);
                        packPsarc.AddEntry("APP_ID", appIdStream);
                    }

                    packageListWriter.WriteLine(info.Name);

                    GenerateSongPsarc(songPsarcStream, info, platform);
                    string songFileName = String.Format("{0}.psarc", info.Name);
                    packPsarc.AddEntry(songFileName, songPsarcStream);
                    songPsarcStream.WriteTmpFile(songFileName, platform);

                    for (int i = 0; i < info.Tones.Count; i++)
                    {
                        var tone = info.Tones[i];
                        var tonePsarcStream = new MemoryStream();
                        toneStreams.Add(tonePsarcStream);

                        var toneKey = info.Name + "_" + tone.Name == null ? "Default" : tone.Name.Replace(' ', '_');

                        GenerateTonePsarc(tonePsarcStream, toneKey, tone);
                        string toneEntry = String.Format("DLC_Tone_{0}.psarc", toneKey);
                        packPsarc.AddEntry(toneEntry, tonePsarcStream);
                        tonePsarcStream.WriteTmpFile(toneEntry, platform);
                        if (i + 1 != info.Tones.Count)
                            packageListWriter.WriteLine("DLC_Tone_{0}", toneKey);
                        else
                            packageListWriter.Write("DLC_Tone_{0}", toneKey);
                    }

                    packageListWriter.Flush();
                    packageListStream.Seek(0, SeekOrigin.Begin);
                    if (platform != GamePlatform.PS3)
                    {
                        string packageList = "PackageList.txt";
                        packPsarc.AddEntry(packageList, packageListStream);
                        packageListStream.WriteTmpFile(packageList, platform);
                    }
                    packPsarc.Write(output);
                    output.Flush();
                    output.Seek(0, SeekOrigin.Begin);
                }
                finally
                {
                    foreach (var stream in toneStreams)
                    {
                        try
                        {
                            stream.Dispose();
                        }
                        catch { }
                    }
                }
            }
        }
        private void FillPackageCreatorForm(DLCPackageData info, string filesBaseDir)
        {
            RS2012.Checked = info.GameVersion == GameVersion.RS2012;
            RS2014.Checked = info.GameVersion == GameVersion.RS2014;

            platformPC.Checked = info.Pc;
            platformMAC.Checked = info.Mac;
            platformXBox360.Checked = info.XBox360;
            platformPS3.Checked = info.PS3;

            PackageVersion = info.PackageVersion;

            TonesLB.Items.Clear();
            switch (CurrentGameVersion) {
                case GameVersion.RS2012:
                    if (info.Tones == null)
                        info.Tones = new List<Tone>();
                    if (info.Tones.Count == 0)
                        info.Tones.Add(CreateNewTone());

                    foreach (var tone in info.Tones) {
                        if (String.IsNullOrEmpty(tone.Key))
                            tone.Key = tone.Name.GetValidName();

                        TonesLB.Items.Add(tone);
                    }
                    break;
                case GameVersion.RS2014:
                    if (info.TonesRS2014 == null)
                        info.TonesRS2014 = new List<Tone2014>();
                    if (info.TonesRS2014.Count == 0)
                        info.TonesRS2014.Add(CreateNewTone());

                    foreach (var toneRS2014 in info.TonesRS2014) {
                        if (String.IsNullOrEmpty(toneRS2014.Key))
                            toneRS2014.Key = toneRS2014.Name.GetValidName();

                        TonesLB.Items.Add(toneRS2014);
                    }
                    break;
            }

            var BasePath = Path.GetDirectoryName(filesBaseDir);

            // Song INFO
            DlcNameTB.Text = info.Name;

            PopulateAppIdCombo();
            Application.DoEvents();
            AppIdTB.Text = info.AppId;
            SelectComboAppId(info.AppId);

            AlbumTB.Text = info.SongInfo.Album;
            SongDisplayNameTB.Text = info.SongInfo.SongDisplayName;
            SongDisplayNameSortTB.Text = info.SongInfo.SongDisplayNameSort;
            YearTB.Text = info.SongInfo.SongYear.ToString();
            ArtistTB.Text = info.SongInfo.Artist;
            ArtistSortTB.Text = info.SongInfo.ArtistSort;
            AverageTempoTB.Text = info.SongInfo.AverageTempo.ToString();

            // Album art
            AlbumArtPath = BasePath.AbsoluteTo(info.AlbumArtPath);

            // Audio file
            if (!String.IsNullOrEmpty(info.OggPath))
                AudioPath = BasePath.AbsoluteTo(info.OggPath);
            platformPC.Checked = !String.IsNullOrEmpty(info.OggPath);

            songVolumeBox.Value = Decimal.Round((decimal)info.Volume, 2);
            previewVolumeBox.Value = (info.PreviewVolume != null) ? Decimal.Round((decimal)info.PreviewVolume, 2) : songVolumeBox.Value;

            //if (platformXBox360.Checked)
            //    rbuttonSignatureLIVE.Checked = info.SignatureType == PackageMagic.LIVE;

            ArrangementLB.Items.Clear();
            foreach (var arrangement in info.Arrangements) {
                arrangement.SongXml.File = BasePath.AbsoluteTo(arrangement.SongXml.File);

                if (arrangement.ToneBase == null)
                {
                    switch (CurrentGameVersion) {
                        case GameVersion.RS2012:
                            arrangement.ToneBase = info.Tones[0].Name;
                            break;
                        case GameVersion.RS2014:
                            arrangement.ToneBase = info.TonesRS2014[0].Name;
                            break;
                    }
                }

                ArrangementLB.Items.Add(arrangement);
            }
        }
Exemplo n.º 22
0
        private static void PackXBox360(string sourcePath, string saveFileName, Platform platform, bool updateSng, bool updateManifest)
        {
            if (updateSng && platform.version == GameVersion.RS2014)
            {
                UpdateSng2014(sourcePath, platform);
                UpdateManifest2014(sourcePath, platform);
            }

            var songData    = new DLCPackageData();
            var packageRoot = Path.Combine(sourcePath, ROOT_XBox360);

            // If 'Root' directory doesn't exist the packing is a conversion process from another platform
            if (!Directory.Exists(packageRoot))
            {
                var songXmlFiles = Directory.EnumerateFiles(sourcePath, "*_*.xml", SearchOption.AllDirectories);

                var songTitle = String.Empty;
                foreach (var xml in songXmlFiles)
                {
                    if (Path.GetFileNameWithoutExtension(xml).ToLower().Contains("vocal") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("showlight"))
                    {
                        continue;
                    }

                    var song = Song2014.LoadFromFile(xml);

                    songData.SongInfo = new SongInfo();
                    songData.SongInfo.SongDisplayName = songTitle = song.Title;
                    songData.SongInfo.Artist          = song.ArtistName;

                    songData.SignatureType = PackageMagic.CON;
                    break;
                }

                var directoryList = Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories);
                var fileList      = Directory.EnumerateFiles(sourcePath, "*.*", SearchOption.AllDirectories);

                // MAKE THE XBOX360 EXPECTED STRUCTURE TO PACK WORK
                var newPackageName = songTitle.GetValidSongName(songTitle).ToLower();
                var newSongDir     = Path.Combine(packageRoot, newPackageName);

                // Creating new directories
                Directory.CreateDirectory(packageRoot);
                Directory.CreateDirectory(newSongDir);

                // Create PackageList file
                var packListFile = Path.Combine(packageRoot, "PackageList.txt");
                File.WriteAllText(packListFile, newPackageName);

                // Move directories to new path
                foreach (string dir in directoryList)
                {
                    Directory.CreateDirectory(dir.Replace(sourcePath, newSongDir));
                }

                // Move files to new path
                foreach (string file in fileList)
                {
                    File.Move(file, file.Replace(sourcePath, newSongDir));
                }

                // Delete old empty directories
                foreach (string emptyDir in directoryList)
                {
                    DirectoryExtension.SafeDelete(emptyDir);
                }
            }

            foreach (var directory in Directory.EnumerateDirectories(packageRoot))
            {
                PackInnerXBox360(packageRoot, directory);
            }

            IEnumerable <string> xboxHeaderFiles = Directory.EnumerateFiles(sourcePath, "*.txt", SearchOption.TopDirectoryOnly);

            if (xboxHeaderFiles.Count() == 1)
            {
                foreach (var file in xboxHeaderFiles)
                {
                    try
                    {
                        string[] xboxHeader = File.ReadAllLines(file);
                        if (xboxHeader != null && xboxHeader.Length > 73)
                        {
                            if (xboxHeader[0].IndexOf("LIVE") > 0)
                            {
                                songData.SignatureType = PackageMagic.LIVE;

                                for (int i = 2; i <= 48; i = i + 3)
                                {
                                    long id   = Convert.ToInt64(xboxHeader[i].GetHeaderValue(), 16);
                                    int  bit  = Convert.ToInt32(xboxHeader[i + 1].GetHeaderValue());
                                    int  flag = Convert.ToInt32(xboxHeader[i + 2].GetHeaderValue());

                                    if (id != 0)
                                    {
                                        songData.XBox360Licenses.Add(new XBox360License()
                                        {
                                            ID = id, Bit = bit, Flag = flag
                                        });
                                    }
                                }
                            }

                            string songInfo = xboxHeader[74];

                            int    index      = songInfo.IndexOf(" by ");
                            string songTitle  = (index > 0) ? songInfo.Substring(0, index) : songInfo;
                            string songArtist = (index > 4) ? songInfo.Substring(index + 4) : songInfo;

                            if (!String.IsNullOrEmpty(songInfo))
                            {
                                songData.SongInfo = new SongInfo();
                                songData.SongInfo.SongDisplayName = songInfo;
                                songData.SongInfo.Artist          = songInfo;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException("XBox360 header file (.txt) not found or is invalid. " + Environment.NewLine +
                                                       "The file is in the same level at 'Root' folder along with the files: 'Content image.png' and 'Package image.png' and no other file .txt can be here.", ex);
                    }
                }
            }

            IEnumerable <string> xboxFiles = Directory.EnumerateFiles(packageRoot);

            DLCPackageCreator.BuildXBox360Package(saveFileName, songData, xboxFiles, platform.version);

            foreach (var file in xboxFiles)
            {
                if (Path.GetExtension(file) == ".psarc" && File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
        private static void GeneratePsarcsForRS1(Stream output, DLCPackageData info, Platform platform)
        {
            IList<Stream> toneStreams = new List<Stream>();
            using (var toolkitVersionStream = new MemoryStream())
            using (var appIdStream = new MemoryStream())
            using (var packageListStream = new MemoryStream())
            using (var songPsarcStream = new MemoryStream())
            {
                try
                {
                    var packPsarc = new PSARC.PSARC();
                    var packageListWriter = new StreamWriter(packageListStream);

                    // TOOLKIT VERSION
                    GenerateToolkitVersion(toolkitVersionStream);
                    packPsarc.AddEntry("toolkit.version", toolkitVersionStream);

                    // APP ID
                    if (platform.platform == GamePlatform.Pc)
                    {
                        GenerateAppId(appIdStream, info.AppId, platform);
                        packPsarc.AddEntry("APP_ID", appIdStream);
                    }

                    packageListWriter.WriteLine(info.Name);

                    GenerateSongPsarcRS1(songPsarcStream, info, platform);
                    string songFileName = String.Format("{0}.psarc", info.Name);
                    packPsarc.AddEntry(songFileName, songPsarcStream);
                    songPsarcStream.WriteTmpFile(songFileName, platform);

                    for (int i = 0; i < info.Tones.Count; i++)
                    {
                        var tone = info.Tones[i];
                        var tonePsarcStream = new MemoryStream();
                        // TODO: generate single tone.manifest.json file that has multiple tones
                        // currently generating multiple tone.manifest.json files
                        toneStreams.Add(tonePsarcStream);
                        var toneKey = info.Name + "_" + tone.Name == null ? "Default" : tone.Name.Replace(' ', '_');
                        GenerateTonePsarc(tonePsarcStream, toneKey, tone);
                        string toneEntry = String.Format("DLC_Tone_{0}.psarc", toneKey);
                        packPsarc.AddEntry(toneEntry, tonePsarcStream);
                        tonePsarcStream.WriteTmpFile(toneEntry, platform);
                        if (i + 1 != info.Tones.Count)
                            packageListWriter.WriteLine("DLC_Tone_{0}", toneKey);
                        else
                            packageListWriter.Write("DLC_Tone_{0}", toneKey);
                    }

                    packageListWriter.Flush();
                    packageListStream.Seek(0, SeekOrigin.Begin);
                    if (platform.platform != GamePlatform.PS3)
                    {
                        string packageList = "PackageList.txt";
                        packPsarc.AddEntry(packageList, packageListStream);
                        packageListStream.WriteTmpFile(packageList, platform);
                    }
                    packPsarc.Write(output, false);
                }
                finally
                {
                    foreach (var stream in toneStreams)
                    {
                        try
                        {
                            stream.Dispose();
                        }
                        catch { }
                    }
                }
            }
        }
        private DLCPackageData GetPackageData()
        {
            if (CurrentGameVersion == GameVersion.RS2014)
            {
                if (!platformPC.Checked && !platformMAC.Checked && !platformXBox360.Checked && !platformPS3.Checked)
                {
                    MessageBox.Show("Error: No game platform selected", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return null;
                }
            }
            else
            {
                if (!platformPC.Checked && !platformXBox360.Checked && !platformPS3.Checked)
                {
                    MessageBox.Show("Error: No game platform selected", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return null;
                }
            }
            int year, tempo;
            if (String.IsNullOrEmpty(DLCName))
            {
                DlcNameTB.Focus();
                return null;
            }
            if (DLCName == SongTitle) {
                MessageBox.Show("Error: DLC name can't be the same of song name", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                DlcNameTB.Focus();
                return null;
            }
            if (String.IsNullOrEmpty(SongTitle))
            {
                SongDisplayNameTB.Focus();
                return null;
            }
            if (string.IsNullOrEmpty(Album))
            {
                AlbumTB.Focus();
                return null;
            }
            if (String.IsNullOrEmpty(Artist))
            {
                ArtistTB.Focus();
                return null;
            }
            if (!Int32.TryParse(AlbumYear, out year))
            {
                YearTB.Focus();
                return null;
            }
            if (!Int32.TryParse(AverageTempo, out tempo))
            {
                AverageTempoTB.Focus();
                return null;
            }
            if (String.IsNullOrEmpty(AppId))
            {
                AppIdTB.Focus();
                return null;
            }
            if (String.IsNullOrEmpty(PackageVersion))
                PackageVersion = "1";

            //Album Art validation (alert only)
            if (String.IsNullOrEmpty(AlbumArtPath) || !File.Exists(AlbumArtPath))
            {
                var diagResult = MessageBox.Show("Warning: Album Art file not found!" + Environment.NewLine +
                                                 "If you click 'Yes' default album art will be defined." + Environment.NewLine +
                                                 "Else you click 'No' you want to select the Album Art File.",
                                                 MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                switch (diagResult)
                {
                    case DialogResult.No:
                        AlbumArtPathTB.Focus();
                        return null;
                    default:
                        break;
                }
            }

            if (!File.Exists(AudioPath))
            {
                audioPathTB.Focus();
                return null;
            }

            string audioPreviewPath = null;
            if (CurrentGameVersion == GameVersion.RS2014)
            {
                audioPreviewPath = Path.Combine(Path.GetDirectoryName(AudioPath), String.Format(Path.GetFileNameWithoutExtension(AudioPath) + "_preview" + Path.GetExtension(AudioPath)));
                if (!File.Exists(audioPreviewPath))
                {
                    if (MessageBox.Show("Warning: Song Preview not found!" + Environment.NewLine +
                                        "File: " + audioPreviewPath + Environment.NewLine +
                                        "If you click 'Yes' the song file will be used for the song preview." + Environment.NewLine +
                                        "Else you click 'No' you could fix the problem before package generation.", MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        audioPathTB.Focus();
                        return null;
                    }
                }
            }

            var arrangements = ArrangementLB.Items.OfType<Arrangement>().ToList();
            if (arrangements.Count(x => x.ArrangementType == ArrangementType.Vocal) > 1)
            {
                MessageBox.Show("Error: Multiple Vocals arrangement found", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
            foreach (var arr in arrangements)
            {
                if (!File.Exists(arr.SongXml.File))
                {
                    MessageBox.Show("Error: Song Xml File doesn't exist: " +  arr.SongXml.File, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return null;
                }
                arr.SongFile.File = "";
            }

            List<Tone> tones = new List<Tone>();
            if (CurrentGameVersion == GameVersion.RS2012)
                tones = TonesLB.Items.OfType<Tone>().ToList();

            List<Tone2014> tonesRS2014 = new List<Tone2014>();
            if (CurrentGameVersion == GameVersion.RS2014)
                tonesRS2014 = TonesLB.Items.OfType<Tone2014>().ToList();

            //string liveSignatureID = xboxLicense0IDTB.Text.Trim();
            //if (rbuttonSignatureLIVE.Checked && String.IsNullOrEmpty(liveSignatureID))
            //{
            //    MessageBox.Show("Error: If LIVE signature is selected, your LIVE signature ID is required (in HEX format)", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    xboxLicense0IDTB.Focus();
            //    return null;
            //}
            //if (rbuttonSignatureLIVE.Checked && !new Regex("([A-Fa-f0-9]{2})+$").IsMatch(liveSignatureID))
            //{
            //    MessageBox.Show("Error: LIVE signature ID seems to be not valid, need a HEX value", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    xboxLicense0IDTB.Focus();
            //    return null;
            //}

            //List<XBox360License> licenses = new List<XBox360License>();
            //if (rbuttonSignatureLIVE.Checked)
            //{
            //    licenses.Add(new XBox360License() { ID = Convert.ToInt64(xboxLicense0IDTB.Text.Trim(), 16), Bit = 1, Flag = 1 });
            //}

            var songVol = (float)songVolumeBox.Value;
            var previewVol = (!String.IsNullOrEmpty(audioPreviewPath)) ? (float)songVolumeBox.Value : songVol;

            var data = new DLCPackageData()
            {
                GameVersion = CurrentGameVersion,
                Pc = platformPC.Checked,
                Mac = platformMAC.Checked,
                XBox360 = platformXBox360.Checked,
                PS3 = platformPS3.Checked,
                Name = DlcNameTB.Text,
                AppId = AppIdTB.Text,

                SongInfo = new SongInfo
                {
                    SongDisplayName = SongDisplayNameTB.Text,
                    SongDisplayNameSort = String.IsNullOrEmpty(SongDisplayNameSortTB.Text.Trim()) ? SongDisplayNameTB.Text : SongDisplayNameSortTB.Text,
                    Album = AlbumTB.Text,
                    SongYear = year,
                    Artist = ArtistTB.Text,
                    ArtistSort = String.IsNullOrEmpty(ArtistSortTB.Text.Trim()) ? ArtistTB.Text : ArtistSortTB.Text,
                    AverageTempo = tempo
                },

                //AlbumArt = AlbumArtPath,
                //AudioPreview = audioPreviewPath,
                //Arrangements = arrangements,
                Tones = tones,
                //TonesRS2014 = tonesRS2014,
                Volume = songVol,
                PreviewVolume = previewVol,
                SignatureType = PackageMagic.CON,
                PackageVersion = PackageVersion
            };

            return data;
        }
        private void FillPackageCreatorForm(DLCPackageData info, string filesBaseDir)
        {
            RS2012.Checked = info.GameVersion == GameVersion.RS2012;
            RS2014.Checked = info.GameVersion == GameVersion.RS2014;

            platformPC.Checked = info.Pc;
            platformMAC.Checked = info.Mac;
            platformXBox360.Checked = info.XBox360;
            platformPS3.Checked = info.PS3;

            PackageVersion = info.PackageVersion;

            TonesLB.Items.Clear();
            switch (CurrentGameVersion) {
                case GameVersion.RS2012:
                    if (info.Tones == null)
                        info.Tones = new List<Tone>();
                    if (info.Tones.Count == 0)
                        info.Tones.Add(CreateNewTone());

                    foreach (var tone in info.Tones) {
                        if (String.IsNullOrEmpty(tone.Key))
                            tone.Key = tone.Name.GetValidName();

                        TonesLB.Items.Add(tone);
                    }
                    break;
                case GameVersion.RS2014:
                    if (info.TonesRS2014.Count == 0)
                        info.TonesRS2014.Add(CreateNewTone());

                    foreach (var toneRS2014 in info.TonesRS2014) {
                        if (String.IsNullOrEmpty(toneRS2014.Key))
                            toneRS2014.Key = toneRS2014.Name.GetValidName();

                        TonesLB.Items.Add(toneRS2014);
                    }
                    break;
            }

            var BasePath = Path.GetDirectoryName(filesBaseDir);

            // Song INFO
            DlcNameTB.Text = info.Name;

            PopulateAppIdCombo();
            Application.DoEvents();
            AppIdTB.Text = info.AppId;
            SelectComboAppId(info.AppId);

            AlbumTB.Text = info.SongInfo.Album;
            SongDisplayNameTB.Text = info.SongInfo.SongDisplayName;
            SongDisplayNameSortTB.Text = info.SongInfo.SongDisplayNameSort;
            YearTB.Text = info.SongInfo.SongYear.ToString();
            ArtistTB.Text = info.SongInfo.Artist;
            ArtistSortTB.Text = info.SongInfo.ArtistSort;
            AverageTempoTB.Text = info.SongInfo.AverageTempo.ToString();

            // Album art
            //AlbumArtPath = BasePath.AbsoluteTo(info.AlbumArt.Path);

            // Audio file
            //if (info.Audio != null)
            //    AudioPath = BasePath.AbsoluteTo(info.Audio.Path);
            //platformPC.Checked = !String.IsNullOrEmpty(info.Audio.Path);

            songVolumeBox.Value = Decimal.Round((decimal)info.Volume, 2);
            previewVolumeBox.Value = (info.PreviewVolume != null) ? Decimal.Round((decimal)info.PreviewVolume, 2) : songVolumeBox.Value;

            //if (platformXBox360.Checked)
            //    rbuttonSignatureLIVE.Checked = info.SignatureType == PackageMagic.LIVE;

            ArrangementLB.Items.Clear();
            foreach (var arrangement in info.Arrangements) {
                arrangement.SongXml.File = BasePath.AbsoluteTo(arrangement.SongXml.File);

                if (arrangement.ToneBase == null)
                {
                    switch (CurrentGameVersion) {
                        case GameVersion.RS2012:
                            arrangement.ToneBase = info.Tones[0].Name;
                            break;
                        case GameVersion.RS2014:
                            arrangement.ToneBase = info.TonesRS2014[0].Name;
                            break;
                    }
                }
                if (arrangement.ArrangementType != ArrangementType.Vocal)
                {
                    try
                    {
                        //Load tunig from Arrangement
                        var tuning = TuningDefinitionRepository.Instance().SelectAny(arrangement.TuningStrings, CurrentGameVersion);
                        if (tuning == null)
                        {
                            tuning = new TuningDefinition();
                            tuning.Tuning = arrangement.TuningStrings;
                            tuning.Custom = true;
                            tuning.GameVersion = CurrentGameVersion;
                            tuning.Name = tuning.UIName = arrangement.Tuning;
                            if (String.IsNullOrEmpty(tuning.Name))
                            {
                                tuning.Name = tuning.UIName = TuningDefinition.NameFromStrings(arrangement.TuningStrings, arrangement.ArrangementType == ArrangementType.Bass);
                            }

                            TuningDefinitionRepository.Instance().Add(tuning, true);
                        }
                        tuning = null; //Cleanup after
                    }
                    catch { /* Handle old types of *.dlc.xml */ }
                }
                ArrangementLB.Items.Add(arrangement);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Loads required DLC info from folder.
        /// </summary>
        /// <returns>The DLCPackageData info.</returns>
        /// <param name="unpackedDir">Unpacked dir.</param>
        /// <param name="targetPlatform">Target platform.</param>
        public static DLCPackageData LoadFromFolder(string unpackedDir, Platform targetPlatform)
        {
            var data = new DLCPackageData();

            data.GameVersion   = GameVersion.RS2014;
            data.SignatureType = PackageMagic.CON;

            //Arrangements / Tones
            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();

            //Source platform + audio files
            var      targetAudioFiles = new List <string>();
            var      sourceAudioFiles = Directory.GetFiles(unpackedDir, "*.wem", SearchOption.AllDirectories);
            Platform sourcePlatform   = new Platform(GamePlatform.Pc, GameVersion.None);

            foreach (var file in sourceAudioFiles)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(file), String.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)));
                if (targetPlatform.IsConsole != (sourcePlatform = file.GetAudioPlatform()).IsConsole)
                {
                    OggFile.ConvertAudioPlatform(file, newFile);
                    targetAudioFiles.Add(newFile);
                }
                else
                {
                    targetAudioFiles.Add(file);
                }
            }

            if (!targetAudioFiles.Any())
            {
                throw new InvalidDataException("Audio files not found.");
            }

            //Load files
            var jsonFiles = Directory.GetFiles(unpackedDir, "*.json", SearchOption.AllDirectories);

            foreach (var json in jsonFiles)
            {
                var attr = Manifest2014 <Attributes2014> .LoadFromFile(json).Entries.ToArray()[0].Value.ToArray()[0].Value;

                var xmlName = attr.SongXml.Split(':')[3];
                var xmlFile = Directory.GetFiles(unpackedDir, xmlName + ".xml", SearchOption.AllDirectories)[0];

                if (attr.Phrases != null)
                {
                    if (data.SongInfo == null)
                    {
                        // Fill Package Data
                        data.Name          = attr.DLCKey;
                        data.Volume        = attr.SongVolume;
                        data.PreviewVolume = (float)(attr.PreviewVolume ?? data.Volume);

                        // Fill SongInfo
                        data.SongInfo = new SongInfo();
                        data.SongInfo.SongDisplayName     = attr.SongName;
                        data.SongInfo.SongDisplayNameSort = attr.SongNameSort;
                        data.SongInfo.Album        = attr.AlbumName;
                        data.SongInfo.SongYear     = attr.SongYear ?? 0;
                        data.SongInfo.Artist       = attr.ArtistName;
                        data.SongInfo.ArtistSort   = attr.ArtistNameSort;
                        data.SongInfo.AverageTempo = (int)attr.SongAverageTempo;
                    }

                    // Adding Tones
                    foreach (var jsonTone in attr.Tones)
                    {
                        if (jsonTone == null)
                        {
                            continue;
                        }
                        var key = jsonTone.Key;
                        if (data.TonesRS2014.All(t => t.Key != key))
                        {
                            data.TonesRS2014.Add(jsonTone);
                        }
                    }

                    // Adding Arrangement
                    data.Arrangements.Add(new Arrangement(attr, xmlFile));
                }
                else
                {
                    var voc = new Arrangement();
                    voc.Name            = attr.JapaneseVocal == true ? ArrangementName.JVocals : ArrangementName.Vocals;
                    voc.ArrangementType = ArrangementType.Vocal;
                    voc.ScrollSpeed     = 20;
                    voc.SongXml         = new SongXML {
                        File = xmlFile
                    };
                    voc.SongFile = new SongFile {
                        File = ""
                    };
                    voc.CustomFont = attr.JapaneseVocal == true;
                    // Get symbols stuff, write plain sng to disk.
                    var fontSng = Directory.GetFiles(unpackedDir, xmlName + ".sng", SearchOption.AllDirectories)[0];
                    var vocSng  = Sng2014HSL.Sng2014File.LoadFromFile(fontSng, sourcePlatform);
                    if (vocSng.IsCustomFont())
                    {
                        voc.CustomFont = true;
                        voc.FontSng    = fontSng;
                        vocSng.WriteChartData(fontSng, new Platform(GamePlatform.Pc, GameVersion.None));
                    }
                    voc.Sng2014 = Sng2014HSL.Sng2014File.ConvertXML(xmlFile, ArrangementType.Vocal, voc.FontSng);

                    // Adding Arrangement
                    data.Arrangements.Add(voc);
                }
            }

            //Get DDS Files + hacky reuse if exist
            var ddsFiles = Directory.GetFiles(unpackedDir, "album_*.dds", SearchOption.AllDirectories);

            if (ddsFiles.Length > 0)
            {
                var ddsFilesC = new List <DDSConvertedFile>();
                foreach (var file in ddsFiles)
                {
                    switch (Path.GetFileNameWithoutExtension(file).Split('_')[2])
                    {
                    case "256":
                        data.AlbumArtPath = file;
                        ddsFilesC.Add(new DDSConvertedFile()
                        {
                            sizeX = 256, sizeY = 256, sourceFile = file, destinationFile = file.CopyToTempFile(".dds")
                        });
                        break;

                    case "128":
                        ddsFilesC.Add(new DDSConvertedFile()
                        {
                            sizeX = 128, sizeY = 128, sourceFile = file, destinationFile = file.CopyToTempFile(".dds")
                        });
                        break;

                    case "64":
                        ddsFilesC.Add(new DDSConvertedFile()
                        {
                            sizeX = 64, sizeY = 64, sourceFile = file, destinationFile = file.CopyToTempFile(".dds")
                        });
                        break;
                    }
                }
                data.ArtFiles = ddsFilesC;
            }
            // Lyric Art
            var LyricArt = Directory.GetFiles(unpackedDir, "lyrics_*.dds", SearchOption.AllDirectories);

            if (LyricArt.Any())
            {
                data.LyricArtPath = LyricArt[0];
            }

            //Get other files
            string   audioPath = null, audioPreviewPath = null;
            FileInfo a = new FileInfo(targetAudioFiles[0]);
            FileInfo b = null;

            if (targetAudioFiles.Count == 2)
            {
                b = new FileInfo(targetAudioFiles[1]);

                if (a.Length > b.Length)
                {
                    audioPath        = a.FullName;
                    audioPreviewPath = b.FullName;
                }
                else
                {
                    audioPath        = b.FullName;
                    audioPreviewPath = a.FullName;
                }
            }
            else
            {
                audioPath = a.FullName;
            }

            data.OggPath = audioPath;

            //Make Audio preview with expected name when rebuild
            if (!String.IsNullOrEmpty(audioPreviewPath))
            {
                var newPreviewFileName = Path.Combine(Path.GetDirectoryName(audioPath), String.Format("{0}_preview{1}", Path.GetFileNameWithoutExtension(audioPath), Path.GetExtension(audioPath)));
                File.Move(audioPreviewPath, newPreviewFileName);
                data.OggPreviewPath = newPreviewFileName;
            }

            //AppID
            var appidFile = Directory.GetFiles(unpackedDir, "*.appid", SearchOption.AllDirectories);

            if (appidFile.Length > 0)
            {
                data.AppId = File.ReadAllText(appidFile[0]);
            }

            //Package version
            var versionFile = Directory.GetFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories);

            if (versionFile.Length > 0)
            {
                data.PackageVersion = GeneralExtensions.ReadPackageVersion(versionFile[0]);
            }
            else
            {
                data.PackageVersion = "1";
            }

            return(data);
        }
        private static void GenerateSongPsarcRS1(Stream output, DLCPackageData info, Platform platform)
        {
            var soundBankName = String.Format("Song_{0}", info.Name);

            try
            {
                Stream albumArtStream = null,
                       audioStream = null;

                string albumArtPath;
                if (File.Exists(info.AlbumArtPath)) {
                    albumArtPath = info.AlbumArtPath;
                } else {
                    using (var defaultArtStream = new MemoryStream(Resources.albumart)) {
                        albumArtPath = GeneralExtensions.GetTempFileName(".dds");
                        defaultArtStream.WriteFile(albumArtPath);
                        defaultArtStream.Dispose();
                        TMPFILES_ART.Add(albumArtPath);
                    }
                }

                var ddsfiles = info.ArtFiles;
                if (ddsfiles == null) {
                    ddsfiles = new List<DDSConvertedFile>();
                    ddsfiles.Add(new DDSConvertedFile() { sizeX = 512, sizeY = 512, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                    ToDDS(ddsfiles);

                    // Save for reuse
                    info.ArtFiles = ddsfiles;
                }

                albumArtStream = new FileStream(ddsfiles[0].destinationFile, FileMode.Open, FileAccess.Read, FileShare.Read);

                // AUDIO
                var audioFile = info.OggPath;
                if (File.Exists(audioFile))
                    if (platform.IsConsole != audioFile.GetAudioPlatform().IsConsole)
                        audioStream = OggFile.ConvertAudioPlatform(audioFile);
                    else
                        audioStream = File.OpenRead(audioFile);
                else
                    throw new InvalidOperationException(String.Format("Audio file '{0}' not found.", audioFile));

                using (var aggregateGraphStream = new MemoryStream())
                using (var manifestStream = new MemoryStream())
                using (var xblockStream = new MemoryStream())
                using (var soundbankStream = new MemoryStream())
                using (var packageIdStream = new MemoryStream())
                using (var soundStream = OggFile.ConvertOgg(audioStream))
                using (var arrangementFiles = new DisposableCollection<Stream>()) {
                    var manifestBuilder = new ManifestBuilder {
                        AggregateGraph = new AggregateGraph.AggregateGraph {
                            SoundBank = new SoundBank { File = soundBankName + ".bnk" },
                            AlbumArt = new AlbumArt { File = info.AlbumArtPath }
                        }
                    };

                    foreach (var x in info.Arrangements) {
                        //Generate sng file in execution time
                        GenerateSNG(x, platform);

                        manifestBuilder.AggregateGraph.SongFiles.Add(x.SongFile);
                        manifestBuilder.AggregateGraph.SongXMLs.Add(x.SongXml);
                    }
                    manifestBuilder.AggregateGraph.XBlock = new XBlockFile { File = info.Name + ".xblock" };
                    manifestBuilder.AggregateGraph.Write(info.Name, platform.GetPathName(), platform, aggregateGraphStream);
                    aggregateGraphStream.Flush();
                    aggregateGraphStream.Seek(0, SeekOrigin.Begin);

                    {
                        var manifestData = manifestBuilder.GenerateManifest(info.Name, info.Arrangements, info.SongInfo, platform);
                        var writer = new StreamWriter(manifestStream);
                        writer.Write(manifestData);
                        writer.Flush();
                        manifestStream.Seek(0, SeekOrigin.Begin);
                    }

                    GameXblock<Entity>.Generate(info.Name, manifestBuilder.Manifest, manifestBuilder.AggregateGraph, xblockStream);
                    xblockStream.Flush();
                    xblockStream.Seek(0, SeekOrigin.Begin);

                    var soundFileName = SoundBankGenerator.GenerateSoundBank(info.Name, soundStream, soundbankStream, info.Volume, platform);
                    soundbankStream.Flush();
                    soundbankStream.Seek(0, SeekOrigin.Begin);

                    GenerateSongPackageId(packageIdStream, info.Name);

                    var songPsarc = new PSARC.PSARC();
                    songPsarc.AddEntry("PACKAGE_ID", packageIdStream);
                    songPsarc.AddEntry("AggregateGraph.nt", aggregateGraphStream);
                    songPsarc.AddEntry("Manifests/songs.manifest.json", manifestStream);
                    songPsarc.AddEntry(String.Format("Exports/Songs/{0}.xblock", info.Name), xblockStream);
                    songPsarc.AddEntry(String.Format("Audio/{0}/{1}.bnk", platform.GetPathName()[0], soundBankName), soundbankStream);
                    songPsarc.AddEntry(String.Format("Audio/{0}/{1}.ogg", platform.GetPathName()[0], soundFileName), soundStream);
                    songPsarc.AddEntry(String.Format("GRAssets/AlbumArt/{0}.dds", manifestBuilder.AggregateGraph.AlbumArt.Name), albumArtStream);

                    foreach (var x in info.Arrangements) {
                        var xmlFile = File.OpenRead(x.SongXml.File);
                        arrangementFiles.Add(xmlFile);
                        var sngFile = File.OpenRead(x.SongFile.File);
                        arrangementFiles.Add(sngFile);
                        songPsarc.AddEntry(String.Format("GR/Behaviors/Songs/{0}.xml", Path.GetFileNameWithoutExtension(x.SongXml.File)), xmlFile);
                        songPsarc.AddEntry(String.Format("GRExports/{0}/{1}.sng", platform.GetPathName()[1], Path.GetFileNameWithoutExtension(x.SongFile.File)), sngFile);
                    }
                    songPsarc.Write(output, false);
                    output.Flush();
                    output.Seek(0, SeekOrigin.Begin);
                }
            }
            finally
            {
            }
        }
Exemplo n.º 28
0
        private static void PackXBox360(string sourcePath, string saveFileName, Platform platform, bool updateSng, bool updateManifest)
        {
            if (updateSng && platform.version == GameVersion.RS2014)
            {
                UpdateSng2014(sourcePath, platform);
                UpdateManifest2014(sourcePath, platform);
            }

            var songData = new DLCPackageData();
            var packageRoot = Path.Combine(sourcePath, ROOT_XBox360);

            // If 'Root' directory doesn't exist the packing is a conversion process from another platform
            if (!Directory.Exists(packageRoot))
            {
                var songXmlFiles = Directory.EnumerateFiles(sourcePath, "*_*.xml", SearchOption.AllDirectories);

                var songTitle = String.Empty;
                foreach (var xml in songXmlFiles)
                {
                    if (Path.GetFileNameWithoutExtension(xml).ToLower().Contains("vocal") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("showlight"))
                        continue;

                    var song = Song2014.LoadFromFile(xml);

                    songData.SongInfo = new SongInfo();
                    songData.SongInfo.SongDisplayName = songTitle = song.Title;
                    songData.SongInfo.Artist = song.ArtistName;

                    songData.SignatureType = PackageMagic.CON;
                    break;
                }

                var directoryList = Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories);
                var fileList = Directory.EnumerateFiles(sourcePath, "*.*", SearchOption.AllDirectories);

                // MAKE THE XBOX360 EXPECTED STRUCTURE TO PACK WORK
                var newPackageName = songTitle.GetValidDlcKey(songTitle).ToLower();
                var newSongDir = Path.Combine(packageRoot, newPackageName);

                // Creating new directories
                Directory.CreateDirectory(packageRoot);
                Directory.CreateDirectory(newSongDir);

                // Create PackageList file
                var packListFile = Path.Combine(packageRoot, "PackageList.txt");
                File.WriteAllText(packListFile, newPackageName);

                // Move directories to new path
                foreach (string dir in directoryList)
                    Directory.CreateDirectory(dir.Replace(sourcePath, newSongDir));

                // Move files to new path
                foreach (string file in fileList)
                    File.Move(file, file.Replace(sourcePath, newSongDir));

                // Delete old empty directories
                foreach (string emptyDir in directoryList)
                    DirectoryExtension.SafeDelete(emptyDir);
            }

            foreach (var directory in Directory.EnumerateDirectories(packageRoot))
            {
                PackInnerXBox360(packageRoot, directory);
            }

            IEnumerable<string> xboxHeaderFiles = Directory.EnumerateFiles(sourcePath, "*.txt", SearchOption.TopDirectoryOnly);
            if (xboxHeaderFiles.Count() == 1)
            {
                foreach (var file in xboxHeaderFiles)
                {
                    try
                    {
                        string[] xboxHeader = File.ReadAllLines(file);
                        if (xboxHeader != null && xboxHeader.Length > 73)
                        {
                            if (xboxHeader[0].IndexOf("LIVE") > 0)
                            {
                                songData.SignatureType = PackageMagic.LIVE;

                                for (int i = 2; i <= 48; i = i + 3)
                                {
                                    long id = Convert.ToInt64(xboxHeader[i].GetHeaderValue(), 16);
                                    int bit = Convert.ToInt32(xboxHeader[i + 1].GetHeaderValue());
                                    int flag = Convert.ToInt32(xboxHeader[i + 2].GetHeaderValue());

                                    if (id != 0)
                                        songData.XBox360Licenses.Add(new XBox360License() { ID = id, Bit = bit, Flag = flag });
                                }
                            }

                            string songInfo = xboxHeader[74];

                            int index = songInfo.IndexOf(" by ");
                            string songTitle = (index > 0) ? songInfo.Substring(0, index) : songInfo;
                            string songArtist = (index > 4) ? songInfo.Substring(index + 4) : songInfo;

                            if (!String.IsNullOrEmpty(songInfo))
                            {
                                songData.SongInfo = new SongInfo();
                                songData.SongInfo.SongDisplayName = songInfo;
                                songData.SongInfo.Artist = songInfo;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException("XBox360 header file (.txt) not found or is invalid. " + Environment.NewLine +
                                                       "The file is in the same level at 'Root' folder along with the files: 'Content image.png' and 'Package image.png' and no other file .txt can be here.", ex);
                    }
                }
            }

            IEnumerable<string> xboxFiles = Directory.EnumerateFiles(packageRoot);
            DLCPackageCreator.BuildXBox360Package(saveFileName, songData, xboxFiles, platform.version);

            foreach (var file in xboxFiles)
                if (Path.GetExtension(file) == ".psarc" && File.Exists(file))
                    File.Delete(file);
        }
        private static void GenerateSongPsarc(Stream output, DLCPackageData info, GamePlatform platform)
        {
            var soundBankName = String.Format("Song_{0}", info.Name);
            Stream albumArtStream = null;
            try
            {
                if (File.Exists(info.AlbumArtPath))
                {
                    albumArtStream = File.OpenRead(info.AlbumArtPath);
                }
                else
                {
                    albumArtStream = new MemoryStream(Resources.albumart);
                }
                using (var aggregateGraphStream = new MemoryStream())
                using (var manifestStream = new MemoryStream())
                using (var xblockStream = new MemoryStream())
                using (var soundbankStream = new MemoryStream())
                using (var packageIdStream = new MemoryStream())
                using (var soundStream = OggFile.ConvertOgg(platform.GetOgg(info)))
                using (var arrangementFiles = new DisposableCollection<Stream>())
                {
                    var manifestBuilder = new ManifestBuilder
                    {
                        AggregateGraph = new AggregateGraph.AggregateGraph
                        {
                            SoundBank = new SoundBank { File = soundBankName + ".bnk" },
                            AlbumArt = new AlbumArt { File = info.AlbumArtPath }
                        }
                    };

                    foreach (var x in info.Arrangements)
                    {
                        //Generate sng file in execution time
                        GenerateSNG(x, platform);

                        manifestBuilder.AggregateGraph.SongFiles.Add(x.SongFile);
                        manifestBuilder.AggregateGraph.SongXMLs.Add(x.SongXml);
                    }
                    manifestBuilder.AggregateGraph.XBlock = new XBlockFile { File = info.Name + ".xblock" };
                    manifestBuilder.AggregateGraph.Write(info.Name, platform.GetPathName(), platform, aggregateGraphStream);
                    aggregateGraphStream.Flush();
                    aggregateGraphStream.Seek(0, SeekOrigin.Begin);

                    {
                        var manifestData = manifestBuilder.GenerateManifest(info.Name, info.Arrangements, info.SongInfo, platform);
                        var writer = new StreamWriter(manifestStream);
                        writer.Write(manifestData);
                        writer.Flush();
                        manifestStream.Seek(0, SeekOrigin.Begin);
                    }

                    XBlockGenerator.Generate(info.Name, manifestBuilder.Manifest, manifestBuilder.AggregateGraph, xblockStream);
                    xblockStream.Flush();
                    xblockStream.Seek(0, SeekOrigin.Begin);

                    var soundFileName = SoundBankGenerator.GenerateSoundBank(info.Name, soundStream, soundbankStream, info.Volume, platform);
                    soundbankStream.Flush();
                    soundbankStream.Seek(0, SeekOrigin.Begin);

                    GenerateSongPackageId(packageIdStream, info.Name);

                    var songPsarc = new PSARC.PSARC();
                    songPsarc.AddEntry("PACKAGE_ID", packageIdStream);
                    songPsarc.AddEntry("AggregateGraph.nt", aggregateGraphStream);
                    songPsarc.AddEntry("Manifests/songs.manifest.json", manifestStream);
                    songPsarc.AddEntry(String.Format("Exports/Songs/{0}.xblock", info.Name), xblockStream);
                    songPsarc.AddEntry(String.Format("Audio/{0}/{1}.bnk", platform.GetPathName()[0], soundBankName), soundbankStream);
                    songPsarc.AddEntry(String.Format("Audio/{0}/{1}.ogg", platform.GetPathName()[0], soundFileName), soundStream);
                    songPsarc.AddEntry(String.Format("GRAssets/AlbumArt/{0}.dds", manifestBuilder.AggregateGraph.AlbumArt.Name), albumArtStream);

                    foreach (var x in info.Arrangements)
                    {
                        var xmlFile = File.OpenRead(x.SongXml.File);
                        arrangementFiles.Add(xmlFile);
                        var sngFile = File.OpenRead(x.SongFile.File);
                        arrangementFiles.Add(sngFile);
                        songPsarc.AddEntry(String.Format("GR/Behaviors/Songs/{0}.xml", Path.GetFileNameWithoutExtension(x.SongXml.File)), xmlFile);
                        songPsarc.AddEntry(String.Format("GRExports/{0}/{1}.sng", platform.GetPathName()[1], Path.GetFileNameWithoutExtension(x.SongFile.File)), sngFile);
                    }
                    songPsarc.Write(output);
                    output.Flush();
                    output.Seek(0, SeekOrigin.Begin);
                }
            }
            finally
            {
                if (albumArtStream != null)
                {
                    albumArtStream.Dispose();
                }
            }
        }
        /// <summary>
        /// Regenerates the aggregategraph file
        /// </summary>
        private static void UpdateAggegrateGraph(string songDirectory, Platform targetPlatform, DLCPackageData info)
        {
            var dlcName = info.Name.ToLower();
            var aggregateGraphFileName = Path.Combine(songDirectory, String.Format("{0}_aggregategraph.nt", dlcName));
            var aggregateGraph         = new AggregateGraph2014.AggregateGraph2014(info, targetPlatform);

            using (var fs = new FileStream(aggregateGraphFileName, FileMode.Create))
                using (var aggregateGraphStream = new MemoryStream())
                {
                    aggregateGraph.Serialize(aggregateGraphStream);
                    aggregateGraphStream.Flush();
                    aggregateGraphStream.Seek(0, SeekOrigin.Begin);
                    aggregateGraphStream.CopyTo(fs);
                }
        }
 public WEM2OGGCorrespondence(string txt_DBFolder, DLCManager.Files filed, DLCPackageData datas, string author, string tkversion, string dD, string bass, string guitar, string combo, string rhythm, string lead, string tunnings, int i, int norows, string original_FileName, string art_hash, string audio_hash, string audioPreview_hash, List<string> alist, List<string> blist, string txt_TempPath, string txt_RocksmithDLCPath, bool AllowEncript, bool AllowORIGDelete)
     : this(txt_DBFolder, txt_TempPath, txt_RocksmithDLCPath, AllowEncript, AllowORIGDelete)
 {
     this.filed = filed;
     this.datas = datas;
     this.author = author;
     this.tkversion = tkversion;
     this.dD = dD;
     this.bass = bass;
     this.guitar = guitar;
     this.combo = combo;
     this.rhythm = rhythm;
     this.lead = lead;
     this.tunnings = tunnings;
     this.i = i;
     this.norows = norows;
     this.original_FileName = original_FileName;
     this.art_hash = art_hash;
     this.audio_hash = audio_hash;
     this.audioPreview_hash = audioPreview_hash;
     this.alist = alist;
     this.blist = blist;
 }
        public static void Generate(string packagePath, DLCPackageData info, Platform platform, DLCPackageType dlcType = DLCPackageType.Song)
        {
            switch (platform.platform)
            {
                case GamePlatform.XBox360:
                    if (!Directory.Exists(XBOX_WORKDIR))
                        Directory.CreateDirectory(XBOX_WORKDIR);
                    break;
                case GamePlatform.PS3:
                    if (!Directory.Exists(PS3_WORKDIR))
                        Directory.CreateDirectory(PS3_WORKDIR);
                    break;
            }

            using (var packPsarcStream = new MemoryStream())
            {
                switch (platform.version)
                {
                    case GameVersion.RS2014:
                        switch (dlcType)
                        {
                            case DLCPackageType.Song:
                                GenerateRS2014SongPsarc(packPsarcStream, info, platform);
                                break;
                            case DLCPackageType.Lesson:
                                throw new NotImplementedException("Lesson package type not implemented yet :(");
                            case DLCPackageType.Inlay:
                                GenerateRS2014InlayPsarc(packPsarcStream, info, platform);
                                break;
                        }
                        break;
                    case GameVersion.RS2012:
                        GeneratePsarcsForRS1(packPsarcStream, info, platform);
                        break;
                    case GameVersion.None:
                        throw new InvalidOperationException("Unexpected game version value");
                }

                var packageName = Path.GetFileNameWithoutExtension(packagePath).StripPlatformEndName();

                var songFileName = String.Format("{0}{1}", Path.Combine(Path.GetDirectoryName(packagePath), packageName), platform.GetPathName()[2]);

                switch (platform.platform)
                {
                    case GamePlatform.Pc:
                    case GamePlatform.Mac:
                        switch (platform.version)
                        {
                            // SAVE PACKAGE
                            case GameVersion.RS2014:
                                using (FileStream fl = File.Create(songFileName + ".psarc"))
                                    packPsarcStream.CopyTo(fl);
                                break;
                            case GameVersion.RS2012:
                                using (var fl = File.Create(songFileName + ".dat"))
                                    RijndaelEncryptor.EncryptFile(packPsarcStream, fl, RijndaelEncryptor.DLCKey);
                                break;
                            default:
                                throw new InvalidOperationException("Unexpected game version value");
                        }
                        break;
                    case GamePlatform.XBox360:
                        BuildXBox360Package(songFileName, info, FILES_XBOX, platform.version, dlcType);
                        break;
                    case GamePlatform.PS3:
                        EncryptPS3EdatFiles(songFileName + ".psarc", platform);
                        break;
                }
            }

            FILES_XBOX.Clear();
            FILES_PS3.Clear();
            DeleteTmpFiles(TMPFILES_SNG);
        }
Exemplo n.º 33
0
        //public void GeneratePackage(object sender, DoWorkEventArgs e)
        public string GeneratePackage(string ID)
        {
            string dlcSavePath = "";
            var cmd = "SELECT * FROM Main ";
            //if (rbtn_Population_Selected.Checked == true)
            cmd += "WHERE ID = " + ID + "";
            //else if (rbtn_Population_All.Checked) ;
            //else if (rbtn_Population_Groups.Checked) cmd += "WHERE Groups = " + cbx_Groups.SelectedText;

            //cmd += " ORDER BY Artist";
            //Read from DB
            var norows = 0;
            norows = SQLAccess(cmd);
            //bcapirtxt_StatisticsOnReadDLCs.Text = "Processing &Repackaging for " + norows + " " + cmd + "\n \n" + rtxt_StatisticsOnReadDLCs.Text;

            var i = 0;
            var artist = "";
            //var cmd = "";
            //rtxt_StatisticsOnReadDLCs.Text = "Repack backgroundworker.."+ norows +  rtxt_StatisticsOnReadDLCs.Text;
            foreach (var file in files)
            {
                if (i > 0) //ONLY 1  FILE WILL BE READ
                    break;
                i++;
                //bcapirtxt_StatisticsOnReadDLCs.Text = "...Pack" + i + " " + file.Artist + " " + file.Song_Title + "\n" + rtxt_StatisticsOnReadDLCs.Text;// UNPACK
                //if (file.Is_Broken != "Yes" || (file.Is_Broken == "Yes" && !chbx_Broken.Checked)) //"8. Don't repack Broken songs")
                //{
                //var unpackedDir = Packer.Unpack(FullPath, Temp_Path_Import, true, true, false);
                //MessageBox.Show(file.Artist+file.Song_Title);
                var packagePlatform = file.Folder_Name.GetPlatform();
                // REORGANIZE
                //rtxt_StatisticsOnReadDLCs.Text = "...0.1.." + file.Folder_Name + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                var structured = ConfigRepository.Instance().GetBoolean("creator_structured");
                //if (structured)
                //file.Folder_Name = DLCPackageData.DoLikeProject(file.Folder_Name);
                // LOAD DATA
                //rtxt_StatisticsOnReadDLCs.Text = "...0.5.." + file.Folder_Name + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                var info = DLCPackageData.LoadFromFolder(file.Folder_Name, packagePlatform);
                //rtxt_StatisticsOnReadDLCs.Text = "...1.."+ file.Folder_Name + "\n" + rtxt_StatisticsOnReadDLCs.Text;

                var bassRemoved = "No";
                var DDAdded = "No";

                var xmlFiles = Directory.GetFiles(file.Folder_Name, "*.xml", SearchOption.AllDirectories);
                var platform = file.Folder_Name.GetPlatform();
                //if (chbx_Additional_Manipualtions.GetItemChecked(3) || chbx_Additional_Manipualtions.GetItemChecked(5) || chbx_Additional_Manipualtions.GetItemChecked(12) || chbx_Additional_Manipualtions.GetItemChecked(26))
                //{
                //    foreach (var xml in xmlFiles)
                //    {
                //        if (chbx_Additional_Manipualtions.GetItemChecked(12) || chbx_Additional_Manipualtions.GetItemChecked(26))
                //            //ADD DD
                //            if (
                //                (//chbx_Additional_Manipualtions.GetItemChecked(12)
                //        false && !Path.GetFileNameWithoutExtension(xml).ToLower().Contains(".old")
                //                && ((Path.GetFileNameWithoutExtension(xml).ToLower().Contains("lead") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("combo") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("rthythm")) && file.Has_DD == "No") || (Path.GetFileNameWithoutExtension(xml).ToLower().Contains("bass") && file.Has_BassDD == "No")
                //                )
                //                || //chbx_Additional_Manipualtions.GetItemChecked(26)
                //        (false && (Path.GetFileNameWithoutExtension(xml).ToLower().Contains("lead") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("combo") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("rthythm"))
                //                && file.Has_DD == "No" && file.Has_Guitar == "Yes" && !Path.GetFileNameWithoutExtension(xml).ToLower().Contains(".old")
                //                )
                //               )
                //            {
                //                File.Copy(xml, xml + ".old", true);
                //                string json = "";
                //                if (chbx_Additional_Manipualtions.GetItemChecked(36)) //37. Keep the Uncompressed Songs superorganized
                //                    json = xml.Replace("EOF", "Toolkit").Replace(".xml", ".json");
                //                else
                //                    json = (xml.Replace(".xml", ".json").Replace("\\songs\\arr\\", calc_path(Directory.GetFiles(file.Folder_Name, "*.json", SearchOption.AllDirectories)[0])));

                //                File.Copy(json, json + ".old", true);
                //                //bcapirtxt_StatisticsOnReadDLCs.Text = chbx_Additional_Manipualtions.GetItemChecked(12).ToString()+ chbx_Additional_Manipualtions.GetItemChecked(26).ToString()+"...." + Path.GetFileNameWithoutExtension(xml) + "...Adding DD using DDC tool" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //                var startInfo = new ProcessStartInfo();

                //                var r = String.Format(" -m \"{0}\"", Path.GetFullPath("ddc\\ddc_5_max_levels.xml"));
                //                var c = String.Format(" -c \"{0}\"", Path.GetFullPath("ddc\\ddc_keep_all_levels.xml"));
                //                startInfo.FileName = Path.Combine(AppWD, "ddc", "ddc.exe");

                //                if (chbx_Additional_Manipualtions.GetItemChecked(36)) //37. Keep the Uncompressed Songs superorganized
                //                    startInfo.WorkingDirectory = file.Folder_Name + "\\EOF\\";// Path.GetDirectoryName();
                //                else
                //                    startInfo.WorkingDirectory = file.Folder_Name + "\\songs\\arr\\";// Path.GetDirectoryName();

                //                startInfo.Arguments = String.Format("\"{0}\" -l {1} -s {2}{3}{4}{5}",
                //                                                    Path.GetFileName(xml),
                //                                                    2, "N", r, c,
                //                                                       " -p Y", " -t N");
                //    //rtxt_StatisticsOnReadDLCs.Text = "working dir: "+ startInfo.WorkingDirectory + "...\n--"+startInfo.FileName+"..." +startInfo.Arguments + "\n\n" + rtxt_StatisticsOnReadDLCs.Text;
                //    startInfo.UseShellExecute = false;
                //    startInfo.CreateNoWindow = true;
                //    startInfo.RedirectStandardOutput = true;
                //    startInfo.RedirectStandardError = true;

                //    using (var DDC = new Process())
                //    {
                //        // rtxt_StatisticsOnReadDLCs.Text = "...1" + "\n" + rtxt_StatisticsOnReadDLCs.Text;

                //        DDC.StartInfo = startInfo;
                //        DDC.Start();
                //        //consoleOutput = DDC.StandardOutput.ReadToEnd();
                //        //consoleOutput += DDC.StandardError.ReadToEnd();
                //        DDC.WaitForExit(1000 * 60 * 5); //wait 15 minutes
                //        // if (DDC.ExitCode > 0 ) rtxt_StatisticsOnReadDLCs.Text = "Issues when adding DD !" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //        DDAdded = "Yes"; rtxt_StatisticsOnReadDLCs.Text = "DDAdded: " + DDAdded + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //        file.Has_BassDD = "Yes";
                //    }
                //}

                //REMOVE DD
                //rtxt_StatisticsOnReadDLCs.Text = "...=.." + xml + "\n\n" + rtxt_StatisticsOnReadDLCs.Text;
                //        if ((Path.GetFileNameWithoutExtension(xml).ToLower().Contains("bass") && file.Has_BassDD == "Yes" && !Path.GetFileNameWithoutExtension(xml).ToLower().Contains(".old") && chbx_Additional_Manipualtions.GetItemChecked(5))
                //            || ((Path.GetFileNameWithoutExtension(xml).ToLower().Contains("lead") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("combo") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("rthythm"))
                //            && file.Has_Guitar == "Yes" && !Path.GetFileNameWithoutExtension(xml).ToLower().Contains(".old") && chbx_Additional_Manipualtions.GetItemChecked(3)))
                //        // continue;
                //        {
                //            if (chbx_Additional_Manipualtions.GetItemChecked(5) && !chbx_Additional_Manipualtions.GetItemChecked(3) && !Path.GetFileNameWithoutExtension(xml).ToLower().Contains("bass")) continue;
                //            bassRemoved = (RemoveDD(file.Folder_Name, file.Is_Original, xml, platform) == "Yes") ? "No" : "Yes";
                //            file.Has_BassDD = (bassRemoved == "Yes") ? "No" : "Yes";

                //        }
                //        //rtxt_StatisticsOnReadDLCs.Text = "...°.." + xmlFiles.Length + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //    }
                //}
                ////rtxt_StatisticsOnReadDLCs.Text = "ooooo" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (chbx_Additional_Manipualtions.GetItemChecked(17)) //18.Repack with Artist/ Title same as Artist / Title Sort
                //{
                //    file.Artist_Sort = file.Artist;
                //    file.Song_Title_Sort = file.Song_Title;
                //}
                ////rtxt_StatisticsOnReadDLCs.Text = "ggggoo" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (chbx_Additional_Manipualtions.GetItemChecked(23) && file.Artist_Sort.Length > 4) //24.Pack with The/ Die only at the end of Title Sort
                //{
                //    //rtxt_StatisticsOnReadDLCs.Text = "1eeeeeeoo" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //    if (chbx_Additional_Manipualtions.GetItemChecked(21) && file.Song_Title_Sort.Length > 4)
                //    {
                //        //rtxt_StatisticsOnReadDLCs.Text = "2eeeeeeoo" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //        file.Song_Title_Sort = (file.Song_Title_Sort.Substring(0, 4) == "The " ? file.Song_Title_Sort.Substring(4, file.Song_Title_Sort.Length - 4) + ",The" : file.Song_Title_Sort);
                //        file.Song_Title_Sort = (file.Song_Title_Sort.Substring(0, 4) == "Die " ? file.Song_Title_Sort.Substring(4, file.Song_Title_Sort.Length - 4) + ",Die" : file.Song_Title_Sort);
                //        file.Song_Title_Sort = (file.Song_Title_Sort.Substring(0, 4) == "the " ? file.Song_Title_Sort.Substring(4, file.Song_Title_Sort.Length - 4) + ",The" : file.Song_Title_Sort);
                //        file.Song_Title_Sort = (file.Song_Title_Sort.Substring(0, 4) == "die " ? file.Song_Title_Sort.Substring(4, file.Song_Title_Sort.Length - 4) + ",Die" : file.Song_Title_Sort);
                //        file.Song_Title_Sort = (file.Song_Title_Sort.Substring(0, 4) == "THE " ? file.Song_Title_Sort.Substring(4, file.Song_Title_Sort.Length - 4) + ",The" : file.Song_Title_Sort);
                //        file.Song_Title_Sort = (file.Song_Title_Sort.Substring(0, 4) == "DIE " ? file.Song_Title_Sort.Substring(4, file.Song_Title_Sort.Length - 4) + ",Die" : file.Song_Title_Sort);
                //    }
                //    //rtxt_StatisticsOnReadDLCs.Text = file.Artist_Sort + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //    file.Artist_Sort = (file.Artist_Sort.Substring(0, 4) == "The " ? file.Artist_Sort.Substring(4, file.Artist_Sort.Length - 4) + ",The" : file.Artist_Sort);
                //    file.Artist_Sort = (file.Artist_Sort.Substring(0, 4) == "Die " ? file.Artist_Sort.Substring(4, file.Artist_Sort.Length - 4) + ",Die" : file.Artist_Sort);
                //    file.Artist_Sort = (file.Artist_Sort.Substring(0, 4) == "the " ? file.Artist_Sort.Substring(4, file.Artist_Sort.Length - 4) + ",The" : file.Artist_Sort);
                //    file.Artist_Sort = (file.Artist_Sort.Substring(0, 4) == "die " ? file.Artist_Sort.Substring(4, file.Artist_Sort.Length - 4) + ",Die" : file.Artist_Sort);
                //    file.Artist_Sort = (file.Artist_Sort.Substring(0, 4) == "THE " ? file.Artist_Sort.Substring(4, file.Artist_Sort.Length - 4) + ",The" : file.Artist_Sort);
                //    file.Artist_Sort = (file.Artist_Sort.Substring(0, 4) == "DIE " ? file.Artist_Sort.Substring(4, file.Artist_Sort.Length - 4) + ",Die" : file.Artist_Sort);
                //}
                //rtxt_StatisticsOnReadDLCs.Text = "4eeeeeeoo" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //data = new DLCPackageData
                //{
                //    GameVersion = RocksmithToolkitLib.GameVersion.RS2014,
                //    Pc = cbx_Format.Text == "PC" ? true : false,
                //    Mac = cbx_Format.Text == "Mac" ? true : false,
                //    XBox360 = cbx_Format.Text == "XBOX360" ? true : false,
                //    PS3 = cbx_Format.Text == "PS3" ? true : false,
                //    Name = txt_DLC_ID.Text,
                //    AppId = txt_APP_ID.Text,

                //    //USEFUL CMDs String.IsNullOrEmpty(
                //    SongInfo = new RocksmithToolkitLib.DLCPackage.SongInfo
                //    {
                //        SongDisplayName = txt_Title.Text,
                //        SongDisplayNameSort = txt_Title_Sort.Text,
                //        Album = txt_Album.Text,
                //        SongYear = txt_Album_Year.Text.ToInt32(),
                //        Artist = txt_Artist.Text,
                //        ArtistSort = txt_Artist_Sort.Text,
                //        AverageTempo = txt_AverageTempo.Text.ToInt32()
                //    },

                //    AlbumArtPath = txt_AlbumArtPath.Text,
                //    OggPath = txt_AudioPath.Text,
                //    OggPreviewPath = ((txt_AudioPath.Text != "") ? txt_AudioPath.Text : txt_AudioPath.Text),
                //    Arrangements = info.Arrangements, //Not yet done
                //    Tones = info.Tones,//Not yet done
                //    TonesRS2014 = info.TonesRS2014,//Not yet done
                //    Volume = txt_Volume.Text.ToInt32(),
                //    PreviewVolume = txt_Preview_Volume.Text.ToInt32(),
                //    SignatureType = txt_SignatureType.Text,
                //    PackageVersion = txt_Version.Text
                //};

                data = new DLCPackageData
                {
                    GameVersion = GameVersion.RS2014,
                    Pc = chbx_Format.Text == "PC" ? true : false, //txt_Platform.Text
                    Mac = chbx_Format.Text == "Mac" ? true : false,
                    XBox360 = chbx_Format.Text == "XBOX360" ? true : false,
                    PS3 = chbx_Format.Text == "PS3" ? true : false,
                    Name = file.DLC_Name,
                    AppId = file.DLC_AppID,
                    ArtFiles = info.ArtFiles,

                    //USEFUL CMDs String.IsNullOrEmpty(
                    SongInfo = new RocksmithToolkitLib.DLCPackage.SongInfo
                    {
                        SongDisplayName = file.Song_Title,
                        SongDisplayNameSort = file.Song_Title_Sort,
                        Album = file.Album,
                        SongYear = file.Album_Year.ToInt32(),
                        Artist = file.Artist,
                        ArtistSort = file.Artist_Sort,
                        AverageTempo = file.AverageTempo.ToInt32()
                    },

                    AlbumArtPath = file.AlbumArtPath,
                    OggPath = file.AudioPath,
                    OggPreviewPath = ((file.audioPreviewPath != "") ? file.audioPreviewPath : file.AudioPath),
                    Arrangements = info.Arrangements, //Not yet done
                    Tones = info.Tones,//Not yet done
                    TonesRS2014 = info.TonesRS2014,//Not yet done
                    Volume = file.Volume.ToInt32(),
                    PreviewVolume = file.Preview_Volume.ToInt32(),
                    SignatureType = info.SignatureType,
                    PackageVersion = file.Version
                };

                //get track no
                if (ConfigRepository.Instance()["dlcm_AdditionalManipul48"] == "Yes")
                {
                    var CleanTitle = "";
                    if (txt_Title.Text.IndexOf("[") > 0) CleanTitle = txt_Title.Text.Substring(0, txt_Title.Text.IndexOf("["));
                    if (txt_Title.Text.IndexOf("]") > 0) CleanTitle += txt_Title.Text.Substring(txt_Title.Text.IndexOf("]"), txt_Title.Text.Length - txt_Title.Text.IndexOf("]"));
                    else if (txt_Title.Text.IndexOf("[") == 0 || txt_Title.Text.Substring(0, 1) != "[") CleanTitle = txt_Title.Text;

                    string z = (GetTrackNo(txt_Artist.Text, txt_Album.Text, CleanTitle)).ToString();
                    txt_Track_No.Text = z == "0" && txt_Track_No.Text != "" ? txt_Track_No.Text : z;
                }

                if (file.Author == "Custom Song Creator" || file.Author == "" && ConfigRepository.Instance()["dlcm_AdditionalManipul47"] == "Yes") file.Author = "RepackedBy" + ConfigRepository.Instance()["general_defaultauthor"].ToUpper();

                DirectoryInfo di;
                var repacked_Path = TempPath + "\\0_repacked";
                if (!Directory.Exists(repacked_Path) && (repacked_Path != null)) di = Directory.CreateDirectory(repacked_Path);

                //bcapirtxt_StatisticsOnReadDLCs.Text = file.Song_Title+" test"+i+ data.SongInfo.Artist + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                var norm_path = repacked_Path + "\\" + Manipulate_strings(ConfigRepository.Instance()["dlcm_File_Name"], 0, false, false); ;//((file.ToolkitVersion == "") ? "ORIG" : "CDLC") + "_" + data.SongInfo.Artist + "_" + data.SongInfo.SongYear + "_" + data.SongInfo.Album + "_" + data.SongInfo.SongDisplayName;
                //rtxt_StatisticsOnReadDLCs.Text = "8"+data.PackageVersion+"...manipul" + norm_path + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //manipulating the info

                //ConfigRepository.Instance()["dlcm_Title"] = txt_Title.Text;
                //ConfigRepository.Instance()["dlcm_Title_sort"] = txt_Title_Sort.Text;
                //ConfigRepository.Instance()["dlcm_Artist"] = txt_Artist.Text;
                //ConfigRepository.Instance()["dlcm_Artist_Sort"] = txt_Artist_Sort.Text;
                //ConfigRepository.Instance()["dlcm_Album"] = txt_Album.Text;
                //ConfigRepository.Instance()["dlcm_File_Name"] = txt_File_Name.Text;
                data.SongInfo.SongDisplayName = Manipulate_strings(ConfigRepository.Instance()["dlcm_Title"], 0, false, false);
                // rtxt_StatisticsOnReadDLCs.Text = "...manipul: "+ file.Song_Title + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (cbx_Activ_Title_Sort.Checked)
                data.SongInfo.SongDisplayNameSort = Manipulate_strings(ConfigRepository.Instance()["dlcm_Title_sort"], 0, false, false);
                //rtxt_StatisticsOnReadDLCs.Text = "...manipul" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (cbx_Activ_Artist.Checked)
                data.SongInfo.Artist = Manipulate_strings(ConfigRepository.Instance()["dlcm_Artist"], 0, false, false);
                //rtxt_StatisticsOnReadDLCs.Text = "...manipul" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (cbx_Activ_Artist_Sort.Checked)
                data.SongInfo.ArtistSort = Manipulate_strings(ConfigRepository.Instance()["dlcm_Artist_Sort"], 0, false, false);
                //rtxt_StatisticsOnReadDLCs.Text = "...manipul" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (cbx_Activ_Album.Checked)
                data.SongInfo.Album = Manipulate_strings(ConfigRepository.Instance()["dlcm_Album"], 0, false, false);
                //rtxt_StatisticsOnReadDLCs.Text = "...3" + "\n" + rtxt_StatisticsOnReadDLCs.Text;

                //rtxt_StatisticsOnReadDLCs.Text = "...nipul" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (chbx_Additional_Manipualtions.GetItemChecked(0)) //"1. Add Increment to all Titles"
                //data.Name = i + data.Name;

                //rtxt_StatisticsOnReadDLCs.Text = "...mpl" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                artist = "";
                //if (chbx_Additional_Manipualtions.GetItemChecked(1)) //"2. Add Increment to all songs(&Separately per artist)"
                //{
                //    if (i > 0)
                //        if (data.SongInfo.Artist == files[i - 1].Artist) no_ord += 1;
                //        else no_ord = 1;
                //    else no_ord += 1;
                //    artist = no_ord + " ";
                //    data.SongInfo.SongDisplayName = i + artist + data.SongInfo.SongDisplayName;
                //}

                //if (chbx_Additional_Manipualtions.GetItemChecked(7)) //"8. Don't repack Broken songs"
                //    if (file.Is_Broken == "Yes") break;
                //rtxt_StatisticsOnReadDLCs.Text = "...4" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //rtxt_StatisticsOnReadDLCs.Text = "...manipl" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (chbx_Additional_Manipualtions.GetItemChecked(2)) //"3. Make all DLC IDs unique (&save)"
                if (chbx_UniqueID.Checked)
                    if (file.UniqueDLCName != "") data.Name = file.UniqueDLCName;
                    else
                    {
                        Random random = new Random();
                        data.Name = random.Next(0, 100000) + data.Name;
                        var k = DataViewGrid.SelectedCells[0].RowIndex;
                        DataViewGrid.Rows[k].Cells[79].Value = data.Name;
                        //var DB_Path = DBFolder + "\\Files.accdb;";
                        using (OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DB_Path))
                        {
                            DataSet dis = new DataSet();
                            cmd = "UPDATE Main SET UniqueDLCName=\"" + data.Name + "\" WHERE ID=" + file.ID;
                            OleDbDataAdapter das = new OleDbDataAdapter(cmd, cnn);
                            das.Fill(dis, "Main");
                            das.Dispose();
                        }
                    }

                //Fix the _preview_preview issue
                var ms = data.OggPath; //var audiopath = ""; var audioprevpath = "";
                var tst = "";
                //MessageBox.Show("One or more");
                //rtxt_StatisticsOnReadDLCs.Text = "maybe fixing .."+ file.Folder_Name+"\n"+ norm_path + "\n"+ rtxt_StatisticsOnReadDLCs.Text;
                try
                {
                    var sourceAudioFiles = Directory.GetFiles(file.Folder_Name, "*.wem", SearchOption.AllDirectories);
                    //if (sourceAudioFiles.Length>0)
                    //var targetAudioFiles = new List<string>();

                    foreach (var fil in sourceAudioFiles)
                    {
                        tst = fil;
                        //MessageBox.Show("test2.02 " + fil);
                        //rtxt_StatisticsOnReadDLCs.Text = "thinking about fixing _preview_preview issue.." + norm_path +"-"+tst+ "\n"+rtxt_StatisticsOnReadDLCs.Text;
                        if (fil.LastIndexOf("_preview_preview.wem") > 0)
                        {
                            ms = fil.Substring(0, fil.LastIndexOf("_preview_preview.wem"));
                            File.Move((ms + "_preview.wem"), (ms + ".wem"));
                            File.Move((ms + "_preview_preview.wem"), (ms + "_preview.wem"));
                            //bcapirtxt_StatisticsOnReadDLCs.Text = "fixing _preview_preview issue..." + rtxt_StatisticsOnReadDLCs.Text;
                        }
                    }
                }
                catch (Exception ee)
                {
                    //bcapirtxt_StatisticsOnReadDLCs.Text = "FAILED6-" + ee.Message + tst + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                    Console.WriteLine(ee.Message);
                }
                if (data == null)
                {
                    MessageBox.Show("One or more fields are missing information.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //return;
                }
                //rtxt_StatisticsOnReadDLCs.Text = "...5" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //dlcSavePath = ds.Tables[0].Rows[i].ItemArray[1].ToString() + "\\";// + ((info.PackageVersion == null) ? "Original" : "CDLC") + "-" + info.SongInfo.SongYear +".psarc";
                //var dlcSavePath = GeneralExtensions.GetShortName("{0}_{1}_v{2}", (((file.Version == null) ? "Original" : "CDLC") + "_" + info.SongInfo.SongDisplayName), (info.SongInfo.SongDisplayName + "_" + info.SongInfo.Album + "_" + info.SongInfo.SongYear), info.PackageVersion, ConfigRepository.Instance().GetBoolean("creator_useacronyms"));
                var FN = "";
                //bcapirtxt_StatisticsOnReadDLCs.Text = file.Song_Title+ "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (cbx_Activ_File_Name.Checked) FN = Manipulate_strings(txt_File_Name.Text, i, true, false);
                //else
                FN = GeneralExtensions.GetShortName("{0}-{1}-v{2}", (((file.Version == null) ? "ORIG" : "CDLC") + "_" + file.Artist), (file.Album_Year.ToInt32() + "_" + file.Album + "_" + file.Song_Title), file.Version, ConfigRepository.Instance().GetBoolean("creator_useacronyms"));//((data.PackageVersion == null) ? "Original" : "CDLC") + "_" + data.SongInfo.Artist + "_" + data.SongInfo.SongYear + "_" + data.SongInfo.Album + "_" + data.SongInfo.SongDisplayName;

                if (file.Is_Alternate == "Yes") FN += "a." + file.Alternate_Version_No + file.Author;

                //rtxt_StatisticsOnReadDLCs.Text = "fn: " + FN + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                if (chbx_Format.Text == "PS3")
                {
                    FN = FN.Replace(".", "_");
                    FN = FN.Replace(" ", "_");
                }

                dlcSavePath = TempPath + "\\" + FN;
                //rtxt_StatisticsOnReadDLCs.Text = "rez : " + dlcSavePath + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //if (GameVersion.RS2014 == GameVersion.RS2012) //old code
                //{
                //    try
                //    {
                //        OggFile.VerifyHeaders(data.OggPath);
                //    }
                //    catch (InvalidDataException ex)
                //    {
                //        MessageBox.Show(ex.Message, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //        return;
                //    }
                //}
                //rtxt_StatisticsOnReadDLCs.Text = "genf : " + "\n" + rtxt_StatisticsOnReadDLCs.Text;

                int progress = 0;
                var errorsFound = new StringBuilder();
                var numPlatforms = 0;
                //if (platformPC.Checked)
                numPlatforms++;
                //if (chbx_Format=="Mac")
                //    numPlatforms++;
                //if (chbx_XBOX360.Checked)
                //    numPlatforms++;
                //if (chbx_PS3.Checked)
                //    numPlatforms++;

                var step = (int)Math.Round(1.0 / numPlatforms * 100, 0);
                // rtxt_StatisticsOnReadDLCs.Text = "...6" + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                if (chbx_Format.Text == "PC")
                    try
                    {
                        //bwRGenerate.ReportProgress(progress, "Generating PC package");
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "1pc..." + rtxt_StatisticsOnReadDLCs.Text;
                        RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, data, new Platform(GamePlatform.Pc, GameVersion.RS2014));
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "2pc..." + rtxt_StatisticsOnReadDLCs.Text;
                        progress += step;
                        //bwRGenerate.ReportProgress(progress);
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "3pc..." + rtxt_StatisticsOnReadDLCs.Text;
                    }
                    catch (Exception ex)
                    {
                        errorsFound.AppendLine(String.Format("Error 0 generate PC package: {0}{1}{0}{2}{0}", Environment.NewLine, ex.Message, ex.StackTrace));
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "...0pc ERROR..." + ex.Message + rtxt_StatisticsOnReadDLCs.Text;
                    }

                if (chbx_Format.Text == "Mac")
                    try
                    {
                        //bwRGenerate.ReportProgress(progress, "Generating Mac package");
                        RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, data, new Platform(GamePlatform.Mac, GameVersion.RS2014));
                        progress += step;
                        //bwRGenerate.ReportProgress(progress);
                    }
                    catch (Exception ex)
                    {
                        errorsFound.AppendLine(String.Format("Error 1 generate Mac package: {0}{1}{0}{2}{0}", Environment.NewLine, ex.Message, ex.StackTrace));
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "...0mac ERROR..." + ex.Message + rtxt_StatisticsOnReadDLCs.Text;
                    }

                if (chbx_Format.Text == "XBOX360")
                    try
                    {
                        //bwRGenerate.ReportProgress(progress, "Generating XBox 360 package");
                        RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, data, new Platform(GamePlatform.XBox360, GameVersion.RS2014));
                        progress += step;
                        //bwRGenerate.ReportProgress(progress);
                    }
                    catch (Exception ex)
                    {
                        errorsFound.AppendLine(String.Format("Error generate XBox 360 package: {0}{1}{0}{2}{0}", Environment.NewLine, ex.Message, ex.StackTrace));
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "...0mac ERROR..." + ex.Message + rtxt_StatisticsOnReadDLCs.Text;
                    }

                if (chbx_Format.Text == "PS3")
                    try
                    {
                        //rtxt_StatisticsOnReadDLCs.Text = "ps3...start..." + rtxt_StatisticsOnReadDLCs.Text;
                        //bwRGenerate.ReportProgress(progress, "Generating PS3 package");
                        //rtxt_StatisticsOnReadDLCs.Text = dlcSavePath + rtxt_StatisticsOnReadDLCs.Text;
                        string dds = dlcSavePath;// + ".psarc.edat";
                        RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dds, data, new Platform(GamePlatform.PS3, GameVersion.RS2014));
                        //progress += step;
                        //bwRGenerate.ReportProgress(progress);
                        // rtxt_StatisticsOnReadDLCs.Text = "ps3...off..." + rtxt_StatisticsOnReadDLCs.Text;
                    }
                    catch (Exception ex)
                    {
                        string ss = String.Format("Error 2generate PS3 package: {0}{1}. {0}PS3 package require 'JAVA x86' (32 bits) installed on your machine to generate properly.{0}", Environment.NewLine, ex.StackTrace);
                        MessageBox.Show(ss);
                        errorsFound.AppendLine(ss);
                        //bcapirtxt_StatisticsOnReadDLCs.Text = "...0Ps3 ERROR..."+ dlcSavePath+"---"+ dlcSavePath.Length+ "----" + ex.Message + rtxt_StatisticsOnReadDLCs.Text;
                    }
                data.CleanCache();
                //rtxt_StatisticsOnReadDLCs.Text = "gen2 : " + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                i++;
                //rtxt_StatisticsOnReadDLCs.Text = "gen r: " + "\n" + rtxt_StatisticsOnReadDLCs.Text;
                //TO DO DELETE the ORIGINAL IMPORTED FILES or not
                //bcapirtxt_StatisticsOnReadDLCs.Text = "\nRepack bkworkerdone.." + i + rtxt_StatisticsOnReadDLCs.Text;

                //}
                //MessageBox.Show("tst");
            }
            //bcapirtxt_StatisticsOnReadDLCs.Text = "\n...Repack done.." + rtxt_StatisticsOnReadDLCs.Text;
            return dlcSavePath;
            MessageBox.Show("Repack done");
        }
        public static void UpdateToneDescriptors(DLCPackageData info)
        {
            foreach (var tone in info.TonesRS2014) {
                if (tone == null) continue;
                string DescName = tone.Name.Split('_').Last();
                foreach (var td in ToneDescriptor.List()) {
                    if (td.ShortName != DescName)
                        continue;

                    tone.ToneDescriptors.Clear();
                    tone.ToneDescriptors.Add(td.Descriptor);
                    break;
                }
            }
        }
Exemplo n.º 35
0
        /// <summary>
        /// Loads required DLC info from folder.
        /// </summary>
        /// <returns>The DLCPackageData info.</returns>
        /// <param name="unpackedDir">Unpacked dir.</param>
        /// <param name="targetPlatform">Target platform.</param>
        /// <param name = "sourcePlatform"></param>
        /// <param name="ignoreMultitoneEx">Ignore multitone exceptions</param>
        public static DLCPackageData LoadFromFolder(string unpackedDir, Platform targetPlatform, Platform sourcePlatform = null, bool ignoreMultitoneEx = false)
        {
            var data = new DLCPackageData();

            data.GameVersion   = GameVersion.RS2014;
            data.SignatureType = PackageMagic.CON;
            if (sourcePlatform == null)
            {
                sourcePlatform = unpackedDir.GetPlatform();
            }

            //Arrangements / Tones
            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();

            //Load files
            var jsonFiles = Directory.EnumerateFiles(unpackedDir, "*.json", SearchOption.AllDirectories).ToArray();

            foreach (var json in jsonFiles)
            {
                var attr = Manifest2014 <Attributes2014> .LoadFromFile(json).Entries.ToArray()[0].Value.ToArray()[0].Value;

                var xmlName = attr.SongXml.Split(':')[3];
                var xmlFile = Directory.EnumerateFiles(unpackedDir, xmlName + ".xml", SearchOption.AllDirectories).FirstOrDefault();

                if (attr.Phrases != null)
                {
                    if (data.SongInfo == null)
                    {
                        // Fill Package Data
                        data.Name          = attr.DLCKey;
                        data.Volume        = (attr.SongVolume == 0 ? -12 : attr.SongVolume); //FIXME: too low song volume issue, revert to -6 to fix.
                        data.PreviewVolume = (attr.PreviewVolume ?? data.Volume);

                        // Fill SongInfo
                        data.SongInfo = new SongInfo
                        {
                            SongDisplayName     = attr.SongName,
                            SongDisplayNameSort = attr.SongNameSort,
                            Album        = attr.AlbumName,
                            AlbumSort    = attr.AlbumNameSort,
                            SongYear     = attr.SongYear ?? 0,
                            Artist       = attr.ArtistName,
                            ArtistSort   = attr.ArtistNameSort,
                            AverageTempo = (int)attr.SongAverageTempo
                        };
                    }

                    // Adding Arrangement
                    data.Arrangements.Add(new Arrangement(attr, xmlFile, ignoreMultitoneEx));

                    // make a list of tone names used in arrangements
                    var toneNames = new List <string>();
                    foreach (var arr in data.Arrangements)
                    {
                        if (!String.IsNullOrEmpty(arr.ToneA))
                        {
                            toneNames.Add(arr.ToneA);
                        }
                        if (!String.IsNullOrEmpty(arr.ToneB))
                        {
                            toneNames.Add(arr.ToneB);
                        }
                        if (!String.IsNullOrEmpty(arr.ToneC))
                        {
                            toneNames.Add(arr.ToneC);
                        }
                        if (!String.IsNullOrEmpty(arr.ToneD))
                        {
                            toneNames.Add(arr.ToneD);
                        }
                        if (!String.IsNullOrEmpty(arr.ToneBase))
                        {
                            toneNames.Add(arr.ToneBase);
                        }
                    }

                    // Adding Tones
                    foreach (var jsonTone in attr.Tones)
                    {
                        if (jsonTone == null)
                        {
                            continue;
                        }
                        var key = jsonTone.Key;
                        if (data.TonesRS2014.All(t => t.Key != key))
                        {
                            // fix tones names that do not have the correct alphacase for cross matching
                            if (attr.Tone_Base.ToLower() == jsonTone.Name.ToLower() && attr.Tone_Base != jsonTone.Name)
                            {
                                jsonTone.Name = attr.Tone_Base;
                            }
                            if (attr.Tone_A != null && attr.Tone_A.ToLower() == jsonTone.Name.ToLower() && attr.Tone_A != jsonTone.Name)
                            {
                                jsonTone.Name = attr.Tone_A;
                            }
                            if (attr.Tone_B != null && attr.Tone_B.ToLower() == jsonTone.Name.ToLower() && attr.Tone_B != jsonTone.Name)
                            {
                                jsonTone.Name = attr.Tone_B;
                            }
                            if (attr.Tone_C != null && attr.Tone_C.ToLower() == jsonTone.Name.ToLower() && attr.Tone_C != jsonTone.Name)
                            {
                                jsonTone.Name = attr.Tone_C;
                            }
                            if (attr.Tone_D != null && attr.Tone_D.ToLower() == jsonTone.Name.ToLower() && attr.Tone_D != jsonTone.Name)
                            {
                                jsonTone.Name = attr.Tone_D;
                            }

                            // this is part of multitone exception handling auto convert to single tone arrangment
                            // make data.TonesRS2014 consistent with data.Arragment.Tones (toneNames)
                            if (toneNames.Contains(jsonTone.Name))
                            {
                                data.TonesRS2014.Add(jsonTone);
                            }
                        }
                    }
                }
                else if (xmlFile.ToLower().Contains("_vocals"))
                {
                    var voc = new Arrangement
                    {
                        Name            = attr.JapaneseVocal == true ? ArrangementName.JVocals : ArrangementName.Vocals,
                        ArrangementType = ArrangementType.Vocal,
                        ScrollSpeed     = 20,
                        SongXml         = new SongXML {
                            File = xmlFile
                        },
                        SongFile = new SongFile {
                            File = ""
                        },
                        CustomFont = attr.JapaneseVocal == true
                    };

                    // Get symbols stuff from _vocals.xml
                    var fontSng = Path.Combine(unpackedDir, xmlName + ".sng");
                    var vocSng  = Sng2014FileWriter.ReadVocals(xmlFile);

                    if (vocSng.IsCustomFont())
                    {
                        voc.CustomFont = true;
                        voc.FontSng    = fontSng;
                        vocSng.WriteChartData(fontSng, new Platform(GamePlatform.Pc, GameVersion.None));
                    }

                    voc.Sng2014 = Sng2014File.ConvertXML(xmlFile, ArrangementType.Vocal, voc.FontSng);

                    // Adding Arrangement
                    data.Arrangements.Add(voc);
                }
            }

            //ShowLights XML
            var xmlShowLights = Directory.EnumerateFiles(unpackedDir, "*_showlights.xml", SearchOption.AllDirectories).FirstOrDefault();

            if (!String.IsNullOrEmpty(xmlShowLights))
            {
                var shl = new Arrangement
                {
                    ArrangementType = ArrangementType.ShowLight,
                    Name            = ArrangementName.ShowLights,
                    SongXml         = new SongXML {
                        File = xmlShowLights
                    },
                    SongFile = new SongFile {
                        File = ""
                    }
                };

                // Adding ShowLights
                data.Arrangements.Add(shl);
                data.Showlights = true;
            }

            //Get DDS Files
            var ddsFiles = Directory.EnumerateFiles(unpackedDir, "album_*.dds", SearchOption.AllDirectories).ToArray();

            if (ddsFiles.Any())
            {
                var ddsFilesC = new List <DDSConvertedFile>();
                foreach (var file in ddsFiles)
                {
                    switch (Path.GetFileNameWithoutExtension(file).Split('_')[2])
                    {
                    case "256":
                        data.AlbumArtPath = file;
                        ddsFilesC.Add(new DDSConvertedFile()
                        {
                            sizeX = 256, sizeY = 256, sourceFile = file, destinationFile = file.CopyToTempFile(".dds")
                        });
                        break;

                    case "128":
                        ddsFilesC.Add(new DDSConvertedFile()
                        {
                            sizeX = 128, sizeY = 128, sourceFile = file, destinationFile = file.CopyToTempFile(".dds")
                        });
                        break;

                    case "64":
                        ddsFilesC.Add(new DDSConvertedFile()
                        {
                            sizeX = 64, sizeY = 64, sourceFile = file, destinationFile = file.CopyToTempFile(".dds")
                        });
                        break;
                    }
                }
                data.ArtFiles = ddsFilesC;
            }

            // Lyric Art
            var lyricArt = Directory.EnumerateFiles(unpackedDir, "lyrics_*.dds", SearchOption.AllDirectories).ToArray();

            if (lyricArt.Any())
            {
                data.LyricArtPath = lyricArt.FirstOrDefault();
            }

            //Get other files
            //Audio files
            var targetAudioFiles = new List <string>();
            var sourceAudioFiles = Directory.EnumerateFiles(unpackedDir, "*.wem", SearchOption.AllDirectories).ToArray();

            foreach (var file in sourceAudioFiles)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(file), String.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)));
                if (targetPlatform.IsConsole != (sourcePlatform = file.GetAudioPlatform()).IsConsole)
                {
                    OggFile.ConvertAudioPlatform(file, newFile);
                    targetAudioFiles.Add(newFile);
                }
                else
                {
                    targetAudioFiles.Add(file);
                }
            }

            if (!targetAudioFiles.Any())
            {
                throw new InvalidDataException("Audio files not found.");
            }

            string audioPath = null, audioPreviewPath = null;
            var    a = new FileInfo(targetAudioFiles[0]);

            if (targetAudioFiles.Count == 2)
            {
                var b = new FileInfo(targetAudioFiles[1]);

                if (a.Length > b.Length)
                {
                    audioPath        = a.FullName;
                    audioPreviewPath = b.FullName;
                }
                else
                {
                    audioPath        = b.FullName;
                    audioPreviewPath = a.FullName;
                }
            }
            else
            {
                audioPath = a.FullName;
            }

            data.OggPath = audioPath;

            //Make Audio preview with expected name when rebuild
            if (!String.IsNullOrEmpty(audioPreviewPath))
            {
                var newPreviewFileName = Path.Combine(Path.GetDirectoryName(audioPath), String.Format("{0}_preview{1}", Path.GetFileNameWithoutExtension(audioPath), Path.GetExtension(audioPath)));
                File.Move(audioPreviewPath, newPreviewFileName);
                data.OggPreviewPath = newPreviewFileName;
            }

            //AppID
            var appidFile = Directory.EnumerateFiles(unpackedDir, "*.appid", SearchOption.AllDirectories).FirstOrDefault();

            if (appidFile != null)
            {
                data.AppId = File.ReadAllText(appidFile);
            }

            // Package Info
            var versionFile = Directory.EnumerateFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories).FirstOrDefault();

            if (versionFile != null)
            {
                var tkInfo = GeneralExtensions.ReadToolkitInfo(versionFile);
                data.PackageVersion = tkInfo.PackageVersion;
                data.PackageComment = tkInfo.PackageComment;
            }
            else
            {
                data.PackageVersion = "1";
                data.PackageComment = "";
            }

            return(data);
        }
        private static void GenerateRS2014InlayPsarc(MemoryStream output, DLCPackageData info, Platform platform)
        {
            var dlcName = info.Inlay.DLCSixName;
            // TODO updateProgress remotely from here
            {
                var packPsarc = new PSARC.PSARC();

                // Stream objects
                Stream rsenumerableRootStream = null,
                       rsenumerableGuitarStream = null;

                try {
                    // ICON/INLAY FILES
                    var ddsfiles = info.ArtFiles;

                    if (ddsfiles == null) {
                        string iconPath;
                        if (File.Exists(info.Inlay.IconPath)) {
                            iconPath = info.Inlay.IconPath;
                        } else {
                            using (var iconStream = new MemoryStream(Resources.cgm_default_icon)) {
                                iconPath = Path.ChangeExtension(Path.GetTempFileName(), ".png");
                                iconStream.WriteFile(iconPath);
                                TMPFILES_ART.Add(iconPath);
                            }
                        }

                        string inlayPath;
                        if (File.Exists(info.Inlay.InlayPath)) {
                            inlayPath = info.Inlay.InlayPath;
                        } else {
                            using (var inlayStream = new MemoryStream(Resources.cgm_default_inlay)) {
                                inlayPath = GeneralExtensions.GetTempFileName(".png");
                                inlayStream.WriteFile(inlayPath);
                                TMPFILES_ART.Add(inlayPath);
                            }
                        }

                        ddsfiles = new List<DDSConvertedFile>();
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 64, sizeY = 64, sourceFile = iconPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 128, sizeY = 128, sourceFile = iconPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 256, sizeY = 256, sourceFile = iconPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 512, sizeY = 512, sourceFile = iconPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                        ddsfiles.Add(new DDSConvertedFile() { sizeX = 1024, sizeY = 512, sourceFile = inlayPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });

                        // Convert to DDS
                        ToDDS(ddsfiles, DLCPackageType.Inlay);

                        // Save for reuse
                        info.ArtFiles = ddsfiles;
                    }

                    foreach (var dds in ddsfiles)
                        if (dds.sizeX == 1024)
                            packPsarc.AddEntry(String.Format("assets/gameplay/inlay/inlay_{0}.dds", dlcName), new FileStream(dds.destinationFile, FileMode.Open, FileAccess.Read, FileShare.Read));
                        else
                            packPsarc.AddEntry(String.Format("gfxassets/rewards/guitar_inlays/reward_inlay_{0}_{1}.dds", dlcName, dds.sizeX), new FileStream(dds.destinationFile, FileMode.Open, FileAccess.Read, FileShare.Read));

                    // FLAT MODEL
                    rsenumerableRootStream = new MemoryStream(Resources.rsenumerable_root);
                    packPsarc.AddEntry("flatmodels/rs/rsenumerable_root.flat", rsenumerableRootStream);
                    rsenumerableGuitarStream = new MemoryStream(Resources.rsenumerable_guitar);
                    packPsarc.AddEntry("flatmodels/rs/rsenumerable_guitars.flat", rsenumerableGuitarStream);

                    using (var toolkitVersionStream = new MemoryStream())
                    using (var appIdStream = new MemoryStream())
                    using (var packageListStream = new MemoryStream())
                    using (var aggregateGraphStream = new MemoryStream())
                    using (var manifestStreamList = new DisposableCollection<Stream>())
                    using (var manifestHeaderStream = new MemoryStream())
                    using (var nifStream = new MemoryStream())
                    using (var xblockStream = new MemoryStream()) {
                        // TOOLKIT VERSION
                        GenerateToolkitVersion(toolkitVersionStream);
                        packPsarc.AddEntry("toolkit.version", toolkitVersionStream);

                        // APP ID
                        if (!platform.IsConsole) {
                            GenerateAppId(appIdStream, info.AppId, platform);
                            packPsarc.AddEntry("appid.appid", appIdStream);
                        }

                        if (platform.platform == GamePlatform.XBox360) {
                            var packageListWriter = new StreamWriter(packageListStream);
                            packageListWriter.Write(dlcName);
                            packageListWriter.Flush();
                            packageListStream.Seek(0, SeekOrigin.Begin);
                            string packageList = "PackageList.txt";
                            packageListStream.WriteTmpFile(packageList, platform);
                        }

                        // AGGREGATE GRAPH
                        var aggregateGraphFileName = String.Format("{0}_aggregategraph.nt", dlcName);
                        var aggregateGraph = new AggregateGraph2014(info, platform, DLCPackageType.Inlay);
                        aggregateGraph.Serialize(aggregateGraphStream);
                        aggregateGraphStream.Flush();
                        aggregateGraphStream.Seek(0, SeekOrigin.Begin);
                        packPsarc.AddEntry(aggregateGraphFileName, aggregateGraphStream);

                        // MANIFEST
                        var attribute = new InlayAttributes2014(info);
                        var attributeDictionary = new Dictionary<string, InlayAttributes2014> { { "Attributes", attribute } };
                        var manifest = new Manifest2014<InlayAttributes2014>(DLCPackageType.Inlay);
                        manifest.Entries.Add(attribute.PersistentID, attributeDictionary);
                        var manifestStream = new MemoryStream();
                        manifestStreamList.Add(manifestStream);
                        manifest.Serialize(manifestStream);
                        manifestStream.Seek(0, SeekOrigin.Begin);
                        var jsonPathPC = "manifests/songs_dlc_{0}/dlc_guitar_{0}.json";
                        var jsonPathConsole = "manifests/songs_dlc/dlc_guitar_{0}.json";
                        packPsarc.AddEntry(String.Format((platform.IsConsole ? jsonPathConsole : jsonPathPC), dlcName), manifestStream);

                        // MANIFEST HEADER
                        var attributeHeaderDictionary = new Dictionary<string, InlayAttributes2014> { { "Attributes", attribute } };
                        var manifestHeader = new ManifestHeader2014<InlayAttributes2014>(platform, DLCPackageType.Inlay);
                        manifestHeader.Entries.Add(attribute.PersistentID, attributeHeaderDictionary);
                        manifestHeader.Serialize(manifestHeaderStream);
                        manifestHeaderStream.Seek(0, SeekOrigin.Begin);
                        var hsanPathPC = "manifests/songs_dlc_{0}/dlc_{0}.hsan";
                        var hsonPathConsole = "manifests/songs_dlc/dlc_{0}.hson";
                        packPsarc.AddEntry(String.Format((platform.IsConsole ? hsonPathConsole : hsanPathPC), dlcName), manifestHeaderStream);

                        // XBLOCK
                        GameXblock<Entity2014> game = GameXblock<Entity2014>.Generate2014(info, platform, DLCPackageType.Inlay);
                        game.SerializeXml(xblockStream);
                        xblockStream.Flush();
                        xblockStream.Seek(0, SeekOrigin.Begin);
                        packPsarc.AddEntry(String.Format("gamexblocks/nguitars/guitar_{0}.xblock", dlcName), xblockStream);

                        // INLAY NIF
                        InlayNif nif = new InlayNif(info);
                        nif.Serialize(nifStream);
                        nifStream.Flush();
                        nifStream.Seek(0, SeekOrigin.Begin);
                        packPsarc.AddEntry(String.Format("assets/gameplay/inlay/{0}.nif", dlcName), nifStream);

                        // WRITE PACKAGE
                        packPsarc.Write(output, !platform.IsConsole);
                        output.Flush();
                        output.Seek(0, SeekOrigin.Begin);
                        output.WriteTmpFile(String.Format("{0}.psarc", dlcName), platform);
                    }
                } catch (Exception ex) {
                    throw ex;
                } finally {
                    // Dispose all objects
                    if (rsenumerableRootStream != null)
                        rsenumerableRootStream.Dispose();
                    if (rsenumerableGuitarStream != null)
                        rsenumerableGuitarStream.Dispose();
                    DeleteTmpFiles(TMPFILES_ART);
                }
            }
        }
        // Load RS1 CDLC into PackageCreator
        public static DLCPackageData RS1LoadFromFolder(string unpackedDir, Platform targetPlatform, bool convert)
        {
            var data = new DLCPackageData();
            data.Arrangements = new List<Arrangement>();
            data.TonesRS2014 = new List<Tone2014>();
            data.Tones = new List<Tone>();

            data.GameVersion = (convert ? GameVersion.RS2014 : GameVersion.RS2012);
            data.SignatureType = PackageMagic.CON;
            // set default volumes
            data.Volume = -6.5F; // default maybe too quite
            data.PreviewVolume = data.Volume;

            //Load song manifest
            var songsManifestJson = Directory.GetFiles(unpackedDir, "songs.manifest.json", SearchOption.AllDirectories);
            if (songsManifestJson.Length < 1)
                throw new DataException("No songs.manifest.json file found.");
            if (songsManifestJson.Length > 1)
                throw new DataException("More than one songs.manifest.json file found.");

            var attr = new List<Attributes>();
            var songsManifest = Manifest.Manifest.LoadFromFile(songsManifestJson[0]).Entries.ToArray();

            for (int smIndex = 0; smIndex < songsManifest.Count(); smIndex++)
            {
                var smData = songsManifest[smIndex].Value.ToArray()[0].Value;
                attr.Add(smData);
            }

            if (attr.FirstOrDefault() == null)
                throw new DataException("songs.manifest.json file did not parse correctly.");

            // Fill SongInfo
            data.SongInfo = new SongInfo();
            data.SongInfo.SongDisplayName = attr.FirstOrDefault().SongName;
            data.SongInfo.SongDisplayNameSort = attr.FirstOrDefault().SongNameSort;
            data.SongInfo.Album = attr.FirstOrDefault().AlbumName;
            data.SongInfo.SongYear = (attr.FirstOrDefault().SongYear == 0 ? 2012 : attr.FirstOrDefault().SongYear);
            data.SongInfo.Artist = attr.FirstOrDefault().ArtistName;
            data.SongInfo.ArtistSort = attr.FirstOrDefault().ArtistNameSort;
            data.Name = attr.FirstOrDefault().SongKey;

            //Load tone manifest, even poorly formed tone_bass.manifest.json
            var toneManifestJson = Directory.GetFiles(unpackedDir, "*tone*.manifest.json", SearchOption.AllDirectories);
            if (toneManifestJson.Length < 1)
                throw new DataException("No tone.manifest.json file found.");

            // toolkit produces multiple tone.manifest.json files when packing RS1 CDLC files
            // rather than change toolkit behavior just merge manifest files for now
            if (toneManifestJson.Length > 1)
            {
                var mergeSettings = new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union };
                JObject toneObject1 = new JObject();

                foreach (var tone in toneManifestJson)
                {
                    JObject toneObject2 = JObject.Parse(File.ReadAllText(tone));
                    //(toneObject1.SelectToken("Entries") as JArray).Merge(toneObject2.SelectToken("Entries"));
                    toneObject1.Merge(toneObject2, mergeSettings);
                }

                toneManifestJson = new string[1];
                toneManifestJson[0] = Path.Combine(unpackedDir, "merged.tone.manifest.json");
                string json = JsonConvert.SerializeObject(toneObject1, Formatting.Indented);
                File.WriteAllText(toneManifestJson[0], json);
            }

            var tones2014 = new List<Tone2014>();
            var tones = new List<Tone>();
            var toneManifest = Manifest.Tone.Manifest.LoadFromFile(toneManifestJson[0]);

            for (int tmIndex = 0; tmIndex < toneManifest.Entries.Count(); tmIndex++)
            {
                var tmData = toneManifest.Entries[tmIndex];
                tones.Add(tmData);
            }

            data.Tones = tones;

            // Load AggregateGraph.nt 
            var songDir = Path.Combine(unpackedDir, data.Name);
            if (targetPlatform.platform == GamePlatform.XBox360)
                songDir = Path.Combine(unpackedDir, "Root", data.Name);

            var aggFile = Directory.GetFiles(songDir, "*.nt", SearchOption.TopDirectoryOnly)[0];
            var aggGraphData = AggregateGraph.AggregateGraph.ReadFromFile(aggFile);

            // Load Exports\Songs\*.xblock
            var xblockDir = Path.Combine(songDir, "Exports\\Songs");
            var xblockFile = Directory.GetFiles(xblockDir, "*.xblock", SearchOption.TopDirectoryOnly)[0];
            // xblockFile = "D:\\Temp\\Mapping\\songs.xblock";
            var songsXblock = XblockX.LoadFromFile(xblockFile);

            // create project map for cross referencing arrangements with tones
            var projectMap = AggregateGraph.AggregateGraph.ProjectMap(aggGraphData, songsXblock, toneManifest);

            // Load xml arrangements
            var xmlFiles = Directory.GetFiles(unpackedDir, "*.xml", SearchOption.AllDirectories);
            if (xmlFiles.Length <= 0)
                throw new DataException("Can not find any XML arrangement files");

            foreach (var xmlFile in xmlFiles)
            {
                if (xmlFile.ToLower().Contains("metadata")) // skip DeadFox file
                    continue;

                // some poorly formed RS1 CDLC use just "vocal"
                if (xmlFile.ToLower().Contains("vocal"))
                {
                    // Add Vocal Arrangement
                    data.Arrangements.Add(new Arrangement
                    {
                        Name = ArrangementName.Vocals,
                        ArrangementType = ArrangementType.Vocal,
                        ScrollSpeed = 20,
                        SongXml = new SongXML { File = xmlFile },
                        SongFile = new SongFile { File = "" },
                        CustomFont = false
                    });
                }
                else
                {
                    var attr2014 = new Attributes2014();
                    var rsSong = new Song();
                    var rsSong2014 = new Song2014();

                    // optimized tone matching effort using project mapping algo
                    var result = projectMap.First(m => String.Equals(Path.GetFileName(m.SongXmlPath), Path.GetFileName(xmlFile), StringComparison.CurrentCultureIgnoreCase));
                    if (result.Tones.Count != 1)
                        throw new DataException("Invalid RS1 CDLC Tones Data");

                    var arrangement = attr.First(s => s.SongXml.ToLower().Contains(result.LLID));
                    var tone = tones.First(t => t.Key == result.Tones[0]);

                    using (var obj1 = new Rs1Converter())
                    {
                        rsSong = obj1.XmlToSong(xmlFile);
                        data.SongInfo.AverageTempo = (int)obj1.AverageBPM(rsSong);
                    }

                    if (arrangement.Tuning == "E Standard")
                        rsSong.Tuning = new TuningStrings { String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0 };
                    else if (arrangement.Tuning == "DropD")
                        rsSong.Tuning = new TuningStrings { String0 = -2, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0 };
                    else if (arrangement.Tuning == "OpenG")
                        rsSong.Tuning = new TuningStrings { String0 = -2, String1 = -2, String2 = 0, String3 = 0, String4 = 0, String5 = -2 };
                    else if (arrangement.Tuning == "EFlat")
                        rsSong.Tuning = new TuningStrings { String0 = -1, String1 = -1, String2 = -1, String3 = -1, String4 = -1, String5 = -1 };
                    else // default to standard tuning
                    {
                        arrangement.Tuning = "E Standard";
                        rsSong.Tuning = new TuningStrings { String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0 };
                    }

                    // save/write the changes to xml file
                    using (var obj1 = new Rs1Converter())
                        obj1.SongToXml(rsSong, xmlFile, true);

                    if (convert)
                        using (var obj1 = new Rs1Converter())
                            tones2014.Add(obj1.ToneToTone2014(tone, rsSong));

                    // load attr2014 with RS1 mapped values for use by Arrangement()
                    attr2014.Tone_Base = tone.Name;
                    attr2014.ArrangementName = arrangement.ArrangementName;
                    attr2014.CentOffset = 0;
                    attr2014.DynamicVisualDensity = new List<float>() { 2 };
                    attr2014.SongPartition = arrangement.SongPartition;
                    attr2014.PersistentID = IdGenerator.Guid().ToString();
                    attr2014.MasterID_RDV = RandomGenerator.NextInt();
                    attr2014.ArrangementProperties = new SongArrangementProperties2014();

                    // processing order is important - CAREFUL
                    // RouteMask  None = 0, Lead = 1, Rhythm = 2, Any = 3, Bass = 4
                    // XML file names are usually meaningless to arrangement determination

                    if (arrangement.ArrangementName.ToLower().Contains("lead") ||
                        rsSong.Arrangement.ToLower().Contains("lead"))
                    {
                        attr2014.ArrangementName = "Lead";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask = (int)RouteMask.Lead;
                        attr2014.ArrangementProperties.PathLead = 1;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("rhythm") ||
                        rsSong.Arrangement.ToLower().Contains("rhythm"))
                    // || rsSong.Arrangement.ToLower().Contains("guitar"))
                    {
                        attr2014.ArrangementName = "Rhythm";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask = (int)RouteMask.Rhythm;
                        attr2014.ArrangementProperties.PathLead = 0;
                        attr2014.ArrangementProperties.PathRhythm = 1;
                        attr2014.ArrangementProperties.PathBass = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("combo") ||
                        rsSong.Arrangement.ToLower().Contains("combo"))
                    {
                        attr2014.ArrangementName = "Combo";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask = arrangement.EffectChainName.ToLower().Contains("lead") ? (int)RouteMask.Lead : (int)RouteMask.Rhythm;
                        attr2014.ArrangementProperties.PathLead = arrangement.EffectChainName.ToLower().Contains("lead") ? 1 : 0;
                        attr2014.ArrangementProperties.PathRhythm = arrangement.EffectChainName.ToLower().Contains("lead") ? 0 : 1;
                        attr2014.ArrangementProperties.PathBass = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("bass") ||
                        rsSong.Arrangement.ToLower().Contains("bass"))
                    {
                        attr2014.ArrangementName = "Bass";
                        attr2014.ArrangementType = (int)ArrangementType.Bass;
                        attr2014.ArrangementProperties.RouteMask = (int)RouteMask.Bass;
                        attr2014.ArrangementProperties.PathLead = 0;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass = 1;
                    }
                    else
                    {
                        // default to Lead arrangment
                        attr2014.ArrangementName = "Lead";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask = (int)RouteMask.Lead;
                        attr2014.ArrangementProperties.PathLead = 1;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass = 0;

                        Console.WriteLine("RS1->RS2 CDLC Conversion defaulted to 'Lead' arrangment");
                    }

                    if (convert) // RS1 -> RS2 magic
                    {
                        using (var obj1 = new Rs1Converter())
                            rsSong2014 = obj1.SongToSong2014(rsSong);

                        // update ArrangementProperties
                        rsSong2014.ArrangementProperties.RouteMask = attr2014.ArrangementProperties.RouteMask;
                        rsSong2014.ArrangementProperties.PathLead = attr2014.ArrangementProperties.PathLead;
                        rsSong2014.ArrangementProperties.PathRhythm = attr2014.ArrangementProperties.PathRhythm;
                        rsSong2014.ArrangementProperties.PathBass = attr2014.ArrangementProperties.PathBass;
                        rsSong2014.ArrangementProperties.StandardTuning = (arrangement.Tuning == "E Standard" ? 1 : 0);

                        // <note time="58.366" linkNext="0" accent="0" bend="0" fret="7" hammerOn="0" harmonic="0" hopo="0" ignore="0" leftHand="-1" mute="0" palmMute="0" pluck="-1" pullOff="0" slap="-1" slideTo="-1" string="3" sustain="0.108" tremolo="0" harmonicPinch="0" pickDirection="0" rightHand="-1" slideUnpitchTo="-1" tap="0" vibrato="0" />
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Bend != 0)))
                            rsSong2014.ArrangementProperties.Bends = 1;
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Hopo != 0)))
                            rsSong2014.ArrangementProperties.Hopo = 1;
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.SlideTo != -1)))
                            rsSong2014.ArrangementProperties.Slides = 1;
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Sustain > 0)))
                            rsSong2014.ArrangementProperties.Sustain = 1;

                        // fixing times that are off
                        var lastEbeatsTime = rsSong2014.Ebeats[rsSong2014.Ebeats.Length - 1].Time;
                        var lastPhraseIterationsTime = rsSong2014.PhraseIterations[rsSong2014.PhraseIterations.Length - 1].Time;

                        // tested ... not source of in game hangs
                        // confirm last PhraseIterations time is less than last Ebeats time
                        if (lastPhraseIterationsTime > lastEbeatsTime)
                        {
                            rsSong2014.PhraseIterations[rsSong2014.PhraseIterations.Length - 1].Time = lastEbeatsTime;
                            rsSong2014.Sections[rsSong2014.Sections.Length - 1].StartTime = lastEbeatsTime;
                        }

                        // tested ... not source of in game hangs
                        // confirm SongLength at least equals last Ebeats time
                        if (rsSong2014.SongLength < lastEbeatsTime)
                            rsSong2014.SongLength = lastEbeatsTime;

                        using (var obj2 = new Rs2014Converter())
                            obj2.Song2014ToXml(rsSong2014, xmlFile, true);
                    }

                    // Adding Song Arrangement
                    try
                    {
                        data.Arrangements.Add(new Arrangement(attr2014, xmlFile));
                    }
                    catch (Exception ex)
                    {
                        // mainly for the benifit of convert2012 CLI users
                        Console.WriteLine(@"This CDLC could not be auto converted." + Environment.NewLine + "You can still try manually adding the arrangements and assests." + Environment.NewLine + ex.Message);
                    }
                }
            }
            if (convert)
            {
                // get rid of duplicate tone names
                tones2014 = tones2014.Where(p => p.Name != null)
                    .GroupBy(p => p.Name).Select(g => g.First()).ToList();
                data.TonesRS2014 = tones2014;
            }

            //Get Album Artwork DDS Files
            var artFiles = Directory.GetFiles(unpackedDir, "*.dds", SearchOption.AllDirectories);
            if (artFiles.Length < 1)
                throw new DataException("No Album Artwork file found.");
            if (artFiles.Length > 1)
                throw new DataException("More than one Album Artwork file found.");

            var targetArtFiles = new List<DDSConvertedFile>();
            data.AlbumArtPath = artFiles[0];
            targetArtFiles.Add(new DDSConvertedFile() { sizeX = 256, sizeY = 256, sourceFile = artFiles[0], destinationFile = artFiles[0].CopyToTempFile(".dds") });
            data.ArtFiles = targetArtFiles;

            //Audio files
            var targetAudioFiles = new List<string>();
            var audioFiles = Directory.GetFiles(unpackedDir, "*.ogg", SearchOption.AllDirectories);
            if (audioFiles.Length < 1)
                throw new DataException("No Audio file found.");
            if (audioFiles.Length > 2)
                throw new DataException("Too many Audio files found.");

            int i;
            for (i = 0; i < audioFiles.Length; i++)
            {
                if (convert && audioFiles[i].Contains("_fixed.ogg")) // use it
                    break;
                if (!convert && !audioFiles[i].Contains("_fixed.ogg"))
                    break;
            }
            // FIXME: platform specific decode is broken
            var sourcePlatform = unpackedDir.GetPlatform();
            if (targetPlatform.IsConsole != (sourcePlatform = audioFiles[i].GetAudioPlatform()).IsConsole)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(audioFiles[i]), String.Format("{0}_cap.ogg", Path.GetFileNameWithoutExtension(audioFiles[i])));
                OggFile.ConvertAudioPlatform(audioFiles[i], newFile);
                audioFiles[i] = newFile;
            }

            targetAudioFiles.Add(audioFiles[i]);

            if (!targetAudioFiles.Any())
                throw new DataException("Audio file not found.");

            var a = new FileInfo(audioFiles[i]);
            data.OggPath = a.FullName;

            //AppID
            if (!sourcePlatform.IsConsole)
            {
                if (!convert)
                {
                    var appidFile = Directory.GetFiles(unpackedDir, "*APP_ID*", SearchOption.AllDirectories);
                    if (appidFile.Length > 0)
                        data.AppId = File.ReadAllText(appidFile[0]);
                }
                else
                    data.AppId = "248750";
            }

            try
            {//TODO: validate that rs1 songs have no this file
                //Package version
                var versionFile = Directory.GetFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories);
                if (versionFile.Length > 0)
                    data.PackageVersion = GeneralExtensions.ReadPackageVersion(versionFile[0]);
                else data.PackageVersion = "1";
            }
            catch {}

            if (convert)
                data.Tones = null;

            return data;
        }
        private static void ConvertPackageRebuilding(string unpackedDir, string targetFileName, Platform targetPlatform, string appId)
        {
            var data = new DLCPackageData(unpackedDir, targetPlatform);
            if (!targetPlatform.IsConsole)
                data.AppId = appId;

            //Build
            RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(data, platform: new Platform(targetPlatform.platform, GameVersion.RS2014));
        }
        private void inlayGenerateButton_Click(object sender, EventArgs e)
        {
            // put inlays in proper directory
            if (Directory.Exists(ConfigRepository.Instance()["general_rs2014path"]))
            {
                dlcSavePath = Path.Combine(ConfigRepository.Instance()["general_rs2014path"], "dlc", "Inlays");
            }
            else
            {
                dlcSavePath = Path.Combine(workDir, "cgm", "dlc", "Inlays");
            }

            if (!Directory.Exists(dlcSavePath))
                Directory.CreateDirectory(dlcSavePath);

            using (var ofd = new SaveFileDialog())
            {
                ofd.FileName = (InlayName.GetValidInlayName(Frets24).ToLower()).GetValidFileName();
                ofd.Filter = "Custom Inlay DLC (*.*)|*.*";
                ofd.InitialDirectory = dlcSavePath;

                if (ofd.ShowDialog() != DialogResult.OK) return;
                dlcSavePath = ofd.FileName;
            }
            DLCPackageData packageData = new DLCPackageData();
            packageData.Inlay = new InlayData();
            packageData.Inlay.InlayPath = InlayFile;
            packageData.Inlay.IconPath = IconFile;
            packageData.Inlay.Frets24 = Frets24;
            packageData.Inlay.Colored = Colored;
            packageData.Inlay.DLCSixName = GeneralExtensions.RandomName(6);

            // CRITICAL - 24 fret inlays have naming dependencies
            if (Frets24) packageData.Inlay.DLCSixName = String.Format("24fret_{0}", packageData.Inlay.DLCSixName);

            packageData.Name = InlayName;
            packageData.AppId = appIdCombo.SelectedValue.ToString();

            // Saving for later
            ConfigRepository.Instance()["cgm_inlayname"] = InlayName;
            ConfigRepository.Instance()["cgm_24frets"] = Frets24.ToString();
            ConfigRepository.Instance()["cgm_coloredinlay"] = Colored.ToString();

            // Generate
            OverwriteExistingPackage();

            if (Path.GetFileName(dlcSavePath).Contains(" ") && platformPS3.Checked)
                if (!ConfigRepository.Instance().GetBoolean("creator_ps3pkgnamewarn"))
                {
                    MessageBox.Show(String.Format("PS3 package name can't support space character due to encryption limitation. {0} Spaces will be automatic removed for your PS3 package name.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    ConfigRepository.Instance()["creator_ps3pkgnamewarn"] = true.ToString();
                }

            if (!bwGenerate.IsBusy && packageData != null)
            {
                updateProgress.Visible = true;
                currentOperationLabel.Visible = true;
                inlayGenerateButton.Enabled = false;
                bwGenerate.RunWorkerAsync(packageData);
            }
        }
Exemplo n.º 40
0
        // Load RS1 CDLC into PackageCreator
        public static DLCPackageData RS1LoadFromFolder(string unpackedDir, Platform targetPlatform, bool convert)
        {
            var data = new DLCPackageData();

            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();
            data.Tones        = new List <Tone>();

            data.GameVersion   = (convert ? GameVersion.RS2014 : GameVersion.RS2012);
            data.SignatureType = PackageMagic.CON;
            // set default volumes
            data.Volume        = (float)-5.5; // - 7 default a little too quite
            data.PreviewVolume = data.Volume;

            //Load song manifest
            var songsManifestJson = Directory.GetFiles(unpackedDir, "songs.manifest.json", SearchOption.AllDirectories);

            if (songsManifestJson.Length < 1)
            {
                throw new DataException("No songs.manifest.json file found.");
            }
            if (songsManifestJson.Length > 1)
            {
                throw new DataException("More than one songs.manifest.json file found.");
            }

            List <Attributes> attr = new List <Attributes>();
            var songsManifest      = Manifest.Manifest.LoadFromFile(songsManifestJson[0]).Entries.ToArray();

            for (int smIndex = 0; smIndex < songsManifest.Count(); smIndex++)
            {
                var smData = songsManifest[smIndex].Value.ToArray()[0].Value;
                attr.Add(smData);
            }

            if (attr.FirstOrDefault() == null)
            {
                throw new DataException("songs.manifest.json file did not parse correctly.");
            }

            // Fill SongInfo
            data.SongInfo = new SongInfo();
            data.SongInfo.SongDisplayName     = attr.FirstOrDefault().SongName;
            data.SongInfo.SongDisplayNameSort = attr.FirstOrDefault().SongNameSort;
            data.SongInfo.Album      = attr.FirstOrDefault().AlbumName;
            data.SongInfo.SongYear   = (attr.FirstOrDefault().SongYear == 0 ? 2012 : attr.FirstOrDefault().SongYear);
            data.SongInfo.Artist     = attr.FirstOrDefault().ArtistName;
            data.SongInfo.ArtistSort = attr.FirstOrDefault().ArtistNameSort;
            data.Name = attr.FirstOrDefault().SongKey;

            //Load tone manifest, even poorly formed tone_bass.manifest.json
            var toneManifestJson = Directory.GetFiles(unpackedDir, "*tone*.manifest.json", SearchOption.AllDirectories);

            if (toneManifestJson.Length < 1)
            {
                throw new DataException("No tone.manifest.json file found.");
            }

            // toolkit produces multiple tone.manifest.json files when packing RS1 CDLC files
            // rather than change toolkit behavior just merge manifest files for now
            if (toneManifestJson.Length > 1)
            {
                var mergeSettings = new JsonMergeSettings {
                    MergeArrayHandling = MergeArrayHandling.Union
                };
                JObject toneObject1 = new JObject();

                foreach (var tone in toneManifestJson)
                {
                    JObject toneObject2 = JObject.Parse(File.ReadAllText(tone));
                    //(toneObject1.SelectToken("Entries") as JArray).Merge(toneObject2.SelectToken("Entries"));
                    toneObject1.Merge(toneObject2, mergeSettings);
                }

                toneManifestJson    = new string[1];
                toneManifestJson[0] = Path.Combine(unpackedDir, "merged.tone.manifest");
                string json = JsonConvert.SerializeObject(toneObject1, Formatting.Indented);
                File.WriteAllText(toneManifestJson[0], json);
            }

            List <Tone> tones        = new List <Tone>();
            var         toneManifest = Manifest.Tone.Manifest.LoadFromFile(toneManifestJson[0]);

            for (int tmIndex = 0; tmIndex < toneManifest.Entries.Count(); tmIndex++)
            {
                var tmData = toneManifest.Entries[tmIndex];
                tones.Add(tmData);
            }

            data.Tones = tones;

            // Load xml arrangements
            var xmlFiles = Directory.GetFiles(unpackedDir, "*.xml", SearchOption.AllDirectories);

            if (xmlFiles.Length <= 0)
            {
                throw new DataException("Can not find any XML arrangement files");
            }

            List <Tone2014> tones2014 = new List <Tone2014>();

            foreach (var xmlFile in xmlFiles)
            {
                if (xmlFile.ToLower().Contains("metadata")) // skip DF file
                {
                    continue;
                }

                // some poorly formed RS1 CDLC use just "vocal"
                if (xmlFile.ToLower().Contains("vocal"))
                {
                    var voc = new Arrangement();
                    voc.Name            = ArrangementName.Vocals;
                    voc.ArrangementType = ArrangementType.Vocal;
                    voc.ScrollSpeed     = 20;
                    voc.SongXml         = new SongXML {
                        File = xmlFile
                    };
                    voc.SongFile = new SongFile {
                        File = ""
                    };
                    voc.CustomFont = false;

                    // Add Vocal Arrangement
                    data.Arrangements.Add(voc);
                }
                else
                {
                    Attributes2014 attr2014 = new Attributes2014();
                    Song           rsSong   = new Song();
                    bool           foundToneForArrangement = false;

                    using (var obj1 = new Rs1Converter())
                    {
                        rsSong = obj1.XmlToSong(xmlFile);
                        data.SongInfo.AverageTempo = (int)obj1.AverageBPM(rsSong);
                    }

                    // matchup rsSong, songs.manifest, and tone.manifest files
                    foreach (var arrangement in attr)
                    {
                        // apply best guesstimate matching, RS1 CDLC are very inconsistent
                        // TODO: improve accuracy possibly by matching .xblock data
                        string xmlArr = rsSong.Arrangement.ToLowerInvariant();
                        // var matchLead = Regex.Match(xmlArr.ToLower(), "^lead$", RegexOptions.IgnoreCase);
                        // if(matchLead.Success)

                        if (xmlArr.ToLower().Contains("guitar") && !xmlArr.ToLower().Equals("lead") && !xmlArr.ToLower().Equals("rhythm") && !xmlArr.ToLower().Equals("combo") && !xmlArr.ToLower().Equals("bass"))
                        {
                            if (xmlArr.ToUpper().Equals("PART REAL_GUITAR_22")) //
                            {
                                if (arrangement.ArrangementName.ToLower().Contains("combo"))
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Rhythm";
                                }
                                else
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Lead";
                                }
                            }
                            else
                            {
                                if (arrangement.ArrangementName.ToLower().Contains("combo"))
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Rhythm";
                                }
                                else
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Lead";
                                }
                            }
                        }

                        if (xmlArr.ToLower().Contains("lead") && arrangement.ArrangementName.ToLower().Contains("rhythm"))
                        {
                            rsSong.Arrangement = arrangement.ArrangementName = "Lead";
                        }

                        if (xmlArr.ToLower().Contains("rhythm") && arrangement.ArrangementName.ToLower().Contains("lead"))
                        {
                            rsSong.Arrangement = arrangement.ArrangementName = "Rhythm";
                        }

                        if (xmlArr.ToLower().Contains("lead"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("lead"))
                            {
                                continue;
                            }
                        }
                        if (xmlArr.ToLower().Contains("rhythm"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("rhythm"))
                            {
                                continue;
                            }
                        }
                        if (xmlArr.ToLower().Contains("combo"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("combo"))
                            {
                                continue;
                            }
                        }
                        if (xmlArr.ToLower().Contains("bass"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("bass"))
                            {
                                continue;
                            }
                        }

                        if (rsSong.Part == arrangement.SongPartition || tones.Count == 1) // this is inaccurate for some
                        {
                            foreach (var tone in tones)                                   // tone.manifest
                            {
                                if (String.IsNullOrEmpty(arrangement.EffectChainName))
                                {
                                    arrangement.EffectChainName = "Default";
                                }

                                if (arrangement.EffectChainName.ToLower() == tone.Key.ToLower() || tones.Count == 1) // ok
                                {
                                    if (convert)
                                    {
                                        using (var obj1 = new Rs1Converter())
                                            tones2014.Add(obj1.ToneToTone2014(tone));

                                        // added for consistent naming
                                        tone.Name = tones2014[tones2014.Count - 1].Name;
                                        tone.Key  = tones2014[tones2014.Count - 1].Key;
                                    }

                                    // load attr2014 with RS1 mapped values for use by Arrangement()
                                    attr2014.Tone_Base            = tone.Name;
                                    attr2014.ArrangementName      = arrangement.ArrangementName;
                                    attr2014.CentOffset           = 0;
                                    attr2014.DynamicVisualDensity = new List <float>()
                                    {
                                        2
                                    };
                                    attr2014.SongPartition = arrangement.SongPartition;
                                    attr2014.PersistentID  = IdGenerator.Guid().ToString();
                                    attr2014.MasterID_RDV  = RandomGenerator.NextInt();

                                    attr2014.ArrangementProperties = new SongArrangementProperties2014();

                                    if (arrangement.ArrangementName.ToLower().Contains("lead"))
                                    {
                                        attr2014.ArrangementType = 0;
                                        attr2014.ArrangementProperties.RouteMask = 1;
                                    }
                                    else if (arrangement.ArrangementName.ToLower().Contains("rhythm"))
                                    {
                                        attr2014.ArrangementType = 1;
                                        attr2014.ArrangementProperties.RouteMask = 2;
                                    }
                                    else if (arrangement.ArrangementName.ToLower().Contains("combo"))
                                    {
                                        attr2014.ArrangementType = 2;
                                        attr2014.ArrangementProperties.RouteMask = arrangement.EffectChainName.ToLower().Contains("lead") ? 1 : 2;
                                    }
                                    else if (arrangement.ArrangementName.ToLower().Contains("bass"))
                                    {
                                        attr2014.ArrangementType = 3;
                                        attr2014.ArrangementProperties.RouteMask = 4;
                                    }
                                    else
                                    {
                                        // some RS1 CDLC do not have a valid ArrangementName
                                        if (rsSong.Arrangement.ToLower().Contains("guitar"))
                                        {
                                            attr2014.ArrangementName = "Lead";
                                            attr2014.ArrangementType = 0;
                                            attr2014.ArrangementProperties.RouteMask = 1;
                                        }
                                        else if (rsSong.Arrangement.ToLower().Contains("bass"))
                                        {
                                            attr2014.ArrangementName = "Bass";
                                            attr2014.ArrangementType = 3;
                                            attr2014.ArrangementProperties.RouteMask = 4;
                                        }
                                        else // default to rhythm
                                        {
                                            attr2014.ArrangementName = "Rhythm";
                                            attr2014.ArrangementType = 1;
                                            attr2014.ArrangementProperties.RouteMask = 2;
                                        }
                                    }

                                    if (arrangement.Tuning == "E Standard")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                                        }
                                    }
                                    ;
                                    else if (arrangement.Tuning == "DropD")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = -2, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                                        }
                                    }
                                    ;
                                    else if (arrangement.Tuning == "OpenG")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = -2, String1 = -2, String2 = 0, String3 = 0, String4 = 0, String5 = -2
                                        }
                                    }
                                    ;
                                    else if (arrangement.Tuning == "EFlat")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = -1, String1 = -1, String2 = -1, String3 = -1, String4 = -1, String5 = -1
                                        }
                                    }
                                    ;
                                    else // default to standard tuning
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                                        }
                                    };

                                    foundToneForArrangement = true;
                                    break;
                                }
                            }
                        }

                        if (foundToneForArrangement)
                        {
                            break;
                        }
                    }

                    if (!foundToneForArrangement)
                    {
                        Console.WriteLine(@"Could not determine the arrangement tone pairing");
                    }

                    // write the tones to file
                    using (var obj1 = new Rs1Converter())
                        obj1.SongToXml(rsSong, xmlFile, true);

                    if (convert) // RS1 -> RS2
                    {
                        Song2014 rsSong2014 = new Song2014();

                        using (var obj1 = new Rs1Converter())
                            rsSong2014 = obj1.SongToSong2014(rsSong);

                        using (var obj2 = new Rs2014Converter())
                            obj2.Song2014ToXml(rsSong2014, xmlFile, true);
                    }

                    // Adding Song Arrangement
                    try
                    {
                        data.Arrangements.Add(new Arrangement(attr2014, xmlFile));
                    }
                    catch (Exception ex)
                    {
                        // mainly for the benifit of convert2012 CLI users
                        Console.WriteLine(@"This CDLC could not be auto converted." + Environment.NewLine + "You can still try manually adding the arrangements and assests." + Environment.NewLine + ex.Message);
                    }
                }
            }

            data.TonesRS2014 = tones2014;

            //Get Album Artwork DDS Files
            var artFiles = Directory.GetFiles(unpackedDir, "*.dds", SearchOption.AllDirectories);

            if (artFiles.Length < 1)
            {
                throw new DataException("No Album Artwork file found.");
            }
            if (artFiles.Length > 1)
            {
                throw new DataException("More than one Album Artwork file found.");
            }

            var targetArtFiles = new List <DDSConvertedFile>();

            data.AlbumArtPath = artFiles[0];
            targetArtFiles.Add(new DDSConvertedFile()
            {
                sizeX = 256, sizeY = 256, sourceFile = artFiles[0], destinationFile = artFiles[0].CopyToTempFile(".dds")
            });
            data.ArtFiles = targetArtFiles;

            //Audio files
            var targetAudioFiles = new List <string>();
            var audioFiles       = Directory.GetFiles(unpackedDir, "*.ogg", SearchOption.AllDirectories);

            if (audioFiles.Length < 1)
            {
                throw new DataException("No Audio file found.");
            }
            if (audioFiles.Length > 2)
            {
                throw new DataException("Too many Audio files found.");
            }

            int i;

            for (i = 0; i < audioFiles.Length; i++)
            {
                if (convert && audioFiles[i].Contains("_fixed.ogg")) // use it
                {
                    break;
                }
                if (!convert && !audioFiles[i].Contains("_fixed.ogg"))
                {
                    break;
                }
            }

            var sourcePlatform = unpackedDir.GetPlatform();

            if (targetPlatform.IsConsole != (sourcePlatform = audioFiles[i].GetAudioPlatform()).IsConsole)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(audioFiles[i]), String.Format("{0}_cap.ogg", Path.GetFileNameWithoutExtension(audioFiles[i])));
                OggFile.ConvertAudioPlatform(audioFiles[i], newFile);
                audioFiles[i] = newFile;
            }

            targetAudioFiles.Add(audioFiles[i]);

            if (!targetAudioFiles.Any())
            {
                throw new DataException("Audio file not found.");
            }

            FileInfo a = new FileInfo(audioFiles[i]);

            data.OggPath = a.FullName;

            //AppID
            if (!convert)
            {
                var appidFile = Directory.GetFiles(unpackedDir, "*APP_ID*", SearchOption.AllDirectories);
                if (appidFile.Length > 0)
                {
                    data.AppId = File.ReadAllText(appidFile[0]);
                }
            }
            else
            {
                data.AppId = "248750";
            }

            //Package version
            var versionFile = Directory.GetFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories);

            if (versionFile.Length > 0)
            {
                data.PackageVersion = GeneralExtensions.ReadPackageVersion(versionFile[0]);
            }
            else
            {
                data.PackageVersion = "1";
            }

            if (convert)
            {
                data.Tones = null;
            }

            return(data);
        }