ModEnc is currently in Maintenance Mode: Changes could occur at any given moment, without advance warning.

CSF File Format: Difference between revisions

From ModEnc
Jump to navigation Jump to search
Pd (talk | contribs)
Added a note about spaces
Line 99: Line 99:
'''LabelName'''<br>A '''non'''-zero-terminated string that is as long as the DWORD at 0x8 says. If it is longer, the rest will be cut off.
'''LabelName'''<br>A '''non'''-zero-terminated string that is as long as the DWORD at 0x8 says. If it is longer, the rest will be cut off.
|}
|}
The first label in ra2md.csf can be found at 0x18.
The first label in ra2md.csf can be found at 0x18.<br>'''Note:''' Using spaces in the label name causes problems - such a label cannot be referenced by map triggers like "Display Text String". For example, calling for a CSF entry named {{Co|{{Tt|desc:this_is_a new string}}|#000|#ccc}} will result in a message {{Co|{{Tt|MISSING:desc:this_is_a}}|#000|#ccc}}. ([http://forums.cncden.com/showpost.php?p=191660&postcount=10 related link] )


===Values===
===Values===

Revision as of 05:40, 11 July 2006

CSF files hold stringtables for RA2/YR (also for Generals/ZH and probably others).
For more information about what a CSF file is, go to the CSF page.

On this page you will find a guide to how the format is built up.

The Header

The header of a CSF file is 0x18 bytes long.
It is built up like this:

Offset Type Description
0x0 char[4]

" FSC"
CSF header identifier
If this is not " FSC", the game will not load the file.

0x4 DWORD

CSF Version
The version number of the CSF format.
RA2, YR, Generals, ZH and the BFME series use version 3.
Nox uses version 2.
Nothing is known about the actual difference between the versions.
Thanks to Siberian GRemlin for providing this information (see here)!

0x8 DWORD

NumLabels
The total amount of labels in the stringtable.

0xC DWORD

NumLabels2
It is not known what the exact difference between NumLabels and NumLabels2.
Sometimes (as in not always), NumLabels2 is one less than NumLabels.
You should always make them be equal, as this is known to work fine.

0x10 DWORD

(nothing)
This is not read or used by the game, which means it is useless.
If you want, you can store an extra information tag there, if your program could use one (assuming you want to write a program that reads CSF files).

0x14 DWORD

Language
The language value for this stringtable.
See below for a list


Language

The language DWORD can have the following values (others will be recognized as "Unknown"):

 0 = US (English)*
 1 = UK (English)
 2 = German*
 3 = French*
 4 = Spanish
 5 = Italian
 6 = Japanese
 7 = Jabberwockie
 8 = Korean*
 9 = Chinese*
>9 = Unknown

* RA2/YR has been released in this language.

Labels

After the header, the label data follows.

A label can be considered an entry in the stringtable (e.g. "GUI:OK" is a label).
Each label can have a name (e.g. "NAME:MTNK"), a value (e.g. "Grizzly Tank") and an extra value (no example in the original ra2.csf/ra2md.csf).
While the name and the extra value are ASCII strings, the value is a Unicode string (in order to support Korean, Chinese, etc).

Now let's come to how the data is stored in the CSF file:

Label header

The label data begins with a label header, which is built up like this:

Offset Type Description
0x0 char[4]

" LBL"
Label identifier
If this is not " LBL", the game will not recognize the following data as label data and read the next 4 bytes.

0x4 DWORD

Unknown
This uses to be 1, and 1 works always.
It is not known what this dword is good for.

0x8 DWORD

LabelNameLength
This value holds the size of the label name that follows.

0xC char[LabelNameLength]

LabelName
A non-zero-terminated string that is as long as the DWORD at 0x8 says. If it is longer, the rest will be cut off.

The first label in ra2md.csf can be found at 0x18.
Note: Using spaces in the label name causes problems - such a label cannot be referenced by map triggers like "Display Text String". For example, calling for a CSF entry named desc:this_is_a new string will result in a message MISSING:desc:this_is_a. (related link )

Values

Directly after the label header, the value data follows.
This is how it is built up:

Offset Type Description
0x0 char[4]

" RTS or "WRTS"
Identifier
" RTS" means that there is no extra value for this label.
"WRTS" means that after the value data, data for the extra value follows (see below).
Everything else is invalid.

0x4 DWORD

ValueLength
This holds the length of the Unicode string (the value) that follows.

0x8 byte[ValueLength*2]

Value
This holds the encoded value of the label.
Note that this is ValueLength*2 bytes long, because the value is a Unicode string, i.e. every character is a word instead of a byte.
To decode the value to a Unicode string, not every byte of the value data (or substract it from 0xFF, see below for an example).

0x8+ValueLength*2 DWORD

ExtraValueLength
This holds the length of the extra value string that follow.
This only applies if the identifier is "WRTS" and not " RTS".

0x8+ValueLength*2+0x4 char[ExtraValueLength]

ExtraValue
Like the label name, a non-zero-terminated string that is as long as ExtraValueLength says. If it is longer, the rest will be cut off.

Decoding the value

To decode the value to a Unicode string, not every byte of the value data (or substract it from 0xFF).
An example in C/C++:

int ValueDataLength=ValueLength<<1
for(register int i=0;i<ValueDataLen;i++)
{
  ValueData[i]=~ValueData[i]
}