aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/engine/kernel32.cpp29
-rw-r--r--engines/sci/engine/message.cpp9
-rw-r--r--engines/sci/engine/segment.cpp2
-rw-r--r--engines/sci/engine/segment.h4
4 files changed, 17 insertions, 27 deletions
diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp
index 9e07dacbc0..cde3c26154 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 870341b7da..39c2eb326b 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:
- 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;
+ case 5: // v5 seems to be compatible with v4
#endif
+ reader = new MessageReaderV4(res->data, res->size);
+ break;
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 e8b47727ba..9f934a3f1d 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 a6ffeb773a..44aff9d41c 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;