From 53380a2cbf374f2073fad7134c99ac4f50811979 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Tue, 1 Sep 2009 02:50:40 +0000 Subject: SCI: Fix bug in SCI1.1 varselector search. svn-id: r43872 --- engines/sci/engine/vm.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 8e09e56a68..05b9c96c08 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1402,34 +1402,26 @@ static int _obj_locate_varselector(SegManager *segManager, Object *obj, Selector // Determines if obj explicitly defines slc as a varselector // Returns -1 if not found SciVersion version = segManager->sciVersion(); // for the selector defines + byte *buf; + uint varnum; if (version < SCI_VERSION_1_1) { - int varnum = obj->variable_names_nr; + varnum = obj->variable_names_nr; int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET; - int i; - byte *buf = obj->base_obj + selector_name_offset; - - obj->base_vars = (uint16 *) buf; - - for (i = 0; i < varnum; i++) - if (READ_LE_UINT16(buf + (i << 1)) == slc) // Found it? - return i; // report success - - return -1; // Failed + buf = obj->base_obj + selector_name_offset; } else { - byte *buf = (byte *) obj->base_vars; - int i; - int varnum = obj->_variables[1].offset; - if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) - buf = ((byte *) obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR])->base_vars); - - for (i = 0; i < varnum; i++) - if (READ_LE_UINT16(buf + (i << 1)) == slc) // Found it? - return i; // report success + obj = obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); - return -1; // Failed + buf = (byte *)obj->base_vars; + varnum = obj->_variables[1].toUint16(); } + + for (uint i = 0; i < varnum; i++) + if (READ_LE_UINT16(buf + (i << 1)) == slc) // Found it? + return i; // report success + + return -1; // Failed } static int _class_locate_funcselector(Object *obj, Selector slc, SciVersion version) { -- cgit v1.2.3