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
  • No one is chatting at the moment.
  • K3Nv2 @ K3Nv2:
    Crazy people actually spend $50 on that stuff
  • BigOnYa @ BigOnYa:
    Towelie runs my farm, he's awesome.
  • SylverReZ @ SylverReZ:
    @K3Nv2, Polly is still around from what I've heard.
  • K3Nv2 @ K3Nv2:
    @SylverReZ, is Pollys alt I knew it
  • BigOnYa @ BigOnYa:
    Yea I see him every once whi!e , incognito
  • SylverReZ @ SylverReZ:
    @K3Nv2, I'm not him. Keep looking.
    +1
  • K3Nv2 @ K3Nv2:
    Still don't know why he left unless someone really hurt his feelings
  • K3Nv2 @ K3Nv2:
    Don't know why people get so emotional online just get over it ffs
    +2
  • BigOnYa @ BigOnYa:
    He was the ass of gbatemp, everyone knocked on him, I honestly felt bad, even though I was guilty myself, but he egged it all on himself,
  • BigOnYa @ BigOnYa:
    But he still here, but under dif name, he pm me sometimes still even.
  • K3Nv2 @ K3Nv2:
    It's like they think we'll be in their bed pissing on it the next day
  • BigOnYa @ BigOnYa:
    I feel like gbatemp should make t-shirts or memorabilia to remember the lost ones. I bet the Polly shirts would sell out quick.
  • K3Nv2 @ K3Nv2:
    Nah that could actually bring lawsuits
  • K3Nv2 @ K3Nv2:
    Tempsuits
  • BigOnYa @ BigOnYa:
    PollySuits
  • BigOnYa @ BigOnYa:
    Your correct, Somebody would be guilty and there would be riots, then they storm the gbatemp capitol,
  • K3Nv2 @ K3Nv2:
    Online or not there are still certain rights that judges would have no issue handing out a warrant over
  • K3Nv2 @ K3Nv2:
    Just look at Kim dotcom
  • BigOnYa @ BigOnYa:
    Honestly I'm scared to, from you, but ok, lemme turn on vpn, virtual machine, private browser first
  • K3Nv2 @ K3Nv2:
    Remember that Alexa robot I gifted you
  • K3Nv2 @ K3Nv2:
    And that laptop Webcam you never tapped up
  • BigOnYa @ BigOnYa:
    That robot is here somewhere, I hear it moving around at night, but I haven't seen it for months.
  • BigOnYa @ BigOnYa:
    Oh that laptop I give to ancientboi, so you been watching him for months, and he's been watching you
  • K3Nv2 @ K3Nv2:
    Oh good more than enough material for the fbi
    +1
  • BigOnYa @ BigOnYa:
    Damn its 5 in morn, I gotta Go wake your mum and send her to work. Check ya later.
    BigOnYa @ BigOnYa: Damn its 5 in morn, I gotta Go wake your mum and send her to work. Check ya later.