jiangzhengwenjzw

now working on pokefirered

Male
Seen 3 Hours Ago
Posted December 19th, 2019
177 posts
7.7 Years
All the codes are now on github and the auto-insertion is completed via armips.
https://github.com/jiangzhengwenjz/Double_wild_battle

Old post:
Spoiler:
I'm here again and here's some information about double wild battle in BPRE. The system is not yet perfect, but I don't have time to improve it so I decided to release the code. Please credit Jambo51 because some of the codes are ripped from his FR649. However, iirr, Karatekid552 has released the ASM codes in FR649 on github, so I think it's not inappropriate to post them here. These routines will make it possible to have "double wild battle" in "grass battles".
Bugs fixed:
1. Loading only 1 pokemon
2. Capture animation
3. Audio error
4. Captured pokemon data
5. pokedex things
6. can't flee
7. nickname issues

Wild Double Battle in BPRE


Now the main bugs are all fixed and here's a picture of what we can do now. (I don't use an English ROM, sorry.)

The byte changes are in the comments of the routines, so please read carefully.
Spoiler:
.thumb
/*0x82a26 -  04 49 08 47
0x82a38 - XX+1 XX XX 08
0x7F760 - 00 00*/

str r0, [sp]
ldr r0, .opponent_slot
add r1, r4, #0
add r2, r6, #0
mov r3, #0x20
ldr r4, .pokemon_make_3
bl linker_4
mov r1, #0
mov r2, #0

loop_1:
mov r4, #0x64
ldr r0, .party_slot
add r0, #0x56
mul r4, r1
add r0, r0, r4
ldrh r0, [r0]
cmp r0, #0
bne add_1

