Skip to content

Commit

Permalink
feature: Complete Audio to MP3 download for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SdtBarbarossa committed Sep 27, 2024
1 parent e470443 commit a7bae9a
Show file tree
Hide file tree
Showing 14 changed files with 5,626 additions and 1 deletion.
30 changes: 30 additions & 0 deletions AssetGUI/MainProgram.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Asset_Getter;
using AssetGetterTools;
using AssetGetterTools.models;
using AssetGetterTools.pck;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand All @@ -17,6 +18,7 @@ public class MainProgram
{
public string workingFolder { get; set; }
public string targetFolder { get; set; }
public string audioTargetFolder { get; set; }
public string AssetVersion { get; set; }

public bool exportShader { get; set; }
Expand All @@ -34,9 +36,12 @@ public string AssetDownloadUrl

public Filehelper fileHelper { get; set; }

public BarbPCKExtractor barbPCKExtractor { get; set; }

public MainProgram(AssetOS assetOS = AssetOS.Windows)
{
this.fileHelper = new Filehelper();
this.barbPCKExtractor = new BarbPCKExtractor();

this.SetAssetOSPath(assetOS);
}
Expand Down Expand Up @@ -76,6 +81,7 @@ public async Task<bool> exportAllFiles()
{
var allAssets = GetAssetsFromManifest();
exportMultipleAssets(allAssets);
Console.WriteLine($"Done exportAllFiles!");
return true;
}

Expand All @@ -86,6 +92,10 @@ public async Task<bool> downloadAllAudioFiles()
{
var audioWwpkgFile = DownloadAudioPackages(asset);
var extractedPCK = ExtractAudioPackage(audioWwpkgFile, asset);
if(extractedPCK != null)
{
ConvertPCKToWave(extractedPCK);
}
}
Console.WriteLine("done downloading all Audio files");
return true;
Expand All @@ -99,6 +109,7 @@ public async Task<bool> exportAllWithPrefixFile(string prefix)
exportSingleFile(asset);
}

Console.WriteLine($"Done exportAllWithPrefixFile!");
return true;
}

Expand All @@ -108,6 +119,7 @@ public void exportMultipleAssets(List<string> allAssetsToExport)
{
exportSingleFile(asset);
}
Console.WriteLine($"Done exportMultipleAssets!");
}

public List<string> diffAssetVersions(string oldVersion, DiffType diffType = DiffType.All)
Expand Down Expand Up @@ -148,6 +160,7 @@ public async Task<bool> exportSingleFile(string assetName)
var prefix = assetName.Split('_')[0];
var downloadedFile = DownloadAssetBundle(assetName);
fileHelper.UnpackBundle(downloadedFile, $"{targetFolder}/{prefix}", assetName, this.exportShader, this.exportMeshes, this.exportAnimator);
Console.WriteLine($"Done exportSingleFile!");
}
catch (Exception ex)
{
Expand Down Expand Up @@ -199,6 +212,23 @@ public string DownloadAssetBundle(string assetBundleName)
}
}

public void ConvertPCKToWave(string pckFileToExtract)
{
try
{
Console.WriteLine($"Converting {Path.GetFileName(pckFileToExtract)}");
var audioOutputDirectory = audioTargetFolder;
Directory.CreateDirectory(audioOutputDirectory);

this.barbPCKExtractor.ExtractSingleFile(pckFileToExtract, audioOutputDirectory);
Console.WriteLine($"Done Converting!");
}
catch (Exception ex)
{
Console.WriteLine($"Error extracting file '{pckFileToExtract}'! you may ignore this.");
}
}

