Savegame manager for X4: Foundations. Used to automatically back up your savegames, and to extract interesting information from them.
- Savegame folder monitoring and auto-backup.
- Extract useful information into JSON files.
- Process large savegames (1+ GB).
- Browser-based user interface:
- Blueprints list (owned/unowned).
- Khaa'k hives and nests list.
- Ship losses list.
- Categorized event log with search function.
- Detailed list of user-added construction plans.
- JSON files can be used by third party apps.
- Via X4 Core, OOP access to game information.
Blueprint browser (unowned shown here)
There are several tools which can be used together:
- The extraction tool
Command line tool to manually extract information from savegame files, for use in the UI or programmatically. - The manager UI
Displays all savegames and available backups. Allows easy access to the information on each save. - The savegame folder monitor
Detects new savegames. Extracts information from them, and creates a backup.
- Clone the repository somewhere.
- Run
composer install
- Rename
config.dist.php
toconfig.php
- Edit
config.php
to adjust the settings
- Execute
./bin/extract -l
to display a list of savegames. - Execute
./bin/extract -e "name"
wherename
is the save you wish to extract.
NOTE: See also the Extract tool command line section for more extraction options - extract multiple saves and more.
- Execute
./bin/run-ui
. - You should see a message that the server is running.
- Note the server URL shown.
- Open a web browser, and go to the URL.
The interface initially shows a list of files available in the game's savegame folder. Any previously archived saves are listed in the Saves Archive tab.
./bin/extract
./bin/extract -l
This will only extract those that have not been extracted yet.
./bin/extract -all
./bin/extract -e "quicksave autosave_01 save_006"
-xml --keep-xml
Keep the XML files--no-backup
Do not create a savegame backup
./bin/extract -la
Regenerates a fresh version of the JSON files, using the extracted XML fragments of an archived savegame.
NOTE: Only available if the XML fragment files have been preserved.
./bin/extract -rebuild "unpack-20230528171642-quicksave"
Where the parameter is the folder name of an archived savegame. Use
the -la
command to show a list.
The Monitor runs in the background, and observes the X4 savegame folder. When a new savegame is written to disk, it is automatically unpacked and backed up to the storage folder to access its information in the UI.
This tool is especially useful if you leave the game running unattended. If something bad happens ingame, it is easy to revert to a previous save. The big advantage here is that it is not limited to the amount of autosave slots the game has.
Simply run the following in a terminal:
./bin/run-monitor
The monitor will periodically display a status message in the terminal to explain what it's doing. If a new savegame is detected, it will say so and unpack it as well as create a backup (if enabled in the config).
If you leave your game running unattended with autosave on, each new autosave will automatically be processed as well.
CAUTION: This can quickly fill your disk if you have the
X4_MONITOR_KEEP_XML
option enabled. More information on this in the Monitor options section.
On Windows, it is possible to add the monitor to the task bar:
- Right-click
run-monitor.bat
, select Create shortcut. - Right-click the shortcut, select Properties.
- Add
cmd /c
at the beginning in the Target field. - Change the icon if you like.
- Drag the shortcut to the task bar.
TIP: This also works with the UI batch file.
Config name: X4_MONITOR_KEEP_XML
Whether to keep the extracted XML fragment files after extraction.
By default, the individual XML files created during extraction (before converting the data to JSON) are automatically deleted when done. They can be useful if you wish to study the XML structure.
Config name: X4_MONITOR_AUTO_BACKUP
Whether to create a copy of the savegame .gz
file.
If enabled, a copy of the savegame file will be stored in the archived
savegame folder, as backup.gz
.
NOTE: This only works when the compression of savegames is turned on in the game settings. For performance reasons, the Monitor does not compress uncompressed XML files.
Config name: X4_MONITOR_LOGGING
Whether to display detailed logging messages in the Monitor's command line. This is mainly used for debugging purposes when developing.
The extraction process creates a folder for each savegame
in the storage folder configured in the config.php
file,
which looks like this:
unpack-20230524194512-quicksave
^ ^
Date + time Save name
This structure means that the quicksave for example can be archived multiple times in the storage folder, to create a history of it - and incidentally, make it possible to go back to a previous version.
NOTE: This works best in combination with the savegame Monitor.
The JSON
folder under the savegame folder contains all extracted
information:
collection-celestial-bodies.json
All celestial bodiescollection-clusters.json
All clusterscollection-event-log.json
Full event logcollection-people.json
All NPCscollection-player.json
Player informationcollection-regions.json
All regionscollection-sectors.json
All sectorscollection-ships.json
All ships (player and NPC)collection-stations.json
All stations (player and NPC)collection-zones.json
All sector zonesdata-khaak-stations.json
Khaa'k stations listdata-losses.json
Player ship lossessavegame-info.json
Global savegame info
If the option to keep XML files is enabled, the XML
folder under
the savegame folder will retain the extracted XML fragment files.
These files are all original XML fragments from the savegame that
were used to extract the information.
NOTE:
{NR}
refers to a generated number assigned during extraction.
savegame.info-{NR}.xml
The savegame's info tag.savegame.log-{ID}.xml
The full event log.savegame.stats-{NR}.xml
The player's statistics.savegame.universe.component[galaxy].connections.connection[ID]-{NR}.xml
Individual connection tags in the galaxy.savegame.universe.factions-002
Faction relations.
After trying a number of technologies to parse the game's large XML files (1+ GB), I eventually settled on a mix of tools to access the relevant information. The result is a multi-tiered parsing process:
Using PHP's XMLReader, all the interesting parts of the XML are extracted, and saved as separate XML files. This works well because the XMLReader does not load the whole file into memory. The save parser also skips as many parts as possible of the XML that is not used.
Now that the XML file sizes are manageable, they are read using PHP's DOMDocument to access their information. To make the data easier to work with, all types (ships, stations, npcs) are collected in global collections (see the collection classes).
All this data is stored in prettified JSON files for easy access.
Once all the data has been collected, the data processing classes can use this to generate additional, specialized reports that also get saved as JSON data files.