The PokéCommunity Forums Fan Games ROM Hacking Research & Development
Research Pokémon Data Structures (Firered)

Research & Development Got a well-founded knack with ROM hacking? Love reverse-engineering the Pokémon games? Or perhaps you love your assembly language. This is the spot for polling and gathering your ideas, and then implementing them! Share your hypothesis, get ideas from others, and collaborate to create!

Reply
 
Thread Tools
  #1    
Old July 16th, 2012 (8:36 PM). Edited July 17th, 2012 by redriders180.
redriders180's Avatar
redriders180 redriders180 is offline
Mastermind of Pokemon Glazed
     
    Join Date: Jun 2010
    Location: Path of Victory, Tunod
    Gender: Male
    Nature: Quirky
    Posts: 540
    Send a message via AIM to redriders180
    Time for me to appeal to the researchers of Pokecommunity in order to help with some things that might be interesting to do in a Rom Hack. Mainly, I'm talking about taking the Pokémon data structures, and modifying them to allow more useful things to be done with that data. To save you the trouble, I've copied the current data structures of the Gen III games:

    Spoiler:

    Personality dword 0
    OT ID
    dword 4
    Nickname
    10 bytes 8
    Language word 18
    OT name
    7 bytes 20
    Mark byte 27
    Checksum
    word 28
    ????
    word 30
    Data
    48 bytes 32
    Status ailment
    dword 80
    Level
    byte 84
    Pokérus remaining byte 85
    Current HP
    word 86
    Total HP
    word 88
    Attack
    word 90
    Defense
    word 92
    Speed
    word 94
    Sp. Attack
    word 96
    Sp. Defense word 98


    and the encrypted data:

    Spoiler:

    Growth:
    Spoiler:

    Species word 0
    Item held
    word 2
    Experience
    dword 4
    PP bonuses
    byte 8
    Friendship byte 9
    ???
    word 10

    Attacks:
    Spoiler:

    Attack 1 word 0
    Attack 2 word 2
    Attack 3
    word 4
    Attack 4
    word 6
    PP 1
    byte 8
    PP 2 byte 9
    PP 3
    byte 10
    PP 4 byte 11

    Effort:
    Spoiler:

    HP EV byte 0
    Attack EV
    byte 1
    Defense EV
    byte 2
    Speed EV
    byte 3
    Sp. Attack EV
    byte 4
    Sp. Defense EV
    byte 5
    Coolness
    byte 6
    Beauty
    byte 7
    Cuteness
    byte 8
    Smartness
    byte 9
    Toughness byte 10
    Feel
    byte 11

    Misc:
    Spoiler:

    Pokérus status byte 0
    Location caught
    byte 1
    Level caught signed byte 2
    Poké Ball/Trainer gender
    byte 3
    IVs
    dword 4
    Ribbons
    dword 8

    The above being copied from Bulbapedia.

    Glancing at the above, there are many slots in the data that aren't used in Firered. Additionally, there are a few bytes that might not serve a purpose in a ROM hack, specifically language, which serves a purpose I currently don't know. I've heard that Pokerus in Firered is nonexistant as well, and the byte is basically unused. The six contest stats, and ribbons are also sitting unused. This unused data could be useful in porting over functions from Gen IV and V into Gen III. The "Pokerus Remaining" byte is the only unencrypted value I'm comfortable hacking, unless I receive confirmation that the language half-word is essentially unused.

    The main function I have in mind for this byte is to breathe new life into a thread that seems to have hit a dead end: Hidden abilities. After browsing that thread, it seems most people were hung on the fact that abilities are controlled by a single bit, meaning two is the max. If we could somehow redirect the code to this byte, instead of to the bit that determines ability, we could easily figure out a way to unlock hidden abilities.

    Gen IV also uses a byte for forme determination. I believe Jambo51 and Chaos Rush have been working on a method for enabling forme changes in their 649 Patches, and they probably use a different method to achieve it, this could be an alternate way. The Gen I and II games have a section of data in their Pokemon data structures that accounts for both primary and secondary typing. If we could use the Pokerus Remaining byte, as well as the language half-word, formes with different types could become more feasible.

    The data structure could be used in plenty of other ways not mentioned, but I can't currently think of. I was hoping to collaborate to see if anyone has any info on how these structures are stored and modified, in addition to info that could be used for anything else I might've mentioned. If anything, I hope I set the wheels turning for someone out there
    __________________


    I think I'm done with ROM hacking. I'll still pop in and visit, though.


    Reply With Quote

    Relevant Advertising!

      #2    
    Old July 17th, 2012 (3:30 AM).
    Ark_Silvanos's Avatar
    Ark_Silvanos Ark_Silvanos is offline
       
      Join Date: Jan 2009
      Location: Texas
      Age: 25
      Gender: Male
      Posts: 150
      but doesn't the pokerus remaining byte get removed if u box a pokemon? i'm not really sure if it will save that value and load it or randomize it when u take it out.

      Also unless i'm mistaken, isn't the bit that controls ablility the last bit in the 'personality' dword? this word controls every random attribute a pokemon has when its first met (i think neway...), and theres no other check for ability otherwise. So in this case, in order for a hidden ability to exist, the game would have to run a check to see if the byte for the hidden ability (in the pokemon data structure) was set and load the hidden ability, and run the normal ability check if its not present (because that byte wouldn't exist for wild pokemon). Which could be done, i guess, but would take a lot of work to make it work. [I might be totally wrong about this tho XD]

      And i'm not totally sure of this, but the language word might be used in a check somewhere when trading pokemon between different language versions? i dunno... bulbapedia has given a list of valid values, so i guess there must be a check somewhere....

      newayz... sorry i'm such a wet blanket ... but i guess if we could find some use for it, it could lead to some pretty cool new features
      __________________


      Reply With Quote
        #3    
      Old July 17th, 2012 (7:08 AM).
      NarutoActor's Avatar
      NarutoActor NarutoActor is offline
      The rocks cry out to me
      • Silver Tier
       
      Join Date: Jan 2009
      Location: Brooklyn/Marlboro
      Age: 23
      Gender: Female
      Nature: Bashful
      Posts: 1,979
      Send a message via AIM to NarutoActor Send a message via Windows Live Messenger to NarutoActor
      Pokerus is only in FireRed for compatibility with the other games. But since it lacks a RTC, it is unlimited if a pokemon already has it, and imposable without trading/cheating.
      __________________
      ~There are those people who understand hex, F the rest
      Reply With Quote
        #4    
      Old July 17th, 2012 (7:16 AM).
      redriders180's Avatar
      redriders180 redriders180 is offline
      Mastermind of Pokemon Glazed
         
        Join Date: Jun 2010
        Location: Path of Victory, Tunod
        Gender: Male
        Nature: Quirky
        Posts: 540
        Send a message via AIM to redriders180
        Quote:
        Originally Posted by Ark_Silvanos View Post
        but doesn't the pokerus remaining byte get removed if u box a pokemon? i'm not really sure if it will save that value and load it or randomize it when u take it out.

        Also unless i'm mistaken, isn't the bit that controls ablility the last bit in the 'personality' dword? this word controls every random attribute a pokemon has when its first met (i think neway...), and theres no other check for ability otherwise. So in this case, in order for a hidden ability to exist, the game would have to run a check to see if the byte for the hidden ability (in the pokemon data structure) was set and load the hidden ability, and run the normal ability check if its not present (because that byte wouldn't exist for wild pokemon). Which could be done, i guess, but would take a lot of work to make it work. [I might be totally wrong about this tho XD]

        And i'm not totally sure of this, but the language word might be used in a check somewhere when trading pokemon between different language versions? i dunno... bulbapedia has given a list of valid values, so i guess there must be a check somewhere....

        newayz... sorry i'm such a wet blanket ... but i guess if we could find some use for it, it could lead to some pretty cool new features
        Well, according to my research, it seems that this byte isn't affected at all during Firered. Pokerus is actually preserved when you store the Pokemon in the PC. Pokerus is designed to end at midnight, and due to Firered's lack of a RTC, it just stays on a Pokemon indefinately. I don't believe you can even find it in the wild in the Firered games...the byte is only there to allow for compatability between RSE, which DO use that byte.

        My idea would require the code that generates Pokemon to be modified somewhat. Currently, ability is decided whether or not the personality value is odd or even. We could modify that code to instead use the pRNG (another source of randomness in-game), see if it's even or odd, and then load the byte value of the corresponding ability into the newly-made "ability" byte. We would also need to modify how an ability is read, by making it use that byte instead of the original way.

        Since most hacks are designed as a stand-alone game, trading between games isn't foremost on my mind. I thought it might have something to do with an experience boost, but foreign language trades don't get a boost until Gen IV.

        I also neglected to mention...some people might want to use the Pokerus byte for what it was actually intended for, to give someone Pokerus that actually does expire and is generated.

        Thanks for everyone's support so far
        __________________


        I think I'm done with ROM hacking. I'll still pop in and visit, though.


        Reply With Quote
          #5    
        Old July 17th, 2012 (9:06 AM).
        Ark_Silvanos's Avatar
        Ark_Silvanos Ark_Silvanos is offline
           
          Join Date: Jan 2009
          Location: Texas
          Age: 25
          Gender: Male
          Posts: 150
          Quote:
          Originally Posted by redriders180 View Post
          Well, according to my research, it seems that this byte isn't affected at all during Firered. Pokerus is actually preserved when you store the Pokemon in the PC. Pokerus is designed to end at midnight, and due to Firered's lack of a RTC, it just stays on a Pokemon indefinately. I don't believe you can even find it in the wild in the Firered games...the byte is only there to allow for compatability between RSE, which DO use that byte.
          no what i meant was when u store a pokemon in the box, the data for the pokerus remaining byte gets erased, since only 80 bytes of data are stored for each pokemon in the boxes. What i'm not sure of is what happens to the pokerus byte tho... does that value get saved somewhere? or does the pokemon get re-infected when it gets taken out?

          Quote:
          Originally Posted by redriders180 View Post
          My idea would require the code that generates Pokemon to be modified somewhat. Currently, ability is decided whether or not the personality value is odd or even. We could modify that code to instead use the pRNG (another source of randomness in-game), see if it's even or odd, and then load the byte value of the corresponding ability into the newly-made "ability" byte. We would also need to modify how an ability is read, by making it use that byte instead of the original way.
          but again, this would only apply to pokemon in the party or pokemon the player owns (depending on using the 'language' or the 'pokerus rmn' data we use) cuz I dont think wild pokemon and enemy pokemon have this data...


          Newayz... I'm not gonna pretend I kno everything about the game, mechanics or otherwise, as I've only played these games very casually (gen 1-3... no 4+). I'm just going by what i read on bulbapedia about how this stuff works, so feel free to correct me if I'm wrong
          __________________


          Reply With Quote
            #6    
          Old July 17th, 2012 (9:30 AM). Edited July 17th, 2012 by redriders180.
          redriders180's Avatar
          redriders180 redriders180 is offline
          Mastermind of Pokemon Glazed
             
            Join Date: Jun 2010
            Location: Path of Victory, Tunod
            Gender: Male
            Nature: Quirky
            Posts: 540
            Send a message via AIM to redriders180
            Quote:
            Originally Posted by Ark_Silvanos View Post
            no what i meant was when u store a pokemon in the box, the data for the pokerus remaining byte gets erased, since only 80 bytes of data are stored for each pokemon in the boxes. What i'm not sure of is what happens to the pokerus byte tho... does that value get saved somewhere? or does the pokemon get re-infected when it gets taken out?



            but again, this would only apply to pokemon in the party or pokemon the player owns (depending on using the 'language' or the 'pokerus rmn' data we use) cuz I dont think wild pokemon and enemy pokemon have this data...


            Newayz... I'm not gonna pretend I kno everything about the game, mechanics or otherwise, as I've only played these games very casually (gen 1-3... no 4+). I'm just going by what i read on bulbapedia about how this stuff works, so feel free to correct me if I'm wrong
            I thought the Pokerus byte was saved higher up, but the last 20 bytes are recalculated when a Pokemon is taken out of the PC.

            Quote:
            Originally Posted by Bulbapedia
            Pokémon that are put into the PC will keep the status indefinitely.
            I think I realize why this is. The Pokerus "flag" is part of the encrypted data subsection of the Pokemon's data. It doesn't get erased when the Pokemon is put in the PC. I assume that, when a Pokerus'd Pokemon is taken out of the PC, it checks if the Pokerus flag is set, and if it is, it'll reset the "Pokerus Remaining" byte.

            That's not to say this is a dead end...the Pokerus "flag" could be used as a "Hidden Ability flag", and when the Pokemon is taken out of the PC, it'll recalculate what the hidden ability is supposed to be.

            Enemy Pokemon are stored in the same format as the team. There are 600 Bytes for the party Pokemon, and 600 bytes reserved for enemy Pokemon. In reality, you could make a "settrainerbattle" script, modify the data in it with writebytetooffset, and then use "repeattrainerbattle" to activate it.

            Edit:
            Quote:
            Originally Posted by Bulbapedia
            Pokérus status is stored in a single byte. The lower 4 bits represents the number of units of time left until the virus wears away. If any bit in the upper 4 bits is set, the Pokémon is immune to Pokérus, indicated a small black dot appears on the Pokémon's status screen. Both values are completely random when caught, leading to the fact that not all Pokémon contract the virus for the same amount of time and some are able to catch it again.
            I'm going to need to do some research, to see if these bytes are actually used in the Firered games.

            Double Edit: At least with givepokemon, these bytes are zero, which means that they shouldn't be an issue.
            __________________


            I think I'm done with ROM hacking. I'll still pop in and visit, though.


            Reply With Quote
              #7    
            Old July 17th, 2012 (1:32 PM).
            Jambo51's Avatar
            Jambo51 Jambo51 is offline
            Glory To Arstotzka
               
              Join Date: Jun 2009
              Gender: Male
              Nature: Quiet
              Posts: 732
              You need to tidy up the list of unencrypted data, it's very hard to read in the format you have it in.

              Anyway - For the creation of formes in FR, I actually used the upper half of the mark byte as storage for the forme ID. There are 4 marks, which can be set to on or off, which is, of course, a binary setting, which means they use a bit each.

              This leaves 4 bits in the upper half of that byte which are unused. After a minor rewrite of the decrypter and encrypter, I was able to gain these bits for my own use.

              4 bits allows for 16 possible combinations, which is actually quite a lot in terms of formes.

              The "upper half" of the byte refers to the leftmost bits in binary:

              128 64 32 16 8 4 2 1

              In more ROM hacking orientated terms, it means that of a mark byte 0x32, the 0x30 stands for the forme the Pokémon is currently in while the 0x2 stands for which marks is has assigned to it.
              __________________
              Hey guys, please check out my recreations of the gen 1 and 2 music on my custom engine at my SoundCloud! - Here!
              Reply With Quote
                #8    
              Old July 17th, 2012 (2:25 PM). Edited July 17th, 2012 by redriders180.
              redriders180's Avatar
              redriders180 redriders180 is offline
              Mastermind of Pokemon Glazed
                 
                Join Date: Jun 2010
                Location: Path of Victory, Tunod
                Gender: Male
                Nature: Quirky
                Posts: 540
                Send a message via AIM to redriders180
                Quote:
                Originally Posted by Jambo51 View Post
                You need to tidy up the list of unencrypted data, it's very hard to read in the format you have it in.

                Anyway - For the creation of formes in FR, I actually used the upper half of the mark byte as storage for the forme ID. There are 4 marks, which can be set to on or off, which is, of course, a binary setting, which means they use a bit each.

                This leaves 4 bits in the upper half of that byte which are unused. After a minor rewrite of the decrypter and encrypter, I was able to gain these bits for my own use.

                4 bits allows for 16 possible combinations, which is actually quite a lot in terms of formes.

                The "upper half" of the byte refers to the leftmost bits in binary:

                128 64 32 16 8 4 2 1

                In more ROM hacking orientated terms, it means that of a mark byte 0x32, the 0x30 stands for the forme the Pokémon is currently in while the 0x2 stands for which marks is has assigned to it.
                Heh, I guess it would be a good idea to proofread before I post...I'll tidy that up after I do this post.

                I had noticed the marks that are used for boxes, and I thought it could be useful, since I don't really know anyone who uses them, except that they're modifiable on a whim. That was a good idea for the formes, though! Maybe we could use a similar method for abilities, or other things.

                If it's not too much to ask, would you share your routine for decrypting the "data" subsection?
                __________________


                I think I'm done with ROM hacking. I'll still pop in and visit, though.


                Reply With Quote
                  #9    
                Old July 17th, 2012 (8:43 PM).
                Ark_Silvanos's Avatar
                Ark_Silvanos Ark_Silvanos is offline
                   
                  Join Date: Jan 2009
                  Location: Texas
                  Age: 25
                  Gender: Male
                  Posts: 150
                  Quote:
                  Originally Posted by redriders180 View Post
                  I think I realize why this is. The Pokerus "flag" is part of the encrypted data subsection of the Pokemon's data. It doesn't get erased when the Pokemon is put in the PC. I assume that, when a Pokerus'd Pokemon is taken out of the PC, it checks if the Pokerus flag is set, and if it is, it'll reset the "Pokerus Remaining" byte.

                  That's not to say this is a dead end...the Pokerus "flag" could be used as a "Hidden Ability flag", and when the Pokemon is taken out of the PC, it'll recalculate what the hidden ability is supposed to be.


                  Edit:

                  I'm going to need to do some research, to see if these bytes are actually used in the Firered games.

                  Double Edit: At least with givepokemon, these bytes are zero, which means that they shouldn't be an issue.
                  ah... haha ur right... it would make sense for it to reset it based on the flag and not randomly ... I dont know where my brain was when i was thinking that... but then we wouldn't be able to see the ability unless it was in our party, right? or is that how hidden abilites are supposed to work? Like ur not supposed to see em, they just work?

                  Wouldn't it just be easier to use the pokerus flag itself? like if we use the upper 4 bits while keeping the lower 4 bits 0, then the pokemon would never contract pokerus (cuz i believe pokerus is coded in the game, it just is never used), and the upper 4 bits can be put to use.

                  Quote:
                  Originally Posted by redriders180 View Post
                  Enemy Pokemon are stored in the same format as the team. There are 600 Bytes for the party Pokemon, and 600 bytes reserved for enemy Pokemon. In reality, you could make a "settrainerbattle" script, modify the data in it with writebytetooffset, and then use "repeattrainerbattle" to activate it.
                  ah k... i didn't kno that... so when u encounter a pokemon (trainer or wild) the entire 100 bytes for the pokemon gets generated?

                  Quote:
                  If it's not too much to ask, would you share your routine for decrypting the "data" subsection?
                  doesnt JPAN have a routine that decrypts it as part of his hacked engine? u could use that as a base...

                  Quote:
                  Originally Posted by Jambo51 View Post
                  You need to tidy up the list of unencrypted data, it's very hard to read in the format you have it in.

                  Anyway - For the creation of formes in FR, I actually used the upper half of the mark byte as storage for the forme ID. There are 4 marks, which can be set to on or off, which is, of course, a binary setting, which means they use a bit each.

                  This leaves 4 bits in the upper half of that byte which are unused. After a minor rewrite of the decrypter and encrypter, I was able to gain these bits for my own use.

                  4 bits allows for 16 possible combinations, which is actually quite a lot in terms of formes.

                  The "upper half" of the byte refers to the leftmost bits in binary:

                  128 64 32 16 8 4 2 1

                  In more ROM hacking orientated terms, it means that of a mark byte 0x32, the 0x30 stands for the forme the Pokémon is currently in while the 0x2 stands for which marks is has assigned to it.
                  With the forms, the routine your using loads all the pokemon data, right? like type and stats and stuff and not only graphics? So then a branch could be made in that routine using the pokerus data as a check to determine if a pokemon has a hidden ability as well?


                  --------------------------------------------------------------------------

                  sorry bout all this, but i figured the easiest way to learn is just by asking you guys
                  __________________


                  Reply With Quote
                    #10    
                  Old July 17th, 2012 (9:14 PM).
                  redriders180's Avatar
                  redriders180 redriders180 is offline
                  Mastermind of Pokemon Glazed
                     
                    Join Date: Jun 2010
                    Location: Path of Victory, Tunod
                    Gender: Male
                    Nature: Quirky
                    Posts: 540
                    Send a message via AIM to redriders180
                    Quote:
                    Originally Posted by Ark_Silvanos View Post
                    ah... haha ur right... it would make sense for it to reset it based on the flag and not randomly ... I dont know where my brain was when i was thinking that... but then we wouldn't be able to see the ability unless it was in our party, right? or is that how hidden abilites are supposed to work? Like ur not supposed to see em, they just work?

                    Wouldn't it just be easier to use the pokerus flag itself? like if we use the upper 4 bits while keeping the lower 4 bits 0, then the pokemon would never contract pokerus (cuz i believe pokerus is coded in the game, it just is never used), and the upper 4 bits can be put to use.
                    This would also serve a nifty dual-purpose...the little dot that indicates that a Pokemon has had Pokerus before could be repurposed as a "Dream World" indicator.

                    If anything, we'd still have to rework fair amounts of the code, such as the code that displays which ability a Pokemon'd have. It would have to display by reading the "Ability" byte, and then displaying whatever ability corresponds with that byte. Just another thing to modify...


                    Quote:
                    ah k... i didn't kno that... so when u encounter a pokemon (trainer or wild) the entire 100 bytes for the pokemon gets generated?
                    Yep!


                    Quote:
                    doesnt JPAN have a routine that decrypts it as part of his hacked engine? u could use that as a base...
                    I was hoping to not have to mess around with trying to find the ASM of the original special, and even then, try to decipher it. I do know that his decryption formula is a little different...it stores the unencrypted data in one spot, and each different data section in one of four locations. I don't know whether that makes it easier or harder to work with, though...I was hoping to maybe get some other input on the subject.

                    For the formes, I've got a small idea about how they might work, at least, graphically speaking. One could make a larger-than-usual Pokemon sprite, similar to the ones in Emerald. You could then read the Forme Change byte, and depending on its value, shift up the image to display one of the other frames. This would just require a small addition to the graphics display code that draws the Front sprite of the opponent, Back sprite of your team, the preview in the PC, the party summary, and possibly the "ShowPokemonPic" command.
                    __________________


                    I think I'm done with ROM hacking. I'll still pop in and visit, though.


                    Reply With Quote
                    Reply
                    Quick Reply

                    Sponsored Links
                    Thread Tools

                    Posting Rules
                    You may not post new threads
                    You may not post replies
                    You may not post attachments
                    You may not edit your posts

                    BB code is On
                    Smilies are On
                    [IMG] code is On
                    HTML code is Off

                    Forum Jump


                    All times are GMT -8. The time now is 5:12 PM.