PDA

View Full Version : WLD file format


daeken_bb
12-28-2003, 09:31 AM
Not sure which forum this is appropriate in, so I'll just drop it here.

The WLD file format is fairly simple once you break it down into fragments. The header is 24 bytes long, and is as follows:


struct WLD_Header {
/* 0x0000 */ unsigned long features[2]; // Info used to analyze what features the WLD uses.
/* 0x0008 */ unsigned long maxFragment; // Number of fragments in the file.
/* 0x000C */ unsigned long unk[2]; // 8 bytes of unknown data, usually 0x1DBB and 0x680D4.
/* 0x0014 */ unsigned long nameHash_size; // The length of the namehash.
};


I am unsure as to what the values of the two longs in the features field or in the unk field are used for, as of yet. The maxFragment field is the number of fragments. The nameHash_size field is the length of the namehash in the file.

After the header comes the namehash, and its length is, of course, the value of nameHash_size. The namehash is encoded and decoded using the following algorithm (thanks to the creators of ZoneConvertor for the algorithm):


function Code($data, $size)
{
$codes = array(0x95, 0x3A, 0xC5, 0x2A, 0x95, 0x7A, 0x95, 0x6A);
for($i = 0; $i < $size; ++$i)
$data{$i} = chr(ord($data{$i}) ^ $codes[$i & 7]);
}


Next comes maxFragment number of fragments which are in the format of this struct:


struct WLD_Fragment {
/* 0x0000 */ unsigned long size; // The size of the fragment.
/* 0x0004 */ unsigned long object; // Fragment type.
};


After the struct, comes the fragment data itself, which is as long as the size field of the struct indicates. Valid fragment/object types are 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x17, 0x18, 0x21, 0x22, 0x26, 0x27, 0x2C, 0x2D, 0x30, 0x31, 0x34, 0x36. If the fragment/object type is set to something else, then it's of type "DataWithName", according to ZoneConvertor. What is done with the fragment data depends on the fragment/object type.


Hopefully my info is accurate ;)

Cheers,
Daeken

daeken_bb
12-28-2003, 10:12 AM
Data03 fragments start with an unsigned long that has the count of chunks in the fragment. Each chunk has an unsigned short which is the length of the data stored in the chunk, and then that many bytes of data.
This data is encoded using the algorithm used for the nameHash in the WLD file header.

Data04 fragments start with an unsigned long containing flags, and then an unsigned long with the count of fragment references.
If the flags & 0x4 != 0, then there is an unsigned long containing "parameter" 1.
If the flags & 0x8 != 0, then there is an unsigned long containing "parameter" 2.
After the optional data is a number of fragment references, indicated by the count in the Data04 header.
Each fragment reference is unsigned long containing the fragment index it references.