[Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.154,2.155 object.cpp,1.170,1.171 resource.cpp,1.193,1.194 resource_v2.cpp,1.39,1.40 resource_v3.cpp,1.25,1.26 saveload.cpp,1.147,1.148 script_v2.cpp,2.243,2.244 script_v5.cpp,1.232,1.233 script_v6.cpp,1.321,1.322 scumm.h,1.383,1.384

Max Horn fingolfin at users.sourceforge.net
Tue Mar 16 18:00:13 CET 2004


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8288

Modified Files:
	intern.h object.cpp resource.cpp resource_v2.cpp 
	resource_v3.cpp saveload.cpp script_v2.cpp script_v5.cpp 
	script_v6.cpp scumm.h 
Log Message:
Fix for bug #893254 (MI1VGA: Changes in object names are not saved); this may introduce regressions, please report them (overall, this is a neat patch, it removes so many ugly hacks :-)

Index: intern.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/intern.h,v
retrieving revision 2.154
retrieving revision 2.155
diff -u -d -r2.154 -r2.155
--- intern.h	2 Mar 2004 10:22:55 -0000	2.154
+++ intern.h	17 Mar 2004 01:50:14 -0000	2.155
@@ -281,7 +281,6 @@
 	void o2_setActorElevation();
 	void o2_setBitVar();
 	void o2_setCameraAt();
-	void o2_setObjectName();
 	void o2_setObjPreposition();
 	void o2_setOwnerOf();
 	void o2_setState01();

Index: object.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/object.cpp,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- object.cpp	1 Mar 2004 21:36:15 -0000	1.170
+++ object.cpp	17 Mar 2004 01:50:14 -0000	1.171
@@ -892,13 +892,10 @@
 	if (obj < _numActors)
 		return derefActor(obj, "getObjOrActorName")->getActorName();
 
-	if (_version >= 6) {
-		for (i = 0; i < _numNewNames; i++) {
-			if (_newNames[i] == obj) {
-				debug(5, "Found new name for object %d at _newNames[%d]", obj, i);
-				return getResourceAddress(rtObjectName, i);
-				break;
-			}
+	for (i = 0; i < _numNewNames; i++) {
+		if (_newNames[i] == obj) {
+			debug(5, "Found new name for object %d at _newNames[%d]", obj, i);
+			return getResourceAddress(rtObjectName, i);
 		}
 	}
 
@@ -922,6 +919,41 @@
 	return findResourceData(MKID('OBNA'), objptr);
 }
 
+void ScummEngine::setObjectName(int obj) {
+	int i;
+
+	if (obj < _numActors)
+		error("Can't set actor %d name with new-name-of", obj);
+
+	const byte *objptr = getOBCDFromObject(obj);
+	if (_version <= 5 && !objptr) {
+		// WORKAROUND bug #587553 and possibly other related script bug.
+		// We do not error out but rather just generate a warning.
+		debug(2, "Can't find OBCD to rename object %d", obj);
+		return;
+	} else if (_version == 6 && !objptr)
+		error("Can't set name of object %d", obj);
+
+	for (i = 0; i < _numNewNames; i++) {
+		if (_newNames[i] == obj) {
+			nukeResource(rtObjectName, i);
+			_newNames[i] = 0;
+			break;
+		}
+	}
+
+	for (i = 0; i < _numNewNames; i++) {
+		if (_newNames[i] == 0) {
+			loadPtrToResource(rtObjectName, i, NULL);
+			_newNames[i] = obj;
+			runInventoryScript(0);
+			return;
+		}
+	}
+
+	error("New name of %d overflows name table (max = %d)", obj, _numNewNames);
+}
+
 uint32 ScummEngine::getOBCDOffs(int object) const {
 	int i;
 

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource.cpp,v
retrieving revision 1.193
retrieving revision 1.194
diff -u -d -r1.193 -r1.194
--- resource.cpp	2 Mar 2004 06:04:38 -0000	1.193
+++ resource.cpp	17 Mar 2004 01:50:14 -0000	1.194
@@ -2101,7 +2101,7 @@
 		_numLocalObjects = _fileHandle.readUint16LE();   // 200
 		_numArray = 50;
 		_numVerbs = 100;
-		_numNewNames = 0;
+		_numNewNames = 50;
 		_objectRoomTable = NULL;
 
 		_fileHandle.readUint16LE();                      // 50

Index: resource_v2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource_v2.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- resource_v2.cpp	6 Jan 2004 12:45:30 -0000	1.39
+++ resource_v2.cpp	17 Mar 2004 01:50:14 -0000	1.40
@@ -187,7 +187,7 @@
 	_numLocalObjects = 200;				// 200
 	_numArray = 50;
 	_numVerbs = 100;
-	_numNewNames = 0;
+	_numNewNames = 50;
 	_objectRoomTable = NULL;
 	_numCharsets = 9;					// 9
 	_numInventory = 80;					// 80

Index: resource_v3.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource_v3.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- resource_v3.cpp	6 Jan 2004 12:45:30 -0000	1.25
+++ resource_v3.cpp	17 Mar 2004 01:50:14 -0000	1.26
@@ -199,7 +199,7 @@
 	_numLocalObjects = 200;				// 200
 	_numArray = 50;
 	_numVerbs = 100;
-	_numNewNames = 0;
+	_numNewNames = 50;
 	_objectRoomTable = NULL;
 	_numCharsets = 9;					// 9
 	_numInventory = 80;					// 80

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/saveload.cpp,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- saveload.cpp	2 Mar 2004 20:35:47 -0000	1.147
+++ saveload.cpp	17 Mar 2004 01:50:14 -0000	1.148
@@ -706,11 +706,16 @@
 		// Old, fragile resource save/load system. Doesn't save resources
 		// with index 0, and breaks whenever we change the limit on a given
 		// resource type.
-		for (type = rtFirst; type <= rtLast; type++)
-			if (res.mode[type] != 1)
-				for (idx = 1; idx < res.num[type]; idx++)
-					if (type != rtTemp && type != rtBuffer)
-						saveLoadResource(s, type, idx);
+ 		for (type = rtFirst; type <= rtLast; type++)
+ 			if (res.mode[type] != 1 && type != rtTemp && type != rtBuffer) {
+ 				// For V1-V5 games, there used to be no object name resources.
+ 				// At some point this changed. But since old savegames rely on
+ 				// unchanged resource counts, we have to hard code the following check
+ 				if (_version < 6 && type == rtObjectName)
+ 					continue;
+ 				for (idx = 1; idx < res.num[type]; idx++)
+ 					saveLoadResource(s, type, idx);
+ 			}
 	}
 
 	s->saveLoadArrayOf(_objectOwnerTable, _numGlobalObjects, sizeof(_objectOwnerTable[0]), sleByte);

Index: script_v2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v2.cpp,v
retrieving revision 2.243
retrieving revision 2.244
diff -u -d -r2.243 -r2.244
--- script_v2.cpp	15 Mar 2004 04:00:00 -0000	2.243
+++ script_v2.cpp	17 Mar 2004 01:50:14 -0000	2.244
@@ -141,7 +141,7 @@
 		OPCODE(o5_actorFollowCamera),
 		OPCODE(o2_actorOps),
 		/* 54 */
-		OPCODE(o2_setObjectName),
+		OPCODE(o5_setObjectName),
 		OPCODE(o2_actorFromPos),
 		OPCODE(o5_getActorMoving),
 		OPCODE(o2_setState02),
@@ -301,7 +301,7 @@
 		OPCODE(o5_actorFollowCamera),
 		OPCODE(o2_actorOps),
 		/* D4 */
-		OPCODE(o2_setObjectName),
+		OPCODE(o5_setObjectName),
 		OPCODE(o2_actorFromPos),
 		OPCODE(o5_getActorMoving),
 		OPCODE(o2_setState02),
@@ -1484,54 +1484,6 @@
 	runInventoryScript(1);
 }
 
-void ScummEngine_v2::o2_setObjectName() {
-	int obj = getVarOrDirectWord(PARAM_1);
-	int size = 0;
-	int a;
-	int i = 0;
-	byte *name = NULL;
-	byte work[256];
-	
-	// Read in new name
-	do {
-		a = fetchScriptByte();
-		work[i++] = a;
-	} while (a);
-
-	if (obj < _numActors)
-		error("Can't set actor %d name with new-name-of", 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.
-
-	// 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++])
-		;
-
-	if (i > size) {
-		warning("New name of object %d too long (old *%s* new *%s*)", obj, name, work);
-		i = size;
-	}
-
-	while (i < size) {
-		work[i - 1] = '@';
-		i++;
-	}
-	work[i - 1] = 0;
-	
-	memcpy(name, work, i);
-	runInventoryScript(0);
-}
-
 void ScummEngine_v2::o2_cursorCommand() {	// TODO: Define the magic numbers
 	uint16 cmd = getVarOrDirectWord(PARAM_1);
 	byte state = cmd >> 8;

Index: script_v5.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v5.cpp,v
retrieving revision 1.232
retrieving revision 1.233
diff -u -d -r1.232 -r1.233
--- script_v5.cpp	15 Mar 2004 03:33:08 -0000	1.232
+++ script_v5.cpp	17 Mar 2004 01:50:14 -0000	1.233
@@ -2055,109 +2055,7 @@
 
 void ScummEngine_v5::o5_setObjectName() {
 	int obj = getVarOrDirectWord(PARAM_1);
-	int size;
-	int a;
-	int i = 0;
-	byte *name = NULL;
-	unsigned char work[256];
-	
-	// Read in new name
-	while ((a = fetchScriptByte()) != 0) {
-		work[i++] = a;
-		if (a == 0xFF) {
-			work[i++] = fetchScriptByte();
-			work[i++] = fetchScriptByte();
-			work[i++] = fetchScriptByte();
-		}
-	}
-	work[i++] = 0;
-
-	if (obj < _numActors)
-		error("Can't set actor %d name with new-name-of", 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) {
-		// WORKAROUND 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;
-	}
-
-	if (_features & GF_SMALL_HEADER) {
-		byte offset = 0;
-
-		if (_features & GF_OLD_BUNDLE)
-			offset = *(objptr + 16);
-		else
-			offset = *(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 separate
-		// resource for changed names. That would be the cleanest solution, but
-		// might proof to be infeasible, as it might lead to unforseen regressions.
-		
-		const uint32 tag = MKID('OBNA');
-		byte *searchin = objptr;
-		uint32 curpos, totalsize;
-	
-		assert(searchin);
-	
-		searchin += 4;
-		totalsize = READ_BE_UINT32(searchin);
-		curpos = 8;
-		searchin += 4;
-	
-		while (curpos < totalsize) {
-			if (READ_UINT32(searchin) == tag) {
-				name = searchin + _resourceHeaderSize;
-				break;
-			}
-	
-			size = READ_BE_UINT32(searchin + 4);
-			if ((int32)size <= 0) {
-				error("(OBNA) Not found... illegal block len %d", 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' (%d), new '%s' (%d))",
-				obj, name, i, work, size);
-		i = size;
-	}
-
-	memcpy(name, work, i);
-	runInventoryScript(0);
+	setObjectName(obj);
 }
 
 void ScummEngine_v5::o5_setOwnerOf() {

Index: script_v6.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v6.cpp,v
retrieving revision 1.321
retrieving revision 1.322
diff -u -d -r1.321 -r1.322
--- script_v6.cpp	15 Mar 2004 21:48:53 -0000	1.321
+++ script_v6.cpp	17 Mar 2004 01:50:15 -0000	1.322
@@ -1427,32 +1427,7 @@
 
 void ScummEngine_v6::o6_setObjectName() {
 	int obj = pop();
-	int i;
-
-	if (obj < _numActors)
-		error("Can't set actor %d name with new-name-of", obj);
-
-	if (_version < 7 && !getOBCDFromObject(obj))
-		error("Can't set name of object %d", obj);
-
-	for (i = 0; i < _numNewNames; i++) {
-		if (_newNames[i] == obj) {
-			nukeResource(rtObjectName, i);
-			_newNames[i] = 0;
-			break;
-		}
-	}
-
-	for (i = 0; i < _numNewNames; i++) {
-		if (_newNames[i] == 0) {
-			loadPtrToResource(rtObjectName, i, NULL);
-			_newNames[i] = obj;
-			runInventoryScript(0);
-			return;
-		}
-	}
-
-	error("New name of %d overflows name table (max = %d)", obj, _numNewNames);
+	setObjectName(obj);
 }
 
 void ScummEngine_v6::o6_isSoundRunning() {

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.383
retrieving revision 1.384
diff -u -d -r1.383 -r1.384
--- scumm.h	15 Mar 2004 03:36:18 -0000	1.383
+++ scumm.h	17 Mar 2004 01:50:15 -0000	1.384
@@ -700,6 +700,7 @@
 protected:
 	int getObjActToObjActDist(int a, int b); // Not sure how to handle
 	const byte *getObjOrActorName(int obj);		 // these three..
+	void setObjectName(int obj);
 
 	void addObjectToDrawQue(int object);
 	void clearDrawObjectQueue();





More information about the Scummvm-git-logs mailing list