Practical Magic
Palette Hacking


Palette Hacking - Applications and Limitations

Actually editing the cars pixel by pixel is an enormously tedious and painstaking process, usually requiring many hours and thousands of mouse-clicks for something that, in the final analysis, someone else is going to want to smash the shit out of when playing GTA. However it also gives the greatest rewards, enabling exact replication of the author's ideas to be achieved in the final product, so long as s/he is willing to work within the restrictions necessary.

The Heart of the Matter - Practical Hacking

The best usage of the pixel-level techniques is where specific coloration is required to achieve the desired effects. In this demonstration I shall show you how I got the racenumbers on Henrik Larsson's Jaguar E-Type to change, showing why only certain numbers are used, how they were placed onto the car, and even showing how you can edit the files yourself to change the numbers on the cars.

I shall be using Paint Shop Pro to demonstrate how to do this hacking, although it can be done in the same manner through Photoshop, or indeed any graphics program that has the means to edit the 8 bit palette directly. However for this kind of editing I recommend PSP as it has many useful features designed for this kind of work, for example the Count Colors Used menu, the Color Replacer tool (illustrated above), and the keyboard shortcut Shift+P to open the Edit Palette dialog.

Please Note:- The changing of the numbers on Henrik's car will be possible by everyone, so don't release it, or post it as your own work! By all means make the cars you import into your game have the numbers you'd prefer to see, but don't distribute them or flood the scene with every version hacked to the same number(s)!


The Basic Deltasheet

On this car, the number takes up a small, central space well away from any damage deltas, so we can safely edit just the single sprite - I've cut it out of the deltas and enlarged it to the left here.

If we zoom in even closer on the number 8 itself, we get the image to the right - it is this tiny group of 28 pixels that we shall work on, although the principles and techniques involved are identical for any size of editing area.

First thing that must be done when editing palette entries directly is to create the 8bit palette, so make sure you have reduced the palette to 256 colors - if you haven't, do so now. Do not change color depth again! Any and all hacking will be lost if you now change up to 24 bit color then back down again.

In order to make sure we have a couple of spare palette entries available for the hacking, when the E-type was changed to 8 bit color Include Windows' colors was checked in the Decrease Color Depth dialog, as shown here. This adds the default 16 Windows colors to the palette in preference to using those entries in making the shading better - it's a trade-off, but one we need to take advantage of here. The resulting palette looks something like this:-


Unhacked Palette

So, we now have the car in an 8bit file, and we have spare colors that are not being used. We can now take a better look at the area we are wanting to edit - the number itself - so next we use the Display Grid option set to single pixel grids to see just which pixels are used for what. You could also copy out the image onto paper or into a seperate file, and then enlarge it to take any notes you may want to add.

If we use the dropper tool to look at the colors used in making this image look the way it does, we find that palette entry 131 is used exclusively to draw the number, and palette entry 218 is the grey that surrounds it on all sides. (For an explanation of how to see which palette entry is used on each pixel, refer to the PSP Hacking Guide.)

By copying the grid we have drawn over the 8, we can practise coloring in different squares to see which other numbers can be displayed using the pixels within the shape of the 8. I limited myself to the simplest numbers to fit in, but you could if you wished add in 1, 4, and 7, as well as 11 if you used simple straight lines. They would require use of pixels none of the other numbers use and so would require more editing, which is why I missed them off - that and there's only 12 maximum different hacks for any car anyhow, so I figured 7 different numbers should be enough for anyone!

      

Once we have the different shapes mapped out, we can then see how they interact with eachother. Make another blank grid and number off each of the pixels that can contain a used pixel, that is to say a pixel that will be made to either show or hide when making each number. As you can see here, I haven't numbered the pixels inside the holes because they never change with our choices of numbers. If we now write down which pixels are used for each number we should get a list something like this:-

