ROM Hack Bit-related question about .NCGR and .NCLR files

Nowa

New Member
OP
Newbie
Joined
Jan 22, 2023
Messages
3
Trophies
0
Age
22
XP
32
Country
Belgium
Hello everyone, it's my first post here. I've been recently playing around with nds games extraction and more particularly Lego Battles, a game dear to me. So much good memories during my childhood!

Anyway, I've read documentation about basic extractions using tools like Tinke and CT2. So far so good, I successfully managed to extract many assets like ost, 3d models, sprites, palettes...

Out of curiosity, I've analyzed the raw data in NCGR and NCLR files of the game to compare theory to practice (theory being the documentation on romhacking net about nds formats) and something caught my attention. To explain myself, please refer to this picture first:

drawing.png

In the upper part of the picture, we can see I exported the sprite on a grid of 8px of space. The last line of the sprite being one single color (let's call it color1), we can easily found the corresponding bytes in the file (n.b.: in the picture I removed header and information from the file to keep only the DATA). Now in the lower part of the picture, we can observe one patter repeating itself 3 times on the file. The pattern is composed as follow: 1x color1, 6x color6 and 1x color1 (color6 being the black pixels). The file has a tile bit depth of 4 bits btw.

When comparing the pattern with the corresponding bytes (0x50555550), my only conclusion is that one byte contains color for 2 pixels in a row (which is normal bc the palette has 16 colors and 2 pixels can fit in 1 byte) but not in the correct order. e.g.: the two first pixels of the pattern (color1 and color6) are stored as 0x50 which, if we cut the byte by 2, is 5 and 0 in decimal. That's exactly the 1st and the 6th colors of the palette.

So first question: why are the bits not arranged in a logical order ? (why do we have to make an inversion ?)

My second point is basically of the same nature as my first observation. This time it concerns the palette (NCLR file). Again, a picture to support my explanation:

drawing2.png

On the upper left, a representation of the full palette and the raw file on the right side. Same proceeding as previous point: find a frequently repeated pattern and its bytes. Here, we see that color are stored in 2 bytes. Let's take the very first pixel (the green one) that is present on many lines and its 8bit color code (#087030). Now let's take the value as encoded in the file (0xC119). If we invert the two bytes and group the bits 5 by 5 as illustrated, we can make a link with the 8bit color code. We can observe that the color depth of the palette is 5bit, which explains the division by 8 for the RGB value (proof: 2⁸ / 2⁵ = 2³ = 8).

My second question is the following: again, why do we make an inversion with the two bytes ?

All this reasoning may seem pointless but I prefer to explain myself clearly before asking questions. I'm really sorry if I didn't make myself clear enough or if my post is a bit too long, but again it's just because I'm curious on how things work. I attached the files for those who are interested.

TL;DR: given the color depth of the palette (5bit), is it normal that colors encoded in the NCLR file and pixel in the NCGR one are "reversed" ? If not, is that some liberty that the studio that developed the game could have taken ?
 

Attachments

  • files.zip
    1.3 KB · Views: 27

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    This was one of the craziest movies I've seen about our food industry, lots of stuff I didn't know. A must see. https://youtu.be/OqzjC-ENrl8?si=GYxmdY5nShzGniVi
  • OctoAori20 @ OctoAori20:
    Oh, that dude?
  • OctoAori20 @ OctoAori20:
    I stopped believing or caring about that dude when I found out about some of the more questionable nonsense he did in his life.
  • BigOnYa @ BigOnYa:
    Like what? I didn't know or hear.
  • K3Nv2 @ K3Nv2:
    You mean like every famous person that ever existed
    +1
  • K3Nv2 @ K3Nv2:
    I get so tired of hearing oh I liked him until...
  • OctoAori20 @ OctoAori20:
    I just know dude was a chronic alcoholic and such.
  • BigOnYa @ BigOnYa:
    I've been to his chicken restaurant he started in his 2nd movie, Holy Chicken, was pretty good. It is only 15-20 miles from me in Ohio. It only lasted 1 yr or so then closed tho.
  • OctoAori20 @ OctoAori20:
    There are very few people I just have just an immense dislike of and he's one of those very few people, the only other example is Gene Simmons. My musician uncle on my mother's side of the family actually met Gene once during some event and said he was the most unpleasant person to be around.
  • K3Nv2 @ K3Nv2:
    I met myself once turns out that guy is a giant piece of shit that doesn't deserve any of my respect
  • BigOnYa @ BigOnYa:
    Damn alcoholics! (Sshhh- Opens another beer)
  • OctoAori20 @ OctoAori20:
    Agreed, Ken
  • OctoAori20 @ OctoAori20:
    I can't say I've ever tried even a sip of beer tbh-
  • K3Nv2 @ K3Nv2:
    You met yourself also and is a giant piece of shit?
    +1
  • OctoAori20 @ OctoAori20:
    Then again, I don't think I'd really enjoy it //shrug
  • OctoAori20 @ OctoAori20:
    I'm sure it's an acquired taste :P
  • K3Nv2 @ K3Nv2:
    Poor lad can never enjoy the amazing taste of four loko
    +1
  • BigOnYa @ BigOnYa:
    Root beer is a gateway drink, don't ever try it either.
  • K3Nv2 @ K3Nv2:
    @BigOnYa, don't you love how smooth MD20 is
  • BigOnYa @ BigOnYa:
    Mad dog 20 20? Oh yea fixed the typo. I haven't seen that or had forever. Do they still make it?
  • K3Nv2 @ K3Nv2:
    I think it's why I'm alive
    +1
  • BigOnYa @ BigOnYa:
    What happens if when playing Paper Mario, you start a fire in-game?
  • Psionic Roshambo @ Psionic Roshambo:
    Paper Mario is a drug dealer and he is all about the paper yo lol
    +1
    Psionic Roshambo @ Psionic Roshambo: Paper Mario is a drug dealer and he is all about the paper yo lol +1