-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extract-PSXCrashVGM.ps1
executable file
·112 lines (100 loc) · 3.28 KB
/
Extract-PSXCrashVGM.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env pwsh
[CmdletBinding(DefaultParameterSetName = 'Path')]
Param (
[SupportsWildCards()]
[Parameter(
Position = 0,
ParameterSetName = 'Path',
ValueFromPipeline = $false,
ValueFromPipelineByPropertyName = $true
)]
[String[]]$Path,
[Alias('LP')]
[Alias('PSPath')]
[Parameter(
Position = 0,
ParameterSetName = 'LiteralPath',
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true
)]
[String[]]$LiteralPath,
[String]$Destination = $PWD,
[Int32]$GameVersion = 6 # [Crash.GameVersion]::Crash3
)
Begin {
Add-Type -LiteralPath $PSScriptRoot/Crash.dll
function FindLinkedVB {
$samples = [Collections.Generic.List[Crash.SampleLine]]::new()
# Calling the generic method (PowerShell 7.3 or higher is required)
$vb0entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB0EID)
$vb1entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB1EID)
$vb2entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB2EID)
$vb3entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB3EID)
$vb4entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB4EID)
$vb5entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB5EID)
$vb6entry = $NSF.GetEntry[Crash.WavebankEntry]($MusicEntry.VB6EID)
if ($null -ne $vb0entry) {
$samples.AddRange($vb0entry.Samples.SampleLines);
}
if ($null -ne $vb1entry) {
$samples.AddRange($vb1entry.Samples.SampleLines);
}
if ($null -ne $vb2entry) {
$samples.AddRange($vb2entry.Samples.SampleLines);
}
if ($null -ne $vb3entry) {
$samples.AddRange($vb3entry.Samples.SampleLines);
}
if ($null -ne $vb4entry) {
$samples.AddRange($vb4entry.Samples.SampleLines);
}
if ($null -ne $vb5entry) {
$samples.AddRange($vb5entry.Samples.SampleLines);
}
if ($null -ne $vb6entry) {
$samples.AddRange($vb6entry.Samples.SampleLines);
}
return ,$samples;
}
}
Process {
trap {
break
}
switch ($PSCmdlet.ParameterSetName) {
'Path' {
$Data = @(Get-Content -Path $Path -Raw -AsByteStream)
break
}
'LiteralPath' {
$Data = @(Get-Content -LiteralPath $LiteralPath -Raw -AsByteStream)
break
}
Default {
Write-Error -Message "Invalid parameter."
return
}
}
for ($i = 0; $i -lt $Data.Count; $i++) {
$NSF = [Crash.NSF]::LoadAndProcess($Data[$i], $GameVersion)
$MusicEntries = @($NSF.GetEntries[Crash.MusicEntry]())
$BaseName = $Data[$i].PSChildName.Split(".")[0]
foreach ($MusicEntry in $MusicEntries) {
$MusicIndex = $MusicEntry.EName[2]
if ($null -ne $MusicEntry.SEP) {
$OutFilePath = Join-Path $Destination "$BaseName($MusicIndex).SEP"
Set-Content -Value $MusicEntry.SEP.Save() -LiteralPath $OutFilePath -AsByteStream
}
$VH = $NSF.GetEntry[Crash.MusicEntry]($MusicEntry.VHEID).VH
if ($null -ne $VH) {
$OutFilePath = Join-Path $Destination "$BaseName($MusicIndex).VH"
Set-Content -Value $VH.Save() -LiteralPath $OutFilePath -AsByteStream
}
$VB = FindLinkedVB
if ($null -ne $VB) {
$OutFilePath = Join-Path $Destination "$BaseName($MusicIndex).VB"
Set-Content -Value ([Crash.SampleSet]::new($VB).Save()) -LiteralPath $OutFilePath -AsByteStream
}
}
}
}