• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Development: Using Berry Bag as Berry Selection Screen

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
[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:
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:


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

Blah

Free supporter
1,924
Posts
11
Years
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

I'm Still Alive, Elsewhere
697
Posts
14
Years
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

Hi I'm dawg
855
Posts
11
Years
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.
 
69
Posts
11
Years
  • Seen Jul 22, 2019
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?
 
Back
Top