Simple guide to converting xnb mods into Content Patcher
For people who don’t know how to code!
Why content packs instead of XNB mods?
More details available here: https://stardewvalleywiki.com/Modding:Using_XNB_mods and Migrate XNB mods for stardew 1.3 if you’re still not convinced :)
“But I have no idea where to start… I can’t code”
It’s ok, me neither. Content packs seem intimidating at first, but once you make your first one, you’ll see that they’re pretty simple.
We’ll walk through making a content pack that changes some images in the game, then go over some more advanced options at the end.
Step 1: Getting the images from the xnb
If you want to take an image replacement mod that already exists and turn it into a content pack, first we’ll need the image.
You can extract the xnb to get the image file. A program such as XNB Extract 0.2.2 will be needed.
If you want to draw your own sprites, you can also extract xnb files from the original game and edit those images.
Step 1: Getting the images from the xnb
For this tutorial, we’ll replace several of the game’s exterior textures:
Just put the files that you want to get images from in the “Packed” folder and run “unpack.bat”. After that step completes, you should see new files in the “Unpacked” folder.
Packed folder
Unpacked folder�
Click
UnpackFiles.bat
In main XNB Extract folder then click Run
You can ignore the .yaml files - we’ll just need the .png files
Step 2: Setting up content pack mod
First thing you’ll want to do is create a folder that has a name to identify what this content pack is for. Since we’re replacing a barn, cow, and cheese press, I will call this mod “Barn Overhaul”.
Within the folder you just made, you should also make a folder named ‘assets’. That’s where the images will go.
In the content pack folder, we’ll need to make two .json files, which can be done with a simple text editor like notepad. However, it might be easier to make these with a program such as sublime text, which color codes the text and makes it easier to spot errors.
The two files will be named manifest.json and content.json and we’ll go over those next:
Step 3: Making the manifest
Open up your text editor and paste in this template:
{
"Name": "YourProjectName",
"Author": "your name",
"Version": "1.0.0",
"Description": "One or two sentences about the mod.",
"UniqueID": "YourName.YourProjectName",
"MinimumApiVersion": "2.0",
"ContentPackFor": {
"UniqueID": "Pathoschild.ContentPatcher", // the ID of required mod
"MinimumVersion": "1.3.0" // optional
}
}
You should change the fields in red as appropriate. For this tutorial, the manifest would look like the example to the right.
Save the file as manifest.json in the Barn Overhaul folder.
Step 4: Starting the content.json file
The content.json file has a simple outline.
First, we use a set of braces and include:
The format indicates which version of content patcher is needed.
All changes will go within the square brackets after changes [ ]
Each set of changes will go within its own braces { } and those braces are separate by commas
You can make comments on a new line by putting // before text
{
"Format": "1.3",
"Changes": []
}
Barn and cow changes in content.json file
For the barn and cow, the barn.xnb and cow.xnb file only contain their respective images. This means that we can have content patcher replace the entire image.
To do this, we’ll use “Action”: “Load” in our changes.
The “Target” is what file in the game’s content folder we want to replace. Since the barn is in Content\Buildings\Barn.xnb we’ll just put Buildings/Barn after target. The brown cow is in Content\Animals\Brown Cow.xnb so we’ll use Animals/Brown Cow after target. For the Target, you shouldn’t include “.xnb” in the file path.
The “FromFile” field is what file in the mod’s asset folders we’ll use to replace the target. In these examples, the files in the assets folder have the same name as the files in the target folder, but that isn’t necessary.
Brown Cow.png
Barn.png
Cheese Press changes in content.json file
The cheese press is part of the Craftables.xnb file, which has many sprites. Since we only want to change the cheese press, we’ll use a feature called EditImage which lets us change a small part of the Craftables file. This allows users to use multiple content packs which would affect the Craftables file without having to choose one edit or the other.
Craftables file
Cheese Press.png
For this example, we’ll replace the default cheese press with a slightly darker version. We’ll need a few pieces of information before we move forward though:
The cheese press is 16px wide and 32 px tall.
Our replacement image is 16px wide and 32 px tall.
The cheese press in the craftables file starts at the pixel with the coordinates (0,64) - The upper left corner of the image is always 0,0. In stardew valley, most sprites should start at pixel coordinates that are divisible by 16.
Our replacement cheese press image starts with the pixel coordinates (0,0)
Cheese Press changes in content.json file
To do this, we’ll use “Action”: “EditImage” in our changes.
The “Target” is what file in the game’s content folder we want to replace. Since the cheese press is in Content\TileSheets\Craftables.xnb we’ll just put TileSheets/Craftables after target.
The “FromFile” field is what file in the mod’s asset folders we’ll use to replace the target. For this example, it’s Cheese Press.png, so we’ll put “assets/Cheese Press.png”
“EditImage” requires some extra information compared to “Load”. “FromArea” requires the starting coordinates and dimensions of the replacement file (what’s in assets). “ToArea” requires the starting coordinates and dimensions of the sprite that’s being replace (what’s in the game file).
{
"Action": "EditImage",
"Target": "TileSheets/Craftables",
"FromFile": "assets/Cheese Press.png",
"FromArea": { "X": 0, "Y": 0,"Width": 16, "Height": 32},
"ToArea": { "X": 0, "Y": 64,"Width": 16, "Height": 32},
}
Final content.json file!
Note that formatting is very important for json files! All of the fields are listed in quotes and each field is separated with commas. Make sure each set of {} or [] is complete - no open brackets!
A program like sublime text can help you find these errors:
Missing end bracket after brown cow changes - the comma and next start bracket show up highlighted:
Result
Once you save your content.json file, if you launch SMAPI, your changes should take effect.
Final setup of content pack folder:
Barn and brown cow are replaced
Cheese press is replaced, but other craftables items are untouched.
content.json - more details
You can make many edits on the same content.json file. In this example, we used 3 simple changes, but you can add many more! While we only changed images for this mod, more types of changes are supported.
Content Patcher documentation - This page contains many details and more advanced features of content patcher. Hopefully this tutorial helped with the first steps of making content packs and you can move on to more advanced features.