33# Pieter De Ridder
44# Extract Fallout 76 (Or Fallout 4) Sound files from BA2 archive files
55# Created : 15/03/2020
6- # Updated : 11/01 /2021
6+ # Updated : 04/10 /2021
77#
88# Note : Because I use Powershell and use objects, but not really use OO architecture,
99# i work in each Function with Open en Close file statements. Just to be safe.
@@ -52,10 +52,10 @@ Function Get-BA2FileList {
5252 )
5353
5454 # create empty array
55- $BA2FilesList = @ ()
55+ [ System.Collections.ArrayList ] $BA2FilesList = @ ()
5656
5757 # hunt BA2 Archive files from given folder
58- If (Test-Path $GameInstallationPath ) {
58+ If (Test-Path - Path $GameInstallationPath ) {
5959 $BA2FilesList = @ ((Get-ChildItem - Path $GameInstallationPath - File - Filter " *.ba2" ).FullName)
6060
6161 # we got some files?
@@ -86,7 +86,7 @@ Function Dump-BA2HeaderRaw {
8686 [string ]$BA2Filename
8787 )
8888
89- If (Test-Path $BA2Filename ) {
89+ If (Test-Path - Path $BA2Filename ) {
9090 # dump first 24 bytes (BA2 Header) as a string
9191 $bytes = [System.IO.File ]::ReadAllBytes($BA2Filename )
9292 $BA2Dump = [System.Text.Encoding ]::ASCII.GetString($bytes , 0 , $global :BA2HeaderSize )
@@ -110,7 +110,7 @@ Function Read-BA2Header {
110110 # init empty var
111111 $BA2Header = $null
112112
113- If (Test-Path $BA2Filename ) {
113+ If (Test-Path - Path $BA2Filename ) {
114114 # Create a custom PWSH object for the BA2 Header
115115 $BA2Header = New-Object PSObject
116116
@@ -175,7 +175,7 @@ Function Read-BA2NameTable {
175175 $BA2NameTable = [System.Collections.ArrayList ]@ ()
176176
177177 If ($BA2Header -ne $null ) {
178- If (Test-Path $BA2Header.ArchiveFilePath ) {
178+ If (Test-Path - Path $BA2Header.ArchiveFilePath ) {
179179 # open the BA2 Archive
180180 $BA2File = [System.IO.File ]::OpenRead($BA2Header.ArchiveFilePath )
181181 $BA2Reader = New-Object System.IO.BinaryReader($BA2File , [System.Text.Encoding ]::ASCII)
@@ -225,7 +225,7 @@ Function Read-BA2FileTable {
225225 $BA2FileTable = [System.Collections.ArrayList ]@ ()
226226
227227 If ($BA2Header -ne $null ) {
228- If (Test-Path $BA2Header.ArchiveFilePath ) {
228+ If (Test-Path - Path $BA2Header.ArchiveFilePath ) {
229229 # open the BA2 Archive
230230 $BA2File = [System.IO.File ]::OpenRead($BA2Header.ArchiveFilePath )
231231 $BA2Reader = New-Object System.IO.BinaryReader($BA2File , [System.Text.Encoding ]::ASCII)
@@ -389,7 +389,7 @@ Function DecompressWrite-BA2Lump {
389389
390390#
391391# Function : Extract-BA2Data
392- # Open archive and extract data lumps
392+ # Open archive and extract BA2 archive data lumps as files
393393#
394394Function Extract-BA2Data {
395395 Param (
@@ -401,7 +401,7 @@ Function Extract-BA2Data {
401401 If (Test-Path $ExtractDestinationPath ) {
402402
403403 If ($BA2Header -ne $null ) {
404- If (Test-Path $BA2Header.ArchiveFilePath ) {
404+ If (Test-Path - Path $BA2Header.ArchiveFilePath ) {
405405 Write-Host " "
406406 Write-Host " Archive File : $ ( $BA2Header.ArchiveFilePath ) "
407407
@@ -427,10 +427,10 @@ Function Extract-BA2Data {
427427 Write-Host " Archive Type : BA2 General archive"
428428 Write-Host " "
429429
430- If ($BA2FileTable.Length -gt 0 ) {
430+ If ($BA2FileTable.Length -gt 0 ) {
431431 ForEach ($BA2FileSig in $BA2FileTable ) {
432- $packedFilename = Split-Path - Path $BA2FileSig.FileName - Leaf
433- # $packedFolder = Split-Path -Path $BA2FileSig.FileName -Parent
432+ [ string ] $packedFilename = Split-Path - Path $BA2FileSig.FileName - Leaf
433+ # [string] $packedFolder = Split-Path -Path $BA2FileSig.FileName -Parent
434434
435435 # extract only sound files
436436 If ($packedFilename.EndsWith (" .xwm" ) -or $packedFilename.EndsWith (" .fuz" )) {
@@ -541,7 +541,7 @@ Function Main {
541541 )
542542
543543 [string ]$FalloutGame = " Fallout 76" # change this to Fallout 4, Fallout 76, Fallout 76 PTS
544- [string ]$FalloutInstallPath = " " # internal var for installation path
544+ [string ]$FalloutInstallPath = [ string ]::Empty # internal var for installation path
545545 [string ]$MyExtractionFolder = " $ ( $PSScriptRoot ) \extracted_sfx" # extraction folder
546546
547547 # logic for cmdline arguments
@@ -550,8 +550,8 @@ Function Main {
550550 # Write-Host "DEBUG : Arg $($i.ToString()) is $($Arguments[$i])"
551551
552552 # default, a PWSH Switch statement on a String is always case insensitive
553- Switch ($Arguments [$i ]) {
554- " -InstallPath" {
553+ Switch ($Arguments [$i ]) {
554+ " -InstallPath" {
555555 # manually override Fallout Installation Path
556556 If (($i +1 ) -le $Arguments.Length ) {
557557 $FalloutInstallPath = $Arguments [$i +1 ]
@@ -574,7 +574,7 @@ Function Main {
574574 " Fallout4" { $FalloutGame = " Fallout 4" }
575575 " Fallout76" { $FalloutGame = " Fallout 76" }
576576 " Fallout76PTS" { $FalloutGame = " Fallout 76 PTS" }
577- }
577+ }
578578 }
579579
580580 " -ExtractDir" {
@@ -628,15 +628,13 @@ Function Main {
628628 # verify custom path with Data folder
629629 If (Test-Path - Path " $ ( $FalloutInstallPath ) \Data" ) {
630630 # add <game>\Data folder if needed our selves
631- $FalloutInstallPath += " \Data"
631+ $FalloutInstallPath = $FalloutInstallPath + " \Data"
632632 }
633633 }
634634
635-
636- # Override path to my local path (for debugging)
635+ # Override path to my personal local path (for debugging)
637636 # $FalloutInstallPath = "E:\Bethesda\$($FalloutGame.Substring(" ", ''))\Data"
638637
639-
640638 Write-Host " "
641639 Write-Host " --- EXTRACT FALLOUT SOUNDS FILES ---"
642640 Write-Host " Fallout game : $ ( $FalloutGame ) "
0 commit comments