diff options
-rw-r--r-- | scumm/object.cpp | 45 | ||||
-rw-r--r-- | scumm/script_v2.cpp | 15 | ||||
-rw-r--r-- | scumm/script_v5.cpp | 68 | ||||
-rw-r--r-- | scumm/scumm.h | 2 | ||||
-rw-r--r-- | scumm/string.cpp | 2 |
5 files changed, 73 insertions, 59 deletions
diff --git a/scumm/object.cpp b/scumm/object.cpp index ecb856d6da..22eddff1b3 100644 --- a/scumm/object.cpp +++ b/scumm/object.cpp @@ -881,7 +881,7 @@ void Scumm::clearDrawObjectQueue() { _drawObjectQueNr = 0; } -byte *Scumm::getObjOrActorName(int obj) { +const byte *Scumm::getObjOrActorName(int obj) { byte *objptr; int i; @@ -915,50 +915,7 @@ byte *Scumm::getObjOrActorName(int obj) { return (objptr + offset); } -#if 0 return findResourceData(MKID('OBNA'), objptr); -#else - // FIXME: we can't use findResourceData anymore, because it returns const - // data, while this function *must* return a non-const pointer. That is so - // because in o2_setObjectName / o5_setObjectName we directly modify this - // data. Now, we could add a non-const version of findResourceData, too - // (C++ makes that easy); but this here is really the *only* place in all - // of ScummVM where it wold be needed! That seems kind of a waste... - // - // So for now, I duplicate some code from findResourceData / findResource - // here. However, a much nicer solution might be (with stress on "might") - // to use the same technique as in V6 games: that is, use a seperate - // resource for changed names. That would be the cleanest solution, but - // might proof to be infeasible, as it might lead to unforseen regressions. - - uint32 tag = MKID('OBNA'); - byte *searchin = objptr; - uint32 curpos, totalsize, size; - - assert(searchin); - - searchin += 4; - totalsize = READ_BE_UINT32_UNALIGNED(searchin); - curpos = 8; - searchin += 4; - - while (curpos < totalsize) { - if (READ_UINT32_UNALIGNED(searchin) == tag) - return searchin + _resourceHeaderSize; - - size = READ_BE_UINT32_UNALIGNED(searchin + 4); - if ((int32)size <= 0) { - error("(%c%c%c%c) Not found in %d... illegal block len %d", - tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF, 0, size); - return NULL; - } - - curpos += size; - searchin += size; - } - - return NULL; -#endif } uint32 Scumm::getOBCDOffs(int object) { diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp index 023ed904a9..9990c95ec2 100644 --- a/scumm/script_v2.cpp +++ b/scumm/script_v2.cpp @@ -1316,9 +1316,18 @@ void Scumm_v2::o2_setObjectName() { if (obj < _numActors) error("Can't set actor %d name with new-name-of", obj); - name = getObjOrActorName(obj); - if (name == NULL) - return; // Silently abort + // TODO: Would be nice if we used rtObjectName resource for pre-V6 + // games, too. The only problem with that which I can see is that this + // would break savegames. I.e. it would require yet another change to + // the save/load system. + + // FIXME: This is rather nasty code. + // Find the object name in the OBCD resource. + byte *objptr; + objptr = getOBCDFromObject(obj); + if (objptr == NULL) + return; // Silently fail for now + name = objptr + *(objptr + 14); while(name[size++]) ; diff --git a/scumm/script_v5.cpp b/scumm/script_v5.cpp index e1901b5991..9ce58b2309 100644 --- a/scumm/script_v5.cpp +++ b/scumm/script_v5.cpp @@ -1879,33 +1879,81 @@ void Scumm_v5::o5_setObjectName() { if (obj < _numActors) error("Can't set actor %d name with new-name-of", obj); - if (!getOBCDFromObject(obj)) { + // TODO: Would be nice if we used rtObjectName resource for pre-V6 + // games, too. The only problem with that which I can see is that this + // would break savegames. I.e. it would require yet another change to + // the save/load system. + + byte *objptr; + objptr = getOBCDFromObject(obj); + if (objptr == NULL) { // FIXME: Bug 587553. This is an odd one and looks more like // an actual bug in the original script. Usually we would error warning("Can't find OBCD to rename object %d to %s", obj, work); return; } - name = getObjOrActorName(obj); - if (name == NULL) - return; // Silently abort - if (_features & GF_SMALL_HEADER) { - // FIXME this is hack to make MonkeyVGA work. needed at least for the german - // version but possibly for others as well. There is no apparent other - // way to determine the available space that works in all cases... - byte *objptr; byte offset = 0; - objptr = getOBCDFromObject(obj); if (_features & GF_OLD_BUNDLE) offset = *(objptr + 16); else offset = READ_LE_UINT16(objptr + 18); + size = READ_LE_UINT16(objptr) - offset; + name = objptr + offset; } else { + name = 0; +#if 0 + name = findResourceData(MKID('OBNA'), objptr); +#else + // FIXME: we can't use findResourceData anymore, because it returns const + // data, while this function *must* return a non-const pointer. That is so + // because in o2_setObjectName / o5_setObjectName we directly modify this + // data. Now, we could add a non-const version of findResourceData, too + // (C++ makes that easy); but this here is really the *only* place in all + // of ScummVM where it wold be needed! That seems kind of a waste... + // + // So for now, I duplicate some code from findResourceData / findResource + // here. However, a much nicer solution might be (with stress on "might") + // to use the same technique as in V6 games: that is, use a seperate + // resource for changed names. That would be the cleanest solution, but + // might proof to be infeasible, as it might lead to unforseen regressions. + + uint32 tag = MKID('OBNA'); + byte *searchin = objptr; + uint32 curpos, totalsize; + + assert(searchin); + + searchin += 4; + totalsize = READ_BE_UINT32_UNALIGNED(searchin); + curpos = 8; + searchin += 4; + + while (curpos < totalsize) { + if (READ_UINT32_UNALIGNED(searchin) == tag) { + name = searchin + _resourceHeaderSize; + break; + } + + size = READ_BE_UINT32_UNALIGNED(searchin + 4); + if ((int32)size <= 0) { + error("(%c%c%c%c) Not found in %d... illegal block len %d", + tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF, 0, size); + } + + curpos += size; + searchin += size; + } +#endif size = getResourceDataSize(name); } + + if (name == 0) + return; // Silently bail out + if (i >= size) { warning("New name of object %d too long (old *%s* new *%s*)", obj, name, work); diff --git a/scumm/scumm.h b/scumm/scumm.h index e747ca1b13..c439cc44db 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -683,7 +683,7 @@ public: int getObjectOrActorXY(int object, int &x, int &y); // Used in actor.cpp, hence public protected: int getObjActToObjActDist(int a, int b); // Not sure how to handle - byte *getObjOrActorName(int obj); // these three.. + const byte *getObjOrActorName(int obj); // these three.. void addObjectToDrawQue(int object); void clearDrawObjectQueue(); diff --git a/scumm/string.cpp b/scumm/string.cpp index f00835d6e4..b96eaec65b 100644 --- a/scumm/string.cpp +++ b/scumm/string.cpp @@ -675,7 +675,7 @@ void Scumm::addVerbToStack(int var) void Scumm::addNameToStack(int var) { int num; - byte *ptr = 0; + const byte *ptr = 0; num = readVar(var); if (num) |