Skip to content

Fog Of War

shartte edited this page Apr 6, 2015 · 9 revisions

Explored Sector Data (esd*)

Stored for each sector in the savegame directory. i.e.: esd402653192

Uses the same sector numbering format as the .sec files.

The file is basically one huge bitfield that contains 9 1-bit flags for each tile that indicate whether a sub-tile of the tile has been explored. For this purpose, tiles are divided into 3x3 subtiles.

The format as a C-Struct might look like this (with 1-byte packing):

struct ExploredSectorData {
    uint8_t allExplored; // If this is 1, the rest of the data is assumed to be 0xFF
    uint8_t exploredSubTiles[(64 * 64 * 9) / 8]; // One bit per sub-tile of a sector
};

A sector is 64x64 tiles. Each tile is 3x3 subtiles and each subtile needs 1 bit of storage. That's how we arrive at a total size of 4608 for the bitfield data.

Also interesting to know: If allExplored is 1, ToEE does not save or load the bitfield. It only saves the allExplored flag in this case.

The functions for handling ESD data are:

// Returns true if successful.
// Will also write allExplored=1 if sector is all explored (it does the check)
bool __cdecl fog_esd_save(uint64_t sectorLoc, ExploredSectorData *fogSec); // @ 1006FB50

// Indicates the result of loading the ESD
enum class EsdLoadResult : uin32_t {
  // Sector ESD exists and is not fully explored
  PartialExplored = 0,
  // Sector ESD does not exist -> must be unexplored
  Unexplored = 1,
  // Sector ESD exists but is marked as all-explored
  Explored = 2
};

EsdLoadResult __cdecl fog_esd_load(uint64_t sectorLoc, ExploredSectorData *fogSec); // @ 1006FAA0
Clone this wiki locally