Post
by Pesmontis » Fri Jun 22, 2012 8:54 am
Here's an introduction to the Spellforce 2 DRS file format:
To start out, there's two types of DRS files, one for 'static' models and one for animated models. Static models are for example weapons. Animated models are obviously heroes, NPCs etc., but buildings are animated as well (**).
The first four bytes in a DRS file determine the model style. Static object DRS files can be recognized by the character sequence "srrd". Animated model DRS files start with HEX(1E F1 7C C5), which can be interpreted as float(-4047.07). For convenience, the different DRS file formats will be designated "srrd" format and "4047" format.
The general DRS header is:
magicNumber - 4 bytes string "srrd" or float -4047.07
numberOfModels - 4 bytes integer 1
Hereafter, the content of the two types greatly differs.
The srrd format is the most straightforward, as it starts out with a mesh header (designated "hsem"), a mesh chunk, a geometry header (designated "moeg"), and a geometry chunk. There's a footer in the srrd format, containing the characters "FOE".
The 4047 format contains two offsets after the general DRS header. These offsets point to two lists at the end of the file. These lists in turn describe and point at the entities in the file. After these two offsets, the number of entities follows. So a 4047 DRS file has an extended header, containing:
entityList01 - 4 bytes offset to the first entity list (list of offsets)
entityList02 - 4 bytes offset to the second entity list (list of entity class names)
numberOfEntities - 4 bytes integer
In order to read out the contents of a 4047 DRS it is best to get these lists first, and then jump through the file using the offsets from entityList01. Identify and parse each entity's contents depending on the class names from entityList02. These class names can be:
"CDspMeshFile"
"CDspJointMap"
"CSkSkeleton"
"CGeoOBBTree" - this class is not sifted yet;
"CGdLocatorList" - this class is sifted only rudimentary;
"CGeoMesh" - this class is sifted only partially;
"CSkSkinInfo"
In addition, the list of class names can contain two additional entities with names containing the words:
"collisionShape" - this class is not sifted yet;
"placementShape" - this class is not sifted yet.
In the DRS file directories, the names of the individual DRS files contains a version number. It seems that "v7" is the latest 4047 DRS file format version, containing only the absolutely required chunks / entities for a complete model. Based on this, it seems that chunks designated with "CGeoMesh", "collisionShape", and "placementShape" are not required for a complete model. It also appears that chunks designated with "CGeoOBBTree" are only required for models of buildings.