2012-04-25 23:43:55 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2012-05-20 06:11:25 +00:00
|
|
|
/*
|
|
|
|
* This code is based on original Tony Tough source code
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997-2003 Nayma Software
|
|
|
|
*/
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
#include "lzo1x.h"
|
|
|
|
*/
|
|
|
|
#include "mpal.h"
|
|
|
|
#include "mpaldll.h"
|
2012-04-29 13:19:30 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "tony/tony.h"
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
namespace Tony {
|
|
|
|
|
|
|
|
namespace MPAL {
|
|
|
|
|
|
|
|
/****************************************************************************\
|
|
|
|
* Funzioni statiche
|
|
|
|
\****************************************************************************/
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
static bool compareCommands(struct command *cmd1, struct command *cmd2) {
|
2012-04-25 23:43:55 +00:00
|
|
|
if (cmd1->type == 2 && cmd2->type == 2) {
|
2012-05-04 13:38:34 +00:00
|
|
|
if (strcmp(cmd1->lpszVarName, cmd2->lpszVarName) == 0 &&
|
2012-06-07 19:14:59 +00:00
|
|
|
compareExpressions(cmd1->expr, cmd2->expr))
|
2012-04-25 23:43:55 +00:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
} else
|
2012-05-04 14:29:44 +00:00
|
|
|
return (memcmp(cmd1, cmd2, sizeof(struct command)) == 0);
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/**
|
2012-05-19 09:05:57 +00:00
|
|
|
* Parses a script from the MPC file, and inserts its data into a structure
|
2012-05-19 02:33:14 +00:00
|
|
|
*
|
|
|
|
* @param lpBuf Buffer containing the compiled script.
|
|
|
|
* @param lpmsScript Pointer to a structure that will be filled with the
|
|
|
|
* data of the script.
|
|
|
|
* @returns Pointer to the buffer after the item, or NULL on failure.
|
|
|
|
*/
|
2012-05-04 14:29:44 +00:00
|
|
|
static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) {
|
2012-05-22 22:19:46 +00:00
|
|
|
int curCmd, j, len;
|
2012-04-25 23:43:55 +00:00
|
|
|
uint i;
|
|
|
|
|
2012-05-14 10:21:54 +00:00
|
|
|
lpmsScript->nObj = (int32)READ_LE_UINT32(lpBuf);
|
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-14 10:21:54 +00:00
|
|
|
lpmsScript->nMoments = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
curCmd = 0;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
for (i = 0; i < lpmsScript->nMoments; i++) {
|
2012-05-22 22:19:46 +00:00
|
|
|
lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf);
|
|
|
|
lpBuf += 4;
|
|
|
|
lpmsScript->Moment[i].nCmds = *lpBuf;
|
|
|
|
lpBuf++;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
for (j = 0; j < lpmsScript->Moment[i].nCmds; j++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].type = *lpBuf;
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
switch (lpmsScript->_command[curCmd].type) {
|
2012-04-25 23:43:55 +00:00
|
|
|
case 1:
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].nCf = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // Variable assign
|
2012-05-22 22:19:46 +00:00
|
|
|
len = *lpBuf;
|
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1);
|
|
|
|
if (lpmsScript->_command[curCmd].lpszVarName == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
2012-06-07 19:14:59 +00:00
|
|
|
copyMemory(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += len;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
lpBuf = parseExpression(lpBuf, &lpmsScript->_command[curCmd].expr);
|
2012-05-19 02:33:14 +00:00
|
|
|
if (lpBuf == NULL)
|
2012-05-22 22:19:46 +00:00
|
|
|
return NULL;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
lpmsScript->Moment[i].CmdNum[j] = curCmd;
|
2012-04-25 23:43:55 +00:00
|
|
|
curCmd++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lpBuf;
|
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/**
|
2012-05-19 09:05:57 +00:00
|
|
|
* Parses a dialog from the MPC file, and inserts its data into a structure
|
2012-05-19 02:33:14 +00:00
|
|
|
*
|
|
|
|
* @param lpBuf Buffer containing the compiled dialog.
|
|
|
|
* @param lpmdDialog Pointer to a structure that will be filled with the
|
|
|
|
* data of the dialog.
|
|
|
|
* @returns Pointer to the buffer after the item, or NULL on failure.
|
|
|
|
*/
|
2012-06-07 19:14:59 +00:00
|
|
|
static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) {
|
2012-05-19 02:33:14 +00:00
|
|
|
uint32 i, j, z, kk;
|
|
|
|
uint32 num, num2, num3;
|
2012-04-25 23:43:55 +00:00
|
|
|
byte *lpLock;
|
|
|
|
uint32 curCmd;
|
|
|
|
uint32 len;
|
|
|
|
|
2012-05-22 22:19:46 +00:00
|
|
|
lpmdDialog->nObj = READ_LE_UINT32(lpBuf);
|
|
|
|
lpBuf += 4;
|
2012-05-04 14:35:16 +00:00
|
|
|
|
2012-04-25 23:43:55 +00:00
|
|
|
/* Periodi */
|
2012-05-22 22:19:46 +00:00
|
|
|
num = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (num >= MAX_PERIODS_PER_DIALOG - 1)
|
|
|
|
error("Too much periods in dialog #%d", lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_periodNums[i] = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-06-08 13:00:48 +00:00
|
|
|
lpmdDialog->_periods[i] = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1);
|
2012-06-07 19:14:59 +00:00
|
|
|
lpLock = (byte *)globalLock(lpmdDialog->_periods[i]);
|
2012-05-04 13:38:34 +00:00
|
|
|
Common::copy(lpBuf + 1, lpBuf + 1 + *lpBuf, lpLock);
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(lpmdDialog->_periods[i]);
|
2012-05-04 13:38:34 +00:00
|
|
|
lpBuf += (*lpBuf) + 1;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_periodNums[i] = 0;
|
|
|
|
lpmdDialog->_periods[i] = NULL;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
/* Gruppi */
|
2012-05-22 22:19:46 +00:00
|
|
|
num = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-05-04 13:38:34 +00:00
|
|
|
curCmd = 0;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (num >= MAX_GROUPS_PER_DIALOG)
|
|
|
|
error("Too much groups in dialog #%d", lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_group[i].num = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_group[i].nCmds = *lpBuf; lpBuf++;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
if (lpmdDialog->_group[i].nCmds >= MAX_COMMANDS_PER_GROUP)
|
|
|
|
error("Too much commands in group #%d in dialog #%d",lpmdDialog->_group[i].num,lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
for (j = 0; j < lpmdDialog->_group[i].nCmds; j++) {
|
|
|
|
lpmdDialog->_command[curCmd].type = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
switch (lpmdDialog->_command[curCmd].type) {
|
2012-04-25 23:43:55 +00:00
|
|
|
// Call custom function
|
|
|
|
case 1:
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].nCf = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].arg1 = READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].arg2 = READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].arg3 = READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].arg4 = READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Variable assign
|
|
|
|
case 2:
|
2012-05-04 13:38:34 +00:00
|
|
|
len = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1);
|
|
|
|
if (lpmdDialog->_command[curCmd].lpszVarName == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
Common::copy(lpBuf, lpBuf + len, lpmdDialog->_command[curCmd].lpszVarName);
|
2012-05-04 13:38:34 +00:00
|
|
|
lpBuf += len;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
lpBuf = parseExpression(lpBuf, &lpmdDialog->_command[curCmd].expr);
|
2012-05-04 13:38:34 +00:00
|
|
|
if (lpBuf == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Do Choice
|
|
|
|
case 3:
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_command[curCmd].nChoice = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
for (kk = 0;kk < curCmd; kk++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
if (compareCommands(&lpmdDialog->_command[kk], &lpmdDialog->_command[curCmd])) {
|
|
|
|
lpmdDialog->_group[i].CmdNum[j] = kk;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
if (kk == curCmd) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_group[i].CmdNum[j] = curCmd;
|
2012-04-25 23:43:55 +00:00
|
|
|
curCmd++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (curCmd >= MAX_COMMANDS_PER_DIALOG)
|
|
|
|
error("Too much commands in dialog #%d",lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
/* Choices */
|
2012-05-22 22:19:46 +00:00
|
|
|
num = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (num >= MAX_CHOICES_PER_DIALOG)
|
|
|
|
error("Too much choices in dialog #%d",lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i].nChoice = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
num2 = *lpBuf++;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (num2 >= MAX_SELECTS_PER_CHOICE)
|
2012-06-07 19:14:59 +00:00
|
|
|
error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
for (j = 0; j < num2; j++) {
|
2012-04-25 23:43:55 +00:00
|
|
|
// When
|
|
|
|
switch (*lpBuf++) {
|
|
|
|
case 0:
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i]._select[j].when = NULL;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2012-06-07 19:14:59 +00:00
|
|
|
lpBuf = parseExpression(lpBuf, &lpmdDialog->_choice[i]._select[j].when);
|
2012-05-04 13:38:34 +00:00
|
|
|
if (lpBuf == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attrib
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i]._select[j].attr = *lpBuf++;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
// Data
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i]._select[j].dwData = READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
// PlayGroup
|
2012-06-02 00:39:00 +00:00
|
|
|
num3 = *lpBuf++;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-02 00:39:00 +00:00
|
|
|
if (num3 >= MAX_PLAYGROUPS_PER_SELECT)
|
2012-06-07 19:14:59 +00:00
|
|
|
error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 13:38:34 +00:00
|
|
|
for (z = 0; z < num3; z++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i]._select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i]._select[j].wPlayGroup[num3] = 0;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Mark the last selection
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[i]._select[num2].dwData = 0;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmdDialog->_choice[num].nChoice = 0;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
return lpBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/**
|
2012-05-19 09:05:57 +00:00
|
|
|
* Parses an item from the MPC file, and inserts its data into a structure
|
2012-05-19 02:33:14 +00:00
|
|
|
*
|
|
|
|
* @param lpBuf Buffer containing the compiled dialog.
|
|
|
|
* @param lpmiItem Pointer to a structure that will be filled with the
|
|
|
|
* data of the item.
|
|
|
|
* @returns Pointer to the buffer after the item, or NULL on failure.
|
|
|
|
* @remarks It's necessary that the structure that is passed has been
|
|
|
|
* completely initialised to 0 beforehand.
|
|
|
|
*/
|
2012-06-07 19:14:59 +00:00
|
|
|
static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) {
|
2012-04-25 23:43:55 +00:00
|
|
|
byte len;
|
2012-05-19 02:33:14 +00:00
|
|
|
uint32 i, j, kk;
|
2012-04-25 23:43:55 +00:00
|
|
|
uint32 curCmd;
|
|
|
|
|
2012-05-14 10:21:54 +00:00
|
|
|
lpmiItem->nObj = (int32)READ_LE_UINT32(lpBuf);
|
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
len = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
copyMemory(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len));
|
2012-05-19 02:33:14 +00:00
|
|
|
lpBuf += len;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (len >= MAX_DESCRIBE_SIZE)
|
2012-05-19 02:33:14 +00:00
|
|
|
error("Describe too long in item #%d", lpmiItem->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
lpmiItem->nActions=*lpBuf;
|
|
|
|
lpBuf++;
|
|
|
|
|
|
|
|
/* Alloca le azioni */
|
2012-05-19 02:33:14 +00:00
|
|
|
if (lpmiItem->nActions > 0)
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
curCmd = 0;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
for (i = 0; i < lpmiItem->nActions; i++) {
|
|
|
|
lpmiItem->Action[i].num = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
|
|
|
|
2012-05-14 10:21:54 +00:00
|
|
|
lpmiItem->Action[i].wParm = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
if (lpmiItem->Action[i].num == 0xFF) {
|
2012-05-14 10:21:54 +00:00
|
|
|
lpmiItem->Action[i].wTime = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
lpmiItem->Action[i].perc = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
if (*lpBuf == 0) {
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
2012-05-19 02:33:14 +00:00
|
|
|
lpmiItem->Action[i].when = NULL;
|
2012-04-25 23:43:55 +00:00
|
|
|
} else {
|
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpBuf = parseExpression(lpBuf,&lpmiItem->Action[i].when);
|
2012-05-04 14:29:44 +00:00
|
|
|
if (lpBuf == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpmiItem->Action[i].nCmds=*lpBuf;
|
|
|
|
lpBuf++;
|
|
|
|
|
2012-05-08 14:42:27 +00:00
|
|
|
if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION)
|
|
|
|
error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
for (j = 0; j < lpmiItem->Action[i].nCmds; j++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].type = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
switch (lpmiItem->_command[curCmd].type) {
|
2012-04-25 23:43:55 +00:00
|
|
|
case 1: // Call custom function
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].nCf = READ_LE_UINT16(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 2;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf);
|
2012-05-22 22:19:46 +00:00
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // Variable assign
|
2012-05-19 02:33:14 +00:00
|
|
|
len = *lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
lpmiItem->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1);
|
|
|
|
if (lpmiItem->_command[curCmd].lpszVarName == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
2012-06-07 19:14:59 +00:00
|
|
|
copyMemory(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len);
|
2012-05-19 02:33:14 +00:00
|
|
|
lpBuf += len;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
lpBuf = parseExpression(lpBuf, &lpmiItem->_command[curCmd].expr);
|
2012-05-19 02:33:14 +00:00
|
|
|
if (lpBuf == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
for (kk = 0; kk < curCmd; kk++) {
|
2012-06-07 19:14:59 +00:00
|
|
|
if (compareCommands(&lpmiItem->_command[kk], &lpmiItem->_command[curCmd])) {
|
2012-05-19 02:33:14 +00:00
|
|
|
lpmiItem->Action[i].CmdNum[j] = kk;
|
2012-04-25 23:43:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 22:19:46 +00:00
|
|
|
if (kk == curCmd) {
|
2012-05-19 02:33:14 +00:00
|
|
|
lpmiItem->Action[i].CmdNum[j] = curCmd;
|
2012-04-25 23:43:55 +00:00
|
|
|
curCmd++;
|
|
|
|
|
|
|
|
if (curCmd >= MAX_COMMANDS_PER_ITEM) {
|
2012-05-08 14:42:27 +00:00
|
|
|
error("Too much commands in item #%d",lpmiItem->nObj);
|
|
|
|
//curCmd=0;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 22:19:46 +00:00
|
|
|
lpmiItem->dwRes = READ_LE_UINT32(lpBuf);
|
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
return lpBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/**
|
2012-05-19 09:05:57 +00:00
|
|
|
* Parses a location from the MPC file, and inserts its data into a structure
|
2012-05-19 02:33:14 +00:00
|
|
|
*
|
|
|
|
* @param lpBuf Buffer containing the compiled location.
|
|
|
|
* @param lpmiLocation Pointer to a structure that will be filled with the
|
|
|
|
* data of the location.
|
|
|
|
* @returns Pointer to the buffer after the location, or NULL on failure.
|
|
|
|
*/
|
2012-05-04 14:29:44 +00:00
|
|
|
static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) {
|
2012-05-14 10:21:54 +00:00
|
|
|
lpmlLocation->nObj = (int32)READ_LE_UINT32(lpBuf);
|
|
|
|
lpBuf += 4;
|
|
|
|
lpmlLocation->dwXlen = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
|
|
|
lpmlLocation->dwYlen = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-05-22 22:19:46 +00:00
|
|
|
lpmlLocation->dwPicRes = READ_LE_UINT32(lpBuf);
|
2012-05-14 10:21:54 +00:00
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
return lpBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************\
|
2012-05-19 02:33:14 +00:00
|
|
|
* Exported functions
|
2012-04-25 23:43:55 +00:00
|
|
|
\****************************************************************************/
|
2012-05-19 02:33:14 +00:00
|
|
|
/**
|
|
|
|
* @defgroup Exported functions
|
|
|
|
*/
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/**
|
|
|
|
* Reads and interprets the MPC file, and create structures for various directives
|
|
|
|
* in the global variables
|
|
|
|
*
|
|
|
|
* @param lpBuf Buffer containing the MPC file data, excluding the header.
|
|
|
|
* @returns True if succeeded OK, false if failure.
|
|
|
|
*/
|
2012-05-04 14:29:44 +00:00
|
|
|
bool ParseMpc(const byte *lpBuf) {
|
2012-05-04 12:28:51 +00:00
|
|
|
uint16 i, j;
|
2012-04-25 23:43:55 +00:00
|
|
|
uint16 wLen;
|
|
|
|
byte *lpTemp, *lpTemp2;
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/* 1. Variables */
|
2012-05-04 14:29:44 +00:00
|
|
|
if (lpBuf[0] != 'V' || lpBuf[1] != 'A' || lpBuf[2] != 'R' || lpBuf[3] != 'S')
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 4;
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nVars = READ_LE_UINT16(lpBuf);
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.hVars = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars);
|
2012-05-13 13:44:08 +00:00
|
|
|
if (GLOBALS.hVars == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
GLOBALS.lpmvVars = (LPMPALVAR)globalLock(GLOBALS.hVars);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-13 13:44:08 +00:00
|
|
|
for (i = 0; i < GLOBALS.nVars; i++) {
|
2012-05-04 14:40:23 +00:00
|
|
|
wLen = *(const byte *)lpBuf;
|
2012-04-25 23:43:55 +00:00
|
|
|
lpBuf++;
|
2012-06-07 19:14:59 +00:00
|
|
|
copyMemory(GLOBALS.lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32));
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += wLen;
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.lpmvVars->dwVal = READ_LE_UINT32(lpBuf);
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 4;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
lpBuf++; // Salta 'ext'
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.lpmvVars++;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.hVars);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/* 2. Messages */
|
2012-05-04 14:29:44 +00:00
|
|
|
if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S')
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 4;
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nMsgs = READ_LE_UINT16(lpBuf);
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
#ifdef NEED_LOCK_MSGS
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.hMsgs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs);
|
2012-05-13 13:44:08 +00:00
|
|
|
if (GLOBALS.hMsgs == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
GLOBALS.lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs);
|
2012-04-25 23:43:55 +00:00
|
|
|
#else
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)GLOBALS.nMsgs);
|
|
|
|
if (GLOBALS.lpmmMsgs==NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
2012-05-13 13:44:08 +00:00
|
|
|
for (i = 0; i < GLOBALS.nMsgs; i++) {
|
|
|
|
GLOBALS.lpmmMsgs->wNum = READ_LE_UINT16(lpBuf);
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
for (j = 0; lpBuf[j] != 0;)
|
|
|
|
j += lpBuf[j] + 1;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.lpmmMsgs->hText = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1);
|
2012-06-07 19:14:59 +00:00
|
|
|
lpTemp2 = lpTemp = (byte *)globalLock(GLOBALS.lpmmMsgs->hText);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
for (j = 0; lpBuf[j] != 0;) {
|
2012-06-07 19:14:59 +00:00
|
|
|
copyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]);
|
2012-05-04 14:29:44 +00:00
|
|
|
lpTemp += lpBuf[j];
|
|
|
|
*lpTemp ++= '\0';
|
|
|
|
j += lpBuf[j] + 1;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += j + 1;
|
|
|
|
*lpTemp = '\0';
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.lpmmMsgs->hText);
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.lpmmMsgs++;
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEED_LOCK_MSGS
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.hMsgs);
|
2012-04-25 23:43:55 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
/* 3. Objects */
|
2012-05-04 14:29:44 +00:00
|
|
|
if (lpBuf[0] != 'O' || lpBuf[1] != 'B' || lpBuf[2] != 'J' || lpBuf[3] != 'S')
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 4;
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nObjs = READ_LE_UINT16(lpBuf);
|
2012-05-04 14:29:44 +00:00
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Check out the dialogs
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nDialogs = 0;
|
|
|
|
GLOBALS.hDialogs = GLOBALS.lpmdDialogs = NULL;
|
2012-05-04 14:29:44 +00:00
|
|
|
if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) {
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.hDialogs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG));
|
2012-05-13 13:44:08 +00:00
|
|
|
if (GLOBALS.hDialogs == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
GLOBALS.lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-13 13:44:08 +00:00
|
|
|
for (i = 0;i < GLOBALS.nDialogs; i++)
|
2012-06-07 19:14:59 +00:00
|
|
|
if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS.lpmdDialogs[i])) == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.hDialogs);
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Check the items
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nItems = 0;
|
|
|
|
GLOBALS.hItems = GLOBALS.lpmiItems = NULL;
|
2012-05-04 14:29:44 +00:00
|
|
|
if (*(lpBuf + 2) == 4 && strncmp((const char *)lpBuf + 3, "Item", 4)==0) {
|
2012-05-22 22:19:46 +00:00
|
|
|
GLOBALS.nItems = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Allocate memory and read them in
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.hItems = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM));
|
2012-05-13 13:44:08 +00:00
|
|
|
if (GLOBALS.hItems == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
GLOBALS.lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-13 13:44:08 +00:00
|
|
|
for (i = 0; i < GLOBALS.nItems; i++)
|
2012-06-07 19:14:59 +00:00
|
|
|
if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS.lpmiItems[i])) == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.hItems);
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Check the locations
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nLocations = 0;
|
|
|
|
GLOBALS.hLocations = GLOBALS.lpmlLocations = NULL;
|
2012-05-22 22:19:46 +00:00
|
|
|
if (*(lpBuf + 2) == 8 && strncmp((const char *)lpBuf + 3, "Location", 8) == 0) {
|
|
|
|
GLOBALS.nLocations = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Allocate memory and read them in
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.hLocations = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION));
|
2012-05-13 13:44:08 +00:00
|
|
|
if (GLOBALS.hLocations == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
GLOBALS.lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS.hLocations);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-13 13:44:08 +00:00
|
|
|
for (i = 0; i < GLOBALS.nLocations; i++)
|
|
|
|
if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS.lpmlLocations[i])) == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.hLocations);
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Check the scripts
|
2012-05-13 13:44:08 +00:00
|
|
|
GLOBALS.nScripts = 0;
|
|
|
|
GLOBALS.hScripts = GLOBALS.lpmsScripts = NULL;
|
2012-05-04 14:29:44 +00:00
|
|
|
if (*(lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Script", 6) == 0) {
|
2012-05-22 22:19:46 +00:00
|
|
|
GLOBALS.nScripts = READ_LE_UINT16(lpBuf);
|
|
|
|
lpBuf += 2;
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Allocate memory
|
2012-06-08 13:00:48 +00:00
|
|
|
GLOBALS.hScripts = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT));
|
2012-05-13 13:44:08 +00:00
|
|
|
if (GLOBALS.hScripts == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
GLOBALS.lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts);
|
2012-04-25 23:43:55 +00:00
|
|
|
|
2012-05-13 13:44:08 +00:00
|
|
|
for (i = 0; i < GLOBALS.nScripts; i++) {
|
|
|
|
if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS.lpmsScripts[i])) == NULL)
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
2012-05-19 02:33:14 +00:00
|
|
|
// Sort the various moments of the script
|
2012-04-25 23:43:55 +00:00
|
|
|
//qsort(
|
2012-05-13 13:44:08 +00:00
|
|
|
//GLOBALS.lpmsScripts[i].Moment,
|
|
|
|
//GLOBALS.lpmsScripts[i].nMoments,
|
|
|
|
//sizeof(GLOBALS.lpmsScripts[i].Moment[0]),
|
2012-04-25 23:43:55 +00:00
|
|
|
//(int (*)(const void *, const void *))CompareMoments
|
|
|
|
//);
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:14:59 +00:00
|
|
|
globalUnlock(GLOBALS.hScripts);
|
2012-04-25 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 14:29:44 +00:00
|
|
|
if (lpBuf[0] != 'E' || lpBuf[1] != 'N' || lpBuf[2] != 'D' || lpBuf[3] != '0')
|
2012-04-25 23:43:55 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace MPAL
|
|
|
|
|
|
|
|
} // end of namespace Tony
|