Skip to content

Commit

Permalink
GRIM: Support transcoding Monkey4 from Traditional to Simplified Chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
phcoder committed Sep 12, 2024
1 parent fcf0ac3 commit d20df79
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions engines/grim/detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ class GrimMetaEngineDetection : public AdvancedMetaEngineDetection<Grim::GrimGam
public:
GrimMetaEngineDetection() : AdvancedMetaEngineDetection(Grim::gameDescriptions, grimGames) {
_guiOptions = GUIO_NOMIDI;
_flags |= kADFlagCanTranscodeTraditionalChineseToSimplified;
}

PlainGameDescriptor findGame(const char *gameid) const override {
Expand Down Expand Up @@ -729,6 +730,17 @@ class GrimMetaEngineDetection : public AdvancedMetaEngineDetection<Grim::GrimGam
return debugFlagList;
}

DetectedGame toDetectedGame(const ADDetectedGame &adGame, ADDetectedGameExtraInfo *extraInfo) const override {
DetectedGame game = AdvancedMetaEngineDetection::toDetectedGame(adGame, extraInfo);
GrimGameType gameID = reinterpret_cast<const GrimGameDescription *>(adGame.desc)->gameType;

if (gameID == GType_MONKEY4 && adGame.desc->language == Common::Language::ZH_TWN) {
game.appendGUIOptions(Common::getGameGUIOptionsDescriptionLanguage(Common::ZH_TWN));
game.appendGUIOptions(Common::getGameGUIOptionsDescriptionLanguage(Common::ZH_CHN));
}

return game;
}
};

} // End of namespace Grim
Expand Down
16 changes: 12 additions & 4 deletions engines/grim/grim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,19 @@ Common::Error GrimEngine::run() {
}

if (getGameType() == GType_MONKEY4 && getGameLanguage() == Common::Language::ZH_TWN) {
Common::File img, imgmap;
if (img.open("font.tga") && imgmap.open("map.bin")) {
BitmapFont *f = new BitmapFont();
f->loadTGA("font.tga", &imgmap, &img);
_transcodeChineseToSimplified = ConfMan.hasKey("language") && (Common::parseLanguage(ConfMan.get("language")) == Common::Language::ZH_CHN);

if (_transcodeChineseToSimplified) {
FontTTF *f = new FontTTF();
f->loadTTFFromArchive("NotoSansSC-Regular.otf", 1200);
_overrideFont = f;
} else {
Common::File img, imgmap;
if (img.open("font.tga") && imgmap.open("map.bin")) {
BitmapFont *f = new BitmapFont();
f->loadTGA("font.tga", &imgmap, &img);
_overrideFont = f;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions engines/grim/grim.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class GrimEngine : public Engine {
int _cursorX = 0;
int _cursorY = 0;
bool _isUtf8 = false;
bool _transcodeChineseToSimplified = false;
Font *_overrideFont = nullptr;
};

Expand Down
5 changes: 5 additions & 0 deletions engines/grim/localize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ Localizer::Localizer() {
_entries[last_entry = Common::String(line, tab - line)] = Common::String(tab + 1, (nextline - tab - 2));
}
}
if (g_grim->_transcodeChineseToSimplified && g_grim->_isUtf8) {
for (Common::StringMap::iterator it = _entries.begin(); it != _entries.end(); it++) {
it->_value = it->_value.decode(Common::CodePage::kUtf8).transcodeChineseT2S().encode(Common::CodePage::kUtf8);
}
}
delete[] data;
}

Expand Down

0 comments on commit d20df79

Please sign in to comment.