Пример #1
0
        private static void ProcessAllBinaries(uint acbFormatVersion, DecodeParams baseDecodeParams, string extractDir, Afs2Archive archive, Stream dataStream, bool isInternal)
        {
            if (!Directory.Exists(extractDir))
            {
                Directory.CreateDirectory(extractDir);
            }

            var afsSource    = isInternal ? "internal" : "external";
            var decodeParams = baseDecodeParams;

            if (acbFormatVersion >= NewEncryptionVersion)
            {
                decodeParams.KeyModifier = archive.HcaKeyModifier;
            }
            else
            {
                decodeParams.KeyModifier = 0;
            }

            foreach (var entry in archive.Files)
            {
                var record          = entry.Value;
                var extractFileName = AcbFile.GetSymbolicFileNameFromCueId(record.CueId);

                extractFileName = extractFileName.ReplaceExtension(".bin", ".wav");

                var extractFilePath = Path.Combine(extractDir, extractFileName);

                using (var fileData = AcbHelper.ExtractToNewStream(dataStream, record.FileOffsetAligned, (int)record.FileLength)) {
                    var isHcaStream = HcaReader.IsHcaStream(fileData);

                    Console.Write("Processing {0} AFS: #{1} (offset={2} size={3})...   ", afsSource, record.CueId, record.FileOffsetAligned, record.FileLength);

                    if (isHcaStream)
                    {
                        try {
                            using (var fs = File.Open(extractFilePath, FileMode.Create, FileAccess.Write, FileShare.Write)) {
                                DecodeHca(fileData, fs, decodeParams);
                            }

                            Console.WriteLine("decoded");
                        } catch (Exception ex) {
                            if (File.Exists(extractFilePath))
                            {
                                File.Delete(extractFilePath);
                            }

                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("skipped (not HCA)");
                    }
                }
            }
        }
Пример #2
0
        // ReSharper disable once IdentifierTypo
        private static void AfsToWav(Afs2FileRecord afsRecord, Stream awbStream, DecodeParams decodeParams,
                                     string output)
        {
            using var fileData =
                      AcbHelper.ExtractToNewStream(awbStream, afsRecord.FileOffsetAligned, (int)afsRecord.FileLength);
            var isHcaStream = DereTore.Exchange.Audio.HCA.HcaReader.IsHcaStream(fileData);

            if (!isHcaStream)
            {
                return;
            }

            using var fs = File.OpenWrite(output);
            try
            {
                HcaToWav(fileData, fs, decodeParams);
            }
            catch (Exception)
            {
                Console.Error.WriteLine($"Failed to convert {output}:");
                throw;
            }
        }
Пример #3
0
        private static void ExtractAllBinaries(string extractDir, Afs2Archive archive, Stream dataStream, bool isInternal)
        {
            if (!Directory.Exists(extractDir))
            {
                Directory.CreateDirectory(extractDir);
            }

            var afsSource = isInternal ? "internal" : "external";

            foreach (var entry in archive.Files)
            {
                var record          = entry.Value;
                var extractFileName = AcbFile.GetSymbolicFileNameFromCueId(record.CueId);
                var extractFilePath = Path.Combine(extractDir, extractFileName);

                using (var fs = File.Open(extractFilePath, FileMode.Create, FileAccess.Write, FileShare.Write)) {
                    using (var fileData = AcbHelper.ExtractToNewStream(dataStream, record.FileOffsetAligned, (int)record.FileLength)) {
                        WriteFile(fileData, fs);
                    }
                }

                Console.WriteLine("Extracted from {0} AFS: #{1} (offset={2} size={3})", afsSource, record.CueId, record.FileOffsetAligned, record.FileLength);
            }
        }