Sunday, December 14, 2014

Extracting information from Creatures 1 PhotoAlbum files (And uncovering a 20 years old 2 pixel bug :)

In the last article, we've seen how to manually use the "dde: pict" CAOS command to take picture of our Norns the way the Owner's kit does it.

When doing it the usual way through the Owner's kit, all pictures are saved in individual photo album files for each Norn.
In this article I will show you all you need to know to extract all information from those file : timestamps, comments, and obviously, the picture data.




The .Photo Album files:

They are found at the root of the Game main directory.
There is one for each Norn for which you took pictures in your games.
They also remain there after a Norn's death, so it is a nice opportunity to recover pictures of dead Norns while the game only allows you to see the last picture you picked for a Norn's grave.

They are named with a string of 4 Hexadecimal characters, followed by the ".Photo Album" extension.
The 8 first characters are hexadecimal representation of a Norn's moniker, and this is how the file are matched to a given Norn.



To find which file contains the data for a given Norn, simply pick it's moniker, convert it's letters to hexadecimal and look for the corresponding file:

0BGE is this Norn's Moniker
  Let's translate a moniker to the corresponding string:
  • 0 = 0x30
  • B= 0x42
  • G=0x47
  • E=0x45
The trick is the moniker is written in reverse in the file name, therefore, when looking for 0BGE's Photo album we don't want the 30424745.Photo Album, but the 45474230.Photo Album one .

Here it is !

Understanding the file format :

When we open the file in a hexadecimal editor, there are familiar things we recognize from the "dde: pict" article.
I'll spare you the whole process of reversing the file format as it's pretty easy and doesn't bring anything more than previous articles.It's mainly made of easily identifiable bits and familiar structures:

This is the file beginning...

And this is the end of the data section for the first picture.



Pretty easy isn't it ?

The .Photo Album format explained:


We now Know the format for C1 Photo album files is read as follows:
  • Number of pictures in album (Coded on 2 bytes)
  • A Cstring containing the Picture timestamp in a readily readable format.
  • Width of first picture coded on 4 bytes
  • Height of first picture coded on 4 bytes
  • The width of the picture again on 4 bytes, this seems to be unused and always equal to first value.
  • The picture actual data ( length is Width x Height bytes )
  • A Cstring representing the Picture's Comment (one single 00 if empty comment)
  • Repeat all above steps for reading Next picture.

The overall format is as such:


Where data for each picture entry is decoded as follows:



 But there is a catch, and a 20 year old two pixel bug:


However there seems to be a bug in the way Photoalbums  are managed:
Whenever there are more than 1 pictures in a given album, a picture's data section length is actually 2 bytes shorter than what it should be.
Reading the full length would make you read the picture comment length and first char as the last pixels data.
Therefore the last 2 pixels of each picture are bound to be corrupted.

Last pixels of the picture are corrupted because the image comment size entry overlaps it.

I find it funny uncovering such a Two pixel bug 19 years after the game release!

You developers thought nobody would ever notice uh ? Sorry about that ^^

Noticing this subtle bug was impossible for even attentive players since pictures are slightly cropped in the Owner's kit:

No visible bug in there, but the pic is cropped !
 While the raw pic contained in the photoalbum is slightly larger and decodes like this :

Corrupted pixel in there !

Also, if you use the game "export pic as BMP" feature, you will notice the exported pic is corrupted in another way that doesn't show the bug :

Exporting pic using the game features doesn't take the bug into account and the picture is slightly corrupted instead.

Unfortunately, this also means going back over the photo album ,adding, removing comments and moving around from inside the Owner's kit seems to be a dangerous activity that might corrupt the Album file.
That's why I never usually use the commenting option.

Trying things out:

 

Okay, let's not give the (awesome) C1 developers to much hard time about that two decades old pair of sketchy pixels and do something constructive instead.

We can now write a quick script to confirm everything works as expected.
What about generating a crude HTML gallery from the game folder using all photoalbums to check our findings ?

There you have it, a quick HTML gallery of all of your Albian population with a quick glance.

I hope you learned some interesting things there.

I promise that when I'm done with the most common game file formats we will get back to slightly more Norn oriented tutorials and explorations, but my goal is to give out as much information about the game as I can so other people can use it for their own needs.

See you soon !




No comments:

Post a Comment