Pages: 1
Posted on 06-08-20, 04:16 pm (rev. 25 by  poudink on 02-07-21, 06:51 am)
Giant Red Paratroopa
Not Edible

Karma: 3386
Posts: 1049/1447
Since: 02-12-16
Ever since NSMB hacking started in the late 2000s on Jul, more and more of the game's file formats have been figured out and became editable. With the recent completion of a certain Blender plugin which finally made Maya SDK plugins obsolete, SPA has become just about the only format in the whole game that is still uneditable. Until now. While this tutorial won't be going over how to make your own completely custom particles (not because I don't know how, but because drawing in a hex editor is too tedious for anybody to bother), I will be going over how to delete particles (we can finally get rid of those pesky snowflakes in the World 5 worldmap), how to replace any particle with any other particle from the game (as well as other games that use the SPA format), as well as (incomplete) format documentation for anyone who might want to create a proper SPA editor tool or people who really want to draw custom particles in hex, made from various information shared by  Gericom and Ed_IT.

Tools Needed


Note About SM64DS
If you are not an SM64DS modder or are not planning on taking particles from SM64DS, you can skip to the next section.
SM64DS is the earliest known game to use the SPA format, and as such certain things hadn't exactly been set in stone. While the format remains largely unchanged from its more recent counterparts, SPA files contained within the game do not harbor the .spa file extension and instead end with "_spa.bin". Simply renaming the file to end with a .spa extension will make it work just fine in MKDSCM and you'll be able to carry on with the tutorial.
That being said, most of the game's particles aren't actually contained in the game's file system at all and are instead embeded inside the arm9 binary. You should be able to find it in a decompressed arm9.bin be searching for the following:
20 41 50 53 31 30 5F 31 41 01 2E 00 00 00 00 00

File starts at the beginning of the search data. It's 0xC214 bytes long.

Finding Your Particle
The first step to editing the particle you want to edit will always obviously be to first find the particle you want to edit in the rom and then in your hex editor. This is what MKDSCM is needed for, as it is still the only program with the ability to view SPA files. Open your rom in MKDSCM and navigate to the particle folder, which contains every SPA file in the game (assuming you're modding NSMBDS). Then, open each file one by one and check every particle in them until you have found the one you were looking for. Write down the particle ID and extract the SPA file.

Now, open the SPA file you've extracted in HxD. Every particle starts with 20 54 50 53 (" TPS" in text) and ends at the start of the next particle, except of course for the last particle which ends at the end of the SPA file. Their order within the file is the same as their order in MKDSCM, as such particle ID 0 will be the first particle in the file, particle ID 1 will be the second, and so on. Based on the particle ID you wrote down earlier, find the instance of 20 54 50 53 that belongs to your particle (I recommend using Find (Ctrl+F) and Find again (F3) for that) and select all of it. Write down the offsets, just in case. Then, move on to either Deleting a Particle or Replacing a Particle.

Deleting a Particle
Replace the particle you've selected with this (thanks Ed_IT):
20 54 50 53 06 F0 01 7C 40 00 00 00 60 00 00 00 10 00 00 00 70 00 00 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Save and insert the edited SPA in the rom with NSMBe.

Replacing a Particle
Repeat everything you did in Finding a Particle to find your replacement particle. Copy it in HxD and paste it over the particle you wanted to replace. You can take any other particle from the game you're editing or any other game that uses the SPA format. Multiple versions of the SPA format exist, but the SPT block, which is what we're editing, is the same for each of them. Here is listed each game that is known to use SPA as well as what version of the format they each use:

GameVersion
Super Mario 64 DS1.01
Nintendogs: Best Friends1.10
Nintendogs: Chihuahua & Friends1.10
Nintendogs: Dachshund & Friends1.10
Nintendogs: Dalmatian & Friends1.10
Nintendogs: Lab & Friends1.10
Animal Crossing: Wild World1.20
Mario Kart DS1.21
Pokémon Black1.21
Pokémon Black 21.21
Pokémon Diamond1.21
Pokémon Heartgold1.21
Pokémon Pearl1.21
Pokémon Platinum1.21
Pokémon Soulsilver1.21
Pokémon White1.21
Pokémon White 21.21
Mario vs. Donkey Kong: Mini-Land Mayhem!1.22
New Super Mario Bros.1.22
The Legend of Zelda: Phantom Hourglass1.22
The Legend of Zelda: Spirit Tracks1.22
Tomodachi Collection1.22

Save and insert the edited SPA in the rom with NSMBe.

Documentation
SPA Header:
OffsetLengthTypeDescription
0x000x04String" APS" (magic ID)
0x040x04StringVersion (see the Replacing a Particle version to know which games use what version)
0x080x02UInt16Number of particles
0x0A0x02UInt16Number of textures
0x100x04UInt32Particle block length
0x140x04UInt32Texture block length
0x180x04UInt32Texture block offset (start offset of first texture)

SPT Particle Header:
OffsetLengthTypeDescription
0x000x04String" TPS" (magic ID)
0x040x04BitfieldTexImageParam*
0x080x04UInt32Texture data Length (=T)
0x0C0x04UInt32Palette offset
0x100x04UInt32Palette data Length (=P)
0x140x04UInt32Texture 4x4 offset?
0x180x04UInt32Texture 4x4 Data Length? (=T44)
0x1C0x04UInt32Texture size?
0x20TTexture data
0x20 + TPPalette data
0x20 + T + PT44Texture 4x4 data?

*TexImageParam:
Bit(s)Description
0-2TexFmt (0=NONE, 1=A3I5, 2=PLTT4, 3=PLTT16, 4=PLTT256, 5=COMP4x4, 6=A5I3, 7=DIRECT)
4-7Size S (Width = 8 << Value)
8-11Size T (Height = 8 << Value)
12Repeat S (0 = S8 ... 7= S1024)
13Repeat T (0 = T8 ... 7= T1024)
14Flip S
15Flip T
16Palette color 0 (0 = USE, 1 = TRNS)

Sources
https://drive.google.com/file/d/1imob87CKxextWIbCSDYB8A0UJGe_bDpW/view?usp=sharing
https://nsmbhd.net/thread/2988-export-a-spa-to-a-bmp/
https://nsmbhd.net/thread/84-help-question-asking-thread/?from=1140#64906

TODO
  • Document the particle block
  • Cover flipping and mirroring

_________________________
Nothing to say, so jadnjkfmnjamnfjkldnajfnjkanfjdksan jsdnvj m.

Pages: 1