Repository navigation
Save Data
What the save structures contain, where they live in memory, how they reach the disk and how a loaded game is set up. Field roles come from the repository's reconstruction (src/application/BF2/gf/data/*.h): the game's own member names are not in the executable, so each field is unknownXX (its byte offset) with a role that the code around it implies. Every role below is therefore inferred unless the text says a name comes from the game. Offsets and sizes are checked by static_assert in the headers against matched functions. Snapshot: main at commit a313ecb66; see Home for the reading guide.
| Record | Size | Content |
|---|---|---|
SDataSystem (gf_data_system.h) |
0x10 |
a version word and the real time of the save |
SDataGame (gf_data_game.h) |
0x117690 (1,144,464 bytes) |
the whole game state |
SDataSave |
0x1176a0 |
SDataSystem (as base class) followed by SDataGame at offset 0x10: this is the save file |
SDataOption (gf_data_option.h) |
0x88 |
the option menu settings; a separate file |
-
Version check.
SDataSystem::unknown00andSDataOption::unknown00hold the constant0x3a15b(237915, namedSAVE_UNKNOWN_237915in the repository, role "save data version").GfGameLoad::execGameLoadBlockForDebugandexecOptionLoadBlockForDebugreturn whether the loaded version word equals that constant; before reading, the load code sets the word to 0 so that a failed read is detected (src/application/BF2/gf/game/gf_game_load.cpp). -
Real time.
RealTimeis a time stamp of the save, packed into bit fields from the system clock (GfFieldTime::getRealTimereadsml::TimeUtil::getTime).GfGameUtilSaveData::setupGameSaveDatafills bothSDataSystem::unknown08andSDataGame::unknown10ad68with it (src/application/BF2/gf/game/gf_game_util_save_data.cpp).
Offsets in bytes from the start of SDataGame. Capacity values are the array sizes in the header.
| Offset | Size / capacity | Inferred role |
|---|---|---|
0x00 |
u32 | money |
0x04 |
u32 | landmark point |
0x10, 0x20
|
Vec3, f32 |
landmark position, landmark rotation Y |
0x24 |
u16 | time stop |
0x26, 0x28
|
u16, u16 | start-chapter-save, event-chapter-save (see "Chapter saves") |
0x2c |
16 x SDataDriver (0x5a0 each) |
drivers |
0x5a2c |
422 x SDataBlade (0x8a4 each) |
Blades; valid Blade ids are 1001 to 1422 (GfDataBlade::isValid) |
0xe9884 |
unknown124 (0x54) |
party: 10 members of (driver, hierarchy driver, hierarchy blade), leader and saved leader with their object types, party gauge, two "clear Rex blades" |
0xe98d8 |
ItemBox (0x122ec) |
the item box (see below) |
0xfbbc4 |
GameFlag (0xdc20) |
the game flags (see below) |
0x1097e4, 0x1097e8
|
QuestID x 2 |
scenario quest, selected quest |
0x1097f0 |
unknown118 (0xd0) |
map state: saved positions of the 3 party drivers and 3 Blades, their rotations, a "save position" and the map-jump id (see "What a save stores") |
0x1098c0, 0x1098c4
|
GameTime, ElapseTime
|
game clock, elapsed time |
0x1098c8 |
unknown122 (0x260) |
mercenary team |
0x109b28, 0x109b2c
|
f32, u32 | player camera distance, game clear count |
0x109b30 |
FixedVector<unknown106, 128> |
task achievements: (quest, purpose, task index) triples, 0xc bytes each |
0x10a138 |
256 x QuestData (4 bytes), count at 0x10a538
|
order parent quests |
0x10a53c |
64 x unknown119 (0x20) |
map infos |
0x10ad3c |
u32 | ether |
0x10ad40, 0x10ad44
|
f32, f32 | achievement counters: distance walked, distance swum |
0x10ad48, 0x10ad4c
|
u32, u32 | assure point, assure count (Blade creation, see Blade-Creation) |
0x10ad50 |
u16 | rare Blade appear type (Blade creation) |
0x10ad54 |
u32 | coin |
0x10ad58 |
u32 x 4 | saved HP |
0x10ad68 |
RealTime |
real time of the save |
0x10ad70, 0x10ae74, 0x10ae78
|
f32 x 3 | camera height, yaw, pitch |
0x10ad74 |
0x100 bytes | block copied wholesale by GfGameUtil::setupNewGameParam (role not established) |
0x10ae7c |
u8 | camera free mode |
0x10ae7d |
u8 | "hikari current" (which of the two Blades that share a slot is out, see below) |
0x10ae7e |
u16 | auto event after load |
0x10ae80, 0x10ae81, 0x10ae82
|
u8 x 3 | collect flag (new version), clear-save-data marker, camera side |
0x10ae84 |
500 x unknown125 (0x64), count at 0x1171d4
|
saved events |
0x1171d8 |
300 x unknown107 (4 bytes), count at 0x117688
|
achievement popups waiting (blade, achievement, level) |
SDataGame has gaps with no reconstructed role (for instance 0x08 to 0x10 and a 0x2d0-byte gap between the Blade array and the party). The constructor SDataGame::SDataGame() (0x7100143f28, 4408 bytes) and the copy assignment operator= (0x7100294798, 1756 bytes) are not decompiled yet, so the default values of a new game's save data are not shown.
Inferred roles: idea set (SDataIdea, 0x20), activate state, id, Blade set slot, 5 Blade ids, 5 rows of 3 skills with a level, 5 hidden skill rows, level, max HP, strength, ether power, dexterity, agility, luck, physical and ether armour, critical rate, guard rate, experience, battle experience, skill points, total skill points, 28 weapon-type records (3 slot arts, weapon points, total weapon points), arts levels (0x2f0-0x570), a scenario mask, attached-party flag, default accessory flag, kizuna ring completion flags (GfDataDriver::setKizunaringComplete), 2 accessories, 3 "pouch" slots (SDataPouch: a float time and an item) and a 28-bit set of activated weapon types.
Inferred roles: activate state, creator, set driver, id, born time, idea set, trust point and rank, 3 arts and 3 N-arts (unknown108: id, level, max level, release level), extra arts, 3 skills and 3 field skills, extra parts, 3 + 3 + 3 + 1 achievement tracks (AchievInfo, 0x90 each), 2 favourites, 3 equipped orbs, hana (equip) data, equip power rank, race and gender, an icon id, and the resource names of the models and motions as 16-character strings.
Fixed arrays of 12-byte item records (index and type bits, a count of 10 bits, an equip flag, a time, a serial number) per item type. Capacities: 200 weapon chips, 900 equipments, 500 equipped orbs, 200 salvage items, 500 precious items, 200 information items, 100 events, 500 collection items, 200 treasures, 500 empty orbs, 500 favourite items, 200 crystals (crystal-list type), 200 boosters, 200 each of hana roles, attributes, arts enhancements and N-arts sets, and 700 hana assist items. The type names in the repository (for instance "crystal list", "booster", "hana role") are its inferred roles; the game's names are not known.
Layout (gf_data_option.h): version word at 0x00; eight option bytes at 0x04 (compared byte by byte by GfMenuObjOption::MainListener::reciveEvent, reset to their defaults by SDataOption::unknown001, whose last byte defaults to true; what each byte means is not established); 0x0c to 0x4b not reconstructed; SSoundUiOption at 0x4c (0x1e bytes); 0x6a to 0x88 not reconstructed.
SSoundUiOption holds 13 volume values stored as u16 (SSoundUiOption::clear fills them from the master volumes of GfMasterVolume, each float multiplied by 255): event voice, event cutscene, event BGM, event SE, game BGM, game environment, game weather, game SE, player voice, enemy voice, "nare" voice (the name is the game's; probably narration, [INFERENCE]), system, menu BGM. After them: a 16-bit value at 0x1a that clear sets to 0x80 and a flag at 0x1c that clear sets to true (roles not established), and a last byte (0x1d) that GfGameUtilSaveData::setupOptionSaveData fills with the selected language type (fw::LangUtil::getLangType()): the language choice is stored in the options file, at offset 0x69 of the record.
GameFlag (gf_game_flag.h) is a packed store of story and world progress, 0xdc20 bytes inside the save:
| Width | Storage | Capacity (GfGameFlag::getMaxFlag) |
|---|---|---|
| 1 bit | bit set | 0x10000 |
| 2 bits |
u32 words |
0x10000 |
| 4 bits |
u32 words |
0x2000 |
| 8 bits | bytes | 0x2000 |
| 16 bits | u16 |
0xc00 |
| 32 bits | u32 |
0xd08 |
-
GfGameFlag::setLocal(GameFlag&, size, index, value)(matched) writes a flag by width and index inside that width; the overloadssetLocal(size, index, value)and the twogetLocal(0x71002b8664,0x71002b87e0,0x71002b8a40) are not decompiled yet. -
GfGameFlag::getFlag(id)/setFlag(id, value)take one global id and split it: ids0to0xd07are 32-bit flags,0xd08to0x1907are 16-bit flags (index minus0xd08),0x1908to0x15907are 8-bit flags and everything above is a 1-bit flag counted from0x15908(getFlagInfo; the repository names the end valuesflag word end,flag short end, ...). The 2-bit and 4-bit flags exist in storage (setLocalhandles them) but no global id range reaches them in the matched code. [Observation] The 8-bit id range is0x14000ids wide while the byte array in the save holds0x2000bytes: either most of that id range is never used or ids are wrapped somewhere not shown. The code read does not decide this. -
The scenario flag.
GfGameFlag::sendCallback(size, index, value, oldValue)(matched) callsGfEvent::callChangeScenarioFlag(value, oldValue)when the flag is the 16-bit one with index 1; the repository names it "flag16 scenario". It is the story-progress counter that listeners follow (GfEvent::gevChangeScenarioFlag, overridden for example byGfGameManager). Which function callssendCallbackis not shown (the not-yet-decompiledsetLocal(size, index, value)is the likely caller [INFERENCE]).GfDataManager::clearfires the same event after clearing so that listeners see the change. - The event system and quest data refer to flags by id through
GfGameFlag::getFlagandGfGameCond(conditions).
GfDataManager (gf_data_manager.cpp) is a singleton built early by GfManager::initialize (see Engine-Overview). Its initialize builds, in order, GfDataBdat (see BDAT-Data), GfGameFlag and GfDataStore. GfDataStore (gf_data_store.cpp) holds the live SDataSystem, SDataGame and SDataOption; everything in the GfData* accessor classes (GfDataDriver, GfDataBlade, GfDataParty, GfDataBladeCreate, ...) reads and writes through GfDataManager::getDataGame(). See Drivers-Blades-Party for those accessors.
-
GfDataManager::clear(): runsGfDataStore::clear(system, game and option reset) andGfGameFlag::clear(amemsetof the flag area of the liveSDataGame), then fires the scenario-flag callback. -
GfDataStore::initGameData: constructs a freshSDataGamein place, sets the development level of each of 8 nations to 0 (GfDataDevelop::setLevel,NATION_UNKNOWN_8), sets the mercenary level to 0, callsGfDataUtil::initializeSaveDataDriverAndBlade(not decompiled yet) and sets one field of every map-info entry to true for map idMAP_UNKNOWN_10and false for the others (role of that field not established). -
GfDataStore::setGameData(system, game, option)(called byGfDataManager::setupGame): copies the given records into the live ones, then refreshes Blade save data and the BDAT-derived parameters (GfDataUtil::refreshBladeSaveData,refreshBdatParam) and settles which of two special Blades is the current one (constantsBLADE_HOMURAandBLADE_HIKARI): if driver 1 currently holdsBLADE_HOMURAwhileBLADE_HIKARIis activated in the party, "hikari current" is cleared when it was set; if driver 1 holdsBLADE_HIKARIwhileBLADE_HOMURAis activated and the flag was not set, it is set. It also clears the clear-save marker (0x10ae81).
GfDataSave (src/application/BF2/gf/data/gf_data_save.cpp) builds the file names. Strings are the game's.
- Folder
save:/. - Game save:
bf2savefile. Option file:bf2option. Chapter saves:bf2chapter. Extensions:.savfor the binary form and.xmlfor an XML form (both name builders exist). -
Slots.
SAVESLOTis anint; the matched code distinguishes four kinds of value, tested in this order:-1= none (empty path),22= the default slot (file name without a number),0to9= numbered slot (file name + the digit), and anything else (10or more) = chapter save (save:/bf2chapter<slot - 8>for writing; for loading the path is/work/gf_select/bf2chapter<slot - 8>, a development folder). The namesSAVESLOT_UNKNOWN_10andSAVESLOT_UNKNOWN_22are the repository's labels ("chapter first", "default"). - The Blade creation screen has a save step (
GfMenuObjBladeCreate::seqSave) that requests a save into slot 22 (see Blade-Creation).
File: src/application/BF2/gf/game/gf_game_save.cpp.
-
createGameSaveData(path): allocatessizeof(SDataSave)bytes (aligned to 16), builds a freshSDataSave, fills it from the live state withGfGameUtilSaveData::setupGameSaveData(see "What a save stores" below), picks the path withGfDataSave::getFileNameForSaveBin(path, slot), then callsGfDataManager::setupGame(&save, &save.game, nullptr), so the live data is replaced by what was just saved (this is how derived data such as the Blade save data is refreshed), copies the three parts into the static mirror_gfgsv::s_SDataSaveand, for slot 22, callsGfManager::setSaveDataCreated()and refreshes the title screen's save buffer (GfGameUtilSaveData::setTitleSaveData). - A write mode picks how the file is written:
execGameSaveNonBlock(asynchronous, finished byOnFileEvent),execGameSaveWithMicroThread(starts the write, waits for it withGfSleep(1), then finishes) orexecGameSaveBlockForDebug(blocking write). The writer isml::DevFileTh::writeFile/writeFileBlock; the mode is stored inunknown08(1 asynchronous, 2 micro-thread, 3 blocking; 0 idle, tested byisBusy). - Options are saved the same way:
createOptionSaveDataallocatessizeof(SDataOption)rounded up to 16, copies the live options throughGfGameUtilSaveData::setupOptionSaveData(which also takes the sound options from the live sound settings), or takesgetValidOptionData()when the game runs in the theatre or advertising mode. -
GfGameSave::makeNewGameSaveData()re-constructs the static mirror and copies the option data from the live ones.
src/application/BF2/gf/game/gf_game_util_save_data.cpp. It builds the record to write from the live state:
- It first computes a "clear" condition: the scenario flag is above
10042, or the clear-save marker (SDataGameoffset0x10ae81) is already non-zero. - It copies the system record (
getSaveData(SDataSystem&): version word and real time) and the whole liveSDataGame. -
Not cleared (the normal case): it records where the party stands. For each of the 3 party slots it asks the driver's object and the current Blade's object for position and rotation and stores them in the map record (
unknown118; the rotation is stored as a vector(0, degrees, 0)); the first stored position is replaced byGfGameScene::getEnableSavePos(); the current map-jump id is stored; the marker is set to 0. It also stores the player camera: yaw, pitch, distance, height, side and free-mode flag, throughGfGamePlayerCamera::getSaveYaw/Pitch/Distance/Height/SideandisSaveFreeMode. This is what makes the camera and the position come back after a load. -
Cleared (scenario flag above 10042 or marker set): the marker is set to 1, the 16-bit scenario flag (index 1) of the saved copy is set to 10032, and, when the title screen exists, the saved copy takes its story data from the title screen's save buffer instead of the live game: about 16 ranges of game flags (2-bit, 1-bit and 8-bit ranges, with indices such as
0x27ato0x662,0xfa2to0x11fa, 15,000 flags from0x3690), the scenario and selected quests, the 256 order parent quests with their count, and the two chapter-save fields (0x26,0x28). [INFERENCE] This looks like how the game keeps a "clear save" from losing the pre-ending story position when you keep playing after the ending; the code shows the mechanism, not its purpose. - In both cases it stores the game clock, elapsed time and time-stop flag from
GfFieldTime, and the real time in both records.
GfGameUtilSaveData::getSaveData(SDataGame&) is the short version: it copies the live game data and refreshes the map record with the same position helper.
File: src/application/BF2/gf/game/gf_game_load.cpp.
GfGameLoad is constructed with a slot or a path. execGameLoadNonBlock allocates a buffer the size of SDataSave, sets its version word to 0, builds the file name for the slot and starts an asynchronous read (ml::DevFileTh::readFile). OnFileEvent handles completion and phaseBinData finishes: it copies the buffer into the destination record, mirrors the three parts into _gfgsv::s_SDataSave, and empties the two big temporary vectors (task achievements and mercenary list) of the buffer before freeing it. The same exists for the options and for micro-thread and blocking modes. Starting the game with the loaded data is GfManager::setupContinueGame, below.
src/application/BF2/gf/gf_manager.cpp:
-
setupDeafult()(spelled so in the game):GfDataManager::clear,GfAssetManager::clear,GfFieldManager::clear,GfGameManager::clear,GfDataManager::setupGame(null, null, null),GfGameManager::setupGame,GfFieldManager::setupGame.setupEventTheaterandsetupReturnTitleare just this. -
setupNewGame(): marks the start kind as "new game" and builds the starting party (GfGameParty::setupNewGameParty). -
setupPowerNewGame(system, game, option):GfGameUtil::setupNewGameParam(game),GfMenuManager::setupGame, thensetupNewGame.GfGameUtil::setupNewGameParam(src/application/BF2/gf/game/gf_game_util.cpp, matched, 6820 bytes) copies selected parts of a givenSDataGameinto the live one: the drivers, the Blades, assure point and count, rare Blade appear type, money (0x00), ether, coin, the item box, the game clock and elapsed time, the camera settings, the game clear count, achievement distances, real time, task achievements, the 0x100-byte block, and then about a hundred ranges of game flags (each range given by width and index range, with no names). [INFERENCE] By its name and by the choice of copied parts (everything the player owns, not the story position), this is the carry-over of a cleared game into a new one (a New Game Plus); the game's own function name issetupPowerNewGame. -
setupContinueGame(system, game, option): marks "continue", clears everything likesetupDeafult, thenGfDataManager::setupGame(&system, &game, &option),GfGameManager::setupGame,GfFieldManager::setupGame, and resets the load timer. -
startGame(isExistSaveData, isClearGameCheck): stores whether a save exists and selects the exec state. For a continue it creates a map jump to the saved position and rotation of the first party member (GfDataParty::getSavePos(0, true),getSaveRot(0, true)converted from degrees to radians), then plays the chapter-save event if the save is a chapter save (GfDataUtil::isStartChapterSave,getEventChapterSave), otherwiseGfDataUtil::getAutoEventAfterLoad. For a new game it ends the new-game wait (GfGameEvent::finishNewGameWait). FinallyGfGameManager::setStartGame. -
GfGameManager::setupGamealso runsGfBladeManager::setupGame, which is where the rare Blade appear type is drawn when it is 0 (see Blade-Creation).
SDataGame::unknown26 and unknown28 hold "start chapter save" and "event chapter save". A chapter save is a save that, when loaded, starts a stored event instead of putting the player on the field directly (GfManager::startGame above). The repository's debug title states and the gf_select folder suggest chapter saves are mostly a development and debug device. This is not established beyond the code paths named.
GfGameUtilSaveData::getSaveDataMenuInfo (0x7100355d30, 96 bytes), SDataGame::SDataGame() and operator= (above), GfDataUtil::initializeSaveDataDriverAndBlade (0x710029527c, 1168 bytes).
BDAT-Data, Blade-Creation, Drivers-Blades-Party, World-Progression, Engine-Overview