Skip to content

Commit 8a48975

Browse files
authored
Merge pull request #4 from BurnoutHints/enhancement/splicer
StrongID & Splicer Enhancements
2 parents f9cb015 + 8a6db69 commit 8a48975

12 files changed

Lines changed: 416 additions & 267 deletions

Volatility/CLI/Commands/AutotestCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task Execute()
4848
TexturePC textureHeaderPC = new TexturePC
4949
{
5050
AssetName = "autotest_header_PC",
51-
ResourceID = GetResourceIDFromName("autotest_header_PC"),
51+
ResourceID = ResourceID.HashFromString("autotest_header_PC"),
5252
Format = D3DFORMAT.D3DFMT_DXT1,
5353
Width = 1024,
5454
Height = 512,
@@ -62,7 +62,7 @@ public async Task Execute()
6262
TextureBPR textureHeaderBPR = new TextureBPR
6363
{
6464
AssetName = "autotest_header_BPR",
65-
ResourceID = GetResourceIDFromName("autotest_header_BPR"),
65+
ResourceID = ResourceID.HashFromString("autotest_header_BPR"),
6666
Format = DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM,
6767
Width = 1024,
6868
Height = 512,
@@ -77,7 +77,7 @@ public async Task Execute()
7777

7878
textureHeaderBPR.SetResourceArch(Arch.x64);
7979
textureHeaderBPR.AssetName = "autotest_header_BPRx64";
80-
textureHeaderBPR.ResourceID = GetResourceIDFromName(textureHeaderBPR.AssetName);
80+
textureHeaderBPR.ResourceID = ResourceID.HashFromString(textureHeaderBPR.AssetName);
8181

8282
// Write 64 bit test BPR header
8383
TestHeaderRW("autotest_header_BPRx64.dat", textureHeaderBPR);
@@ -86,7 +86,7 @@ public async Task Execute()
8686
TexturePS3 textureHeaderPS3 = new TexturePS3
8787
{
8888
AssetName = "autotest_header_PS3",
89-
ResourceID = GetResourceIDFromName("autotest_header_PS3"),
89+
ResourceID = ResourceID.HashFromString("autotest_header_PS3"),
9090
Format = CELL_GCM_COLOR_FORMAT.CELL_GCM_TEXTURE_COMPRESSED_DXT45,
9191
Width = 1024,
9292
Height = 512,
@@ -100,7 +100,7 @@ public async Task Execute()
100100
TextureX360 textureHeaderX360 = new TextureX360
101101
{
102102
AssetName = "autotest_header_X360",
103-
ResourceID = GetResourceIDFromName("autotest_header_X360"),
103+
ResourceID = ResourceID.HashFromString("autotest_header_X360"),
104104
Format = new GPUTEXTURE_FETCH_CONSTANT
105105
{
106106
Tiled = true,

Volatility/CLI/Commands/ExportResourceCommand.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ public async Task Execute()
116116
case TextureBase texture:
117117
texture.PushAll();
118118
goto default;
119-
case Splicer splicer:
120-
splicer.WriteToStream(writer);
121-
splicer.SpliceSamples(writer, Path.GetDirectoryName(sourceFile));
122-
break;
123119
default:
124120
resource.WriteToStream(writer);
125121
break;

Volatility/CLI/Commands/ImportResourceCommand.cs

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using System.Text;
12
using System.Diagnostics;
3+
using System.Security.Cryptography;
24
using System.Text.RegularExpressions;
35

46
using YamlDotNet.Serialization;
5-
using YamlDotNet.Serialization.NamingConventions;
67

78
using Volatility.Resources;
89
using Volatility.Utilities;
@@ -73,7 +74,7 @@ public async Task Execute()
7374
.DisableAliases()
7475
.WithTypeInspector(inner => new IncludeFieldsTypeInspector(inner))
7576
.WithTypeConverter(new ResourceYamlTypeConverter())
76-
.WithTypeConverter(new ResourceIDYamlTypeConverter())
77+
.WithTypeConverter(new StrongIDYamlTypeConverter())
7778
.WithTypeConverter(new StringEnumYamlTypeConverter())
7879
.Build();
7980

@@ -157,62 +158,75 @@ public async Task Execute()
157158

158159
Splicer? splicer = resource as Splicer;
159160

160-
byte[][]? samples = splicer?.GetLoadedSamples();
161-
162-
for (int i = 0; i < samples?.Length; i++)
163-
{
164-
string sampleName = $"{resource.AssetName}_{i}";
165-
166-
string sampleDirectory = Path.Combine(directoryPath, $"{resource.AssetName}_Samples");
161+
List<Splicer.Sample>? samples = splicer?.GetLoadedSamples();
162+
for (int i = 0; i < samples?.Count; i++)
163+
{
164+
string sampleDirectory = Path.Combine("data", "Splicer", "Samples");
167165

168166
Directory.CreateDirectory(sampleDirectory);
169167

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

173-
if (sxExists)
170+
string samplePathName = Path.Combine(sampleDirectory, sampleName);
171+
172+
if (!File.Exists($"{samplePathName}.snr") || Overwrite)
173+
{
174+
Console.WriteLine($"Writing extracted sample {sampleName}.snr");
175+
await File.WriteAllBytesAsync($"{samplePathName}.snr", samples[i].Data);
176+
}
177+
else
174178
{
175-
string samplePathName = Path.Combine(sampleDirectory, sampleName);
179+
Console.WriteLine($"Skipping extracted sample {sampleName}.snr");
180+
}
176181

182+
if (sxExists)
183+
{
177184
string convertedSamplePathName = Path.Combine(sampleDirectory, "_extracted");
178185

179186
Directory.CreateDirectory(convertedSamplePathName);
180187

181-
convertedSamplePathName = Path.Combine(convertedSamplePathName, sampleName);
182-
183-
ProcessStartInfo start = new ProcessStartInfo
184-
{
185-
FileName = sxPath,
186-
Arguments = $"-wave -s16l_int -v0 \"{samplePathName}.snr\" -=\"{convertedSamplePathName}.wav\"",
187-
RedirectStandardOutput = true,
188-
RedirectStandardError = true,
189-
UseShellExecute = false,
190-
CreateNoWindow = true
191-
};
192-
193-
using (Process process = new Process())
194-
{
195-
process.StartInfo = start;
196-
process.OutputDataReceived += (sender, e) =>
197-
{
198-
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
199-
};
200-
201-
process.ErrorDataReceived += (sender, e) =>
202-
{
203-
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
204-
};
205-
206-
Console.WriteLine($"Converting extracted sample {sampleName}.snr to wave...");
207-
process.Start();
208-
process.BeginOutputReadLine();
209-
process.BeginErrorReadLine();
210-
process.WaitForExit();
211-
}
212-
}
213-
}
214-
}
215-
Console.WriteLine($"Imported {Path.GetFileName(ImportPath)} as {Path.GetFullPath(filePath)}.");
188+
convertedSamplePathName = Path.Combine(convertedSamplePathName, sampleName + ".wav");
189+
190+
if (!File.Exists(convertedSamplePathName) || Overwrite)
191+
{
192+
ProcessStartInfo start = new ProcessStartInfo
193+
{
194+
FileName = sxPath,
195+
Arguments = $"-wave -s16l_int -v0 \"{samplePathName}.snr\" -=\"{convertedSamplePathName}\"",
196+
RedirectStandardOutput = true,
197+
RedirectStandardError = true,
198+
UseShellExecute = false,
199+
CreateNoWindow = true
200+
};
201+
202+
using (Process process = new Process())
203+
{
204+
process.StartInfo = start;
205+
process.OutputDataReceived += (sender, e) =>
206+
{
207+
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
208+
};
209+
210+
process.ErrorDataReceived += (sender, e) =>
211+
{
212+
if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data);
213+
};
214+
215+
Console.WriteLine($"Converting extracted sample {sampleName}.snr to wave...");
216+
process.Start();
217+
process.BeginOutputReadLine();
218+
process.BeginErrorReadLine();
219+
process.WaitForExit();
220+
}
221+
}
222+
else
223+
{
224+
Console.WriteLine($"Converted sample {Path.GetFileName(convertedSamplePathName)} already exists, skipping...");
225+
}
226+
}
227+
}
228+
}
229+
Console.WriteLine($"Imported {Path.GetFileName(sourceFile)} as {Path.GetFullPath(filePath)}.");
216230
}));
217231
}
218232
await Task.WhenAll(tasks);

Volatility/Resources/Resource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Resource(string path, Endian endianness = Endian.Agnostic)
9494
else
9595
{
9696
// TODO: Add new entry to ResourceDB
97-
ResourceID = Convert.ToUInt64(GetResourceIDFromName(name, importEndianness), 16);
97+
ResourceID = Convert.ToUInt64(ResourceID.FromIDString(name));
9898
AssetName = name;
9999
}
100100

0 commit comments

Comments
 (0)