[Scummvm-cvs-logs] SF.net SVN: scummvm: [25025] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Sat Jan 6 12:17:21 CET 2007


Revision: 25025
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25025&view=rev
Author:   drmccoy
Date:     2007-01-06 03:17:20 -0800 (Sat, 06 Jan 2007)

Log Message:
-----------
- Fixed cut off and missing sounds
- Fixed a crash/static reported in the forums (sending Winkle to the vulture)
- (Hopefully) fixed the immediately-closing notepad heisenbug (#1621089)
- Fixed using unitialised values after allocating the variables

Modified Paths:
--------------
    scummvm/trunk/engines/gob/game.cpp
    scummvm/trunk/engines/gob/game.h
    scummvm/trunk/engines/gob/game_v1.cpp
    scummvm/trunk/engines/gob/game_v2.cpp
    scummvm/trunk/engines/gob/global.h
    scummvm/trunk/engines/gob/init.cpp
    scummvm/trunk/engines/gob/inter_v1.cpp
    scummvm/trunk/engines/gob/inter_v2.cpp
    scummvm/trunk/engines/gob/sound.h

Modified: scummvm/trunk/engines/gob/game.cpp
===================================================================
--- scummvm/trunk/engines/gob/game.cpp	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/game.cpp	2007-01-06 11:17:20 UTC (rev 25025)
@@ -150,11 +150,12 @@
 		delete[] _word_2FC80;
 }
 
-char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
+char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight, uint32 *dataSize) {
 	int16 commonHandle;
 	int16 itemsCount;
 	int32 offset;
 	uint32 size;
+	uint32 realSize;
 	ExtItem *item;
 	char isPacked;
 	int16 handle;
@@ -206,6 +207,7 @@
 
 	debugC(7, DEBUG_FILEIO, "off: %d size: %d", offset, tableSize);
 	_vm->_dataio->seekData(handle, offset + tableSize, SEEK_SET);
+	realSize = size;
 	// CHECKME: is the below correct?
 	if (isPacked)
 		dataBuf = new char[size];
@@ -227,13 +229,15 @@
 
 	if (isPacked != 0) {
 		packedBuf = dataBuf;
-		dataBuf = new char[READ_LE_UINT32(packedBuf)];
+		realSize = READ_LE_UINT32(packedBuf);
+		dataBuf = new char[realSize];
 		_vm->_pack->unpackData(packedBuf, dataBuf);
 		delete[] packedBuf;
 	}
 
+	if (dataSize)
+		*dataSize = realSize;
 	return dataBuf;
-
 }
 
 void Game::freeCollision(int16 id) {
@@ -302,12 +306,14 @@
 	_vm->_draw->_spritesArray[30 + _captureCount] = 0;
 }
 
