• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

PokeFireRed how to easily add new types (Fairy)

853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Ok was going to write a whole thing but just not feeling it right now, I wrote a tutorial on the subject in the pokecommunity discord.

If you follow this link you'll find a step by step guide for how to add fairy type to your repository.

For this you'll need a vanilla fire red rom (just any should be fine, doesn't need to be unused or anything) Hex Maniac Advance, and Graphics Gale image editor.

And either Notepad++ or a project manager like visual studio 2019 (community is the free version) to open and move through multiples files in your repository fluidly.

The last 2 aren't really required they just make it easier, and are programs you should just have already.
*Note this guide assumes you've setup using msys2 compiler. (only relevant for 1 or 2 steps, but keep in mind)

I'll get around to fleshing it out here eventually.
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Hey, haven't had time to set this up properly yet, but wanted to add a little blerb about the uses for this tutorial.

It says adding fairy type, but its really a methodology that can be used to add (I guess) any image properly into your decomp.

It uses HMA as a go between, because I like it, and it has a intuitive graphics editor, say for example you just made a new item function in your decomp
most things are derivative so its probably similar or inspired by something already exists, so what you can do is pull up a similar item in hma, using a binary rom.

Open it in the HMA graphics editor, and just design your new item's graphic right there.

Export it, and put in the appropriate folder in your decomp, then just follow the steps for the guide above.
then add your defines, and the path in your graphics folder and you should be golden.


Believe the theory is all sound, but I haven't had time to test with working on other stuff.

So this essentially both a decomp tutorial, and a guide on how to still get some use out of HMA,
even if you don't do binary.
 
5
Posts
2
Years
  • Age 29
  • Seen Aug 25, 2021
Re-posting the tutorial here in full from the discord messages, since not everyone who came here from google is on the discord server:


My first step was getting the icon itself, onto the type chart. this was simplest with Hex Maniac Advance, so open a firered rom in the latest version of that program. Adding the fairy type for binary is made simple because that program has a simple drag and drop method for adding it. So do that in HMA to add the fairy type to the vanilla rom, (or make your own).

Once thats done use the goto menu (CTRL G) input type.icons and then press enter, that will bring you to your type chart image. Export that and save somewhere easy to get to. (if you're planning to add multiple types you'd need to expand the image first, only ever touch the height, and make sure its divisible by 8. Expanding the image in HMA is as simple as changing the 3rd number in the top bar. defualt is 4x16x16 most people will only ever need 4x16x24.)

Screenshot_1002.png


Now after you've exported your image you'll need HMA for one other thing, and that's knowing the coordinates of your new type within the image. use the goto menu again, but this time input type.map and then press enter.

Screenshot_1003.png


This takes you to the coordinates within the image, now if you want to compare the numbers here with the picture you had before, just press that image tab to the left and you'll be able to see your image instead of that left menu.

There's a whole methodology to understanding how the coordinates are setup, and you need to know that the order of the types within the image isn't the order of the types within the roms, but HMA makes it simple so you can just find where it says FAIRY, and just click the values in parenthesis. in HMA most formatted values are shown in decimal but for our purposes what we need is the hex values. But that's easy to get, once you've selected the cell I mentioned you can see the hex value for the selection in the bottom right corner. for me that's the "08 00"

Now I don't know the name of the method for rearranging the value, here but in your pokefirered the values will need to be in "0x00" format, so my value is below FF it only takes the first byte shown there. For those its simple, I just put a "0x" in front of whatever byte value is shown at the bottom. So mine in the decomp file was "0x08" (that's because my type was added at the top, instead of the end of the chart) If you add to the end your value will be above FF so 2 bytes.

Luckily I have another type added, that one was 00 01. (one more than FF) so for values like that, you take reverse the numbers, so you put the 01 in front of the ones on the left and read it that way. If the second byte was in the single digits, I usually think of it as remove the 0 in front of the value, and then reverse it. Done that way you can see you get 100. So for a 00 01, the hex value is 0x100.

