Files
DC_Recomp/tests/dc_language_tests.cpp
Thomas MartinandClaude Opus 5.5 95903df0c9 Add a game language setting: French, German, Italian
The USA disc also carries the European release's translations of the
text (message files <name>_<n>.mes) and menus (commenu/a_fre, a_ger,
a_ita), and the program still picks them by LanguageCode (0x2A1E88,
1 on the USA disc). The port sets it before the first frame from
--language en|fr|de|it or <user folder>/game.ini, which the launcher's
Settings -> Game language and RecompLauncher's Language write.

Spanish is not offered: the USA disc lacks 42 of its 90 story text
files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 13:32:55 +01:00

57 lines
2.1 KiB
C++

// The game's language setting (dc_language.h): the choices, game.ini's reading and LanguageCode in guest memory.
#include "dc_language.h"
#include <cstdio>
#include <cstring>
#include <fstream>
#include <vector>
namespace
{
int failures = 0;
void check(bool ok, const char *what)
{
if (!ok)
{
++failures;
std::printf("FAIL: %s\n", what);
}
}
std::string iniWith(const std::filesystem::path &file, const char *text)
{
std::ofstream(file, std::ios::binary | std::ios::trunc) << text;
return dc::language::readIni(file);
}
}
int main(int, char **argv)
{
using namespace dc::language;
check(choices().size() == 4, "four languages");
check(find("en") && find("en")->code == 1, "English is the USA disc's own code 1");
check(find("fr") && find("fr")->code == 3, "French 3");
check(find("DE") && find("DE")->code == 4, "German 4, any case");
check(find("it") && find("it")->code == 5, "Italian 5");
check(!find("es") && !find("") && !find("jp") && !find("english"), "Spanish and anything else refused");
const auto file = std::filesystem::path(argv[0]).parent_path() / "dc_language_test.ini";
check(iniWith(file, "# Dark Cloud\n[game]\nlanguage = fr\n") == "fr", "section and comment skipped");
check(iniWith(file, "[game]\r\n language=it ; Italiano\r\n") == "it", "CRLF, spaces and a trailing comment");
check(iniWith(file, "[game]\nlanguages = de\nlang = de\n") == "", "only the language key");
check(iniWith(file, "# language = de\n") == "", "a commented line");
std::filesystem::remove(file);
check(readIni(file) == "", "no file");
std::vector<uint8_t> ram(32u << 20, 0);
const uint32_t usa = 1;
std::memcpy(ram.data() + kLanguageCode, &usa, 4);
apply(ram.data(), *find("de"));
uint32_t code = 0;
std::memcpy(&code, ram.data() + kLanguageCode, 4);
check(code == 4, "LanguageCode written");
check(ram[kLanguageCode - 1] == 0 && ram[kLanguageCode + 4] == 0, "nothing around it");
std::printf("%s (%d failures)\n", failures ? "FAILED" : "dc_language: all checks passed", failures);
return failures ? 1 : 0;
}