From b812ed50c8f6d9a24b607831a88a398730458d9a Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 11 Jun 2012 11:51:54 +0300 Subject: SCI: Bugfix for negative numbers in kString(at) Fixes one of the bugs in the savegame selection screen in Phantasmagoria --- engines/sci/engine/kstring.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'engines/sci/engine/kstring.cpp') diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index fe8d631497..0877e37a65 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -653,10 +653,18 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { case 1: // Size return make_reg(0, s->_segMan->getString(argv[1]).size()); case 2: { // At (return value at an index) - if (argv[1].segment == s->_segMan->getStringSegmentId()) - return make_reg(0, s->_segMan->lookupString(argv[1])->getRawData()[argv[2].toUint16()]); - - return make_reg(0, s->_segMan->getString(argv[1])[argv[2].toUint16()]); + // Note that values need to be truncated to bytes, otherwise + // 0xff (negative char -1) will incorrectly be changed to + // 0xffff (negative int16 -1) + if (argv[1].segment == s->_segMan->getStringSegmentId()) { + SciString *string = s->_segMan->lookupString(argv[1]); + byte val = string->getRawData()[argv[2].toUint16()]; + return make_reg(0, val); + } else { + Common::String string = s->_segMan->getString(argv[1]); + byte val = string[argv[2].toUint16()]; + return make_reg(0, val); + } } case 3: { // Atput (put value at an index) SciString *string = s->_segMan->lookupString(argv[1]); -- cgit v1.2.3