From 4be2788ffd8b9e8ec8a2ba6080bcd7701bd6c08a Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Wed, 23 Dec 2009 05:10:16 +0000 Subject: [PATCH] Some SCI32 (minor) String bug fixes and cleanup. svn-id: r46492 --- engines/sci/engine/kernel32.cpp | 29 ++++++++++++----------------- engines/sci/engine/message.cpp | 9 +++------ engines/sci/engine/segment.cpp | 2 +- engines/sci/engine/segment.h | 4 +--- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp index 9e07dacbc0f..cde3c261543 100644 --- a/engines/sci/engine/kernel32.cpp +++ b/engines/sci/engine/kernel32.cpp @@ -455,6 +455,11 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { SciString *string = s->_segMan->allocateString(&stringHandle); string->setType(3); string->setSize(argv[1].toUint16()); + + // Make sure the first character is a null character + if (string->getSize() > 0) + string->setValue(0, 0); + return stringHandle; } case 1: // Size @@ -512,23 +517,16 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { if (string1->getSize() < index1 + count) string1->setSize(index1 + count); + // Note: We're accessing from c_str() here because the string's size ignores + // the trailing 0 and therefore triggers an assert when doing string2[i + index2]. for (uint16 i = 0; i < count; i++) - string1->setValue(i + index1, string2[i + index2]); + string1->setValue(i + index1, string2.c_str()[i + index2]); return argv[1]; } case 7: { // Cmp - Common::String string1, string2; - - if (argv[1].isNull()) - string1 = ""; - else - string1 = s->_segMan->lookupString(argv[1])->toString(); - - if (argv[2].isNull()) - string2 = ""; - else - string2 = s->_segMan->lookupString(argv[2])->toString(); + Common::String string1 = argv[1].isNull() ? "" : s->_segMan->getString(argv[1]); + Common::String string2 = argv[2].isNull() ? "" : s->_segMan->getString(argv[2]); if (argc == 4) // Strncmp return make_reg(0, strncmp(string1.c_str(), string2.c_str(), argv[3].toUint16())); @@ -547,11 +545,8 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { return argv[1]; return GET_SEL32(s->_segMan, argv[1], data); - case 10: { // Stringlen - SciString *sciString = s->_segMan->lookupString(argv[1]); - Common::String string = sciString->toString(); - return make_reg(0, string.size()); - } + case 10: // Stringlen + return make_reg(0, s->_segMan->strlen(argv[1])); case 11: // Printf // TODO: Return a new formatting string warning("kString(Printf)"); diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index 870341b7dab..39c2eb326be 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -153,14 +153,11 @@ bool MessageState::getRecord(CursorStack &stack, bool recurse, MessageRecord &re reader = new MessageReaderV3(res->data, res->size); break; case 4: +#ifdef ENABLE_SCI32 + case 5: // v5 seems to be compatible with v4 +#endif reader = new MessageReaderV4(res->data, res->size); break; -#ifdef ENABLE_SCI32 - case 5: - // TODO: Decode this version's format... It's at least used in Torin. - warning("The SCI 2.1 message format is not supported"); - return false; -#endif default: warning("Message: unsupported resource version %d", version); return false; diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index e8b47727ba4..9f934a3f1dd 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -512,7 +512,7 @@ void SciString::fromString(Common::String string) { SegmentRef StringTable::dereference(reg_t pointer) { SegmentRef ret; - ret.isRaw = false; + ret.isRaw = true; ret.maxSize = _table[pointer.offset].getSize(); ret.raw = (byte*)_table[pointer.offset].getRawData(); return ret; diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index a6ffeb773ad..44aff9d41c4 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -706,6 +706,7 @@ public: // Check if we never created an array before if (!_data) { + _size = _actualSize = size; _data = newArray; return; } @@ -736,9 +737,6 @@ public: byte getType() { return _type; } uint32 getSize() { return _size; } T *getRawData() { return _data; } - - //Common::String toString(); - //void fromString(Common::String string); protected: int8 _type;