• 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: Making Dive Work in FireRed

Giga Universe

Working on a tool.
121
Posts
16
Years
Dive doesn't work in FireRed, I'm not sure if the code is there for it to work, but I suppose we could just write some more, as we could then create things like the underground.
I'm not sure if it helps, but I wrote a routine that finds a connection and stores the map and bank of that connection in a variable. You have to tell it what kind of connection to search for though...
0x5 is a 'Dive' connection, and 0x6 is a 'Emerge' connection.

Code:
.text
.align 2
.thumb
.thumb_func

main:
	push {r0-r5,lr}
	ldr r0, mapheader
	ldr r0, [r0,#0xC]
	ldr r1, [r0]
	ldr r0, [r0,#0x4]
	ldr r4, variable
	ldrh r5, [r4]
	mov r2, #0x0
	b search

search:
	cmp r1, #0x0
	beq notfound
	ldrb r3, [r0,r2]
	cmp r3, r5
	beq found
	add r2,#0xC
	sub r1, #0x1
	b search
	
notfound:
	pop {r0-r5,pc}

found:
	add r2, #0x8
	ldrb r1, [r0,r2]
	add r2, #0x1
	ldrb r2, [r0,r2]
	lsl r3, r1, #0x8
	orr r3, r2
	strh r3, [r4]
	pop {r0-r5,pc}
	
.align 2

mapheader:
	.word 0x02036DFC
	
variable:
	.word 0x020370D0 @Last result

All we need from here is to make it warp, and then we can make a tile behavior for it or something. I have absolutely no idea how to make it warp, so if someone could help there, then I could make this thing work...
 

knizz

192
Posts
16
Years
  • Seen Oct 28, 2020
From Underwater: call script 081BE3D4
From Overworld: call script 081BE38B

To connect change the hometown-connection to a dive-connection set 08352754 to 05

To disable the check whether you actually have a dive pokemon with you set the 6 bytes 081BE394-081BE399 to 0. This function also decides which pokemon is shown in the black bar. So if you disable it and see a bad egg. That's because of this.

Disable the badge-check for HMs set 0812462E to 0.

There are two ways to warp. The special one is just used when the behaviour of the tile the player is standing on is 0x19 and when the light byte is set to 0x5. Through different ways the execution can reach 0806DFB0. To avoid that you can destroy the bne/beqs. Write 0000 to 0806DF82 and 0806DF9C. This is not a good solution though. I'm sure there is a reason why these if's are there.

I don't know if the warp destination is correct. But the bank and mapnumber are in the variables 7004 and 7005.
 
Last edited:

Teh Blazer

Divider of Zero
776
Posts
15
Years
I may not be the brightest Ampharos in the lighthouse, but how would I make sense of this? Do we have to write a script and put this in, and how do we give stuff tile behaviors?
 
Last edited:

Putin

Anspruchsvolle Narr
52
Posts
13
Years
Perhaps this is flawed somehow, but could this not effectively be done using signpost scripts? You'd have to use it sparingly unless you had the space to spare, but then, using too many dive points is kind of obnoxious anyway.
 

Lyzo

Back from vacation
261
Posts
17
Years
Perhaps this is flawed somehow, but could this not effectively be done using signpost scripts? You'd have to use it sparingly unless you had the space to spare, but then, using too many dive points is kind of obnoxious anyway.
You could do that, but if you wanted to make big dive areas like in Ruby and Saphire, this would make the game lag. So putting an ASM routine in the tile behaviour, either using JPAN's engine, or... something else :P Is much more efficient.

If you would like to make Dive work in only one part of your game, then your solution would work ;)
 

sonic1

ASM is my life now...
77
Posts
15
Years
Why don't you locate one of those useless tile behaviour scripts like the ones that are the TV's talking or something and make a 'goto' (like in asm bx r0 xD ) to the diving scripts?

This way it isn't needed JPAN's engine for it to work. And its more easier IMO.
 
182
Posts
13
Years
  • Seen May 16, 2014
Wow, I was just about to start a thread about this :3

When it comes to ASM hacking Pokemon games I know nothing, in fact, my ASM knowledge is limited at best, and only limited to the Sonic The Hedgehog titles for the Genesis, lol. If you can port various things from one Sonic title to another though, I'm sure someone could port Dive and it's functionality to Fire Red. Sooo, yeah, if anyone is working on this, keep at it!
 
275
Posts
13
Years
  • Seen Oct 9, 2019
Why don't you locate one of those useless tile behaviour scripts like the ones that are the TV's talking or something and make a 'goto' (like in asm bx r0 xD ) to the diving scripts?
Those are actually scripts, not ASM.

As for the DIVE functionality, I can tell you guys that the scripts (as in XSE) for it still exist in FireRed. They don't have any identifiable warp calls, so either the warping results from the field move animation commands, or ASM detects when the script ends and warps then.

If the former, then that would explain why the DIVE field move animation crashes when triggered from script: it needs to read values from some location to know where to warp to, and it's not getting valid ones. Figure out how the field move animation works, and it may then be possible to make DIVE fully-functional.
 
35
Posts
16
Years
  • Seen Jun 17, 2013
Wow, it´s realy working?
for dive you can insert a new tileset (underwater tileset maybe tiles from kyledove). Ok, I try to make it work on a german rom. I hope I´m succesful.
What do I need in the Script? Should I use any special commands?

//Edit1: Ok, it works on a german rom, too.

//Edit2: Ok, I have written a tutorial. I hope you can understand it. If not please tell me and I would explain it. http://www.pokecommunity.com/showthread.php?t=276031
 
Last edited:
2
Posts
11
Years
  • Seen May 13, 2012
Well, another trick is to have Dive at certain spots make you 'wash up' on some other location. Say, a beach that you warp to.
 

Lance32497

LanceKoijer of Pokemon_Addicts
792
Posts
9
Years
From Underwater: call script 081BE3D4
From Overworld: call script 081BE38B
Good Day knizz, about the quoted one, How to call that offsets? So do I need to call it as a script or something? What is the step by step procedure?

To connect change the hometown-connection to a dive-connection set 08352754 to 05
What is 08352754? Is that 0x352754 offset? And 08 refers to a POINTER? Am I right?



And.... Do I need to insert the ASM code given by giga universe?
 
Last edited:
160
Posts
8
Years
So how do you add the HM Dive in Pokemon Firered exactly. I have no idea how do do it. Can anybody help me, please?

I have no idea how to make this work properly:(

Okay, now it works :D :D :D
Yeah!
The only problem is the surfing sprite, that´s all.
 
Last edited by a moderator:
5,256
Posts
16
Years

FireRed Dive

Download and fully extract the .zip file attached to this post.
Load firered_dive.asm in your text editor of choice and follow its instructions.

The attached download simply contains the file firered_dive.asm (found in the spoiler below and at https://pastebin.com/raw/1yjWuuuz), Lunar IPS, and base.gba (simply a 0xFFFFFF-sized file of just 0xFF bytes -- the .gba extension is just for simplicity's sake as it will mean Lunar IPS lists it by default).


Spoiler: firered_dive.asm
Code:
[FONT="Source Code Pro"].thumb
.global firered_dive

@ FireRed v1.0 HM08 DIVE Port
@ Credits: Spherical Ice, Squeetz

@ CHANGE THESE:
.equ offset, 0x800000 @ ROM address of 0x400 bytes of free space
.equ OW_MALE_DIVE, 14 @ male player's diving overworld sprite number
.equ OW_FEMALE_DIVE, 15 @ female player's diving overworld sprite number
.equ FLAG_ALLOW_DIVE, 0x827 @ flag which allows the use of Dive
@ YOU MUST CHANGE THE ABOVE VALUES

@ INSTALL:
@ 1. Change the .equ values above, labelled CHANGE THESE
@ 2. If you wish to disable badge checking, follow the DISABLE BADGE CHECKING instructions below
@ 3. Save this file
@ 4. Assemble this file using the following command:
@ thumb firered_dive.s firered_dive.gba
@ 5. Create a .IPS patch using Lunar IPS:
@ Use the included base.gba file as the base ROM
@ Use the newly generated firered_dive.gba file as the modified ROM
@ 6. Patch your FireRed v1.0 ROM with the generated .IPS patch
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ DISABLE BADGE CHECKS:
@ Find and remove the appropriately labelled lines of code below
@ Ctrl + F: REMOVE THE FOLLOWING 5 LINES TO DISABLE BADGE CHECK
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ MAKE DIVE POSSIBLE IN MAPS:
@ Set the second behaviour byte of Dive-able tiles to the value of DIVE_TILE_BYTE below (0x23 by default)
@ Set their second behaviour byte of Emerge-able tiles to the value of EMERGE_TILE_BYTE below (0x24 by default)
@ Set underwater maps' light level (the Type: field in the Header view on AdvanceMap) to Underwater (0x5)
@ Create Emerge map connections to underwater maps leading to their surface maps
@ Create Dive map connections to surface maps leading to their underwater maps
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ Changing these is optional (they are the default FireRed currently)
.equ OW_MALE_WALK, 0 @ male player's normal, walking overworld sprite number
.equ OW_MALE_CYCLE, 1 @ male player's cycling overworld sprite number
.equ OW_MALE_SURF, 2 @ male player's surfing/"sat down" overworld sprite number
.equ OW_MALE_ITEM_0, 3 @ male player's first item usage overworld sprite number
.equ OW_MALE_FISH, 4 @ male player's fishing overworld sprite number
.equ OW_MALE_ITEM_1, 5 @ male player's second item usage overworld sprite number
.equ OW_FEMALE_WALK, 7 @ female player's normal, walking overworld sprite number
.equ OW_FEMALE_CYCLE, 8 @ female player's cycling overworld sprite number
.equ OW_FEMALE_SURF, 9 @ female player's surfing/"sat down" overworld sprite number
.equ OW_FEMALE_ITEM_0, 10 @ female player's first item usage overworld sprite number
.equ OW_FEMALE_FISH, 11 @ female player's fishing overworld sprite number
.equ OW_FEMALE_ITEM_1, 12 @ female player's second item usage overworld sprite number
.equ DIVE_TILE_BYTE, 0x23 @ second behaviour byte value for diving
.equ EMERGE_TILE_BYTE, 0x24 @ second behaviour byte value for emerging
.equ FLAG_ALLOW_RUN, 0x82F @ flag which allows the use of the Running Shoes
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@ DO NOT CHANGE THESE VALUES:
.equ rom, 0x08000000
@ DO NOT CHANGE THE ABOVE VALUES

@ Hooks and branches
.org 0x5BA30, 0xFF
    ldr r0, =(disable_running_underwater + rom + 1)
    bx r0
.pool

.org 0x5C7F4, 0xFF
    .word player_overworld_list + rom

.org 0x5C826, 0xFF
    ldr r1, =(get_gender_from_sprite + rom + 1)
    bx r1
.pool

.org 0x5C9B0, 0xFF
    .word walkrun_overworld_list + rom

.org 0x5C9BA, 0xFF
    cmp r2, #3

.org 0x5C9F4, 0xFF
    .word walkrun_overworld_list + rom

.org 0x6CB30, 0xFF
    ldr r0, =(check_for_events + rom + 1)
    bx r0
.pool
    
.org 0x6CCCC, 0xFF
    ldr r1, =(check_dive + rom + 1)
    bx r1
.pool

.org 0x6DF78, 0xFF
    b 0x6DF84

.org 0x35B854, 0xFF
    .word change_sprite_to_diving + rom + 1

.org 0x471EEC, 0xFF
    .word player_behaviour_dive + rom + 1

.org offset, 0xFF
@ New data
player_overworld_list:
    .byte OW_MALE_WALK, OW_FEMALE_WALK
    .byte OW_MALE_CYCLE, OW_FEMALE_CYCLE
    .byte OW_MALE_SURF, OW_FEMALE_SURF
    .byte OW_MALE_ITEM_0, OW_FEMALE_ITEM_0
    .byte OW_MALE_FISH, OW_FEMALE_FISH
    .byte OW_MALE_ITEM_1, OW_FEMALE_ITEM_1
    .byte OW_MALE_DIVE, OW_FEMALE_DIVE

walkrun_overworld_list:
    .byte OW_MALE_WALK, 0b00001
    .byte OW_MALE_CYCLE, 0b00010
    .byte OW_MALE_SURF, 0b01000
    .byte OW_MALE_DIVE, 0b10000
    .byte OW_FEMALE_WALK, 0b00001
    .byte OW_FEMALE_CYCLE, 0b00010
    .byte OW_FEMALE_SURF, 0b01000
    .byte OW_FEMALE_DIVE, 0b10000

@ New code
disable_running_underwater:
	ldr r6, =(0x02037078) @ walkrun_state
	ldrb r1, [r6, #0] @ walkrun->bitfield
	mov r0, #16
	and r0, r1
	cmp r0, #0
	bne i_forgot_what_this_label_is
	mov r0, #2
	and r5, r0
	cmp r5, #0
	beq cannot_run
	ldr r0, =(FLAG_ALLOW_RUN)
	ldr r3, =(0x0806E6D0+1) @ flag_check
	bl call_via_r3
	lsl r0, r0, #24
	lsr r0, r0, #24
	cmp r0, #0
	beq cannot_run
	ldr r2, =(0x02036E38) @ npc_states
	ldrb r1, [r6, #5]
	lsl r0, r1, #3
	add r0, r0, r1
	lsl r0, r0, #2
	add r0, r0, r2
	ldrb r0, [r0, #30]
	ldr r3, =(0x080BD488+1) @ is_tile_to_run_on
	bl call_via_r3
	cmp r0, #0
	bne cannot_run

can_run:
	ldr r0, =(0x0805BA5A+1)
	bx r0

i_forgot_what_this_label_is:
	ldr r0, =(0x0805BA9E+1)
	bx r0

cannot_run:
	ldr r0, =(0x0805BA8C+1)
	bx r0

.pool

get_gender_from_sprite:
    lsl r0, r0, #24
    lsr r0, r0, #24
    cmp r0, #OW_MALE_DIVE
    beq male
    cmp r0, #OW_FEMALE_DIVE
    beq female
    cmp r0, #OW_FEMALE_FISH
    bgt male
    cmp r0, #OW_FEMALE_WALK
    blt male

female:
    mov r0, #1
    b return_to_x5C838
    
male:
    mov r0, #0
    
return_to_x5C838:
    ldr r1, =(0x0805C838 + 1)
    bx r1
.pool

check_for_events:
    mov r0, #0x80
    and r0, r1
    cmp r0, #0
    beq check_aftermove
    bl consider_dive_emerging
    cmp r0, #1
    beq something_happened

check_aftermove:
    ldrb r1, [r5]
    mov r0, #0x40
    and r0, r1
    cmp r0, #0
    beq check_move
    ldr r0, =(0x0806CB38 + 1)
    bx r0
    
something_happened:
    ldr r0, =(0x0806CB6C + 1)
    bx r0
    
check_move:
    ldr r0, =(0x0806CB74 + 1)
    bx r0
.pool

consider_dive_emerging:
    push {lr}
@ REMOVE THE FOLLOWING 5 LINES TO DISABLE BADGE CHECK 
    ldr r0, =(FLAG_ALLOW_DIVE)
    ldr r1, =(0x0806E6D0 + 1) @ checkflag
    bl call_via_r1
    cmp r0, #0
    beq no_emerging
@ REMOVE THE ABOVE 5 LINES TO DISABLE BADGE CHECK
    ldr r0, =(0x02036DFC) @ map_header
    ldrb r0, [r0, #23] @ map_header->light_level
    cmp r0, #5
    bne no_emerging
    bl get_block_secondary_role
    cmp r0, #EMERGE_TILE_BYTE
    bne no_emerging
    ldr r0, =(0x081BE3D4) @ emerge_script
    ldr r1, =(0x08069AE4 + 1) @ script_start
    bl call_via_r1
    mov r0, #1
    b dive_return
    
no_emerging:
    mov r0, #0

dive_return:
    pop {r1}
    bx r1
.pool

check_dive:
    ldrb r1, [r5]
    mov r0, #1
    and r0, r1
    cmp r0, #0
    beq no_dive
    bl consider_diving
    cmp r0, #1
    beq something_happened

no_dive:
    ldrb r1, [r5]
    mov r0, #4
    and r0, r1
    cmp r0, #0
    beq something
    ldr r2, =(0x0806CCD6 + 1)
    bx r2
    
something:
    ldr r0, =(0x0806CCFC + 1)
    bx r0
.pool
    
consider_diving:
    push {lr}
@ REMOVE THE FOLLOWING 5 LINES TO DISABLE BADGE CHECK
    ldr r0, =(FLAG_ALLOW_DIVE)
    ldr r1, =(0x0806E6D0 + 1) @ checkflag
    bl call_via_r1
    cmp r0, #0
    beq cant_dive
@ REMOVE THE ABOVE 5 LINES TO DISABLE BADGE CHECK
    bl get_block_secondary_role
    cmp r0, #DIVE_TILE_BYTE
    bne cant_dive
    ldr r0, =(0x081BE38B) @ dive_script
    ldr r1, =(0x08069AE4 + 1) @ script_start
    bl call_via_r1
    mov r0, #1
    b dive_pop
    
cant_dive:
    mov r0, #0

dive_pop:
    pop {r1}
    bx r1
.pool

get_block_secondary_role:
    push {r4, lr}
    sub sp, sp, #4
    mov r4, sp
    add r4, #2
    mov r0, sp
    mov r1, r4    
    ldr r3, =(0x0805C538 + 1) @ player_get_pos_to
    bl call_via_r3
    mov r0, sp
    mov r1, #0
    ldsh r0, [r0, r1]
    mov r2, #0
    ldsh r1, [r4, r2]
    lsl r0, r0, #16
    asr r0, r0, #16
    lsl r1, r1, #16
    asr r1, r1, #16
    mov r2, #8
    ldr r3, =(0x08058F48 + 1) @ cur_mapdata_block_get_field_at
    bl call_via_r3
    lsl r0, r0, #16
    lsr r0, r0, #24
    add sp, sp, #4
    pop {r4}
    pop {r1}
    bx r1
.pool

player_behaviour_dive:
    push {r4, lr}
    ldr r0, =(0x02037078) @ walkrun_state
    ldrb r0, [r0, #5] @ walkrun_state->npcid
    lsl r4, r0, #3
    add r4, r4, r0
    lsl r4, r4, #2
    ldr r0, =(0x02036E38) @ npc_states
    add r4, r4, r0
    mov r0, #6
    ldr r3, =(0x0805C808 + 1) @ get_sprite_for_player
    bl call_via_r3
    add r1, r0, #0
    lsl r1, r1, #24
    lsr r1, r1, #24
    add r0, r4, #0
    ldr r3, =(0x081507BC + 1) @ npc_change_sprite_call
    bl call_via_r3
    ldrb r1, [r4, #24]
    lsr r1, r1, #4
    add r0, r4, #0
    ldr r3, =(0x0805F218 + 1) @ npc_turn
    bl call_via_r3
    mov r0, #16
    ldr r3, =(0x0805C970 + 1) @ change_sprite_bitfield
    bl call_via_r3
    ldrb r0, [r4, #4]
    ldr r3, =(0x080DC6B0 + 1) @ bobbing
    bl call_via_r3
    strb r0,[r4, #26]
    pop {r4}
    pop {r0}
    bx r0
.pool

change_sprite_to_diving:
    push {lr}
    mov r0, #4

set:
    ldr r1, =(0x08150498 + 1) @ set_player_behaviour
    bl call_via_r1
    pop {r1}

call_via_r1:
    bx r1

call_via_r3:
    bx r3
.pool

.org 0xFFFFFF, 0xFF
.byte 0xFF
[/FONT]
 

Attachments

  • firered_dive.zip
    76.1 KB · Views: 63
Last edited:
17
Posts
8
Years
it looks like the original, thanks spherical ice :)

EDIT: how to insert this at FR? it's complicated :3
 
Last edited by a moderator:
5,256
Posts
16
Years

FireRed Dive

Bumping again, I added a routine which force prevents running when underwater because it was still possible despite B being used for emerging if you started walking first. This is somewhat untested on a clean ROM so confirmation it works would be appreciated. I'm fairly certain it should work fine, though.
 
476
Posts
6
Years
  • Age 23
  • Seen Feb 26, 2020
Couldn't you just use AdvanceMap? There's an option to create Dive/Emerge connections...
 
Back
Top