/ Days to Die / Unity texture format

Textures, recreate headers, conversions, algorithms and parsing of image files
Karlovsky120
Posts: 2
Joined: Mon Sep 05, 2016 6:37 pm

/ Days to Die / Unity texture format

Post by Karlovsky120 »

I'm writing a small program that requires images of inventory items. Now, I don't want to bundle that data with the program (firstly, it's not mine, secondly, the project will be more future-proof if I do as explained below).

What I want to do is open the resource.assets where those images reside (in a single 2DTexture object), extract the object, transform it into a more standard image format (for example a png) and use that in my program.

The problem I have encountered is that I don't understand the 2DTexture object structure. I think that first 8 bytes are the height and the width of the texture (I converted it to PNG with a tool to which source I have no access and the image size was 4096*4096). Since the size of the file is 67.108.936 bytes and 4096*4096 = 16.777.216 and 16.777.216 * 4 = 67.108.864 I can assume that each pixel is represented with 4 bytes (RGBA maybe?). There are also 67.108.936 - 67.108.864 = 72 bytes of metadata. First eight seem to be the size, but I'm not sure what the rest 64 represent. Here are the first 72 bytes:

Code: Select all

00 10 00 00   00 10 00 00   00 00 00 04   05 00 00 00
01 00 00 00   01 01 00 00   01 00 00 00   02 00 00 00
01 00 00 00   01 00 00 00   00 00 00 00   00 00 00 00
00 00 00 00   00 00 00 00   00 00 00 04   00 00 00 00
00 00 00 00   00 00 00 00


I'm aware that some of the 72 bytes might be in the end of the file, but the texture I'm looking at has at least a few rows of pixels on the top and the bottom completely white. Given that there are only zeros for several thousand bytes after the part I copied and file ends with several thousand bytes of zeroes as well, I can assume that the part above is all of the metadata. I can also assume that four zeros mean white, and since it holds images that go into inventory slots, I can also assume that it's completely translucent.

Here is an example of the rest of the file:

Code: Select all

ff cf 6b 41   ff e6 87 5b   ff f6 9a 6b   ff f1 93 66
ff f8 9f 70   ff fc b1 80   ff ff b8 87   ff fb a7 77
ff eb 8f 61   ff de 83 58   ff e0 89 5c   ff e3 8d 60
ff d9 86 59   ff ca 7f 54   ff e3 99 69   f2 cf 88 5e
9d 6e 3d 28   79 76 48 30   00 ae 65 40   00 99 63 43
00 9a 6d 4c   00 cd 8c 60   00 6e 48 30   00 6f 52 38
00 a6 60 3d   00 8c 59 3b   00 8a 5c 3e   00 56 3e 2a
00 b7 76 4f   00 54 2c 1b   00 a0 56 35   00 95 5d 3b
00 82 4d 2f   00 4d 30 1f   00 bf 7e 54   00 71 50 37
00 88 60 42   00 cd 8c 5f   00 84 59 3c   00 37 17 09
00 bc 73 4f   00 82 54 3c   00 7e 4f 39   00 b5 69 47
00 4d 21 0f   00 6b 44 2d   00 b5 6a 44   00 97 60 41
00 8c 5d 41   00 b8 6b 49   00 fe fe fe   00 fb fb fb
02 fc fc fc   07 f6 f7 f6   0f eb ec ec   1b db dc dd
6f c6 c9 c8   b6 a4 a7 a8   f0 95 98 9a   ff a6 a7 a9
ff b5 b4 af   ff 99 97 8e   ff 75 71 6b   ff 69 67 65
ff 75 77 78   ff 8e 8f 90   ff b2 b6 ba   ff d5 da db
ff cb d4 d7   ff aa b2 b6   ff 59 5c 61   ff 2b 2c 2e
ff 2e 2e 2e   ff 2d 2d 2d   ff 32 32 33   ff 40 43 46
ff 63 69 6c   ff 9e a4 a6   ff d6 dd de   ff e4 e5 e6
ff e8 e9 ea   ff d0 d2 d2   ff c5 ca cc   f1 c1 c6 cc
c3 c4 cb cf   8e cd d1 d3   56 df e2 e3   21 ec ed ef
13 ef f1 f2   0c f5 f6 f7   07 f9 f9 fa   04 fb fc fc
02 fd fe fe   01 fe fe fe   00 fd fd fd   00 fd fd fd
01 fe fd fd   06 f9 f8 f5   12 ee ea e3   4b e7 e0 d6
d2 b7 a5 88   ff 9d 84 5d   ff a5 8d 67   ff a9 92 6d
ff ac 97 72   ff bd a8 84


I'm not really that well versed in structures of different image formats so I don't know what type of metadata they tend to carry. Do any of you know what could this 72-bytes of data mean, as well as how might a single pixel be structured with it's 4 bytes?
Karlovsky120
Posts: 2
Joined: Mon Sep 05, 2016 6:37 pm

Re: / Days to Die / Unity texture format

Post by Karlovsky120 »

Well, I managed to figure it our, sort of. I still have no idea what those 64 bytes mean.

I pulled all the pixel data into my program and constructed a ARGB image from it. It had weird colors and was flipped upside down. Then I swapped each 1st and 4th pixel byte. Picture looked a lot better. I tried swapping 2nd and 3rd pixel bytes and viola, picture had normal colors. It seems it was a BGRA image. I then flipped it and it looked exactly as it should. I could then extract specific items from fixed-up image.

Only problem I have left is that when I'm accessing data from the asset bundle, I specify exact byte where the image starts. Which will work great until the next game update when everything might get shifted due to new asset additions. This isn't really a matter for this subforum, but is there some kind of an index in the bundle file header that would point me to the right location?

Anyway, as far as this thread goes, I have resolved my problem.