BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
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#

FolderWhat 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#

Programs bf2_server · bf2_client (native + wasm) · bf2_backend · bf2_gate · launcher Heroes: bfh-server · bfh-client · bfh-ui · bfh-game · bfh-data Presentation render · shaders · audio · hud · ui · input Network net · netio · netview Simulation world · physics · gameplay · game · ai · effects Script and data con · objects · engine · python Formats mesh · collision · anim · terrain · texture · font Foundation core (Game / Product) · platform · fs · webfs
The crates by layer: formats at the bottom, the engine systems in the middle, the programs on top.
LayerCrates
Foundationbf2-core (game / product selection, shared helpers), bf2-platform, bf2-fs (zip archives, mounts), bf2-webfs
Script and databf2-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)
Formatsbf2-mesh, bf2-collision, bf2-anim, bf2-terrain, bf2-texture, bf2-font, bf2-geomdata, bf2-bink, bf2-vorbis, bf2-speex
Simulationbf2-world, bf2-physics, bf2-gameplay, bf2-game, bf2-ai, bf2-effects
Networkbf2-net (bit streams, packets, events, ghosts), bf2-netio, bf2-netview (capture viewer)
Presentationbf2-render (wgpu), bf2-shaders (D3D9 bytecode to WGSL), bf2-audio, bf2-hud, bf2-ui (Flash via Ruffle), bf2-input
Programsbf2-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
Heroesbfh-data, bfh-game, bfh-server, bfh-client, bfh-ui
Checkingbf2-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).

build (release)
cargo build --release -p bf2-server --bins
cargo build --release --manifest-path crates\bf2-client\app\Cargo.toml --target-dir target
a BF2 server and a client
# 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 under tools/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#

WhatWhere
Pagesdocs/dev/**/*.md (front matter: title, section, order, status: wip) and docs/dev/diagrams/*.svg
Generatortools/devwiki/build.py (Markdown in md.py, search index in search.py, theme in theme/)
Generated referencestools/devwiki/refs_python.py (Python host API), refs_con.py (CON properties)
Previewpython tools\devwiki\build.py --serve 26060 then open http://127.0.0.1:26060/dev/
Publishpython tools\devwiki\publish_devwiki.py --who <you> (rollback: --rollback <stamp>)
Testspython 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):

CrateWhat it is
crates/bf2-gatePROGRAM bf2_gate: the WebSocket gateway between browser clients and the backend and servers
crates/bf2-aibot AI: navigation data formats and pathfinding
crates/bf2-animskeletons, bone animations and the animation system
crates/bf2-audiothe sound system: decoders, sound templates, mixing rules
crates/bf2-backendPROGRAM bf2_backend: master, server list, login and stats on one host; its deploy files and the site's pages are under deploy/
crates/bf2-binkBink 1 video and audio decoder and a movie playback interface
crates/bf2-clientthe client's engine assembly as a library: boot, console, profiles, movies, join, level load, frame loop
crates/bf2-collisioncollision mesh files
Source: docs/dev/codebase/organisation.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.