mistralys/x4-core

Core files for all X4 tools.

0.0.11 2025-06-07 13:13 UTC

This package is auto-updated.

Last update: 2025-06-11 20:40:46 UTC


README

Utility classes used to access X4: Foundations game data in an OOP way. Designed to be used as a library in other projects (see X4 Tools).

Requirements

Usage

Installation

Require the package in your Composer project:

composer require mistralys/x4-core

Accessing Faction information

All factions available in the game can be accessed through the faction collection.

The faction collection

All factions are available through the FactionDefs collection class.

use Mistralys\X4\Database\Factions\FactionDefs;

echo "Available factions:" . PHP_EOL;

foreach(FactionDefs::getInstance()->getAll() as $faction) {
    echo $faction->getLabel() . PHP_EOL;
}

Faction getter methods

When working with the faction classes, dedicated getter methods exist to access factions instead of using the faction ID constants.

use Mistralys\X4\Database\Factions\KnownFactions;

$argon = KnownFactions::getInstance()->getArgon();

echo $argon->getLabel(); // Outputs "Argon"

Accessing ware information

All items available in the game, from trade goods to ships, are available in the main ware collection.

The ware collection

All wares are available through the Wares collection class.

use Mistralys\X4\Database\Wares\WareDefs;

echo "Available wares:" . PHP_EOL;

foreach(WareDefs::getInstance()->getAll() as $ware) {
    echo $ware->getLabel() . PHP_EOL;
}

This fetches wares by ID:

use Mistralys\X4\Database\Wares\WareDefs;

$advancedElectronics = WareDefs::getInstance()
    ->getByID('module_gen_prod_advancedelectronics_01');

The ware finder

The ware finder utility class allows selecting search criteria to filter the wares and retrieve specific wares. The following example uses the ware finder to retrieve all ship engines provided by the Boron DLC.

use Mistralys\X4\Database\Wares\WareDefs;
use Mistralys\X4\Database\Wares\WareGroups;

$boronEngines = WareDefs::getInstance()
    ->findWares()
    ->selectDLC()
    ->boron()
    ->selectGroup(WareGroups::GROUP_ENGINES)
    ->getAll();

Accessing translations

The official translations are bundled with the package, and can be accessed to translate text codes like {20101,20604} ("Manorina (Gas) Vanguard").

use Mistralys\X4\Database\Translations\Languages;

$english = Languages::getInstance()->getEnglish();

$shipName = $english->t('{20101,20604}');

Development setup

Unpacking game data files

The mod requires the game's data files to be unpacked using the X4 Data Extractor tool. The tool acts as a library to access the extracted information. This includes the DLC metadata necessary to generate the correct mod file structure.

Please refer to the tool's instructions to unpack the game data files.

Configuration

  1. Unpack the data files (see above).
  2. Clone this repository.
  3. Copy dev-config.php.dist to dev-config.php.
  4. Edit the file to set the correct paths.

Database update

To update the bundled database, use the build Composer command to update the JSON files in the data folder.

composer build

X4 Tools and libraries