-char *Game::loadTotResource(int16 id) {
+char *Game::loadTotResource(int16 id, int16 *dataSize) {
 	TotResItem *itemPtr;
 	int32 offset;
 
 	itemPtr = &_totResourceTable->items[id];
 	offset = itemPtr->offset;
+	if (dataSize)
+		*dataSize = itemPtr->size;
 	if (offset >= 0) {
 		return _totResourceTable->dataPtr + szGame_TotResTable +
 		    szGame_TotResItem * _totResourceTable->itemsCount + offset;
@@ -316,20 +322,22 @@
 	}
 }
 
-void Game::loadSound(int16 slot, char *dataPtr) {
+void Game::loadSound(int16 slot, char *dataPtr, uint32 dataSize) {
 	Snd::SoundDesc *soundDesc;
+	byte *data = (byte *) dataPtr;
 
 	soundDesc = new Snd::SoundDesc;
 
 	_soundSamples[slot] = soundDesc;
 
-	soundDesc->frequency = (dataPtr[4] << 8) + dataPtr[5];
-	soundDesc->size = (dataPtr[1] << 16) + (dataPtr[2] << 8) + dataPtr[3];
+	soundDesc->frequency = (data[4] << 8) + data[5];
+	// Somehow, one sound in one CD version has a wrong size, leading to statics and crashes
+	soundDesc->size = MIN((uint32) ((data[1] << 16) + (data[2] << 8) + data[3]), dataSize - 6);
 	soundDesc->data = dataPtr + 6;
 	soundDesc->timerTicks = (int32)1193180 / (int32)soundDesc->frequency;
-
 	soundDesc->inClocks = (soundDesc->frequency * 10) / 182;
 	soundDesc->flag = 0;
+
 }
 
 void Game::freeSoundSlot(int16 slot) {
@@ -350,13 +358,13 @@
 		char* data = _soundSamples[slot]->data;
 
 		_vm->_snd->freeSoundDesc(_soundSamples[slot], false);
-		_soundSamples[slot] = 0;
 
 		if (_soundFromExt[slot] == 1) {
 			delete[] (data - 6);
 			_soundFromExt[slot] = 0;
 		}
 	}
+	_soundSamples[slot] = 0;
 }
 
 int16 Game::adjustKey(int16 key) {
@@ -748,7 +756,7 @@
 
 Snd::SoundDesc *Game::loadSND(const char *path, int8 arg_4) {
 	Snd::SoundDesc *soundDesc;
-	int32 dsize;
+	uint32 dsize;
 	char *data;
 	char *dataPtr;
 

Modified: scummvm/trunk/engines/gob/game.h
===================================================================
--- scummvm/trunk/engines/gob/game.h	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/game.h	2007-01-06 11:17:20 UTC (rev 25025)
@@ -186,8 +186,8 @@
 	Game(GobEngine *vm);
 	virtual ~Game();
 
-	char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight);
-	char *loadTotResource(int16 id);
+	char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight, uint32 *dataSize = 0);
+	char *loadTotResource(int16 id, int16 *dataSize = 0);
 
 	void capturePush(int16 left, int16 top, int16 width, int16 height);
 
@@ -195,7 +195,7 @@
 	void freeSoundSlot(int16 slot);
 	void freeCollision(int16 id);
 
-	void loadSound(int16 slot, char *dataPtr);
+	void loadSound(int16 slot, char *dataPtr, uint32 dataSize = 4294967295U);
 	int16 adjustKey(int16 key);
 	int32 loadTotFile(char *path);
 	void loadExtTable(void);

Modified: scummvm/trunk/engines/gob/game_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v1.cpp	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/game_v1.cpp	2007-01-06 11:17:20 UTC (rev 25025)
@@ -173,8 +173,7 @@
 				variablesCount = READ_LE_UINT32((char *)_totFileData + 0x2c);
 				_vm->_global->_inter_variables = new char[variablesCount * 4];
 				_vm->_global->_inter_variablesSizes = new byte[variablesCount * 4];
-				for (i = 0; i < variablesCount; i++)
-					WRITE_VAR(i, 0);
+				_vm->_global->clearVars(variablesCount);
 			}
 
 			_vm->_global->_inter_execPtr = (char *)_totFileData;

Modified: scummvm/trunk/engines/gob/game_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v2.cpp	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/game_v2.cpp	2007-01-06 11:17:20 UTC (rev 25025)
@@ -201,8 +201,7 @@
 				variablesCount = READ_LE_UINT32((char *)_totFileData + 0x2c);
 				_vm->_global->_inter_variables = new char[variablesCount * 4];
 				_vm->_global->_inter_variablesSizes = new byte[variablesCount * 4];
-				for (i = 0; i < variablesCount; i++)
-					WRITE_VAR(i, 0);
+				_vm->_global->clearVars(variablesCount);
 			}
 
 			_vm->_global->_inter_execPtr = (char *)_totFileData;

Modified: scummvm/trunk/engines/gob/global.h
===================================================================
--- scummvm/trunk/engines/gob/global.h	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/global.h	2007-01-06 11:17:20 UTC (rev 25025)
@@ -163,6 +163,22 @@
 	int16 _inter_mouseX;
 	int16 _inter_mouseY;
 
