• 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: Dynamic Overworld Palettes

76
Posts
9
Years

Dynamic Overworld Palettes

mVPzwio.png


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
858
Posts
15
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.
 
76
Posts
9
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!
 
3,830
Posts
14
Years
  • Age 26
  • OH
  • Seen Feb 26, 2024
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.
 
17
Posts
17
Years
  • Age 36
  • Seen Dec 13, 2016
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.
 
76
Posts
9
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

Will finish GS Chronicles, I swear!
522
Posts
10
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?
 
534
Posts
11
Years
  • Age 26
  • Seen Jul 24, 2023
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^
 
17
Posts
17
Years
  • Age 36
  • Seen Dec 13, 2016
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
 
76
Posts
9
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.
 

Joexv

ManMadeOfGouda joexv.github.io
1,037
Posts
11
Years
Just got a chance to use this and its freakin amazing! Thank you for helping my reflection ocd. Thank you.
 

Shiny Quagsire

I'm Still Alive, Elsewhere
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.
 

tayyab43

The Don
25
Posts
8
Years
  • Age 24
  • Seen Jan 30, 2021
This is going to sound incredibly nooby but how would i use this patch to add pallettes?
 

Joexv

ManMadeOfGouda joexv.github.io
1,037
Posts
11
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
 

PokéMew1

Pokémon Fuchsia
484
Posts
10
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.
 
Back
Top