Skip to content

String Replacement

mzzvxm edited this page Nov 28, 2026 · 2 revisions

String Replacement

Dump the text of the game's string tables to TOML and replace it with your own, for translations or text mods. Source: src/mc_engine/core/string_dumper.h and .cpp, src/mc_engine/menus/string_table.cpp.

Options

Option Type Default Effect
string_dump_enabled bool false Capture encountered strings to TOML. Hot reload.
string_replace_enabled bool false Inject replacement strings from disk when available. Hot reload. Turning it on also reads replace/ again.
string_folder string "" Override the strings folder. Empty means strings/ under the game data folder. Needs a restart.
string_language string "" Language code for per-language replacements, for example pt_BR or es_ES. Used when replace/ is read.

Source of all four: src/mc_engine/core/string_dumper.cpp.

Folder layout

<strings folder>/
  dump/strings.toml        what was seen
  replace/*.toml           what to show instead

Only files with the .toml extension in replace/ are read.

Dump format

Entries are appended to dump/strings.toml. A string already in the file is not written again. The file starts with a comment saying to edit strings in replace/, not in the dump.

[[strings]]
hash = "0123456789abcdef"
context = "..."
original = "..."
address = "0x82000000"

address is written only when known. The hash is FNV-1a over the context, a separator and the text, as 16 hex digits; replacements are matched by recomputing it from context and original.

Replacement format

Each file in replace/ holds a [[strings]] array. An entry needs context and original exactly as in the dump, plus one of:

# every language
[[strings]]
context = "..."
original = "Hello"
text = "Ola"

# per language, chosen by string_language
[[strings]]
context = "..."
original = "Hello"
[strings.pt_BR]
text = "Ola"

Rules from the code:

  • A plain text field applies in every language.
  • Otherwise the sub-table named after string_language is used. With string_language empty, only plain text entries load.
  • Entries without context or original are skipped.
  • A file that fails to parse is skipped with StringDumper: failed to parse <file>; other files still load.

Log lines: StringDumper: N replacement(s) indexed from <dir>, loaded N replacement(s) from <file>.

The context value

It is not a category, and there is no fixed list of values. It is mcla: followed by 8 upper-case hex digits: the hash under which the game's string table files that text. Take it from the dump. address is where the text was in the game's memory when it was dumped.

What is dumped and replaced

  • Every text of the string tables the game has loaded (ui/mc4stringtable*.strtbl, in the current language), as the table stores it. A text that is built from other texts keeps its <D>name</D> parts.
  • The !!name!! text the game shows for a name its tables lack.
  • Not the text the game writes into its own buffers while it runs (money, scores, counters, names). It is not dumped.

Rules for a replacement

  • It keeps the original's <D>...</D> parts: the same names, each as many times (letter case does not matter).
  • It keeps the original's % codes, such as %s or %d, in the same order. %% and a % followed by a space are not codes.
  • At most 1023 bytes, valid UTF-8. A letter outside ASCII takes two bytes or more.
  • A replacement of a !!name!! text is cut to 131 bytes, at a whole letter: [string-table] <context>: replacement cut to 131 bytes.
  • A text that has only a buffer size inside a <D> part, such as <D>128</D>, is never dumped or replaced.

A replacement that breaks a rule is not used: [string-table] <context>: replacement refused: <reason>.

When changes take effect

  • replace/ is read when the dumper starts, and again each time string_replace_enabled goes from off to on. After editing a file or changing string_language, turn it off and on.
  • Replacements go in when the game loads its string tables (at start and at every language change) and when replacement is turned on. Turning it off puts the game's text back.
  • While the game runs, a text that is part of another one or is built from others is not made longer than it is, and neither is a text past what a buffer the game already holds for it takes. Such a replacement waits for the next language change or the next start: [string-table] <context>: waits for the next language change (the game sized a buffer for the current text). The same holds when turning replacement off puts a longer original back.
  • Dumps written by earlier builds also hold texts that are no longer dumped (built texts with their parts filled in, and run-time values). Entries for those in replace/ match nothing.
  • Turning replacement off and on while the game runs has not been checked in game yet.

Source: src/mc_engine/menus/string_table.cpp, src/mc_engine/core/string_dumper.cpp.

Clone this wiki locally