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

Settings and profiles: where the game keeps what you chose

BF22142Heroes

Refractor 2 has no settings file format. Every setting that is saved is saved as console commands, in a script that the game runs again at the next start. There are two layers: a small typed store that the engine reads, and a set of settings objects behind the options screens, each of which writes one file into the player's profile folder. This page covers both, and the handful of oddities a port has to copy to write the same files.

Where a setting lives an options screen audio, video, controls, general: each edits one settings object the settings object its fields, a constructor, a reset; a writer that prints console commands a file of the profile Audio.con, Video.con, Controls.con, General.con: run again when the profile is activated the settings repository seven typed maps by name; what the engine itself reads Usersettings.con the nine settings registered as saved, written when the client shuts down BF2.exe!0x0040fdf0 (the repository), 0x004076b0 (defaults), 0x006a3540 (save), 0x004ab1d0 (a profile's activation)
Where a setting lives, from the options screen to a line of a script.

The settings repository#

The first thing the engine creates (bf2_w32ded.exe!0x00409730, BF2.exe!0x0040fdf0), registered under a name with a typing error that the port keeps, SettingsRepostitory. It is seven independent maps from a name to a value: int, float, unsigned, string, bool, and vectors of three and four. Names are case-sensitive. The same name may exist in several of the maps at once.

Reading a setting never creates it: get answers the stored value or the caller's default.

The engine's defaults#

Registered before the command line is read (0x00403bd0):

NameDefaultSaved
GSModDirectorymods/bf2
GSLevelDirectoryLevels/
GSViewDistance850
GSPlayerNameDefaultPlayerNameyes
GSInterpolationTime100yes
GSExtrapolationTime1200yes
GSDefaultLatencyCompensation0.1yes
GSUseObjectCachetrueyes
GSExtrapolateFrame, GSShowNetGraphfalseyes
GSPerfLogAtPlayerCount30yes
GSUseClientSidePredictiontrueno
GSUseLatencyCompensationfalseno
GSFullScreentrueno

Nine settings are registered as persistent (the eight marked above and one for the anti-cheat client), and those nine are all that Usersettings.con ever holds. The command line writes more settings, and the level code reads others by name.

Usersettings.con#

Loaded while the subsystems start; saved when the client shuts down. The dedicated server never saves it. The game ships no such file: it appears after the first run.

The writer emits a three-line header and then one line a registered name, in name order:

text
rem
rem Settingsfile automatically saved by bf2
rem
SettingsManager.floatSet GSDefaultLatencyCompensation 0.100000
SettingsManager.U32Set GSExtrapolationTime 1200
SettingsManager.stringSet GSPlayerName "DefaultPlayerName"
SettingsManager.boolSet GSUseObjectCache 1

(four of the nine lines shown). A SettingsManager.*Set command acts only on a registered name: a line for anything else returns 0 and changes nothing. You cannot add a setting by editing the file.

Profiles#

A profile is a folder under the player's documents folder (Battlefield 2/Profiles/<number>), and each file in it is a console script written by one settings object:

FileConsole objectWhat it holds
Profile.conLocalProfilethe profile's name and nick, played time, login count
General.conGeneralSettingsHUD and crosshair options, bot settings, the server browser's filters, favourites and history: 30 properties
Audio.conAudioSettingsvolumes, provider, quality, voice chat: 15 properties (voices and space, voice chat)
Video.conVideoSettingsresolution, antialiasing, eight quality levels, the view distance scale
Controls.conthe control mapskey bindings (input)
ServerSettings.consvthe settings of a server you host from the menu: 50 properties
Haptic.conHapticSettingsa haptic controller's 224 settings

Profiles/Global.con names the default profile. Activating a profile runs Profile.con, then each settings object's file, then the demo bookmarks and the profile's map list, and sets GSPlayerName to the profile's nick.

How a float is written#

The settings objects write through a C++ text stream, and the port's writer reproduces its habits so that a file the original wrote is written back byte for byte:

  • six significant digits, as %g: 0.5, 1.23457e+006;
  • an exponent has three digits: 1e-005;
  • negative zero prints 0;
  • a NaN prints in the old Microsoft spelling, 1.#QNAN, and infinity 1.#INF;
  • a bool prints as a number; line ends are single line feeds.

Some lines are written only sometimes: the audio object writes its "force number of voices" line only for a positive value.

A fresh profile's defaults#

Each settings object has a constructor and a reset, and the options screen's "defaults" button is the reset.

  • Video starts at 800 x 600 at 60 Hz, antialiasing off, every quality at its middle level. The real defaults come from the renderer's hardware detection, which picks a low, medium or high preset; that detection is not reimplemented, and the port resets Video without a renderer for now.
  • Audio picks its quality from the machine's memory (0x004b0b80): Low below 768 MB, else Medium.
More than 4 GB counts as none

The memory is read with a 32-bit call. On a machine with more than 4 GB it reports the largest 32-bit number; the original then adds half a megabyte to round, the sum wraps to zero, and the default sound quality comes out as Low: 16 voices on every modern machine, until the player changes it. The port computes the same.

What differs per game#

2142
Battlefield 2142 and Heroes

The repository and the console-script files are the same idea in all three. 2142 has its own profile folder and volume defaults (music and help voice at 0.5); Heroes keeps a hero's data on its account service's side, which is outside this wiki, and its local options in the same kind of script.

What the port has#

PartState
the repository, the engine's defaults, the Usersettings.con writerverified from the code; the port's tests reproduce the file
the settings objects' writers, console setters and copiesverified in-process against the original; files the original wrote are re-saved byte for byte
constructors and resetsverified: 960 written texts and 960 object dumps, no difference
the activation order of a profile's filesfrom the code
the renderer's video presets and hardware detectionnot reimplemented
the event a changed setting raisesnot modelled

How it is tested#

The original's settings objects are constructed, set by random console calls, written and reset inside the original program's own code, and the port's objects are put through the same calls: the written texts and the objects' bytes are compared (the oracle). The Usersettings.con test writes the defaults and compares the text with the one above.

In the code#

WhatWhere
the repository and Usersettings.concrates/bf2-engine/src/settings.rs
the settings objects, their tables and defaultscrates/bf2-engine/src/ (profile_settings, profile_defaults, generated settings_tables.rs, settings_defaults.rs)
the console's SettingsManager commandscrates/bf2-runtime
control mapscrates/bf2-input

Notes: notes/subsystems/settings-profiles.md, notes/subsystems/input.md (section 9).

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