I started by looking at existing Cheatcode.dat file to see if there were already encounter codes.
There were two for "no more encounter. Press specific buttons to battle!". It contained the address where the battle counter is stored.
In the debugger, I found an address near this one which increased after each steps, and when reaching 0x10 it incremented the battle counter by 0x70.
memory positions:
battle encounter : 0x020D9CE8 (4 bytes little endian)
step counter: 0x020D9D04
So the game has two counters for the battles : a Step counter and a random battle counter.
The step counter incrementing speed is affected by the character's speed: walk = +1, run = +2.
if you are in town, the step counter increases indefinitely without modifying the battle counter, when you go to the map it's reset to 0.
Code:
if(stepCounter > 0x0F)
{
stepcounter = 0;
Battle counter +=0x70;
}
Sometime it's +0x07, I don't know why. maybe it depends on the map/location/ailment on characters.
battle start randomly regardless of the counter value and long as it's above 0x1000. If below, battle never start.
So we have different possible values we can edit :
- the step counter, which depends on the walk speed : not good, when walking it's already set to minimum value (1). we can't set it less.
- the steps counter limit triggering an increment of the random Battle counter. <-- We can slow encounter rate by increasing the walk limit.
- the battle increment value. <-- We can slow encounter rate by decreasing the battle increment value.
I decided to go with the Battle counter increment value 0x70.
I added a breakpoint on the Battle encounter address, but couldn't trace where the 0x70 came from. It's stored in r0 but when adding the breakpoint r0=70 it often crash the debugger.
I then put a breakpoint on the step counter address, and finally could trace what happened when the counter reaches 0x10. That value is hard coded in the ASM.
I decided that I could edit the 0x10 to increment it. I looked at the memory where the ASM code was located and tried to make it 0xFFFF but it didn't work. (I don't know ASM commands to edit the data size), so I only changed it to 0xFF.
ASM address
020481CC : step counter increment function
020481FC : max value for steps before incrementing the battle counter (memory address 020481E0)
02048204 : battle counter increment function
To create the AR code, I used
this website to understand the codetype, and finally tested it in no$gba. hopefully it worked
AR Code:
220481EC 0000000F <--Current encounter rate
220481EC 000000FF <-- maximum slower encounter rate