Castles II: Siege and Conquest Cluster Format

From ModdingWiki
Jump to: navigation, search
Castles II: Siege and Conquest Cluster Format
Format typeText
Text purposeStory
Line endings
Character set
Games

The Castles II: Siege and Conquest Cluster Format is used to store the plotlines and plot text for Castles II: Siege and Conquest. This format describes the LIB.CLU file. The name stands for "cluster library".

Bytes 0 to 3999 (from 0x0000 to 0x0F9F) are all 0. Then bytes 4000 to 12803 (from 0x0FA0 to 0x3203) contain the byte location of each cluster entry, in 4-byte little endian format. However, each entry from 12064 to 12803 simply point to byte 1253323 (0x131FCB), which is the end of the file, so they are basically unused. Also, many entries point to the same location as the previous entry, so they basically point to "virtual" clusters of 0 bytes long, as a "null" entry. There are 359 non-"null" entries.

Each cluster has some header information and can be divided 3 subclusters after the header information. The header information contains things like the location of each node within that cluster. Each cluster has up to 10 nodes, each node being a plot branch. The first subcluster is the plot instructions for that cluster's nodes. The second subcluster is the index for each line of text. The third subcluster is the text itself.

The overall structure of LIB.CLU is as follows:

Location DataType Description
0 to 3999 (0x0000 to 0x0F9F) UINT32LE All values are 00
4000 to 12803 (0x0FA0 to 0x3203) UINT32LE Byte location for the start of each cluster
12804 to 1253322 (0x3204 to 0x131FCA) (rest of file) variable Cluster data

The overall structure of each cluster is as follows:

Length DataType Description
2 UINT16LE Cluster ID
2 UINT16LE Unknown (values vary from 0 to 9)
2 UINT16LE Starting byte location (within cluster) of first subcluster (all values are 40 because header is 40 bytes long)
2 UINT16LE Number of plot instructions in cluster (note each instruction is 6 bytes long)
2 UINT16LE Number of (non-virtual) nodes in cluster
2 UINT16LE Starting byte location (within cluster) of second subcluster
2 UINT16LE Number of plot text lines in cluster (note each plot text line index is 2 bytes long)
2 UINT16LE Starting byte location (within cluster) of third subcluster
2 UINT16LE Number of bytes of third subcluster
2 UINT16LE Total length of cluster (or last byte of third subcluster)
20 UINT16LE Byte locations of nodes 0 to 9 (2 bytes each)
variable * 6 UINT16LE Plot instructions (each is 6 bytes long, consisting of 3 little-endian 2-bytes)
variable * 2 UINT16LE Location of each plot text line (each location is 2 bytes long)
variable ASCII (encrypted) Plot text lines; plain ASCII text but encrypted by bit-wise XOR with the first byte of the header (i.e. the first byte of the cluster ID)

Credits

This file format was reverse engineered by Vanshilar. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)