Skip to main content

Fairy Type in B2W2

Author(s): BluRose
Research: BluRose, Sunk, MeroMero

This is a tutorial that details how to insert the Fairy type in Black 2 and White 2 using MeroMero's initial research from years ago and building upon it with a new and improved better understanding of just what happens in the assembly. While yet imperfect, the improvements allow for a much better Fairy representation overall, eliminating the appearance of glitched graphics and crashes entirely.


Table of Contents

Graphics

Various other type graphics are leftover from possible features. We look to replace those here.

Type Icons - /a/0/8/2, /a/1/2/5

Here we replace the Cool and ??? type icons with the Fairy type icon to allow us to print the icon. Tinke allows us to do this by replacing the relevant files, first in /a/0/8/2:

a082_33.RLCN and a082_51.RGCN should replace the ones in the ROM from an extracted /a/0/8/2.

This replaces with

Similarly in /a/1/2/5, we just replace the ??? type icon at the bottom of an image to now be the Fairy type, replacing the files in /a/1/2/5 with a125_22.RLCN and a125_23.RGCN

This replaces with .

Move Selection Palette - /a/0/1/1

Here we add a new palette to /a/0/1/1 to make Fairy moves appear as pink in the move selection screen.

This file is a011_572.RLCN.

a011 originally just has 571 files. We add a 572nd file for our purposes. You can either unpack/repack using narchive (included in the b2w2-fairy repository) or Extract directory using Tinke, add the file, and Change by directory using Tinke again.

Hall of Fame Palette - /a/2/1/3

Here we add a new palette to /a/2/1/3 to make Fairy Pokémon show up in the Hall of Fame with a pink nameplate.

The file to replace with once extracted: a213_9.RLCN

Code - ASM File

I have made a repository which should be downloaded as-is that has the fairy type code and is maintained as such. Any additions or changes (future bugfixes!) will be included there.

All you need to do is follow the instructions there, abridged here (currently for Windows only):

  • Place your White 2/Black 2 ROM in the base folder (b2w2-fairy-main) as base.nds
  • Read and modify the configs at the beginning of asm\fairy.s. The only one that should really be changed is BLACK2 being 1 if you are applying to Black 2, and 0 if applying to White 2.
  • Double click on the applyfairytype.bat batch file
    • A script will run that applies all the Fairy type code changes to copied overlay files and recompresses them in the base folder for ROM insertion
  • Open base.nds in Tinke
  • "Change file" all of overlays 167, 168, 207, 255, 265, 296, 298, the overlay table (y9.bin), and the arm9
  • Save your ROM as some other named file
Documentation - Code Changes

Overlay 167

This overlay hosts the type chart. All the edits made to this overlay are for adjusting the type chart. The type chart declaration is

const u8 gTypeEffectiveness[NUM_OF_TYPES][NUM_OF_TYPES];

gTypeEffectiveness[atkType][defType] grabs the effectiveness of atkType when attacking defType
- 08 is super effective
- 04 is normal effective
- 02 is not very effective
- 00 is ineffective

So all of the code for accessing subsequent entries needs to take into account an extra element in each row and an extra column.


Overlay 168

This overlay hosts the move type -> move selection palette table. We just write a 572 near the end of the file and leave it be to correspond to the newly created nclr in a011.


Overlay 207

This overlay handles a lot of the code for the summary screen. We edit it to support the new type icon.

The old structure allocated for this was 0x264 in size, and at 0x130 it kept track of the type icon OAM id's or something like that. I'm honestly not 100% certain what it is, but it maps something to the graphics. This is a common theme with all of the type icon edits made.

First, we double the memory heap allocation size for the summary screen to give us freedom in messing with the structure. We need to add an entry to the 0x130 structure. This is an issue--it's baked into the overall structure. We need to move it to the end of the old structure--we can do this by replacing the 0x130 entries that represent this with 0x264 and to increase the size of the allocated structure to begin with to allow for this moving. How this is done is documented in the asm\fairy.s file.


Overlay 255

Similarly, the PC Screen has a structure 0xA5BC in size. At 0xA268 of this structure, the type icon OAM id's are stored once again. This would be as simple as moving it to the end, but 0xA268 is actually just a part of a substructure that is baked into the overall structure that starts at 0x18C. At 0xA0DC of this substructure, there is a massive array of OAM id's for every sprite that is possibly on screen. This includes and captures the 0xA268 from the overall structure--so the code is written to move the type icons to the end of the structure at tag 475. This prevents any overlap with other sprites that are present on screen as well.

Whenever switching off of a Pokémon, the type icons are all deleted and and replaced--this is done by deleting all of the type OAM id's in a for loop. There are two separate code areas that are run for these, one for switching onto a new Pokémon and another for switching into blank space. These for loops are both expanded to run one more time for the Fairy type.


Overlay 265

Here, the table u32 type_to_loaded_gfx_hof[NUM_OF_TYPES] exists to map the types to their loaded SPA file when the hall of fame cutscene happens. This SPA is all of the particles that appear when the Pokémon slides on screen. Similarly, the palette table is at the very end of the overlay, and the code was modified to make that table consist of halfwords over u32's to allow us to add more to the end without overflowing the overlay's memory region.


Overlay 296

Here, there is a lot of handling to increase the PokéDex's loaded sprites. We increase the amount of space for the Dex structure and go on to move all of the type objects to the end of the structure so that the fairy type icon can be loaded as well.


Overlay 298

There is an initializer in the PokéDex routines that determines how many files can be loaded. This limit is increased.

Cleanup

From there, just make Struggle type 18 to make it typeless. Assign all the Pokémon that need it to be Fairy type. Make moves that have the Fairy typing as well. It's now a functional type entirely!