From 5e2db7a1788573ea7e5683d6a9d56a8f55ec485d Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 22 Aug 2018 23:46:12 +0300 Subject: SCI32: Add workarounds for OOB reads for parameters These are mostly used to silence known cases, for now. Some workarounds of this type have already been addded --- engines/sci/engine/vm.cpp | 13 +++++++++---- engines/sci/engine/workarounds.cpp | 11 ++++++++++- engines/sci/engine/workarounds.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 0324feb576..fb010adefe 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -141,10 +141,15 @@ static reg_t read_var(EngineState *s, int type, int index) { } case VAR_PARAM: { // Out-of-bounds read for a parameter that goes onto stack and hits an uninitialized temp - // We return 0 currently in that case - const SciCallOrigin origin = s->getCurrentCallOrigin(); - warning("Uninitialized read for parameter %d from %s", index, origin.toString().c_str()); - return NULL_REG; + // We need to find correct replacements for each situation manually + SciCallOrigin originReply; + SciWorkaroundSolution solution = trackOriginAndFindWorkaround(index, uninitializedReadForParamWorkarounds, &originReply); + if (solution.type == WORKAROUND_NONE) { + warning("Uninitialized read for parameter %d from %s", index, originReply.toString().c_str()); + return NULL_REG; + } else { + return make_reg(0, solution.value); + } } default: break; diff --git a/engines/sci/engine/workarounds.cpp b/engines/sci/engine/workarounds.cpp index 90c854bc38..766fdcc20c 100644 --- a/engines/sci/engine/workarounds.cpp +++ b/engines/sci/engine/workarounds.cpp @@ -317,6 +317,16 @@ static const uint16 sig_uninitread_sq1_1[] = { SIG_END }; +// Workarounds for uninitialized reads for parameters +// gameID, room,script,lvl, object-name, method-name, local-call-signature, index-range, workaround +const SciWorkaroundEntry uninitializedReadForParamWorkarounds[] = { + { GID_HOYLE5, -1, 15, -1, "Hand", "add", NULL, 1, 1,{ WORKAROUND_FAKE, 0 } }, // When the game adds cards to your hand in any mini-game + { GID_PHANTASMAGORIA2,-1, 64926, 0, "Thumb", "action", NULL, 1, 1,{ WORKAROUND_FAKE, 0 } }, // When dragging one of the volume sliders and releasing the mouse button over the +/- buttons + { GID_PHANTASMAGORIA2,-1, 63019, 0, "WynDocTextView", "cue", NULL, 2, 2,{ WORKAROUND_FAKE, 0 } }, // When dragging the slider next to an e-mail message + SCI_WORKAROUNDENTRY_TERMINATOR +}; + +// Workarounds for uninitialized reads for temporary variables // gameID, room,script,lvl, object-name, method-name, local-call-signature, index-range, workaround const SciWorkaroundEntry uninitializedReadWorkarounds[] = { { GID_CAMELOT, 40, 40, 0, "Rm40", "handleEvent", NULL, 0, 0, { WORKAROUND_FAKE, 0 } }, // when looking at the ground at the pool of Siloam - bug #6401 @@ -444,7 +454,6 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = { { GID_PEPPER, -1, 894, 0, "Package", "doVerb", NULL, 3, 3, { WORKAROUND_FAKE, 0 } }, // using the hand on the book in the inventory - bug #5154 { GID_PEPPER, 150, 928, 0, "Narrator", "startText", NULL, 0, 0, { WORKAROUND_FAKE, 0 } }, // happens during the non-interactive demo of Pepper { GID_PHANTASMAGORIA, -1, 64921, -1, "Print", "addEdit", NULL, 1, 1, { WORKAROUND_FAKE, 0 } }, // When trying to use the game debugger's flag setting command - { GID_PHANTASMAGORIA2,-1, 64926, -1, "Thumb", "action", NULL, 1, 1, { WORKAROUND_FAKE, 0 } }, // When dragging one of the volume sliders and releasing the mouse button over the +/- buttons { GID_PQ4, -1, 25, 0, "iconToggle", "select", NULL, 1, 1, { WORKAROUND_FAKE, 0 } }, // when toggling the icon bar to auto-hide or not { GID_PQ4, 170, 170, -1, "hideAndSeek", "handleEvent", NULL, 1, 1, { WORKAROUND_FAKE, 0 } }, // when clicking to move right while still moving left during the Emo shootout - bug #9847 { GID_PQ4, 275, 64964, -1, "DPath", "init", NULL, 1, 1, { WORKAROUND_FAKE, 0 } }, // when Sherry walks out of the morgue on day 3 diff --git a/engines/sci/engine/workarounds.h b/engines/sci/engine/workarounds.h index a462fddcaa..ff1f5c6a87 100644 --- a/engines/sci/engine/workarounds.h +++ b/engines/sci/engine/workarounds.h @@ -62,6 +62,7 @@ struct SciWorkaroundEntry { extern const SciWorkaroundEntry arithmeticWorkarounds[]; extern const SciWorkaroundEntry uninitializedReadWorkarounds[]; +extern const SciWorkaroundEntry uninitializedReadForParamWorkarounds[]; extern const SciWorkaroundEntry kAbs_workarounds[]; extern const SciWorkaroundEntry kCelHigh_workarounds[]; extern const SciWorkaroundEntry kCelWide_workarounds[]; -- cgit v1.2.3