aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm
diff options
context:
space:
mode:
authorEugene Sandulenko2016-05-26 10:56:03 +0200
committerEugene Sandulenko2016-05-26 12:16:04 +0200
commit056c5a7ae71128cbbe55dcf45a8989e71f7d9ae5 (patch)
tree440fb4ea509eb444c89e7c9e3a2a711cd664ca24 /engines/scumm
parentd035e960144fba6cf2ae2db76833fa1e3f14d41f (diff)
downloadscummvm-rg350-056c5a7ae71128cbbe55dcf45a8989e71f7d9ae5.tar.gz
scummvm-rg350-056c5a7ae71128cbbe55dcf45a8989e71f7d9ae5.tar.bz2
scummvm-rg350-056c5a7ae71128cbbe55dcf45a8989e71f7d9ae5.zip
SCUMM HE: Fixed SCUMM wrapper for nuking array in U32.
This was leading to an out of bounds assert.
Diffstat (limited to 'engines/scumm')
-rw-r--r--engines/scumm/he/moonbase/ai_main.cpp38
-rw-r--r--engines/scumm/he/moonbase/ai_targetacquisition.cpp6
-rw-r--r--engines/scumm/he/moonbase/moonbase.cpp8
-rw-r--r--engines/scumm/he/moonbase/moonbase.h1
-rw-r--r--engines/scumm/he/script_v72he.cpp2
5 files changed, 31 insertions, 24 deletions
diff --git a/engines/scumm/he/moonbase/ai_main.cpp b/engines/scumm/he/moonbase/ai_main.cpp
index 554d2eeb06..d34a5c163a 100644
--- a/engines/scumm/he/moonbase/ai_main.cpp
+++ b/engines/scumm/he/moonbase/ai_main.cpp
@@ -407,7 +407,7 @@ int masterControlProgram(const int paramCount, const int32 *params) {
nextBuilding = _vm->_moonbase->readFromArray(unitsArray, 0, unitsCounter);
}
- _vm->nukeArray(unitsArray);
+ _vm->_moonbase->deallocateArray(unitsArray);
if (!balloonFlag) {
launchAction = new int[4];
@@ -907,7 +907,7 @@ int masterControlProgram(const int paramCount, const int32 *params) {
opponentBuilding = _vm->_moonbase->readFromArray(nearbyOpponents, 0, opponentCounter);
}
- _vm->nukeArray(nearbyOpponents);
+ _vm->_moonbase->deallocateArray(nearbyOpponents);
if (defenseOn && defenseOff) {
if (!_vm->_rnd.getRandomNumber(1)) {
@@ -1164,7 +1164,7 @@ int chooseBehavior() {
energyBuilding = _vm->_moonbase->readFromArray(energyUnits, 0, energyCounter);
}
- _vm->nukeArray(energyUnits);
+ _vm->_moonbase->deallocateArray(energyUnits);
if (energyCount < poolMaxCount) {
int closestHub = getClosestUnit(poolX, poolY, 300, currentPlayer, 1, BUILDING_MAIN_BASE, 1);
@@ -1257,7 +1257,7 @@ int chooseBehavior() {
defenseBuilding = _vm->_moonbase->readFromArray(defArray, 0, defCounter);
}
- _vm->nukeArray(defArray);
+ _vm->_moonbase->deallocateArray(defArray);
if (!numDefenders) {
int defArray2 = getUnitsWithinRadius(hubX, hubY, 170);
@@ -1276,7 +1276,7 @@ int chooseBehavior() {
defenseBuilding2 = _vm->_moonbase->readFromArray(defArray, 0, defCounter);
}
- _vm->nukeArray(defArray2);
+ _vm->_moonbase->deallocateArray(defArray2);
}
@@ -1314,7 +1314,7 @@ int chooseBehavior() {
}
}
- _vm->nukeArray(enemyArray);
+ _vm->_moonbase->deallocateArray(enemyArray);
offCon--;
}
@@ -1363,7 +1363,7 @@ int chooseBehavior() {
closeBuilding = _vm->_moonbase->readFromArray(closeBuildingsArray, 0, closeBuildingCounter);
}
- _vm->nukeArray(closeBuildingsArray);
+ _vm->_moonbase->deallocateArray(closeBuildingsArray);
int defCounter = 0;
int defArray = getUnitsWithinRadius(hubX, hubY, 170);
@@ -1382,7 +1382,7 @@ int chooseBehavior() {
defenseBuilding = _vm->_moonbase->readFromArray(defArray, 0, defCounter);
}
- _vm->nukeArray(defArray);
+ _vm->_moonbase->deallocateArray(defArray);
if (numDefenders > 2)
defCon++;
@@ -1481,7 +1481,7 @@ int chooseTarget(int behavior1) {
thisPoolUnit = _vm->_moonbase->readFromArray(poolUnitsArray, 0, j);
}
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
// if enemy collector, put at bottom
if (enemyPool) {
@@ -1532,7 +1532,7 @@ int chooseTarget(int behavior1) {
if ((getTerrain(getHubX(thisBuilding), getHubY(thisBuilding)) != TERRAIN_TYPE_WATER) || (getPlayerEnergy() > 6)) {
if (getClosestUnit(getHubX(thisBuilding), getHubY(thisBuilding), 380, currentPlayer, 1, BUILDING_MAIN_BASE, 1)) {
returnBuilding = thisBuilding;
- _vm->nukeArray(enemyArray);
+ _vm->_moonbase->deallocateArray(enemyArray);
return returnBuilding;
}
} else {
@@ -1558,7 +1558,7 @@ int chooseTarget(int behavior1) {
}
}
- _vm->nukeArray(enemyArray);
+ _vm->_moonbase->deallocateArray(enemyArray);
if (attackableIndex) {
int thisWorth = 0;
@@ -1718,7 +1718,7 @@ int chooseTarget(int behavior1) {
defenseBuilding = _vm->_moonbase->readFromArray(defenseArray, 0, j);
}
- _vm->nukeArray(defenseArray);
+ _vm->_moonbase->deallocateArray(defenseArray);
// Calculate if this unit is attackable
// get dist to nearest enemy hub, offense
@@ -1925,7 +1925,7 @@ Tree *initAcquireTarget(int targetX, int targetY, Node **retNode) {
int thisElement = _vm->_moonbase->readFromArray(unitsArray, 0, 0);
- _vm->nukeArray(unitsArray);
+ _vm->_moonbase->deallocateArray(unitsArray);
if (!thisElement) {
delete myBaseTarget;
@@ -2062,7 +2062,7 @@ int *energizeTarget(int &targetX, int &targetY, int index) {
}
if (poolUnitsArray)
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
poolUnitsArray = getUnitsWithinRadius(targetX, targetY, 450);
assert(poolUnitsArray);
@@ -2175,14 +2175,14 @@ int *energizeTarget(int &targetX, int &targetY, int index) {
if (nextUnit <= 0)
retVal[0] = 0;
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
poolUnitsArray = 0;
return retVal;
}
}
if (result > 0) {
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
poolUnitsArray = 0;
targetX = xPos;
@@ -2205,7 +2205,7 @@ int *energizeTarget(int &targetX, int &targetY, int index) {
} else {
int *retVal = new int[4];
retVal[0] = 0;
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
poolUnitsArray = 0;
return retVal;
@@ -2224,12 +2224,12 @@ int *energizeTarget(int &targetX, int &targetY, int index) {
j = 0;
}
} else {
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
poolUnitsArray = 0;
return NULL;
}
- _vm->nukeArray(poolUnitsArray);
+ _vm->_moonbase->deallocateArray(poolUnitsArray);
poolUnitsArray = 0;
int *retVal = new int[4];
retVal[0] = 0;
diff --git a/engines/scumm/he/moonbase/ai_targetacquisition.cpp b/engines/scumm/he/moonbase/ai_targetacquisition.cpp
index fb74d8ae3c..253142a82f 100644
--- a/engines/scumm/he/moonbase/ai_targetacquisition.cpp
+++ b/engines/scumm/he/moonbase/ai_targetacquisition.cpp
@@ -361,7 +361,7 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
}
}
- _vm->nukeArray(unitsArray);
+ _vm->_moonbase->deallocateArray(unitsArray);
//Check if repair is needed
int targetUnit = getClosestUnit(targetX + 5, targetY, 15, currentPlayer, 1, 0, 0, 0);
@@ -384,7 +384,7 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
}
}
- _vm->nukeArray(unitsArray);
+ _vm->_moonbase->deallocateArray(unitsArray);
if (defCount) {
//repair
@@ -480,7 +480,7 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
setPower(power);
setAngle(angle);
- _vm->nukeArray(unitsArray2);
+ _vm->_moonbase->deallocateArray(unitsArray2);
return 1;
}
diff --git a/engines/scumm/he/moonbase/moonbase.cpp b/engines/scumm/he/moonbase/moonbase.cpp
index d7069e73d8..833d84706d 100644
--- a/engines/scumm/he/moonbase/moonbase.cpp
+++ b/engines/scumm/he/moonbase/moonbase.cpp
@@ -35,7 +35,13 @@ Moonbase::~Moonbase() {
int Moonbase::readFromArray(int array, int y, int x) {
_vm->VAR(((ScummEngine_v90he *)_vm)->VAR_U32_ARRAY_UNK) = array;
- return _vm->readArray(116, y, x);
+ return _vm->readArray(((ScummEngine_v90he *)_vm)->VAR_U32_ARRAY_UNK, y, x);
+}
+
+void Moonbase::deallocateArray(int array) {
+ _vm->VAR(((ScummEngine_v90he *)_vm)->VAR_U32_ARRAY_UNK) = array;
+
+ return _vm->nukeArray(((ScummEngine_v90he *)_vm)->VAR_U32_ARRAY_UNK);
}
int Moonbase::callScummFunction(int scriptNumber, int paramCount,...) {
diff --git a/engines/scumm/he/moonbase/moonbase.h b/engines/scumm/he/moonbase/moonbase.h
index 7d93661dec..f7d8cdbb94 100644
--- a/engines/scumm/he/moonbase/moonbase.h
+++ b/engines/scumm/he/moonbase/moonbase.h
@@ -35,6 +35,7 @@ public:
~Moonbase();
int readFromArray(int array, int y, int x);
+ void deallocateArray(int array);
int callScummFunction(int scriptNumber, int paramCount,...);
void blitT14WizImage(uint8 *dst, int dstw, int dsth, int dstPitch, const Common::Rect *clipBox,
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index 9b1b617aff..d32eb766cb 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -119,7 +119,7 @@ byte *ScummEngine_v72he::defineArray(int array, int type, int dim2start, int dim
id = findFreeArrayId();
- debug(9,"defineArray (array %d, dim2start %d, dim2end %d dim1start %d dim1end %d", id, dim2start, dim2end, dim1start, dim1end);
+ debug(9, "defineArray (array %d, dim2start %d, dim2end %d dim1start %d dim1end %d", id, dim2start, dim2end, dim1start, dim1end);
if (array & 0x80000000) {
error("Can't define bit variable as array pointer");