Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Volatility/CLI/Commands/AutotestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task Execute()
TexturePC textureHeaderPC = new TexturePC
{
AssetName = "autotest_header_PC",
ResourceID = GetResourceIDFromName("autotest_header_PC"),
ResourceID = ResourceID.HashFromString("autotest_header_PC"),
Format = D3DFORMAT.D3DFMT_DXT1,
Width = 1024,
Height = 512,
Expand All @@ -62,7 +62,7 @@ public async Task Execute()
TextureBPR textureHeaderBPR = new TextureBPR
{
AssetName = "autotest_header_BPR",
ResourceID = GetResourceIDFromName("autotest_header_BPR"),
ResourceID = ResourceID.HashFromString("autotest_header_BPR"),
Format = DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM,
Width = 1024,
Height = 512,
Expand All @@ -77,7 +77,7 @@ public async Task Execute()

textureHeaderBPR.SetResourceArch(Arch.x64);
textureHeaderBPR.AssetName = "autotest_header_BPRx64";
textureHeaderBPR.ResourceID = GetResourceIDFromName(textureHeaderBPR.AssetName);
textureHeaderBPR.ResourceID = ResourceID.HashFromString(textureHeaderBPR.AssetName);

// Write 64 bit test BPR header
TestHeaderRW("autotest_header_BPRx64.dat", textureHeaderBPR);
Expand All @@ -86,7 +86,7 @@ public async Task Execute()
TexturePS3 textureHeaderPS3 = new TexturePS3
{
AssetName = "autotest_header_PS3",
ResourceID = GetResourceIDFromName("autotest_header_PS3"),
ResourceID = ResourceID.HashFromString("autotest_header_PS3"),
Format = CELL_GCM_COLOR_FORMAT.CELL_GCM_TEXTURE_COMPRESSED_DXT45,
Width = 1024,
Height = 512,
Expand All @@ -100,7 +100,7 @@ public async Task Execute()
TextureX360 textureHeaderX360 = new TextureX360
{
AssetName = "autotest_header_X360",
ResourceID = GetResourceIDFromName("autotest_header_X360"),
ResourceID = ResourceID.HashFromString("autotest_header_X360"),
Format = new GPUTEXTURE_FETCH_CONSTANT
{
Tiled = true,
Expand Down
4 changes: 0 additions & 4 deletions Volatility/CLI/Commands/ExportResourceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public async Task Execute()
case TextureBase texture:
texture.PushAll();
goto default;
case Splicer splicer:
splicer.WriteToStream(writer);
splicer.SpliceSamples(writer, Path.GetDirectoryName(sourceFile));
break;
default:
resource.WriteToStream(writer);
break;
Expand Down
110 changes: 62 additions & 48 deletions Volatility/CLI/Commands/ImportResourceCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Text;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text.RegularExpressions;

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

using Volatility.Resources;
using Volatility.Utilities;
Expand Down Expand Up @@ -73,7 +74,7 @@ public async Task Execute()
.DisableAliases()
.WithTypeInspector(inner => new IncludeFieldsTypeInspector(inner))
.WithTypeConverter(new ResourceYamlTypeConverter())
.WithTypeConverter(new ResourceIDYamlTypeConverter())
.WithTypeConverter(new StrongIDYamlTypeConverter())
.WithTypeConverter(new StringEnumYamlTypeConverter())
.Build();

Expand Down Expand Up @@ -157,62 +158,75 @@ public async Task Execute()

Splicer? splicer = resource as Splicer;

byte[][]? samples = splicer?.GetLoadedSamples();

for (int i = 0; i < samples?.Length; i++)
{
string sampleName = $"{resource.AssetName}_{i}";

string sampleDirectory = Path.Combine(directoryPath, $"{resource.AssetName}_Samples");
List<Splicer.Sample>? samples = splicer?.GetLoadedSamples();
for (int i = 0; i < samples?.Count; i++)
{
string sampleDirectory = Path.Combine("data", "Splicer", "Samples");

Directory.CreateDirectory(sampleDirectory);

Console.WriteLine($"Writing extracted sample {sampleName}.snr");
await File.WriteAllBytesAsync(Path.Combine(sampleDirectory, $"{sampleName}.snr"), samples[i]);
string sampleName = $"{samples[i].SampleID}";

if (sxExists)
string samplePathName = Path.Combine(sampleDirectory, sampleName);

if (!File.Exists($"{samplePathName}.snr") || Overwrite)
{
Console.WriteLine($"Writing extracted sample {sampleName}.snr");
await File.WriteAllBytesAsync($"{samplePathName}.snr", samples[i].Data);
}
else
{
string samplePathName = Path.Combine(sampleDirectory, sampleName);
Console.WriteLine($"Skipping extracted sample {sampleName}.snr");
}

if (sxExists)
{
string convertedSamplePathName = Path.Combine(sampleDirectory, "_extracted");

Directory.CreateDirectory(convertedSamplePathName);

convertedSamplePathName = Path.Combine(convertedSamplePathName, sampleName);

ProcessStartInfo start = new ProcessStartInfo
{
FileName = sxPath,
Arguments = $"-wave -s16l_int -v0 \"{samplePathName}.snr\" -=\"{convertedSamplePathName}.wav\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};

using (Process process = new Process())
{
process.StartInfo = start;
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
};

Console.WriteLine($"Converting extracted sample {sampleName}.snr to wave...");
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
}
}
}
Console.WriteLine($"Imported {Path.GetFileName(ImportPath)} as {Path.GetFullPath(filePath)}.");
convertedSamplePathName = Path.Combine(convertedSamplePathName, sampleName + ".wav");

if (!File.Exists(convertedSamplePathName) || Overwrite)
{
ProcessStartInfo start = new ProcessStartInfo
{
FileName = sxPath,
Arguments = $"-wave -s16l_int -v0 \"{samplePathName}.snr\" -=\"{convertedSamplePathName}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};

using (Process process = new Process())
{
process.StartInfo = start;
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
};

Console.WriteLine($"Converting extracted sample {sampleName}.snr to wave...");
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
}
else
{
Console.WriteLine($"Converted sample {Path.GetFileName(convertedSamplePathName)} already exists, skipping...");
}
}
}
}
Console.WriteLine($"Imported {Path.GetFileName(sourceFile)} as {Path.GetFullPath(filePath)}.");
}));
}
await Task.WhenAll(tasks);
Expand Down
2 changes: 1 addition & 1 deletion Volatility/Resources/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Resource(string path, Endian endianness = Endian.Agnostic)
else
{
// TODO: Add new entry to ResourceDB
ResourceID = Convert.ToUInt64(GetResourceIDFromName(name, importEndianness), 16);
ResourceID = Convert.ToUInt64(ResourceID.FromIDString(name));
AssetName = name;
}

Expand Down
Loading
Loading