DIRECTOR: LINGO: Allow nonsense coercion of symbol to integer

Fixes the collision detection loop in the maze minigame of Virtual
Nightclub.
This commit is contained in:
Scott Percival 2024-05-17 10:08:14 +08:00 committed by Eugene Sandulenko
parent 417106a9d0
commit fb1f453dc1
2 changed files with 23 additions and 8 deletions

View File

@ -833,6 +833,9 @@ int Lingo::getAlignedType(const Datum &d1, const Datum &d2, bool equality) {
opType = FLOAT;
} else if ((d1Type == STRING && d2Type == INT) || (d1Type == INT && d2Type == STRING)) {
opType = STRING;
} else if ((d1Type == SYMBOL && d2Type != SYMBOL) || (d2Type == SYMBOL && d1Type != SYMBOL)) {
// some fun undefined behaviour: adding anything to a symbol returns an int.
opType = INT;
} else if (d1Type == d2Type) {
opType = d1Type;
}
@ -1041,6 +1044,11 @@ int Datum::asInt() const {
res = (int)u.f;
}
break;
case SYMBOL:
// Undefined behaviour, but relied on by bad game code that e.g. adds things to symbols.
// Return a 32-bit number that's sort of related.
res = (int)((uint64)u.s & 0xffffffffL);
break;
default:
warning("Incorrect operation asInt() for type: %s", type2str());
}

View File

@ -80,6 +80,21 @@ scummvmAssert("incorrect" + 5 > 10000)
scummvmAssert(" 2.5 " + 5 > 10000)
scummvmAssert("2 uhhh" + 5 > 10000)
scummvmAssert("2.5 uhhh" + 5 > 10000)
put "sausages" into testString
put (testString + 0) into testPointer
scummvmAssertEqual(testPointer > 10000, TRUE)
scummvmAssertEqual(testString + 4, testPointer + 4)
scummvmAssertEqual(testString - 4, testPointer - 4)
scummvmAssertEqual(testString * 4, testPointer * 4)
scummvmAssertEqual(testString / 4, testPointer / 4)
-- same horrible logic should apply to symbols
put #haggis into testString
put (testString + 0) into testPointer
scummvmAssertEqual(testPointer > 10000, TRUE)
scummvmAssertEqual(testString + 4, testPointer + 4)
scummvmAssertEqual(testString - 4, testPointer - 4)
scummvmAssertEqual(testString * 4, testPointer * 4)
scummvmAssertEqual(testString / 4, testPointer / 4)
-- casting to integer
scummvmAssertEqual(integer("2"), 2)
@ -109,14 +124,6 @@ scummvmAssertEqual(float(" 2.5 extra"), " 2.5 extra")
scummvmAssertEqual(float("2extra"), "2extra")
scummvmAssertEqual(float(" 2extra"), " 2extra")
put "sausages" into testString
put (testString + 0) into testPointer
scummvmAssertEqual(testPointer > 10000, TRUE)
scummvmAssertEqual(testString + 4, testPointer + 4)
scummvmAssertEqual(testString - 4, testPointer - 4)
scummvmAssertEqual(testString * 4, testPointer * 4)
scummvmAssertEqual(testString / 4, testPointer / 4)
-- LC::charOF
set string to "Macromedia"