Jump to content

Welcome to NiGHTS COMMUNiTY
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

Reverse engineering Steam NiGHTS Into Dreams...


  • Please log in to reply
3 replies to this topic

#1
The Gremmar Warden

The Gremmar Warden

    Newbie

  • Visitor
  • Pip
  • 5 posts
  • Gender:Female
A little after buying NiGHTS Into Dreams... on Steam a month ago, I was looking through the gallery and I was curious if I could find the raw images somewhere in the game's files. On my computer, these files can be found in 

C:\Program Files (x86)\Steam\steamapps\common\NiGHTS Into Dreams\afs .
 
Among these are a variety of file formats including .adx, .csb, .sfd, and most importantly, .bin files. A number of these files, labeled GAMEUI_GALLERY_XXX.BIN, where XXX is a 3-digit number, seemed likely candidates for gallery image files, so I took a look at them in a hex editor. Long story short, I spent the next few weeks trying to reverse engineer as much of the image files as I could using my amateur programming skills. If you want to see the details I put them in the spoiler below.

 

Spoiler

 
With knowledge of these file formats, it's now simple to convert images into the game's format and create custom textures. Here are a couple I've tried for NiGHTS:
 20210719231345-1.jpg

20210721181812-1.jpg
 

 
The code I have can be modified to potentially edit any of the game's textures. However, at the moment it's very user-unfriendly. I'm trying to improve it and adding a GUI or at least a way to use it from the command line, but right now it's pretty messy. 
 
 

Aside from textures, there are some interesting things I found among the gallery files. The big one is a set of graphics that I believe is from the PS2 release:
000.png
 

 

I'm having technical problems due to the amount of images so here are links:

 

 

 
Most of the gallery images correspond with the ones in-game, and are in a similar order. Some however, are not seen in-game, namely these merch images, which dhoppy203 on the NiGHTS Into Dreams amino pointed out to be from Saturn Christmas NiGHTS:

 
 
Other notes:
Images are always square and have a size corresponding to a power of 2, with 256x256 and 512x512 being the most common. Images that are larger than this are split into 512x512 blocks each with separate palette. 

 

The files have an interesting header structure with the bytes representing "P Q R S" repeating a certain number of times before the actual image data begins. I don't know what the header data means aside from that there are more repetitions for images with multiple 512x512 blocks. The header portion ends with four FF bytes. The image data doesn't immediately follow the header but begins at some multiple of 0x100. 

https://ibb.co/FnmPg6z

 
All of the gallery images appear to be squashed horizontally to 5/6 of their correct ratio. I would guess that this is intentional because the video files are also horizontally squashed.

 

The gallery files appear not to be used in-game, as renaming them doesn't change the gallery images' in-game appearance. The in-game gallery also appears to have higher quality images than the bitmaps.

 

Texture files can be found about midway through files with names such as DATCLARIS.BIN and DATWIZE.BIN. The rest of the data is probably for the character's 3d model itself.

 

Interestingly, Christmas NiGHTS' model data includes the halloween texture, even though Halloween NiGHTS also has a separate file.
 

Some textures ripped using this method:

https://ibb.co/HCLPcKS

 
 
 
Some questions I have for you guys:
Has anyone else had luck with ripping textures and other data from this game, and might have an easier way of viewing the files than my cobbled-together programs?
Is anyone familiar with the file formats used in this game, and knows the meaning of the header data or what program the files were designed for?
Does the PS2 version of NiGHTS Into Dreams include the merch images in its gallery?
 
 
That's all I have for now. I'm curious to hear what you guys think!



#2
The Gremmar Warden

The Gremmar Warden

    Newbie

  • Visitor
  • Pip
  • 5 posts
  • Gender:Female

Some updates:

  1. Actually, images can be rectangular, and many of them are.
  2. Some images are encoded as 4-bit bitmaps, using only 4 bits for each pixel. This limits the color palette to 16 colors. They also appear to be scrambled in a different way than the 8-bit bitmaps.
  3. After some trial and error, I think I've managed to figure out the meaning of certain header bytes. Here's an example:

These two blocks of bytes are the header data for one image. I believe the first one refers to the length and formatting of the pixel data itself, and the second one defines the length and formatting of the palette. However, some files (notably some starting with DITEM) have an odd number of header "blocks." I'm not sure what this means.

 

I'm not completely sure, but this blue byte seems to be connected with whether or not you need to double the width and height values to get the true size of the image. If 14, don't double, and if 00, do double. 

 

06 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00

04 00 00 00 00 00 00 10 0E 00 00 00 00 00 00 00

00 00 00 00 66 04 02 14 50 00 00 00 00 00 00 00         

00 00 00 00 00 00 00 00 51 00 00 00 00 00 00 00

08 00 00 00 10 00 00 00 52 00 00 00 00 00 00 00        pink = width of image in pixels

00 00 00 00 00 00 00 00 53 00 00 00 00 00 00 00        green = height of image in pixels 

04 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00

04 00 00 30 00 00 00 00 00 00 00 00 00 00 00 00

Both the width and height values appear to be 4-byte integers, and are little endian (bytes must be read backwards). Thus, width here is 0x00000008 = 8, and height is 0x00000010 = 16.

 

This byte is connected with the type of palette. If 02, the colors are 16-bit, otherwise they are 24-bit.

06 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00

04 00 00 00 00 00 00 10 0E 00 00 00 00 00 00 00

00 00 00 00 BA 04 01 02 50 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 51 00 00 00 00 00 00 00

08 00 00 00 02 00 00 00 52 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 53 00 00 00 00 00 00 00

02 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00

02 00 00 30 00 00 00 00 00 00 00 00 00 00 00 00

 

These 2 bytes always appear to have the same value as each other, and seem to say whether or not an image is 4-bit (probably has something to do with the size of the palette). If 02, the pixels are 4-bit, otherwise they are 8-bit.

 



#3
Bosco

Bosco

    Member

  • Visitor
  • PipPipPip
  • 63 posts
  • Gender:Male
  • Location:Santiago, Chile
  • Interests:Programming, sciences and arts.

Woah! Amazing! Keep it up!
It's nice to know that more people is interested in reverse engineering the original game (SAT/PC).

I would like to see more updates from you soon.



#4
The Gremmar Warden

The Gremmar Warden

    Newbie

  • Visitor
  • Pip
  • 5 posts
  • Gender:Female

Thanks!
And yep, there are some more updates. First, someone informed me that the images are using a common PS2 file format, so it turns out there was no need to reverse engineer them after all. Instead, I turned to the model formats (probably a known format as well but I didn't know that at the time, and the only PS2 model ripping methods I see when googling it involve using a PS2 emulator). I stumbled across this reddit post that gave me a clue on where and how the vertices were stored. Starting with this knowledge, I was able to work out how most of the model data is stored (details in spoiler)

Spoiler

 

And now having access to the model data, me and a few other people in a NiGHTS discord channel discovered that there is actually a HUGE amount of unused content. This is just one of many unused, likely prototype models in the game:

NiGHTSintoDreams-UnusedNiGHTSModel.png

We put some of this content up on TCRF, and someone else offered add the rest of the model renders there. 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users