Number 8 - 2, 3, 5, 6, 7, 8, 10, 11, 13, 14, 15, 16, 18, 19
Number 9 - 2, 3, 5, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19
Number 0 - 2, 3, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 18, 19
Number 2 - 2, 3, 5, 6, 8, 10, 11, 13, 15, 17, 18, 19, 20
Number 3 - 2, 3, 5, 6, 8, 10, 11, 14, 15, 16, 18, 19
Number 5 - 1, 2, 3, 4, 5, 7, 10, 11, 14, 15, 16, 18, 19
Number 6 - 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 16, 18, 19

From this list we can tell that certain pixels are changed a lot, while others never change no matter which shape we choose to display. We shall label each pixel as being either fixed or variable depending on whether it changes state with each number or is always the same no matter which number is showing. :-

Pixel 1 - variable
Pixel 2 - fixed
Pixel 3 - fixed
Pixel 4 - variable
Pixel 5 - fixed
Pixel 6 - variable
Pixel 7 - variable
Pixel 8 - variable
Pixel 9 - variable
Pixel 10 - variable
Pixel 11 - variable
Pixel 12 - variable
Pixel 13 - variable
Pixel 14 - variable
Pixel 15 - fixed
Pixel 16 - variable
Pixel 17 - variable
Pixel 18 - fixed
Pixel 19 - fixed
Pixel 20 - variable

And if we look at the list closer still, we will see that pixels 1 and 4, 10 and 11, 14 and 16, and 17 and 20 change as pairs only. This means that to make all of these different numbers appear, we need to use just 11 different palette entries, and one of those will be the current number color.

If we open the palette we can see that we have 10 spare entries right at the beginning, so we can use these. The next step then is to decide which colors will be used for which changes, and for this I just took them a first-come first-used - the original number color is left on the pixels that never change and each of the 10 new palette entries can take the place of a changing pixel or pixel-pair.


The palette, with numbers overlaid to indicate the entries to be used

Pixel type 0 - All background pixels. palette entry 218
Pixel type 1 - Always visible foreground pixels. palette entry 131
Pixel type 2 - Variable visibility foreground pixels. palette entry 1
Pixel type 3 - Variable visibility foreground pixels. palette entry 2
Pixel type 4 - Variable visibility foreground pixels. palette entry 3
Pixel type 5 - Variable visibility foreground pixels. palette entry 4
Pixel type 6 - Variable visibility foreground pixels. palette entry 5
Pixel type 7 - Variable visibility foreground pixels. palette entry 6
Pixel type 8 - Variable visibility foreground pixels. palette entry 7
Pixel type 9 - Variable visibility foreground pixels. palette entry 8
Pixel type 10 - Variable visibility foreground pixels. palette entry 9
Pixel type 11 - Variable visibility foreground pixels. palette entry 10

Now we get to perform the "surgery" part of all this, and put the new pixels into the picture. This is the hack - by changing the color of the pixels in the positions illustrated to those we have chosen from the unused section of the palette we are making a change as to how it shall be recognised by the computer for display purposes. After you have added these changes, from now on the computer will be looking in a different place to find out how it should show this part of the picture to us, and this is what we shall be changing when we edit the palettes later on.

Lost yet?

Right! If you're still following this you're either on the way to becoming an expert hacker, or deluding yourself. LOL

What you should now have is something looking very similar to the image on the right. I have changed the color for displaying the unchanged parts of the number to white to make them stand out more, but yours should still be showing the dull red it was before.

Save your work! Make sure you don't save it over the unchanged car, unless you are certain you never want to use that copy of it again. If you have been working on a single sprite as part of a deltasheet, now is the time to copy and paste it onto the other delta sprites. If you wait until you have edited the palette the computer will paste the wrong data, and if you only have the hacking done on the undamaged image then as soon as you crash your editing will revert to what is on the other deltas. I shall continue to show single images only, but you should be working with a full deltasheet from now on.

Time to edit the palette again. We're going to make the number look like an 8 again, as the way it looks now is decidely strange.

