Age 28
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
8.4 Years

Dynamic Overworld Palettes




Anyone who has ever inserted new overworld sprites has probably realized that the existing palette system is pretty inflexible and inextensible regarding new, custom palettes. In fact, the game simply loads a predefined list of palettes which all the NPCs share. Only palette slots 0 and 0xA are loaded dynamically when a respective NPC enters the screen. However, the palette in slot 0 is already taken by a few sprites, such as the warp arrow or the emotion bubbles, so it's not recommendable to edit it. It's quite apparent that dealing with overworld palettes is a pain under these circumstances, so I decided to write a new, dynamic palette system.

How it works


With this patch applied, the four bits in the NPC structure which usually determine what palette slot to use are ignored. Instead, the game uses a reference counting system that keeps track of what palettes are loaded and how many OBJs access them. When a sprite shows up on the screen, its palette is automatically loaded into a free palette slot if it hasn't been already. When all sprites using a certain palette have been deleted, the palette slot is available again for other palettes.

It's also worth mentioning that this doesn't only affect NPCs, I've basically tried to include any sprite that ever appears in the overworld. OBJs that show up in menus or the like will not be affected. While I've done much testing and I'm pretty sure that I've incorporated all overworld sprites there are, I can't rule out the possibility that I overlooked one. So if you find a sprite with a wrong palette, I'd greatly appreciate a short feedback so I can fix it.

Additional fixes


Aside from significantly easier palette handling, the patch also fixes some minor bugs of the vanilla game. These are:
  • When changing the weather from sandstorm or cloud reflections to another type, the game doesn't load the new palette, so rain and other weather styles end up looking really weird.
  • Some sprites are not grayscale during the flashback, such as sandstorm, cloud reflections or block animaitons during fog weather.
  • Speaking of fog, only weather type 'Steady mist' makes block animations brighter so they fit the brightness of the fog, the other fog types don't.
As a further bonus, I've made reflection palettes fully dynamic too, which means the game automatically creates them based on the NPC palette.

The patch


You can download the patch here. I've put the source code on Github.

The data will be written to 0xF00000, in order to make it compatible with as many ROMs as possible. Should your ROM already have other data at that offset, you can download the source, specify another offset in the linker script and then insert it using the Python script. For further info, see the ReadMe file.

This patch only works with FireRed 1.0!

Special thanks to knizz for his FireRed IDB and Touched for publishing his Mega Evolution source, which I could learn a few things from.

MrDollSteak

Formerly known as 11bayerf1

Age 28
Male
Hong Kong
Seen March 16th, 2023
Posted September 26th, 2022
859 posts
14.5 Years
This is a fantastic hack! Kudos to you!

Overworlds were honestly one of the things I hated most about making my hack. JPAN's hack although helpful didn't really take into account the palette slots leading to custom palettes having distorted colours, which I'm sure you realised too.
Age 28
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
8.4 Years
This is a fantastic hack! Kudos to you!

Overworlds were honestly one of the things I hated most about making my hack. JPAN's hack although helpful didn't really take into account the palette slots leading to custom palettes having distorted colours, which I'm sure you realised too.
Thanks!

You're right, JPAN's patch doesn't really help with palette slots, the only thing it does in terms of overworld palettes is it repoints the table so you can add more of them. You'd still be forced to put your custom palettes into slot 0 or A, or to load them separately in a level script or so. This should no longer be a problem!

This is amazing!

I've submitted a small bug I noticed to the Issue Tracker on github, hope it helps!
Thanks!

Strangely enough, I just tried to reproduce this issue on a clean ROM, but it stayed dark there. It may be something specific to Gaia, a particular hook or something. I'll try to find out what's causing it, thanks for reporting!
Age 28
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
8.4 Years
My suspicion turned out to be true. The hack was actually colliding with daniilS' snowflakes routine that keeps the screen from darkening. I've updated the file Insert.py accordingly, it should work now!

To stop the snowflakes weather from darkening the screen when returning to the map, just delete this line.

esperance

Age 26
Male
OH
Seen 6 Hours Ago
Posted January 11th, 2022
3,830 posts
13.2 Years
This is really great! A wonderful hack.

It might be worth mentioning that while the Insert.py script will work with Python 2.7 it won't work with Python 3 (the way print works was changed in Python 3). Fortunately it's a simple modification to make.
What are you so afraid of?
Seen December 13th, 2016
Posted March 9th, 2016
17 posts
17.1 Years
I've wanted something like this for so long. Brilliant!

