mirror of
https://github.com/TheBozos/DC_Recomp.git
synced 2026-12-01 07:38:29 -10:00
A Language entry in the game's own Options (between Travel and Quit Game): English, Francais, Deutsch, Italiano, the one in use and the one saved for the next start marked. Cross writes game.ini (as the launcher does); the running game keeps its language until it starts again, since part of its text is loaded once at boot. Without the game window (headless) the page only says it needs it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
#include "dc_language.h"
|
|
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <cstring>
|
|
#include <fstream>
|
|
|
|
namespace dc::language
|
|
{
|
|
const std::vector<Choice> &choices()
|
|
{
|
|
static const std::vector<Choice> list = {
|
|
{"en", "English", 1}, {"fr", "Fran\xC3\xA7" "ais", 3}, {"de", "Deutsch", 4}, {"it", "Italiano", 5}};
|
|
return list;
|
|
}
|
|
|
|
const Choice *find(const std::string &key)
|
|
{
|
|
std::string k = key;
|
|
std::transform(k.begin(), k.end(), k.begin(), [](unsigned char c) { return char(std::tolower(c)); });
|
|
for (const Choice &c : choices())
|
|
if (k == c.key)
|
|
return &c;
|
|
return nullptr;
|
|
}
|
|
|
|
std::string readIni(const std::filesystem::path &file)
|
|
{
|
|
std::ifstream in(file);
|
|
std::string line, value;
|
|
auto trim = [](std::string s)
|
|
{
|
|
const size_t first = s.find_first_not_of(" \t\r");
|
|
return first == std::string::npos ? std::string() : s.substr(first, s.find_last_not_of(" \t\r") - first + 1);
|
|
};
|
|
while (std::getline(in, line))
|
|
{
|
|
line = trim(line.substr(0, line.find_first_of("#;")));
|
|
const size_t equal = line.find('=');
|
|
if (line.empty() || line.front() == '[' || equal == std::string::npos)
|
|
continue;
|
|
if (trim(line.substr(0, equal)) == "language")
|
|
value = trim(line.substr(equal + 1));
|
|
}
|
|
return value;
|
|
}
|
|
|
|
bool writeIni(const std::filesystem::path &file, const Choice &choice)
|
|
{
|
|
const std::filesystem::path tmp = file.string() + ".tmp";
|
|
{
|
|
std::ofstream out(tmp, std::ios::binary | std::ios::trunc);
|
|
out << "# Dark Cloud's own settings (the launcher and RecompLauncher write this file; the game reads it when it starts).\n"
|
|
"# language: en (English), fr (French), de (German) or it (Italian), from the disc's own text and menus.\n"
|
|
"\n[game]\nlanguage = "
|
|
<< choice.key << "\n";
|
|
if (!out)
|
|
return false;
|
|
}
|
|
std::error_code ec;
|
|
std::filesystem::rename(tmp, file, ec);
|
|
return !ec;
|
|
}
|
|
|
|
const Choice *current(const uint8_t *ram)
|
|
{
|
|
uint32_t code = 0;
|
|
std::memcpy(&code, ram + kLanguageCode, sizeof(code));
|
|
for (const Choice &c : choices())
|
|
if (c.code == code)
|
|
return &c;
|
|
return nullptr;
|
|
}
|
|
|
|
void apply(uint8_t *ram, const Choice &choice)
|
|
{
|
|
std::memcpy(ram + kLanguageCode, &choice.code, sizeof(choice.code));
|
|
}
|
|
} // namespace dc::language
|