• 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: Day/Night Switching of Wild Pokémon

Jambo51

Glory To Arstotzka
736
Posts
14
Years
  • Seen Jan 28, 2018
I would like to note that the general framework for these hacks were based on an idea that a Brazilian hacker had, his name escapes me right now, but some credit must be given to him/her!

These routines DO NOT support the new RTC and Day and Night Feature developed by Prime unless you use the same RAM offsets. Even if you do, I would ideally like to redevelop these routines to use the new system Prime has developed as it would be more efficient.

FireRed (Extensively Tested)

Spoiler:


Emerald (Basic Testing)

Spoiler:


Ruby (Not Started Yet)

Spoiler:
 
Last edited:

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
Nice job! I haven't read it through completely, but I will after I get some rest. :p

One thing you could do is explain what each original routine does, what arguments are loaded through the registers, and how the routine modifies this.
 
43
Posts
13
Years
:D I've been working on the tool so far got the GUI down got most of the code but running into a few bugs will post it here and the tool section when i've finished doing it ;) preview attatched as an attatchment
 

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
I could help with the tool. But some advice from me is:

1. Make the window smaller, or items bigger. There is too much empty space
2. More options, if possible and simpler user interface. Instead of making them insert hex, make the program convert it to hex.
3.Why make a program? If you do that, then D/N Pokemon will be less common.
 
3,830
Posts
14
Years
  • Age 26
  • OH
  • Seen Feb 26, 2024
3.Why make a program? If you do that, then D/N Pokemon will be less common.
I believe you mean more common, not less common.

