[XBOX 360] Perfect Dark Zero *.CAF archive

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
E3245
Posts: 10
Joined: Sat Aug 22, 2015 9:37 pm

[XBOX 360] Perfect Dark Zero *.CAF archive

Post by E3245 »

Hello again.
Several years ago, I asked the Facepunch community if there was a way to extract from this game. We've got a few models out, but with much difficulty.

A little bit of info:

The PKG files that were on the disk was a zlib type file, so offzip was able to unpack the CAF file. The CAF file is a container of sorts, with organized sections: Data, GPU, Stream.
The header starts with CAFF28.01.05.0031.

There are also readable ASCII strings, plus paths, when opening up the .caf file in a hex editor.
Image

More details of this format can be found in this link: https://facepunch.com/showthread.php?t=1235313&page=3

From mariokart64n:

all strings are on alignment of 8 rest of the data is on 16.

Anyway your notes were solid, and that unknown data really just looks like rubbish.
I thought I saw some form of floats in the data.. but really cant find make use of it, I was gonna poke the data.. but I then realized that PDZ is first person, its only 3rd person in cutscenes, or if you roll. so testing things like poking when you can't see the main models makes things difficult :P

To top that I really don't see any UVs or weights, or bones, or any other components other then the verts and faces..

I'm going off a guess but the components must have been in other data sections, So I've been using the past 3-4hours looking at the PKG->CAF files..

PKG is zlib, which unpacks a CAF, the CAF is a file container. but data is organized into broad categories, Data, GPU, Stream.
Data houses the model data along with any other misc data.
GPU houses Textures, and Stream I believe is shader data... I haven't examined alot of CAF files so its only a guess

after the strings, like data, gpu, stream etc are there block sizes. then after is the data starting position. so position of each resource block can be calculated.

GPU and Stream seem to be RAW streams, therefore data contains the necessary info to understand the later blocks

Now looking into deciphering the data block, its pretty wild.


Here's the link to the file:
http://www.mediafire.com/?yhqpwdopvwztfq1

The file is approximately 215 MB when uncompressed.

I'm not sure if it is worth anyone's time, but I'm giving it another shot. All I need is a way to extract models and textures from this.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: [XBOX 360] Perfect Dark Zero *.CAF archive

Post by aluigi »

Very chaotic.
If you need a way to dump the sections of the file (useless) you can use this script:

Code: Select all

endian big
idstring "CAFF"
get DUMMY string
padding 4
get DUMMY1 long
get DUMMY2 long
get DUMMY3 long
get DUMMY4 long
get DUMMY5 long
get DUMMY6 long
get DUMMY7 long
get DUMMY8 long
get DUMMY9 long
get BASE_OFF long
get DUMMY10 long    # contains the number of sections in 8bit?

for OFFSET = BASE_OFF
    getdstring NAME 8
    if NAME == ""
        break
    endif
    get DUMMY1 long
    get DUMMY2 long
    get SIZE long
    get DUMMY4 long
    get DUMMY5 long
    get DUMMY6 long
    get DUMMY7 long
    get SIZE long

    log NAME OFFSET SIZE
    math OFFSET + SIZE
next

The first part of ".data" is a list of names+extensions but there are no offsets or other information, it's just a mess.
E3245
Posts: 10
Joined: Sat Aug 22, 2015 9:37 pm

Re: [XBOX 360] Perfect Dark Zero *.CAF archive

Post by E3245 »

Thanks for giving it a shot, aluigi. Like I said, this file format is difficult to decipher. Someone on Facepunch had to use a custom script with unbundler to extract the textures, and some kind of method to extract the vertices of each model. He disappeared a long time ago, though.
E3245
Posts: 10
Joined: Sat Aug 22, 2015 9:37 pm

Re: [XBOX 360] Perfect Dark Zero *.CAF archive

Post by E3245 »

Alright, here we go. I think I've found some documented information on the CAFF format.
Taken from here: http://www.therwp.com/forums/showpost.php?p=455932&postcount=309
CAFF (most likely stands for Common Asset File Format) and has been used by Rare since it's days on the original Xbox.

Code: Select all

Header (size 0x78)
offset   size   desc
0x00   0x04   FourCC (CAFF)
0x04   0x10   Version (char) 07.08.06.0036
0x14   0x04   Size of header (0x78)
0x18   0x04   Header Checksum
0x1c   0x04   Number of Symbols
0x20   0x04   Number of File Parts
0x48   0x01   Type
0x49   0x01   Number of Sections
0x50   0x04   DataBase (offset from the end of the caff header (0x78) )
0x60   0x04   DataBase
0x64   0x04   DataOffs (add to DataBase to get start of section data)
0x74   0x04   DataOffs

Then follows a SectionInfo structure for each Section


Code: Select all

Section Info   (size 0x21)
offset   size   desc
0x09   0x04   Data Length
0x1d   0x04   Data Length

Next follows the null terminated section names

0x00 0x04 Length of Symbols Buffer

Then follows an offset value for each Symbol. This is an offset into the Symbol Buffer

Then the null-terminated Symbols

Then follows a entry for each file part. So, if a file has data in more than one section, it would have multiple entries here, tied together by the FileID member.

Code: Select all

FileInfo   (size 0x14)
offset   size   desc
0x01   0x02   FileID
0x03   0x04   Data Offset
0x07   0x04   Data Len
0x0B   0x01   Section

Then the data sections

It is fairly easy to extract section data by iterating through the sectionInfo structures, adding the lengths to make data offsets

Extracting actual files can be achieved by iterating through the symbols list, and then getting it's data from each section by using the FileInfo table.


TYPES

.data
Generic data. For example: information describing the texture, such as type, width, height

.texturegpu
The data that will be loaded into the gpu. i.e raw texture data that has been converted to the correct format for the target platform.

.stream
data that will be streamed. Information about this layout is likely to be described in the .data section

The are more types, but I've not had to look at any more yet, but obviously when extracting models the .gpu section will come into play

It must be noted that some sections can be compressed. This was the case on Perfect Dark Zero, but I've not come across any that are compressed in Nuts & Bolts.