mirror of
https://github.com/4sval/FModel.git
synced 2026-04-24 06:48:38 -05:00
Added ADX decoder
This commit is contained in:
parent
c525243c50
commit
3b82f14290
|
|
@ -1 +1 @@
|
|||
Subproject commit b4ac4238fea01ef2ca2cb3849d135552e320ea9a
|
||||
Subproject commit 8713445a76718e26f58d1a85d9dab114979d1bfc
|
||||
|
|
@ -13,6 +13,8 @@ using CSCore.CoreAudioAPI;
|
|||
using CSCore.DSP;
|
||||
using CSCore.SoundOut;
|
||||
using CSCore.Streams;
|
||||
using CUE4Parse.UE4.CriWare.Decoders;
|
||||
using CUE4Parse.UE4.CriWare.Decoders.ADX;
|
||||
using CUE4Parse.UE4.CriWare.Decoders.HCA;
|
||||
using CUE4Parse.Utils;
|
||||
using FModel.Extensions;
|
||||
|
|
@ -580,37 +582,9 @@ public class AudioPlayerViewModel : ViewModel, ISource, IDisposable
|
|||
|
||||
return false;
|
||||
}
|
||||
case "adx":
|
||||
case "hca":
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] wavData = HcaWaveStream.ConvertHcaToWav(SelectedAudioFile.Data, UserSettings.Default.CurrentDir.CriwareDecryptionKey);
|
||||
|
||||
string wavFilePath = Path.Combine(UserSettings.Default.AudioDirectory, SelectedAudioFile.FilePath.TrimStart('/'));
|
||||
wavFilePath = Path.ChangeExtension(wavFilePath, ".wav");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(wavFilePath)!);
|
||||
|
||||
File.WriteAllBytes(wavFilePath, wavData);
|
||||
|
||||
var newAudio = new AudioFile(SelectedAudioFile.Id, new FileInfo(wavFilePath));
|
||||
Replace(newAudio);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (CriwareDecryptionException ex)
|
||||
{
|
||||
FLogger.Append(ELog.Error, () => FLogger.Text($"Encrypted HCA: {ex.Message}", Constants.WHITE, true));
|
||||
Log.Error($"Encrypted HCA: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLogger.Append(ELog.Error, () => FLogger.Text($"Failed to convert HCA: {ex.Message}", Constants.WHITE, true));
|
||||
Log.Error($"Failed to convert HCA: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return TryConvertCriware();
|
||||
case "rada":
|
||||
case "binka":
|
||||
{
|
||||
|
|
@ -628,6 +602,48 @@ public class AudioPlayerViewModel : ViewModel, ISource, IDisposable
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool TryConvertCriware()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] wavData = SelectedAudioFile.Extension switch
|
||||
{
|
||||
"hca" => HcaWaveStream.ConvertHcaToWav(
|
||||
SelectedAudioFile.Data,
|
||||
UserSettings.Default.CurrentDir.CriwareDecryptionKey),
|
||||
"adx" => AdxDecoder.ConvertAdxToWav(
|
||||
SelectedAudioFile.Data,
|
||||
UserSettings.Default.CurrentDir.CriwareDecryptionKey),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
|
||||
string wavFilePath = Path.Combine(
|
||||
UserSettings.Default.AudioDirectory,
|
||||
SelectedAudioFile.FilePath.TrimStart('/'));
|
||||
wavFilePath = Path.ChangeExtension(wavFilePath, ".wav");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(wavFilePath)!);
|
||||
File.WriteAllBytes(wavFilePath, wavData);
|
||||
|
||||
var newAudio = new AudioFile(SelectedAudioFile.Id, new FileInfo(wavFilePath));
|
||||
Replace(newAudio);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (CriwareDecryptionException ex)
|
||||
{
|
||||
FLogger.Append(ELog.Error, () => FLogger.Text($"Encrypted {SelectedAudioFile.Extension.ToUpper()}: {ex.Message}", Constants.WHITE, true));
|
||||
Log.Error($"Encrypted {SelectedAudioFile.Extension.ToUpper()}: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLogger.Append(ELog.Error, () => FLogger.Text($"Failed to convert {SelectedAudioFile.Extension.ToUpper()}: {ex.Message}", Constants.WHITE, true));
|
||||
Log.Error($"Failed to convert {SelectedAudioFile.Extension.ToUpper()}: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryConvert(out string wavFilePath) => TryConvert(SelectedAudioFile.FilePath, SelectedAudioFile.Data, out wavFilePath);
|
||||
private bool TryConvert(string inputFilePath, byte[] inputFileData, out string wavFilePath)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -783,10 +783,11 @@ public class CUE4ParseViewModel : ViewModel
|
|||
|
||||
TabControl.SelectedTab.SetDocumentText(JsonConvert.SerializeObject(awbReader, Formatting.Indented), saveProperties, updateUi);
|
||||
|
||||
var directory = Path.GetDirectoryName(archive.Name) ?? "/Criware/";
|
||||
var extractedSounds = CriWareProvider.ExtractCriWareSounds(awbReader, archive.Name);
|
||||
foreach (var sound in extractedSounds)
|
||||
{
|
||||
SaveAndPlaySound(Path.Combine("/Criware/", sound.Name), sound.Extension, sound.Data, saveAudio);
|
||||
SaveAndPlaySound(Path.Combine(directory, sound.Name), sound.Extension, sound.Data, saveAudio);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -798,10 +799,11 @@ public class CUE4ParseViewModel : ViewModel
|
|||
|
||||
TabControl.SelectedTab.SetDocumentText(JsonConvert.SerializeObject(acbReader, Formatting.Indented), saveProperties, updateUi);
|
||||
|
||||
var directory = Path.GetDirectoryName(archive.Name) ?? "/Criware/";
|
||||
var extractedSounds = CriWareProvider.ExtractCriWareSounds(acbReader, archive.Name);
|
||||
foreach (var sound in extractedSounds)
|
||||
{
|
||||
SaveAndPlaySound(Path.Combine("/Criware/", sound.Name), sound.Extension, sound.Data, saveAudio);
|
||||
SaveAndPlaySound(Path.Combine(directory, sound.Name), sound.Extension, sound.Data, saveAudio);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -1043,6 +1045,7 @@ public class CUE4ParseViewModel : ViewModel
|
|||
};
|
||||
|
||||
var directory = Path.GetDirectoryName(atomObject.Owner?.Name) ?? "/Criware/";
|
||||
directory = Path.GetDirectoryName(atomObject.Owner.Provider.FixPath(directory));
|
||||
foreach (var sound in extractedSounds)
|
||||
{
|
||||
SaveAndPlaySound(Path.Combine(directory, sound.Name).Replace("\\", "/"), sound.Extension, sound.Data, saveAudio);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user