upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNotRexed <therealnothingfn@gmail.com>2026-11-20 15:22:16 -0500
committerNotRexed <therealnothingfn@gmail.com>2026-11-20 15:22:16 -0500
commitdb0dc8bd5ebce6e2bc27d47085f7f104eb3037d3 (patch)
tree4fb3edca45f8b4dd3368c6ac2a0e4fdc8ed7065c /scripts
Initial commit: Leonida, build-it-yourself PC port groundwork
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V), asset export via rpf9-explorer's Core (submodule), PE loader and shim skeleton, and make_game.py, which builds from the user's own copy of the game. No game data, keys or executables are included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/build_runtime.ps146
-rw-r--r--scripts/carve_all.ps120
-rw-r--r--scripts/first_look.ps141
-rw-r--r--scripts/meta_to_xml.ps152
4 files changed, 159 insertions, 0 deletions
diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1
new file mode 100644
index 000000000..ffca056fd
--- /dev/null
+++ b/scripts/build_runtime.ps1
@@ -0,0 +1,46 @@
1# Builds runtime\build\gta6rt.exe with MSVC at BelowNormal priority, on half the cores.
2# Uses VS's CMake + Ninja when the "C++ CMake tools" component is installed, otherwise calls cl.exe directly.
3param([switch]$Debug)
4$ErrorActionPreference = "Stop"
5
6$root = Split-Path $PSScriptRoot -Parent
7$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
8$vs = & "$installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
9if (-not $vs) { throw "Visual Studio with the C++ x64 tools wasn't found." }
10$vcvars = Join-Path $vs "VC\Auxiliary\Build\vcvars64.bat"
11$jobs = [Math]::Max(1, [int]([Environment]::ProcessorCount / 2))
12
13$src = Join-Path $root "runtime"
14$out = Join-Path $src "build"
15New-Item -ItemType Directory -Force $out | Out-Null
16
17$cmakeDir = Join-Path $vs "Common7\IDE\CommonExtensions\Microsoft\CMake"
18$cmake = Join-Path $cmakeDir "CMake\bin\cmake.exe"
19$ninja = Join-Path $cmakeDir "Ninja\ninja.exe"
20$cfg = if ($Debug) { "Debug" } else { "RelWithDebInfo" }
21
22if ((Test-Path $cmake) -and (Test-Path $ninja)) {
23 $body = @"
24"$cmake" -S "$src" -B "$out" -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" -DCMAKE_BUILD_TYPE=$cfg || exit /b 1
25"$cmake" --build "$out" -j $jobs || exit /b 1
26"@
27} else {
28 # Keep this list in step with runtime\CMakeLists.txt.
29 $files = "src\main.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\xmem.cpp", "shims\d3d12_xs.cpp" | ForEach-Object { "`"$src\$_`"" }
30 $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" }
31 $body = @"
32cd /d "$out" || exit /b 1
33cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /Zi $opt /MP$jobs /DWIN32_LEAN_AND_MEAN /DNOMINMAX /DUNICODE /D_UNICODE $($files -join ' ') /Fe:gta6rt.exe /link /OPT:NOREF psapi.lib || exit /b 1
34"@
35}
36
37# A .cmd file avoids cmd.exe's quote stripping on paths with spaces.
38$bat = Join-Path $out "_build.cmd"
39"@echo off`r`nset `"PATH=$installer;%PATH%`"`r`ncall `"$vcvars`" >nul || exit /b 1`r`n$body" | Set-Content -Encoding ascii $bat
40
41$p = Start-Process cmd.exe -ArgumentList "/c", "`"$bat`"" -NoNewWindow -PassThru
42$null = $p.Handle # keeps the exit code readable after WaitForExit
43try { $p.PriorityClass = "BelowNormal" } catch {}
44$p.WaitForExit()
45if ($p.ExitCode -ne 0) { throw "build failed ($($p.ExitCode))" }
46Write-Host "built $out\gta6rt.exe"
diff --git a/scripts/carve_all.ps1 b/scripts/carve_all.ps1
new file mode 100644
index 000000000..c70aab30a
--- /dev/null
+++ b/scripts/carve_all.ps1
@@ -0,0 +1,20 @@
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
3param([Parameter(Mandatory)][string]$Game, [Parameter(Mandatory)][string]$Out)
4$root = Split-Path $PSScriptRoot -Parent
5$tool = Join-Path $root "tools\rpf9_carve.py"
6$rows = @()
7foreach ($f in Get-ChildItem $Game -Recurse -Filter *.rpf | Sort-Object Length) {
8 $rel = $f.FullName.Substring($Game.Length + 1)
9 $dest = Join-Path $Out ([IO.Path]::GetFileNameWithoutExtension(($rel -replace "[\\/]", "_")))
10 if (-not (Test-Path (Join-Path $dest "index.json"))) {
11 Write-Host ("{0:HH:mm:ss} carving {1} ({2:N1} GiB)" -f (Get-Date), $rel, ($f.Length / 1GB))
12 python -I $tool $f.FullName $dest | Select-Object -Last 1
13 }
14 $s = (Get-Content (Join-Path $dest "index.json") -Raw | ConvertFrom-Json).summary
15 $rows += [pscustomobject]@{ archive = $rel; files = $s.files; bink2 = $s.bink2_files; span = $s.span
16 readable = [math]::Round(($s.compressed_bytes) / $s.span, 4)
17 unread = [math]::Round($s.unread_bytes / $s.span, 4); inflated = $s.inflated_bytes }
18}
19$rows | ConvertTo-Json | Set-Content -Encoding utf8 (Join-Path $Out "coverage.json")
20$rows | Format-Table archive, files, bink2, @{n = "GiB"; e = { [math]::Round($_.span / 1GB, 2) } }, readable, unread -AutoSize | Out-String -Width 200
diff --git a/scripts/first_look.ps1 b/scripts/first_look.ps1
new file mode 100644
index 000000000..913b0a9c3
--- /dev/null
+++ b/scripts/first_look.ps1
@@ -0,0 +1,41 @@
1# Day-one report for the game executable: PE inspection, encryption check, import surface and a loader dry run.
2# Reads the exe only; no game code runs.
3param(
4 [Parameter(Mandatory)][string]$Exe,
5 [string]$GameDir = (Split-Path $Exe -Parent)
6)
7$ErrorActionPreference = "Stop"
8$root = Split-Path $PSScriptRoot -Parent
9$name = [IO.Path]::GetFileNameWithoutExtension($Exe)
10$out = Join-Path $root "reports\exe\$name"
11New-Item -ItemType Directory -Force $out | Out-Null
12
13if (-not (Test-Path $Exe)) { throw "$Exe not found" }
14$fs = [IO.File]::OpenRead($Exe); $mz = New-Object byte[] 2; [void]$fs.Read($mz, 0, 2); $fs.Close()
15if ([Text.Encoding]::ASCII.GetString($mz) -ne "MZ") {
16 throw "$Exe doesn't start with an MZ header. It's still packaged or encrypted, so there's nothing to inspect."
17}
18
19$size = (Get-Item $Exe).Length
20$hash = (Get-FileHash $Exe -Algorithm SHA256).Hash.ToLower()
21"sha256 $hash size $size" | Tee-Object (Join-Path $out "hash.txt")
22
23Write-Host "`n== PE inspection"
24python -I (Join-Path $root "tools\pe_inspect.py") $Exe --game-dir $GameDir --out $out
25if ($LASTEXITCODE -ne 0) { throw "pe_inspect failed" }
26
27$rt = Join-Path $root "runtime\build\gta6rt.exe"
28if (-not (Test-Path $rt)) { & (Join-Path $PSScriptRoot "build_runtime.ps1") }
29Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)"
30& $rt --dry-run $Exe --game-dir $GameDir 2>&1 | Tee-Object (Join-Path $out "dryrun.txt") | Select-Object -Last 40
31
32# Shim to-do list, grouped by DLL, most functions first.
33$report = Get-Content (Join-Path $out "$name.json") -Raw | ConvertFrom-Json
34$todo = $report.imports | Where-Object { $_.where -eq "shim" } | Sort-Object { -$_.functions.Count }
35$lines = foreach ($t in $todo) { "{0,-40} {1,5}" -f $t.dll, $t.functions.Count }
36$lines | Set-Content (Join-Path $out "shim-todo.txt")
37Write-Host "`n== Shim to-do (DLL, function count)"
38$lines
39$enc = $report.sections | Where-Object { $_.looks_encrypted } | ForEach-Object { $_.name }
40if ($enc) { Write-Warning "High-entropy sections (still encrypted or packed): $($enc -join ', ')" }
41Write-Host "`nReports: $out"
diff --git a/scripts/meta_to_xml.ps1 b/scripts/meta_to_xml.ps1
new file mode 100644
index 000000000..cdef1be86
--- /dev/null
+++ b/scripts/meta_to_xml.ps1
@@ -0,0 +1,52 @@
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 G:\gta6-work\carve -Out G:\gta6-work\meta [-Limit N]
4# Each blob becomes <Out>\<archive>\<offset>.xml. Failures go to <Out>\failures.txt with the parser's message.
5param(
6 [string]$Carve = "G:\gta6-work\carve",
7 [string]$Out = "G:\gta6-work\meta",
8 [string]$CodeWalker = "G:\ref\codewalker-gen9",
9 [int]$Limit = 0
10)
11$ErrorActionPreference = "Stop"
12try { (Get-Process -Id $PID).PriorityClass = "BelowNormal" } catch {}
13Add-Type -Path "$CodeWalker\SharpDX.dll"; Add-Type -Path "$CodeWalker\SharpDX.Mathematics.dll"
14[void][Reflection.Assembly]::LoadFrom("$CodeWalker\CodeWalker.Core.dll")
15New-Item -ItemType Directory -Force $Out | Out-Null
16$fail = Join-Path $Out "failures.txt"
17"" | Set-Content $fail
18$ok = @{ pso = 0; rbf = 0 }; $bad = @{ pso = 0; rbf = 0 }; $n = 0
19
20foreach ($dir in Get-ChildItem $Carve -Directory) {
21 $idx = Join-Path $dir.FullName "index.json"
22 if (-not (Test-Path $idx)) { continue }
23 $files = (Get-Content $idx -Raw | ConvertFrom-Json).files |
24 Where-Object { $_.head.StartsWith("5053494e") -or $_.head.StartsWith("52424630") }
25 if (-not $files) { continue }
26 $dest = Join-Path $Out $dir.Name
27 New-Item -ItemType Directory -Force $dest | Out-Null
28 foreach ($r in $files) {
29 if ($Limit -and $n -ge $Limit) { break }
30 $n++
31 $name = "{0:x12}" -f [int64]$r.off
32 $bytes = [IO.File]::ReadAllBytes((Join-Path $dir.FullName "$name.bin"))
33 $kind = if ($r.head.StartsWith("5053494e")) { "pso" } else { "rbf" }
34 try {
35 if ($kind -eq "pso") {
36 $f = New-Object CodeWalker.GameFiles.PsoFile; $f.Load($bytes)
37 $xml = [CodeWalker.GameFiles.PsoXml]::GetXml($f)
38 } else {
39 $f = New-Object CodeWalker.GameFiles.RbfFile; $f.Load($bytes)
40 $xml = [CodeWalker.GameFiles.RbfXml]::GetXml($f)
41 }
42 [IO.File]::WriteAllText((Join-Path $dest "$name.$kind.xml"), $xml)
43 $ok[$kind]++
44 } catch {
45 $bad[$kind]++
46 $msg = $_.Exception.InnerException; if (-not $msg) { $msg = $_.Exception }
47 "$($dir.Name)\$name $kind : $($msg.Message)" | Add-Content $fail
48 }
49 }
50 if ($Limit -and $n -ge $Limit) { break }
51}
52"pso ok $($ok.pso) failed $($bad.pso); rbf ok $($ok.rbf) failed $($bad.rbf) -> $Out"