On this page
Archives and the file system
No game file is opened by its disk path. Every loader asks the file manager for a virtual path such
as Objects/Vehicles/bri_jeep_willys/meshes/bri_jeep_willys.bundledmesh, and the file manager answers
from the first source that holds it: a .zip archive mounted at a matching mount point, or a loose file
under one of the search paths. Which archive answers is decided by the mount order.
Archives, mount points and the split#
The install ships its content as plain zip archives (stored or deflated, read with the semantics of the minizip 1.01 the engine links; bf2-fs zip.rs ZipArchive). An archive is mounted at a directory: the archive's entries are relative to it. The mod's start-up scripts list them:
fileManager.mountArchive Objects/Common_server.zip Objects\Common
fileManager.mountArchive Objects/Effects_server.zip Objects\Effects
...
fileManager.mountArchive Objects/Common_client.zip Objects\Common
fileManager.mountArchive Objects/Effects_client.zip Objects\EffectsMost content comes in pairs. The _server archive holds what a dedicated server needs to simulate: the CON scripts and tweaks, collision meshes, heightmaps, animations, game modes. The _client archive holds what only a player sees and hears: render meshes, textures, sounds, the lightmaps and colour maps of a level. The server runs ServerArchives.con only; the client runs ServerArchives.con first and then ClientArchives.con, so at every mount point the server archive comes first (startup.rs mount_mod, BF2.exe!0x00408ef0). In the Heroes 1.126 install no path is in both halves of a pair (checked over the 14 mod pairs and village's level pair), so there the order never hides a file.
How a lookup resolves#
- The mount table is a sorted map from mount point to the archives mounted there.
opentakes the first mount point that is a prefix of the path's directory and asks its archives in mount order; the first that has the entry answers (archive selection0x0064c780, clientBF2.exe!0x0069a3b0). - Only if no archive has it, the search paths are tried for a loose file, the most recently added first: for Heroes
mods/bfheroes/, thenmods/bf2/, then the install root (addPathinserts at the front,0x0064d340). This is howInit.con, the levelInfofolders and the loose menu images are found. - Archives shadow loose files at the same path, which is why a mod that wants to replace one file has to ship it in an archive. While the BF2 client loads a level it even skips loose files except names with
png,@HOME@or@ROOT@(read mode "archives only",BF2.exe!0x004d2e90).
A level adds its own pair: GameLogic::loadLevel (BF2.exe!0x004f30d0, bf2-fs startup.rs load_level_archives) unmounts the previous level's archives (*levels), mounts <level>/server.zip and, on the client, <level>/client.zip at the level folder, and runs the level's own archive scripts if it has any. Mounting is only allowed while those scripts run; anything else gets "not supported in runtime".
The layers bf2-rs adds (not retail)#
| Layer | Asked | What it is | Code |
|---|---|---|---|
| overlay | before everything | the editor's writable layer: files saved by the web editor shadow the archives, deleted paths are tombstoned; --overlay DIR natively, OPFS /overlays/<game>/<name>/ in the browser | bf2-fs overlay.rs |
| enhanced packs | after the overlay | opt-in asset packs (the remaster's HQ textures): folders of loose files by virtual path with an index pack_index.txt (<path> TAB <size> TAB <tag>); they replace files, never directory listings | bf2-fs packs.rs |
| web file system | instead of the disk | the browser build serves the same install from published content-addressed objects: an archive's entries arrive unpacked through ByteSource::read_entry, so the mount table and every lookup stay retail's | bf2-fs vfs.rs, bf2-webfs WebVfs |
With no overlay and no pack (the default) every lookup is the original's.
Per game#
| BF2 | 2142 | Heroes 1.126 | |
|---|---|---|---|
| mods and search paths | mods/bf2/; Special Forces mods/xpack/ falls back to mods/bf2/, then the root | mods/bf2142/ (and its booster packs) | one mod, mods/bfheroes/; nothing to fall back to |
| archive pairs | Objects_server/client.zip, Common, Menu, Fonts, Shaders, Sound | the same scheme; Northern Strike adds *_bp1_* archives | 14 pairs: 11 Objects/<Kind>_server/client.zip (Items, Kits, Soldiers, Vehicles, ...) plus Common, Menu, Sound; Fonts and Shaders client only |
| per-level archives | server.zip + client.zip; Booster_*.zip stay mounted on three levels | the same | the same, and a variant level (village_snow, lake_night, ...) mounts its base level's archives from its Init.con (BFHeroes.exe!0x005128f9 allows mounting around that run; startup.rs mount_level_init_archives) |
| file manager | bf2_w32ded.exe!0x0064e460, BF2.exe!0x006ac1a0 | BF2142.exe!0x004373e0: the same up to the layout | Heroes' copy, same lookups |
| menus | .swf in Menu_client.zip | .dfm (encrypted SWF) in Menu_*.zip | two .dfm movies in Menu_server.zip, 6,562 images in Menu_client.zip (Flash menus) |
How it is tested#
- The helpers under every lookup (
crates/bf2-fs/tests): comparing, finding and equating names without case, each written from Battlefield 2's listing, and run again in a 2142 process for the twin. - The content check's hashing (
md5_update_final_hex_bf2.rs): the update, the final padding and the text form, each read to its end beside its port. - In use: every test that reads a shipped level or mesh goes through the archive reader, so a wrong lookup fails those.
None of this page's ten addresses stands in a test's own text: the mount order and the server/client split are proven by levels that load and by scenarios, which the count calls any, not strict (parity).
Where it is read#
| Step | bf2-rs |
|---|---|
| zip reading | bf2-fs zip.rs ZipArchive |
| mount table, lookups, listings | bf2-fs manager.rs FileManager (open, find_file, find_files, mount_archive) |
ServerArchives.con / ClientArchives.con | bf2-fs archives_con.rs |
| start-up and level mounting | bf2-fs startup.rs |
| the picture | crates/bf2-fs/examples/mount_json.rs |
The full analysis with every address and the open questions is notes/subsystems/filesystem.md. What the files inside the archives are: meshes, textures, animations, terrain, effects, Flash menus.
docs/dev/assets/archives.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.