On this page
Shared engine, different games
One codebase runs all three games. The engine, the data formats and most systems are shared; each game adds its own features on top. This page shows where the lines are and how the code decides.
How bf2-rs knows which game it runs#
The data root decides, once, at start-up:
| Data root contains | bf2_core::game::current() | product() | Notes |
|---|---|---|---|
mods/bf2 | Game::Bf2 | Product::Bf2 | Battlefield 2 v1.50 (and Special Forces as mods/xpack) |
mods/bf2142 | Game::Bf2142 | Product::Bf2142 | Battlefield 2142, final patch |
mods/bfheroes | Game::Bf2142 | Product::Heroes | Heroes is the 2142 engine generation plus a product axis |
Code that differs branches at the point of difference, with a citation of each original:
match bf2_core::game::current() {
bf2_core::Game::Bf2 => &HOST_FUNCTIONS, // bf2_w32ded.exe!0x0082d2e0
bf2_core::Game::Bf2142 => &HOST_FUNCTIONS_2142, // bf2142ded!0x0896b5e0
}
// Heroes: `if bf2_core::game::is_heroes() { ... }` or a hook into crates/bfh-*Heroes-only systems live in their own crates (bfh-data, bfh-game, bfh-server, bfh-client, bfh-ui, plus the backend's Heroes services); shared crates get one hook call per site. A 2142 path that Heroes reaches is presumed shared until it is checked against BFHeroes.exe; the checks are logged in notes/bfheroes/carryover.md.
What is shared#
| Area | Shared by all three | Differences |
|---|---|---|
| CON language | the interpreter, keywords, variables | each game's command table (BF2 about 1,200 objectTemplate commands, 2142 about 1,260, Heroes about 1,780); see the cross-game table |
| Templates and objects | the class / template model, components, class ids | new classes per game (Titan parts, pods, Heroes abilities and items) |
| File system | zip archives, mod mounting, level archives | Heroes ships its own archive set and versioned data |
| Networking | transport, bit streams, the three payload streams | ghost and event tables grow per game (2142 and Heroes add networkables and events) |
| Python | CPython 2.3.4, the host module mechanism | the function / method / event tables: 53 / 16 / 42 (BF2), 69 / 18 / 64 (2142), 75 / 24 / 86 (Heroes); see the API reference |
| Rendering | the D3D9 effect model translated to WGSL, meshes, terrain | 2142 and Heroes renderer generation (shaders, post effects); Heroes cartoon materials |
| Online services | - | BF2 / 2142: GameSpy (replaced by our backend); Heroes: EA Plasma (FESL, Theater, Magma), reimplemented in bf2-backend |
| UI | the Flash menu player (Ruffle) and the HUD system | each game's menus and HUD files |
Area by area#
What each of the later games changed, with the page for each area: 2142 by area and Heroes by area.
Choosing a game for a mod#
- A BF2 mod uses the BF2 tables: everything in the property reference marked BF2.
- A 2142 mod can use the 2142 additions (heat, pods, Titan) and the 2142 Python events.
- A Heroes mod builds on the Heroes data (
mods/bfheroes): its game modes (gpm_cq,gpm_ctf,gpm_cdm,gpm_hoth, the tutorialgpm_tut), abilities, hero classes and the XP / prestige Python functions.
The per-game pages: Battlefield 2, Battlefield 2142, Battlefield Heroes.
How it is tested#
This page explains; it holds no code of its own. What the three games share is one code base with per-game arms; each arm is tested in its own game's process (Battlefield 2, 2142, Heroes). 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.
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-core | shared types and helpers; which game a process runs |
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/bfh-client | Battlefield Heroes client boot: command line, login and the join ticket |
crates/bfh-data | Battlefield Heroes data: the template properties and console objects it adds |
crates/bfh-game | Battlefield Heroes game systems on the server: hero abilities, capture-the-flag |
crates/bfh-server | Battlefield Heroes server pieces: Python host tables and functions, console objects, our own navigation data |
crates/bfh-ui | Battlefield Heroes' own menu natives |
docs/dev/games/shared.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.