Ok, I have FINALLY fixed the dex position glitch! My fix however, rather than finding the mistake, I just branch to a custom routine that undoes the mistake. To fix it, do these byte changes:
BBD94: 0E 4A
BBDD0: 9C 0F 00 02
Next, insert this routine into free space:
Code:
.text
.align 2
.thumb
.thumb_func
.global positionfix
main:
push {r0-r3}
ldr r0, .FirstCheck
ldrb r0, [r0]
mov r1, #0xFF
cmp r0, r1 /*compares .FirstCheck value to FF. If not, you're outside*/
bne Outside
b Inside
Inside:
ldr r0, .Counter1Inside
ldrb r0, [r0]
ldr r1, .Counter2Inside
ldrb r1, [r1]
cmp r0, r1
bne next1
b End
next1:
mov r2, #0x0
ldr r3, .FinalPosInside
strh r2, [r3]
b End
Outside:
ldr r0, .Counter1Outside
ldrb r0, [r0]
ldr r1, .Counter2Outside
ldrb r1, [r1]
cmp r0, r1
bne next2
b End
next2:
mov r2, #0x0
ldr r3, .FinalPosOutside
strh r2, [r3]
b End
End:
pop {r0-r3}
ldr r0, .NextRoutine
str r0, [r6]
pop {r4-r7}
pop {r0}
bx r0
.align
.FirstCheck: .word 0x02000D1C
.Counter1Inside: .word 0x02000F9E
.Counter2Inside: .word 0x02000FA0
.FinalPosInside: .word 0x02000F9A
.Counter1Outside: .word 0x02000D22
.Counter2Outside: .word 0x02000D24
.FinalPosOutside: .word 0x02000D1E
.NextRoutine: .word 0x080C1D39
And then make these byte changes:
C1808: 12 01
C1814: 00 48 00 47
C1818: XX XX XX 08 (offset of the routine +1)
This makes sure that the position is remembered if you're
NOT switching dex modes. If you
ARE switching dex modes (like from National to Hoenn, or vice-versa), then it will reset to Bulbasaur/Treecko (slot 0), which is intended as vanilla RSE behaves like this too.
(for those of you that didn't know, the problem I was having was that it was always resetting to Bulbasaur/Treecko even if I wasn't switching dex modes. But that has now been fixed)
I would like to say that we now have a perfect Emerald Pokédex expansion, but first I'm going to try out expanding to 721 to address any potential bugs that don't happen with just 493.