View Single Post
Old July 26th, 2011 (4:10 PM). Edited 3 Weeks Ago by Missingyep.
Missingyep Missingyep is offline
    Join Date: Jul 2010
    Posts: 275
    Item Creation in FireRed

    Pokemon FireRed contains numerous "????????" items. These are unused items that serve no purpose in the game. Using hex editing and some programs, we can turn these into real items, with their own names, descriptions, and images. Certain hacks that have been released even allow us to make our items run scripts.

    This tutorial will tell you how to do all of that -- that is, how to create an item with a custom name, description, image, and (if using JPAN's hacked engine) function.

    To follow this tutorial, you will need:
    Basic changes
    Start up Item Manager, and choose any of the "????????" items. In this tutorial, we will be editing the "????????" that comes right after "GREEN SHARD".

    Use Item Manager to change the item's name and attributes as desired. Do not touch the "Description" or "Index" fields; we will deal with the description later.

    Correcting the index
    Every item has an "index" value, which the game seems to use to verify that the item is real. The index values correspond to the order the items' data is stored in. The "????????" items, however, don't have valid indices; they all have index values of 0. To turn our "????????" into a real item, we must give it a valid index.

    If you look at the indices of valid items, you'll find that they're all numbered in sequence. BLUE SHARD has an index of 31, YELLOW SHARD is 32, GREEN SHARD is 33... and the "????????" after it is 0. We need to give it an index that follows the pattern -- in this case, 34.

    Remember that we're dealing with hex, not decimal.

    Change the index and save your changes. Close the Item Manager.

    Changing the description
    XSE is a script editor. People use it to make NPCs talk and perform other actions. One of XSE's features is the ability to add new strings (chunks of text) to the ROM, for scripts to use. We're going to do something a little different, though: we're going to write a "script" that consists of a string... and nothing else. And then we are going to tell the game to use that string as the description for our new item.

    Open XSE and load your ROM.

    In the main textbox, type the following:
    #dynamic 0x0800000
    #org @string
    = This is a description for our new\nitem.
    The first line (#dynamic 0x0800000) tells XSE to automatically look for unused space in the ROM, and to store our string in any free space it finds. The number (0x0800000) just tells XSE where to start looking.

    The second line (#org @string) tells XSE that we are creating a new section for our "script". In this case, the section is a string.

    The third line is the actual value of our string. (The equal sign and first space won't be stored.) The "\n" represents a line break. Feel free to use any value of your choosing; XSE has a "Text Adjuster" that you can use to place line breaks in the proper spots. Remember that you only have three lines of text to work with.

    Click the button with an image of two gears ("Compile"), and pay very careful attention to the window that pops up when you do.

    At the bottom of the "Compiler Output" window, there will be two list-boxes. Above them is the text "Dynamic Offsets". These boxes tell us the specific offset that XSE saved the string to. Click the "Copy" button to copy the offset. Do not lose this number.

    (The number probably will not be the same as the one in my screenshots. For this tutorial, I am using a FireRed ROM that has had no other changes applied to it, so the offset for my description is 800000. If you've made changes to your ROM, your offset will probably be different. This is perfectly normal.)

    Close XSE. You don't have to save, if it asks you.

    Using the item description
    Reopen the Item Manager.

    Go back to the "Description" box, and replace its contents with the offset that the description was saved to. Hit the "Save" button, and you should see your new description.

    Adding a new item image to the game
    Before we can give the item a new image, we must insert that image into the ROM. And before we can insert the image into the ROM, we have to create it.

    Open the image editor of your choice, and create a 24x24-pixel image. Do not use more than 16 colors (including the background color, which should become transparent). When you are finished, use the image editor to decrease the color depth of the image, and save it as a 16-color bitmap (*.BMP) or PNG. (Microsoft Paint won't be able to reduce the color depth, but the freely-available editor IrfanView can.)

    For the tutorial, we will be using this image:

    Now that we have created the image, open NSE, and use it to load your ROM. When you do, NSE will automatically open the Hero overworld sprite for viewing.

    Open the "View" menu, and choose "Offset". You should see this dialog box:

    In order to create a new sprite, we have to find unused space in the ROM. Open the Free Space Finder, and load your ROM.

    Use FSF to find 256 bytes of free space starting at 800000. Copy the offset that it gives you. Note that it may not give you the same offset that it gives me in these images; it depends on how much content you have added to your ROM.

    The offset must end in "0", "4", "8", or "C". If it doesn't, then the game will crash when it attempts to load the sprite!
    If the offset doesn't end in one of those characters, then simply increase it until it does. If you so desire, you can use FSF to make sure that the revised offset still has enough room.

    Paste the offset into the NSE dialog ("Offset Browsing") that you opened before. Write it down somewhere else as well, as you will need it later.

    Add 0x100 to the offset. If you don't know how to do math in hex, then you can use Windows Calculator (in "Programmer" mode). Insert the new offset into FSF's "Search from offset" textbox. Search for 128 bytes of free space.

    Copy the result, and paste it into the "Palette" field in the NSE dialog. Write it down somewhere else as well, as you will need it later.

    The offset must end in "0", "4", "8", or "C". If it doesn't, then the game will crash when it attempts to load the sprite!
    If the offset doesn't end in one of those characters, then simply increase it until it does. If you so desire, you can use FSF to make sure that the revised offset still has enough room.

    In the NSE dialog, change the "Size" fields to both read "24", and then click "Open". Then close the dialog. Close FSF.

    You should see this:

    Now, we need to import the image file into NSE. Go to File -> Import -> Import Image. This dialog box will appear:

    [Image 18 -- Missing due to link rot. Sorry!]

    Use the "Load" button to select your image file. Then, change the "Image" dropdown to "All" and click "Save". You'll see a confirmation dialog; click "Yes". On the Import dialog, click "Close".

    The main NSE window should now look like this:

    Go to File -> Insert. Insert your image and your palette, using the offsets that you entered earlier. For both dialog boxes, check "Compress Data [Lz77]".

    Go to File -> Save. Close NSE.

    Using the new item image
    Open Item Image Editor and load your ROM.

    [Image 20 -- Missing due to link rot. Sorry!]

    Find your item in the list and select it. This may be a bit difficult, as Item Image Editor does not use the item names that are stored in the ROM.

    Change the image and palette offsets to the ones that you copied out of FSF. Go to File -> Save ROM, and then exit the Item Image Editor.

    Making the item do something
    NOTE: This part of the tutorial only works if you are using JPAN's Hacked FireRed Engine. If your ROM does not use that hack, then attempting to follow these instructions will only cause problems.

    JPAN's FireRed Hacked Engine contains an interesting little feature. It is possible to make an item that, when used, backs the player out of their Bag and runs an XSE script. We are going to explore how to do that, but first, a warning: it does not work if you activate an item by pressing Select.

    First, we have to create a script for our item to use. Open XSE. You can create any kind of script you want; I'll be making a script that teleports a player to Map 4.1 -- the player's bedroom, in an unmodified FireRed ROM. The code:

    #dynamic 0x800000
    #org @start
    warp 0x04 0x01 0x00 0x00 0x00

    Compile the script and write its offset down somewhere. For my FireRed ROM, the offset is 800154.

    Open the Item Manager. Click the ">>" button to go to the second "page" of the form. Change the "Field Usage" value to 161521; this is where some of JPAN's code is stored. Click the "Save" button.

    Unfortunately, we'll need to break out the hex editor now. And we'll also need to do some math. Open your ROM using the hex editor of your choice, and go to offset 03DB028.

    Here is where we need to use some math. Take the hex index of the new item -- 34, in this case -- and multiply it by 2C. (You can use Windows Calculator's "Programmer" mode for this.) The result, for index 34, is 8F0. Add the result to the hex number 03DB028. When you're done with all the math, you'll have the offset of the first letter in your item's name -- 3DB918, for this tutorial. Go to that offset in your hex editor. Write it down somewhere, too.

    Add hex E to that offset (result 3DB926, for this tutorial) and verify that the value of the byte at that new offset is the same as the item's index. For this tutorial, we check if the byte at offset 3DB926 has the hex value "34". If it does, then proceed.

    Take the offset of your script. Split it into bytes and put them in reverse order. My script offset, 800154, should become 54 01 80. Put an 08 at the end of your rearranged offset: for me, the result is 54 01 80 08. This data is called a "pointer"; it tells the game where to look for something. We need to insert that pointer into a part of the item data that most programs don't allow you to modify.

    Remember the offset that I said to write down? The offset of the first letter in your item's name? Take that offset and add hex 28 to it. For this tutorial, that's 3DB918 + 28 = 3DB940. Go to that offset in your hex editor. Select the four bytes located there.

    Replace them with your pointer.

    Take the offset of the first letter again, and add 1C to it. (For this tutorial, that'll be 3DB934.) Go to that new offset. The first three bytes at that offset should be 21 15 16. If the byte after those three is not 08, change it to 08. (Apparently, Item Manager is a bit forgetful sometimes...)

    Save the changes and exit your hex editor.

    All that remains is for you to test the item. Since it's an unused item, there's no normal way to obtain it in-game. You'll have to use XSE to create or modify a script to give it to you.

    Here are some images of me testing the new item out; if you used the text and images provided in this tutorial, your finished item should look pretty much the same. To test, I created a separate copy of the ROM and in that copy, I replaced the bedroom PC script with one that just hands out the item.

    I took the item from the PC. Checked the icon and description. Went outside, used it. And it worked.

    My instructions on how to use the item functionality in JPAN's hacked engines were based on the instructions that he posted in his thread. Info on the Select-button bug in that functionality also posted by JPAN.
    Reply With Quote