Plus, this routine is very useful. I have been looking into information on this for quite some time now, to no avail. Thanks!
 

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
Yeah, I meant that. Anyways, I improved the code so that it is backward compatible with original game data. At the beginning, add this before pushing r0:
Code:
mov r1, r0
 ldrb r1, [r1, #0x3]
 cmp r1, #0x8
 bne normal

//Add the following lines after [B]back[/B]:
normal:
add r0, r4, r0
ldrh r0, [r0, #0x2]
ldr r3, Back
 bx r3

What this does is it checks for an 08 3 bytes after r0, which would be where your day pointer is. If not, it uses the pokemon table as normal data, like the game normally would. The byte that is actually checked is the flipped byte of the pokemon's species. Luckily, no pokemon goes over the number 2,048, so the check works. Another check you could add is to, instead of loading another pokemon data table, check the byte loaded into r0 after this instruction:
Code:
ldrh r0, [r0, #0x2]
This loads the pokemon's data, and once loaded, it can be checked. So let's say we wanted a pidgey to turn into a hoothoot. You could add this to next:
Code:
next: 
ldr r0, [r0, #0x0]
 add r0, r4, r0
 ldrh r0, [r0, #0x2]
ldr r3, hour
 ldrb r3, [r0, #0x0]
 cmp r3, #0x15          /*9PM - Change it if you want*/
 bge hoothoot
b back
hoothoot: cmp r0, #0x10 /*Is it pidgey?*/
bne back /*If not, return to normal*?
mov r0, #0xA3 /*Change pokemon to hoothoot*/
b back

Also, It's pretty tedious to hex edit pokemon, so I'm going to create a tool sometime. It's not too hard in fact, since it's such a simple format:
Code:
[MinLV][MaxLV][Species][Species]

edit: I've also added backward support for the levels. Simply add this before pushing r0 at the beginning:
Code:
 ldrb r2, [r2, #0x3]
 cmp r2, #0x8
 bne nextnormal

Add nextnormal to the second line in next:

Code:
next: ldr r0, [r0, #0x0]        /*Loads the word stored at the location pointed to in R0, the pointer to the wild data*/
 nextnormal:add r0, r4, r0                    /*Adds the number of bytes from the start of the table that the wild Pokémon slot the game has selected is*/
 add r4, r0, #0x0                /*Adds the contents of R0 into R4*/
 ldrb r0, [r4, #0x1]             /*Loads the upper level limit for the Pokémon if they're stored systematically*/

...
This essentially does the same thing as before. It checks if the pointer exists, and if not, it treats the table data as the normal pokemon data.
 
Last edited:

Jambo51

Glory To Arstotzka
736
Posts
14
Years
  • Seen Jan 28, 2018
Yeah, I meant that. Anyways, I improved the code so that it is backward compatible with original game data. At the beginning, add this before pushing r0:
Code:
mov r1, r0
 ldrb r1, [r1, #0x3]
 cmp r1, #0x8
 bne normal

//Add the following lines after [B]back[/B]:
normal:
add r0, r4, r0
ldrh r0, [r0, #0x2]
ldr r3, Back
 bx r3

What this does is it checks for an 08 3 bytes after r0, which would be where your day pointer is. If not, it uses the pokemon table as normal data, like the game normally would. The byte that is actually checked is the flipped byte of the pokemon's species. Luckily, no pokemon goes over the number 2,048, so the check works. Another check you could add is to, instead of loading another pokemon data table, check the byte loaded into r0 after this instruction:
Code:
ldrh r0, [r0, #0x2]
This loads the pokemon's data, and once loaded, it can be checked. So let's say we wanted a pidgey to turn into a hoothoot. You could add this to next:
Code:
next: 
ldr r0, [r0, #0x0]
 add r0, r4, r0
 ldrh r0, [r0, #0x2]
ldr r3, hour
 ldrb r3, [r0, #0x0]
 cmp r3, #0x15          /*9PM - Change it if you want*/
 bge hoothoot
b back
hoothoot: cmp r0, #0x10 /*Is it pidgey?*/
bne back /*If not, return to normal*?
mov r0, #0xA3 /*Change pokemon to hoothoot*/
b back

Also, It's pretty tedious to hex edit pokemon, so I'm going to create a tool sometime. It's not too hard in fact, since it's such a simple format:
Code:
[MinLV][MaxLV][Species][Species]

edit: I've also added backward support for the levels. Simply add this before pushing r0 at the beginning:
Code:
 ldrb r2, [r2, #0x3]
 cmp r2, #0x8
 bne nextnormal

Add nextnormal to the second line in next:

Code:
next: ldr r0, [r0, #0x0]        /*Loads the word stored at the location pointed to in R0, the pointer to the wild data*/
 nextnormal:add r0, r4, r0                    /*Adds the number of bytes from the start of the table that the wild Pokémon slot the game has selected is*/
 add r4, r0, #0x0                /*Adds the contents of R0 into R4*/
 ldrb r0, [r4, #0x1]             /*Loads the upper level limit for the Pokémon if they're stored systematically*/

...
This essentially does the same thing as before. It checks if the pointer exists, and if not, it treats the table data as the normal pokemon data.

Thanks man! I'll add these improvements in when I get home from work. I can't believe i didn't put these checks in myself XD. I don't pretend to br a great ASM hacker, i'm still learning most of it.
 

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
I would totally love this addition if it could support Emerald and have Morning added, too.
It would probably be simple to do, but I'm too lazy to do it myself ATM.

Since emerald is based off of fire red, it was actually only a search for a few bytes. The routine is at 080b4c76 for the level routine. However, it may be loaded differently, so I'll have to check if it's safe. ;)

edit: Actually, the code from all games is exactly the same, except for when the data is written. Here are the level offsets:

Code:
Emerald: 080b4c76
Ruby: 08084d32

Unfortunatly, the wild data loading is very different. I'll have to dive a bit deeper on that one.
 

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
Mind backing that up with some evidence?

Sure. I'm not a liar, and I always back up my evidence.

Level loading from Fire Red:
Code:
080828FA 00C                 MOVS    R4, R0
080828FC 00C                 LDRB    R0, [R4,#1]
080828FE 00C                 LDRB    R1, [R4]
08082900 00C                 CMP     R0, R1
08082902 00C                 BCC     loc_08082908

Level Loading From Emerald:

Code:
ROM:080B4C76                 MOVS    R4, R0
ROM:080B4C78                 LDRB    R0, [R4,#1]
ROM:080B4C7A                 LDRB    R1, [R4]
ROM:080B4C7C                 CMP     R0, R1
ROM:080B4C7E                 BCC     loc_80B4C86

And finally, Ruby:

Code:
ROM:08084D32                 MOVS    R4, R0
ROM:08084D34                 LDRB    R0, [R4,#1]
ROM:08084D36                 LDRB    R1, [R4]
ROM:08084D38                 CMP     R0, R1
ROM:08084D3A                 BCC     loc_8084D40

As you can see, it's essencially the same thing. If you were to look in IDA or VBA's decompiler, you'd see the same thing, but with a few different registers here and there.
 

Jambo51

Glory To Arstotzka
736
Posts
14
Years
  • Seen Jan 28, 2018
I would totally love this addition if it could support Emerald and have Morning added, too.
It would probably be simple to do, but I'm too lazy to do it myself ATM.

Adding morning would be very easy. In fact I originally developed it to support 4 times of day, morning, day, evening and night, but decided to cut it down for use as it takes a lot of work to manually hex edit the Pokémon in. As for Emerald support, I guess I could have a look and see if I can apply the principle, if not necessarily the exact same routine, to the rom. Although in order for me to do that, someone would need to supply me with the ram location of the RTC in an Emerald rom, as, unlike FR, it already has an RTC built in so I can't just look at the inserted routine of the D/N routine.
 
Last edited:

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
Adding morning would be very easy. In fact I originally developed it to support 4 times of day, morning, day, evening and night, but decided to cut it down for use as it takes a lot of work to manually hex edit the Pokémon in. As for Emerald support, I guess I could have a look and see if I can apply the principle, if not necessarily the exact same routine, to the rom. Although in order for me to do that, someone would need to supply me with the ram location of the RTC in an Emerald rom, as, unlike FR, it already has an RTC built in so I can't just look at the inserted routine of the D/N routine.

Yeah, I'll be doing morning, and I'm developing a wild pokemon data editor for this D/N System. I'll post some pics later. As for the RTC, I'm sure ColColStyles might know it, since he does a lot of emerald hacking. ;)
 

Jambo51

Glory To Arstotzka
736
Posts
14
Years
  • Seen Jan 28, 2018
I look forward to seeing this tool, for my own use as well as for other XD :D.

I, in the mean time, will endeavour to port the code over to as many versions of the roms as I can. I'll start by extending support to Ruby and Emerald's english versions, and then go from there. Hopefully, the routines will be in exactly the same place for other language roms, thus requiring no modification. The routines should, in theory, be identical, if not necessarily in exactly the same place.

And I asked colcolstyles for any info he may have on the RTC in Emerald, hopefully he'll be able to provide me with at least a starting point to go from :D
 

Shiny Quagsire

I'm Still Alive, Elsewhere
697
Posts
14
Years
I look forward to seeing this tool, for my own use as well as for other XD :D.

I, in the mean time, will endeavour to port the code over to as many versions of the roms as I can. I'll start by extending support to Ruby and Emerald's english versions, and then go from there. Hopefully, the routines will be in exactly the same place for other language roms, thus requiring no modification. The routines should, in theory, be identical, if not necessarily in exactly the same place.

And I asked colcolstyles for any info he may have on the RTC in Emerald, hopefully he'll be able to provide me with at least a starting point to go from :D

The code isn't in the exact same place.

Sure. I'm not a liar, and I always back up my evidence.

Level loading from Fire Red:
Code:
080828FA 00C                 MOVS    R4, R0
080828FC 00C                 LDRB    R0, [R4,#1]
080828FE 00C                 LDRB    R1, [R4]
08082900 00C                 CMP     R0, R1
08082902 00C                 BCC     loc_08082908

Level Loading From Emerald:

Code:
ROM:080B4C76                 MOVS    R4, R0
ROM:080B4C78                 LDRB    R0, [R4,#1]
ROM:080B4C7A                 LDRB    R1, [R4]
ROM:080B4C7C                 CMP     R0, R1
ROM:080B4C7E                 BCC     loc_80B4C86

And finally, Ruby:

Code:
ROM:08084D32                 MOVS    R4, R0
ROM:08084D34                 LDRB    R0, [R4,#1]
ROM:08084D36                 LDRB    R1, [R4]
ROM:08084D38                 CMP     R0, R1
ROM:08084D3A                 BCC     loc_8084D40

As you can see, it's essencially the same thing. If you were to look in IDA or VBA's decompiler, you'd see the same thing, but with a few different registers here and there.
 

Jambo51

Glory To Arstotzka
736
Posts
14
Years
  • Seen Jan 28, 2018
I know it's not in exactly the same place between Ruby, FireRed and Emerald, but it may be in exactly the same locations in an English Fire Red rom and a Spanish Fire Red rom. I'll need to have a look. I don't expect them to be, but they'll more than likely be very similarly placed, and the actual routine should (in theory) be identical. So no rewriting for a Spanish rom, simply insert at a different location. I will have to rewrite the routines to work with Emerald after having a quick look at the offsets posted by shiny quagsire, but only because it uses different registers. I couldn't get Ruby to open in VHA-SDL-H (probably a messed up rom) but I'll have a look shortly.
 
Back
Top