PDA

View Full Version : Using Berry Bag as Berry Selection Screen


Shiny Quagsire
January 26th, 2013, 09:59 PM
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 (http://www.pokecommunity.com/showthread.php?t=208424) 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:

@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:

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:

#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

@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:

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.

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:
http://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

FBI agent
January 27th, 2013, 03:57 PM
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:
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 :P).

Anyways, nice work my dear Quagsire.

Shiny Quagsire
January 27th, 2013, 10:43 PM
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. ;)

tajaros
January 29th, 2013, 01:42 AM
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.

dreamengine
March 7th, 2013, 10:07 PM
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?

pokemontutorialTV
August 6th, 2014, 09:12 AM
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.

Lance32497
May 3rd, 2015, 03:18 PM
is callasm 0x10a67d a fixed pointer to asm, or I replace it with the offset where I placed the routine

Ephraim225
May 3rd, 2015, 11:07 PM
It's a fixed pointer, yes