diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-30 04:00:53 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-30 04:00:53 -0500 |
| commit | 45df09b8432a2891ca71d6c6143ed62707d9fc7a (patch) | |
| tree | 6e1546fcc269e90dbdb21e62aa481d2101872e46 /scripts | |
| parent | dcba958e52efe681343fc25bbb9706b40420e222 (diff) | |
chore: remove 13 dead one-off scripts, fix /home/nolan test paths, drop unused imports (CHORE-TIER2A-PYTHON-CLEANUP)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/bench_translate.py | 1 | ||||
| -rw-r--r-- | scripts/bench_wave64.py | 1 | ||||
| -rw-r--r-- | scripts/carve_all.ps1 | 81 | ||||
| -rw-r--r-- | scripts/meta_to_xml.ps1 | 69 |
4 files changed, 0 insertions, 152 deletions
diff --git a/scripts/bench_translate.py b/scripts/bench_translate.py index 6c60b3493..5e9ce4f94 100644 --- a/scripts/bench_translate.py +++ b/scripts/bench_translate.py | |||
| @@ -24,7 +24,6 @@ them with a run of the same commit, not with the table in the pull request that | |||
| 24 | import argparse | 24 | import argparse |
| 25 | import json | 25 | import json |
| 26 | import os | 26 | import os |
| 27 | import statistics | ||
| 28 | import struct | 27 | import struct |
| 29 | import subprocess | 28 | import subprocess |
| 30 | import sys | 29 | import sys |
diff --git a/scripts/bench_wave64.py b/scripts/bench_wave64.py index 3a566ebfd..3872c7b37 100644 --- a/scripts/bench_wave64.py +++ b/scripts/bench_wave64.py | |||
| @@ -15,7 +15,6 @@ native 64-wide subgroup, such as Apple Silicon. Every process must complete the | |||
| 15 | output hash; there is deliberately no claim that the hash was compared with a native Wave64 device. | 15 | output hash; there is deliberately no claim that the hash was compared with a native Wave64 device. |
| 16 | """ | 16 | """ |
| 17 | import argparse | 17 | import argparse |
| 18 | import json | ||
| 19 | import os | 18 | import os |
| 20 | import re | 19 | import re |
| 21 | import statistics | 20 | import statistics |
diff --git a/scripts/carve_all.ps1 b/scripts/carve_all.ps1 deleted file mode 100644 index 9442f5e08..000000000 --- a/scripts/carve_all.ps1 +++ /dev/null | |||
| @@ -1,81 +0,0 @@ | |||
| 1 | # Carves every .rpf in the game folder into <Out>\<archive path with _>, smallest first (research tool; the | ||
| 2 | # build itself doesn't need it). Skips archives that already have an index.json. Summary: <Out>\coverage.json | ||
| 3 | param([Parameter(Mandatory)][string]$Game, [Parameter(Mandatory)][string]$Out) | ||
| 4 | $root = Split-Path $PSScriptRoot -Parent | ||
| 5 | $tool = Join-Path $root "tools\rpf9_carve.py" | ||
| 6 | if (-not (Test-Path -LiteralPath $Game -PathType Container)) { | ||
| 7 | throw "Game folder '$Game' does not exist or is not a directory." | ||
| 8 | } | ||
| 9 | $outFull = [IO.Path]::GetFullPath($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Out)) | ||
| 10 | if (Test-Path -LiteralPath $outFull -PathType Leaf) { | ||
| 11 | throw "Output path '$Out' is a file, not a directory." | ||
| 12 | } | ||
| 13 | [System.IO.Directory]::CreateDirectory($outFull) | Out-Null | ||
| 14 | # -Game may be relative or end in a separator; archive names are cut from a separator-ended prefix. | ||
| 15 | $Game = (Resolve-Path -LiteralPath $Game).ProviderPath | ||
| 16 | # Resolve-Path preserves 8.3 short components (e.g. RUNNER~1), while Get-ChildItem emits canonical | ||
| 17 | # FullName paths. Deriving the prefix from Resolve-Path then cuts the wrong number of characters and | ||
| 18 | # re-carves already-caved archives; use the canonical form for both sides of the Substring. | ||
| 19 | $prefix = (Get-Item -LiteralPath $Game).FullName.TrimEnd('\') + '\' | ||
| 20 | $destinations = [System.Collections.Generic.Dictionary[string, string]]::new([StringComparer]::OrdinalIgnoreCase) | ||
| 21 | # Validate every destination before accepting any cached index or starting a carve. | ||
| 22 | $archives = foreach ($f in Get-ChildItem -LiteralPath $Game -Recurse -File -Filter *.rpf | Sort-Object Length) { | ||
| 23 | $rel = $f.FullName.Substring($prefix.Length) | ||
| 24 | $name = [IO.Path]::GetFileNameWithoutExtension(($rel -replace "[\\/]", "_")) | ||
| 25 | if ($destinations.ContainsKey($name)) { | ||
| 26 | throw ("Archives '{0}' and '{1}' both map to '{2}'." -f $destinations[$name], $rel, $name) | ||
| 27 | } | ||
| 28 | $destinations.Add($name, $rel) | ||
| 29 | [pscustomobject]@{ file = $f; relative = $rel; destination = Join-Path $outFull $name } | ||
| 30 | } | ||
| 31 | |||
| 32 | $rows = @() | ||
| 33 | foreach ($archive in $archives) { | ||
| 34 | $f = $archive.file | ||
| 35 | $rel = $archive.relative | ||
| 36 | $dest = $archive.destination | ||
| 37 | $index = Join-Path $dest "index.json" | ||
| 38 | if (-not (Test-Path -LiteralPath $index)) { | ||
| 39 | Write-Host ("{0:HH:mm:ss} carving {1} ({2:N1} GiB)" -f (Get-Date), $rel, ($f.Length / 1GB)) | ||
| 40 | python -I $tool $f.FullName $dest | Select-Object -Last 1 | ||
| 41 | if ($LASTEXITCODE -ne 0) { throw "Carving $rel failed (exit $LASTEXITCODE)" } | ||
| 42 | } | ||
| 43 | try { | ||
| 44 | $s = (Get-Content -LiteralPath $index -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop).summary | ||
| 45 | foreach ($field in 'files', 'bink2_files', 'span', 'compressed_bytes', 'unread_bytes', 'inflated_bytes') { | ||
| 46 | $value = $s.$field | ||
| 47 | if ((($value -isnot [int]) -and ($value -isnot [long])) -or $value -lt 0) { | ||
| 48 | throw "summary.$field must be a non-negative integer." | ||
| 49 | } | ||
| 50 | } | ||
| 51 | if ($s.span -eq 0 -and ($s.compressed_bytes -ne 0 -or $s.unread_bytes -ne 0)) { | ||
| 52 | throw 'A zero summary.span requires zero compressed and unread bytes.' | ||
| 53 | } | ||
| 54 | # Stored streams and unread gaps occupy disjoint parts of the span. Subtract instead of | ||
| 55 | # adding the counters so a total just above Int64.MaxValue cannot lose precision. | ||
| 56 | if ($s.compressed_bytes -gt $s.span -or $s.unread_bytes -gt ($s.span - $s.compressed_bytes)) { | ||
| 57 | throw 'summary.compressed_bytes and summary.unread_bytes must fit within summary.span.' | ||
| 58 | } | ||
| 59 | if ($s.bink2_files -gt $s.files) { | ||
| 60 | throw 'summary.bink2_files must not exceed summary.files.' | ||
| 61 | } | ||
| 62 | } catch { | ||
| 63 | throw "Invalid carve index '$index': $($_.Exception.Message)" | ||
| 64 | } | ||
| 65 | $denominator = [math]::Max(1L, $s.span) | ||
| 66 | $rows += [pscustomobject]@{ archive = $rel; files = $s.files; bink2 = $s.bink2_files; span = $s.span | ||
| 67 | readable = [math]::Round($s.compressed_bytes / $denominator, 4) | ||
| 68 | unread = [math]::Round($s.unread_bytes / $denominator, 4); inflated = $s.inflated_bytes } | ||
| 69 | } | ||
| 70 | $coverageJson = if ($rows.Count -eq 0) { "[]" } else { $rows | ConvertTo-Json } | ||
| 71 | $coveragePath = Join-Path $outFull "coverage.json" | ||
| 72 | $tmpCoverage = Join-Path $outFull (".coverage.{0}.{1}.tmp" -f $PID, [guid]::NewGuid().ToString("N")) | ||
| 73 | try { | ||
| 74 | [System.IO.File]::WriteAllText($tmpCoverage, $coverageJson + "`n", [System.Text.UTF8Encoding]::new($false)) | ||
| 75 | Move-Item -LiteralPath $tmpCoverage -Destination $coveragePath -Force | ||
| 76 | } finally { | ||
| 77 | if (Test-Path -LiteralPath $tmpCoverage) { Remove-Item -LiteralPath $tmpCoverage -Force -ErrorAction SilentlyContinue } | ||
| 78 | } | ||
| 79 | if ($rows.Count -gt 0) { | ||
| 80 | $rows | Format-Table archive, files, bink2, @{n = "GiB"; e = { [math]::Round($_.span / 1GB, 2) } }, readable, unread -AutoSize | Out-String -Width 200 | ||
| 81 | } | ||
diff --git a/scripts/meta_to_xml.ps1 b/scripts/meta_to_xml.ps1 deleted file mode 100644 index 38a00837d..000000000 --- a/scripts/meta_to_xml.ps1 +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | # Converts carved PSO ('PSIN') and RBF ('RBF0') metadata blobs to XML with CodeWalker.Core's parsers. | ||
| 2 | # Run in Windows PowerShell 5.1. | ||
| 3 | # .\meta_to_xml.ps1 -Carve <work>\carve -Out <work>\meta [-Limit N] | ||
| 4 | # Each blob becomes <Out>\<archive>\<offset>.xml. Failures go to <Out>\failures.txt (UTF-8 with BOM) with the error message. | ||
| 5 | param( | ||
| 6 | [string]$Carve = "<work>\carve", | ||
| 7 | [string]$Out = "<work>\meta", | ||
| 8 | [string]$CodeWalker = "<ref>\codewalker-gen9", | ||
| 9 | [int]$Limit = 0 | ||
| 10 | ) | ||
| 11 | $ErrorActionPreference = "Stop" | ||
| 12 | if ($Limit -lt 0) { | ||
| 13 | throw "-Limit must be 0 or greater." | ||
| 14 | } | ||
| 15 | try { (Get-Process -Id $PID).PriorityClass = "BelowNormal" } catch {} | ||
| 16 | Add-Type -Path "$CodeWalker\SharpDX.dll"; Add-Type -Path "$CodeWalker\SharpDX.Mathematics.dll" | ||
| 17 | [void][Reflection.Assembly]::LoadFrom("$CodeWalker\CodeWalker.Core.dll") | ||
| 18 | New-Item -ItemType Directory -Force $Out | Out-Null | ||
| 19 | $fail = Join-Path $Out "failures.txt" | ||
| 20 | "" | Set-Content -LiteralPath $fail -Encoding utf8 | ||
| 21 | $ok = @{ pso = 0; rbf = 0 }; $bad = @{ pso = 0; rbf = 0 }; $n = 0 | ||
| 22 | |||
| 23 | foreach ($dir in Get-ChildItem -LiteralPath $Carve -Directory) { | ||
| 24 | $idx = Join-Path $dir.FullName "index.json" | ||
| 25 | if (-not (Test-Path -LiteralPath $idx)) { continue } | ||
| 26 | $files = (Get-Content -LiteralPath $idx -Raw | ConvertFrom-Json).files | | ||
| 27 | Where-Object { | ||
| 28 | $_.head -is [string] -and ( | ||
| 29 | $_.head.StartsWith("5053494e", [StringComparison]::OrdinalIgnoreCase) -or | ||
| 30 | $_.head.StartsWith("52424630", [StringComparison]::OrdinalIgnoreCase) | ||
| 31 | ) | ||
| 32 | } | ||
| 33 | if (-not $files) { continue } | ||
| 34 | $dest = Join-Path $Out $dir.Name | ||
| 35 | New-Item -ItemType Directory -Force $dest | Out-Null | ||
| 36 | foreach ($r in $files) { | ||
| 37 | if ($Limit -and $n -ge $Limit) { break } | ||
| 38 | $n++ | ||
| 39 | $name = "{0:x12}" -f [int64]$r.off | ||
| 40 | $kind = if ($r.head.StartsWith("5053494e", [StringComparison]::OrdinalIgnoreCase)) { "pso" } else { "rbf" } | ||
| 41 | try { | ||
| 42 | $bytes = [IO.File]::ReadAllBytes((Join-Path $dir.FullName "$name.bin")) | ||
| 43 | if ($kind -eq "pso") { | ||
| 44 | $f = New-Object CodeWalker.GameFiles.PsoFile; $f.Load($bytes) | ||
| 45 | $xml = [CodeWalker.GameFiles.PsoXml]::GetXml($f) | ||
| 46 | } else { | ||
| 47 | $f = New-Object CodeWalker.GameFiles.RbfFile; $f.Load($bytes) | ||
| 48 | $xml = [CodeWalker.GameFiles.RbfXml]::GetXml($f) | ||
| 49 | } | ||
| 50 | $xmlPath = Join-Path $dest "$name.$kind.xml" | ||
| 51 | $tmpXml = "$xmlPath.$PID.tmp" | ||
| 52 | try { | ||
| 53 | [IO.File]::WriteAllText($tmpXml, $xml) | ||
| 54 | Move-Item -LiteralPath $tmpXml -Destination $xmlPath -Force | ||
| 55 | } finally { | ||
| 56 | if (Test-Path -LiteralPath $tmpXml) { | ||
| 57 | Remove-Item -LiteralPath $tmpXml -Force -ErrorAction SilentlyContinue | ||
| 58 | } | ||
| 59 | } | ||
| 60 | $ok[$kind]++ | ||
| 61 | } catch { | ||
| 62 | $bad[$kind]++ | ||
| 63 | $msg = $_.Exception.InnerException; if (-not $msg) { $msg = $_.Exception } | ||
| 64 | "$($dir.Name)\$name $kind : $($msg.Message)" | Add-Content -LiteralPath $fail -Encoding utf8 | ||
| 65 | } | ||
| 66 | } | ||
| 67 | if ($Limit -and $n -ge $Limit) { break } | ||
| 68 | } | ||
| 69 | "pso ok $($ok.pso) failed $($bad.pso); rbf ok $($ok.rbf) failed $($bad.rbf) -> $Out" | ||