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

Assets and file formats

BF22142Heroes

Every asset the three games ship is read by a bf2-rs crate that mirrors the original loader. This page is the map: which crate reads which file, and where its layout is written down. The three games share the formats; where a later game changed one, the crate handles both.

What goes into a game asset#

A jeep in Battlefield Heroes is not one file. It is a CON template tree that names a mesh, a collision mesh, textures, sounds and child objects, each read by its own loader. These pages take one real example of each kind from the Heroes 1.126 install and show what the engine reads, with pictures our own readers drew:

Where the files come from#

The games read their content through a virtual file system: the .zip archives of the install (and of a mod), mounted in a fixed order, plus loose files on disk. crates/bf2-fs reimplements that file manager (FileManager, ZipArchive, Win32FileSystem), so a path resolves to the same archive entry as in the original. The browser build reads the same tree from published content-addressed objects through crates/bf2-webfs (WebVfs), mounted into bf2-fs through its platform hook.

Formats and their readers#

FilesWhat they holdReaderNotes
*.zip, loose filesthe archives and the mount ordercrates/bf2-fsnotes/subsystems/filesystem.md, archives
.staticmesh, .bundledmesh, .skinnedmeshrender meshes: buildings, vehicles, soldierscrates/bf2-mesh (MeshFile)notes/formats/meshes.md, meshes
road .meshcompiled road meshescrates/bf2-mesh (RoadMesh)notes/formats/road-splines.md
.collisionmeshcollision geometry per LODcrates/bf2-collisionnotes/formats/collisionmesh.md
.occ, Roads/Splines/*_compiled.datoccluder planes, road template datacrates/bf2-geomdatanotes/formats/occluders.md
.ddstextures (3D, HUD, fonts)crates/bf2-texturenotes/formats/textures.md, textures
.ske, .bafskeletons and bone animationscrates/bf2-animnotes/formats/animation.md, animations
.fxthe D3D9 effect sources the renderer compilescrates/bf2-shadersmaterials
.wav, .ogg, .eaxsounds, music, reverb presetscrates/bf2-audio, crates/bf2-vorbisnotes/formats/audio.md, sounds
.dif, .fontbitmap fonts of the HUD, menus and consolecrates/bf2-fontnotes/formats/fonts.md
.bikintro and menu moviescrates/bf2-binknotes/formats/bink.md
.swf, .dfmFlash menus (SWF 7, ActionScript 2)crates/bf2-ui, Heroes natives in crates/bfh-uinotes/subsystems/menu-flash.md, Flash menus
.con, .tweak, .incobject templates and settingscrates/bf2-con, crates/bf2-objectsThe CON system, objects
effect .tweak, particle textureseffect bundles and particle systemscrates/bf2-effects, crates/bf2-rendernotes/subsystems/effects.md, effects
heightmaps, terraindata.raw, .taiterrain and level datacrates/bf2-terrain, crates/bf2-worldnotes/formats/terrain.md, terrain, Level authoring, editor plan, levels

How the pictures are made#

Every picture on the asset pages is generated by tools/devwiki/asset_examples.py from the retail Heroes archives (read-only) through the bf2-rs readers the game itself uses, run as small cargo examples:

AssetReader (crate / file / function)Example tool
.staticmesh .bundledmesh .skinnedmeshbf2-mesh template.rs MeshFile::parsecrates/bf2-mesh/examples/mesh_json.rs
.collisionmeshbf2-collision lib.rs CollisionMesh::parsecrates/bf2-collision/examples/collision_json.rs
.dds .tgabf2-texture dds.rs Dds::parse, decode.rs decode_rgba8, lib.rs decode_d3dxcrates/bf2-texture/examples/texture_mips.rs
.wav .ogg, envelopesbf2-audio soundfile.rs load (Ogg through bf2-vorbis), envelope.rs Envelope::evalcrates/bf2-audio/examples/sound_pcm.rs
templates, placed objectsbf2-editor level.rs LevelData::object_json / template_jsonbf2_editor --object / --template
.ske .bafbf2-anim ske.rs Skeleton::parse, baf.rs BoneAnimation::decode, sample.rs Clip::sample, pose.rs SkeletonPose::update_worldcrates/bf2-anim/examples/anim_json.rs
archives, mount orderbf2-fs startup.rs mount_mod / load_level_archives / mount_level_init_archives, manager.rs FileManager::opencrates/bf2-fs/examples/mount_json.rs
.dfm .swf menusbf2-ui swf.rs decode_dfm, the Ruffle-based player walkthrough.rs Session::screenshotcrates/bf2-ui/player/examples/menu_frame.rs
heightmaps, terraindata.raw, patch textures, roadsbf2-terrain heightdata.rs apply, terraindata.rs parse, terrain_con.rs naming; bf2-mesh road.rs RoadMesh::parsecrates/bf2-terrain/examples/terrain_layers.rs, mesh_json.rs
effect templates, sprite atlasesbf2-editor LevelData::template_json, bf2-texture decode_rgba8bf2_editor --template, texture_mips.rs

Python only lays the results out (numpy and matplotlib). The script has no clock and writes PNGs without a date, so a re-run produces the same bytes; --check proves it:

regenerate the pictures (zoomie, retail Heroes 1.126 installed)
python tools\devwiki\asset_examples.py            # writes docs\dev\assets\img\*
python tools\devwiki\asset_examples.py --check    # re-runs into a temp folder and compares
python tools\devwiki\build.py                     # the wiki, with the pictures copied next to the pages

The examples: the village house townhousemedium_e_03, the Heroes jeep bri_jeep_willys, a royal hero's default items (BRI_M_Head001, BRI_M_Body001, ...), the hero skeleton with the cheer emote, the mount table of village_snow, the main menu mainMenu_west.dfm, the terrain of village and the explosion e_exp_medium. The menu frame needs the player's own cargo workspace (crates/bf2-ui/player, Ruffle in third_party/ruffle-bf2). How the renderer draws them frame by frame is the subject of the render pipeline page; the scripts that create them are the CON system.

How it is tested#

This page explains; it holds no code of its own. Each format's page says how its reader is tested: archives, meshes, textures, terrain, animation, sound. The common pattern: every shipped file of the kind is read and must be consumed exactly, and where the port also writes the format, writing a parsed file gives the file back byte for byte. The wiki's test checks that every link and anchor on it leads to a page of the build and that its diagrams are the ones the script draws.

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-meshrender mesh files (static, bundled, skinned, roads)
crates/bf2-uithe Flash front-end menus: native interface and host model
crates/bf2-animskeletons, bone animations and the animation system
crates/bf2-audiothe sound system: decoders, sound templates, mixing rules
crates/bf2-collisioncollision mesh files
crates/bf2-terrainterrain and level data formats
crates/bf2-texturetexture files and texture atlases

Files this page names: crates/bf2-mesh/examples/mesh_json.rs, crates/bf2-collision/examples/collision_json.rs, crates/bf2-texture/examples/texture_mips.rs, crates/bf2-audio/examples/sound_pcm.rs, crates/bf2-anim/examples/anim_json.rs, crates/bf2-fs/examples/mount_json.rs, crates/bf2-ui/player/examples/menu_frame.rs, crates/bf2-terrain/examples/terrain_layers.rs.

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