BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
Refractor 2 · reimplemented in Rust

bf2-rs developer wiki

How the engine behind Battlefield 2, 2142 and Heroes works, how our Rust reimplementation is organised, and how to mod it: the Python game-script API, the CON object system, vehicles, weapons, levels and assets.

Where do you come from?#

I play

You came from the game's site and want to know what changed, or why something is not as you remember it.

  1. The port's status, in two minutes
  2. Today: Battlefield 2, 2142, Heroes
  3. What's new: the changelog, in a player's words
  4. Questions players ask about Heroes
  5. How to report a bug that gets fixed
  6. Feature checklists: what is checked, what is open
  7. Short answers

I host a server

You have a copy of a game and want a server of your own, for friends or for the public.

  1. Build and run a server and a client
  2. Start-up and the main loop: what the server reads and when
  3. Rounds, tickets, flags and game modes
  4. Bots
  5. The Python layer: scripts that change the rules

I want to read or change the code

You want to understand the engine, port a function, or mod the game.

  1. Your first hour: build, play, test, read one port
  2. How the codebase is organised
  3. How a port is made, from an address to a proof
  4. Parity: how much is proven, and what is still open
  5. The CON system, for modders
Start11

Build the server and the client and run them against your own install of a game.

every page of this area (11)
Engine144

Objects and templates, the frame, networking, the console, and how the crates fit together.

every page of this area (144)
Network7

Packets bit by bit, the three streams, ghosts, the control block and prediction, demos.

every page of this area (7)
Vehicles6

Engine, gearbox, wheels and springs with their formulas, and what float precision does to a lap.

every page of this area (6)
Soldier10

The soldier on foot and his weapons: a tick of input, sprint, whole-tick timers, deviation.

every page of this area (10)
Audio5

Sound templates, the gain over the distance, engine sounds, music and voice-over.

every page of this area (5)
UI5

The Flash layer behind the menus: the player, the native API, text in the engine's fonts.

every page of this area (5)
Server7

What a server decides: rounds, tickets, a control point's flag, spawning, the map list and votes.

every page of this area (7)
Heroes63

Abilities, the three classes' values, the HUD variable by variable, the item bar's widgets.

every page of this area (63)
Python14

The game-script layer: lifecycle, every host function, host.Object method and event per game.

every page of this area (14)
CON objects114

The CON language, templates and components, and every property a .con or .tweak file can set.

every page of this area (114)
Levels5

The level folder: heightmaps, static objects, spawns, game modes, and the editor's format matrix.

every page of this area (5)
Assets13

Archives, meshes, textures, animations, sounds and Flash menus: the file formats and their readers.

every page of this area (13)
Games10

What Battlefield 2, 2142 and Heroes share, and where each one differs.

every page of this area (10)
Editor4

The web modding editor: the engine in the page, the JS / wasm contract, the stages.

every page of this area (4)
Test rigs7

How the port is checked against the original programs: the parity count and its kinds of proof, the function oracle, the differentials, scenarios and sweeps.

every page of this area (7)
Parity dashboard

How much of each game bf2-rs covers, checked function by function against the original programs.

What is bf2-rs?#

bf2-rs is a clean reimplementation, in Rust, of the engine the three games shipped with. It reads the games' own data (your install's archives and scripts), speaks their network protocol, and runs the same Python 2.3 game scripts through an embedded CPython. Behaviour is checked against the original programs function by function: the parity dashboard shows how much of each game is covered.

This wiki is written for two kinds of reader: modders who want to add a vehicle, change a weapon or script a game mode, and engine developers who want to understand a system before they touch the Rust. Every page cites where its facts come from (a file in the repository or an address in the original binaries), and the reference sections are generated from the code on every build, so they say what the engine really does today.

Battlefield 2 (2005) mods/bf2 · Game::Bf2 Battlefield 2142 (2006) mods/bf2142 · Game::Bf2142 Battlefield Heroes (2009) mods/bfheroes · 2142 gen + Product::Heroes Game content: CON / tweak scripts · Python game modes · meshes · levels · Flash menus plain files in zip archives; everything a modder changes lives here Refractor 2 engine (reimplemented by bf2-rs) Console/CON Templates Objects/World Game logic Python host Network Physics Animation Renderer Audio HUD/Flash UI AI bots bf2_server · bfh-server authoritative simulation, Python, ghosts out bf2_client (native + browser/WebGPU) render, sound, input, HUD; ghosts in
One engine, three games: content on top, the Refractor 2 systems in the middle, the bf2-rs server and client underneath.

How this wiki is built#

The site is a single-page app generated by tools/devwiki/build.py from Markdown in docs/dev/ plus reference pages generated from the Rust sources (tools/devwiki/refs_*.py). Search is a prebuilt index, so it works offline and instantly: press / for the sidebar search or Ctrl K for the search dialog. The diagrams are drawn by a script (tools/devwiki/diagrams.py), and the pieces you can play with (a drivetrain bench, a packet explorer, a control point simulator, a 3D collision mesh viewer and more) are plain JavaScript of our own (tools/devwiki/theme/ix.js) that runs the port's formulas in the page. New here? Start here, or take your first hour as one guided path; the words are in the glossary. Pages marked in progress are being written right now; the wiki is updated as the project moves. Its colours come from web/tokens/bf2.css, the design tokens it shares with the web editor.

How it is tested#

This page explains; it holds no code of its own. The wiki's test checks that every link and anchor on it leads to a page of the build and that its diagrams are the ones the script draws. The interactive pieces are held twice: a test names the Rust statements each piece copies, so a change in the port fails the wiki's test, and a tour in a headless browser moves each piece's controls and reads its answers.

In the code#

This page names no crate of its own. How the codebase is organised maps the crates by area, and docs/release/LAYOUT.md in the tree has one line for every folder and crate.

Source: docs/dev/index.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.