X4: Foundations

X4: Foundations

Not enough ratings
How to make Custom Paintmods
By manoeuvring with difficulty
A guide targeted towards those starting out with no experience modding x4 while also being useful to those familiar with mods but unfamiliar with paintmods in particular.
   
Award
Favorite
Favorited
Unfavorite
Requirements
To make a paintmod at the bare minimum the following will be required:
• A text editor (Notepad++ is great)
• X-Tools CAT/DAT exporter/importer
• A compression tool that can compress files to .gzip

In addition, it is also useful to have the following programs for making and working with pattern files:
• Nvidia texture tools importer/exporter (or a similar program that can convert between .png and
.dds)
• A drawing or graphic design tool to make patterns (GIMP is a great open-source option but of
course there are proprietary options too)
Getting Started
To start off, its best to get the folder hierarchy set up and the *.xml documents in the correct place, all folders and files must match the style of the vanilla hierarchy (this can be checked by unpacking the catalogues of the game into a directory).
Folders required are outlined below:
\extensions\yourmodnamehere\assets\fx\gui\textures\paintmods \extensions\yourmodnamehere\assets\textures\pattern (only required for paintmods with patterns) \extensions\yourmodnamehere\libraries

Within \libraries the following files are required

paintmods.xml wares.xml stock.xml icons.xml

(This list has been ordered based on the order the files should be changed in to avoid making errors rather than the alphabetical order in which they appear)

Within \paintmods the following files are required

1 icon file for every paintmod, this is a gzipped *.dds file with the .dds file extension removed before compression. The filename must be lowercase and match the paintmod’s wareid. Failing to place an icon file for each paintmod will result in random icons from vanilla gamefiles being used instead.

Within \pattern the pattern files are placed if patterns are being used on paintmods. Much like the icons the files must be a gzipped *.dds file with the .dds file extension removed before compression. The filename must be lowercase but can be pretty much any string with letters and numbers (underscores are probably okay but other special characters should be avoided).
Setting up the xmls
Once all the files have been created in the correct folders it’s time to start setting up the files. All .xml files are formatted to insert extra sections into the identically named vanilla sections. These work by using the diff root tag with the add, replace and remove operators (More on how X4 foundations uses xml here[forum.egosoft.com]). For paintmods only the add operator is required. An example of how a *.xml file can be formatted for x4 is shown below from adding paintmods to the paintmods.xml, all other xmls will have a similar layout.
<?xml version="1.0" encoding="utf-8"?> <!--xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <diff> <add sel="/paintmods"> <paint ware=" " quality="" hue="" brightness="" saturation="" metal="" smooth="" dirt="" extradirt="" pattern=" strength="" scale="" sharpness="" invert="" red="" green="" blue="" alpha=""/> </add> </diff>

Note: <paint ... /> is all on one line, steam typesetting makes it run over multiple lines unfortunately.
paintmods.xml
Now that a paintmods file has been created and set up like the example above its time to look at what attributes there are and what values they can take. Importantly, not all of the attributess are required and omitted attributess will revert to the default, however, for consistency, even if its not required by the game, it is good to make sure they are in the same order as the vanilla files.

While some of these attributes take a floating point number it is often best to restrict it between -1 and 1 for best results

Attribute
Values
Function
ware
Same as wareid in wares.xml
Relates the paintmod to the corresponding entries in other xml documents
quality
1,2 or 3
Describes the standard, enhanced and exceptional qualities respectively
hue
0-360
Determines the hue of the main colour based on an HSB colour wheel, the other colour will have a hue 135 degrees from the main one
brightness
float
Determines the brightness (-1 is black, 1 is the same as the hue) based on an HSB colour wheel.
saturation
float
Determines the saturation (-1 is monochrome, 1 is full colour) based on an HSB colour wheel
metal
float
smooth
float
dirt
float
Adds an overlaying dirt texture
extradirt
float
Adds an additional overlaying dirt texture

Additionally, if working with patterns, the following is required:

Attribute
Values
Function
pattern
filepath+filename (without *.gz extension)
Specifies the location of the paintmod pattern. Should be
\yourmodnamehere\assets\textures\pattern\filename
strength
0 to 1
0 is a transparent pattern where 1 is fully opaque. Regions of the pattern that are already transparent will remain so.
sharpness
0 to 100
invert
0 or 1
Determines whether or not the black, white and grey regions are inverted before the RGB colour is applied over the top
red
0 to 255
Determines the red content of the pattern
green
0 to255
Determines the green content of the pattern
blue
0 to 255
Determines the blue content of the pattern
alpha
255
Do not change from 255

An example of a paintmods.xml file contents without a pattern applied is the following (Note that omitted attributes will be set as the default values):
<?xml version="1.0" encoding="utf-8"?> <!--xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <diff> <add sel="/paintmods"> <paint ware="mwdtestpaint" quality="1" hue="60" brightness="0" saturation="0" /> </add> </diff>

An example of a paintmods.xml file contents with a pattern applied is the following:
<?xml version="1.0" encoding="utf-8"?> <!--xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <diff> <add sel="/paintmods"> <paint ware="mwdtrianglegreen" quality="1" hue="0" brightness="-0.9" saturation="0" metal="0.5" smooth="0.8" extradirt="-0.68" pattern="extensions\mwdpaintmods\assets\textures\pattern\mwdtriangle" strength="0.9" scale="6" sharpness="100" invert="1" red="21" green="160" blue="70" alpha="255"/> </add> </diff>

