Skip to content

Commit

Permalink
SCUMM: Fix encoding for Hebrew dialogs
Browse files Browse the repository at this point in the history
Like Pause dialog.
  • Loading branch information
orgads committed Jul 21, 2021
1 parent 1ffa77c commit 6611307
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
14 changes: 4 additions & 10 deletions engines/scumm/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ void InfoDialog::reflowLayout() {

const Common::U32String InfoDialog::queryResString(int stringno) {
byte buf[256];
byte reverseBuf[256];
const byte *result;

if (stringno == 0)
Expand Down Expand Up @@ -457,6 +458,8 @@ const Common::U32String InfoDialog::queryResString(int stringno) {
return _(string_map_table_v345[stringno - 1].string);
}

if (_vm->reverseIfNeeded(result, reverseBuf))
result = reverseBuf;
// Convert to a proper string (take care of FF codes)
byte chr;
String tmp;
Expand All @@ -468,16 +471,7 @@ const Common::U32String InfoDialog::queryResString(int stringno) {
}
}

Common::CodePage convertFromCodePage = Common::kCodePageInvalid;
if (_vm->_language == Common::KO_KOR)
convertFromCodePage = Common::kWindows949;
else if (_vm->_language == Common::JA_JPN)
convertFromCodePage = Common::kWindows932;
else if (_vm->_language == Common::ZH_TWN || _vm->_language == Common::ZH_CNA)
convertFromCodePage = Common::kWindows950;
else if (_vm->_language == Common::RU_RUS)
convertFromCodePage = Common::kDos866;

const Common::CodePage convertFromCodePage = _vm->getDialogCodePage();
return convertFromCodePage == Common::kCodePageInvalid ? _(tmp) : U32String(tmp, convertFromCodePage);
}

Expand Down
6 changes: 5 additions & 1 deletion engines/scumm/scumm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ class ScummEngine : public Engine, public Common::Serializable {
virtual void CHARSET_1();
bool newLine();
void drawString(int a, const byte *msg);
void fakeBidiString(byte *ltext, bool ignoreVerb);
void fakeBidiString(byte *ltext, bool ignoreVerb) const;
void debugMessage(const byte *msg);
void showMessageDialog(const byte *msg);

Expand All @@ -1150,6 +1150,10 @@ class ScummEngine : public Engine, public Common::Serializable {

// Used by class ScummDialog:
virtual void translateText(const byte *text, byte *trans_buff);
// Old Hebrew games require reversing the dialog text.
bool reverseIfNeeded(const byte *text, byte *reverseBuf) const;
// Returns codepage that matches the game for languages that require it.
Common::CodePage getDialogCodePage() const;

// Somewhat hackish stuff for 2 byte support (Chinese/Japanese/Korean)
bool _useCJKMode;
Expand Down
36 changes: 35 additions & 1 deletion engines/scumm/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ bool ScummEngine::newLine() {
return true;
}

void ScummEngine::fakeBidiString(byte *ltext, bool ignoreVerb) {
void ScummEngine::fakeBidiString(byte *ltext, bool ignoreVerb) const {
// Provides custom made BiDi mechanism.
// Reverses texts on each line marked by control characters (considering different control characters used in verbs panel)
// While preserving original order of numbers (also negative numbers and comma separated)
Expand Down Expand Up @@ -2075,4 +2075,38 @@ void ScummEngine::translateText(const byte *text, byte *trans_buff) {
memcpy(trans_buff, text, resStrLen(text) + 1);
}

bool ScummEngine::reverseIfNeeded(const byte *text, byte *reverseBuf) const {
if (_language != Common::HE_ISR)
return false;
if (_game.id != GID_LOOM && _game.id != GID_ZAK)
return false;
strcpy(reinterpret_cast<char *>(reverseBuf), reinterpret_cast<const char *>(text));
fakeBidiString(reverseBuf, true);
return true;
}

Common::CodePage ScummEngine::getDialogCodePage() const {
switch (_language) {
case Common::KO_KOR:
return Common::kWindows949;
case Common::JA_JPN:
return Common::kWindows932;
case Common::ZH_TWN:
case Common::ZH_CNA:
return Common::kWindows950;
case Common::RU_RUS:
return Common::kDos866;
case Common::HE_ISR:
switch (_game.id) {
case GID_LOOM:
case GID_ZAK:
return Common::kDos862;
default:
return Common::kWindows1255;
}
default:
return Common::kCodePageInvalid;
}
}

} // End of namespace Scumm

0 comments on commit 6611307

Please sign in to comment.