Modding
Modding
Contents
General Information................................................................................................3
Where to put mods?...........................................................................................................3
What parts of the game can be modded?...............................................................................3
Is certain prior knowledge needed for modding?.....................................................................3
How to setup the basic structure of a mod.............................................................................4
Prepare your mod for distribution.........................................................................................5
Testing & Debugging................................................................................................6
Config settings...................................................................................................................6
Debugging keys.................................................................................................................7
Music Modding........................................................................................................8
Requirements....................................................................................................................8
How to mod.......................................................................................................................8
Loop Start.........................................................................................................................9
Fast Music Tracks...............................................................................................................9
Details on audio_replacements.json......................................................................................9
Level Modding.......................................................................................................11
Preparations....................................................................................................................11
Setup your mod...............................................................................................................11
Details on the raw data JSON entries...................................................................................12
Can you show me?............................................................................................................12
Note on distribution..........................................................................................................12
Sprite Modding......................................................................................................13
The starting point.............................................................................................................13
The sprite sheet...............................................................................................................13
The JSON file...................................................................................................................14
Limitations......................................................................................................................15
Palette Modding.....................................................................................................16
What can be modded?.......................................................................................................16
Character palette limitations...............................................................................................16
How to define your custom palette......................................................................................16
Raw Data Modding.................................................................................................18
What is this about?...........................................................................................................18
Mod structure..................................................................................................................18
Script Modding......................................................................................................20
What do I need?...............................................................................................................20
Make a script mod for development.....................................................................................20
Using Custom Mod Settings................................................................................................21
Game-specific Script Functions...........................................................................................22
Font Modding........................................................................................................23
About font modding..........................................................................................................23
Font mod layout...............................................................................................................23
Please note: Starting with preview version 19.07.15.0, the folder structure used for mods changes.
Older game versions support only a single mod that needs to be placed inside
"%appdata%/Sonic3AIR/mods/data", while newer versions allow for multiple mods with their own
names next to this "data" folder.
Keep in mind that your mods built in the new format as described in this document won‘t work
with older versions of the game. It‘s probably worth a note in the mod description when you
distribute e.g. sprite mods.
Make sure to export all PNGs as either RGB or RGBA with 8 bits per channel and no interlacing.
Config settings
Especially when making level mods, you certainly want to be able to quickly start into the game and test
your changes. There are some hidden options supported in the "config.json" that is located in the game
installation‘s base folder. To enable them, open this file with a text editor and add one or more of the
following lines inside the "DevMode" section:
"Enabled": "1",
Enables Dev Mode. This includes the Debug Mode as known from original Sonic 3 & Knuckles (it can be
unlocked by completing achievements as well, but Dev Mode will enable it in any case), and it enables
certain debugging keys and features as described in the Oxygen handbook PDF.
"StartPhase": "2",
Skips more or less steps of the game, like disclaimer and title screen.
As parameter use one of the following:
• "0" -> Start the game as usual, beginning with the disclaimer
• "1" -> Start with the SEGA screen, skipping only the disclaimer
• "2" -> Start with the main menu, skipping everything before
• "3" -> Start right into the game, which makes most sense when combined with loading a save
state
This option has no effect if "LoadLevel" is used.
"LoadLevel": "0x0701",
Skip all menus and directly load a level. The parameter uses hexadecimal notation of the zone and act in
the form "0xZZAA".
• For ZZ, use the zone‘s number in internal a.k.a. "Prototype" zone ordering:
00 is Angel Island, …, 03 is Carnival Night, 04 is Flying Battery, 05 is Ice Cap, …, 09 is Lava Reef.
• For AA, only 00 or 01 is valid, for Act 1 and 2, respectively.
The example above would load Mushroom Hill Act 2. Note that this won‘t work with invalid or incomplete
zone/act combinations.
"UseCharacters": "3",
To be used with "LoadLevel". Specify which character(s) you want to start the level with:
• "0" -> Sonic & Tails
• "1" -> Sonic
• "2" -> Tails
• "3" -> Knuckles
• "4" -> Knuckles & Tails (if unlocked)
Requirements
You can change the game‘s music and jingles.
To do so, two things are needed:
• One or more music files in Ogg Vorbis format.
• A JSON file telling the game which music to replace using which file.
How to mod
First of all, setup your mod as described under "How to setup the basic structure of a mod" in the
General "Information section" above.
To start with your music mod, now go through the following steps:
1. Create a subfolder "audio" inside your mod.
2. Place all music files you want to use in there.
3. Copy the template file "audio_replacements.json" inside "modding/audio" next to this
document into your mod‘s "audio" folder.
4. Open the JSON file with a text editor and fill in the right content.
◦ Remove all lines referring to music tracks you don‘t want to replace; the comment
should tell you which lines are the right ones.
◦ Replace all ... with the names of your music files, and leave the rest as it is; a line
should look like that afterwards:
"0F": { "File": "mhz1.ogg", "Type": "Music" },
5. When you‘re done, start the game to test your mod.
Details on audio_replacements.json
If you‘re interested in diving deeper into audio modding, here‘s the details on how the JSON lines in
audio_replacements.json are built.
The key can be an arbitrary string, so you can choose whatever you like and reference that key string in
a script like inside the "Standalone.playAudio" function.
Be aware though that some key strings have a special meaning:
• A two-character string that is a hexadecimal value (like "6A") is automatically associated with one
of S3&K‘s original sound IDs. Using these, you will in almost all cases overwrite an existing music
track or sound effect.
• If the string ends with _fast, it‘s regarded as a fast music version – see above.
Please note: Starting with version 19.12.15.0, the folder structure for level mods has changed, and
support for the old format will be removed with a future version of S3AIR.
The old format used entries in the "mod.json", whereas the new format uses the raw data
mechanism to reference binary files. See details below and in the "Raw Data Modding" section.
Preparations
Before you begin, setup the SonLVL editor and the Sonic 3 & Knuckles Github disassemblies. There are
instructions how to do so on Sonic Retro.
It‘s a good idea to have the disassemblies relatively close to your Sonic3AIR saved data folder, as you
have to reference files in the disassemblies from your mod using relative file paths (see below). You can
just place them right inside the saved data folder - it won‘t bother the game anyway.
Once the SonLVL setup is done, you can start editing in SonLVL.
Whenever you save, it overwrites certain files in the disassemblies (using example paths for Angel
Island Act 1, the others should be self-explanatory):
• Level layout in "skdisasm-master/Levels/AIZ/Layout/1.bin"
• Object placements in "skdisasm-master/Levels/AIZ/Object Pos/1.bin"
• Ring placements in "skdisasm-master/Levels/AIZ/Ring Pos/1.bin"
Inside your mod folder, i.e. next to the "mod.json" file, add a folder named "rawdata" and create a
JSON file with an arbitrary name, but ending with ".json". Or have a look at the sample level mod that
you can find inside "sample-mods" next to this document.
In here, you have to define references to all individual binary files that will make up your level mod.
This includes:
• The layout for each level you want to mod
• Objects in the level
• Rings in the level
For each such entry, there is a key string, and a relative file path pointing to one of the binary files that
SonLVL creates on saving.
Fill these in correctly for the game to use your changed level layout / objects / rings when you start a
level. Note that changes to the JSON file require a reload of modded data with F10, and a restart of
the level (Pause Menu → Restart Act).
The file path after "File" is meant to be the location of the binary file, as a relative path from the JSON
file itself (not from the mod folder).
• While working on your mod, it‘s certainly a good idea to use file references directly into the
disassemblies directory, so you can make changes in SonLVL and don‘t need to copy the binary
files around each time.
E.g.: "aiz1_layout": { "File": "../../../skdisasm-master/Levels/AIZ/Layout/1.bin" }
• When you want to distribute your mod, you have to move the binary files somewhere into the
mod folder, and change the JSON entry accordingly.
E.g.: "aiz1_layout": { "File": "../levels/zone01_aiz/aiz1_layout.bin" }
For details on that, see section "Note on distribution" below.
Note on distribution
When your mod is ready, you need to manually move all the .bin files referenced in the raw data JSON
file from the disassemblies into your mod folder. This will most likely require you to do some renamings
and/or create subfolders for the files. Feel free to do so as you like – I‘d recommend at least making a
subfolder "levels" in the mod‘s base folder and subfolders in there for each zone / act.
Afterwards, remember to change the paths in the raw data JSON file accordingly. The lines will now be
something like this:
"aiz1_layout": { "File": "../levels/zone1_aiz/act1_layout.bin" }
To get started:
• First setup your mod as described under "How to setup the basic structure of a mod" in the
General "Information section" above.
• Add a subfolder "sprites" inside your mod.
• Then copy one or multiple of the JSON files and the respective template files into the "sprites"
folder. Now you can make changes to both of them as described below.
BMP sprites
Open the BMP file in an image editor application that supports indexed 8-bit BMPs and make your
changes.
Please note that not all image editors support indexed images at all.
For instance, Paint.NET does not and thus is not useful for making BMP sprites.
PNG sprites
Certain parts of the in-game HUD can be modded, too.
These are not using palettes at all, which makes things easier: What you
define in the sprite sheet is what you get in the game.
When saving, make sure to save the file with the following settings:
• PNG format
• RGB or RGBA with 8 bits per channel (16 bits are not supported)
• No interlacing
The image to the right shows what the right settings look like in GIMP,
with the important parts highlighted.
For PNG sprites specifically, it‘s okay to use Paint.NET if you like.
See the second image to the right.
Sprite sizes
It might be necessary to replace the sprites with larger ones. In that case,
you will need to edit the sprite‘s rectangle inside the sprite sheet as well
in the JSON file – see below.
The game has some limitations for colors in general, namely it uses only 5 bits per color channel. This
allows for a total of 2^15 = 32768 possible colors.
(For comparison: The original game uses 3 bits per channel, i.e. 512 possible colors.)
That means, there might be subtle differences between the colors you define in your palettes and how
characters look in the game.
But be warned...!
This is worth nothing except you know exactly where the data you want to overwrite resides in the
ROM.
Which makes this a feature only really usable for experts on S3&K ROM hacking.
Mod structure
As an example, have a look at the mod inside "sample-mods/sample-rawdata-mod".
It demonstrates the structure of a mod that uses raw data modding, namely:
• A sub-folder with the fixed name "rawdata"
• Inside, one or more JSON with arbitrary names (they have to use the .json extension, of course)
• Plus one or more binary files with arbitrary names
"another_identifier":
{
"File": "another-binary-file.bin",
"RomInject": "0x0abcde"
}
Each of the entries in there (like "some_identifier") needs the following two parameters:
• "File" is the name of a binary file in the same folder as the JSON file itself.
Its file contents will get copied into the ROM data from the given ROM address on.
• "RomInject" is the hexidecimal address inside the ROM where the data will be written.
Note that from this address the complete file contents will be written, i.e. the binary file size
determines the number of bytes written.
Side note: You might have noticed that Level Modding uses the same basic structure for its JSON files,
but without the "RomInject" parameter.
This is because the game handles both kinds of modding in a very similar way:
It loads all JSON files inside the "rawdata" folder, and goes through the entries there. Then it either
injects the binary data for an entry directly into the ROM, if an address is set via "RomInject". Or it
keeps the binary data until some part of the game logic, like level loading, needs it - in that case,
hard-coded keys like "aiz1_layout" are used.
What do I need?
To make script mods, it's highly recommended to switch the game to Dev Mode as described in the
Config settings chapter.
Also make sure to check out engine‘s Handbook PDF file that contains a lot of information and
documentation on the Dev mode features and the scripting language in general.
In a mod, you can overwrite functions of the original scripts to make the game execute your own script
function instead of the original function. To do this, add a new function into your main.lemon 1 using the
exact same signature (i.e. parameters and return value) as the function you want to replace.
In case you‘d like to execute the original function as well inside your own function, call it with a "base."
prefix added. See the sample script mod for an example.
1 - Or if you want to use multiple script files, place it in a custom .lemon file and make sure to reference it in the main.lemon via an
include line.
To add settings, you first need to define a global variable for each setting somewhere in your script mod
like this:
global u8 my_own_setting
As data type, use one of the following: u8, s8, u16, s16, u32, s32.
Note that is really must be a global variable, a define will not work.
The second step is adding a "Settings" section into your mod.json file, next to the "Metadata" section,
using the following structure:
"Settings":
{
"List":
[
{
"InternalName": "MyOwnSetting",
"DisplayName": "My Own Setting",
"Variable": "my_own_setting",
"DefaultValue": "0",
"Options":
{
"0": "Disabled",
"1": "Active",
"2": "Very Active"
}
}
]
}
Plus there‘s these two optional properties you can use as well:
• "DefaultValue" is the initial value for the setting.
• "Category" is the display name of a category for that setting, in case you want to group your
settings into multiple categories in the Options menu.
You can define more than one setting by adding multiple blocks into the "List" array.
See the "doc/sample-script-mod" for an example.
Discord Integration
Game.setDiscordDetails(u64 text)
• Overrides the "Details" text in Discord Rich Presence.
• This is the first of two custom text lines, and usually displays the current game mode.
Game.setDiscordState(u64 text)
• Overrides the "State" text in Discord Rich Presence.
• This is the second of two custom text lines, and usually displays additional info like the current
character selection.
Game.setDiscordLargeImage(u64 imageName)
• Overrides the main image in Discord Rich Presence.
• Due to restrictions set by Discord, you can only choose from a range of pre-defined images, as
shown below.
Game.setDiscordSmallImage(u64 imageName)
• Overrides the small image in Discord Rich Presence, which is displayed in the lower right corner
of the main image.
• Due to restrictions set by Discord, you can only choose from a range of pre-defined images, as
shown below.
The important new part is the "font" subfolder, which contains one or multiple font definitions.
Each font definition consists of:
• A PNG image similar to a sprite sheet, i.e. it contains all the individual image for all text
characters that the font supports. Note that there's currently no support for palette-based fonts,
using BMPs as images.
• A JSON text file with basic information about the font, and the locations of each character in the
PNG image.
Both files should share the same file name (except for the file extension, obviously).
1) In combination with scripts, primarily by using the Renderer.drawText function. The first parameter
there is the font name, and can be a original game font or your modded font.
2) As a replacement for an original game font (or even the font of another mod). This also affects the
otherwise unmoddable menus, if you replace one of the fonts used there.
To replace another font, just give your font the exact same name.
For an overview of the existing original game fonts, have a look at the Sonic 3 A.I.R. Github.
These are also good examples of how font definitions generally look like, as they use the same format as
modded fonts.