Thread: Research: Items
View Single Post
  #11    
Old July 13th, 2011 (11:29 PM).
JPAN JPAN is offline
pokemon rom researcher
     
    Join Date: Dec 2008
    Posts: 104
    It's been a long time since I last posted, but I'm back with some new information on Items. Today, I'll be updating you on how Party-screen Items work.

    Party screen Items are a variety of items that are used directly on your pokemon on the party screen, or that are used in battle and affect your party pokemon. These include Healing items, Rare candy, Stones, Vitamins and stat-boosting items (like X-attack). TM's use a different system.

    Party-items use the same routines to be executed, but differ in the routine called. Namely, they are:
    Spoiler:
    Healing Item Function
    Code:
    Used by: Potion, Antidote, revive,, Vitamins, Berries
    Does: Allows pokemon selection, prints the "restored X HP" or "cured from X" after displaying the health bar restoring.
    Normal routine: 080a16e1
    Battle routine:  080a1fbd
    PP Restoring Function
    Code:
    Used by: Elixir, Ether, Leppa berry
    Does: Allows pokemon selection,then attack selection on a small mini-screen, prints the "restored X PP"
    Normal routine: 080a16fd
    Battle routine:  080a1ff5
    Healing item on all Pokemon
    Code:
    Used by: Sacred Ash
    Does: Allows pokemon selection,then uses desired effect on all pokemon that are capable of using it
    Normal routine: 080a176d
    Battle routine:  none
    Level up screen
    Code:
    Used by: Rare candy
    Does: Allows pokemon selection, prints the stats screen after use
    Normal routine: 080a1735
    Battle routine:  none
    Increase PP screen
    Code:
    Used by: PP Up
    Does: Allows pokemon selection,attack selection, prints effect
    Differs only from the restore screen because of the "PP to increase" line that appears next to the Attack selection box.
    Normal routine: 080a1719
    Battle routine:  none
    Battle stats
    Code:
    Used by: X Attack, Dire Hit
    Does: No pokemon selection, prints effect after used.
    Normal routine: none
    Battle routine:  080a1e7d
    CanUse-ShowHP screen
    Code:
    Used by: Fire Stone, Leaf stone
    Does: Allows pokemon selection, Shows "can't use" on top of pokemon where the item has no effect and HP bars over the ones where it works.
    Normal routine: 080a1751
    Battle routine:  none
    There is still one used by Yellow flute at 080a2239

    Putting this UI differences aside, the code beneath is pretty much the same. It runs two functions, one at 080413E4, that actually executes the code, and one at 08042414, that is called before, when the item is to be used on the pokemon, to determine if it will work at all. If either of them fails a "It Won't work" message is displayed.
    Each of this functions border the 4KB in size, so I won't be posting them here. But they work by reading from a table of Item Flags, and working on each.
    ItemFlags are stored in a table starting at 082528BC, starting with the value for the potion, and going all the way to Sitrus Berry, placing 0 on the items that have no party use. Those flags are a group of 6 to 10 bytes(depends on the flags present). Their layout is as follows:
    Spoiler:
    Code:
    byte 0
    80 heals infatuation
    40 forces to apply to first pokemon (no selection)
    20 is dire-hit (up to 30)
    1-f is increase attack battle stat by the given value
     
    byte 1
    1-f is increase speed battle stat by given value
    10-f0 is increase defence, in the same manner
     
    byte 2
    1-f is increase special attack (note: x special raises only special attack)
    10-f0 is increase accuracy
     
    byte 3
    80 is guard-spec 
    40 for level up
    20 for clear sleep
    10 for clear poison
    8 for clear burn
    4 for clear ice
    2 for clear paralyze
    1 for clear confusion
     
    byte 4
    1 is up HP EV
    2 is up Attack EV
    4 means heal HP
    8 means heal PP
    10 means only to selected attack (select made by GUI choice)
    20 means increase max PP
    40 means revive and heal
    80 means it's an evolution stone
     
    when 40 and 4 are set, item only heals fainted pokemon
    4 and 8 are mutually exclusive, you cannot heal PP and HP at the same time. 4 takes precedence over 8. 
     
    byte 5
    0x80 is the change happiness when 200+
    0x40 is the change happiness when 100-->199
    0x20 is the change happiness when -99
    0x10 is the increase PP to max on selected attack
    0x08 special defense ev up
    0x04 special attack ev up
    0x02 speed ev up
    0x01 defense ev up
     
    byte 6 
    recovery value for Potion-like items,
    increase in EV for EV-increasing items.
     
    PP restoring items have a maximum of 7f
    For health restoration, ff means max health, fe means half max health, fd is used by rare candy (only increase with level up)
     
    byte 7
    happiness increase/decrease for happiness on the range of 0-99
     
    byte 8
    happiness increase/decrease for happiness on the range of 100-199
     
    byte 9
    happiness increase/decrease for happiness on the range of 200-255
     
    bytes 7 to 9 are signed bytes, meaning that FF = decrease of 1 happiness


    So, what can we do with this information? Well, we can start designing new items with uses, such as new types of potions, new evolution stones, or new battle items. However, please note that you are limited to using items in the range between Potion(0d) and Sitrus berry (8e). To change that, we can erase the limiters at 0x08042508 (for the check routine) and the one at 0x0804152C (for the actual item usage). Replace each of those locations with 00 00 00 00. That will replace the jump with nop operations, erasing the check. Remember to repoint the entire table to a safe location if you do.

    But the best part about this find is that we now know all items of this type call two functions to determine what to do. If we change these functions, we can make items do whatever we want to the pokemon in our party.
    The system in place right now gives you some freedom to combine effects. But it will not allow you to do much. Even something as simple as an item that heals both PP and HP is impossible (without changing the routine).

    To end, an example of a new item, a candy that boosts happiness and heals 10 hp to your pokemon:
    The script would be
    Code:
    00 00 00 00 04 e0 0a 0a 06 04
    Which means happiness boosted by 10 if less than 99, 6 if between 100 and 199 and 4 if over 200.
    Placing this item immediately before HP-up, you would:
    - place this in the rom in some location
    - place the address to this location at 08252980
    - overwrite the item above HP-up (Starting at 083dbad0), with all the usual data (index, name, price...)
    - place as the Normal usage pointer the healing item function.
    __________________
    Here are the links for my work


    Currently working on:
    Battle Script Documentation
    Another large project
    Reply With Quote