Skip to content

Scene localisation table (.LOC)

56 of the 71 scene archives hold a <scene>.LOC: every interface string, item and character name, briefing, tutorial, newspaper text and subtitle the scene can show, with the voice line that goes with a subtitle. It is a tree of named folders and strings, searched by path such as AllLevels/Interface/Buttons/Yes. The loading-screen scenes and errormessages have none.

This page was read from src/engine/enginedata/locale.cpp and checked against all 56 files. tools/port/scene/loc.py parses and rewrites every one byte for byte (LOC: 56/56 identical; also in roundtrip.py). It adds or replaces strings (set_text), and engine_lookup reimplements the engine's search to check written files.

Loading and lookup

  • ZEngineDataBase::AllocSequence calls m_pLocaleResources->LoadFile(CalcCacheFileName("loc")) (enginedatabase.cpp:1045). ResourceCollection::LoadFile (locale.cpp:70) reads the file into one buffer and keeps it. Nothing is relocated.
  • Lookup (locale.cpp:83) takes a key, skips leading /, and per path segment binary-searches the current node with strncasecmp(name, segment, len(segment)). It then steps to the element's data (name + len + 2). On the last segment it returns the address of the element's mask byte, which becomes Resource::m_pData.
  • Resource::GetText (line 40) returns m_pData + 1 when mask bit 0 is set, else "". GetSoundResourceId (line 48) skips the text (bit 0) and the second string (bit 1) and reads a little-endian uint32 when bit 5 is set.
  • GetNumElements and GetElementText/GetElementResource (lines 213, 341, 271) enumerate a folder (mask bit 4). LookupElementFrom reads the element count as a signed char, so a folder with more than 127 elements cannot be enumerated by index past 127. 113 folders on the disc have more than 127 elements; the largest has 232. Lookup by name uses an unsigned count and finds all of them.
  • Resource::SetKey also builds <key>.wav, the name the PC version used for the voice file.

Layout

The file is one node; there is no header.

A node is:

Offset Size Field
0 1 numElems, 0 to 255 (uint8 in Lookup)
1 4 × (numElems − 1) offsets of elements 1 to numElems − 1, little-endian uint32, read byte by byte, so unaligned. They count from the end of this table (data + numElems·4 − 3); element 0 sits at offset 0
1 + 4·(numElems − 1) the elements

A node with no elements is the single byte 0 (AllLevels/ExtraCharacters in all 56 files).

An element is its name, a NUL, a mask byte, then the payload the mask names:

Mask bit Payload Read by
0x10 a child node (the element is a folder; no other bit is set) Lookup, LookupElement, GetNumElements
0x01 the text, NUL-terminated GetText
0x02 a second NUL-terminated string (4 elements on the disc) skipped by GetSoundResourceId
0x20 uint32 sound resource id GetSoundResourceId
0x08 a trailing uint32, when the element has text not read by the engine

Elements are laid out back to back in table order. Each one ends where the next one starts, and the last one ends where its parent element or the file ends. The node table is sorted case-insensitively by name, as the binary search requires (all 56,007 folders are). The packer sometimes lists a key twice: then two table entries hold the same offset and there is one body (56 such entries on the disc).

Masks on the disc (202,647 strings, 56,007 folders):

Mask Count Payload
0x09 150,327 text, then a zero word
0x29 43,726 text, sound id, then the sound id again in 43,616 (no trailing word in 110)
0x10 56,007 folder
0x08 8,588 nothing (an empty entry, for example an unused Caliber line)
0x28, 0x0b, 0x2b 2 each sound only; text and second string; all three

So bit 3 seems to mark "has a trailing word" only together with bit 0. loc.py keeps whatever follows the fields the engine reads as extra bytes, which makes the rule irrelevant for a round trip. New strings use mask 0x09 with a zero word, or 0x29 with the sound id repeated, as most of the disc does.

Text encoding. UTF-8: every string on the disc decodes as UTF-8, and the bytes above 0x7f are UTF-8 sequences (0xc3 0xa9 for é and so on). The text uses \n for line breaks and \t in places. Whether the PS2 font code draws every UTF-8 sequence is a question for the GUI code; the disc's strings show what is safe.