One issue I ran into was that thunderstorms were causing OW palettes to glitch out when wandering from map to map (Just for reference, I'm running a dynamic weather system using JPANs hacked fire red engine along with his walking script special) I don't know if this is a limitation of this hack? or a bug from the weather refreshing/changing from one to another or anything else? Just thought it would be worth mentioning.
Age 28
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
8.4 Years
This is really great! A wonderful hack.

It might be worth mentioning that while the Insert.py script will work with Python 2.7 it won't work with Python 3 (the way print works was changed in Python 3). Fortunately it's a simple modification to make.
Ohhh, I wasn't aware of this. Thanks for telling, I'll change it. Luckily it's indeed an easy fix haha.

I've wanted something like this for so long. Brilliant!

One issue I ran into was that thunderstorms were causing OW palettes to glitch out when wandering from map to map (Just for reference, I'm running a dynamic weather system using JPANs hacked fire red engine along with his walking script special) I don't know if this is a limitation of this hack? or a bug from the weather refreshing/changing from one to another or anything else? Just thought it would be worth mentioning.
Hm... Thunderstroms should definitely work with this hack. I'll look into JPAN's walking scripts and see if they have anything to do with it. Thanks for your notice though!

Anyways, I'm glad to see that you guys enjoy this project!

Dr. Seuss

Navegando en mi automóvil, hablando con la nena por el móvil 😎...

Age 27
Male
Guatemala City
Seen 2 Days Ago
Posted 5 Days Ago
522 posts
9.3 Years
A-W-E-S-O-M-E!!!
But my question is, Can I put in the same map up to 16 overworlds with a different pallete?
Graphic design is my passion...

Click on the picture to see the best hack ever created (?
Seen December 13th, 2016
Posted March 9th, 2016
17 posts
17.1 Years
Ohhh, I wasn't aware of this. Thanks for telling, I'll change it. Luckily it's indeed an easy fix haha.


Hm... Thunderstroms should definitely work with this hack. I'll look into JPAN's walking scripts and see if they have anything to do with it. Thanks for your notice though!

Anyways, I'm glad to see that you guys enjoy this project!
Just a quick update on this. I was wrong. The thunderstorm isn't causing the issue, it seems to be a green script tile linked to a trainer battle. The aftermath of that event seems to be causing the issue for me. I'll have a good look at the script and mess around with a few things on a clean ROM to see if I can reproduce the issue in certain circumstances. Just don't start going on a wild goose chase with the thunderstorm and JPAN walking script specials. It's looking more and more likely to be human error on my part. :P
Age 28
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
8.4 Years
A-W-E-S-O-M-E!!!
But my question is, Can I put in the same map up to 16 overworlds with a different pallete?
Yes, you can! Technically you can have even more than 16 overworlds with different palettes in one map, as long as you don't have more than 16 visible on the screen. But bear in mind that this also includes all other palettes, like tall grass, sandy footprints, reflections, the weather, and so on.

Uhm... I have a question about this. Since the palettes are now dynamic, can I put more palettes for the overworlds (I think the current has 15 or so)? If so, how? Do I manually put the offset for a specific sprite's palette?

P.S. This is a great discovery! Thank you for this! ^U^
You can repoint the NPC palette table at 0x3A5158 (or 0x1A2400 if you're using JPAN's patch) and add as many palettes as you wish. Each entry in that table consists of 8 bytes: 4 bytes for the pointer to the palette, 2 bytes for the palette number and 2 filler bytes. The palette number can be any value from 0 to 0xFFFF except 0x11FF, because this would indicate the end of the table. This palette number is the one that you'll need to specify in the data structure of your NPC.

Just a quick update on this. I was wrong. The thunderstorm isn't causing the issue, it seems to be a green script tile linked to a trainer battle. The aftermath of that event seems to be causing the issue for me. I'll have a good look at the script and mess around with a few things on a clean ROM to see if I can reproduce the issue in certain circumstances. Just don't start going on a wild goose chase with the thunderstorm and JPAN walking script specials. It's looking more and more likely to be human error on my part. :P
Okay, good to know. :) Just let me know if you find out that it's connected with this hack in any way.

Shiny Quagsire

I'm Still Alive, Elsewhere

Age 25
Male
Hoenn Safari Zone
Seen August 7th, 2020
Posted April 17th, 2017
697 posts
14 Years
Looks great, it always bothered me with how hacky the palette system was done, especially with respect to reflections and weather. Seems like this actually managed to improve on a lot of things without having to compromise either, which is great.

Joexv

ManMadeOfGouda
joexv.github.io

Age 25
Male
Oregon
Seen 1 Day Ago
Posted April 8th, 2022
1,035 posts
10.6 Years
This is going to sound incredibly nooby but how would i use this patch to add pallettes?
This patch isnt used to add palettes you would either need to expand your palette table or use jpans engine to add more.

This patch just makes using those added palettes much easier
New living flesh vessel who dis?

PokéMew

Pokémon Fuchsia

Male
Refresh
Seen October 5th, 2022
Posted April 8th, 2017
484 posts
9.7 Years
This is going to sound incredibly nooby but how would i use this patch to add pallettes?
Adding to what Joexv said, in vanilla you could have at most 2 custom palettes on screen at once. This hack allows you to have custom palettes from each of the 16 slots at once. Again like Joexv said, you can simply expand the palette table to add more palettes.
Non-binary
Seen 6 Days Ago
Posted January 23rd, 2023
21 posts
7.3 Years
all my pokemon have the wrong palette at the move deleter and possibly other places too, these are standard gen 3 pokemon that haven't been altered on a fairly clean firered 1.0 rom

other than that good job, but can we get an update to fix this one
Edit: I just removed the dynamic palettes and its fixed so this was definitely the problem

MrDollSteak

Formerly known as 11bayerf1

Age 28
Male
Hong Kong
Seen March 16th, 2023
Posted September 26th, 2022
859 posts
14.5 Years
Would this work for the PC boxes too?
'Cause you know, we can't use generation VI icons because of their palettes, which have to come out of 3 fixed palettes.
Will we be able to use the original generation VI style icons with this hack?
Sadly no, because the boxes and cursors as well as the existing 3 palettes take up all of the palettes afaik.
Age 28
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
8.4 Years
Edit: I just removed the dynamic palettes and its fixed so this was definitely the problem
Oh ****, good catch!
I'm definitely going to have a look at that and fix it as soon as I can. I was planning to clean up the code a bit anyway, so I'll probably do both things at once. Anyhow, thanks for reporting!

Would this work for the PC boxes too?
'Cause you know, we can't use generation VI icons because of their palettes, which have to come out of 3 fixed palettes.
Will we be able to use the original generation VI style icons with this hack?
Like MrDollSteak said, that won't work unfortunately. I do actually think that some palette slots are unused in the Pokémon menu and the PC boxes, however they would only suffice for the 6 Pokémon in your party at best. Considering a box on the PC can hold up to 30 Pokémon, there's just no way to give each icon its own palette.