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

BF22142Heroes
Battlefield 2 commander, squads, ranks GameSpy stats, xpack 53 host fns, 42 events Battlefield 2142 Titan mode, pods, EMP unlocks, field upgrades 69 host fns, 64 events Battlefield Heroes heroes, abilities, XP, prestige EA Plasma online, 75 host fns Refractor 2 CON · templates · net Python 2.3 host 2142 generation: formats, archives, renderer, FESL
The engine core is shared by all three; 2142 and Heroes share the second engine generation; each game keeps its own features.

How bf2-rs knows which game it runs#

The data root decides, once, at start-up:

Data root containsbf2_core::game::current()product()Notes
mods/bf2Game::Bf2Product::Bf2Battlefield 2 v1.50 (and Special Forces as mods/xpack)
mods/bf2142Game::Bf2142Product::Bf2142Battlefield 2142, final patch
mods/bfheroesGame::Bf2142Product::HeroesHeroes is the 2142 engine generation plus a product axis

Code that differs branches at the point of difference, with a citation of each original:

the pattern used across the crates
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#

AreaShared by all threeDifferences
CON languagethe interpreter, keywords, variableseach 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 objectsthe class / template model, components, class idsnew classes per game (Titan parts, pods, Heroes abilities and items)
File systemzip archives, mod mounting, level archivesHeroes ships its own archive set and versioned data
Networkingtransport, bit streams, the three payload streamsghost and event tables grow per game (2142 and Heroes add networkables and events)
PythonCPython 2.3.4, the host module mechanismthe function / method / event tables: 53 / 16 / 42 (BF2), 69 / 18 / 64 (2142), 75 / 24 / 86 (Heroes); see the API reference
Renderingthe D3D9 effect model translated to WGSL, meshes, terrain2142 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
UIthe Flash menu player (Ruffle) and the HUD systemeach 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 tutorial gpm_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):

CrateWhat it is
crates/bf2-coreshared types and helpers; which game a process runs
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/bfh-clientBattlefield Heroes client boot: command line, login and the join ticket
crates/bfh-dataBattlefield Heroes data: the template properties and console objects it adds
crates/bfh-gameBattlefield Heroes game systems on the server: hero abilities, capture-the-flag
crates/bfh-serverBattlefield Heroes server pieces: Python host tables and functions, console objects, our own navigation data
crates/bfh-uiBattlefield Heroes' own menu natives
Source: docs/dev/games/shared.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.