Sound ids. The id is the packed index (byte offset) of a Sound record in the same scene's .SND: all 43,620 non-zero ids on the disc point at type-1 records (snd.md). The same key therefore has different ids in different scenes, and each scene's LOC is built against its own SND.

What the scenes hold

Top-level folders: AllLevels (shared text: Actions, ClothNames, Info, Interface, Items, Oneliners, Upgrades, …) in all 56, NewsPaper in 25 (news and post-mission scenes), FMVSubtitles in 18, and an M<nn> folder in 25 mission scenes (its Dialogue, Oneliners, ActorSounds, Tutorials, TVAndRadio). File sizes range from 159,923 bytes (front-end scenes) to 501,085 (news and post-mission scenes, which carry every mission's newspaper).

The newspaper templates

NewsPaper/Texts holds the newspaper's articles as templates. ZStatisticsTest::LoadText (statisticsscreen.cpp) takes the string named like each text element of the page: NewsPaperTextStats (which includes NewsPaperTextStats_Murder), NewsPaperTextStory, NewsPaperTextFillerLongA and others; NewsPaperTextStats_OLD, _Accident and the copy_of_ drafts are named by nothing. The statistics parser expands {set}, {if}/{else}/{endif} and {locale}KEY{endlocale} (a lookup in the same table, whose result is expanded again) against the mission's statistics, and ZSIMPLEHTML lays the result out with its own tags (zsimplehtml.cpp, GetTagType, ParseHtmlTag):

  • <width>, <indent>, <font>, <linespacing>, <kerning>, <justify>, <gutter>, <caps all|line|word|next>, <tabsize>, <color> and <autocolumn> push a value on a stack of their own, and the closing tag pops it; a stack's last entry is never popped. <beforeLine N> skips what follows, up to </beforeLine>, once the text is past line N. <tab>, <br>, <lt>, <gt> and <img src=... align=... border=...> place things; <!-- --> is a comment.
  • <kerning N> moves the letters of a word N/10 pixels apart (negative: closer), on top of the font's own kerning.
  • </kerning> pops the line-spacing stack, not the kerning stack, on the PS2 and on the PC: a kerning holds until another <kerning> replaces it.
  • The tags match on their first four letters, upper-cased (<caps Next> is <CAPS NEXT>).

PC version

The PC's 54 tables have the same layout and every disc key. Each adds the same 291 PC-only keys (AllLevels/Interface/Online, Interface/Options/PC, Interface/Mouse, more Interface/KeyConfiguration), and 14 keys have other text. The sound ids name the PC scene's .SND, so the same key has other ids on the two sides. PC assets: PC text compares them key by key and describes the port's merge (pcloc.cpp, which parses and writes the layout above in C++, as loc.py does in Python).

Writing strings for a new level

from tools.port.scene import loc
root = loc.parse(open("M00_main.LOC", "rb").read())
loc.set_text(root, "MyLevel/Briefing/Title", "The Lighthouse")
loc.set_text(root, "MyLevel/Dialogue/Keeper_01", "Who goes there?", sound=0x41ee0)  # a Sound from snd.add_sound
open("MyLevel.LOC", "wb").write(loc.write(root))

set_text creates folders along the path, keeps each folder sorted with the engine's comparison, and replaces an existing string in place. write recomputes every offset table, so the file can grow freely. A node holds at most 255 elements. loc.py selftest FILE adds six strings (new folders, a non-ASCII name, an entry that sorts first) and reads them and all existing strings back with engine_lookup, the step-by-step port of Lookup.

A minimal new scene

  • The LOC is optional (LoadFile returns when the size is not positive). Without it, every GetResourceText(first, last) returns last, the key's last segment, so the interface shows key names.
  • The game's shared interface reads AllLevels/... keys. Start from an existing scene's file, the _main scene of a similar mission, and add the level's own folder. The AllLevels subtitles carry sound ids for the scene they came from. With a different SND those ids must be rewritten or cleared (set_text(..., sound=None)), otherwise they play whatever record sits at that offset.
  • Mission scripts and the GUI name the keys. Which keys a briefing screen reads for a new mission is not part of this file.

Unknown

  • The meaning of mask bit 3 and its trailing word (zero, or a copy of the sound id).
  • Which tool chose the packer's order for repeated keys. The repeated keys are identical entries listed twice.