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

BF22142Heroes

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:

mods/bfheroes/ServerArchives.con and ClientArchives.con (retail, first lines)
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\Effects

Most 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.

lookup order of FileManager::open: the first layer holding the path answers 1 overlay (not retail; bf2-fs overlay.rs) the editor's writable layer: --overlay DIR natively, OPFS /overlays/<game>/<name>/ in the browser; tombstones hide paths below 2 enhanced packs (not retail, opt-in; bf2-fs packs.rs) folders of loose files by virtual path, indexed by pack_index.txt (<path> TAB <size> TAB <tag>); replace files, never listings 3 mount table: archives at their mount point, in mount order (bf2-fs manager.rs, retail) mount point archives (first mounted answers first; server script runs before client) common/ common_server.zip 30 common_client.zip 83 fonts/ fonts_client.zip 586 levels/village/ server.zip 33 client.zip 57 <- Levels/village_snow/Init.con (Heroes: the variant mounts its base level) levels/village_snow/ server.zip 22 client.zip 33 <- the level load (GameLogic::loadLevel) menu/ menu_server.zip 56 menu_client.zip 6562 objects/common/ common_server.zip 83 common_client.zip 26 objects/effects/ effects_server.zip 1224 effects_client.zip 243 objects/items/ items_server.zip 5042 items_client.zip 4967 objects/kits/ kits_server.zip 29 kits_client.zip 2 objects/roads/ roads_server.zip 18 roads_client.zip 18 objects/soldiers/ soldiers_server.zip 2878 soldiers_client.zip 4 objects/staticobjects/ staticobjects_server.zip 1081 staticobjects_client.zip 592 objects/vegitation/ vegitation_server.zip 100 vegitation_client.zip 61 objects/vehicles/ vehicles_server.zip 97 vehicles_client.zip 77 objects/water/ water_server.zip 3 water_client.zip 2 objects/weapons/ weapons_server.zip 1551 weapons_client.zip 547 shaders/ shaders_client.zip 114 sound/ sound_server.zip 8 sound_client.zip 1044 _server / server.zip (ServerArchives.con) _client / client.zip (client only) 4 search paths: loose files (retail) tried in this order: "mods/bfheroes/", "mods/bf2/", "" (the empty one = the install root) lookups (bf2-fs examples/mount_json.rs after mount_mod + load_level_archives + mount_level_init_archives) Objects/Vehicles/bri_jeep_willys/bri_jeep_willys.tweak -> mods/bfheroes/objects/vehicles_server.zip Objects/Vehicles/bri_jeep_willys/meshes/bri_jeep_willys.bundledmesh -> mods/bfheroes/objects/vehicles_client.zip Levels/village_snow/terraindata.raw -> mods/bfheroes/levels/village_snow/client.zip Levels/village/HeightmapPrimary.raw -> mods/bfheroes/levels/village/server.zip Menu/External/FlashMenu/mainMenu_west.dfm -> mods/bfheroes/menu_server.zip Init.con -> loose file mods/bfheroes/Init.con Levels/village_snow/Info/village_snow.desc -> loose file mods/bfheroes/Levels/village_snow/Info/village_snow.desc ServerArchives.con: 14 mounts; ClientArchives.con: 16 mounts; Levels/village_snow/Init.con: 2 mounts
The sources of Heroes village_snow in lookup order: the two layers bf2-rs adds (dashed), the retail mount table after the mod start-up and the level load, the search paths for loose files, and where seven example paths resolve. Generated by bf2-fs examples/mount_json.rs on the retail install.

How a lookup resolves#

  1. The mount table is a sorted map from mount point to the archives mounted there. open takes 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 selection 0x0064c780, client BF2.exe!0x0069a3b0).
  2. Only if no archive has it, the search paths are tried for a loose file, the most recently added first: for Heroes mods/bfheroes/, then mods/bf2/, then the install root (addPath inserts at the front, 0x0064d340). This is how Init.con, the level Info folders and the loose menu images are found.
  3. 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)#

LayerAskedWhat it isCode
overlaybefore everythingthe 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 browserbf2-fs overlay.rs
enhanced packsafter the overlayopt-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 listingsbf2-fs packs.rs
web file systeminstead of the diskthe 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'sbf2-fs vfs.rs, bf2-webfs WebVfs

With no overlay and no pack (the default) every lookup is the original's.

Per game#

BF22142Heroes 1.126
mods and search pathsmods/bf2/; Special Forces mods/xpack/ falls back to mods/bf2/, then the rootmods/bf2142/ (and its booster packs)one mod, mods/bfheroes/; nothing to fall back to
archive pairsObjects_server/client.zip, Common, Menu, Fonts, Shaders, Soundthe same scheme; Northern Strike adds *_bp1_* archives14 pairs: 11 Objects/<Kind>_server/client.zip (Items, Kits, Soldiers, Vehicles, ...) plus Common, Menu, Sound; Fonts and Shaders client only
per-level archivesserver.zip + client.zip; Booster_*.zip stay mounted on three levelsthe samethe 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 managerbf2_w32ded.exe!0x0064e460, BF2.exe!0x006ac1a0BF2142.exe!0x004373e0: the same up to the layoutHeroes' copy, same lookups
menus.swf in Menu_client.zip.dfm (encrypted SWF) in Menu_*.ziptwo .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#

Stepbf2-rs
zip readingbf2-fs zip.rs ZipArchive
mount table, lookups, listingsbf2-fs manager.rs FileManager (open, find_file, find_files, mount_archive)
ServerArchives.con / ClientArchives.conbf2-fs archives_con.rs
start-up and level mountingbf2-fs startup.rs
the picturecrates/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.

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