On this page
Your first hour: build, play a round, run a test, read one port
This is one path, not a menu. At its end you have built the two programs, played a round on your own server, run a test and watched it pass, and read one function of the original game beside its Rust port and the test that holds the two together. Everything after that is on the other pages.
The wiki's own worker does not run the compiler: it may only read the tree and run Python. So every command on this page carries one of two marks. Checked here means it was run, or its file was opened and the arithmetic redone, while this page was written. As the tree's docs give it means the command is copied from the named document of the tree, which is kept by the people who run it: if it fails for you, that document is the one to read and to correct.
Before the clock starts#
| You need | Why | Source |
|---|---|---|
| your own install of Battlefield 2 (version 1.50), 2142 or Heroes | bf2-rs is an engine; it ships no game data and only ever reads yours | README.md |
| Windows 10 or 11 with a current Vulkan or DirectX 12 driver | what the play guide was tested on | notes/play-guide.md, section 1 |
the Rust toolchain stable-x86_64-pc-windows-gnu | every build | docs/release/BUILDING.md, "What a build needs" |
| Python 3 | the tools, the scenarios, this wiki | used by every command under tools/ |
| about an hour, most of it the first build |
Two source fetches are needed once, for the server's script host and the client's menus. As the tree's docs give it (docs/release/BUILDING.md; the commands are in notes/play-guide.md, section 1):
powershell -File crates\bf2-python\fetch-cpython.ps1
powershell -File crates\bf2-ui\vendor\ruffle\setup.ps1Both scripts are in the tree (checked here: the two files exist).
Step 1: build the two programs#
From the tree's top. As the tree's docs give it (README.md, "Build and run"; the same two lines are in docs/release/BUILDING.md and notes/play-guide.md):
cargo build --release -p bf2-server --bins
cargo build --release --manifest-path crates\bf2-client\app\Cargo.toml --target-dir targetThat gives target\release\bf2_server.exe and target\release\bf2_client.exe. Build release: the docs say a debug build is too slow to play.
While it compiles, read what bf2-rs is and skim how the codebase is organised: the server and the client are thin programs over some fifty crates, and one pair of programs runs all three games. Which game runs follows from the folder you point them at.
Step 2: a server, a client, a round#
The server must not run in your install: it writes compiled scripts, settings and logs. It gets a folder of its own. As the tree's docs give it (notes/play-guide.md, sections 3 to 5):
powershell -File crates\bf2-server\difftest\levels\make-root.ps1 -Root <a folder under analysis\scratch>
copy <server>\mods\bf2\Settings\ServerSettings.con <server>\mysettings.conPut one line into a new file <server>\mymaplist.con:
mapList.append strike_at_karkand gpm_cq 16In mysettings.con set sv.numPlayersNeededToStart 1, so that the round starts with you alone (the original's default is 2). Then, in two windows:
target\release\bf2_server.exe --root <server> -- +config mysettings.con +mapList mymaplist.con
target\release\bf2_client.exe --home <profile folder> -- +restart 1 +joinServer 127.0.0.1 +port 16567 +playerName TesterThe server prints Port: 16567 Map: ... Players: 0/16 when it is up. A new profile folder gets a profile named "Tester". Keep +restart 1: the play guide explains that a join given on the command line is otherwise dropped while the intro movies play. On the spawn screen pick a kit and a spawn point, press DONE, and you are in.
What every setting means, bots, a second player on the network, and what is known not to work: start here, which is this step in full, and notes/play-guide.md.
The server ran the original game's own Python scripts and its own level files through a Rust engine; the client drew the original's own menus through a Flash player. One tick of the server shows what happened thirty times a second while you walked, and the life of a player what the server did when you joined, spawned and died.
Step 3: run one test#
Pick the smallest thing that can fail: the tests of the random number generator, which you will read in the next step. As the tree's docs give it (docs/release/CONTRIBUTING.md, section 2: "a crate: cargo test -p <crate>"), narrowed with cargo's own name filter:
cargo test -p bf2-gameplay --lib lehmerIt should run two tests, lehmer_matches_modular_multiplication and lehmer_first_steps_by_hand (checked here: both are in crates/bf2-gameplay/src/random.rs; the command itself was not run by the wiki's worker).
Then make it fail, on purpose. Open crates/bf2-gameplay/src/random.rs, change the multiplier 0x5e30 in next_state to 0x5e31, and run the test again. Both tests must go red. Put the digit back. That is a mutation, and it is not a party trick: every port in this tree has to show that its test can fail (how a port is made).
A test that needs a real server and a real client is a scenario. As the tree's docs give it (the head of tools/scenarios/scn.py):
python tools\scenarios\scn.py list
python tools\scenarios\scn.py run spawn_moveScenarios explains what a scenario asserts and where its pictures go.
One command on this page was run by the wiki's worker, many times: the wiki itself, built from your checkout and served on your own machine.
python tools\devwiki\build.py --serve 26060
python tools\devwiki\test_devwiki.pyStep 4: read one port, end to end#
The port is the generator behind weapon deviation: 21 callers in the original's server, about forty lines of Rust. Read it in this order.
1. The claim. The original has a function at bf2_w32ded.exe!0x00580750. It takes a 32-bit state, multiplies it by 24112 and then by 26143, each time modulo 231 - 1, stores the result back and returns it. The notes say so in notes/subsystems/gameplay-weapons.md ("Random numbers"), and the wiki's page is random numbers.
2. The port. crates/bf2-gameplay/src/random.rs, the type Lehmer. Look at three things:
- the comment above the type cites the address and the number of callers. A port without its citation is not counted (parity);
mul_stepdoes not write(s * m) % 0x7fffffff. It splits the state into 16-bit halves and shifts, as the original's machine code does. The result is the same number; the port keeps the original's shape so that a reader can lay the two side by side;next_k24is the next thing every caller does with the state:((state | 0x80) >> 7) + 1, a number from 1 to 224.
3. The test. At the bottom of the same file. lehmer_matches_modular_multiplication compares ten thousand steps with the plain modular product. lehmer_first_steps_by_hand starts from the seed of the deviation table, 0x20fee, and asserts two numbers worked out by hand in its comment.
4. Check the test's numbers yourself. You do not have to believe the comment. Checked here, with Python:
>>> M = 2**31 - 1
>>> 135150 * 24112 % M # 0x20fee is 135150
1111253153
>>> 1111253153 * 26143 % M
332402263
>>> ((332402263 | 0x80) >> 7) + 1
2596894Those are the test's two expected values, 332,402,263 and 2,596,894.
5. See it move. The page random numbers has the generator as a piece you can click, draw by draw.
6. Follow one caller. A shot's deviation reads a table of 1024 offsets, and that table is filled by this generator from the seed 0x20fee: deviation and the random table. That page ends with a table of what the port has and how it is tested, as most pages of this wiki do. The rows that are not finished, from every page, are gathered on what is still open: that list is where a second hour could start.
What you know now#
| You did | The idea behind it | Read on |
|---|---|---|
| pointed two programs at a folder | the engine is ours, the data is yours | the asset pipeline |
| ran a server in a copy | the original is only ever read | start here |
| broke a test on purpose | a proof must be able to fail | how a port is made |
| read an address, a port and a test | every claim about the original cites its evidence | reading the notes |
| saw a table of open rows | nothing is called done that was not compared | parity, what is still open |
How this page is tested#
The wiki's test checks that every link on it leads to a page of the build. The commands marked "as the tree's docs give it" are not run by that test; the documents they are copied from are named beside each.
In the code#
| What | Where |
|---|---|
| the build's table of programs | docs/release/BUILDING.md |
| how a change gets in | docs/release/CONTRIBUTING.md |
| every folder and crate, one line each | docs/release/LAYOUT.md |
| the play guide | notes/play-guide.md |
| the generator of step 4 | crates/bf2-gameplay/src/random.rs |
| the scenario runner | tools/scenarios/scn.py |
docs/dev/guide/first-hour.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.