From cec2799c64d996dba247669c6eedfbffacc5f384 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 3 Oct 2016 05:29:58 +0300 Subject: CHEWY: Properly handle the text encryption in atds.tap (game texts) --- engines/chewy/resource.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'engines/chewy/resource.cpp') diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp index 90849cd555..352e2f11d7 100644 --- a/engines/chewy/resource.cpp +++ b/engines/chewy/resource.cpp @@ -41,9 +41,9 @@ namespace Chewy { // misc/inventar.iib // misc/inventar.sib // room/test.rdi -// txt/*.tap +// txt/atds.tap (game texts) // txt/diah.adh -// txt/inv_st.s and txt/room_st.s +// txt/inv_st.s and txt/room_st.s (inventory/room control bytes) // txt/inv_use.idx Resource::Resource(Common::String filename) { @@ -52,6 +52,7 @@ Resource::Resource(Common::String filename) { const uint32 headerTxtEnc = MKTAG('T', 'C', 'F', '\1'); const uint32 headerSprite = MKTAG('T', 'A', 'F', '\0'); + filename.toLowercase(); _stream.open(filename); uint32 header = _stream.readUint32BE(); @@ -72,6 +73,9 @@ Resource::Resource(Common::String filename) { _encrypted = false; } + if (filename == "atds.tap") + _encrypted = true; + _chunkCount = _stream.readUint16LE(); for (uint i = 0; i < _chunkCount; i++) { @@ -113,6 +117,8 @@ byte *Resource::getChunkData(uint num) { _stream.seek(chunk->pos, SEEK_SET); _stream.read(data, chunk->size); + if (_encrypted) + decrypt(data, chunk->size); return data; } @@ -170,6 +176,15 @@ void Resource::unpackRLE(byte *buffer, uint32 compressedSize, uint32 uncompresse } } +void Resource::decrypt(byte *data, uint32 size) { + byte *c = data; + + for (uint i = 0; i < size; i++) { + *c = -(*c); + ++c; + } +} + TAFChunk *SpriteResource::getSprite(uint num) { assert(num < _chunkList.size()); @@ -276,17 +291,9 @@ Common::String ErrorMessage::getErrorMessage(uint num) { byte *data = new byte[chunk->size]; _stream.seek(chunk->pos, SEEK_SET); - _stream.read(data, chunk->size); - - if (_encrypted) { - byte *c = data; - - for (uint i = 0; i < chunk->size; i++) { - *c = -(*c); - ++c; - } - } + if (_encrypted) + decrypt(data, chunk->size); str = (char *)data; delete[] data; -- cgit v1.2.3