don't click here

Beginners Tutorials

Discussion in 'Engineering & Reverse Engineering' started by Syren, Sep 12, 2004.

  1. Syren

    Syren

    Member
    4,330
    0
    0
    Teesside, UK
    Reintergration
    Tutorial One: Pallet hacking.

    This is a tutorial on Pallet editing with hex. I have written this tutorial because some newbies to the community might want to have a greater understanding of hex, or to build up their skill in hex editing.

    Before people ask "Wouldn't this be redundant? There are pallet editing programs..." I am aware of that. I'm sure this could be handy to some people, and after all I do believe that a people like me shouldn't be dependant on programs instead of doing the manual work. :P

    In this tutorial, I will be giving a complete explination of how to change pallets, and I will do this with two examples with the offsets to these examples.


    Example ONE: Sonic's pallet. (Or Tela Titulo in ESE II.)


    Sonic's pallet colours are located at various offsets in the ROM. The image below shows a picture containing the pallet and the hex codes for the specific colours:

    [​IMG]

    The numbers on the pallet colours are for me to use when writing these offsets. And these offsets are:

    1) 0133EC
    2) 0133EE
    3) 0133F0
    4) 0133F2
    5) 0133F4
    6) 0133F6
    7) 0133F8
    8) 0133FA
    9) 0133FC
    10) 0133FE
    11) 013400
    12) 013402
    13) 013404
    14) 013406
    15) 013408
    16) 01340A

    So basicaly, if you go to 0133EEC in a hex editor (And if anyone isn't sure of what to use, I reccomend Hex Workshop by Breakpoint Software.) And you will see that the numbers and letter at 0133EEC is 0E20. To change that, just write over it with the colour you want to use. (I will get on to that later.)

    Example TWO: Spectial Stage One.
    Again, the colour information is located at various places in the ROM, and I have made another picture for you all to show the offsets and hex for the colours.

    [​IMG]

    The offsets in this pallet are:

    1) 0031C2
    2) 0031C4
    3) 0031C6
    4) 0031C8
    5) 0031CA
    6) 0031CC
    7) 0031CE
    8) 0031CF
    9) 0031D0
    10) 0031D2
    11) 0031D4
    12) 0031D6
    13) 0031D8
    14) 0031DA
    15) 0031DC
    16) 0031DE

    Notice that they all go up in 2's. I don't know why they do, but I think it's worth noting.

    Now that you have a decent example of two pallets, I'll write out a few more without detail so that anyone who reads this can do some of the work theirselves.

    Metropolis Zone: Pallet starts at 002AE2. Since it has four lines of 16 colours on any pallet editor, some may get confused on which colour is at 002AE, so it's worth noting that the offsets for each colour go across, not down. Here's a rather poorly made picture to show what I mean.

    [​IMG]

    Now, this is the part where I make less explinations but more pictures. The hex values of colours in the genesis are set out like this, 0BGR, which means that there is a 0 before ever colour in a pallet, ammount of Blue, ammount of Green, and then the ammount of Red.
    Since you (being anyone who does this) are working in Hex, it's impossible to see what colour 0888 is (although I have heard of some hex editors that do that). So here's a picture of every colour in the Genny.

    Ok, so maybe every colour in the Genny is a bit mutch for me to do. 1536 colours! So here's a picture of the main Red Green Blue values (Another note: All colour values go up in two. You'll see what I mean in the picture) :

    [​IMG]

    Further notes: I have tried finding a website that lists all 1536 combinations, but I have failed. If anyone could post a link, it would be very usefull! :)

    I hope this is of use to anyone. If I have made a mistake or left anything out that I haven't done intentionaly, please tell me! :(
     
  2. LOst

    LOst

    Tech Member
    4,891
    8
    18
    I would rather see screenshots of the hex editor.... How to find the offsets in the first place, and what is an offset?
     
  3. Syren

    Syren

    Member
    4,330
    0
    0
    Teesside, UK
    Reintergration
    Good point.

    What is an offset?

    An offset is a specific place in the ROM that holds certain data. Nothing more, nothing less. An example is the offsets for the pallets. To get to an offset, we use this in the above mentioned Hex Workshop:

    Open the ROM in Hex workshop. I want to get to offset 0133EC, so I click Edit. then Goto.

    [​IMG]

    When the Goto box comes up, I enter the offset in hex.

    [​IMG]

    After I have done that, I click go. Hey presto, I'm at 0133EC.

    [​IMG]
     
  4. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    This is because the data is stored exactly as you have shown it in your lovely little image, in groups of two bytes consecutively.
     
  5. LOst

    LOst

    Tech Member
    4,891
    8
    18
    I'm using Winhex. The basics are the same.

    This is where you find the goto offset:
    [​IMG]

    The offset is mostly showing up at the bottom status bar in any hex editing program:
    [​IMG]
    Go to offset D382 to find the Sonic object's pointer in Sonic 1.

    [​IMG]
    At the left side of the hex editor, you can see the offsets with a 16 byte boundary.
    The sonic object is at offset 12BD8, so the Sonic 1 ROM declares the offset with a 4 byte pointer: 00 01 2B D8 as seen above.
     
  6. Syren

    Syren

    Member
    4,330
    0
    0
    Teesside, UK
    Reintergration
    Thanks Quick Man and LOst, it's great that I made something worth people adding to and caring about. :D
     
  7. Icy Guy

    Icy Guy

    Hedgehog. Sonic the Hedgehog. Member
    776
    0
    0
    California
    GoldenEye 007 level hack
    1536? Don't you mean 512?

    # of colors for red: 8
    # of colors for green: 8
    # of colors for blue: 8

    8 x 8 x 8 = 512

    Anyway, looks good, Soil. :) Even if you can do something in an editor, it's important to have at least some idea as to how to do it in a hex editor. Well, at least most of the time. :P
     
  8. Syren

    Syren

    Member
    4,330
    0
    0
    Teesside, UK
    Reintergration
    I thought it was that number, but Quick Man told me on IRC that it was 1536 including shading and whatnot. Either that's a mistake on his behlaf or someone's making me look like a monkey. :P

    You're right about the importance of knowing vaguely how to do it by hand. I'm not the most informed, but I'm still learning and trying hard to break things down.

    I remember way back (SirisDincht ring a bell?) when I downloaded a hex editor, opened up Sonic 2, and almost cried because I found it frustrating as hell. I didn't know what an offset was (and supprisingly I didn't include that with this untill it was brought to my attention! :o) and everything I read looked like random words strung together. Hence this tutorial topic.
     
  9. Icy Guy

    Icy Guy

    Hedgehog. Sonic the Hedgehog. Member
    776
    0
    0
    California
    GoldenEye 007 level hack
    IcyGuy900: 1536 colors on the MD, eh?
    XinuX 2000: I was assuming that the shades from highlight/shadow were different to the ones for regular use.
    XinuX 2000: So 0EEE will be inbetween 0CCC and 0EEE when shadowed, and brighter than 0EEE when highlighted.
    IcyGuy900: So are they?
    XinuX 2000: I dunno.
    XinuX 2000: I can't find any data on highlight/shadow.

    Guess that settles it, but after all: we're all still "only human." :)

    EDIT: Apparently, 1536 colors at once IS possible, according to...Charles McDonald, I think. Check it.
     
  10. Syren

    Syren

    Member
    4,330
    0
    0
    Teesside, UK
    Reintergration
    It doesn't add up to me, there aren't that many combinations of 8 shades of 3 colours, is there?
     
  11. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    Three shades of three shades of eight colours.
     
  12. Bleeding Cut

    Bleeding Cut

    Dr. Knuckles Member
    Thank you Soil! Now hex doesn't look like a bunch of random numbers and letters to me! :)

    I think it might be a good idea if this went into the E&RE Archive for future reference.
     
  13. Umm, this may be a dumb question, but how do you convert the rom's palette RGB values to real values. I'll explain why I am asking...

    When I was trying to correct a palette for a sprite sheet, I originaly made the sheet using Gens' colors, but later I use Megasis to get cirtain sprites I couldn't in Gens and they were darker.

    Okay, so maybe Gens' engine reads colors differently than Megasis, so I use SonED to sample colors... o_O Different again! Okay, lets try ESEII, OMFG!!! The same color on all 4 was a different shade/hue/brightness ><

    So then, to get a genuine palette, I began using the values in the rom, thank god they show a pattern! Now, I began constucting a palette in PSP using the values as values for html colors. For example, I would turn 0E44 into #4040E0 in html values. This is the way Megasis does it, but another program wrote these same values as #4444EE *head explodes*. WHICH IS THE RIGHT WAY TO CONVERT!?
     
  14. Drakmyth

    Drakmyth

    Inspector Drakmyth Master at your service. Oldbie
    420
    0
    0
    In the void beneath the ancient maze...
    Sonic Eclipse 2, Return of the Hidden Palace, Unnamed Sonic 2 Hack
    hmm... I'm not big into palette editing but here's two things you could do.

    1.) Actually figure it out, probably via someone's post that will be appearing here in the future giving you the answer.

    2.) Go to a place where no one knows you and demand they do it for you adding loads of turd talk.

    I'm not sure what's wrong with me today. I just really feel the need to reply to posts with an answer that could be done but has almost no chance of working.
     
  15. turd talk? You mean newb talk right? Because if I go anywhere talking like a turd, I'll ether get teh ban or flamed ><. And why do that? I'm only a tad bid new to Sonic hacking, not hex editing or Sonic in general. So acting turd will get me nowhere. I'll just wait till someone posts a relavent response.
     
  16. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    There is no "right way" to convert. That format IS.
     
  17. Drakmyth

    Drakmyth

    Inspector Drakmyth Master at your service. Oldbie
    420
    0
    0
    In the void beneath the ancient maze...
    Sonic Eclipse 2, Return of the Hidden Palace, Unnamed Sonic 2 Hack
    No I meant turd. Like I said, I'm kinda messed up today so just pick out the parts that might work. I should be better tomorrow.
     
  18. Syren

    Syren

    Member
    4,330
    0
    0
    Teesside, UK
    Reintergration
    8-Bit dragon's been here longer than I have, so I doubt he's that bad.

    Anyhow, on topic por favor.

    Aah, satisfying thank you's.

    What should I move onto next? Pallet hacking is one of the most basic things people do, yet they choose not to learn further and do it in hex. Maybe I could do Music hacking. What do you guys think?

    The reason I ask is because I'm learning too. I wouldn't actualy know myself what offsets are in Sonic's pallet, the main pallet colours, etc, if it weren't for reaserch. And ESE.
     
  19. Kles

    Kles

    Member
    Do Sonic 2 music hacking. It'd be fun trying to mess around in it, and I don't know how, I'm too lazy to read up or use Sonic QX (I don't like the program, too many bells and whistles that I don't recognize.. sure, it'd probably be great if I understood. Anyways.. /tangent), so go for it :P

    I wanna be able to mod it like I can (could) in Sonic 1.. if that's possible (I'm pretty sure it is.)
     
  20. Korama

    Korama

    Tech Member
    272
    2
    0
    That's no dumb question but a good one.

    First, let's look at the format of a Mega Drive color value:
    Hexadecimal: $0BGR
    Binary (16 bits): %0000bbb0ggg0rrr0
    There are 3 bits per RGB component, meaning that each component can have 8 values: 0..7.
    But PCs normally use 8 bits per component (values 0..255).

    So, in order to convert an MD color to a PC color, you have to scale each component from 3 to 8 bits, and that can be done in several ways.

    1) The accurate mathematical conversion which uses the full target range is "PCValue := MDValue * 255 / 7", with MDValue being a number from 0 to 7. To avoid having to do that calculation every time, you could also initialise a small lookup table with the converted values, rounded to the nearest integer.
    Code (Text):
    1. MDValue --> PCValue
    2. 0 --> 0
    3. 1 --> 36
    4. 2 --> 73
    5. 3 --> 109
    6. 4 --> 146
    7. 5 --> 182
    8. 6 --> 219
    9. 7 --> 255

    2) Separate the three components into individual bytes and shift each byte 4 bits to the left. That way, $0EEE would become $E0E0E0. This method is very fast because you only need bit shifts, no multiplications or divisions. But it has the disadvantage that the full dynamic range isn't used. $E0E0E0 is no perfect white, $FFFFFF would be it. This list shows the results of the conversion:
    Code (Text):
    1. MDValue --> PCValue
    2. 0 --> 0
    3. 1 --> 32
    4. 2 --> 64
    5. 3 --> 96
    6. 4 --> 128
    7. 5 --> 160
    8. 6 --> 192
    9. 7 --> 224
    3) There is a method that combines the benefits of the first (full range) and second (only bit operations required, no other arithmetics) ways. It works in all situations where you have to expand a certain number of bits.
    The formula for our case here is "PCValue := (MDValue shl 5) or (MDValue shl 2) or (MDValue shr 1)", with "shl" being binary left shift, "shr" binary right shift and "or" binary OR. MDValue is a number from 0 to 7 again.
    I'll try to illustrate what this does:
    Code (Text):
    1. MDValue = %xyz (three bits)
    2. %xyz00000 (MDValue shifted 5 to the left)
    3. %000xyz00 (MDValue shifted 2 to the left)
    4. %000000xy (MDValue shifted 1 to the right)
    5. ---------- combine with OR
    6. %xyzxyzxy (resulting PCValue, using the full range of 8 bits)
    The results of this function are the same as those of method 1. Neat, eh?


    Finally, to convert an 8 bit PC component back into a 3 bit MD component, you just shift it 5 to the right (that is, you take the 3 most significant bits of the PC component and discard the rest).