On this page
Battlefield 2's HUD: nodes, variables and writers
The in-game HUD is not Flash. It is a tree of menu nodes (texts, pictures, bars, lists, a map) that the game's own scripts build at start, and every node shows a named variable. Code writes the variables; the nodes draw them. To know why a number on the screen is what it is, find its variable and the function that writes it.
How it is built#
BF2HudManager::init (BF2.exe!0x00756ce0):
- makes the menu system at 800 x 600 (
0x007af010), with its font and the texture atlas; - creates the builder (
0x00794e30) and the sub-managers: the spawn screen, the chat, the comm rose; - loads the node file
Menu/InGameas the root; - runs
Menu/HUD/HudSetup/HudSetupMain.conand the files it names: every HUD script; - runs the name tags' script.
Each frame the renderer calls BF2HudManager::render (0x0074f110) as one of its last steps (the render pipeline).
The scripts are lines of the hudBuilder console object: 118 commands, 101 of them used by the game's own files. A line creates a node (createTextNode, createPictureNode, createBarNode, ...) or binds the node last made (setTextNodeStringVariable, setBarNodeValueVariable, setNodeShowVariable). A mod that moves a HUD element edits these files, not code.
The variables#
HudInformationLayer (0x00468dd0) is the table of variables: bool, int, float, string and wide string, each registered under a name (0x00466240). There are 2,043 of them:
| Registered by | How many | Examples |
|---|---|---|
| the layer's own constructor | 425 | tickets, the round's time, the capture bars |
BF2HudManager::init and its sub-objects | 359 | ShowIngameHud, BottomRightAlpha, the chat's |
| nodes, while the scripts run | 1,257 | 36 for each object marker, 3 for each hover node, 42 for each map node |
| the engine, before the HUD exists | 2 | the blinding light's alpha and show flag |
Two rules catch people: the name map keeps the first id registered for a name (a second registration is only logged), and a lookup by name with the wrong type finds nothing, so the builder's line fails.
The parts#
Health, stamina and the weapon panel#
The bottom-left block shows the health bar (hit points over the maximum) and a number that is a percent: the ceiling of the ratio times 100 (0x0078a910). The block hides when the soldier is dead or critically wounded. The bottom-right block shows the kit's items, the rounds in the magazine and the magazines left (0x007a5800), the fire rate's icon and a mounted gun's heat (a fire arm's heat).
Tickets and the round's time#
The ticket numbers blink while a team bleeds: two faders over the teams' bleed flags run every frame (0x00771a30). From their first state the alpha jumps to 1, falls to 0 and rises back within two seconds even without a bleed, then blinks while the team bleeds. The round's time (0x00464870) prints %d: hours when there are any, %02d: minutes and %02d seconds (server rules).
The capture bar#
Inside a control point's radius two bars show the flag's height: one for a point being made neutral, one for a point being taken (a control point's flag).
The minimap#
One node, Minimap (Bf2MenuMapNode, constructor 0x00780180), draws three maps: the minimap at the top right, the big map of the spawn screen, and the commander's map. It draws the control points with their names, the players, vehicles and strategic objects as icons, squad and commander orders, the supply lines, the combat area's shade and the satellite scan. A click on the spawn screen's map selects a spawn group; a click on the commander's mini map is handed to the HUD manager.
Chat and kill messages#
Two chat managers (0x007a08c0) fill two lists: the in-game one and the commander's. The in-game list has 4 rows for chat, 5 for kill messages and 3 and 2 for two more kinds, each kind in its own region; a line lives 15 seconds, a kill message 20. The lines also go to the console.
The scoreboard and the squad screen#
The scoreboard's rows are written by one function (0x007a4c80): per team the players' rows and the sums. The squad screen (0x00792100) lists the squads with their members and has the buttons to create, join and leave one.
The commander screen#
HudCommanderSquadManager (0x00794700) owns the commander's variables: the armour of the UAV, the satellite and the artillery, each asset's reload (the artillery and the supply drop 60 seconds, the vehicle drop by a console setting), the "no artillery / no UAV" marks when an asset is destroyed, and the list of squads to select and order.
How it is tested#
The original's HUD code was run in an emulator and ours beside it:
| What | Result |
|---|---|
| the builder: every object the scripts make, field for field | 0 differences, both mods |
| rendering: the draw calls of 742 HUD states | 1,151 of 1,152 frames identical; the one that differs reads an uninitialised value in the original |
| the kit variables of the spawn screen | 1,500 random template sets, 43,763 string writes equal |
| screen changes | 2,450 and 3,675 cases over every pair of screens |
| name tags | 5,248 draws equal |
On top of that the HUD and menu sweeps play every screen in scenarios (test rigs).
In the code#
| What | Where |
|---|---|
| nodes, the builder, rendering, the map, name tags | crates/bf2-hud (native, render, map, nametag, hil) |
| the writers that need the game | crates/bf2-client/src/ (hud_live.rs, hud_writers.rs, hud_vehicle.rs, hud_hit.rs, spawn_screen.rs) |
| the tables of variables and their writers | re/data/hud_variables.tsv, re/data/hud_variable_writers.tsv |
Notes: notes/subsystems/hud.md. The other games: Battlefield 2142, Heroes.
The names over soldiers' heads are the renderer's, not the HUD's: name tags.
docs/dev/ui/hud-bf2.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.