Step 2. Moving on, keep hma open, but you're not going to need it for a while. The next step is replacing the type chart image in the repository with the exported image you created, and making sure it has the correct pallete for your new icon. Presently HMA doesn't have a way to export indexed pngs (which is what's needed for your repository to build correctly) That's where graphics gale comes in.

But before that open your msys2 compiler and run this command I was given from the root folder, this will create a new type chart image, with the correct palette, (before this it was just a monochrome image that I couldn't work with at all) I believe you don't need to delete the original image beforehand. Here's the command.

Code:
 tools/gbagfx/gbagfx graphics/interface/dex_caught_pokeball_and_pokemon_types.4bpp graphics/interface/dex_caught_pokeball_and_pokemon_types.png -width 16 -palette graphics/interface/pokemon_types.gbapal

It's all on one line, so all you need do, is copy and paste that whole thing into your msys2 compiler in your rom master folder (for anyone else reading the paste command is SHIFT INSERT) Also when I keep saying msys 2 compiler I'm talking about the Windows Batch File, in your msys 2 folder. the one named msys2_shell

So more quick info for those not in the know. you use the cd command to change directories(move to different folders) type cd then press enter, to make sure you start at your home menu. (which is usually your "username" folder. if you need to move into a folder that has two words as its name just put the folder name in quotation ex. "New Folder"

But if you setup your decomp stuff correctly, you should have it right there in your username folder so this step should be as simple as typing cd pokefirered (yes you need a space between cd & the rom name also while I'm at it, if you check pinned messages above, follow lunos' tutorial on setting up with msys2, if you need more help on that.) after that its as simple as pressing SHIFT INSERT to paste in the code I have above and then pressing "Enter"

Step 3. That will create the image in the folder. To find it open your pokefirered folder goto graphics then interface, the file you're looking for is
Code:
 dex_caught_pokeball_and_pokemon_types

Now open GraphicsGale and open that file in it. Also open the image chart you previously exported from HMA. All we need to do here is copy the image from the exported file into the one from our repository. Luckily that's really simple, right click the the top of the imagea window of the exported image select copy, Then right click the top of the dex_caught image and select paste. you're done. save. Close GraphcisGale (if you expanded your image you need to make the dex_caught file the same size before you can paste into it. [also when you add an image to GG its really squashed so you'll need to drag the bottom right corner to expand them a little first, before you're able right click it] To expand the dex_caught file click it, then in the menu above click "All Frames" Then click "Enlarge Canves" like I mentioned earlier we never touch the width here the height is shown in pixels to convert it to a recognizable dimmenssion divide the height by 8. that should give you 16. So for example if your expanded image was set to height 24 in HMA, multiply that by 8, and you'll have the value your height needs to be here.

Step.4 Ok now that the image stuff is done, the data is actually there for the new type, all we need to do from here, is to make some code adjustments so the game will no where to look. It's pretty fast from here, I think we only need to edit like 6 files. Those being battle_main.c & battle_main.h, pokemon.c & pokemon.h (the one from the include/constants folder) , list_menu.c, battle_message.c, graphics_file_rules.mk, & type_constants.inc, hold_ effects.h & base_stats.h for applying the type to pokemon.

Step.5 I think that's the essential stuff, by changing those you'll be able to have type effectiveness and have your icon show up in all relevant menus, (this doesn't cover the tms though as I'm still figuring that out. Pull up HMA again for your coordinates, then open list_menu.c and go to line 75 the side comments let you know what is what, but comparing to HMA its pretty clear what you need to add, make a new line at the end in the same format as the rest, put in 32 for your width and 12 for your height, then use the hex value found earlier for your coordinates. Like I said for mine its 0x08. Now in the below Image I have my file screenshotted where I made note of certain things, that can cause issues, while its not listed in the actual types if you look at the type image you'll see there are other icons there besides the them, listed directly afterwards, if you just count normal types and your new type value in after dark as 0x12 it'll be wrong you need to count the additional types and list yours after like I have mine below in the comments (ignore different dimmensions for my icon, that's on purpose just 32 for yours.)

Screenshot_1004.png


Step 6. Adjusting the other files, open graphcis_file_rules.mk goto line 28 add fairy to the end of the types listed. Next open include/constants/pokemon.h goto line 95, here's where you define the type. Add FAIRY to the list under the dark type, (same format) but make sure you list fairy as 0x17 like I showed from the link above. Then change the number of types from 12 to 0x13.

Step 7. Open battle_message.c, line 1276, here type is referenced in some string, not sure what its for but, I created one for fairy, you can just copy paste this in either at the end or under the dark type like I did.

Code:
const u8 gFairymovetype[] = ("a FAIRY move");

Open type_constants.inc, add FAIRY to the end, and again make sure the listed value is 0x17. That's most of the work done, finally we handle type effectiveness open battle_main.c can't give a line name since my edited file is very different, but search for "gtypenames" and in the same format as the others add fairy to the bottom.

Next go up to line 312, this type effectiveness, put in what you want here, if you want the same as in game use these values from pokemondb https://pokemondb.net/type/fairy

Now that value on line 313, that says 336, I believe is meant to represent every possible variation of the options written there. That number is the number of entries in the array, multiplied by 3. (That's either No Effect, Super Effective, or Not Effective the three options seen in that array)

When you're done subtract the line that end table is on from the line 313, where the open brackets is, then multiply that by 3. To get the new value you should replace 336 with.

Finally go to battle_main.h we need to put that same number in on line 60, so it matches. That's all the necessary changes to get the fairy type to show up in your menus. Other optional stuff is going to hold_effect.h and adding "Fairy Power" to the list for a fairy boost hold item. you can just paste this in at the end

Code:
#define HOLD_EFFECT_FAIRY_POWER       67

And that's it, you can follow the same process for adding any type, but you'd just need to create the icon manually in HMA instead of relying on the paste script.
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Ok found an issue with my setup so thought I'd pop in to address that.

the contest types, or non-type types, take up space on the type chart and are read after type_dark.

For binary that was the reason fairy had to go in at 0x17, directly after them. But I've realized it doesn't have to be that way for decomp.

Plus it messes up the gTypeNames array.

so once you have the image for your type chart setup, and know the coordinates for your fairy icon.

in the list_menu.c file around line 75 find "const struct MoveMenuInfoIcon gMoveMenuInfoIcons"

that's the array for the type icons in the type chart. instead of putting fairy after Effect icon

put it directly after type dark. like so.

Code:
const struct MoveMenuInfoIcon gMoveMenuInfoIcons[] = //fairy addition this should be for coordinates. use HMA table to easily apply additions, just read the hex value @ bottom right
{ //                                    anything above 0xFF need use reverse indian or little indian? so 00 01  should be 0x100
    { 12, 12, 0x00 },       // Unused
    { 32, 12, 0x20 },       // Normal icon  -00
    { 32, 12, 0x64 },       // Fight icon   -01
    { 32, 12, 0x60 },       // Flying icon  -02
    { 32, 12, 0x80 },       // Poison icon  -03
    { 32, 12, 0x48 },       // Ground icon  -04
    { 32, 12, 0x44 },       // Rock icon    -05
    { 32, 12, 0x6C },       // Bug icon     -06
    { 32, 12, 0x68 },       // Ghost icon   -07
    { 32, 12, 0x88 },       // Steel icon   -08
    { 32, 12, 0xA4 },       // ??? (Mystery) icon
    { 32, 12, 0x24 },       // Fire icon    -0A
    { 32, 12, 0x28 },       // Water icon   -0B
    { 32, 12, 0x2C },       // Grass icon   -0C
    { 32, 12, 0x40 },       // Electric icon 0D
    { 32, 12, 0x84 },       // Psychic icon -0E
    { 32, 12, 0x4C },       // Ice icon     -0F
    { 32, 12, 0xA0 },       // Dragon icon  -10
    { 32, 12, 0x8C },       // Dark icon    -11
    { 40, 12, 0x08 },       // Fairy Icon   -12    //fixed was 17 realized I could put here.
    { 40, 12, 0xA8 },       // -Type- icon  -13  
    { 40, 12, 0xC0 },       // -Power- icon -14
    { 40, 12, 0xC8 },       // -Accuracy- icon
    { 40, 12, 0xE0 },       // -PP- icon    -16
    { 40, 12, 0xE8 },       // -Effect- icon 17    
};

now instead of 0x17 fairy should be 0x12

after that I just had to update the values in type_constants.inc

pokemon.h

and make sure gTypeNames in battle_main.c had fairy right after dark.

adding any other types should follow the same convention,

add to type chart,

calculate coordinate

insert size and coordinate of icon in the array above before -type-icon

then update the other files for the new type as mentioned above.



Decomp is very adaptable, as long as we have the type icon somewhere on the chart,
and we have the size & coordinates.

We can adjust the order the game reads it in however we want, just by setting its place in the array in list_menu.c

if instead of after dark, I put my fairy data before type normal, then fairy would be type 1, the first read from the type chart
regardless of its location on the image.

(and of course I'd still need to update the other mentioned files appropriately)
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Forgot an important file, the game has a file that tells it how to read images, that also deals with types/type order.

that's the graphics_file_rules.mk not much you need to do to this one, but add fairy to the list of types.


Screenshot (1570).png


The final thing needed to properly set up your new type, is to adjust the TM_case icons function in tm_case.c

Code:
static void DrawMoveInfoUIMarkers(void)
{
    BlitMoveInfoIcon(4, 19, 0, 0);
    BlitMoveInfoIcon(4, 20, 0, 12);
    BlitMoveInfoIcon(4, 21, 0, 24);
    BlitMoveInfoIcon(4, 22, 0, 36);
    CopyWindowToVram(4, COPYWIN_GFX);
}

It's not very intuitive looking at it

But BlitMoveInfoIcon follows this convention. [window iD, Icon Id, X , Y]


This function pulls from the gMoveMenuInfoIcons array, where all the type icons are listed.

I now understand that THIS is why putting fairy at type 12, makes it over lap the type icon for the tm_case.


Since types start at value 0, making fairy the type 12, means its actually the 13th type in the game.

And it says here in the tm_case function that it uses IconId 19

BlitMoveInfoIcon(4, 19, 0, 0);

The slightly tricky part was realizing that converted to hexadecimal, 13 is 19. (since you just add 6 to whatever the normal value is)


So to add on to the last tip,

after moving the coordinate data of your new type, to before type-icon and after dark-icon.

you need to go to tm_case.c, and increase the IconID value for each of these BlitMoveInfoIcon functions,
by the number of types you added.

If you're just setting up fairy then increase them all by 1.


Like so.

Code:
static void DrawMoveInfoUIMarkers(void)
{
    BlitMoveInfoIcon(4, 20, 0, 0); 
    BlitMoveInfoIcon(4, 21, 0, 12); 
    BlitMoveInfoIcon(4, 22, 0, 24);
    BlitMoveInfoIcon(4, 23, 0, 36);
    CopyWindowToVram(4, COPYWIN_GFX);
}


and that's the FINAL thing necessary to setup a new type.
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
What's the max amount of types one can add? Is there a hard limit that the game will handle? Has anybody tested this?

Some of the functions involved in the process of adding new types use a u8 data type, so by default, the limit is probably 255.


SmashLucario

Yeah what Lunos said sounds right, I never looked into that but, I just want to add that while that is the physical/code limit, ( unless expanded -which isn't necessary)
Someone adding a bunch of types may run into a more practical limit before hitting 255.

This is mostly me just guessing/spit-ballin, (as I don't have my code in front of me right now)
but I believe its possible that adding a large number of types could cause ewram issues or game slowdowns.

Since you'd need to continue expanding the grahic sheet image to fit the type icons, there also may be a
limit to how big an image the rom/game could process.

and it could potentially (maybe) cause a size issue, if the file size for the sheet gets too big, it could affect the rom size.
Don't know to what degree or if it could even be a problem based on how its processed but, its a thing to consider.
 
1
Posts
1
Years
  • Age 28
  • Seen Jun 11, 2023
Adding the fairy type for binary is made simple because that program has a simple drag and drop method for adding it. So do that in HMA to add the fairy type to the vanilla rom, (or make your own).

Would anyone mind elaborating on this? I was using HMA for an initial binary hack and was unaware of this feature. I'm on the decomp route now but this would have made my life easier lmao. I have the fairy data set up on my decomp currently but this is the only lead i have for adding the actual icon.

nvm found it. somehow missed StarstruckShinys tutorial on this
 
Last edited:
Back
Top