Shiny Quagsire
I'm Still Alive, Elsewhere
- 697
- Posts
- 15
- Years
- Age 27
- Hoenn Safari Zone
- Seen Aug 8, 2020
[FR] Using (Berry) Bag for Item Selection
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:
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:
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:
#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. :P
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:
hijacknormbag.asm
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:
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.
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:
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. :P
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
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. :P
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:
... 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
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
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:
![[PokeCommunity.com] Using Berry Bag as Berry Selection Screen [PokeCommunity.com] Using Berry Bag as Berry Selection Screen](https://i569.photobucket.com/albums/ss135/mtinc2/temp-1_zpsbfc6c31d.png)
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. :P
Last edited: