[Scummvm-git-logs] scummvm master -> 91916981cf9ab2e9f1f7fc9116bdd8f9b9c7bdd7

sluicebox noreply at scummvm.org
Mon Aug 26 05:40:49 UTC 2024


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
155552cecd AGI: Update opcode tables
91916981cf AGI: Validate Picture priority and color parameters


Commit: 155552cecdf1041b40d19d2b56c253f5f750a825
    https://github.com/scummvm/scummvm/commit/155552cecdf1041b40d19d2b56c253f5f750a825
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-25T22:36:58-07:00

Commit Message:
AGI: Update opcode tables

Changed paths:
    engines/agi/opcodes.cpp


diff --git a/engines/agi/opcodes.cpp b/engines/agi/opcodes.cpp
index 9f8735de5bd..fb3f159ea96 100644
--- a/engines/agi/opcodes.cpp
+++ b/engines/agi/opcodes.cpp
@@ -85,7 +85,7 @@ static const AgiOpCodeDefinitionEntry opCodesV1[] = {
 	{ "reverse.loop",       "nn",       &cmdReverseLoopV1 },    // 1E
 	{ "move.obj",           "nnnnn",    &cmdMoveObj },          // 1F
 	{ "set.view",           "nn",       &cmdSetView },          // 20
-	{ "follow.ego",         "nnn",      &cmdFollowEgo },        // 21
+	{ "follow.ego",         "nnv",      &cmdFollowEgo },        // 21
 	{ "block",              "nnnn",     &cmdBlock },            // 22
 	{ "unblock",            "",         &cmdUnblock },          // 23
 	{ "ignore.blocks",      "n",        &cmdIgnoreBlocks },     // 24
@@ -120,36 +120,37 @@ static const AgiOpCodeDefinitionEntry opCodesV1[] = {
 	{ "quit",               "",         &cmdQuitV1 },           // 41
 	{ "set.speed",          "v",        &cmdSetSpeed },         // 42
 	{ "move.obj.v",         "nvvvv",    &cmdMoveObjF },         // 43
-	{ "...",                "nn",       &cmdUnknown },          // 44
+	{ "get.num",            "nv",       &cmdUnknown },          // 44
 	{ "get.v",              "v",        &cmdUnknown },          // 45
 	{ "assign.v",           "vv",       &cmdUnknown },          // 46
-	{ "...",                "n",        &cmdUnknown },          // 47 # printvar.v
+	{ "printvar",           "v",        &cmdUnknown },          // 47 prints a variable (debug script)
 	{ "get.priority",       "nv",       &cmdGetPriority },      // 48
 	{ "ignore.objs",        "n",        &cmdIgnoreObjs },       // 49
 	{ "observe.objs",       "n",        &cmdObserveObjs },      // 4A
 	{ "distance",           "nnv",      &cmdDistance },         // 4B
 	{ "object.on.land",     "n",        &cmdObjectOnLand },     // 4C
-	{ "...",                "nv",       &cmdUnknown },          // 4D # set.priority.f
+	{ "set.priority.v",     "nv",       &cmdUnknown },          // 4D # set.priority.v / set.priority.f
 	{ "show.obj",           "n",        &cmdShowObj },          // 4E # show.obj (KQ2)
 	{ "load.logics",        "n",        &cmdLoadLogic },        // 4F # load.global.logics
 	{ "display",            "nnns",     &cmdDisplay },          // 50 TODO: 4 vs 3 args
 	{ "prevent.input???",   "",         &cmdUnknown },          // 51
 	{ "...",                "",         &cmdUnknown },          // 52 # nop
-	{ "...",                "n",        &cmdUnknown },          // 53 # text.screen
-	{ "...",                "",         &cmdUnknown },          // 54 ???
-	{ "stop.motion",        "",         &cmdStopMotion },       // 55 or force.update??
+	{ "text.screen",        "n",        &cmdUnknown },          // 53
+	{ "graphics",           "",         &cmdUnknown },          // 54
+	{ "stop.motion",        "",         &cmdStopMotion },       // 55
 	{ "discard.view",       "n",        &cmdDiscardView },      // 56
 	{ "discard.pic",        "v",        &cmdDiscardPic },       // 57
 	{ "set.item.view",      "nn",       &cmdSetItemView },      // 58
-	{ "...",                "",         &cmdUnknown },          // 59 # reverse.cycle
+	{ "...",                "",         &cmdUnknown },          // 59 # reverse.cycle, unused in KQ2 or BC
 	{ "last.cel",           "nv",       &cmdLastCel },          // 5A
 	{ "set.cel.v",          "nv",       &cmdSetCelF },          // 5B
-	{ "...",                "",         &cmdUnknown },          // 5C # normal.cycle
+	{ "...",                "",         &cmdUnknown },          // 5C # normal.cycle, unused in KQ2 or BC
 	{ "load.view",          "n",        &cmdLoadView },         // 5D
-	{ "...",                "",         &cmdUnknown },          // 5E
-	{ "...",                "",         &cmdUnknown },          // 5F
+	{ "...",                "",         &cmdUnknown },          // 5E unused in KQ2 or BC
+	{ "...",                "",         &cmdUnknown },          // 5F BC script 102 when attempting to fill flask
 	{ "setbit",             "nv",       &cmdUnknown },          // 60
-	{ "...",                "nv",       &cmdUnknown },          // 61 # clearbit
+	{ "...",                "nv",       &cmdUnknown },          // 61 # clearbit, unused in KQ2 or BC
+	{ "set.upper.left",     "nn",       &cmdSetUpperLeft }      // 62 BC Apple II
 };
 
 static const AgiOpCodeDefinitionEntry opCodesV2Cond[] = {
@@ -331,7 +332,7 @@ static const AgiOpCodeDefinitionEntry opCodesV2[] = {
 	{ "print.at.v",         "vnnn",     &cmdPrintAtV },         // 98
 	{ "discard.view.v",     "v",        &cmdDiscardView},       // 99
 	{ "clear.text.rect",    "nnnnn",    &cmdClearTextRect },    // 9A
-	{ "set.upper.left",     "nn",       &cmdSetUpperLeft },     // 9B
+	{ "set.upper.left",     "nn",       &cmdSetUpperLeft },     // 9B Apple II
 	{ "set.menu",           "s",        &cmdSetMenu },          // 9C
 	{ "set.menu.item",      "sn",       &cmdSetMenuItem },      // 9D
 	{ "submit.menu",        "",         &cmdSubmitMenu },       // 9E


Commit: 91916981cf9ab2e9f1f7fc9116bdd8f9b9c7bdd7
    https://github.com/scummvm/scummvm/commit/91916981cf9ab2e9f1f7fc9116bdd8f9b9c7bdd7
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-25T22:36:58-07:00

Commit Message:
AGI: Validate Picture priority and color parameters

Fixes SQ1 Apple II pictures. draw_SetColor() and draw_SetPriority()
consumed bytes without validating them.

Changed paths:
    engines/agi/picture.cpp
    engines/agi/picture.h


diff --git a/engines/agi/picture.cpp b/engines/agi/picture.cpp
index 1f9432c4e1b..a42e4d5afd5 100644
--- a/engines/agi/picture.cpp
+++ b/engines/agi/picture.cpp
@@ -73,6 +73,16 @@ byte PictureMgr::getNextByte() {
 	}
 }
 
+bool PictureMgr::getNextParamByte(byte &b) {
+	byte value = getNextByte();
+	if (value >= _minCommand) {
+		_dataOffset--;
+		return false;
+	}
+	b = value;
+	return true;
+}
+
 byte PictureMgr::getNextNibble() {
 	if (!_dataOffsetNibble) {
 		_dataOffsetNibble = true;
@@ -89,42 +99,34 @@ byte PictureMgr::getNextNibble() {
 ** Draws an xCorner  (drawing action 0xF5)
 **************************************************************************/
 void PictureMgr::draw_xCorner(bool skipOtherCoords) {
-	int x1, x2, y1, y2;
+	byte x1, x2, y1, y2, dummy;
 
-	if ((x1 = getNextByte()) >= _minCommand ||
-	        (y1 = getNextByte()) >= _minCommand) {
-		_dataOffset--;
+	if (!(getNextParamByte(x1) && getNextParamByte(y1)))
 		return;
-	}
 
 	putVirtPixel(x1, y1);
 
 	for (;;) {
-		x2 = getNextByte();
-
-		if (x2 >= _minCommand)
+		if (!getNextParamByte(x2))
 			break;
 
 		if (skipOtherCoords)
-			if (getNextByte() >= _minCommand)
+			if (!getNextParamByte(dummy))
 				break;
 
 		draw_Line(x1, y1, x2, y1);
 		x1 = x2;
 
 		if (skipOtherCoords)
-			if (getNextByte() >= _minCommand)
+			if (!getNextParamByte(dummy))
 				break;
 
-		y2 = getNextByte();
-
-		if (y2 >= _minCommand)
+		if (!getNextParamByte(y2))
 			break;
 
 		draw_Line(x1, y1, x1, y2);
 		y1 = y2;
 	}
-	_dataOffset--;
 }
 
 /**************************************************************************
@@ -133,42 +135,33 @@ void PictureMgr::draw_xCorner(bool skipOtherCoords) {
 ** Draws an yCorner  (drawing action 0xF4)
 **************************************************************************/
 void PictureMgr::yCorner(bool skipOtherCoords) {
-	int x1, x2, y1, y2;
+	byte x1, x2, y1, y2, dummy;
 
-	if ((x1 = getNextByte()) >= _minCommand ||
-	        (y1 = getNextByte()) >= _minCommand) {
-		_dataOffset--;
+	if (!(getNextParamByte(x1) && getNextParamByte(y1)))
 		return;
-	}
 
 	putVirtPixel(x1, y1);
 
 	for (;;) {
 		if (skipOtherCoords)
-			if (getNextByte() >= _minCommand)
+			if (!getNextParamByte(dummy))
 				break;
 
-		y2 = getNextByte();
-
-		if (y2 >= _minCommand)
+		if (!getNextParamByte(y2))
 			break;
 
 		draw_Line(x1, y1, x1, y2);
 		y1 = y2;
-		x2 = getNextByte();
-
-		if (x2 >= _minCommand)
+		if (!getNextParamByte(x2))
 			break;
 
 		if (skipOtherCoords)
-			if (getNextByte() >= _minCommand)
+			if (!getNextParamByte(dummy))
 				break;
 
 		draw_Line(x1, y1, x2, y1);
 		x1 = x2;
 	}
-
-	_dataOffset--;
 }
 
 /**************************************************************************
@@ -302,26 +295,18 @@ void PictureMgr::plotPattern(int x, int y) {
 ** Plots points and various brush patterns.
 **************************************************************************/
 void PictureMgr::plotBrush() {
-	int x1, y1;
-
 	for (;;) {
 		if (_patCode & 0x20) {
-			byte b = getNextByte();
-			if (b >= _minCommand)
+			if (!getNextParamByte(_patNum))
 				break;
-			_patNum = b;
 		}
 
-		if ((x1 = getNextByte()) >= _minCommand)
-			break;
-
-		if ((y1 = getNextByte()) >= _minCommand)
+		byte x1, y1;
+		if (!(getNextParamByte(x1) && getNextParamByte(y1)))
 			break;
 
 		plotPattern(x1, y1);
 	}
-
-	_dataOffset--;
 }
 
 /**************************************************************************
@@ -392,6 +377,7 @@ void PictureMgr::drawPictureC64() {
 			_scrOn = true;
 			break;
 		case 0xe6:  // plot brush
+			// TODO: should this be getNextParamByte()?
 			_patCode = getNextByte();
 			plotBrush();
 			break;
@@ -551,6 +537,7 @@ void PictureMgr::drawPictureV2() {
 			draw_Fill();
 			break;
 		case 0xf9:
+			// TODO: should this be getNextParamByte()?
 			_patCode = getNextByte();
 
 			if (_vm->getGameType() == GType_PreAGI)
@@ -634,7 +621,8 @@ void PictureMgr::drawPictureAGI256() {
 }
 
 void PictureMgr::draw_SetColor() {
-	_scrColor = getNextByte();
+	if (!getNextParamByte(_scrColor))
+		return;
 
 	// For CGA, replace the color with its mixture color
 	switch (_vm->_renderMode) {
@@ -647,7 +635,7 @@ void PictureMgr::draw_SetColor() {
 }
 
 void PictureMgr::draw_SetPriority() {
-	_priColor = getNextByte();
+	getNextParamByte(_priColor);
 }
 
 // this gets a nibble instead of a full byte
@@ -764,22 +752,19 @@ void PictureMgr::draw_Line(int16 x1, int16 y1, int16 x2, int16 y2) {
  * Draws short lines relative to last position. (drawing action 0xF7)
  */
 void PictureMgr::draw_LineShort() {
-	int x1, y1, disp, dx, dy;
+	byte x1, y1, disp;
 
-	if ((x1 = getNextByte()) >= _minCommand ||
-	        (y1 = getNextByte()) >= _minCommand) {
-		_dataOffset--;
+	if (!(getNextParamByte(x1) && getNextParamByte(y1)))
 		return;
-	}
 
 	putVirtPixel(x1, y1);
 
 	for (;;) {
-		if ((disp = getNextByte()) >= _minCommand)
+		if (!getNextParamByte(disp))
 			break;
 
-		dx = ((disp & 0xf0) >> 4) & 0x0f;
-		dy = (disp & 0x0f);
+		int dx = ((disp & 0xf0) >> 4) & 0x0f;
+		int dy = (disp & 0x0f);
 
 		if (dx & 0x08)
 			dx = -(dx & 0x07);
@@ -790,7 +775,6 @@ void PictureMgr::draw_LineShort() {
 		x1 += dx;
 		y1 += dy;
 	}
-	_dataOffset--;
 }
 
 /**************************************************************************
@@ -799,38 +783,29 @@ void PictureMgr::draw_LineShort() {
 ** Draws long lines to actual locations (cf. relative) (drawing action 0xF6)
 **************************************************************************/
 void PictureMgr::draw_LineAbsolute() {
-	int16 x1, y1, x2, y2;
+	byte x1, y1, x2, y2;
 
-	if ((x1 = getNextByte()) >= _minCommand ||
-	        (y1 = getNextByte()) >= _minCommand) {
-		_dataOffset--;
+	if (!(getNextParamByte(x1) && getNextParamByte(y1)))
 		return;
-	}
 
 	putVirtPixel(x1, y1);
 
 	for (;;) {
-		if ((x2 = getNextByte()) >= _minCommand)
-			break;
-
-		if ((y2 = getNextByte()) >= _minCommand)
+		if (!(getNextParamByte(x2) && getNextParamByte(y2)))
 			break;
 
 		draw_Line(x1, y1, x2, y2);
 		x1 = x2;
 		y1 = y2;
 	}
-	_dataOffset--;
 }
 
 // flood fill
 void PictureMgr::draw_Fill() {
-	int16 x1, y1;
+	byte x1, y1;
 
-	while ((x1 = getNextByte()) < _minCommand && (y1 = getNextByte()) < _minCommand)
+	while (getNextParamByte(x1) && getNextParamByte(y1))
 		draw_Fill(x1, y1);
-
-	_dataOffset--;
 }
 
 void PictureMgr::draw_Fill(int16 x, int16 y) {
diff --git a/engines/agi/picture.h b/engines/agi/picture.h
index f7e762fed47..a00016da113 100644
--- a/engines/agi/picture.h
+++ b/engines/agi/picture.h
@@ -78,6 +78,7 @@ private:
 	void plotBrush();
 
 	byte getNextByte();
+	bool getNextParamByte(byte &b);
 	byte getNextNibble();
 
 public:




More information about the Scummvm-git-logs mailing list