mirror of
https://github.com/blueskythlikesclouds/SonicAudioTools.git
synced 2025-02-09 23:48:25 +01:00
117 lines
4.4 KiB
Plaintext
117 lines
4.4 KiB
Plaintext
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.ComponentModel;
|
|
using System.Collections;
|
|
|
|
using SonicAudioLib;
|
|
using SonicAudioLib.Archive;
|
|
using SonicAudioLib.Collections;
|
|
using SonicAudioLib.IO;
|
|
using SonicAudioLib.CriMw;
|
|
|
|
using System.Xml;
|
|
|
|
namespace SonicAudioCmd
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
if (args.Length < 1)
|
|
{
|
|
Console.WriteLine("Usage: [path]");
|
|
Console.WriteLine("Drag and drop an ACB file to unpack its contents.");
|
|
Console.WriteLine("Drag and drop a folder to pack its contents back into the ACB. (The ACB file must be in the same directory.)");
|
|
Console.ReadLine();
|
|
return;
|
|
}
|
|
|
|
if (args[0].EndsWith(".acb"))
|
|
{
|
|
string baseDirectory = Path.Combine(
|
|
Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]));
|
|
|
|
Directory.CreateDirectory(baseDirectory);
|
|
|
|
using (CriTableReader reader = CriTableReader.Create(args[0]))
|
|
{
|
|
reader.Read();
|
|
|
|
using (Stream afs2Stream = reader.GetSubstream("AwbFile"))
|
|
{
|
|
Afs2Archive archive = new Afs2Archive(afs2Stream);
|
|
|
|
using (CriTableReader waveformReader = CriTableReader.Create(reader.GetSubstream("WaveformTable")))
|
|
{
|
|
while (waveformReader.Read())
|
|
{
|
|
if (!waveformReader.GetBoolean("Streaming"))
|
|
{
|
|
ushort cueIndex = waveformReader.GetUInt16("Id");
|
|
Afs2Entry entry = archive.GetEntryByCueIndex(cueIndex);
|
|
|
|
string fileName = entry.CueIndex.ToString();
|
|
switch (waveformReader.GetByte("EncodeType"))
|
|
{
|
|
case 0:
|
|
fileName += ".adx";
|
|
break;
|
|
case 2:
|
|
fileName += ".hca";
|
|
break;
|
|
case 13:
|
|
fileName += ".dsp";
|
|
break;
|
|
default:
|
|
fileName += ".bin";
|
|
break;
|
|
}
|
|
|
|
using (Stream entryIn = entry.Open(), entryOut = File.Create(Path.Combine(baseDirectory, fileName)))
|
|
{
|
|
entryIn.CopyTo(entryOut);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
CriTable criTable = new CriTable();
|
|
criTable.Load(args[0] + ".acb");
|
|
|
|
Afs2Archive afs2Archive = new Afs2Archive();
|
|
|
|
List<string> files = new List<string>();
|
|
files.AddRange(Directory.GetFiles(args[0], "*.adx"));
|
|
files.AddRange(Directory.GetFiles(args[0], "*.hca"));
|
|
files.AddRange(Directory.GetFiles(args[0], "*.dsp"));
|
|
files.AddRange(Directory.GetFiles(args[0], "*.bin"));
|
|
|
|
foreach (string file in Directory.GetFiles(args[0], "*.*"))
|
|
{
|
|
string baseName = Path.GetFileNameWithoutExtension(file);
|
|
|
|
Afs2Entry afs2Entry = new Afs2Entry();
|
|
afs2Entry.CueIndex = int.Parse(baseName);
|
|
afs2Entry.LocalFilePath = new FileInfo(file);
|
|
afs2Archive.Entries.Add(afs2Entry);
|
|
}
|
|
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
afs2Archive.Write(memoryStream);
|
|
|
|
criTable.Rows[0]["AwbFile"] = memoryStream.ToArray();
|
|
criTable.Save(args[0] + ".acb", CriTableFileMode.Adx2);
|
|
}
|
|
}
|
|
}
|
|
}
|