public string ExtractAudioPackage(string audioWwwpkgPath, string assetBundleName)
{
try
Expand Down
2 changes: 1 addition & 1 deletion AssetGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<ComboBox x:Name="cbAssetOs" Grid.Row="1" Grid.Column="1" MinWidth="400" ItemsSource="{x:Bind AssetOSs}" SelectedItem="{x:Bind SelectedAssetOS, Mode=TwoWay}"></ComboBox>

<TextBlock x:Name="tblVersion" Text="Assetversion:" Grid.Row="2" Grid.Column="0"></TextBlock>
<TextBox x:Name="tbVersion" Text="31500" Grid.Row="2" Grid.Column="1"></TextBox>
<TextBox x:Name="tbVersion" Text="3512" Grid.Row="2" Grid.Column="1"></TextBox>
<Button x:Name="btRefreshVersion" Grid.Row="2" Grid.Column="2" Click="btRefreshVersion_Click">
<SymbolIcon Symbol="Refresh"/>
</Button>
Expand Down
2 changes: 2 additions & 0 deletions AssetGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private async void getListOfAssets()
mainProgram.AssetVersion = tbVersion.Text;
mainProgram.workingFolder = tbExportPath.Text;
mainProgram.targetFolder = tbExportPath.Text + "/OutPut";
mainProgram.audioTargetFolder = this.tbExportPath.Text + "/Audio_OutPut";

this.mainProgram.SetAssetOSPath(this.SelectedAssetOS);

Expand Down Expand Up @@ -207,6 +208,7 @@ private async void setPathViaPicker()

mainProgram.workingFolder = this.tbExportPath.Text;
mainProgram.targetFolder = this.tbExportPath.Text + "/OutPut";
mainProgram.audioTargetFolder = this.tbExportPath.Text + "/Audio_OutPut";
}

private async void refreshVersion()
Expand Down
36 changes: 36 additions & 0 deletions AssetGetterTools/AssetGetterTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,46 @@

