Advertisement
FatalBulletHit

Tom Clancy's Rainbow Six Siege - Audio Extractor

May 15th, 2018 (edited)
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://pastebin.com/eGSUFbcs | https://forum.xentax.com/viewtopic.php?p=140570#p140570
  2.  
  3. ####################################################################################################
  4. # <><><><><><><><><> [READ ME] Tom Clancy's Rainbow Six Siege - Audio Extractor <><><><><><><><><> #
  5. #                                                                                                  #
  6. #                                                                                                  #
  7. # The Tom Clancy's Rainbow Six Siege - Audio Extractor will download multiple resources in order   #
  8. # to extract, convert and sort most of the audio files from the Ubisoft game Tom Clancy's Rainbow  #
  9. # Six Siege.                                                                                       #
  10. #                                                                                                  #
  11. # Be aware that the entire process may take several hours. For information on how to increase      #
  12. # performance, check the documentation (see below).                                                #
  13. #                                                                                                  #
  14. #                                                                                                  #
  15. # Note that from now on sorting is no longer directly possible as the proper names have been       #
  16. # removed from the end of the '.bnk' files when the audio source files were changed and is now     #
  17. # done based on file names and OasisIDs from old source files.                                     #
  18. #                                                                                                  #
  19. # Additionally all the '.lwav' files have been altered in a way that they are now extracted as     #
  20. # '.wav_unknown' files and cannot be converted at the moment.                                      #
  21. #                                                                                                  #
  22. #                                                                                                  #
  23. # Disclaimer:                                                                                      #
  24. #                                                                                                  #
  25. # I did not write any of the programs or scripts that are needed for extraction and conversion.    #
  26. # All credits belong to their authors, you may check out the links to the forum entries and        #
  27. # websites below.                                                                                  #
  28. #                                                                                                  #
  29. #     QuickBMS                                                                                     #
  30. #         http://aluigi.altervista.org/quickbms.htm                                                #
  31. #                                                                                                  #
  32. #     pck_AKPK_extractor.bms                                                                       #
  33. #         http://forum.xentax.com/viewtopic.php?p=80192#p80192                                     #
  34. #                                                                                                  #
  35. #     func_getTYPE.bms                                                                             #
  36. #         http://forum.xentax.com/viewtopic.php?f=13&p=69577#p69577                                #
  37. #                                                                                                  #
  38. #     bnk_extractor.bms                                                                            #
  39. #         http://forum.xentax.com/viewtopic.php?f=13&t=4450&p=89662#p89662                         #
  40. #                                                                                                  #
  41. #     ww2ogg (includes packed_codebooks_aoTuV_603.bin)                                             #
  42. #         https://www.hcs64.com/vgm_ripping.html                                                   #
  43. #         https://github.com/hcs64/ww2ogg                                                          #
  44. #                                                                                                  #
  45. #     revorb                                                                                       #
  46. #         https://hydrogenaud.io/index.php/topic,64328.msg574110.html#msg574110                    #
  47. #                                                                                                  #
  48. #     wwise_ima_adpcm (sound_conveter_v1.15.zip)                                                   #
  49. #         https://bitbucket.org/zabb65/payday-2-modding-information/downloads                      #
  50. #                                                                                                  #
  51. #     wwise_pcm_decoder.bms                                                                        #
  52. #         http://forum.xentax.com/viewtopic.php?p=110795#p110795                                   #
  53. #                                                                                                  #
  54. #                                                                                                  #
  55. # Documentation:                                                                                   #
  56. #                                                                                                  #
  57. #     XeNTaX post                                                                                  #
  58. #         http://forum.xentax.com/viewtopic.php?p=140570#p140570                                   #
  59. #                                                                                                  #
  60. #     Name overview                                                                                #
  61. #         https://goo.gl/PxQuCTv                                                                   #
  62. #                                                                                                  #
  63. #                                                                                                  #
  64. # Feel free to contact me if you have any suggestions or feedback, as well as bugs or similar.     #
  65. # You can do that by replying in the XeNTaX thread (see above) or emailing me (see below).         #
  66. #                                                                                                  #
  67. #                                                                                                  #
  68. # <><><><><><><><><><><><><><><> Contact:  FatalBulletHit@gmail.com <><><><><><><><><><><><><><><> #
  69. ####################################################################################################
  70.  
  71.  
  72.  
  73. # Variables below may be altered by the user if desired or needed (check the documentation for more information).
  74.  
  75. # Tom Clancy's Rainbow Six Siege installation directory (if the script cannot find it, uncomment the line below and adjust the path if needed)
  76. # $dirSource = "C:\Program Files (x86)\Steam\steamapps\common\Tom Clancy's Rainbow Six Siege"
  77.  
  78. # Output directory (feel free to adjust the path)
  79. $dirOutput = '{0}\output' -f $PSScriptRoot
  80.  
  81. # Remove '.wav_unknown' files when removing redundant files (don't know how to convert '.wav_unknown' (previously '.lwav'), 'wwise_ima_adpcm.exe' just produces nonsense)
  82. $wav_unknownRedundant = 1
  83.  
  84. # Remove redundant files ('.00040000', '.01020000', '.wav' (before conversion) and '.wav_unknown' (if the option above is enabled))
  85. $removeRedundant = 1
  86.  
  87. # Remove duplicate files (recommended as it decreases conversion duration and saves drive space)
  88. $removeDuplicates = 1
  89.  
  90. # Remove all extracted files after conversion
  91. $removeSource = 1
  92.  
  93. # Remove all empty directories after conversion
  94. $removeEmptyDir = 1
  95.  
  96. # When moving '.Wwise' files, use ranges for OasisIDs where possible rather than certain matches
  97. $greedyOasisTable = 1
  98.  
  99. # Creates a log file
  100. $createLog = 1
  101.  
  102.  
  103.  
  104. ####################################################################################################
  105. # <><><><><><><><><><><><><><><><><><><><> INITIALIZATION <><><><><><><><><><><><><><><><><><><><> #
  106.  
  107. $Version = '0.9.3'
  108. $OverallStart = (Get-Date)
  109. $ErrorActionPreference = 'Continue'
  110. $Global:ProgressPreference = 'SilentlyContinue'
  111. $RawUI = $Host.UI.RawUI
  112. $RawUI.WindowTitle = "Tom Clancy's Rainbow Six Siege - Audio Extractor"
  113. $RawUI.BackgroundColor = 'Black'
  114. $RawUI.ForegroundColor = 'Cyan'
  115. Clear-Host
  116.  
  117. $Connection = (Test-Connection -Computer 'google.com' -Count 1 -Quiet)
  118. $bnkTable = New-Object System.Collections.Hashtable
  119. $contentTable = New-Object System.Collections.Hashtable
  120. $dupTable = New-Object System.Collections.Hashtable
  121. $nameTable_bnk = New-Object System.Collections.Hashtable
  122. $nameTable_pck = New-Object System.Collections.Hashtable
  123. $oasisTable = New-Object System.Collections.Hashtable
  124. $oasisTable_ext = New-Object System.Collections.Hashtable
  125.  
  126. function Animate-Dot {
  127.  
  128.     Param (
  129.  
  130.         [Parameter(ValueFromPipeline=$true)]
  131.         [int]$Stop
  132.  
  133.     )
  134.  
  135.         if (!$Stop) {
  136.        
  137.         Write-Host '    ' -NoNewline
  138.        
  139.         if ($createLog) {
  140.        
  141.             '... ' | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -NoNewline
  142.        
  143.         }
  144.        
  145.         return (Start-Process PowerShell {
  146.        
  147.         $ParentProcessID = (Get-WmiObject -Class win32_process | Where-Object {$_.ProcessID -eq $PID}).ParentProcessID
  148.        
  149.             while ((Get-Process -Id $ParentProcessID 2>$null) -ne $null) {
  150.            
  151.                 for ($i = 0; $i -lt 4; $i++) {
  152.                
  153.                     Write-Host ("""`b`b`b`b{0,-4}""" -f ('.' * $i)) -NoNewline
  154.                     Start-Sleep -Milliseconds 250
  155.                    
  156.                 }
  157.             }
  158.        
  159.         } -NoNewWindow -PassThru).Id
  160.    
  161.     } else {
  162.    
  163.         Stop-Process -Id $Stop
  164.         Write-Host "`b`b`b`b... " -NoNewline
  165.         Write-Host -ForegroundColor Green ('Done!').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  166.         Write-Host (' | {0:h\:mm\:ss}' -f ((Get-Date) - $Start)).ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  167.    
  168.     }
  169. }
  170.  
  171. function Stop-ChildOnExit {
  172.  
  173.     Param (
  174.  
  175.         [Parameter(ValueFromPipeline=$true)]
  176.         [int]$monitorPID
  177.  
  178.     )
  179.  
  180.     $env:monitorPID = $monitorPID
  181.    
  182.     Start-Process PowerShell {
  183.    
  184.         while ((Get-Process -Id $env:monitorPID 2>$null) -ne $null) {
  185.        
  186.             if ((Get-Process -Id (Get-WmiObject -Class win32_process | Where-Object {$_.ProcessID -eq $PID}).ParentProcessID 2>$null) -eq $null) {
  187.            
  188.                 Stop-Process -Id $env:monitorPID 2>$null
  189.                
  190.             } else {
  191.            
  192.                 Start-Sleep -Milliseconds 100
  193.        
  194.             }
  195.         }
  196.    
  197.     } -WindowStyle Hidden
  198.    
  199.     Wait-Process -Id $monitorPID
  200.    
  201. }
  202.  
  203. if (Test-Path -LiteralPath $env:TEMP\tc_r6s_audio_extractor_started.tmp) {
  204.  
  205.     Remove-Item -LiteralPath $env:TEMP\tc_r6s_audio_extractor_started.tmp -ErrorAction SilentlyContinue
  206.  
  207. }
  208.  
  209. New-Item -Path $env:TEMP\tc_r6s_audio_extractor_started.tmp -ItemType File >$null
  210.  
  211. if ($RawUI.BufferSize.Width -lt 150) {
  212.  
  213.     [System.Console]::SetBufferSize(150, $RawUI.BufferSize.Height)
  214.  
  215. }
  216.  
  217. if ($RawUI.MaxPhysicalWindowSize.Width -ge 150) {
  218.  
  219.     [System.Console]::SetWindowSize(150, $RawUI.WindowSize.Height)
  220.     [System.Console]::SetBufferSize(150, $RawUI.BufferSize.Height)
  221.    
  222. }
  223.  
  224. if ($RawUI.MaxPhysicalWindowSize.Height -ge 40) {
  225.  
  226.     [System.Console]::SetWindowSize($RawUI.WindowSize.Width, 40)
  227.    
  228. }
  229.  
  230. if (Test-Path -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt) {
  231.  
  232.     Remove-Item -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -ErrorAction SilentlyContinue
  233.  
  234. }
  235.  
  236. # Installing
  237. if ((Get-Content -LiteralPath $PSCommandPath -Tail 1).Length -eq 99 -or $PSScriptRoot -eq (Get-Item -LiteralPath $env:TEMP).FullName) {
  238.  
  239.     # Default directory
  240.     $parentPID = (Get-WmiObject -Class win32_process | Where-Object {$_.ProcessID -eq $PID}).ParentProcessId
  241.    
  242.     if (($parentPath = (Get-WmiObject -Class win32_process | Where-Object {$_.ProcessID -eq $parentPID}).CommandLine.Split('"') | ? {$_ -match '\.bat'}).Count -gt 0 -and (Test-Path -LiteralPath $parentPath) -and ($parentItem = (Get-Item -LiteralPath $parentPath)).FullName.Substring(0,$env:TEMP.Length) -ne $env:TEMP) {
  243.    
  244.         $dirSelect = $parentItem.DirectoryName
  245.         $toggleSwitch = $false
  246.    
  247.     } else {
  248.    
  249.         $dirSelect = '{0}\Desktop' -f $Home
  250.         $toggleSwitch = $true
  251.    
  252.     }
  253.    
  254.     $dirSelectSub = '\tc_r6s_audio_extractor'
  255.  
  256.     # Description for FolderBrowserDialog
  257.     $description = 'Select the directory to move and download all the required and related files in:'
  258.  
  259.     Add-Type -AssemblyName System.Windows.Forms
  260.     $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{Description = $description}
  261.     $CursorPositionY = $RawUI.CursorPosition.Y + 2
  262.     Write-Host (' Destination directory for all required and related files:').ForEach({if ($createLog) {("{0}`n" -f $_) | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt; $_} else {$_}})
  263.    
  264.     if ($toggleSwitch) {
  265.    
  266.         Write-Host -ForegroundColor Magenta ("`n`t {0}{1}`n" -f $dirSelect, $dirSelectSub)
  267.    
  268.     } else {
  269.    
  270.         Write-Host -ForegroundColor Magenta ("`n`t {0}`n" -f $dirSelect)
  271.    
  272.     }
  273.    
  274.     Write-Host ' [B]rowse / [C]onfirm / ' -NoNewline
  275.    
  276.     if ($toggleSwitch) {
  277.    
  278.         Write-Host -ForegroundColor Yellow '[T]oggle pre-defined directory' -NoNewline
  279.    
  280.     } else {
  281.    
  282.         Write-Host '[T]oggle pre-defined directory' -NoNewline
  283.    
  284.     }
  285.  
  286.     while (($tempKey = [string]([System.Console]::ReadKey('NoEcho')).Key) -ne 'C') {
  287.  
  288.         if ($tempKey -eq 'T') {
  289.        
  290.             [System.Console]::SetCursorPosition(0, $CursorPositionY)
  291.        
  292.             if (($toggleSwitch = !$toggleSwitch)) {
  293.            
  294.                 Write-Host -ForegroundColor Magenta ("{0}`r`t {1}{2}`n" -f (' ' * $RawUI.BufferSize.Width), $dirSelect, $dirSelectSub).Replace('\\','\')
  295.            
  296.             } else {
  297.            
  298.                 Write-Host -ForegroundColor Magenta ("{0}`r`t {1}`n" -f (' ' * $RawUI.BufferSize.Width), $dirSelect).Replace('\\','\')
  299.            
  300.             }
  301.        
  302.         } elseif ($tempKey -eq 'B') {
  303.        
  304.             Write-Host -ForegroundColor Yellow "`r [B]rowse " -NoNewline
  305.             Write-Host '/ [C]onfirm' -NoNewline
  306.             [void]$FolderBrowser.ShowDialog()
  307.             [System.Console]::SetCursorPosition(0, $CursorPositionY)
  308.            
  309.             if ([string]$FolderBrowser.SelectedPath -ne $null -and (Test-Path -LiteralPath $FolderBrowser.SelectedPath)) {
  310.            
  311.                 $dirSelect = $FolderBrowser.SelectedPath
  312.            
  313.             }
  314.            
  315.             Write-Host -ForegroundColor Magenta ("{0}`r`t {1}{2}`n" -f (' ' * $RawUI.BufferSize.Width), $dirSelect, $dirSelectSub).Replace('\\','\')
  316.             Write-Host ' [B]rowse / [C]onfirm' -NoNewline
  317.        
  318.         }
  319.        
  320.         [System.Console]::SetCursorPosition(24, $CursorPositionY + 2)
  321.        
  322.         if ($toggleSwitch) {
  323.        
  324.             Write-Host -ForegroundColor Yellow '[T]oggle pre-defined directory' -NoNewline
  325.        
  326.         } else {
  327.        
  328.             Write-Host '[T]oggle pre-defined directory' -NoNewline
  329.        
  330.         }
  331.     }
  332.  
  333.     $env:dirExtractor = $dirExtractor = $dirSelect
  334.    
  335.     if ($toggleSwitch) {
  336.    
  337.         $env:dirExtractor = $dirExtractor = ('{0}{1}' -f $dirSelect, $dirSelectSub).Replace('\\','\')
  338.    
  339.     }
  340.    
  341.     Write-Host "`r [B]rowse /" -NoNewline
  342.     Write-Host -ForegroundColor Yellow ' [C]onfirm'
  343.    
  344.     if ($createLog) {
  345.    
  346.         ("`t{0}" -f $dirExtractor) | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt
  347.    
  348.     }
  349.    
  350.     if (!(Test-Path -LiteralPath $dirExtractor)) {
  351.    
  352.         New-Item -Path $dirExtractor -ItemType Directory >$null
  353.    
  354.     } else {
  355.    
  356.         if (Test-Path -LiteralPath ('{0}\tc_r6s_audio_extractor.ps1' -f $dirExtractor)) {
  357.              
  358.             if (($tempMatch = [regex]::Matches((Get-Content -LiteralPath ('{0}\tc_r6s_audio_extractor.ps1' -f $dirExtractor)), '\$Version = ({0}|")([0-9]+\.[0-9]+\.?[0-9]*)({0}|")' -f [char]39)).Count -gt 0 -and $tempMatch.Groups[2].Value -ne $Version) {
  359.            
  360.                 Rename-Item -LiteralPath ('{0}\tc_r6s_audio_extractor.ps1' -f $dirExtractor) -NewName ('tc_r6s_audio_extractor_old_{0}.ps1' -f $tempMatch.Groups[2].Value)
  361.            
  362.             } else {
  363.            
  364.                 Rename-Item -LiteralPath ('{0}\tc_r6s_audio_extractor.ps1' -f $dirExtractor) -NewName 'tc_r6s_audio_extractor_old.ps1'
  365.            
  366.             }
  367.         }
  368.     }
  369.    
  370.     if ((Test-Path -LiteralPath $parentPath) -and ('{0}\{1}' -f $dirExtractor, $parentItem.Name) -ne $parentItem.FullName) {
  371.  
  372.         if (Test-Path -LiteralPath ('{0}\{1}' -f $dirExtractor, $parentItem.Name)) {
  373.          
  374.             Rename-Item -LiteralPath $parentItem.FullName -NewName ('{0}\{1}_old.bat' -f $parentItem.DirectoryName, $parentItem.BaseName)
  375.        
  376.         }
  377.        
  378.         Move-Item -LiteralPath $parentItem.FullName -Destination $dirExtractor -Force
  379.        
  380.     } elseif ($Connection -and !(Test-Path -LiteralPath ('{0}\Launcher.bat' -f $dirExtractor))) {
  381.    
  382.         (Invoke-WebRequest -Uri 'https://pastebin.com/raw/iC6YuYPj' -UseBasicParsing).Content | Out-File -LiteralPath ('{0}\Launcher.bat' -f $dirExtractor) -Encoding 'UTF8'
  383.    
  384.     }
  385.    
  386.     Move-Item -LiteralPath $PSCommandPath -Destination $dirExtractor -Force
  387.    
  388.     if ($dirOutput -eq ('{0}\output' -f (Get-Item -LiteralPath $env:TEMP).FullName)) {
  389.    
  390.         $dirOutput = ('{0}\output' -f $dirExtractor)
  391.    
  392.     }
  393.    
  394.     '#' | Add-Content -LiteralPath ('{0}\tc_r6s_audio_extractor.ps1' -f $dirExtractor) -NoNewline
  395.     Set-Location -LiteralPath $dirExtractor
  396.     Write-Host -ForegroundColor Green ("`n Installation successful!`n").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt} else {$_}})
  397.     Write-Host ' [C]ontinue with default preferences / [E]xit' -NoNewline
  398.    
  399.     while (!('C', 'E').Contains(($tempKey = [string]([System.Console]::ReadKey('NoEcho')).Key))) {}
  400.    
  401.     if ($tempKey -eq 'E') {
  402.    
  403.         Write-Host -ForegroundColor Yellow "`b`b`b`b`b`b[E]xit`n"
  404.         Write-Host ('Exiting!').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt} else {$_}})
  405.         Start-Sleep 3
  406.         exit
  407.    
  408.     }
  409.    
  410.     Write-Host -ForegroundColor Yellow "`r [C]ontinue with default preferences`n "
  411.     Write-Host ('Continuing!').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt} else {$_}})
  412.     Start-Sleep 3
  413.     Clear-Host
  414.  
  415. } else {
  416.  
  417.     $env:dirExtractor = $dirExtractor = $PSScriptRoot
  418.  
  419. }
  420.  
  421. # Moving error log if any
  422. Start-Process PowerShell {
  423.  
  424.     $ParentProcessID = (Get-WmiObject -Class win32_process | Where-Object {$_.ProcessID -eq $PID}).ParentProcessID
  425.    
  426.     do {
  427.    
  428.         Start-Sleep -Milliseconds 250
  429.        
  430.         if (Test-Path -LiteralPath $env:TEMP\tc_r6s_audio_extractor_error.txt) {
  431.        
  432.             if ((Get-Item -LiteralPath $env:TEMP\tc_r6s_audio_extractor_error.txt).Length -gt 0) {
  433.            
  434.                 Stop-Process -Id $ParentProcessID
  435.                 New-Item -Path ('{0}\error_logs' -f $env:dirExtractor) -ItemType Directory -ErrorAction SilentlyContinue >$null
  436.                 Move-Item -LiteralPath $env:TEMP\tc_r6s_audio_extractor_error.txt -Destination ('{0}\error_logs\tc_r6s_audio_extractor_error_{1}.txt' -f $env:dirExtractor, (Get-Date).ToString('yymmddhhmmss'))
  437.                
  438.                 Start-Process PowerShell {
  439.                
  440.                     $Host.UI.RawUI.WindowTitle = 'Tom Clancy{0}s Rainbow Six Siege - Audio Extractor' -f ([char]39)
  441.                     $Host.UI.RawUI.BackgroundColor = 'Black'
  442.                     $Host.UI.RawUI.ForegroundColor = 'Cyan'
  443.                     Clear-Host
  444.                     Write-Host -ForegroundColor Yellow (' WARNING: An error occurred during script execution! The log has been moved to').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  445.                     Write-Host -ForegroundColor Magenta (' {0}\error_logs' -f $env:dirExtractor).ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  446.                     Read-Host
  447.                     exit
  448.                
  449.                 }
  450.                
  451.             } else {
  452.            
  453.                 Remove-Item -LiteralPath $env:TEMP\tc_r6s_audio_extractor_error.txt
  454.            
  455.             }
  456.         }
  457.        
  458.     } until ((Get-Process -Id $ParentProcessID 2>$null) -eq $null)
  459.    
  460.     if (Test-Path -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt) {
  461.    
  462.         New-Item -Path ('{0}\logs' -f $env:dirExtractor) -ItemType Directory -ErrorAction SilentlyContinue >$null
  463.         Move-Item -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -Destination ('{0}\logs\tc_r6s_audio_extractor_log_{1}.txt' -f $env:dirExtractor, (Get-Date).ToString('yymmddhhmmss'))
  464.    
  465.     }
  466.    
  467.     Start-Sleep 5
  468.     exit
  469.  
  470. } -WindowStyle Hidden
  471.  
  472. # Testing connection
  473. if (!$Connection) {
  474.  
  475.     Write-Host -ForegroundColor Yellow ("`n WARNING: Cannot establish internet connection!").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  476.  
  477. } else {
  478.  
  479.     if (($AvailableVersion = (Invoke-WebRequest -Uri 'https://pastebin.com/raw/XBQPYqnz' -UseBasicParsing).Content) -ne $Version) {
  480.  
  481.         Write-Host -ForegroundColor Yellow ("`n Current version: {0} | Latest version: {1}" -f $Version, $AvailableVersion).ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  482.         Write-Host ("`n Downloading latest version!").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  483.         Rename-Item -LiteralPath $PSCommandPath -NewName ('{0}_old_{1}.ps1' -f (Get-Item -LiteralPath $PSCommandPath).BaseName, $Version)
  484.         ('{0}#' -f (Invoke-WebRequest -Uri 'https://pastebin.com/raw/eGSUFbcs' -UseBasicParsing).Content) | Out-File -LiteralPath $PSCommandPath -Encoding UTF8 -NoNewline
  485.         Write-Host ("`n Please restart manually!").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -NoNewline
  486.         Read-Host
  487.         exit
  488.  
  489.     } else {
  490.  
  491.         Write-Host -ForegroundColor Green ("`n Current version: {0} | Latest version: {1}" -f $Version, $AvailableVersion).ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  492.  
  493.     }
  494. }
  495.  
  496. # Searching for missing resources
  497. New-Item -Path '.\resources\aliasTables', '.\resources\applications', '.\resources\scripts', '.\resources\archives' -ItemType Directory -ErrorAction SilentlyContinue >$null
  498. Write-Host ("`n Searching for missing and outdated resources").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  499. $Start = (Get-Date)
  500. $animatePID = Animate-Dot
  501.  
  502. if ((Get-ChildItem '.\resources\aliasTables' -File).Count -gt 0) {
  503.  
  504.     (Invoke-WebRequest -Uri 'https://pastebin.com/raw/zCreUdGp' -UseBasicParsing).Content | ForEach-Object {
  505.    
  506.         if (!(Test-Path ('.\resources\aliasTables\{0}' -f $_.Split(';')[0])) -or ($tempLine = (Get-Content ('.\resources\aliasTables\{0}' -f $_.Split(';')[0]) -TotalCount 1)).Substring(0,1) -ne '#' -or $tempLine.Substring(2,3) -ne $_.Split(';')[1].Substring(0,3)) {
  507.        
  508.             $outdatedAlias += ,('.\resources\aliasTables\{0}' -f $_.Split(';')[0])
  509.        
  510.         }
  511.     }
  512. }
  513.  
  514. (('.\resources\applications\quickbms.exe', '.\resources\archives\quickbms.zip'), ('https://drive.google.com/uc?export=download&id=1qfUHube-SnZJV3P5Iej62b6DbxnOogv1', 'http://aluigi.altervista.org/papers/quickbms.zip')), (('.\resources\applications\ww2ogg.exe', '.\resources\archives\ww2ogg024.zip'), ('https://drive.google.com/uc?export=download&id=1urVxXt3cKykCj7G2Wm4IYJuPLP_QoUZc', 'https://www.hcs64.com/files/ww2ogg024.zip')), (('.\resources\applications\packed_codebooks_aoTuV_603.bin', '.\resources\archives\ww2ogg024.zip'), ('https://drive.google.com/uc?export=download&id=1Tebo2-rDlnf58oXQgCDTPD3g_W-kSTML', 'https://www.hcs64.com/files/ww2ogg024.zip')), ('.\resources\applications\revorb.exe', ('https://drive.google.com/uc?export=download&id=1M4a7Zknk_d02vD-LopOmoqWZWOcdlS05', 'http://yirkha.fud.cz/progs/foobar2000/revorb.exe')), (('.\resources\applications\wwise_ima_adpcm.exe', '.\resources\archives\sound_conveter_v1.15.zip'), ('https://drive.google.com/uc?export=download&id=1Hr7r7RVKLU6iJVpZZpBSTO97NXXq1S9J', 'https://bitbucket.org/zabb65/payday-2-modding-information/downloads/sound_conveter_v1.15.zip')), ('.\resources\scripts\bnk_extractor.bms', ('https://drive.google.com/uc?export=download&id=1qsqo9EHi9mgQ_ytu4o35wr1puHJ74le6', 'https://pastebin.com/raw/LXUa1Mri')), ('.\resources\scripts\func_getTYPE.bms', ('https://drive.google.com/uc?export=download&id=1HrPJjBwk1gDmfHWwlLUHp5GsVEYfMMXV', 'https://pastebin.com/raw/puz9zQ6f')), ('.\resources\scripts\pck_AKPK_extractor.bms', ('https://drive.google.com/uc?export=download&id=1SrIqUn6ba_VlB3LTQp9HuL8fDo3U5PH2', 'https://pastebin.com/raw/n6BccWjA')), ('.\resources\scripts\wwise_pcm_decoder.bms', ('https://drive.google.com/uc?export=download&id=1ciksiKfhPkAeckJcqN8yXjRqy8yuyVxw', 'https://pastebin.com/raw/qB4JWNeV')), ('.\resources\aliasTables\r6s_extractor_bnkTable.txt', 'https://pastebin.com/raw/34ekBA6T'), ('.\resources\aliasTables\r6s_extractor_nameTable_bnk.txt', 'https://drive.google.com/uc?export=download&id=13Ey2tjLY92j7g-RUXs0m92a5ndQZNl0V'), ('.\resources\aliasTables\r6s_extractor_nameTable_pck.txt', 'https://drive.google.com/uc?export=download&id=12wyuUCtqYnUUHeS8UER7L5bIt8Xxu9VX'), ('.\resources\aliasTables\r6s_extractor_oasisTable_greedy.txt', 'https://pastebin.com/raw/CGrY3PWX'), ('.\resources\aliasTables\r6s_extractor_oasisTable_exact.txt', 'https://pastebin.com/raw/Yi5SeynY') | ForEach-Object {
  515.  
  516.     if ($_[0] -is [array]) {
  517.    
  518.         if (!(Test-Path $_[0][0])) {
  519.        
  520.             if (!(Test-Path $_[0][1])) {
  521.            
  522.                 if ($Connection) {
  523.                
  524.                     Invoke-WebRequest -Uri $_[1][1] -OutFile $_[0][1] -UseBasicParsing
  525.                     $Downloading = $true
  526.                    
  527.                 } else {
  528.                
  529.                     $Missing += "`n`t'{0}'" -f ($_[0][0]).Split('\')[3]
  530.            
  531.                 }
  532.             }
  533.            
  534.             if (Test-Path $_[0][1]) {
  535.            
  536.                 New-Item -Path '.\resources\archives\temp' -ItemType Directory -ErrorAction SilentlyContinue >$null
  537.                 Expand-Archive $_[0][1] -DestinationPath '.\resources\archives\temp'
  538.                 Move-Item ('.\resources\archives\temp\{0}' -f ($_[0][0]).Split('\')[3]) -Destination '.\resources\applications'
  539.                 Remove-Item '.\resources\archives\temp' -Recurse
  540.                
  541.             } elseif ($Connection) {
  542.            
  543.                 Invoke-WebRequest -Uri $_[1][0] -OutFile $_[0][0] -UseBasicParsing
  544.            
  545.             }
  546.            
  547.             if (!(Test-Path $_[0][0]) -and $Downloading) {
  548.            
  549.                 $Missing += "`n`t'{0}'" -f ($_[0][0]).Split('\')[3]
  550.            
  551.             }
  552.         }
  553.        
  554.     } else {
  555.    
  556.         if (!(Test-Path $_[0]) -or ($outdatedAlias.Count -gt 0 -and $outdatedAlias.Contains($_[0]))) {
  557.        
  558.             if ($Connection) {
  559.                
  560.                 if ($_[1] -is [array]) {
  561.                
  562.                     Invoke-WebRequest -Uri $_[1][1] -OutFile $_[0] -UseBasicParsing
  563.                
  564.                     if (Test-Path $_[0]) {
  565.                    
  566.                         Invoke-WebRequest -Uri $_[1][0] -OutFile $_[0] -UseBasicParsing
  567.                    
  568.                     }
  569.                
  570.                 } else {
  571.                
  572.                     Invoke-WebRequest -Uri $_[1] -OutFile $_[0] -UseBasicParsing
  573.                
  574.                 }
  575.                
  576.                 if (!(Test-Path $_[0])) {
  577.                
  578.                     $Missing += "`n`t'{0}'" -f ($_[0]).Split('\')[3]
  579.                
  580.                 }
  581.                
  582.             } elseif ($_[0] -notmatch 'alias') {
  583.            
  584.                 $Missing += "`n`t'{0}'" -f ($_[0]).Split('\')[3]
  585.        
  586.             }
  587.         }
  588.     }
  589.    
  590.     Clear-Variable -Name 'Downloading' -ErrorAction SilentlyContinue
  591.    
  592. }
  593.  
  594. $animatePID | Animate-Dot
  595.  
  596. if ($Missing.Length -gt 0) {
  597.  
  598.     Write-Host ("`n ERROR: Missing the following resources:`n").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -ForegroundColor Red
  599.     Write-Host $Missing.ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -ForegroundColor Red
  600.     Write-Host ("`n Download manually or try again.").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -ForegroundColor Magenta
  601.     Write-Host ("`n Terminating!").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -ForegroundColor Red
  602.     Start-Sleep 5
  603.     exit
  604.  
  605. }
  606.  
  607. # Checking for installation directory
  608. if ($dirSource -eq $null -or !(Test-Path -LiteralPath $dirSource)) {
  609.  
  610.     if ((Test-Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs\635') -and (Test-Path -LiteralPath ($tempPath = (Get-ItemProperty 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs\635').InstallDir.Replace('/', '\')))) {
  611.    
  612.         $dirSource = $tempPath.TrimEnd('\')
  613.    
  614.     } else {
  615.    
  616.         Write-Host ("`n ERROR: Cannot find Tom Clancy's Rainbow Six Siege installation directory, define manually in script!`n`n Terminating!").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -ForegroundColor Red
  617.         Start-Sleep 5
  618.         exit
  619.    
  620.     }
  621. }
  622.  
  623. if (Test-Path -LiteralPath ('{0}\sounddata\pc' -f $dirSource)) {
  624.    
  625.     $dirSource += '\sounddata\pc'
  626.    
  627. }
  628.  
  629. # Checking for source files
  630. if (($pckCount = (Get-ChildItem -LiteralPath $dirSource -Recurse -File -Filter *.pck).Count) -eq 0) {
  631.  
  632.     Write-Host ("`n ERROR: Cannot find any source files, define manually in script!`n`n Terminating!").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}}) -ForegroundColor Red
  633.     Start-Sleep 5
  634.     exit
  635.  
  636. } else {
  637.  
  638.     Write-Host ("`n Found {0} '.pck' files at " -f $pckCount).ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  639.     Write-Host -ForegroundColor Magenta $dirSource.ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  640.  
  641. }
  642.  
  643. # Checking for output directory
  644. if (!(Test-Path -LiteralPath $dirOutput)) {
  645.  
  646.     New-Item -Path $dirOutput -ItemType 'Directory' -ErrorAction SilentlyContinue >$null
  647.     Write-Host -ForegroundColor Green ("`n Created output directory at ").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  648.     Write-Host -ForegroundColor Magenta $dirOutput.ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  649.  
  650. } else {
  651.  
  652.     Write-Host -ForegroundColor Green ("`n Output directory located at ").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  653.     Write-Host -ForegroundColor Magenta $dirOutput.ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  654.  
  655. }
  656.  
  657. # <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> #
  658. ####################################################################################################
  659.  
  660. ####################################################################################################
  661. # <><><><><><><><><><><><><><><><><><><><><> EXTRACTION <><><><><><><><><><><><><><><><><><><><><> #
  662.  
  663. # .pck
  664. Write-Host ("`n Extracting '.pck' files").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  665. $Start = (Get-Date)
  666. $animatePID = Animate-Dot
  667.  
  668. # Extracting .pck
  669. (Start-Process .\resources\applications\quickbms.exe -ArgumentList ('-F *.pck -K -D -Y -. -Q -R .\resources\scripts\pck_AKPK_extractor.bms "{0}" "{1}"' -f $dirSource, $dirOutput) -WindowStyle Hidden -PassThru).Id | Stop-ChildOnExit
  670.  
  671. $animatePID | Animate-Dot
  672.  
  673. # .bnk
  674. Write-Host (" Extracting '.bnk' files").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  675. $Start = (Get-Date)
  676. $animatePID = Animate-Dot
  677.  
  678. # Populating $bnkTable
  679. Get-Content .\resources\aliasTables\r6s_extractor_bnkTable.txt | Select-Object -Skip 1 | ForEach-Object {
  680.  
  681.     $bnkTable.Add($_.Split(';')[0].Split(','), (($_.Split(';') | Select-Object -Skip 1) -join ';'))
  682.  
  683. }
  684.  
  685. # Extracting .bnk
  686. Get-ChildItem $dirOutput -File -Recurse -Filter *.bnk | ForEach-Object {
  687.  
  688.     $fileName = $_.BaseName
  689.    
  690.     if (($alias = ($bnkTable.GetEnumerator() | Where-Object {$_.Name.Contains($fileName.Substring(2))} | Select-Object -First 1).Value) -ne $null) {
  691.    
  692.         if ($alias.Contains(';')) {
  693.        
  694.             $dirPath = $_.DirectoryName
  695.             $alias = ($alias.Split(';') | Where-Object {$dirPath -match $_.Split(',')[1]} | Select-Object -First 1 | ForEach-Object {$_.Split(',')[0]})
  696.        
  697.         }
  698.        
  699.         $bnkOut = '{0}\{1} ({2})' -f $_.DirectoryName, $alias, $_.BaseName
  700.    
  701.     } else {
  702.    
  703.         $bnkOut = '{0}\{1}' -f $_.DirectoryName, $_.BaseName
  704.    
  705.     }
  706.    
  707.     (Start-Process .\resources\applications\quickbms.exe -ArgumentList ('-K -D -Y -. -Q -R .\resources\scripts\bnk_extractor.bms "{0}" "{1}"' -f $_.FullName, $bnkOut) -WindowStyle Hidden -PassThru).Id | Stop-ChildOnExit
  708.     Clear-Variable -Name 'fileName', 'bnkOut' 2>$null
  709.    
  710. }
  711.  
  712. $animatePID | Animate-Dot
  713.  
  714. # <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> #
  715. ####################################################################################################
  716.  
  717. ####################################################################################################
  718. # <><><><><><><><><><><> REMOVING REDUNDANT AND DUPLICATE FILES AND SORTING <><><><><><><><><><><> #
  719.  
  720. # Removing redundant files
  721. if ($removeRedundant) {
  722.  
  723.     Write-Host (' Removing redundant files').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  724.     $Start = (Get-Date)
  725.     $animatePID = Animate-Dot
  726.  
  727.     $filter = '.00040000', '.01020000', '.wav'
  728.    
  729.     if ($wav_unknownRedundant) {
  730.    
  731.         $filter += ,'.wav_unknown'
  732.    
  733.     }
  734.    
  735.     if ($removeSource) {
  736.    
  737.         $filter += ,'.bnk'
  738.    
  739.     }
  740.    
  741.     Get-ChildItem -LiteralPath $dirOutput -File -Recurse | Where-Object {$filter.Contains($_.Extension)} | ForEach-Object {
  742.    
  743.         Remove-Item -LiteralPath $_.FullName
  744.    
  745.     }
  746.    
  747.     $animatePID | Animate-Dot
  748.    
  749. }
  750.  
  751. # Moving files
  752. # Based on .bnk output
  753. Write-Host (' Moving extracted files').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  754. $Start = (Get-Date)
  755. $animatePID = Animate-Dot
  756.  
  757. Get-ChildItem -LiteralPath $dirOutput -File -Recurse -Filter '* *' | Where-Object { $_.Directory.Name -notmatch 'sounds' } | ForEach-Object {
  758.    
  759.     if ($_.Extension -eq '.Wwise' -and ($tempMatch = [regex]::Matches((Get-Content $_.FullName), 'OasisID[0-9]+')).Count -gt 0) {
  760.    
  761.         if (!$oasisTable.Contains($tempMatch.Groups[0].Value)) {
  762.        
  763.             $oasisTable.Add($tempMatch.Groups[0].Value, $_.Directory.Name)
  764.        
  765.         }
  766.    
  767.     } elseif (!$contentTable.Contains(([string]$tempContent = (Get-Content $_.FullName -TotalCount 3)))) {
  768.    
  769.         $contentTable.Add($tempContent, $_.Directory.Name)
  770.    
  771.     }
  772. }
  773.  
  774. Get-ChildItem -LiteralPath $dirOutput -File -Recurse -Exclude '* *' | Where-Object { $_.Directory.Name -match 'sounds' } | ForEach-Object {
  775.  
  776.     if (($_.Extension -eq '.Wwise' -and ($tempMatch = [regex]::Matches((Get-Content $_.FullName), 'OasisID[0-9]+')).Count -gt 0 -and ($tempName = $oasisTable.($tempMatch.Groups[0].Value))) -or ($tempName = $contentTable.((Get-Content $_.FullName -TotalCount 3) -as [string]))) {
  777.    
  778.         if (!(Test-Path ('{0}\{1}' -f $_.DirectoryName, $tempName))) {
  779.        
  780.             New-Item ('{0}\{1}' -f $_.DirectoryName, $tempName) -ItemType Directory >$null
  781.        
  782.         }
  783.        
  784.         Move-Item $_.FullName -Destination ('{0}\{1}' -f $_.DirectoryName, $tempName)
  785.    
  786.     }
  787. }
  788.  
  789. # Based on $oasisTable_ext
  790. if ($greedyOasisTable) {
  791.  
  792.     $tempPath = '.\resources\aliasTables\r6s_extractor_oasisTable_greedy.txt'
  793.  
  794. } else {
  795.  
  796.     $tempPath = '.\resources\aliasTables\r6s_extractor_oasisTable_exact.txt'
  797.  
  798. }
  799.  
  800. # Populating $oasisTable_ext
  801. Get-Content $tempPath | Select-Object -Skip 1 | ForEach-Object {
  802.  
  803.     $oasisTable_ext.Add(($_.Split(';')[0].Split(',') | ForEach-Object {
  804.  
  805.         if ($_.Contains('..')) {
  806.        
  807.             [int]$s, [int]$e = $_ -split '\.\.'
  808.             $s..$e
  809.        
  810.         } else {
  811.        
  812.             $_
  813.        
  814.         }
  815.    
  816.     }), $_.Split(';')[1])
  817.  
  818. }
  819.  
  820. Get-ChildItem -LiteralPath $dirOutput -File -Recurse -Filter *.Wwise | Where-Object { $_.Directory.Name -cnotmatch '[A-Z]' } | ForEach-Object {
  821.  
  822.     if (($tempMatch = [regex]::Matches((Get-Content $_.FullName), 'OasisID([0-9]+)')).Count -gt 0 -and ($tempName = ($oasisTable_ext.GetEnumerator() | Where-Object {$_.Name.Contains($tempMatch.Groups[1].Value)}).Value) -ne $null) {
  823.    
  824.         if ($_.Directory.Name -match '0x') {
  825.        
  826.             $tempDir = $_.Directory.Parent.FullName
  827.             $tempName += ' ({0})' -f $_.Directory.Name
  828.        
  829.         } else {
  830.        
  831.             $tempDir = $_.DirectoryName
  832.        
  833.         }
  834.        
  835.         if (!(Test-Path ('{0}\{1}' -f $tempDir, $tempName))) {
  836.        
  837.             New-Item ('{0}\{1}' -f $tempDir, $tempName) -ItemType Directory >$null
  838.        
  839.         }
  840.        
  841.         Move-Item $_.FullName -Destination ('{0}\{1}' -f $tempDir, $tempName)
  842.  
  843.     }
  844. }
  845.  
  846. # Based on $nameTable_pck
  847. # Populating $nameTable_pck
  848. Get-Content .\resources\aliasTables\r6s_extractor_nameTable_pck.txt | Select-Object -Skip 1 | ForEach-Object {
  849.  
  850.     $nameTable_pck.Add($_.Split(';')[0].Split(',').Replace('lwav', 'wav_unknown'), $_.Split(';')[1])
  851.  
  852. }
  853.  
  854. Get-ChildItem -LiteralPath $dirOutput -File -Recurse -Exclude '* *' | ? { $_.Directory.Name -cnotmatch '[A-Z]' } | ForEach-Object {
  855.  
  856.     $tempBaseFile = $_.BaseName.Substring(2)
  857.     $tempFile = $_.Name.Substring(2)
  858.    
  859.     if (($tempName = ($nameTable_pck.GetEnumerator() | Where-Object {$_.Name.Contains($tempBaseFile) -or $_.Name.Contains($tempFile)}).Value) -ne $null) {
  860.    
  861.         if ($_.Directory.Name -match '0x') {
  862.        
  863.             $tempDir = $_.Directory.Parent.FullName
  864.             $tempName += ' ({0})' -f $_.Directory.Name
  865.        
  866.         } else {
  867.        
  868.             $tempDir = $_.DirectoryName
  869.        
  870.         }
  871.        
  872.         if (!(Test-Path ('{0}\{1}' -f $tempDir, $tempName))) {
  873.        
  874.             New-Item ('{0}\{1}' -f $tempDir, $tempName) -ItemType Directory >$null
  875.        
  876.         }
  877.        
  878.         Move-Item $_.FullName -Destination ('{0}\{1}' -f $tempDir, $tempName)
  879.  
  880.     }
  881. }
  882.  
  883. # Based on $nameTable_bnk
  884. # Populating $nameTable_bnk
  885. Get-Content .\resources\aliasTables\r6s_extractor_nameTable_bnk.txt | Select-Object -Skip 1 | ForEach-Object {
  886.  
  887.     $nameTable_bnk.Add($_.Split(';')[0].Split(',').Replace('lwav', 'wav_unknown'), $_.Split(';')[1])
  888.  
  889. }
  890.  
  891. Get-ChildItem -LiteralPath $dirOutput -File -Recurse -Filter '* *' | ? { $_.Directory.Name -cnotmatch '[A-Z]' } | ForEach-Object {
  892.  
  893.     $tempBaseFile = $_.BaseName.Substring(2)
  894.    
  895.     if (($tempName = ($nameTable_pck.GetEnumerator() | Where-Object {$_.Name.Contains($tempBaseFile)}).Value) -ne $null) {
  896.    
  897.         if ($_.Directory.Name -match '0x') {
  898.        
  899.             $tempDir = $_.Directory.Parent.FullName
  900.             $tempName += ' ({0})' -f $_.Directory.Name
  901.        
  902.         } else {
  903.        
  904.             $tempDir = $_.DirectoryName
  905.        
  906.         }
  907.        
  908.         if (!(Test-Path ('{0}\{1}' -f $tempDir, $tempName))) {
  909.        
  910.             New-Item ('{0}\{1}' -f $tempDir, $tempName) -ItemType Directory >$null
  911.        
  912.         }
  913.        
  914.         Move-Item $_.FullName -Destination ('{0}\{1}' -f $tempDir, $tempName)
  915.  
  916.     }
  917. }
  918.  
  919. $animatePID | Animate-Dot
  920.  
  921. # Removing duplicate files
  922. if ($removeDuplicates) {
  923.  
  924.     Write-Host (' Removing duplicate files').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  925.     $Start = (Get-Date)
  926.     $animatePID = Animate-Dot
  927.    
  928.     Get-ChildItem -LiteralPath $dirOutput -File -Recurse | ForEach-Object {
  929.  
  930.         if (!$dupTable.Contains(($hash = (Get-FileHash -LiteralPath $_.FullName -Algorithm MD5).Hash))) {
  931.        
  932.             $dupTable.Add($hash, $_.FullName)
  933.        
  934.         } else {
  935.        
  936.             if ($_.Directory.Name -cmatch '[A-Z]' -and ((Get-Item -LiteralPath $dupTable.$hash).Directory.Name) -cnotmatch '[A-Z]') {
  937.            
  938.                 Remove-Item -LiteralPath $dupTable.$hash
  939.                 $dupTable.Remove($hash)
  940.                 $dupTable.Add($hash, $_.FullName)
  941.            
  942.             } else {
  943.            
  944.                 Remove-Item -LiteralPath $_.FullName
  945.            
  946.             }
  947.         }
  948.     }
  949.    
  950.     $animatePID | Animate-Dot
  951.    
  952. }
  953.  
  954. # <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> #
  955. ####################################################################################################
  956.  
  957. ####################################################################################################
  958. # <><><><><><><><><><><><><><><><><><><><><>< CONVERSION ><><><><><><><><><><><><><><><><><><><><> #
  959.  
  960. # Converting .Wwise files
  961. Write-Host (" Converting '.Wwise' files").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  962. $Start = (Get-Date)
  963. $animatePID = Animate-Dot
  964.  
  965. Get-ChildItem -LiteralPath $dirOutput -File -Recurse -Filter *.Wwise | ForEach-Object {
  966.  
  967.     if (!((.\resources\applications\ww2ogg.exe $_.FullName --pcb .\resources\applications\packed_codebooks_aoTuV_603.bin) -match 'Parse error')) {
  968.    
  969.         .\resources\applications\revorb.exe $_.FullName.Replace('.Wwise','.ogg')
  970.  
  971.     }
  972. }
  973.  
  974. $animatePID | Animate-Dot
  975.  
  976. <# Don't know how to convert .wav_unknown files (previously .lwav), 'wwise_ima_adpcm.exe' only produces nonsense #>
  977.  
  978. # Converting .at3 files
  979. Write-Host (" Converting '.at3' files").ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  980. $Start = (Get-Date)
  981. $animatePID = Animate-Dot
  982.  
  983. (Start-Process .\resources\applications\quickbms.exe -ArgumentList ('-F *.at3 -K -D -Y -. -Q -R .\resources\scripts\wwise_pcm_decoder.bms "{0}" "{0}"' -f $dirOutput) -WindowStyle Hidden -PassThru).Id | Stop-ChildOnExit
  984.  
  985. $animatePID | Animate-Dot
  986.  
  987. # <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> #
  988. ####################################################################################################
  989.  
  990. ####################################################################################################
  991. # <><><><><><><><><><><><><><><><><><><>< REMOVING  SOURCE ><><><><><><><><><><><><><><><><><><><> #
  992.  
  993. # Removing extracted source files
  994. if ($removeSource) {
  995.  
  996.     Write-Host (' Removing extracted source files').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  997.     $Start = (Get-Date)
  998.     $animatePID = Animate-Dot
  999.  
  1000.     Get-ChildItem -LiteralPath $dirOutput -File -Recurse | Where-Object {('.00040000', '.01020000', '.bnk', '.wav_unknown', '.Wwise', '.at3').Contains($_.Extension)} | ForEach-Object {
  1001.    
  1002.         Remove-Item -LiteralPath $_.FullName
  1003.    
  1004.     }
  1005.    
  1006.     $animatePID | Animate-Dot
  1007.  
  1008. }
  1009.  
  1010. # Removing empty directories
  1011. if ($removeEmptyDir) {
  1012.  
  1013.     Write-Host (' Removing empty directories').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru -NoNewline} else {$_}}) -NoNewline
  1014.     $Start = (Get-Date)
  1015.     $animatePID = Animate-Dot
  1016.  
  1017.     Get-ChildItem -LiteralPath $dirOutput -Directory -Recurse | Where-Object {(Get-ChildItem -LiteralPath $_.FullName -File -Recurse | Select-Object -First 1).Count -eq 0} | ForEach-Object {
  1018.    
  1019.         Remove-Item -LiteralPath $_.FullName -Recurse
  1020.    
  1021.     }
  1022.    
  1023.     $animatePID | Animate-Dot
  1024.  
  1025. }
  1026.  
  1027. # Finishing
  1028. Write-Host ("`n Overall duration: {0:h\:mm\:ss}`n" -f ((Get-Date) - $OverallStart)).ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  1029. Write-Host -ForegroundColor Green (' Done!').ForEach({if ($createLog) {$_ | Add-Content -LiteralPath $env:TEMP\tc_r6s_audio_extractor_log.txt -PassThru} else {$_}})
  1030. Read-Host
  1031.  
  1032. # <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> #
  1033. ###################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement