Ejemplo n.º 1
0
        private void TryReplacingTrackContents(Blackboard blackboard, TemporaryTrack track)
        {
            if (track.ExpectedName == null)
            {
                return;
            }

            var originalCodec = AvailableCodecs.GetCodec(track.CurrentCodec);

            if (originalCodec == null)
            {
                blackboard.Logger.Error($"The track ({track.ExpectedName}) uses the {track.OriginalEntry.Codec} Codec, but AudioMog has no handler to replace it! Skipping!");
                return;
            }

            var typelessFilePath = Path.Combine(_hcaFilesFolder, track.ExpectedName);

            if (blackboard.Settings.UseWavFilesIfAvailable)
            {
                var wavFilePath = AddExtension(typelessFilePath, ".wav");
                if (File.Exists(wavFilePath))
                {
                    blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, ".wav")}!");
                    var wavFileBytes = File.ReadAllBytes(wavFilePath);
                    var wavReader    = new WaveReader();
                    var audioData    = wavReader.Read(wavFileBytes);
                    var hcaWriter    = new HcaWriter();
                    var hcaFileBytes = hcaWriter.GetFile(audioData);
                    track.RawPortion   = hcaFileBytes;
                    track.CurrentCodec = MaterialCodecType.HCA;
                    return;
                }
            }


            var hcaFilePath = AddExtension(typelessFilePath, ".hca");

            if (File.Exists(hcaFilePath))
            {
                blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, ".hca")}!");
                var hcaFileBytes = File.ReadAllBytes(hcaFilePath);
                track.RawPortion   = hcaFileBytes;
                track.CurrentCodec = MaterialCodecType.HCA;
                return;
            }

            var rawFilePath = AddExtension(typelessFilePath, originalCodec.FileFormat);

            if (File.Exists(rawFilePath))
            {
                blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, originalCodec.FileFormat)}!");
                var hcaFileBytes = File.ReadAllBytes(rawFilePath);
                track.RawPortion   = hcaFileBytes;
                track.CurrentCodec = track.OriginalEntry.Codec;
                return;
            }

            blackboard.Logger.Log($"Found no replacement to {track.ExpectedName}, using original track from uexp!");
        }
Ejemplo n.º 2
0
        private void FixHeader(TemporaryTrack track)
        {
            var codec = AvailableCodecs.GetCodec(track.CurrentCodec);

            if (codec == null)
            {
                return;
            }

            codec.FixHeader(track);
        }
Ejemplo n.º 3
0
        private void WriteOutAudioFile(byte[] fileBytes, string outputFolder, MaterialSection.MaterialEntry entry)
        {
            var extractedFilePath = Path.Combine(outputFolder, _materialIndexToFileName[entry.EntryIndex]);

            var fullFilePath   = Path.GetFullPath(extractedFilePath);
            var fullFolderPath = Path.GetDirectoryName(fullFilePath);

            if (!Directory.Exists(fullFolderPath))
            {
                Directory.CreateDirectory(fullFolderPath);
                Logger.Log($"Created folder at: {fullFolderPath}");
            }

            var codec = AvailableCodecs.GetCodec(entry.Codec);

            if (codec == null)
            {
                Logger.Error(
                    $"The track ({_materialIndexToFileName[entry.EntryIndex]}) uses the {entry.Codec} Codec, but AudioMog has no handler to extract it! Skipping!");
                return;
            }

            if (Settings.AudioExtractor.ExtractAsRaw)
            {
                var rawPath = ExtensionMethods.ChangeExtension(fullFilePath, codec.FileFormat);
                codec.ExtractOriginal(Logger, entry, fileBytes, rawPath);
            }

            if (Settings.AudioExtractor.ExtractAsWav)
            {
                try
                {
                    var wavPath = ExtensionMethods.ChangeExtension(fullFilePath, ".wav");
                    codec.ExtractAsWav(Logger, entry, fileBytes, wavPath);
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to convert to wav! Will attempt to continue extraction!");
                    Logger.Error(e.ToString());
                }
            }
        }