increment:
add r1, #1
cmp r1, #6
bne loop_1
cmp r2, #2
blt back_1
ldr r1, .offset
ldr r2, .save_block_1
ldr r2, [r2]
ldrb r3, [r2, #4] @bank
lsl r3, r3, #2
add r1, r1, r3
ldr r1, [r1]
ldrb r3, [r2, #5] @map
lsl r3, r3, #2
add r1, r1, r3
ldr r1, [r1]
ldr r1, [r1]
ldr r3, [r1, #0x10]
ldr r2, .tileset_table
cmp r3, r2
bne back_1
bl get_block_id
mov r2, #0

loop_2:
mov r1, pc
add r1, #0x92
lsl r3, r2, #2
add r1, r1, r3
ldrh r3, [r1]
cmp r0, r3
beq calculation
ldr r1, .end
cmp r1, r3
beq back_1
add r2, #1
b loop_2

add_1:
add r2, #1
b increment

back_1:
mov r0, #0
ldr r1, .battle_flag
str r0, [r1]

back_2:
add sp, sp, #0x10
pop {r4-r6, pc}

get_block_id:
push {lr}
ldr r0, .npc_state
ldrh r1, [r0, #0x12] @Y
ldrh r0, [r0, #0x10] @X
ldr r4, .getter
bl linker_4
pop {pc}

calculation:
ldrb r4, [r1, #2]
cmp r4, #0x63
bhi doubletwo
bl random
mov r1, #0x64
bl mod_func

doublethree:
add r1, r4, #0
cmp r0, r1
bge back_1

double: 
mov r0, #1
ldr r1, .battle_flag
str r0, [r1]
ldr r4, .rand_grass
bl linker_4
ldr r1, [r7, #4]
lsl r0, r0, #2
add r0, r0, r1
ldrh r4, [r0, #2]
ldr r1, .generate
bl linker_1
add r6, r0, #0
bl random
mov r1, #0x19
bl mod_func
str r0, [sp]
ldr r0, .opponent_slot
add r0, #0x64
add r1, r4, #0
add r2, r6, #0
mov r3, #0x20
ldr r4, .pokemon_make_3
bl linker_4
b back_2

doubletwo:
mov r0, #0
b doublethree

mod_func:
ldr r3, .mod_addr
bx r3

random:
ldr r2, .rand
bx r2

linker_1:
bx r1

linker_4:
bx r4

.word 0x0005000A
.word 0x0005000B
.word 0x0005000C
.word 0x0005000D
.hword 0xFEFE

.align 2
.opponent_slot: .word 0x0202402C
.pokemon_make_3: .word 0x0803DD99
.party_slot: .word 0x02024284
.battle_flag: .word 0x02022B4C
.offset: .word 0x083526A8
.save_block_1: .word 0x03005008
.tileset_table: .word 0x082D4A94
.npc_state: .word 0x02036E38
.getter: .word 0x08058E49
.end: .word 0x0000FEFE
.mod_addr: .word 0x081E4685
.rand: .word 0x08044EC9
.rand_grass: .word 0x0808274D
.generate: .word 0x080828F9
.thumb
.align 2
/*0x16824 - 00 48 00 47 JJ+1 JJ JJ 08*/
cmp r3, #5
beq .L_1
mov r0, #1
and r3, r0
cmp r3, #0
bne .L_0

.L_1:
ldr r0, =0x801682D
bx r0

.L_0:
ldr r0, =0x801682D
add r0, #0x42
bx r0
.thumb
/*Change all 1D 1E 0A 08 to the pointer (+1) to this routine, and please do the change before inserting the routine!!!!!!!!!!!!!!!!!!*/
ldr r1, .battle_flag
ldr r1, [r1]
cmp r1, #5
bne normal
ldr r1, .struct
mov r2, #0x58
lsl r2, r2, #1
add r2, r1, r2
ldrh r1, [r1, #0x28]
ldrh r2, [r2, #0x28]
mul r1, r2
cmp r1, #0
bne two_mon
normal:
ldr r1, .pokeball
bx r1
two_mon:
push {r4, lr}
mov r0, #0
mov r1, #2
ldr r2, .string_shown
ldr r3, .bag_print
ldr r4, .texter
bl jump
pop {r4, pc}
jump:
bx r4

.align 2
.battle_flag: .word 0x2022B4C
.pokeball:  .word 0x80A1E1D
.struct: .word 0x2023C3C
.bag_print: .word 0x810a1f9
.texter: .word 0x08108E71
.string_shown: .word 0x08[text offset]
Please change [text offset] to a piece of text data. The text should be like "There're 2 pokemon on the opponent side and i can't lock on the target".
.thumb
.align 2
/*21d46 - 00 47
21d94 - ZZ+1 ZZ ZZ 08*/
ldr r0, =0x2022b4c
ldr r0, [r0]
cmp r0, #5
beq double

audio:
ldr r0, =0x137
ldr r1, =0x80722A1
bl jump
ldr r1, =0x8021D4B

jump:
bx r1

double:
ldr r0, =0x2023C3C
mov r1, #0x58
lsl r1, r1, #1
add r1, r0, r1
ldrh r0, [r0, #0x28]
ldrh r1, [r1, #0x28]
add r0, r0, r1
cmp r0, #0
beq audio
ldr r1, =0x8021D4B
add r1, #8
bx r1
.thumb
.align 2
/*0x2D44C - 30 47
0x2D480 - MM+1 MM MM 08
0x2D812 - 00 00
0x2D858 - 00 00
0x2D8A6 - 00 00
0x2D8F4 - 01 1C
0x2DF36 - 08 1C
0x2DE58 - 00 00
0x2DE84 - 00 00
0x2DEA4 - 00 00
0x2DEC2 - 04 1C
0x2D874 - 6C 3D 02 02
0x2D94C - 6C 3D 02 02
0x2DF64 - 6C 3D 02 02
0x2DF04 - 6C 3D 02 02*/
ldr r6, =0x2022b4c
ldr r6, [r6]
cmp r6, #5
bne normal
ldr r6, =0x2023C3C
ldrh r6, [r6, #0x28]
cmp r6, #0
bne case_1

case_2:
mov r0, #3
b back

case_1:
mov r0, #1
b back

normal:
mov r1, #1
eor r0, r1

back:
ldr r6, =0x2023D6C
ldr r1, =0x802d451
bx r1
.thumb
.align 2
/*0x2d95c - 00 48 00 47 NN+1 NN NN 08*/
push {r4, r5, lr}
ldr r4, =0x0202402C
ldr r0, =0x02023D6C
ldrb r0, [r0]
lsr r0, r0, #1
mov r1, #0x64
mul r0, r1
add r0, r0, r4
add r4, r0, #0
mov r1, #0xb
ldr r2, =0x0802D965
bx r2
.thumb
.align 2
/*0x2d9de - 00 47
0x2da00 - UU+1 UU UU 08*/
ldr r0, =0x0202402C
ldr r1, =0x02023D6C
ldrb r1, [r1]
lsr r1, r1, #1
mov r2, #0x64
mul r1, r2
add r0, r1, r0
mov r1, #0xb
ldr r2, =0x0802D9E1
bx r2
.thumb
.align 2
/*0xEF5F8 - 10 47
0xEF680 - QQ+1 QQ QQ 08*/
ldr r2, =0x02037F1B
ldr r0, =0x02022B4C
ldr r0, [r0]
cmp r0, #5
bne normal
ldr r0, =0x02023C3C
mov r1, #0x58
lsl r1, r1, #1
add r1, r0, r1
ldrh r1, [r1, #0x28]
cmp r1, #0
beq normal
mov r1, #3
strb r1, [r2]

normal:
mov r8, r2
ldr r0, =0x080EF5FB
bx r0


After inserting the first routine, there will be a table in this format: 0A 00 05 00 0B 00 05 00 0C 00 05 00...... (The table is in the first routine and you can search for it)
The "05" is the rate of double battle in grass battles, which means 5% and you can change that on your own.
A, B, C, D are the ID of the 4 grass tile blocks and it's compatible with the clean BPRE 1.0 ROM.

As for now, there should still be some bugs like the fact that the name of captured pokemon is not shown right, but I won't do it now because I'm busy with my univ life. :)