Modding:Editing XNB files
This page explains how to edit the game files to change in-game data, images, and maps.
What are XNB files?
The game stores data in a compressed format with the .xnb file extension inside its Content folder. For example, Abigail's portrait shown during dialogue is from Content\Portraits\Abigail.xnb. Each .xnb file contains two files: the data file (like an image), and a metadata file (information about the data file). For example, here's what's inside Content\Portraits\Abigail.xnb:
Abigail.xnb Abigail.png Abigail.yaml
In the above example:
- Abigail.png contains Abigail's portraits. This is the file you would edit if you wanted to change her portraits in the game:
- Abigail.yaml contains metadata about Abigail.png (like what type of file it is). You don't need to worry about this file, since you generally won't be changing it.
How do I get my changes in the game?
There are three ways to get your changes in the game:
- Create a Content Patcher content pack. This lets you change the game's XNB data with zero programming (just editing a JSON file) and without replacing the actual game files.
- Create a SMAPI mod and use the Content API. This requires programming, though.
- Create an XNB mod by replacing the original game files. This is no longer recommended and not documented here; see using XNB mods for more info.
Where can I get help?
The Stardew Valley modding community is very welcoming. Feel free to ask the community for help.
Unpack & pack game files
You can't edit an .xnb file itself, you need to edit the file that's inside it. Pulling out that inner file is called unpacking, and putting it back is called packing. You can do that using xnbcli, a tool for packing and unpacking XNB files. It's open-source and natively crossplatform.
- Download xnbcli.
- Unpack the file for editing:
- Find the file you want to edit in the game's Content folder.
- Copy it into xnbcli's packed folder.
- Double-click unpack.bat (Windows), unpack.sh (Linux), or unpack.command (Mac).
- Edit the unpacked file (see below).
- Repack the file for the game:
- Double-click pack.bat (Windows), pack.sh (Linux), or pack.command (Mac).
- Move the repacked .xnb file back to the original location.
- If you get permission denied on Linux/Mac:
- Open a terminal. (In MacOS, search 'Terminal' in Spotlight.)
chmod +x, with a space at the end. Don't press enter yet.
- Drag the unpack.sh (Linux) or unpack.command (Mac) file onto the terminal to paste its path.
- Hit enter. If you did it correctly, the terminal won't show any message but the permission error should be gone.
- Repeat for pack.sh (Linux) or pack.command (Mac).
Each data XNB has its own format. See the documentation at Modding:Index#Advanced topics.
A few definitions:
- A spritesheet is a PNG file containing small images (usually in a regular grid pattern). Each square in the spritesheet's grid pattern is called a sprite. For example, each in-game item has a sprite in Content\Maps\spring_objects.xnb.
- A tilesheet is a synonym for spritesheet when used for map tiles. In a tilesheet, each square is called a tile and is 16×16 pixels.
- A portrait is a sprite from the Content\Characters\*.xnb spritesheets.
Spritesheets are easy to edit:
- Unpack the file you want to change.
- Open the unpacked .png file in an image editor (like Paint.NET on Windows, or GIMP on Windows/Linux/Mac). Note that it's important to use an image editor that can handle transparency (a.k.a. an alpha channel), unlike Microsoft Paint.
- Make changes directly to the image.
- Repack the file and copy it back to the original location.
That's it! You can launch the game to see your changes.