Again <paint ... /> is all meant to be on one line.
wares.xml
The wares.xml is the heart of any mod that adds wares and paintmod mods are no different. The file specifies the name, description, price range and average, volume and transport type. Conveniently, paintmods all follow the same format:
<?xml version="1.0" encoding="utf-8"?> <diff> <add sel="/wares"> <ware id="wareid" name="Paintmod Name" description="Paintmod Description" transport="inventory" volume="1" tags="inventory paintmod"> <price min="minprice" average="averageprice" max="maxprice" /> <container ref="sm_gen_wares_common_01_macro" /> <icon video="ware_inventory_generic_macro" /> <sources> <source type="{20224,41}" /> </sources> </ware> </add> </diff>

Everything from <container ref="sm_gen_wares_common_01_macro" /> and onward need not be changed.

Note: <ware id ... > is all meant to be on one line but steam typesets this incorrectly
stock.xml
stock.xml specifies where, what amounts and what the likelihood is of being able to buy a given ware from either a regular or pirate station trader. Again, much like wares.xml the format can be followed to the letter.

<?xml version="1.0" encoding="utf-8"?> <diff> <add sel="/stocks/stock[@id='default_trader']"> <ware ref="wareid" min="min" max="min" chance="0-100" /> </add> </diff>

Additionally, to give paintmods to pirate traders [@id='default_trader'] can be changed to [@id='pirate_trader']. Finally, paintmods can be added to traders of a specific faction by using the faction tag.
icons.xml
icons.xml relates each paintmod ware to the icon that is shown in the redesign menu. It doesn’t require a lot of work as it changes only one line regardless of how many paintmods and respective icons you create.

<?xml version="1.0" encoding="utf-8"?> <diff> <add sel="/icons"> <icon name="*" texture="extensions\yourmodnamehere\assets\fx\gui\textures\paintmods\*" height="256" width="256"></icon> </add> </diff>

It’s possible of course to write out the full paths instead of asterisks if the icons are named differently to the paintmods for whatever reason.
Making Patterns
Taking a step back from xml its time to look at how patterns work within the context of paintmods. Patterns must be square and preferably 1024x1024 as this is the size used by the default patterns already in game. Patterns can be any combination of colours or monochromatic but it is important to note that multi-coloured paintmods can’t have their colours changed in paintmods.xml where monochromatic paintmods can have their colour changed on a whim and makes created different coloured versions of the same pattern much easier. Transparent regions of patterns become sections where the hull texture is evident, white regions become the colour specified by red=”” green=”” blue=”” and black regions will remain black. When patterns are inverted the white regions become black and the black regions become the colour specified by red=”” green=”” blue=””.

With the pattern file created in an editor of some description it is time to get it into the correct format. If the editor being used doesn't support the *.dds format natively export it as a *.png to minimise loss and preserve transparency. The *.png can then be converted to *.dds with the Nvidia texture tools exporter. Finally, delete the *.dds file extension and compress it to a gzip file in
assets/textures/pattern
Finishing up
With all necessary files and folders created and filled to test it in game the X Tools CAT/DAT Importer/exporter (more information here[forum.egosoft.com]) is required to condense all the files into a readable extension. Simply specify the location of yourmodnamehere, choose “import folders” and select both assets and libraries. Then choose export as catalogue and place the catalog into the extensions\yourmodnamehere folder of the game’s root directory. Finally, create a content.xml file in the extensions\yourmodnamehere folder and insert the following information:

<?xml version="1.0" encoding="utf-8"?> <content id="" name="Yourmodname" description="Adds a few custom paintmods" version="100" author="" save="0" date="2021-09-12" lastupdate="1631425253" sync="false"> <text language="07" name="Yourmodname" description="" author=""/> <text language="33" name="Yourmodname" description="" author=""/> <text language="34" name="Yourmodname" description="" author=""/> <text language="39" name="Yourmodname" description="" author=""/> <text language="44" name="Yourmodname" description="" author=""/> <text language="49" name="Yourmodname" description="" author=""/> <text language="55" name="Yourmodname" description="" author=""/> <text language="81" name="Yourmodname" description="" author=""/> <text language="82" name="Yourmodname" description="" author=""/> <text language="86" name="Yourmodname" description="" author=""/> <text language="88" name="Yourmodname" description="" author=""/> </content>

An id is not required for the mod to work or for uploading to the steam workshop.

Now the mod should be good to go and already enabled when the game is run. If desired the mod can be uploaded to the steam workshop, to do so follow the process outlined in this guide here
3 Comments
mad-rooky 6 Apr @ 5:32am 
The files do not need to be packed into the archive format. I am not even sure if that makes any sense with a mod for a handful of paint jobs. Other than a bit of file compression with large amounts of data I can't see any advantage. I even unpack certain mods I download to be able to make changes on the fly.

What I miss specifically to this post is a reference HUE colour wheel as it is a bit of a pain in the butt to figure out the main and secondary colours. The fact that the secondary colour is 135° relative to the main colour is... annoying, as you get all kinds of weird combinations that just don't look good on many hulls. A workaround to apply only the main colour can be using a fully transparent "pattern".
Poacher886 7 Nov, 2023 @ 3:00am 
This is excellent, what im not understanding is the xml folder without pattern, where are the values for the actual colour??
King 23 Jan, 2023 @ 7:45am 
A necessary step that OP omitted from this guide is that the compressed .cat and .dat files MUST follow the proper naming conventions. I.e. you should be naming them ext_01.cat and ext_01.dat .