First you'll need to find out exactly whay you are changing the palette colors to - do this by using the dropper tool to show you the RGB value of an unedited pixel. In this example, the red "on" state is R:086, G:006, B:000 and the grey "off" state is R:172, G:172, B:172. By referring to our grids and lists we made earlier, we can see that the following changes to the palette need to be made:-

Pixel type 0 - All background pixels. palette entry 218 - Leave
Pixel type 1 - Always visible foreground pixels. palette entry 131 - Leave
Pixel type 2 - Variable visibility foreground pixels. palette entry 1 - Change to "off"
Pixel type 3 - Variable visibility foreground pixels. palette entry 2 - Change to "on"
Pixel type 4 - Variable visibility foreground pixels. palette entry 3 - Change to "on"
Pixel type 5 - Variable visibility foreground pixels. palette entry 4 - Change to "on"
Pixel type 6 - Variable visibility foreground pixels. palette entry 5 - Change to "off"
Pixel type 7 - Variable visibility foreground pixels. palette entry 6 - Change to "on"
Pixel type 8 - Variable visibility foreground pixels. palette entry 7 - Change to "off"
Pixel type 9 - Variable visibility foreground pixels. palette entry 8 - Change to "on"
Pixel type 10 - Variable visibility foreground pixels. palette entry 9 - Change to "on"
Pixel type 11 - Variable visibility foreground pixels. palette entry 10 - Change to "off"

Open the Edit Palette dialog and change the values of the indicated palette entries to match the "on" and "off" colors. Your palette should now hopefully resemble this:-


YMMV, other entries may have been changed before release.

When you close the Edit Palette menu your car will now look just like it did before you hacked it - don't you feel proud? No? Well save this anyhow, making sure it's got a different filename to anything else of course, and now we'll change the number again using only the palette!

Pick a number between 0 and 9, not including 1, 4, or 7 - got one? Well, I can't tell what it is because I wrote this way before you read it, so I'm going to pick 5 because it has the most changes needed - 4 of them, in fact:-

Pixel type 2 - Variable visibility foreground pixels. palette entry 1 - Change to "on"
Pixel type 3 - Variable visibility foreground pixels. palette entry 2 - Change to "off"
Pixel type 5 - Variable visibility foreground pixels. palette entry 4 - Change to "off"
Pixel type 9 - Variable visibility foreground pixels. palette entry 8 - Change to "off"

As if by magic, your car now has a number 5 on it's roof, even though you haven't actually redrawn anything -

That's the Secret of Palette Hacking!


Which do you want to drive today?

Play, experiment, if you've followed things this far you shouldn't have any problem working out how to change the palette to get any of the other numbers we hacked in. If you're feeling really adventurous, why not make the extra edits needed to allow 11 to be put on the car's roof - it'll require one extra palette entry and either 2 or 4 pixels per car will need to be redrawn, depending on how exactly you do it.

 

The Possibilities

What can be achieved using this technique of planning exactly what will happen to each individual pixel is limited by only 2 things:-
  1. the size of the palette, i.e. 255 usable entries (0 is always the transparency); and
  2. your imagination!
My edit of Azz/Andy A's Mini Sprint used this technique to create the 4 different roof choices, the mirror changes, and the different bonnet stripes. Each element was recolored to a different section of the spectrum and then the palette was edited directly to achieve the desired effects.

Another use of the Palette Editing technique is making black, white, or grey hacks in PSP. As PSP5 doesn't allow you to individually desaturate individual hues like Photoshop does, editing the palette can give you access to different looks for your car that would otherwise be out of your grasp - in fact, before I realised I could use Photoshop to make the neutral colors I did it this way in PSP myself.

Enjoy, have fun, but don't blame me if you kill your car!

 

BAck to the Palette Hacking Index.


All elements of this tutorial are ©1999 JH4C unless specifically stated otherwise. All comments, queries, hatemail, etc. should be addressed to JustHere4Coffee@Yahoo.com.