- 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

svn-id: r25025
This commit is contained in:
Sven Hesse 2007-01-06 11:17:20 +00:00
parent 61d741514e
commit 6e0835da11
9 changed files with 51 additions and 27 deletions

View File

@ -150,11 +150,12 @@ Game::~Game() {
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 @@ char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
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 @@ char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
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 @@ void Game::capturePop(char doDraw) {
_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 @@ char *Game::loadTotResource(int16 id) {
}
}
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 @@ void Game::freeSoundSlot(int16 slot) {
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 @@ void Game::collAreaSub(int16 index, int8 enter) {
Snd::SoundDesc *Game::loadSND(const char *path, int8 arg_4) {
Snd::SoundDesc *soundDesc;
int32 dsize;
uint32 dsize;
char *data;
char *dataPtr;

View File

@ -186,8 +186,8 @@ public:
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 @@ public:
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);

View File

@ -173,8 +173,7 @@ void Game_v1::playTot(int16 skipPlay) {
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;

View File

@ -201,8 +201,7 @@ void Game_v2::playTot(int16 skipPlay) {
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;

View File

@ -163,6 +163,22 @@ public:
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;

View File

@ -206,8 +206,7 @@ memBlocks = word ptr -2*/
_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);

View File

@ -1339,9 +1339,8 @@ bool Inter_v1::o1_keyFunc(char &cmdCount, int16 &counter, int16 &retFlag) {
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) {

View File

@ -933,7 +933,7 @@ void Inter_v2::o2_stub0x85(void) {
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 @@ int16 Inter_v2::loadSound(int16 search) {
_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;

View File

@ -33,7 +33,7 @@ public:
struct SoundDesc {
Audio::SoundHandle handle;
char *data;
int32 size;
uint32 size;
int16 repCount;
int16 timerTicks;
int16 inClocks;