|
DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
|
Game text can come from JSON files instead of the disc's .mes message files. A JSON file holds only the messages it changes; every message it leaves out, and every file it does not mention, is read from the disc as before. Nothing from the disc is shipped: a translator starts from an export of their own extracted data (below), and the files the port distributes hold only text written for the port.
The files are laid out as Minecraft's language files are: one flat JSON file per language, named language_COUNTRY.json, each an object of "dotted.key": "text", with the same keys in every language.
darkcloud --data <data folder> --export-text <folder>. Choose <save folder>/lang-export/ for the output folder, for example. This writes every language's JSON (en_gb.json, fr_fr.json...). They come from your own disc, so the build cannot make them and the repository does not hold them. Normal game startup does not generate these exports. Copy the file you want to change to <save folder>/lang/ and edit it (the save folder is --save, else ./save).tools/font/, see its README), instead of the game's blurry bitmaps. The build copies it to lang/font.ttf and lang/font_thin.ttf beside the executable. To use another font, put it at <save folder>/lang/font.ttf (that wins), or start with --font <file>.game.language in config.json).One file per language, named by the language the game is set to:
| Language | LanguageCode | File |
|---|---|---|
| Japanese | 0 | ja_jp.json |
| English (US) | 1 | en_us.json |
| English (UK) | 2 | en_gb.json |
| Francais | 3 | fr_fr.json |
| Deutsch | 4 | de_de.json |
| Italiano | 5 | it_it.json |
| Espanol | 6 | es_es.json |
The port looks in two folders, in this order, and a later file's messages replace an earlier one's:
lang/ beside the executable,lang/ in the save folder (--save, or DC_SAVE).The language is looked up whenever the game asks for a file, so a change of language takes effect on the next file the game loads; the JSON itself is read once per language, so restart the game after editing a file.
-32768 to 32767); an id the disc's file does not have is added.fr_fr.json and de_de.json have the same keys for the same messages and can be set side by side. It is the path the game loads with the language taken out, the .mes taken off and the slashes made dots:| The game loads | Key |
|---|---|
dun/script/d01/d01_3.mes (and d01_2.mes, d01_4.mes...) | dun.script.d01.d01 |
meswin/system14_2.mes | meswin.system14 |
gedit/e01/e01talk_3.mes | gedit.e01.e01talk |
commenu/a_fre/dungeon/dunmenu5.pak/allmenu.mes (a_eng/, a_ger/...) | commenu.dungeon.dunmenu5.pak.allmenu |
noda_w/dun00_eng.mes (no language in its name) | noda_w.dun00_eng |
A message file inside a pack (.pak, .pac) is the pack's path and the entry's name, as in the last rows. The "language" is the last number of a file's name (_0 to _6) or a menu folder named a_xxx/.
options.; see "The port's own text" below.\n is a line break and {{ is a {. What is not a letter, a space or a line break is a control code, written in braces by its name (below). The game stores them as numbers; a number in braces, {-253}, is the same code and is read too, but the export always writes the name.| Written | Is |
|---|---|
{page} | wait for a button, then the next page |
{wait 12} | pause for 12 more frames before the next letter |
{white} {yellow} {cyan} {green} {dark} {gold} {grey} {highlight} | switch the text colour; {/color} goes back to the window's own. {color 9} is a colour with no name |
{value} {value1} ... {value8} | a number the game puts in (a price, a damage, an amount) |
{name1} ... {name6} | a character's name |
{insert1} ... {insert10} | a message the game picks while it runs (an item or place name) |
{gap 8} {spacing 10} {justify 3} | width of a gap, of the spaces, and the justified area, in the units the game uses |
{bubble 5} | the shape of the speech bubble |
{select} {start} {L1} {R1} {L2} {R2} {circle} {triangle} {cross} {square} | the pad's buttons |
{dpad} {dpad-updown} {dpad-sides} {up} {right} {down} {left} | the d-pad and arrows |
{heart} {note} {alert} {hand} {bait} {monster} {word-button} {red-x} {red-slash} {yellow-arrow} {orange-arrow} | other symbols the game draws as one character |
{icon-sword} {icon-orb} {icon-georama} {icon-jar} | the item-kind pictures |
{icon 32} | a symbol with no name |
Names are not case sensitive. A name the game has no code for is read as the text it is, and a code that is in none of these tables (there are none in the PAL text) is written as its number. Keep the codes in a translation as the English has them; where a word is moved, its code moves with it. Every code the PAL languages' text uses is in the table: no number is left in the English, French, German, Italian or Spanish export.
The Options screen is the port's, not the disc's, so its words are not in the disc's message files. They are in the language files too, under keys the code derives from each setting, so a new row gets its keys without any other change:
| Key | Is |
|---|---|
options.page.game (display, audio, controls, text...) | a page's name |
options.<setting>.label | the row's name; <setting> is the name in config.json, game.map, video.aspect... |
options.<setting>.help | the help window's text for a setting the port describes itself |
options.<setting>.choice.<n> | the n-th choice of the setting, counting from 0 (On, Off...) |
options.<setting>.value.<English> | a value the row works out itself, by its English (Desktop, Unlimited) |
options.shortcuts, options.help.*, options.display.* | the hints at the bottom and the warning texts |
A text may hold %1, %2... where the program puts a number or a name, and the pad's button glyphs as their codes ({square}, {triangle}, {circle}, {cross}, {L1}, {R1}); keep both as the English has them. Help windows hold four lines of about 22 characters, and a label about 20; a longer one runs past its window.
The settings the game describes itself (the help for Message Speed, Clock...) are the disc's messages and come from the disc's language files as before.
port/lang/ ships these strings in French, German, Italian and Spanish; the build copies it to lang/ beside the executable, where the game reads it, so they need no export. English is in the code, and is what shows where a language has no text for a key. The export lists every one of them with the text the language would show now, so a translator starts from the shipped text. A translation written in <save>/lang/ takes the place of the shipped one, key by key. The translations are first drafts: a native speaker should look at them.
The language screen at the start of the game sets the language, as retail does. To skip it, and to change the language at any time, set it in config.json or on the Options screen (Text page, Language row):
ask (the default) shows the language screen; english, francais, deutsch, italiano and espanol start in that language without asking, going straight to the attract movie where the language screen would have led. Changing the row on the Options screen switches the game to that language once the Options screen closes: the town or title it is in is loaded again, so every message, menu and image is the new language. A dungeon floor is not restarted for it; the language takes hold when the next area loads. ask leaves the current language alone.
Translator exports are generated on demand. Normal game startup does not create or regenerate <save>/lang-export/. Generate the files with:
This writes one flat file per language into <folder>, from every message file under the data folder (loose .mes files and the .mes entries of .pak and .pac packs; 855 files on the PAL disc):
| File | Holds |
|---|---|
en_gb.json, fr_fr.json, de_de.json, it_it.json, es_es.json, en_us.json, ja_jp.json | the messages of that language's files, all keyed as above |
hashes/<language>.json | the same keys, each with the hash of the message's text, for patches |
A file that names no language and is not Japanese (noda_w/dun00_eng.mes) is in every language's file. The menu packs left in commenu/ that are Japanese go to ja_jp.json. Where a file's path names its language it wins over one that does not. Two files of one language that come to the same key are told on stderr (there are none on the PAL disc).
The export checks as it goes that every message encodes back to the disc's own codes, and prints how many files do not (none, on the PAL disc). Messages that have no end code in the disc's file (one unused id in allmenu.mes) are left out.
The export is the disc's own text. It is the user's data and must not be committed or shared: /lang-export/ is in .gitignore, and anything you put in a lang/ folder next to a build you distribute should be your own text, not an export.
<save>/lang/ (fr_fr.json...).{code} and line break the disc's text has unless you know what it does.localize: lines (overlong texts, characters the font lacks).writes one CSV per language (fr_fr, de_de, it_it, es_es) with en_gb.json as the reference, one row per message that differs in a way worth looking at: missing (English has it, this language does not), extra, empty, same (the English text, often untranslated, and every message of a file that names no language), and long (more than twice or under half English's length, where a window may not fit it), and a summary.txt of the counts. The CSVs hold the disc's own text: keep them out of git.
A patch changes a message the disc has without carrying the disc's text. Patch files are patches/*.json in either lang/ folder, read in name order for every language. They are applied to the disc's text each time the file loads, so updating a patch needs no re-export:
file is the path the game loads or the message file's key.replace is a list of [find, with] pairs; every occurrence of find becomes with. A pair whose find is not in the message is skipped and reported; if none match, the patch is.text replaces the message whole. Give exactly one of replace and text.original (optional) is the hash of the disc's whole message (a 64-bit FNV-1a of the UTF-8 text, as 16 hex digits; the export lists them in hashes/). The patch applies only when it matches, so a different disc, or a message already changed, is left alone.find sees an earlier patch's result.Every file the port writes is UTF-8 without a byte-order mark, and letters are written as themselves, never as \uXXXX escapes, so Crème and Jäger-Ohrring read as they are in any editor. The port reads UTF-8 files (a BOM is not expected).
Japanese is the exception, for now. The Japanese messages are not text but numbers: each letter is the index (0 to 784) of a glyph in the game's own Japanese font, which is not Unicode, so ja_jp.json has them as {237}{9}{2}.... (These are font positions, not control codes; the control codes in Japanese text are named like any other.) Writing them as real Japanese needs a table from those indices to characters, which the port does not have yet. Until then they stay as the codes, which still round-trip exactly, and the other languages are unaffected.
The PAL font has the 88 letters, digits and marks of its gaiji.img and the accented letters ÀÁÂÄÈÉÊËÌÍÎÏÑÒÓÔÖÙÚÛÜàáâäèéêëìíîïñòóôöùúûü, œ Œ ß Ç ç ¡ ¿, and the curly quotes and dashes become the plain ones. Anything else (;, _, ~, a Cyrillic or Greek letter) is drawn as ?, and the port tells you once per file how many characters did that. The full table is in PC.md.
The game draws its text from 14x20 bitmaps, which blur when the picture is scaled up. With Chronicle Sharp in lang/ (font.ttf and font_thin.ttf, as the build puts them), the 88 letters of gaiji.img are drawn from the two fonts at the screen's own resolution, each into the cell the game cuts its letter from, and the game draws them where and as it draws its bitmaps: the windows look as they do on the disc, sharp at any size. What follows applies to a font.ttf without font_thin.ttf.
Put a TrueType file called font.ttf in a lang/ folder (the save folder's, then the executable's) and the port draws every character the font has from it instead, rasterized at the screen's own resolution, in the cell the game laid the bitmap character out in (size, colour, outline and the cursor row's flashing are the game's own). A character the font lacks, and the icons and pad buttons, still draw as bitmaps; a font that has blank placeholders for the accented letters, the cedilla, ¡, ¿, œ and Œ gets them built from its own letters and marks. The port logs font: message text from <file> when it loads one.
menu.caption.<name> string in the language's JSON (see caption_text.cpp) overrides one caption. English keeps the painted labels, including OPTION and GEORAMA PARTS. Runtime captions fit the painted labels' bounds; stayframe stays intact for Original font mode, missing fonts and the text wipe.CREDITS, see tools/font/README.md); a font you add is yours to license.Some words are not messages but textures: an area's name card (Nolun Village...), the dungeon floor labels (Floor, Limited Zone, Back) and the bosses' names. The disc has one picture of each per language. The port takes a language's pictures from
<language folder>/textures/<language>/<texture name>.png e.g. lang/textures/fr_fr/mt01.png
in the same folders as the language files (the save folder's before the executable's); <language> is the language file's stem (en_gb, fr_fr...). It looks when the game decodes a texture of that name, so the pictures follow game.language like the messages. A picture is scaled to the size of the texture it stands for; one of another shape (a 4:1 card for a 2:1 sheet) is left unused and the port says so once. If two textures of different sizes share a name, <name>_<w>x<h>.png is tried first. A texture with no picture is the disc's.
The pictures are not shipped (they are made from the disc's art). tools/textpack/build.py draws them on the player's own machine from the words in tools/textpack/strings/*.json:
python tools/textpack/build.py --originals <extracted textures> --out <save folder>/lang/textures
It erases the old lettering from the disc's own textures and draws the language's words in Chronicle Sharp (the cards squeezed, with an outline, glow and underline; the floor labels embossed). The bosses' names are a serif that is not in that font; Cinzel (tools/font/, SIL Open Font License) stands in for it. --originals is a folder of the disc's textures as PNG files named <game file with / as __>/<name>.png. Change a word in the strings file and run it again; add a language by adding its words. The Japanese pictures are not made.
Area name cards as text. The loading screen's name card can be a plate and text instead of a picture per language: python tools/textpack/build.py --originals <extracted textures> --out <save folder>/lang/textures --only plates writes, for each card, textures/plates/<card>.png (the backdrop without its lettering, the same in every language) and textures/plates/<card>.json (where the name goes, as fractions of the card, and its colours, outline, glow and underline, sampled from the disc's card). With a plate for the card and the font loaded, the port shows the plate and draws the name over it from the font at the screen's own resolution (area_card.cpp), so the lettering is sharp at any window size and a better plate (a hand-redrawn or upscaled one) improves every language at once. The names are area.<card> in the language's JSON (area.mt01...), shipped for every language. Without a plate or the font the card is the language's picture as above, or the disc's.
Shadows. The pictures carry no shadow of their own; the port casts it when it loads one, so it can be set per kind of text. In Options, Display page: Text Shadow (the message text), Symbol Shadow (the button symbols), and for the pictures Area Name Shadow, Floor Label Shadow and Boss Name Shadow (video.text_shadow, video.glyph_shadow, video.name_shadow, video.floor_shadow, video.boss_shadow in config.json; percent in steps of 5, default 50). A picture's shadow is its lettering moved down and to the right by about a tenth of the letters' height and blurred, black, at an opacity that rises quickly (50% is a solid shadow, 100% darker and a little longer, 0% none). What casts it is <name>_text.png where the language folder has one (the name cards do: their backdrop is opaque), otherwise the picture's own opacity (the floor labels and boss names are lettering on transparency). A change takes effect from the next area that loads the picture. python tools/textpack/shadow_preview.py <folder> <name> <area|floor|boss> <out.png> shows a picture at 0, 25, 50 and 100 percent.
| Pictures | Names | Strings file |
|---|---|---|
16 area name cards (+ mtNN_text.png) | mt01..mt301 | strings/titles.json |
7 dungeon floor label sheets (+ floorNN_text.png) | floor00..floor06 | strings/floors.json |
| 5 boss names | boss_1, boss_3, boss_4, boss_6, boss_7 | strings/bosses.json |
A text that does not fit is left as the disc has it, and the port says so once on stderr (localize: ...):
{value}, {name1} and {insert1} count as what they expand to);dun/script/..., gedit/..., meswin/...) is read into a buffer sized for the disc's file, rounded up to whole 2048-byte sectors. A translated file that comes to more than that keeps the disc's text for the whole file. Translate longer by shortening elsewhere in the file, or put the text in a message file the game reads out of a pack, which has no such limit.Bad JSON (not JSON, a key that is not a file key and an id, a value that is not a string) is reported once and the file is ignored; the game runs on disc text.
The JSON for the current language (the language's file, from both folders) is held parsed in memory: about 100 bytes of bookkeeping per message plus the text. A translation that changes some messages is a few hundred KB; a full export of the disc's English is about 3.5 MB. A message file taken from a pack is rebuilt once and kept (about 80 KB each, about 2 MB for every pack). Loose message files are rebuilt each time the game loads them and not kept. Reading a file costs a transient 3 to 4 times its size. With font.ttf, the glyph atlas is one 2048 x 2048 texture (16 MB of video memory), which Chronicle Sharp's letters share.
Set DC_LOCALIZE_TRACE=1 to log every message file the game loads and whether the JSON has an entry for it.
port/src/localize/localize.{hpp,cpp}: LocalizeText and LocalizeFormat give the port's own strings, LocalizeMessageKey makes a file's key, LocalizeParse reads a language's file, LocalizeMessages lays texts over a disc message file (through GameTextFile), LocalizeFile and LocalizePack are the hooks, and LocalizeExport is --export-text. The Options screen asks LocalizeText for each of its words (port/src/options/menu_option.cpp; OptionStrings() lists them for the export), and lays its text out again when it is opened in another language. The hooks sit in port/src/game/dataread.cpp: LoadFile2 and LoadFileBG pass each file they read to LocalizeLoaded and LocalizeFile, and the port's GetPackFile gives a message entry through LocalizePack. Tests: port/src/tests/localize_test.cpp.