diff options
author | Eugene Sandulenko | 2008-09-21 10:23:22 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2008-09-21 10:23:22 +0000 |
commit | 297d4228d38a8321b9df8c72f22e7a372de22d0c (patch) | |
tree | 2259b205f26a7b49fc421ffa3daa0051a34df832 /engines | |
parent | 727b220d25c217fde2dd1095ee5fa5f9509fc5f1 (diff) | |
download | scummvm-rg350-297d4228d38a8321b9df8c72f22e7a372de22d0c.tar.gz scummvm-rg350-297d4228d38a8321b9df8c72f22e7a372de22d0c.tar.bz2 scummvm-rg350-297d4228d38a8321b9df8c72f22e7a372de22d0c.zip |
Patch #2054467: CRUISE: 64bits fixes
svn-id: r34622
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cruise/cruise_main.cpp | 2 | ||||
-rw-r--r-- | engines/cruise/ctp.cpp | 14 | ||||
-rw-r--r-- | engines/cruise/dataLoader.cpp | 21 | ||||
-rw-r--r-- | engines/cruise/overlay.cpp | 312 | ||||
-rw-r--r-- | engines/cruise/overlay.h | 2 | ||||
-rw-r--r-- | engines/cruise/saveload.cpp | 3 | ||||
-rw-r--r-- | engines/cruise/vars.h | 3 |
7 files changed, 155 insertions, 202 deletions
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp index 5d16c6e68a..7064f81a90 100644 --- a/engines/cruise/cruise_main.cpp +++ b/engines/cruise/cruise_main.cpp @@ -243,7 +243,7 @@ ovlData3Struct *scriptFunc1Sub2(int32 scriptNumber, int32 param) { return NULL; } - return ((ovlData3Struct *) (ovlData->ptr1 + param * 0x1C)); + return &ovlData->ptr1[param]; } void scriptFunc2(int scriptNumber, scriptInstanceStruct * scriptHandle, diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp index 6c7be713ef..b45b6dc866 100644 --- a/engines/cruise/ctp.cpp +++ b/engines/cruise/ctp.cpp @@ -153,8 +153,8 @@ void makeCtStruct(uint8* str, int16 table[][40], int num, int z) { int16* a2; a1 = a2 = (int16*)str; - a2 += 4+sizeof(int16*); // skip header - + a2 += sizeof(int16*) / sizeof(int16) + 6; // skip header + int16* XArray = XMIN_XMAX; int minY = *XArray++; @@ -178,8 +178,8 @@ void makeCtStruct(uint8* str, int16 table[][40], int num, int z) { adrStructPoly = (uint8*)a2; - *(uint16**)a2 = (uint16*)-1; - + *(uint16**)a2 = (uint16*)-1; //chained list terminator + a1+=sizeof(int16*); *a1++=num; *a1++=walkboxColor[num]; @@ -339,20 +339,20 @@ int initCt(const char *ctpName) { makeCtStruct(adrStructPoly, ctp_walkboxTable, i, 0 ); } - polyStructExp = adrStructPoly += 4; + polyStructExp = adrStructPoly += sizeof(int16 *); for(int i= numberOfWalkboxes-1; i >=0; i--) { makeCtStruct(adrStructPoly, ctp_walkboxTable, i, walkboxZoom[i] * 20 ); } - int ctSize = (adrStructPoly - ptr) + 4; // for now, the +4 is a safe zone + int ctSize = (adrStructPoly - ptr) + sizeof(int16 *); // for now, the +sizeof(int16 *) is a safe zone adrStructPoly = polyStructNorm = polyStruct = (uint8 *) malloc(ctSize); for(int i= numberOfWalkboxes-1; i >=0; i--) { makeCtStruct(adrStructPoly, ctp_walkboxTable, i, 0); } - polyStructExp = adrStructPoly += 4; + polyStructExp = adrStructPoly += sizeof(int16 *); for(int i= numberOfWalkboxes-1; i >=0; i--) { makeCtStruct(adrStructPoly, ctp_walkboxTable, i, walkboxZoom[i] * 20); diff --git a/engines/cruise/dataLoader.cpp b/engines/cruise/dataLoader.cpp index 7ce69448a6..c274291142 100644 --- a/engines/cruise/dataLoader.cpp +++ b/engines/cruise/dataLoader.cpp @@ -24,6 +24,7 @@ */ #include "cruise/cruise_main.h" +#include "common/endian.h" namespace Cruise { @@ -412,7 +413,6 @@ int loadFNTSub(uint8 *ptr, int destIdx) { } int loadSetEntry(const char *name, uint8 *ptr, int currentEntryIdx, int currentDestEntry) { - uint8 *ptr2; uint8 *ptr3; int offset; int sec = 0; @@ -422,28 +422,27 @@ int loadSetEntry(const char *name, uint8 *ptr, int currentEntryIdx, int currentD sec = 1; } - ptr2 = ptr + 4; - - memcpy(&numIdx, ptr2, 2); - flipShort(&numIdx); + numIdx = READ_BE_UINT16(ptr + 4); ptr3 = ptr + 6; offset = currentEntryIdx * 16; { - uint8 *ptr4; int resourceSize; int fileIndex; setHeaderEntry localBuffer; uint8 *ptr5; - ptr4 = ptr + offset + 6; - - memcpy(&localBuffer, ptr4, sizeof(setHeaderEntry)); + Common::MemoryReadStream s4(ptr + offset + 6, 16); - flipLong((int32 *) & localBuffer.field_0); - flipGen(&localBuffer.width, 12); + localBuffer.field_0 = s4.readUint32BE(); + localBuffer.width = s4.readUint16BE(); + localBuffer.height = s4.readUint16BE(); + localBuffer.type = s4.readUint16BE(); + localBuffer.transparency = s4.readUint16BE(); + localBuffer.field_C = s4.readUint16BE(); + localBuffer.field_E = s4.readUint16BE(); if (sec == 1) { localBuffer.width = localBuffer.width - (localBuffer.type * 2); // Type 1: Width - (1*2) , Type 5: Width - (5*2) diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp index d3cb93c37c..4d476ceaf1 100644 --- a/engines/cruise/overlay.cpp +++ b/engines/cruise/overlay.cpp @@ -23,6 +23,8 @@ * */ +#include "common/stream.h" + #include "cruise/cruise_main.h" namespace Cruise { @@ -50,8 +52,7 @@ int loadOverlay(const char *scriptName) { char fileName[50]; int fileIdx; int unpackedSize; - char *unpackedBuffer; - char *scriptPtr; + byte *unpackedBuffer; ovlDataStruct *ovlData; printf("Load overlay: %s\n", scriptName); @@ -105,7 +106,7 @@ int loadOverlay(const char *scriptName) { unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2; // TODO: here, can unpack in gfx module buffer - unpackedBuffer = (char *)mallocAndZero(unpackedSize); + unpackedBuffer = (byte *)mallocAndZero(unpackedSize); if (!unpackedBuffer) { return (-2); @@ -127,12 +128,13 @@ int loadOverlay(const char *scriptName) { printf("OVL loading done...\n"); - scriptPtr = unpackedBuffer; + Common::MemoryReadStream s(unpackedBuffer, unpackedSize); ovlData = overlayTable[scriptIdx].ovlData; - memcpy(ovlData, scriptPtr, sizeof(ovlDataStruct)); - + // Skip pointers + s.skip(60); + ovlData->arrayProc = NULL; ovlData->ptr1 = NULL; ovlData->arrayObject = NULL; @@ -148,24 +150,22 @@ int loadOverlay(const char *scriptName) { ovlData->arrayNameSymbGlob = NULL; ovlData->data4Ptr = NULL; ovlData->ptr8 = NULL; - ovlData->numProc = readB16(scriptPtr + 60); - ovlData->numRel = readB16(scriptPtr + 62); - ovlData->numSymbGlob = readB16(scriptPtr + 64); - ovlData->numRelocGlob = readB16(scriptPtr + 66); - ovlData->numMsgRelHeader = readB16(scriptPtr + 68); - ovlData->numObj = readB16(scriptPtr + 70); - ovlData->numStrings = readB16(scriptPtr + 72); - ovlData->size8 = readB16(scriptPtr + 74); - ovlData->size9 = readB16(scriptPtr + 76); - ovlData->nameExportSize = readB16(scriptPtr + 78); - ovlData->exportNamesSize = readB16(scriptPtr + 80); - ovlData->specialString2Length = readB16(scriptPtr + 82); - ovlData->sizeOfData4 = readB16(scriptPtr + 84); - ovlData->size12 = readB16(scriptPtr + 86); - ovlData->specialString1Length = readB16(scriptPtr + 88); - ovlData->scriptNumber = readB16(scriptPtr + 90); - - scriptPtr += 92; + ovlData->numProc = s.readUint16BE(); + ovlData->numRel = s.readUint16BE(); + ovlData->numSymbGlob = s.readUint16BE(); + ovlData->numRelocGlob = s.readUint16BE(); + ovlData->numMsgRelHeader = s.readUint16BE(); + ovlData->numObj = s.readUint16BE(); + ovlData->numStrings = s.readUint16BE(); + ovlData->size8 = s.readUint16BE(); + ovlData->size9 = s.readUint16BE(); + ovlData->nameExportSize = s.readUint16BE(); + ovlData->exportNamesSize = s.readUint16BE(); + ovlData->specialString2Length = s.readUint16BE(); + ovlData->sizeOfData4 = s.readUint16BE(); + ovlData->size12 = s.readUint16BE(); + ovlData->specialString1Length = s.readUint16BE(); + ovlData->scriptNumber = s.readUint16BE(); if (ovlData->numSymbGlob) { // export data int i; @@ -177,13 +177,11 @@ int loadOverlay(const char *scriptName) { } for (i = 0; i < ovlData->numSymbGlob; i++) { - ovlData->arraySymbGlob[i].var0 = readB16(scriptPtr); - ovlData->arraySymbGlob[i].var2 = readB16(scriptPtr + 2); - ovlData->arraySymbGlob[i].var4 = readB16(scriptPtr + 4); - ovlData->arraySymbGlob[i].idx = readB16(scriptPtr + 6); - ovlData->arraySymbGlob[i].offsetToName = readB16(scriptPtr + 8); - - scriptPtr += 10; + ovlData->arraySymbGlob[i].var0 = s.readUint16BE(); + ovlData->arraySymbGlob[i].var2 = s.readUint16BE(); + ovlData->arraySymbGlob[i].var4 = s.readUint16BE(); + ovlData->arraySymbGlob[i].idx = s.readUint16BE(); + ovlData->arraySymbGlob[i].offsetToName = s.readUint16BE(); } } @@ -194,8 +192,7 @@ int loadOverlay(const char *scriptName) { return (-2); } - memcpy(ovlData->arrayNameSymbGlob, scriptPtr, ovlData->exportNamesSize); - scriptPtr += ovlData->exportNamesSize; + s.read(ovlData->arrayNameSymbGlob, ovlData->exportNamesSize); } if (ovlData->numRelocGlob) { // import data @@ -210,13 +207,11 @@ int loadOverlay(const char *scriptName) { } for (i = 0; i < ovlData->numRelocGlob; i++) { - ovlData->arrayRelocGlob[i].var0 = readB16(scriptPtr); - ovlData->arrayRelocGlob[i].var1 = readB16(scriptPtr + 2); - ovlData->arrayRelocGlob[i].linkType = readB16(scriptPtr + 4); - ovlData->arrayRelocGlob[i].linkIdx = readB16(scriptPtr + 6); - ovlData->arrayRelocGlob[i].nameOffset = readB16(scriptPtr + 8); - - scriptPtr += 10; + ovlData->arrayRelocGlob[i].var0 = s.readUint16BE(); + ovlData->arrayRelocGlob[i].var1 = s.readUint16BE(); + ovlData->arrayRelocGlob[i].linkType = s.readUint16BE(); + ovlData->arrayRelocGlob[i].linkIdx = s.readUint16BE(); + ovlData->arrayRelocGlob[i].nameOffset = s.readUint16BE(); } } @@ -226,13 +221,12 @@ int loadOverlay(const char *scriptName) { if (!ovlData->arrayNameRelocGlob) { return (-2); } - - memcpy(ovlData->arrayNameRelocGlob, scriptPtr, - ovlData->nameExportSize); - scriptPtr += ovlData->nameExportSize; + + s.read(ovlData->arrayNameRelocGlob, ovlData->nameExportSize); } if (ovlData->numMsgRelHeader) { // link data + int i; ASSERT(sizeof(linkDataStruct) == 0x22); ovlData->arrayMsgRelHeader = (linkDataStruct *) mallocAndZero(ovlData->numMsgRelHeader * sizeof(linkDataStruct)); @@ -241,9 +235,30 @@ int loadOverlay(const char *scriptName) { return (-2); } - memcpy(ovlData->arrayMsgRelHeader, scriptPtr, ovlData->numMsgRelHeader * sizeof(linkDataStruct)); - scriptPtr += ovlData->numMsgRelHeader * sizeof(linkDataStruct); - flipGen(ovlData->arrayMsgRelHeader, ovlData->numMsgRelHeader * sizeof(linkDataStruct)); + for (i = 0; i < ovlData->numMsgRelHeader; i++) { + ovlData->arrayMsgRelHeader[i].type = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].id = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].offsetVerbeName = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].verbOverlay = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].verbNumber = s.readUint16BE(); + + ovlData->arrayMsgRelHeader[i].obj1Overlay = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].obj1Number = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].obj2Overlay = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].obj2Number = s.readUint16BE(); + + ovlData->arrayMsgRelHeader[i].trackX = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].trackY = s.readUint16BE(); + + ovlData->arrayMsgRelHeader[i].obj1NewState = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].obj2NewState = s.readUint16BE(); + + ovlData->arrayMsgRelHeader[i].obj1OldState = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].obj2OldState = s.readUint16BE(); + + ovlData->arrayMsgRelHeader[i].trackDirection = s.readUint16BE(); + ovlData->arrayMsgRelHeader[i].dialog = s.readUint16BE(); + } } if (ovlData->numProc) { // script @@ -251,53 +266,47 @@ int loadOverlay(const char *scriptName) { int i; ovlData->arrayProc = - (ovlData3Struct *) mallocAndZero(ovlData->numProc * - sizeof(ovlData3Struct)); + (ovlData3Struct *) mallocAndZero(ovlData->numProc * sizeof(ovlData3Struct)); if (!ovlData->arrayProc) { -/* releaseScript(scriptIdx,scriptName); - - if (freeIsNeeded) { - freePtr(unpackedBuffer); - } */ - return (-2); } - memcpy(ovlData->arrayProc, scriptPtr, - ovlData->numProc * sizeof(ovlData3Struct)); - scriptPtr += ovlData->numProc * 0x1C; - - flipGen(ovlData->arrayProc, - ovlData->numProc * sizeof(ovlData3Struct)); + for (i = 0; i < ovlData->numProc; i++) { + s.skip(4); + ovlData->arrayProc[i].dataPtr = NULL; + ovlData->arrayProc[i].sizeOfData = s.readUint16BE(); + ovlData->arrayProc[i].offsetToSubData3 = s.readUint16BE(); + ovlData->arrayProc[i].offsetToImportData = s.readUint16BE(); + ovlData->arrayProc[i].offsetToSubData2 = s.readUint16BE(); + ovlData->arrayProc[i].offsetToImportName = s.readUint16BE(); + ovlData->arrayProc[i].offsetToSubData5 = s.readUint16BE(); + ovlData->arrayProc[i].sysKey = s.readUint16BE(); + ovlData->arrayProc[i].var12 = s.readUint16BE(); + ovlData->arrayProc[i].numRelocGlob = s.readUint16BE(); + ovlData->arrayProc[i].subData2Size = s.readUint16BE(); + ovlData->arrayProc[i].var18 = s.readUint16BE(); + ovlData->arrayProc[i].var1A = s.readUint16BE(); + } tempPtr = ovlData->arrayProc; for (i = 0; i < ovlData->numProc; i++) { - uint8 *ptr = tempPtr->dataPtr = - (uint8 *) mallocAndZero(tempPtr->sizeOfData); - - if (!ptr) { - /* releaseScript(scriptIdx,scriptName); - * - * if (freeIsNeeded) - * { - * freePtr(unpackedBuffer); - * } */ + tempPtr->dataPtr = (uint8 *) mallocAndZero(tempPtr->sizeOfData); + if (!tempPtr->dataPtr) { return (-2); } - memcpy(ptr, scriptPtr, tempPtr->sizeOfData); - scriptPtr += tempPtr->sizeOfData; + s.read(tempPtr->dataPtr, tempPtr->sizeOfData); if (tempPtr->offsetToImportData) { - flipGen(ptr + tempPtr->offsetToImportData, + flipGen(tempPtr->dataPtr + tempPtr->offsetToImportData, tempPtr->numRelocGlob * 10); } if (tempPtr->offsetToSubData2) { - flipGen(ptr + tempPtr->offsetToImportData, + flipGen(tempPtr->dataPtr + tempPtr->offsetToSubData2, tempPtr->subData2Size * 10); } @@ -310,43 +319,47 @@ int loadOverlay(const char *scriptName) { int i; ovlData->ptr1 = - (uint8 *) mallocAndZero(ovlData->numRel * 0x1C); + (ovlData3Struct *) mallocAndZero(ovlData->numRel * sizeof(ovlData3Struct)); if (!ovlData->ptr1) { return (-2); } - memcpy(ovlData->ptr1, scriptPtr, ovlData->numRel * 0x1C); - scriptPtr += ovlData->numRel * 0x1C; - flipGen(ovlData->ptr1, ovlData->numRel * 0x1C); - + for (i = 0; i < ovlData->numRel; i++) { + s.skip(4); + ovlData->ptr1[i].dataPtr = NULL; + ovlData->ptr1[i].sizeOfData = s.readUint16BE(); + ovlData->ptr1[i].offsetToSubData3 = s.readUint16BE(); + ovlData->ptr1[i].offsetToImportData = s.readUint16BE(); + ovlData->ptr1[i].offsetToSubData2 = s.readUint16BE(); + ovlData->ptr1[i].offsetToImportName = s.readUint16BE(); + ovlData->ptr1[i].offsetToSubData5 = s.readUint16BE(); + ovlData->ptr1[i].sysKey = s.readUint16BE(); + ovlData->ptr1[i].var12 = s.readUint16BE(); + ovlData->ptr1[i].numRelocGlob = s.readUint16BE(); + ovlData->ptr1[i].subData2Size = s.readUint16BE(); + ovlData->ptr1[i].var18 = s.readUint16BE(); + ovlData->ptr1[i].var1A = s.readUint16BE(); + } + tempPtr = (ovlData3Struct *) ovlData->ptr1; for (i = 0; i < ovlData->numRel; i++) { - uint8 *ptr = tempPtr->dataPtr = - (uint8 *) mallocAndZero(tempPtr->sizeOfData); - - if (!ptr) { - /* releaseScript(scriptIdx,scriptName); - * - * if (freeIsNeeded) - * { - * freePtr(unpackedBuffer); - * } */ + tempPtr->dataPtr = (uint8 *) mallocAndZero(tempPtr->sizeOfData); + if (!tempPtr->dataPtr) { return (-2); } - memcpy(ptr, scriptPtr, tempPtr->sizeOfData); - scriptPtr += tempPtr->sizeOfData; + s.read(tempPtr->dataPtr, tempPtr->sizeOfData); if (tempPtr->offsetToImportData) { - flipGen(ptr + tempPtr->offsetToImportData, + flipGen(tempPtr->dataPtr + tempPtr->offsetToImportData, tempPtr->numRelocGlob * 10); } if (tempPtr->offsetToSubData2) { - flipGen(ptr + tempPtr->offsetToImportData, + flipGen(tempPtr->dataPtr + tempPtr->offsetToSubData2, tempPtr->subData2Size * 10); } @@ -367,8 +380,7 @@ int loadOverlay(const char *scriptName) { return (-2); } - memcpy(ovlData->ptr8, scriptPtr, ovlData->size12); - scriptPtr += ovlData->size12; + s.read(ovlData->ptr8, ovlData->size12); } if (ovlData->numObj) { @@ -378,47 +390,20 @@ int loadOverlay(const char *scriptName) { sizeof(objDataStruct)); if (!ovlData->arrayObject) { -/* releaseScript(scriptIdx,scriptName); - - if (freeIsNeeded) { - freePtr(unpackedBuffer); - } */ - return (-2); } for (i = 0; i < ovlData->numObj; i++) { - ovlData->arrayObject[i]._type = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->arrayObject[i]._type); - - int16 tempClass = *(int16 *) scriptPtr; - flipShort(&tempClass); - ovlData->arrayObject[i]._class = (eClass)tempClass; - scriptPtr += 2; - - ovlData->arrayObject[i]._nameOffset = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->arrayObject[i]._nameOffset); - - ovlData->arrayObject[i]._numStates = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->arrayObject[i]._numStates); - - ovlData->arrayObject[i]._varTableIdx = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->arrayObject[i]._varTableIdx); - - ovlData->arrayObject[i]._firstStateIdx = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->arrayObject[i]._firstStateIdx); - - ovlData->arrayObject[i]._stateTableIdx = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->arrayObject[i]._stateTableIdx); + ovlData->arrayObject[i]._type = s.readUint16BE(); + ovlData->arrayObject[i]._class = (eClass) s.readUint16BE(); + ovlData->arrayObject[i]._nameOffset = s.readUint16BE(); + ovlData->arrayObject[i]._numStates = s.readUint16BE(); + ovlData->arrayObject[i]._varTableIdx = s.readUint16BE(); + ovlData->arrayObject[i]._firstStateIdx = s.readUint16BE(); + ovlData->arrayObject[i]._stateTableIdx = s.readUint16BE(); } - // allocte states for object with multiple states + // allocate states for object with multiple states if (scriptNotLoadedBefore) { overlayTable[scriptIdx].state = stateID; @@ -430,38 +415,30 @@ int loadOverlay(const char *scriptName) { ovlData->arrayObjVar = (objectParams *) mallocAndZero(ovlData->size9 * sizeof(objectParams)); - memset(ovlData->arrayObjVar, 0, - ovlData->size9 * sizeof(objectParams)); if (!ovlData->arrayObjVar) { -/* releaseScript(scriptIdx,scriptName); - - if (freeIsNeeded) { - freePtr(unpackedBuffer); - } */ - return (-2); } } if (ovlData->size8) { + int i; ovlData->arrayStates = (objectParams *) mallocAndZero(ovlData->size8 * sizeof(objectParams)); if (!ovlData->arrayStates) { -/* releaseScript(scriptIdx,scriptName); - - if (freeIsNeeded) { - freePtr(unpackedBuffer); - } */ - return (-2); } - memcpy(ovlData->arrayStates, scriptPtr, ovlData->size8 * 12); // TODO: made read item by item - scriptPtr += ovlData->size8 * 12; - flipGen(ovlData->arrayStates, ovlData->size8 * 12); + for (i = 0; i < ovlData->size8; i++) { + ovlData->arrayStates[i].X = s.readUint16BE(); + ovlData->arrayStates[i].Y = s.readUint16BE(); + ovlData->arrayStates[i].Z = s.readUint16BE(); + ovlData->arrayStates[i].frame = s.readUint16BE(); + ovlData->arrayStates[i].scale = s.readUint16BE(); + ovlData->arrayStates[i].state = s.readUint16BE(); + } } if (ovlData->numStrings) { @@ -472,23 +449,15 @@ int loadOverlay(const char *scriptName) { sizeof(stringEntryStruct)); for (i = 0; i < ovlData->numStrings; i++) { - ovlData->stringTable[i].idx = *(int16 *) scriptPtr; - flipShort(&ovlData->stringTable[i].idx); - scriptPtr += 2; + ovlData->stringTable[i].idx = s.readUint16BE(); } } -/* if (freeIsNeeded) { - freePtr(unpackedBuffer); - } */ - if (ovlData->sizeOfData4) { ovlData->data4Ptr = (uint8 *) mallocAndZero(ovlData->sizeOfData4); - memset(ovlData->data4Ptr, 0, ovlData->sizeOfData4); if (!ovlData->data4Ptr) { - //releaseScript(scriptIdx,scriptName); return (-2); } } @@ -516,7 +485,7 @@ int loadOverlay(const char *scriptName) { unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2; // TODO: here, can unpack in gfx module buffer - unpackedBuffer = (char *)mallocAndZero(unpackedSize); + unpackedBuffer = (byte *)mallocAndZero(unpackedSize); if (!unpackedBuffer) { return (-2); @@ -538,12 +507,9 @@ int loadOverlay(const char *scriptName) { loadPakedFileToMem(fileIdx, (uint8 *) unpackedBuffer); } - scriptPtr = unpackedBuffer; - - memcpy(&ovlData->specialString1Length, scriptPtr, 2); - scriptPtr += 2; - flipShort(&ovlData->specialString1Length); // recheck if needed + Common::MemoryReadStream s2(unpackedBuffer, unpackedSize); + ovlData->specialString1Length = s2.readUint16BE(); if (ovlData->specialString1Length) { ovlData->nameVerbGlob = (char *) mallocAndZero(ovlData->specialString1Length); @@ -558,15 +524,10 @@ int loadOverlay(const char *scriptName) { return (-2); } - memcpy(ovlData->nameVerbGlob, scriptPtr, - ovlData->specialString1Length); - scriptPtr += ovlData->specialString1Length; + s2.read(ovlData->nameVerbGlob, ovlData->specialString1Length); } - memcpy(&ovlData->specialString2Length, scriptPtr, 2); - scriptPtr += 2; - flipShort(&ovlData->specialString2Length); // recheck if needed - + ovlData->specialString2Length = s2.readUint16BE(); if (ovlData->specialString2Length) { ovlData->arrayNameObj = (char *) mallocAndZero(ovlData->specialString2Length); @@ -581,15 +542,11 @@ int loadOverlay(const char *scriptName) { return (-2); } - memcpy(ovlData->arrayNameObj, scriptPtr, - ovlData->specialString2Length); - scriptPtr += ovlData->specialString2Length; + s2.read(ovlData->arrayNameObj, ovlData->specialString2Length); } for (i = 0; i < ovlData->numStrings; i++) { - ovlData->stringTable[i].length = *(int16 *) scriptPtr; - scriptPtr += 2; - flipShort(&ovlData->stringTable[i].length); + ovlData->stringTable[i].length = s2.readUint16BE(); if (ovlData->stringTable[i].length) { ovlData->stringTable[i].string = @@ -607,8 +564,7 @@ int loadOverlay(const char *scriptName) { return (-2); } - memcpy(ovlData->stringTable[i].string, scriptPtr, ovlData->stringTable[i].length); - scriptPtr += ovlData->stringTable[i].length; + s2.read(ovlData->stringTable[i].string, ovlData->stringTable[i].length); } } } diff --git a/engines/cruise/overlay.h b/engines/cruise/overlay.h index 7d8b2051e1..7ba90a1449 100644 --- a/engines/cruise/overlay.h +++ b/engines/cruise/overlay.h @@ -129,7 +129,7 @@ struct objectParams { struct ovlDataStruct { ovlData3Struct *arrayProc; - uint8 *ptr1; + ovlData3Struct *ptr1; objDataStruct *arrayObject; objectParams *arrayStates; objectParams *arrayObjVar; diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp index 63edf7cb36..3d8321e420 100644 --- a/engines/cruise/saveload.cpp +++ b/engines/cruise/saveload.cpp @@ -465,8 +465,7 @@ void saveCT(Common::OutSaveFile& currentSaveFile) { void loadSavegameDataSub6(Common::InSaveFile& currentSaveFile) { int32 var; - var = currentSaveFile.readUint32LE(); - flipLong(&var); + var = currentSaveFile.readUint32BE(); if (var) { int i; diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h index 5f65446cc5..692d1baeb6 100644 --- a/engines/cruise/vars.h +++ b/engines/cruise/vars.h @@ -91,8 +91,7 @@ struct dataFileName { }; struct setHeaderEntry { - int16 field_0; // offset ptr part 1 - int16 field_2; // offset ptr part 2 + int32 field_0; // offset ptr int16 width; int16 height; int16 type; // resource type, ie. sprites 0,1,4,5 and 8 |