Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions STATUS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development log

## Current state (8 November 2026, v0.3.0)
## Current state (18 November 2026, v0.4.0)

- **Mac**: playable from `~/Applications/Portal 2 Natif.app`. Metal
(Direct3D 9 bridge to mtld3d) is the default renderer when `libd3d9metal` is
Expand All @@ -13,8 +13,23 @@
- **Half-Life 2** (experimental): built from the same checkout into
`build/hl2`, Metal by default, 120 fps on Mac, 60 fps on an iPhone 15 Pro Max
in a short test ([docs/hl2.md](docs/hl2.md)).
- **Portal** (experimental, contributed in #31): built into `build/portal1`
from the current Linux binaries (depot 404); the first chambers have been
played on a Mac ([docs/portal1.md](docs/portal1.md)). The `save` crash of
#44 is fixed in the lifter and checked in Half-Life 2, which shares that
code; not confirmed in Portal yet.
- **Portal 2 Puzzle Maker** (#42): Build and Play works on Mac. VBSP, VVIS
and VRAD are recompiled too and run natively; they are opt-in
(`./setup.sh --puzzle-maker` or the installer's box,
[docs/puzzlemaker.md](docs/puzzlemaker.md)).
- **Generated code**: the lifter proves that Portal 2 never reads x86 flags
across calls and stops saving them around every call (binary 17 % smaller);
Half-Life 2 does not pass the proof and keeps the previous mode.
- **Native plugins**: a server plugin built as a macOS arm64 dylib loads
where the game expects a Linux `.so`
([docs/native-plugins.md](docs/native-plugins.md)).
- **Install**: the Natif Installer app or `./setup.sh` (and `--ios`), for
one game or both ([README](README.md#install-on-mac)).
one game or all ([README](README.md#install-on-mac)).

The rest of this file is the measurements, the performance analysis and a
dated history, newest first. Run and diagnostics instructions are in
Expand Down Expand Up @@ -229,6 +244,14 @@ forcing buffer usage, `gl_bufmode`, an order file of hot functions

## History

- **18 Nov. 2026** (v0.4.0): Puzzle Maker export and native map compilers
(#42, opt-in since #48), SIGCHLD delivery hardened (#47), PIC switches
that jump through a copy of the GOT register recognised by the lifter
(#45, fixes #44).
- **9–17 Nov.**: Portal added (#31); ABI flags mode of the lifter (#33);
native plugins (#32); a message instead of a crash without Steam (#39);
Mac key repeat and raw mouse input (#40); Workshop crash in Half-Life 2
(#37); linker paths with spaces (#43).
- **8 Nov. 2026**: audit and cleanup: merged worktrees removed, `runtime/`,
`tests/` and `tools/` factored, documentation pruned; HL2 iPhone first run.
- **7–8 Nov.**: HL2 performance work above (event queries reached at Present,
Expand Down
3 changes: 2 additions & 1 deletion docs/puzzlemaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ python3 tools/build_puzzlemaker.py
python3 tools/make_app.py --game portal2
```

`./setup.sh --puzzle-maker` does the same. The compilers are opt-in because
`./setup.sh --puzzle-maker` does the same, and so does the Puzzle Maker box
under Portal 2 in the installer app. The compilers are opt-in because
they add about ten minutes to the build and 220 MB to the app; without the
option the editor opens, but Build and Play cannot compile the chamber. The
game still installs if the Linux depot has no `vbsp_linux` or the compilers
Expand Down
61 changes: 49 additions & 12 deletions installer/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Game: Identifiable, Equatable {
let installFolder: String // under steamapps/common
let linuxFiles: [String] // files of the Linux depot (setup.sh's checks)
let minutes: Int
var mapCompiler: String? = nil // Linux depot file of the Puzzle Maker's map compilers (setup.sh --puzzle-maker)

var appName: String { "\(title) Natif" }
var installedApp: URL { home.appendingPathComponent("Applications/\(appName).app") }
Expand All @@ -56,6 +57,10 @@ struct Game: Identifiable, Equatable {
func isLinuxDepot(_ url: URL) -> Bool {
linuxFiles.allSatisfy { FileManager.default.fileExists(atPath: url.appendingPathComponent($0).path) }
}
func hasMapCompiler(_ linux: URL?) -> Bool {
guard let mapCompiler, let linux else { return false }
return FileManager.default.fileExists(atPath: linux.appendingPathComponent(mapCompiler).path)
}
func findGame() -> URL? {
let installed = steamSupport.appendingPathComponent("steamapps/common/\(installFolder)")
let candidates = [installed, findDepot(appID, dataDepot)].compactMap { $0 }.filter(isGameFolder)
Expand All @@ -67,10 +72,13 @@ struct Game: Identifiable, Equatable {
}
}

let mapCompilerMinutes = 10

let allGames = [
Game(id: "portal2", title: "Portal 2", appID: 620, dataDepot: 621, linuxDepot: 661, linuxSize: "about 90 MB",
marker: "portal2", markerFile: "portal2/pak01_dir.vpk", installFolder: "Portal 2",
linuxFiles: ["bin/linux32/engine.so", "portal2/bin/linux32/server.so"], minutes: 10),
linuxFiles: ["bin/linux32/engine.so", "portal2/bin/linux32/server.so"], minutes: 10,
mapCompiler: "bin/linux32/vbsp_linux"),
Game(id: "hl2", title: "Half-Life 2", appID: 220, dataDepot: 221, linuxDepot: 224, linuxSize: "about 320 MB",
marker: "hl2_complete", markerFile: "hl2_complete/gameinfo.txt", installFolder: "Half-Life 2",
linuxFiles: ["hl2_linux", "bin/engine.so", "hl2_complete/bin/server.so"], minutes: 20),
Expand Down Expand Up @@ -144,15 +152,21 @@ final class Installer: ObservableObject {
@Published var log: [String] = []
@Published var warnings: [String] = []
@Published var showLog = false
@Published var puzzleMaker = false // the user's wish; buildsMapCompilers says whether it applies
private var process: Process?
private var timer: Timer?
private var queue: [Game] = [] // games still to build in this run
private var runCount = 1, runIndex = 0
private var runHasMapCompilers = false // the current setup.sh run also builds them

func state(_ game: Game) -> GameState { states[game.id] ?? GameState() }
var chosen: [Game] { allGames.filter { state($0).selected && state($0).ready } }
var canInstall: Bool { tools && !chosen.isEmpty && phase != .installing }
var built: [Game] { allGames.filter { state($0).built } }
func buildsMapCompilers(_ game: Game) -> Bool {
puzzleMaker && state(game).selected && game.hasMapCompiler(state(game).linux)
}
var minutes: Int { chosen.map { $0.minutes + (buildsMapCompilers($0) ? mapCompilerMinutes : 0) }.reduce(0, +) }

func setSelected(_ game: Game, _ on: Bool) {
states[game.id]?.selected = on
Expand Down Expand Up @@ -251,7 +265,9 @@ final class Installer: ObservableObject {
private func runSetup(game: Game, gameDir: URL, linux: URL) {
let p = Process()
p.executableURL = URL(fileURLWithPath: "/bin/bash")
p.arguments = [sourceDir.appendingPathComponent("setup.sh").path, "--game", game.id, gameDir.path, linux.path]
runHasMapCompilers = buildsMapCompilers(game)
p.arguments = [sourceDir.appendingPathComponent("setup.sh").path, "--game", game.id]
+ (runHasMapCompilers ? ["--puzzle-maker"] : []) + [gameDir.path, linux.path]
p.currentDirectoryURL = sourceDir
var env = ProcessInfo.processInfo.environment
// A Finder app gets a bare PATH: add Rust's and Homebrew's, used when present.
Expand Down Expand Up @@ -299,20 +315,26 @@ final class Installer: ObservableObject {
}

/// Progress from setup.sh's output: its steps, then build_game.py's
/// "lifted a/b jobs" (10-35 %) and "compiled a/b files" (35-95 %).
static func progress(after line: String, from current: Double) -> Double {
/// "lifted a/b jobs" (10-35 %) and "compiled a/b files" (35-95 %). With the
/// map compilers, a second build follows the game's: the game then fills
/// 10-55 % and the compilers 55-95 %, each split the same way.
static func progress(after line: String, from current: Double, mapCompilers: Bool = false) -> Double {
func fraction(_ prefix: String) -> Double? {
guard let r = line.range(of: prefix) else { return nil }
let parts = line[r.upperBound...].prefix { $0 != " " && $0 != "," }.split(separator: "/")
guard parts.count == 2, let a = Double(parts[0]), let b = Double(parts[1]), b > 0 else { return nil }
return min(a / b, 1)
}
let first = 0.10, last = 0.95, middle = mapCompilers ? 0.55 : last
let (start, end) = mapCompilers && current >= middle ? (middle, last) : (first, middle)
let lifted = start + (end - start) * 0.25 / 0.85
var value = current
if line.hasPrefix("==> Recompiling") { value = 0.10 }
else if line.hasPrefix("==> Creating") { value = 0.95 }
else if line.hasPrefix("==> ") { value = min(current + 0.012, 0.10) }
else if let f = fraction("lifted ") { value = 0.10 + 0.25 * f }
else if let f = fraction("compiled ") { value = 0.35 + 0.60 * f }
if line.hasPrefix("==> Recompiling") { value = first }
else if line.hasPrefix("==> Building the Puzzle Maker") { value = middle }
else if line.hasPrefix("==> Creating") { value = last }
else if line.hasPrefix("==> ") { value = min(current + 0.012, first) }
else if let f = fraction("lifted ") { value = start + (lifted - start) * f }
else if let f = fraction("compiled ") { value = lifted + (end - lifted) * f }
return max(current, value)
}

Expand All @@ -321,7 +343,7 @@ final class Installer: ObservableObject {
// Each game's run fills its own share of the bar.
let share = 1.0 / Double(max(runCount, 1)), base = Double(runIndex) * share
let inRun = min(max((progress - base) / share, 0), 1)
progress = base + share * Installer.progress(after: line, from: inRun)
progress = base + share * Installer.progress(after: line, from: inRun, mapCompilers: runHasMapCompilers)
if line.hasPrefix("==> ") {
step = String(line.dropFirst(4))
} else if line.hasPrefix("warning: ") {
Expand Down Expand Up @@ -525,6 +547,15 @@ struct GameRow: View {
}
}
}
if game.mapCompiler != nil, s.ready {
let available = game.hasMapCompiler(s.linux)
Toggle(available ? "Puzzle Maker: also build the map compilers (about \(mapCompilerMinutes) more minutes, 220 MB)"
: "Puzzle Maker: unavailable, no \((game.mapCompiler! as NSString).lastPathComponent) in these Linux binaries",
isOn: Binding(get: { model.puzzleMaker && available }, set: { model.puzzleMaker = $0 }))
.toggleStyle(.checkbox)
.disabled(!available || !s.selected || model.phase == .installing)
.help("Needed for Build and Play in Community Test Chambers. Without them the editor opens, but a chamber cannot be built.")
}
}
.padding(.leading, 20)
.font(.callout).foregroundStyle(.secondary)
Expand Down Expand Up @@ -575,9 +606,8 @@ struct ContentView: View {
switch model.phase {
case .ready:
let games = model.chosen
let minutes = games.map(\.minutes).reduce(0, +)
Text(games.isEmpty ? "Tick at least one game found above."
: "About \(minutes) minutes the first time and \(5 * games.count) GB of disk. Re-running later only rebuilds what changed.")
: "About \(model.minutes) minutes the first time and \(5 * games.count) GB of disk. Re-running later only rebuilds what changed.")
case .installing:
ProgressView(value: model.progress)
Text(model.step).lineLimit(1)
Expand Down Expand Up @@ -659,6 +689,7 @@ func snapshot(to path: String, state: String) {
case "incomplete":
model.states["portal2"]?.dataIssue = "Incomplete game data: portal2_dlc2/scripts/editoritems.txt is missing, unreadable or empty. An empty placeholder does not help. In Steam, verify the integrity of Portal 2's files (Properties > Installed Files), choose a complete game folder, or download the game data below:"
model.states["portal2"]?.selected = false
case "puzzlemaker": model.puzzleMaker = true
case "building": model.phase = .installing
model.step = "Recompiling Portal 2 (about 10 minutes the first time, seconds afterwards)"; model.progress = 0.25
model.showLog = true; model.log = ["==> Preparing the Linux modules of Portal 2", "[lift] engine.so: 41 233 functions", "[cc] 312/1024"]
Expand Down Expand Up @@ -691,6 +722,12 @@ enum Main {
p = Installer.progress(after: line, from: p)
print(String(format: "%.3f", p), line)
}
p = 0.0
for line in ["==> Recompiling Portal 2", " compiled 330/330 files, 600 s", "==> Building the Puzzle Maker map compilers",
" lifted 4/4 jobs: 1 functions", " compiled 50/100 files, 60 s", "==> Creating ~/Applications/Portal 2 Natif.app"] {
p = Installer.progress(after: line, from: p, mapCompilers: true)
print(String(format: "%.3f", p), line, "(map compilers)")
}
return
}
if args.contains("--unpack") { // tests: unpack into sourceDir and exit
Expand Down
Loading