Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("DJSLACKERS - DJMainExtract");

            args = Subfolder.Parse(args);

            if (System.Diagnostics.Debugger.IsAttached && args.Length == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Debugger attached. Input file name:");
                args = new string[] { Console.ReadLine() };
                if (args[0] == "")
                {
                    args[0] = @"D:\chds\753jaa11.chd";
                }
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (File.Exists(args[i]))
                {
                    string sourceFileName = Path.GetFileNameWithoutExtension(args[i]);
                    string sourcePath     = Path.GetDirectoryName(args[i]);
                    string targetPath     = Path.Combine(sourcePath, sourceFileName);
                    Directory.CreateDirectory(targetPath);

                    Console.WriteLine();
                    Console.WriteLine("Processing " + args[i]);

                    using (FileStream fs = new FileStream(args[i], FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        CHD          chd    = CHD.Load(fs);
                        BinaryReader reader = new BinaryReader(chd);

                        long totalChunks = (int)(chd.Length / 0x1000000L);

                        for (int j = 0; j < totalChunks; j++)
                        {
                            chd.Position = (long)j * 0x1000000;
                            //DJMainChunk chunk = DJMainChunk.Read(chd, new int[] { 0x002000, 0x006000, 0x00A000, 0x00E000, 0x012000, 0x016000 }, new int[] { 0x000000, 0x000200 }, 0x020000);
                            DJMainChunk chunk = DJMainChunk.Read(chd, new int[] { 0x000400 }, new int[] { 0x000000, 0x000200 }, 0x002000);

                            if (chunk.ChartCount > 0)
                            {
                                Console.WriteLine("Exporting set " + j.ToString());
                                string fname = Path.Combine(Path.GetDirectoryName(args[i]), Util.ConvertToDecimalString(j, 3));
                                //ConvertHelper.BemaniToBMS.ConvertChart(chunk.Charts[0], 16, 192, fname, "", 0, chunk.SampleMaps[0]);
                                ConvertHelper.BemaniToBMS.ConvertSounds(chunk.Sounds, fname, 0.6f);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("DJSLACKERS - DJMainExtract");

            args = Subfolder.Parse(args);

            if (System.Diagnostics.Debugger.IsAttached && args.Length == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Debugger attached. Input file name:");
                args = new string[] { Console.ReadLine() };
                if (args[0] == "")
                {
                    args[0] = @"D:\chds\bmfinal.zip";
                }
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (File.Exists(args[i]))
                {
                    string sourceFileName = Path.GetFileNameWithoutExtension(args[i]);
                    string sourcePath     = Path.GetDirectoryName(args[i]);
                    string targetPath     = Path.Combine(sourcePath, sourceFileName);
                    Directory.CreateDirectory(targetPath);

                    Console.WriteLine();
                    Console.WriteLine("Processing " + args[i]);

                    // default config
                    config              = new Configuration();
                    sampleMapOffsets    = new int[] { 0x000000, 0x000200 };
                    sampleMapAssignment = new int[] { 0, 0, 0, 0, 0, 0 };
                    soundOffset         = 0x002000;

                    var source = ConvertHelper.StreamAdapter.Open(args[i]);
                    using (var fs = source.Stream)
                    {
                        int chunkLength = 0x1000000;

                        BinaryReader reader = new BinaryReader(fs);

                        totalChunks = (long)(source.Length - chunkLength) / (long)chunkLength;
                        var identifiedMix = IdentifyMix(fs);

                        if (totalChunks >= 1)
                        {
                            byte[] rawData = new byte[chunkLength];

                            for (int j = 0; j < totalChunks; j++)
                            {
                                if (fs.Read(rawData, 0, CHUNK_LENGTH) < CHUNK_LENGTH)
                                {
                                    break;
                                }

                                using (MemoryStream ms = new MemoryStream(rawData))
                                {
                                    var    chunk     = DJMainChunk.Read(ms, chartOffsets, sampleMapOffsets, soundOffset);
                                    string soundPath = Path.Combine(targetPath, Util.ConvertToDecimalString(j, 3));
                                    string chartPath = Path.Combine(soundPath, Util.ConvertToDecimalString(j, 3));

                                    if (chunk.ChartCount > 0)
                                    {
                                        Console.WriteLine("Converting set " + j.ToString());
                                        Directory.CreateDirectory(soundPath);
                                        for (int chartIndex = 0; chartIndex < chunk.ChartCount; chartIndex++)
                                        {
                                            ConvertHelper.BemaniToBMS.ConvertChart(chunk.Charts[chartIndex], config, chartPath, chartIndex, chunk.SampleMaps[sampleMapAssignment[chartIndex]]);
                                        }

                                        Console.WriteLine("Consolidating set " + j.ToString());
                                        ConvertHelper.StereoCombiner.Process(chunk.Sounds, chunk.Charts, stereoAmp);
                                        Console.WriteLine("Writing set " + j.ToString());
                                        ConvertHelper.BemaniToBMS.ConvertSounds(chunk.Sounds, soundPath, 0.6f);
                                    }
                                    else
                                    {
                                        bool chunkEmpty = true;
                                        byte byteZero   = rawData[0];
                                        for (int k = 0; k < chunkLength; k++)
                                        {
                                            if (rawData[k] != byteZero)
                                            {
                                                chunkEmpty = false;
                                                break;
                                            }
                                        }
                                        if (!chunkEmpty)
                                        {
                                            Console.WriteLine("Nonempty chunk failed heuristic: " + j.ToString());
                                            File.WriteAllBytes(soundPath, rawData);
                                        }
                                        else
                                        {
                                            Console.WriteLine("Skipping empty set " + j.ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }