Advertiser Content

Development Dynamic Overworld Palettes

Started by Navenatox December 11th, 2015 2:45 PM
  • 23718 views
  • 78 replies

Navenatox

Age 24
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
4.5 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 24
Male
Hong Kong
Seen 5 Days Ago
Posted May 15th, 2019
846 posts
10.6 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.

Navenatox

Age 24
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
4.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.
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!

Navenatox

Age 24
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
4.5 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 22
Male
Ohio
Seen 1 Week Ago
Posted 3 Weeks Ago
3,827 posts
9.3 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
13.2 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.

Navenatox

Age 24
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
4.5 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!
Seen December 13th, 2016
Posted March 9th, 2016
17 posts
13.2 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

Navenatox

Age 24
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
4.5 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 21
Male
Hoenn Safari Zone
Seen March 10th, 2018
Posted April 17th, 2017
700 posts
10.2 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

joexv.github.io

Age 21
Male
Oregon
Seen 6 Days Ago
Posted August 7th, 2018
1,031 posts
6.8 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
I died and am dead

PokéMew

Pokémon Fuchsia

Male
Refresh
Seen January 6th, 2019
Posted April 8th, 2017
490 posts
5.8 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 March 3rd, 2017
Posted March 9th, 2016
20 posts
3.5 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 24
Male
Hong Kong
Seen 5 Days Ago
Posted May 15th, 2019
846 posts
10.6 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.

Navenatox

Age 24
Male
Austria
Seen February 4th, 2019
Posted September 11th, 2017
76 posts
4.5 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.
Advertiser Content