From 5cc1313ffe20baf44addd2d156deb83835af8a1d Mon Sep 17 00:00:00 2001 From: Vincent Hamm Date: Mon, 17 Dec 2007 22:40:58 +0000 Subject: Fix dangling pointer Fix low color background Fix input svn-id: r29897 --- engines/cruise/cruise_main.cpp | 92 ++++++++++++++++++++++++++++-------------- engines/cruise/function.cpp | 27 ++++++++++++- engines/cruise/gfxModule.cpp | 5 +-- engines/cruise/script.cpp | 2 + 4 files changed, 91 insertions(+), 35 deletions(-) (limited to 'engines/cruise') diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp index fa596f6855..49d131497f 100644 --- a/engines/cruise/cruise_main.cpp +++ b/engines/cruise/cruise_main.cpp @@ -1047,7 +1047,16 @@ bool findRelation(int objOvl, int objIdx, int x, int y) { if ( (!first) && ((testState==-1) || (testState==objectState))) { if (!strlen(verbe_name)) - attacheNewScriptToTail(&relHead, j, ptrHead->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); + { + if(currentScriptPtr) + { + attacheNewScriptToTail(&relHead, j, ptrHead->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); + } + else + { + attacheNewScriptToTail(&relHead, j, ptrHead->id, 30, 0, 0, scriptType_REL); + } + } else if (ovl2->nameVerbGlob) { found = true; ptr = getObjectName(ptrHead->verbNumber, ovl2->nameVerbGlob); @@ -1120,39 +1129,46 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) { if ((pHeader->obj2OldState == -1) || (params.scale == pHeader->obj2OldState)) { if (pHeader->type == 30) { // REL - attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); + if(currentScriptPtr) + { + attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); + } + else + { + attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, 0, 0, scriptType_REL); + } - if ((narratorOvl > 0) && (pHeader->trackX != -1) && (pHeader->trackY != -1)) { - actorStruct* pTrack = findActor(&actorHead, narratorOvl, narratorIdx, 0); + if ((narratorOvl > 0) && (pHeader->trackX != -1) && (pHeader->trackY != -1)) { + actorStruct* pTrack = findActor(&actorHead, narratorOvl, narratorIdx, 0); + + if (pTrack) { + animationStart = false; + + if (pHeader->trackDirection == 9999) { + objectParamsQuery naratorParams; + getMultipleObjectParam(narratorOvl, narratorIdx, &naratorParams); + pTrack->x_dest = naratorParams.X; + pTrack->y_dest = naratorParams.Y; + pTrack->endDirection = direction(naratorParams.X, naratorParams.Y, pTrack->x_dest, pTrack->y_dest, 0, 0); + } else if ((pHeader->trackX == 9999) && (pHeader->trackY == 9999)) { + objectParamsQuery naratorParams; + getMultipleObjectParam(narratorOvl, narratorIdx, &naratorParams); + pTrack->x_dest = naratorParams.X; + pTrack->y_dest = naratorParams.Y; + pTrack->endDirection = pHeader->trackDirection; + } else { + pTrack->x_dest = pHeader->trackX; + pTrack->y_dest = pHeader->trackY; + pTrack->endDirection = pHeader->trackDirection; + } - if (pTrack) { - animationStart = false; + pTrack->flag = 1; - if (pHeader->trackDirection == 9999) { - objectParamsQuery naratorParams; - getMultipleObjectParam(narratorOvl, narratorIdx, &naratorParams); - pTrack->x_dest = naratorParams.X; - pTrack->y_dest = naratorParams.Y; - pTrack->endDirection = direction(naratorParams.X, naratorParams.Y, pTrack->x_dest, pTrack->y_dest, 0, 0); - } else if ((pHeader->trackX == 9999) && (pHeader->trackY == 9999)) { - objectParamsQuery naratorParams; - getMultipleObjectParam(narratorOvl, narratorIdx, &naratorParams); - pTrack->x_dest = naratorParams.X; - pTrack->y_dest = naratorParams.Y; - pTrack->endDirection = pHeader->trackDirection; - } else { - pTrack->x_dest = pHeader->trackX; - pTrack->y_dest = pHeader->trackY; - pTrack->endDirection = pHeader->trackDirection; + autoTrack = true; + userEnabled = 0; + changeScriptParamInList(ovlIdx, pHeader->id, &relHead, 0, 9998); } - - pTrack->flag = 1; - - autoTrack = true; - userEnabled = 0; - changeScriptParamInList(ovlIdx, pHeader->id, &relHead, 0, 9998); } - } } else if (pHeader->type == 50) { ASSERT(0); } @@ -1183,7 +1199,14 @@ void callRelation(menuElementSubStruct *pMenuElement, int nObj2) { if (pHeader->obj2Number == nObj2) { // REL if (pHeader->type == 30) { - attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); + if(currentScriptPtr) + { + attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); + } + else + { + attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, 0, 0, scriptType_REL); + } if ((narratorOvl > 0) && (pHeader->trackX != -1) && (pHeader->trackY != -1)) { actorStruct* pTrack = findActor(&actorHead, narratorOvl, narratorIdx, 0); @@ -1247,7 +1270,14 @@ void callRelation(menuElementSubStruct *pMenuElement, int nObj2) { } } - createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), currentActiveBackgroundPlane, currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber); + if(currentScriptPtr) + { + createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), currentActiveBackgroundPlane, currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber); + } + else + { + createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), currentActiveBackgroundPlane, 0, 0); + } userWait = 1; autoOvl = ovlIdx; diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp index d63f362c62..eb8d84760e 100644 --- a/engines/cruise/function.cpp +++ b/engines/cruise/function.cpp @@ -1550,6 +1550,30 @@ int16 Op_LinkObjects(void) { return 0; } +int16 Op_UserDelay(void) +{ + int delay = popVar(); + + if(delay >= 0) + { + userDelay = delay; + } + + return userDelay; +} + +int16 Op_UserWait(void) +{ + userWait = 1; + if (currentScriptPtr->type == scriptType_PROC) { + changeScriptParamInList(currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber, &procHead, -1, 9999); + } else if (currentScriptPtr->type == scriptType_REL) { + changeScriptParamInList(currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber, &relHead, -1, 9999); + } + + return 0; +} + void setupOpcodeTable(void) { int i; @@ -1577,7 +1601,7 @@ void setupOpcodeTable(void) { opcodeTablePtr[0x12] = NULL; // used to be exec debug opcodeTablePtr[0x13] = Op_AddMessage; opcodeTablePtr[0x14] = Op_RemoveMessage; - opcodeTablePtr[0x15] = NULL; // user wait + opcodeTablePtr[0x15] = Op_UserWait; opcodeTablePtr[0x16] = Op_FreezeCell; opcodeTablePtr[0x17] = Op_LoadCt; opcodeTablePtr[0x18] = Op_AddAnimation; @@ -1604,6 +1628,7 @@ void setupOpcodeTable(void) { opcodeTablePtr[0x32] = Op_freeBackgroundInscrustList; opcodeTablePtr[0x33] = Op_DialogOn; opcodeTablePtr[0x34] = Op_DialogOff; + opcodeTablePtr[0x35] = Op_UserDelay; opcodeTablePtr[0x37] = Op_37; opcodeTablePtr[0x38] = Op_removeBackground; opcodeTablePtr[0x39] = Op_SetActiveBackgroundPlane; diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp index 98df881dbd..d7a2a9cbf8 100644 --- a/engines/cruise/gfxModule.cpp +++ b/engines/cruise/gfxModule.cpp @@ -62,11 +62,10 @@ void outputBit(char *buffer, int bitPlaneNumber, uint8 data) { *(buffer + (8000 * bitPlaneNumber)) = data; } -void gfxModuleData_field_60(char *sourcePtr, int width, int height, - char *destPtr, int x_, int y_) { +void gfxModuleData_field_60(char *sourcePtr, int width, int height, char *destPtr, int x_, int y_) { for (int y = 0; y < height; ++y) { - for (int x = 0; x < width / 8; ++x) { + for (int x = 0; x < width; ++x) { for (int bit = 0; bit < 16; ++bit) { uint8 color = 0; for (int p = 0; p < 4; ++p) { diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp index 11be0dcc67..a187b5daba 100644 --- a/engines/cruise/script.cpp +++ b/engines/cruise/script.cpp @@ -738,6 +738,8 @@ int executeScripts(scriptInstanceStruct *ptr) { } } while (!opcodeTypeTable[(opcodeType & 0xFB) >> 3] ()); + currentScriptPtr = NULL; + return (0); } -- cgit v1.2.3