2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cruise/cruise_main.h"
|
|
|
|
|
|
|
|
namespace Cruise {
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
exportEntryStruct *parseExport(int *out1, int *pExportedFuncionIdx, char *buffer) {
|
2007-04-27 22:33:45 +00:00
|
|
|
char localBuffer[256];
|
2007-11-10 17:15:48 +00:00
|
|
|
char functionName[256];
|
|
|
|
char overlayName[256];
|
2007-04-27 22:33:45 +00:00
|
|
|
char *dotPtr;
|
|
|
|
char *ptr2;
|
|
|
|
int idx;
|
2007-10-28 17:40:04 +00:00
|
|
|
int numSymbGlob;
|
2007-04-27 22:33:45 +00:00
|
|
|
exportEntryStruct *currentExportEntry;
|
2007-11-10 17:15:48 +00:00
|
|
|
char *entity1Name;
|
2007-04-27 22:33:45 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
*out1 = 0;
|
|
|
|
*pExportedFuncionIdx = 0;
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
strcpy(localBuffer, buffer);
|
2007-04-27 22:33:45 +00:00
|
|
|
dotPtr = strchr(localBuffer, '.');
|
|
|
|
|
|
|
|
if (dotPtr) {
|
2007-11-10 17:15:48 +00:00
|
|
|
strcpy(functionName, dotPtr + 1);
|
2007-04-27 22:33:45 +00:00
|
|
|
*dotPtr = 0;
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
strcpy(overlayName, localBuffer);
|
2007-04-27 22:33:45 +00:00
|
|
|
} else {
|
|
|
|
overlayName[0] = 0;
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
strcpy(functionName, buffer);
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr2 = strchr((char *)functionName, ':');
|
|
|
|
|
|
|
|
if (ptr2) {
|
|
|
|
*ptr2 = 0;
|
|
|
|
|
|
|
|
*out1 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strToUpper(overlayName);
|
|
|
|
strToUpper(functionName);
|
|
|
|
if (strlen((char *)overlayName) == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
idx = findOverlayByName2(overlayName);
|
|
|
|
|
|
|
|
if (idx == -4)
|
|
|
|
return (NULL);
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
if (overlayTable[idx].alreadyLoaded == 0)
|
|
|
|
return (NULL);
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
if (!overlayTable[idx].ovlData)
|
|
|
|
return (NULL);
|
|
|
|
|
2007-10-28 17:40:04 +00:00
|
|
|
numSymbGlob = overlayTable[idx].ovlData->numSymbGlob;
|
|
|
|
currentExportEntry = overlayTable[idx].ovlData->arraySymbGlob;
|
|
|
|
entity1Name = overlayTable[idx].ovlData->arrayNameSymbGlob;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (!entity1Name)
|
|
|
|
return (0);
|
|
|
|
|
2007-10-28 17:40:04 +00:00
|
|
|
for (i = 0; i < numSymbGlob; i++) {
|
2007-11-10 17:15:48 +00:00
|
|
|
char exportedName[256];
|
|
|
|
char *name = entity1Name + currentExportEntry->offsetToName;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
strcpy(exportedName, name);
|
2007-04-27 22:33:45 +00:00
|
|
|
strToUpper(exportedName);
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
if (!strcmp(functionName, exportedName)) {
|
2007-04-27 22:33:45 +00:00
|
|
|
*pExportedFuncionIdx = idx;
|
|
|
|
|
|
|
|
return (currentExportEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentExportEntry++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int updateScriptImport(int ovlIdx) {
|
|
|
|
char buffer[256];
|
|
|
|
ovlDataStruct *ovlData;
|
|
|
|
int numData3;
|
|
|
|
int size5;
|
2007-10-28 17:40:04 +00:00
|
|
|
int numRelocGlob;
|
2007-04-27 22:33:45 +00:00
|
|
|
int param;
|
|
|
|
int var_32;
|
|
|
|
ovlData3Struct *pScript;
|
2007-10-28 17:40:04 +00:00
|
|
|
// char* arrayRelocGlob;
|
2007-04-27 12:58:35 +00:00
|
|
|
// char* namePtr;
|
2007-10-28 17:40:04 +00:00
|
|
|
// char* arrayMsgRelHeader;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (!overlayTable[ovlIdx].ovlData)
|
|
|
|
return (-4);
|
|
|
|
|
|
|
|
ovlData = overlayTable[ovlIdx].ovlData;
|
|
|
|
|
2007-10-28 17:40:04 +00:00
|
|
|
numData3 = ovlData->numProc;
|
|
|
|
size5 = ovlData->numRel;
|
|
|
|
numRelocGlob = ovlData->numRelocGlob;
|
2007-04-27 22:33:45 +00:00
|
|
|
param = 0;
|
|
|
|
|
|
|
|
// do it for the 2 first string types
|
|
|
|
do {
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (param == 0) {
|
|
|
|
var_32 = numData3;
|
|
|
|
} else {
|
|
|
|
var_32 = size5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var_32) {
|
|
|
|
do {
|
|
|
|
importScriptStruct *ptrImportData;
|
2007-11-10 17:15:48 +00:00
|
|
|
const char *ptrImportName;
|
2007-04-27 22:33:45 +00:00
|
|
|
uint8 *ptrData;
|
|
|
|
|
|
|
|
int var_22 = 0;
|
|
|
|
|
|
|
|
if (param == 0) {
|
|
|
|
pScript = getOvlData3Entry(ovlIdx, i);
|
|
|
|
} else {
|
|
|
|
pScript = scriptFunc1Sub2(ovlIdx, i);
|
|
|
|
}
|
|
|
|
|
2009-01-16 02:43:41 +00:00
|
|
|
ptrImportData = (importScriptStruct *)(pScript->dataPtr + pScript->offsetToImportData); // import data
|
2007-11-10 17:15:48 +00:00
|
|
|
ptrImportName = (const char*)(pScript->dataPtr + pScript->offsetToImportName); // import name
|
2007-04-27 22:33:45 +00:00
|
|
|
ptrData = pScript->dataPtr;
|
|
|
|
|
|
|
|
var_22 = 0;
|
|
|
|
|
2007-10-28 17:40:04 +00:00
|
|
|
if (pScript->numRelocGlob > 0) {
|
|
|
|
int counter = pScript->numRelocGlob;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
do {
|
2007-11-10 17:15:48 +00:00
|
|
|
int param2 = ptrImportData->type;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (param2 != 70) {
|
2007-11-10 17:15:48 +00:00
|
|
|
exportEntryStruct * ptrDest2;
|
2007-04-27 22:33:45 +00:00
|
|
|
int out1;
|
|
|
|
int out2;
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
strcpy(buffer, ptrImportName + ptrImportData->offsetToName);
|
|
|
|
ptrDest2 = parseExport(&out1, &out2, buffer);
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (ptrDest2 && out2) {
|
|
|
|
int temp =
|
|
|
|
ptrImportData->
|
|
|
|
offset;
|
2007-09-10 13:17:20 +00:00
|
|
|
if (out1) { //is sub function... (ie 'invent.livre:s')
|
2007-04-27 22:33:45 +00:00
|
|
|
uint8 *ptr = ptrData + temp;
|
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
*(ptr + 1) = out2;
|
|
|
|
*(int16 *)(ptr + 2) = ptrDest2->idx;
|
|
|
|
|
|
|
|
flipShort((int16 *)(ptr + 2));
|
2007-04-27 22:33:45 +00:00
|
|
|
} else {
|
2007-09-10 13:17:20 +00:00
|
|
|
if (param2 == 20 || param2 == 30 || param2 == 40 || param2 == 50) { // this patch a double push
|
|
|
|
uint8 *ptr = ptrData + temp;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
*(ptr + 1) = 0;
|
|
|
|
*(ptr + 2) = out2; // update the overlay number
|
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
*(int16 *)(ptr + 4) = ptrDest2->idx;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
flipShort((int16 *)(ptr + 4));
|
2007-04-27 22:33:45 +00:00
|
|
|
} else {
|
|
|
|
int var_4 = ptrDest2->var4;
|
|
|
|
|
|
|
|
if (var_4 & 1) {
|
2007-09-10 13:17:20 +00:00
|
|
|
param2 = 8;
|
2007-04-27 22:33:45 +00:00
|
|
|
} else {
|
2007-09-10 13:17:20 +00:00
|
|
|
param2 = 16;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (var_4 >= 0 && var_4 <= 3) {
|
2007-09-10 13:17:20 +00:00
|
|
|
param2 |= 5;
|
2007-04-27 22:33:45 +00:00
|
|
|
} else {
|
2007-09-10 13:17:20 +00:00
|
|
|
param2 |= 6;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*(ptrData + temp) = param2;
|
|
|
|
*(ptrData + temp + 1) = out2;
|
|
|
|
|
2009-01-16 02:43:41 +00:00
|
|
|
*(int16 *)(ptrData + temp + 2) = ptrDest2->idx;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
flipShort
|
2009-01-16 02:43:41 +00:00
|
|
|
(
|
2007-04-27 22:33:45 +00:00
|
|
|
(int16
|
2009-01-16 02:43:41 +00:00
|
|
|
*)
|
2007-04-27 22:33:45 +00:00
|
|
|
(ptrData
|
2009-01-16 02:43:41 +00:00
|
|
|
+
|
|
|
|
temp
|
|
|
|
+
|
|
|
|
2));
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ptrImportData++;
|
|
|
|
} while (--counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (++i < var_32);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (++param < 2);
|
|
|
|
|
2007-10-28 17:40:04 +00:00
|
|
|
if (ovlData->arrayRelocGlob && ovlData->arrayNameRelocGlob && numRelocGlob) {
|
|
|
|
int numImport2 = numRelocGlob;
|
2007-04-27 22:33:45 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numImport2; i++) {
|
|
|
|
int out1;
|
|
|
|
int foundExportIdx;
|
|
|
|
exportEntryStruct *pFoundExport;
|
|
|
|
int linkType;
|
|
|
|
int linkEntryIdx;
|
|
|
|
|
2007-11-10 23:20:47 +00:00
|
|
|
strcpy(buffer, ovlData->arrayNameRelocGlob + ovlData->arrayRelocGlob[i].nameOffset);
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2007-11-10 23:20:47 +00:00
|
|
|
pFoundExport = parseExport(&out1, &foundExportIdx, buffer);
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2007-10-28 17:40:04 +00:00
|
|
|
linkType = ovlData->arrayRelocGlob[i].linkType;
|
|
|
|
linkEntryIdx = ovlData->arrayRelocGlob[i].linkIdx;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (pFoundExport && foundExportIdx) {
|
|
|
|
switch (linkType) {
|
2009-01-16 02:43:41 +00:00
|
|
|
case 0: { // verb
|
|
|
|
ovlData->arrayMsgRelHeader[linkEntryIdx].verbOverlay = foundExportIdx;
|
|
|
|
ovlData->arrayMsgRelHeader[linkEntryIdx].verbNumber = pFoundExport->idx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: { // obj1
|
|
|
|
ovlData->arrayMsgRelHeader[linkEntryIdx].obj1Overlay = foundExportIdx;
|
|
|
|
ovlData->arrayMsgRelHeader[linkEntryIdx].obj1Number = pFoundExport->idx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: { // obj2
|
|
|
|
ovlData->arrayMsgRelHeader[linkEntryIdx].obj2Overlay = foundExportIdx;
|
|
|
|
ovlData->arrayMsgRelHeader[linkEntryIdx].obj2Number = pFoundExport->idx;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check that the newly loaded isn't used by the already loaded overlays
|
2007-04-27 22:33:45 +00:00
|
|
|
void updateAllScriptsImports(void) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 90; i++) {
|
|
|
|
if (overlayTable[i].ovlData && overlayTable[i].alreadyLoaded) {
|
|
|
|
updateScriptImport(i);
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Cruise
|