On this page
How the codebase is organised
bf2-rs is one Rust workspace that reimplements the engine of all three games, plus the reverse-engineering data it is checked against and the tools that test and ship it.
The repository#
| Folder | What is in it |
|---|---|
crates/ | the Rust workspace: one crate per engine system (bf2-*) and the Heroes-only crates (bfh-*) |
notes/ | everything known about the originals: subsystems/*.md (one per system), formats/*.md (file formats), bf2142/, bfheroes/ |
re/ | reverse-engineering data and scripts: re/data/*.tsv (function maps, console commands, template properties, Python host API), re/py/ (extractors and generators such as gen_template_props.py, comment_lint.py) |
tools/ | test, build and ops tooling: scenarios/ (end-to-end tests), bfheroes/ (deploys, site), web/ (browser tests), devwiki/ (this wiki) |
docs/dev/ | the hand-written pages of this wiki |
retail/ (not in git) | your own installs of the games, read only |
The rule that keeps it honest: every ported function cites the original's address next to the code (bf2_w32ded.exe!0x0042c450, BF2142.exe!0x..., BFHeroes.exe@bfh126!0x...), and re/py/comment_lint.py checks the comments.
The crates#
| Layer | Crates |
|---|---|
| Foundation | bf2-core (game / product selection, shared helpers), bf2-platform, bf2-fs (zip archives, mounts), bf2-webfs |
| Script and data | bf2-con (CON interpreter, command registry), bf2-objects (class ids, templates, properties), bf2-engine (settings, level load plan, timing), bf2-python (embedded CPython 2.3.4, host tables) |
| Formats | bf2-mesh, bf2-collision, bf2-anim, bf2-terrain, bf2-texture, bf2-font, bf2-geomdata, bf2-bink, bf2-vorbis, bf2-speex |
| Simulation | bf2-world, bf2-physics, bf2-gameplay, bf2-game, bf2-ai, bf2-effects |
| Network | bf2-net (bit streams, packets, events, ghosts), bf2-netio, bf2-netview (capture viewer) |
| Presentation | bf2-render (wgpu), bf2-shaders (D3D9 bytecode to WGSL), bf2-audio, bf2-hud, bf2-ui (Flash via Ruffle), bf2-input |
| Programs | bf2-server (dedicated server), bf2-client (native + browser client), bf2-backend (accounts, server lists, stats, Heroes' FESL / Theater / Magma), bf2-gate (browser to UDP relay), bf2-launcher |
| Heroes | bfh-data, bfh-game, bfh-server, bfh-client, bfh-ui |
| Checking | bf2-runtime, retail-oracle-rs, bf2-demo |
The full table with what each crate replaces: notes/architecture.md.
Run a server and a client#
You need your own copy of the game you want to run and the Rust toolchain (notes/play-guide.md has every detail).
cargo build --release -p bf2-server --bins
cargo build --release --manifest-path crates\bf2-client\app\Cargo.toml --target-dir target# a server folder copied from your install (never point the server at the install itself)
powershell -File crates\bf2-server\difftest\levels\make-root.ps1 -Root analysis\scratch\<you>\server
target\release\bf2_server.exe --root <server> -- +config mysettings.con +mapList mymaplist.con
target\release\bf2_client.exe --home <profile folder> -- +szx 1280 +szy 960- The map list holds lines like
mapList.append strike_at_karkand gpm_cq 16. - A 2142 or Heroes root runs those games with the same binaries; Heroes roots are made with
python tools\bfheroes\make_root.py server --out <dir> --src <your Heroes install>. - The browser build is the same client compiled to WebAssembly with WebGPU; it talks to servers through
bf2-gate. The public builds are on bf2.us/play.
Tests#
cargo test -p <crate>per crate; data tests run every parser over every original file.- Scenarios (
tools/scenarios/): end-to-end runs of real servers and clients (python tools\scenarios\scn.py run <name>), each a TOML file undertools/scenarios/scenarios/with PASS / FAIL checks; suites group them per game. - Oracles and differentials: the original programs' functions and traces compared with ours (
notes/retail_oracle.md,crates/retail-oracle-rs).
The parity dashboard#
How much of each game's original code is reimplemented and exercised is measured function by function and published on the parity dashboard (tools/bfheroes/parity_report.py; the numbers in notes/bfheroes/parity_coverage*.md).
This wiki#
| What | Where |
|---|---|
| Pages | docs/dev/**/*.md (front matter: title, section, order, status: wip) and docs/dev/diagrams/*.svg |
| Generator | tools/devwiki/build.py (Markdown in md.py, search index in search.py, theme in theme/) |
| Generated references | tools/devwiki/refs_python.py (Python host API), refs_con.py (CON properties) |
| Preview | python tools\devwiki\build.py --serve 26060 then open http://127.0.0.1:26060/dev/ |
| Publish | python tools\devwiki\publish_devwiki.py --who <you> (rollback: --rollback <stamp>) |
| Tests | python tools\devwiki\test_devwiki.py (search index, Markdown, reference extraction, idempotent build) |
In the code#
The crates this page names, each with its line of docs/release/LAYOUT.md (the list is gathered by the wiki's build from the page itself):
| Crate | What it is |
|---|---|
crates/bf2-gate | PROGRAM bf2_gate: the WebSocket gateway between browser clients and the backend and servers |
crates/bf2-ai | bot AI: navigation data formats and pathfinding |
crates/bf2-anim | skeletons, bone animations and the animation system |
crates/bf2-audio | the sound system: decoders, sound templates, mixing rules |
crates/bf2-backend | PROGRAM bf2_backend: master, server list, login and stats on one host; its deploy files and the site's pages are under deploy/ |
crates/bf2-bink | Bink 1 video and audio decoder and a movie playback interface |
crates/bf2-client | the client's engine assembly as a library: boot, console, profiles, movies, join, level load, frame loop |
crates/bf2-collision | collision mesh files |
docs/dev/codebase/organisation.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.