BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Server-side vs client-side mods

"If I add boost to a vehicle and use that mod on my server, do clients need it?" It depends on which lines you change. Every template property and every data file has a scope: the server reads it, the game client reads it, or both do. This page explains the three scopes, how bf2-rs works them out, and walks through three mods. Every property's scope is a badge per game in the cross-game command table (the scope table keeps the file types), the unified reference finds one name in all three games, and the web editor shows the same scope as a badge next to each property.

BF22142Heroes

The three scopes#

The reference tables call the third scope shared (both in scope.json and the editor's B badge).

ScopeWho reads itA mod on the server alonePlayers need the mod
serveronly the servertakes effect for everyoneno
clientonly the game client (drawing, sound, HUD)changes nothing anyone seesyes, each player who should see it
sharedthe server and every clientthe server's result is right, but each client computes its own view with the old valueyes, the same version as the server

"Both" is the case that surprises people. A client does not just display what the server sends: it predicts its own soldier and vehicle, fires its own weapon locally, and builds the same object tree as the server. If its copy of a value differs, it predicts wrong and then snaps to the server's answer (rubber-banding, shots that seem to go elsewhere, a speedometer that lies).

Pure servers check the files

A server with the content check on compares an MD5 of the client's ClientArchives.con, ServerArchives.con, Init.con, GameLogicInit.con and of pieces of every mounted archive with its own (runMiscChecksum / runArchiveChecksum, BF2.exe!0x006b57f0 / 0x006b6170, bf2-rs crates/bf2-fs/src/checksum.rs). On such a server even a client-only mod has to be the server's exact files.

How the files are split#

Each mod folder has two archive lists. ServerArchives.con mounts the *_server.zip archives (template scripts, collision meshes, AI, animations), ClientArchives.con the *_client.zip archives (meshes, textures, sounds, effects, fonts, shaders). The dedicated server mounts only the server list; the game client mounts both, server list first (mod start-up bf2_w32ded.exe!0x00404500, BF2.exe!0x00408ef0; bf2-rs crates/bf2-fs/src/startup.rs mount_mod). The shipped dedicated server packages hold no _client archive at all. So:

  • a file that only exists in a _client archive (.dds, .tga, .staticmesh, .bundledmesh, .skinnedmesh, .ogg, .wav, .fx, ...) is client: the server never sees it;
  • a file in a _server archive is read by the server and by every client (they mount it too). Whether the client actually uses a given line decides its scope. .ai files are the exception that is server only: bots run in the server.

Level folders work the same way: Levels/<name>/server.zip and client.zip. StaticObjects.con is both (each side builds the statics from its own copy). In GamePlayObjects.con both sides run the template definitions at the top, but the placements (Object.create and its position lines for spawners, control points and spawn points) sit inside if v_arg1 == host and run on the server only: moving a spawner is server, the clients get the objects over the network (crates/bf2-engine/src/level.rs runs the file with host or client).

How a property's scope is worked out#

tools/bfheroes/mod_scope.py derives every scope from the data the engine is built from, in this order (the table's Basis column names the step that decided):

  1. Retail behaviour - a short list of properties where the original game's behaviour is clear and bf2-rs's reads say less, for example ObjectTemplate.damage (the server applies damage; clients receive hit points).
  2. Rule - whole families: the AI templates (aiTemplate, aiTemplatePlugIn, kitTemplate and weaponTemplate strengths) are server; NetworkableInfo (the object's network format) and CollisionManager are both.
  3. Retail registry - a command only the game client registers (BF2.exe or RendDX9.dll, not bf2_w32ded.exe) is client: the dedicated server does not even know the line (every hudBuilder command, weaponHud.*, vehicleHud.*, GeometryTemplate.*). A property the dedicated server accepts and ignores (re/data/template_properties.tsv category noop) is client too. bf2-rs does the same: its template host only has the client-only commands when it runs as the client (crates/bf2-objects/src/template/host.rs TemplateHost::new).
  4. bf2-rs reads - which crates read the property: its generated field in crates/bf2-objects/src/template/props.rs or its name as a string, in the server crates (bf2-server, bfh-server, bf2-ai), the client crates (bf2-client, bfh-client, bf2-hud, bf2-render, bf2-audio, bf2-effects, ...) or the shared simulation both run (bf2-world, bf2-gameplay, bf2-physics, ...). A client-only read of a value the dedicated server stores counts as both unless it is presentation (sound, HUD, effects); a server-only read of a simulation value (mass, drag, speed, torque) counts as both, because clients predict their own soldier and vehicle with it.
  5. Name - a 2142 or Heroes property bf2-rs does not read yet, named like presentation (hud, sound, effect, light, camera), is client.
  6. Retail reads - what the original code itself reads (tools/bfheroes/template_reads.py over the decompiled game client BF2.exe and dedicated server bf2_w32ded.exe, kept in tools/bfheroes/template_reads.yaml): a template field the dedicated server's code reads through a template pointer is both; one only the client's code reads, at an offset the server never names, is client. Battlefield 2142 commands its dedicated server (bf2142ded) does not register are client, as in step 3; the others take their field from the 2142 server's setter and are read the same way in bf2142ded (the Linux dedicated server) and BF2142.exe. A read counts only for the template type of the reading function's class (or a type along its inheritance), so another template's field at the same offset does not count; a read whose function has no known class is left out.
  7. Default - anything else is both: nobody has shown that the clients ignore it, so keep server and clients the same. Most of these are Heroes-only commands: Battlefield Heroes shipped no dedicated server binary to compare its client with.

The table is rebuilt from the code on every wiki build, so it follows bf2-rs as more of the engine is read.

Worked example 1: more speed for a jeep#

Michael's mod: make Battlefield 2's HMMWV faster. Its speed comes from the Engine template in Objects/Vehicles/Land/USJEP_HMMWV/USJEP_HMMWV.tweak (in Objects_server.zip):

USJEP_HMMWV.tweak (shipped)
ObjectTemplate.activeSafe Engine USJEP_HMMWV_Engine
ObjectTemplate.setEngineType c_ETNewCar2
ObjectTemplate.setTorque 225
ObjectTemplate.setDifferential 4
ObjectTemplate.setGearRatios 2.25 1.25 1 0.6 0.6
ObjectTemplate.newCar2.maxRpm 4000
LineScopeWhy
setTorque, setDifferential, newCar2.maxRpmsharedthe vehicle simulation; the driver's client predicts its own vehicle with them
setGearRatios, setEngineTypesharedread by the shared vehicle code (bf2-world vehicle.rs)
soundFilename of the engine soundsclientonly the client plays sounds

Answer: clients need the mod. On the server alone the jeep really is faster (the server simulates it and every other player sees the server's position), but its driver's client keeps predicting the old speed and is pulled forward every update. A Heroes jeep's boost flame (statusGLEffect.effectName E_wheel_Boost) is client only.

Worked example 2: a new weapon's damage#

A harder-hitting M16A2: Weapons/Handheld/usrif_m16a2/USRIF_M16A2.tweak.

USRIF_M16A2.tweak (shipped)
ObjectTemplate.fire.roundsPerMinute 900
ObjectTemplate.projectileTemplate M16a2Projectile
ObjectTemplate.velocity 1000
ObjectTemplate.create GenericProjectile M16a2Projectile
ObjectTemplate.minDamage 1
ObjectTemplate.damage 30
LineScopeWhy
damage, minDamage, distToMinDamageserverthe server applies damage; clients only receive the hit points
fire.roundsPerMinute, velocity, projectileTemplatesharedthe shooter's client fires the weapon locally (rate, muzzle flash, tracer)
weaponHud.weaponIconclientthe HUD; the dedicated server does not know the command

Answer: changing only the damage is a pure server mod. Changing the rate of fire or the muzzle velocity is not: the shooter would see a different weapon from the one the server simulates.

Worked example 3: a new HUD icon#

A new weapon icon is a .tga / .dds under Menu/HUD/... or Objects/Weapons/.../Icons (a _client archive) and the ObjectTemplate.weaponHud.weaponIcon line that names it (client only: BF2.exe registers it, the dedicated server does not). Answer: a client mod. The server needs nothing; every player who should see the icon installs it (and on a pure server it must still match the server's files).

In the editor#

The web editor's inspector shows a scope badge (S, C, B) next to every property of the selected object's template chain (hover it for the reason), and its Mod scope line says what a change to the object needs. The same lookup tells an overlay what it needs: this overlay needs: the server only / every client / server and clients (web/editor/src/engine/scope.ts overlayNeeds).

Scopes generated by tools/bfheroes/mod_scope.py (docs/dev/modding/scope.json).

How it is tested#

  • The table is generated from the code (tools/bfheroes/mod_scope.py): which crate reads a property decides its scope, and the tool's own tests hold its rules (tools/bfheroes/test_mod_scope.py).
  • Kept current: the wiki's publish reports when the committed scope file no longer matches the code, and the editor's checks fail on a stale one.
  • In play: on a pure server a client whose files differ from the server's fails the content check, whose lists every shipped level passes (server start-up).

A property with the scope "default" is read by nothing in the port yet; that it must be equal on both sides is the safe assumption, not a tested fact.

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-fsthe engine's file system: file manager, archives
crates/bf2-objectsthe object model: class and interface ids, templates, objects
crates/bf2-worldthe runtime object world: objects from templates, object manager, hierarchy, tick order
crates/bf2-aibot AI: navigation data formats and pathfinding
crates/bf2-audiothe sound system: decoders, sound templates, mixing rules
crates/bf2-clientthe client's engine assembly as a library: boot, console, profiles, movies, join, level load, frame loop
crates/bf2-effectsvisual effects: templates and the simulation of particles, decals and lights
crates/bf2-engineengine assembly shared by the programs: command line, start-up and level-load order, main loop timing, localization, settings

Files this page names: crates/bf2-fs/src/checksum.rs, crates/bf2-fs/src/startup.rs, crates/bf2-engine/src/level.rs, crates/bf2-objects/src/template/host.rs, crates/bf2-objects/src/template/props.rs.

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