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!

TrollandToad.com
Reply
 
Thread Tools
  #1    
Old January 26th, 2013 (9:59 PM). Edited January 27th, 2013 by Shiny Quagsire.
Shiny Quagsire's Avatar
Shiny Quagsire Shiny Quagsire is offline
I'm Still Alive, Elsewhere
     
    Join Date: May 2009
    Location: Hoenn Safari Zone
    Age: 19
    Gender: Male
    Nature: Jolly
    Posts: 700
    Using the Berry Bag for Item Selection

    So, recently I've been working on making a complete berry system based on JPAN's Berry System on Fire Red. For a planting script, it required some sort of berry selection, and having a scripted multichoice menu for it was a no-go for me. So, I got to work, searching and searching, and I got it!

    While you may think doing this would be complicated, there are is actually only one ASM routine required for this. Basically, what it does is it forces the bag into thinking every item is the Exit item, which will exit the bag immediately as it's selected. Along the way to exiting the routine, it stores the berry ID to variable 0x800E, or 0x0 if the user didn't select anything or pressed B. Under normal circumstances, this is wiped upon exiting the bag, but because of the way we call the bag, it preserves this variable.

    hijackbag.asm:
    Code:
    @Forces the bag to exit instead of opening the menu.
    @Insert bx r3 at (18 47) 0813DB18, and the pointer to this routine (+1) at 0813DB30
    
    .thumb
    .thumb_func
    .global hijackbag
    
    main:
    	ldr r3, var_8000
    	ldrh r3, [r3]
    	cmp r3, #0x7E
    	beq hack
    	ldr r3, unk_0203F370
    	mov r8, r3
    	ldrb r0, [r3,#0x4]
    	b return
    hack:
    	ldr r3, unk_0203F370
    	mov r8, r3
    	mov r0, #0x5
    return:
    	ldr r3, returnaddress
    	bx r3
    .align 2
    returnaddress: 		.word 0x0813DB1D
    unk_0203F370:		.word 0x0203F370
    var_8000:		.word 0x020370B8
    All this does it it checks variable 0x8000 (you can change it to use the variable decrypter if you wish) for a strange value that wouldn't misfire our hack. In this case, I chose 0x7E. Any other weird values will work if you feel 0x7E isn't apropriate.

    To insert this, place 18 47 at 0x13DB18, and the pointer to this routine + 1 at 0x13DB30.

    Now, to use this hack, simply place the following into a script:
    Code:
    fadescreen 1        'Fade the screen to prevent any graphical glitches from being visible. And it looks nice. :)
    setvar 0x8000 0x7E  'Set 0x8000 to trigger our script
    setvar 0x800E 0x0   'Make sure 0x800E isn't set, because if it is, weird things happen.
    callasm 0x0a1881    'Call the berry bag. This is stored internally in the ROM
    waitmsg             'I'll explain this later.
    setvar 0x8000 0x0   'Reset our hack to prevent weirdness.
    Ok, so basically this fades the screen, sets our trigger variable, calls the routine, and resets. However, if your a scripter, you might be thinking "What the heck is up with that waitmsg? Did we even call an msgbox?" Well, there's a reason for doing that. When the ASM code is called, it basically hands it to a table so that it is updated every time the game runs the main loop. However, this also means that the script keeps going during this time, which can be bad if you're calling a bufferitem 0x0 0x800E afterwards, or anything that borrows the value at 0x800E. So, the waitmsg acts as a delay so that the script waits until our player is finished choosing which berry he wants.

    As for applications to apply this to, here's an example script I wrote to test this:
    Spoiler:

    #dynamic 0x100011B
    #include stditems.rbh

    #org @start
    lock
    faceplayer
    msgbox @msg 0x5
    compare 0x800d 0x1
    if 0x1 goto @plant
    release
    end

    #org @plant
    giveitem ITEM_ORANBERRY 3 0
    giveitem ITEM_CHERIBERRY 1 0
    giveitem ITEM_SITRUSBERRY 1 0
    fadescreen 1
    setvar 0x8000 0x7E
    setvar 0x800E 0x0
    callasm 0x0a1881
    waitmsg
    setvar 0x8000 0x0
    compare 0x800E 0x0
    if 0x1 goto @noberry
    bufferitem 0x0 0x800E
    msgbox @planted 2
    release
    end

    #org @noberry
    msgbox @noplant 2
    release
    end

    #org @msg
    = There is a dude standing here.\pWould you like to plant a berry?
    #org @planted
    = You planted a [buffer0].
    #org @noplant
    = The trees cried because you\ndidn't plant anything. :'(


    Final Notes (and things to consider)
    So, this is an interesting hack, but what if we could use it with the normal bag, and have a way to manually give items to someone, ie a junk dealer, or a quest where you have to guess what the person likes? EDIT: Done! See section below!

    As a final note, if you find any bugs, report them, and suggestions are welcome. Also, be sure to give credits. It's a good morale booster for me.


    Using the Normal Bag for Item Selection

    So after completing my berry bag hack, I posted some final notes and things I thought about afterwards. Since both bags functioned relatively the same, I decided to port the same hack from the Berry Bag to the Main Bag.

    Since I'm lazy, I'm going to use quotes:
    Quote:
    Originally Posted by Shiny Quagsire View Post
    ... there are is actually only one ASM routine required for this. Basically, what it does is it forces the bag into thinking every item is the Exit item, which will exit the bag immediately as it's selected. Along the way to exiting the routine, it stores the berry ID to variable 0x800E, or 0x0 if the user didn't select anything or pressed B. Under normal circumstances, this is wiped upon exiting the bag, but because of the way we call the bag, it preserves this variable.
    hijacknormbag.asm
    Code:
    @Forces the bag to exit instead of showing the item menu.
    @Place the pointer to this routine at 0x081090D0, and place bx r1 (08 47) at 0x081090B6
    
    .thumb
    .thumb_func
    .global BagHack
    
    main:
    	ldr r1, var_8000
    	ldrh r1, [r1]
    	cmp r1, #0x7F
    	beq skip
    	ldr r1, var_800E
    	strh r0, [r1]
    	ldr r1, return
    	bx r1
    skip:
    	ldr r1, var_800E
    	strh r0, [r1]
    	ldr r1, skipaddr
    	bx r1
    	
    var_8000:	.word 0x020370B8
    var_800E:	.word 0x0203AD30
    skipaddr:	.word 0x08109065
    return:	.word 0x081090B9
    To insert this, place the pointer to the compiled routine (+ 1) at 0x1090D0, and place 08 47 at 0x1090B6.

    Now, one thing to notice if you can read this is that there is one major difference from the berry bag hack, and that's in this section of code:
    Code:
    cmp r1, #0x7F
    Instead of using 0x7E like the berry bag, I wanted to distinguish this hack from the other one to avoid confusion while scripting. so I made it check variable 0x8000 for 0x7F instead.

    Now, since this is almost exactly like the berry bag hack, the script calling is pretty much the same. I'll comment out any major differences.
    Code:
    fadescreen 1
    setvar 0x8000 0x7F    'Set 0x8000 to 0x7F instead of 0x7E
    setvar 0x800E 0x0
    callasm 0x10a67d       'This calls the bag. If you ever want to use this without the hack, it works.
    waitmsg
    setvar 0x8000 0x0
    Final Notes (and things to consider)
    As for applications for this, pretty much anything you want. Truthfully, I just reused my berry script for testing, because I was too lazy to do anything special or cool with it as seen by this pic:


    However, some ideas for this are:
    • A Junk Dealer who buys random items
    • An event where you have to give a certain item
    • An event where you trade items
    • A script where you have to guess an item that someone wants
    • Fossil scripts
    • Etc.

    As usual, report any bugs associated with the routine and suggestions are welcome. Also, be sure to give credits. It's a good morale booster for me.
    __________________



    Reply With Quote

    Relevant Advertising!

      #2    
    Old January 27th, 2013 (3:57 PM).
    FBI's Avatar
    FBI FBI is offline
    Free supporter
    • Silver Tier
     
    Join Date: Jan 2013
    Location: Unknown Island
    Gender: Male
    Posts: 1,770
    Real nice work there, I'm sure hackers using or looking to use a berry system will find this very useful. I read through the whole thing and I'm glad you've explained how things work rather than just posting the code and instructing us how to insert things.

    What really caught my eye is this little part here:
    Quote:
    Along the way to exiting the routine, it stores the berry ID to variable 0x800E, or 0x0 if the user didn't select anything or pressed B.
    I assume this process can be duplicated for other things as well? Would be interesting and sounds like the key to using custom items outside of battle (maybe there's an easy way that I don't know of ).

    Anyways, nice work my dear Quagsire.
    __________________
    ...
    Reply With Quote
      #3    
    Old January 27th, 2013 (10:43 PM).
    Shiny Quagsire's Avatar
    Shiny Quagsire Shiny Quagsire is offline
    I'm Still Alive, Elsewhere
       
      Join Date: May 2009
      Location: Hoenn Safari Zone
      Age: 19
      Gender: Male
      Nature: Jolly
      Posts: 700
      Updated! Now has tutorial for using the main bag for item selection. Luckily for me, the routines were pretty much identical.

      When I get the chance I'll upload a video of the routine in action.
      __________________



      Reply With Quote
        #4    
      Old January 29th, 2013 (1:42 AM).
      tajaros's Avatar
      tajaros tajaros is offline
      Hi I'm dawg
         
        Join Date: Apr 2012
        Location: Philippines
        Age: 18
        Gender: Male
        Nature: Timid
        Posts: 857
        Cool thing here Shiny Quagsire! Just in time cause I was thinking to add the berry system a week ago.

        I'll try this out this weekend since I'll have free to do this at that time.
        __________________
        Reply With Quote
          #5    
        Old March 7th, 2013 (10:07 PM).
        dreamengine's Avatar
        dreamengine dreamengine is offline
           
          Join Date: Aug 2012
          Gender: Male
          Posts: 68
          Uh, not to sound noobish, but what exactly does this do? lol sorry, but from what I can tell it adds another Bag page especially for berries rather than using the berry pouch. Am I correct?
          __________________
          I support...
          Reply With Quote
            #6    
          Old August 6th, 2014 (9:12 AM).
          pokemontutorialTV's Avatar
          pokemontutorialTV pokemontutorialTV is offline
             
            Join Date: Feb 2014
            Location: Germany, Kaiserslautern
            Gender: Male
            Nature: Calm
            Posts: 75
            Sorry for recieving this thread, but i have to warn you if you follow the "Normal bag for selection". Under normal situation it worked, but if you use the PC in Pokémoncenter you can't use no more Items till you dont change the var in 0x8000. The reason for that is, that the PC-ASM writes 0x7F to 0x8000 - same value like in the tutorial.
            I would recommend using annother value, for example 0x7A.
            Also you have to watch out, because you also can select Basic-Items and if you remove 0x800E from your bag, it may remove a bicicle or sth. like that.
            You should avoid it with following solution:
            checkitemtype 0x800E
            compare 0x800D 0x[itemtype_to_avoid]
            if 0x1 goto @cancel

            Hop this helps.
            __________________
            Making Youtube Videos about Pokémon.
            _______________________________________________
            Pokémon Zoisit:

            _______________________________________________
            My Youtube Channel with over 1000 videos to Pokémon: http://www.youtube.com/user/pokemontutorialTV
            Reply With Quote
              #7    
            Old May 3rd, 2015 (3:18 PM).
            Lance32497's Avatar
            Lance32497 Lance32497 is offline
            LanceKoijer of Pokemon_Addicts
               
              Join Date: Aug 2014
              Location: Criscanto town-Ginoa Region xD
              Gender: Male
              Nature: Adamant
              Posts: 793
              is callasm 0x10a67d a fixed pointer to asm, or I replace it with the offset where I placed the routine
              __________________
              This signature has been disabled.
              Scrollbar appears
              Please review and fix the issues by reading the signature rules.

              You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.

              Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
              Reply With Quote
                #8    
              Old May 3rd, 2015 (11:07 PM).
              Ephraim225's Avatar
              Ephraim225 Ephraim225 is offline
              Freaky Frillish Guy
                 
                Join Date: Jul 2013
                Location: In America
                Gender: Male
                Nature: Modest
                Posts: 156
                It's a fixed pointer, yes
                __________________
                Reply With Quote
                Reply

                Quick Reply

                Join the conversation!

                Create an account to post a reply in this thread, participate in other discussions, and more!

                Create a PokéCommunity Account

                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 9:06 PM.