<ItemGroup>
<None Remove="Texture2DDecoderNative.dll" />
<None Remove="x64\PCK_Tools_Native_win\bnkextr.exe" />
<None Remove="x64\PCK_Tools_Native_win\ffmpeg.exe" />
<None Remove="x64\PCK_Tools_Native_win\LICENSE.txt" />
<None Remove="x64\PCK_Tools_Native_win\packed_codebooks_aoTuV_603.bin" />
<None Remove="x64\PCK_Tools_Native_win\quickbms.exe" />
<None Remove="x64\PCK_Tools_Native_win\quickbms.txt" />
<None Remove="x64\PCK_Tools_Native_win\revorb.exe" />
<None Remove="x64\PCK_Tools_Native_win\wavescan.bms" />
<None Remove="x64\PCK_Tools_Native_win\ww2ogg.exe" />
<None Remove="x86\Texture2DDecoderNative.dll" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\bnkextr.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\ffmpeg.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\LICENSE.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\packed_codebooks_aoTuV_603.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\quickbms.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\quickbms.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\revorb.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\wavescan.bms">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\PCK_Tools_Native_win\ww2ogg.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="x64\Texture2DDecoderNative.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down
128 changes: 128 additions & 0 deletions AssetGetterTools/pck/BarbPCKExtractor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AssetGetterTools.pck
{
public class BarbPCKExtractor
{
public void ExtractSingleFile(string fileToExtract, string outputFolder)
{
var dllDir = GetDirectedDllDirectory();


var inputFileName = Path.GetFileName(fileToExtract);

var unpackFileName = inputFileName.Replace(".pck", "");

var fullOutputPath = Path.Combine(outputFolder, unpackFileName);
Directory.CreateDirectory(fullOutputPath);

/*
* macht aus einer PCK mehrere wav
* quickbms.exe wavescan.bms "Game Files" "Tools\Decoding"
*
* macht aus wav eine OGG:
* ww2ogg.exe "C:\Users\midi.D1\Documents\swgoh\Git\Wwise-Unpacker\tools\Decoding\audio_mus_home_1.wav" --pcb Tools\packed_codebooks_aoTuV_603.bin
*
* macht aus OGG eine MP3:
* revorb.exe "C:\Users\midi.D1\Documents\swgoh\Git\Wwise-Unpacker\tools\Decoding\audio_mus_home_1.ogg"
*/

var pathToExecuteable_quickbms = $"{dllDir}/PCK_Tools_Native_win/quickbms.exe";
var pathToExecuteable_ww2ogg = $"{dllDir}/PCK_Tools_Native_win/ww2ogg.exe";
var pathToExecuteable_revorb = $"{dllDir}/PCK_Tools_Native_win/revorb.exe";

var pathTobms_wavescan = $"{dllDir}/PCK_Tools_Native_win/wavescan.bms";

var pathTobms_packed_codebooks_aoTuV_603 = $"{dllDir}/PCK_Tools_Native_win/packed_codebooks_aoTuV_603.bin";

this.CheckIfExecuteableIsAvailable(pathToExecuteable_quickbms);
this.CheckIfExecuteableIsAvailable(pathToExecuteable_ww2ogg);
this.CheckIfExecuteableIsAvailable(pathToExecuteable_revorb);

this.CheckIfExecuteableIsAvailable(pathTobms_wavescan);

this.CheckIfExecuteableIsAvailable(pathTobms_packed_codebooks_aoTuV_603);

var process = new Process();
process.StartInfo.WorkingDirectory = fullOutputPath;
process.StartInfo.FileName = pathToExecuteable_quickbms;
process.StartInfo.Arguments = $"{pathTobms_wavescan} {fileToExtract} {fullOutputPath}";
process.Start();
process.WaitForExit();

var allWavFilesInOutputFolder = Directory.GetFiles(fullOutputPath).Where(filename => filename.EndsWith(".wav")).ToList();

if (allWavFilesInOutputFolder.Count > 0)
{
//cast into OGG
foreach (var currentFile in allWavFilesInOutputFolder)
{
var filename = Path.GetFileName(currentFile);
var filePath = Path.GetDirectoryName(currentFile);

var processWW2OGG = new Process();
processWW2OGG.StartInfo.WorkingDirectory = fullOutputPath;
processWW2OGG.StartInfo.FileName = pathToExecuteable_ww2ogg;
processWW2OGG.StartInfo.Arguments = $"{currentFile} --pcb {pathTobms_packed_codebooks_aoTuV_603}";
processWW2OGG.Start();
processWW2OGG.WaitForExit();

File.Delete(currentFile);
}

var allOGGFilesInOutputFolder = Directory.GetFiles(fullOutputPath).Where(filename => filename.EndsWith(".ogg")).ToList();

//Cast to MP3
foreach (var currentOGGFile in allOGGFilesInOutputFolder)
{
var filename = Path.GetFileName(currentOGGFile);
var filePath = Path.GetDirectoryName(currentOGGFile);

var processWW2OGG = new Process();
processWW2OGG.StartInfo.WorkingDirectory = fullOutputPath;
processWW2OGG.StartInfo.FileName = pathToExecuteable_revorb;
processWW2OGG.StartInfo.Arguments = currentOGGFile;
processWW2OGG.Start();
processWW2OGG.WaitForExit();

File.Move(currentOGGFile, currentOGGFile.Replace(".ogg", ".mp3"));
}
}

//Delete all Subfolder
var allSubfolders = Directory.GetDirectories(fullOutputPath);
foreach(var subfolderNow in allSubfolders)
{
Directory.Delete(subfolderNow);
}
}

private void CheckIfExecuteableIsAvailable(string pathToExecutable)
{
Console.WriteLine($"Checking for file {pathToExecutable}");

if (!File.Exists(pathToExecutable))
{
throw new Exception($"The Executable could not be found. Make sure it exists in the folder '{pathToExecutable}'");
}
}

private static string GetDirectedDllDirectory()
{
var localPath = Process.GetCurrentProcess().MainModule.FileName;
var localDir = Path.GetDirectoryName(localPath);

var subDir = Environment.Is64BitProcess ? "x64" : "x86";

var directedDllDir = Path.Combine(localDir, subDir);

return directedDllDir;
}
}
}
Loading

0 comments on commit a7bae9a

Please sign in to comment.