+	inline void clearVars(uint32 count)
+	{
+		uint32 i;
+
+		for (i = 0; i < count; i++) {
+			_inter_variablesSizes[i * 4] = 3;
+			_inter_variablesSizes[i * 4 + 1] = 0;
+			_inter_variablesSizes[i * 4 + 2] = 0;
+			_inter_variablesSizes[i * 4 + 3] = 0;
+			_inter_variables[i * 4] = 0;
+			_inter_variables[i * 4 + 1] = 0;
+			_inter_variables[i * 4 + 2] = 0;
+			_inter_variables[i * 4 + 3] = 0;
+		}
+	}
+
 	inline void writeVarSizeStr(uint32 offset, uint32 len) {
 		uint32 i;
 		uint32 inVar;

Modified: scummvm/trunk/engines/gob/init.cpp
===================================================================
--- scummvm/trunk/engines/gob/init.cpp	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/init.cpp	2007-01-06 11:17:20 UTC (rev 25025)
@@ -206,8 +206,7 @@
 
 		_vm->_global->_inter_variables = new char[varsCount * 4];
 		_vm->_global->_inter_variablesSizes = new byte[varsCount * 4];
-		for (i = 0; i < varsCount; i++)
-			WRITE_VAR(i, 0);
+		_vm->_global->clearVars(varsCount);
 		WRITE_VAR(58, 1);
 
 		strcpy(_vm->_game->_curTotFile, buffer);

Modified: scummvm/trunk/engines/gob/inter_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v1.cpp	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/inter_v1.cpp	2007-01-06 11:17:20 UTC (rev 25025)
@@ -1339,9 +1339,8 @@
 	animPalette();
 	_vm->_draw->blitInvalidated();
 
-	_vm->_video->waitRetrace(_vm->_global->_videoMode);
 	// Gob2 busy-waits here, so add a delay
-	_vm->_util->delay(1);
+	_vm->_util->longDelay(1);
 
 	if (flag != 0) {
 

Modified: scummvm/trunk/engines/gob/inter_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v2.cpp	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/inter_v2.cpp	2007-01-06 11:17:20 UTC (rev 25025)
@@ -933,7 +933,7 @@
 int16 Inter_v2::loadSound(int16 search) {
 	int16 id; // si
 	int16 slot; // di
-	int32 i;
+	uint32 i;
 	bool isADL;
 	char sndfile[14];
 	char *extData;
@@ -1003,21 +1003,25 @@
 				_vm->_game->_soundSamples[slot] = soundDesc;
 				_vm->_game->_soundFromExt[slot] = 1;
 			} else { // loc_99BC
-				extData = _vm->_game->loadExtData(id, 0, 0);
+				uint32 dataSize;
+
+				extData = _vm->_game->loadExtData(id, 0, 0, &dataSize);
 				if (extData == 0)
 					return slot;
 				_vm->_game->_soundTypes[slot] = 1;
 				if (!isADL)
-					_vm->_game->loadSound(slot, extData);
+					_vm->_game->loadSound(slot, extData, dataSize);
 				else
 					// TODO: This is very ugly
 					_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) extData;
 				_vm->_game->_soundFromExt[slot] = 1;
 			}
 		} else { // loc_9A13
-			extData = _vm->_game->loadTotResource(id);
+			int16 dataSize;
+
+			extData = _vm->_game->loadTotResource(id, &dataSize);
 			if (!isADL)
-				_vm->_game->loadSound(slot, extData);
+				_vm->_game->loadSound(slot, extData, dataSize);
 			else
 				// TODO: This is very ugly
 				_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) extData;

Modified: scummvm/trunk/engines/gob/sound.h
===================================================================
--- scummvm/trunk/engines/gob/sound.h	2007-01-06 05:11:41 UTC (rev 25024)
+++ scummvm/trunk/engines/gob/sound.h	2007-01-06 11:17:20 UTC (rev 25025)
@@ -33,7 +33,7 @@
 	struct SoundDesc {
 		Audio::SoundHandle handle;
 		char *data;
-		int32 size;
+		uint32 size;
 		int16 repCount;
 		int16 timerTicks;
 		int16 inClocks;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list