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.