Commit Graph
4076 Commits
Author SHA1 Message Date
Colin Snover ef69a59467 SCI: Stop leaking locals segments during script reuse
When a game deletes a script and then loads the same script again
before it has been fully deallocated,
SegManager::instantiateScript tries to reuse the same script
& locals segments, but it was failing to reuse the old locals
segment because Script::freeScript would unconditionally clear
the old locals SegmentId, which meant the old locals segment would
just leak.

This patch does not fix old save games which may contain orphaned
locals segments, but should prevent the problem from occurring
going forward. (It is possible to clean up these old save games,
but this is not a big leak so it doesn't seem worth the extra
effort to do so.)
2017-05-20 21:14:18 -05:00
Colin Snover bc728a1c93 SCI: Fix warning about missing base object when loading save games
This situation occurs rarely, but normally, when unreachable but
not yet GC'd objects use a superclass which has already been GC'd.

Thanks to @wjp for looking at this with me and clarifying what
was going on.
2017-05-20 21:14:18 -05:00
Colin Snover 4917330038 SCI: Find and store the original static names of objects
See code comment in Object::init for more details.

Fixes Trac#9780.
2017-05-20 21:14:18 -05:00
Colin Snover 1f29e6f241 SCI: Refactor relocation code
This groundwork enables an object to look up its static name
separately from the normal process that is used to populate
Object::_variables when an object is first constructed.

(The static name property needs to be able to be retrieved from
objects inside of earlier save games whose name properties may
have already been modified at runtime, so the code cannot simply
pluck the value out of Object::_variables when they are first
initialised and then persisted into the save game, as nice and
easy as that would have been.)

This commit also helps to clarify the situation with relocation
tables in SCI1 games that start with a zero entry.

Refs Trac#9780.
2017-05-20 21:14:18 -05:00
Colin Snover d09ae57fd8 SCI32: Remove bad assertion in relocateSci3
While extremely rare (only Rama script 64948 seems to have this
profile), it *is* possible for an object to have zero properties
(and thus, zero property offsets).
2017-05-20 21:14:18 -05:00
Colin Snover eda836f21a SCI: Nitpicky cleanup of some magic numbers and what-not-why comments 2017-05-20 21:14:18 -05:00
Colin Snover 71630a7cb2 SCI: Remove duplicate relocateBlock function 2017-05-20 21:14:18 -05:00
Colin Snover bc9835ba5e SCI: Always use SegManager::getObjectName to get object names
This ensures that all object name reading code works the same and
is in one place in the codebase.
2017-05-20 21:14:18 -05:00
Colin Snover 881be25fcd SCI: Stop making copies of ObjMap and remove related dead code
ObjMap owns Objects, so every time this map gets copied instead of
referenced, it creates a copy of every single object in the
associated script. This is expensive, and it breaks things like
the `Object::syncBaseObject` call in savegame.cpp, which hasn't
actually been doing anything since
58190c36b4 because it has been
operating on copies.
2017-05-20 21:14:18 -05:00
Colin Snover 66efb750a0 SCI: Add more support for >16-bit SCI3 offsets
Basically just grepped for getOffset calls being assigned to
uint16s and expanded those to uint32 when they looked trivial.

While some of these changes seem superfluous, at least for the
US/English SCI3 games where potentially impacted game scripts are
not large enough to have a problem with 16-bit offsets (e.g. when
feature detecting the sound type), at least some of these changes
are necessary for correct operation of the find_callk debugger
command in SCI3 games. There should not be a reason why any of
these variables need to be kept as uint16, in any case.
2017-05-20 21:14:18 -05:00
Colin Snover 14a521a211 SCI32: Fix kPlatform operation for SCI2 through SCI2.1early
Fixes Trac#9795.
2017-05-20 21:14:18 -05:00
Willem Jan Palenstijn 779b8336b1 SCI: Let getClassAddress fail gracefully with SCRIPT_GET_DONT_LOAD
This fixes a crash in the debugger when disassembling the class opcode
with a class from a script that hasn't yet been loaded.
2017-05-16 22:41:47 +02:00
Martin Kiewitz cadd89e675 SCI: Add script patch for "Tickets, only" during game over scene
Audio played was "Tickets, only", subtitle shows "Tickets, please".

Also remove forcing myDialog for KQ6Print::say (which was added,
while fixing this script patch).
see a46f3c1625
Forcing myDialog causes issues during game over screen (bug #9771).
Bug is solved by this, but script patch isn't perfect right now.
2017-05-15 22:56:04 +02:00
Colin Snover 1911b19e15 SCI32: Make sure all save game validity checks are in kCheckSaveGame32
Save game metadata validity checks in SCI32 should all exist within
kCheckSaveGame32 since this allows most games to recover
successfully from an attempt to load an invalid save game. If
gamestate_restore fails, the game will usually crash because the
engine is left in an inconsistent state (game scripts have cleaned
up objects in preparation for a game load that is no longer
happening).
2017-05-13 22:46:25 -05:00
Colin Snover 262ef4de61 SCI32: Fix crash at end of Torin
This "fix" is more of a hack, in the interest of making the game
completable. The root cause is a combination of two problems in
the game scripts:

1. Blink::init expects to receive either 0 or 2 arguments, but
   it assumes that if it received *any* arguments, it must have
   received 2 arguments. This assumption is wrong, though,
   because--
2. soTorinWhoAreYou::changeState(0) calls
   poPecandEyes::setCycle(Blink) without including a second
   argument (the blink speed).

This ends up with the second parameter being some garbage, and
that garbage gets sent to kRandom which then complains about
receiving garbage.

The correct fix for this would be to fix soTorinWhoAreYou (in
script 51400) to pass a second argument to setCycle, but there are
not enough obvious spare bytes for a quick and easy patch, so this
workaround will have to do for now.

Fixes Trac#9779.
2017-05-13 22:46:13 -05:00
Colin Snover ae628c18d4 SCI32: Add workaround for KQ7
Fixes Trac#9763.
2017-05-08 19:45:07 -05:00
Colin Snover c9cbb8e31c SCI: Translate messages passed to dialogues 2017-05-08 11:26:46 -05:00
Colin Snover a403523faf SCI32: Add workaround for KQ7
Fixes Trac#9759.
2017-05-06 21:45:41 -05:00
Colin Snover c9f22eb1aa SCI32: Add missing ifdef for EngineState::_eventCounter 2017-05-06 21:23:23 -05:00
Colin Snover 57dd79d4dc SCI32: Detect and handle tight loops around kGetEvent
In SSCI, mouse events are received through a hardware interrupt
and the cursor is drawn directly to the graphics card by the
interrupt handler. This allows game scripts to omit calls to
kFrameOut without stopping the mouse cursor from being redrawn
in response to mouse movement.

ScummVM, in contrast, needs to poll for events and submit screen
updates explicitly from the main thread. Submitting screen updates
may block on vsync, which means that this call should really only
be made once per frame, just after the game has finished updating
its back buffer. The closest signal in SCI32 for having completed
drawing a frame is the kFrameOut call, so this is where the
update is submitted (by calling OSystem::updateScreen).

The problem with the approach in ScummVM is that, even though the
mouse position is being updated (by calls to kGetEvent) and drawn
to the backend's back buffer (by GfxCursor32::drawToHardware),
OSystem::updateScreen is never called during game loops that omit
calls to kFrameOut.

This commit introduces a workaround that looks at the number of
times kGetEvent is called between calls to kFrameOut. If the
number of kGetEvent calls is higher than usual (where "usual"
seems to be 0 or 1), we assume that the game is running one of
these tight event loops, and kGetEvent starts calling
OSystem::updateScreen until the next kFrameOut call. We also
then start throttling the calls to kGetEvent to keep CPU usage
down. This fixes at least two such known loops:

1. When interacting with the menu bar at the top of the screen
   in LSL6hires;
2. When restoring a game in Phant2 and sitting on the "click mouse"
   screen.

A similar workaround may also be needed for kGetTime, though loops
around kGetTime should preferably be replaced using a script patch
to call kWait instead.
2017-05-06 19:03:54 -05:00
Colin Snover 91df45c6c5 SCI32: Fix missing/incorrect game features detection 2017-05-06 10:38:58 -05:00
Colin Snover b73e275b42 SCI32: Micro-optimize speedRoom comparison 2017-05-06 10:38:58 -05:00
Tarek Soliman f30f34cbde SCI32: Set a savegame description if none was entered
This fixes the the SCI32 incarnation of Trac#5343
(defect#3061964): Savegames with no name can't be restored
2017-05-05 12:38:04 -05:00
Colin Snover 8d94a04605 SCI32: Disable game script video benchmarking
The approach to video benchmarking used by SCI engine does not
translate very well to modern video devices -- it will either be
so slow that the games think the system is not capable of showing
normal visual effects, or so fast that the benchmarks overflow
their counters. So, game scripts that perform video benchmarking
are now patched to unconditionally return the highest speed value.

A pleasant but subtle side-effect of this change is that the extra
time sitting at a blank screen before the start of a game (while
benchmarks ran) is now gone.

Fixes Trac#9741.
2017-05-04 23:00:53 -05:00
Colin Snover 68218d15f2 SCI32: Fix incorrect arguments to readPixel in kCelInfo
Fixes Trac#9750.
2017-05-02 11:00:45 -05:00
Colin Snover 00168003fe SCI: Clean up ugly syncBaseObject call 2017-04-30 13:44:34 -05:00
Colin Snover 94dc6ae052 SCI: Hold script data as mutable internally
Script buffer data is modified after a script is loaded by
savegame operations, and, in SCI16, by string operations. Casting
away const to allow these mutations to happen is not a very good
design, so this patch just changes the privately held reference
to data to be mutable. (Public accessors still return immutable
data.)
2017-04-30 12:47:32 -05:00
Colin Snover 519719db49 SCI: Add var count sanity checking to object initialization 2017-04-24 21:45:49 -05:00
Colin Snover e15a4c806a SCI: Use the var count from the instance's class in SCI1.1-2.1 when looking up selectors
At least some versions of Island of Dr Brain have a bMessager
instance in script 0 with a var count greater than that of its
class. This probably should never happen since it means the
object has a variable with no corresponding selector.

The next commit adds some extra sanity checking code to object
initialization, to warn on any other games where this happens.
2017-04-24 21:39:30 -05:00
Colin Snover 28a06656af SCI: Improve error messages in Script::validateExportFunc 2017-04-23 13:07:25 -05:00
Colin Snover d53f3f6095 SCI32: Exclude SCI3 code from compilation when SCI32 is disabled 2017-04-23 13:07:25 -05:00
Colin Snover 6f95b1a440 SCI32: Fix missing mustSetViewVisible data in cloned objects
This information comes directly from script data and is not
modified at runtime, so it does not need to be persisted in save
games, but does need to be set when reconstructing clones.
2017-04-23 13:07:25 -05:00
Colin Snover a2d7851e4d SCI32: Improve disassembly output of SCI3 property opcodes
Since SCI3 scripts use selectors instead of offsets as operands
to property-related opcodes, the disassembler can look up and
display property names everywhere (unlike SCI2.1 and earlier,
which need to know the object being operated on to look up the
correct selector for a given offset).
2017-04-23 13:07:25 -05:00
Colin Snover 3d4fb4ccb4 SCI32: Fix mustSetViewVisible for SCI3
In SCI2/2.1, variable indexes are used along with a range encoded
in the interpreter executable to determine whether an object
variable is a view-related variable. Operands to aTop, sTop, ipToa,
dpToa, ipTos, and dpTos are byte offsets into an object, which
are divided by two to get the varindex to check against the
interpreter range.

In SCI3, objects in game scripts contain groups of 32 selectors,
and each group has a flag that says whether or not the selectors
in that group are view-related. Operands to aTop, sTop, ipToa,
dpToa, ipTos, and dpTos are selectors.
2017-04-23 13:07:25 -05:00
Colin Snover 1962b1bb6d SCI32: Replace magic numbers in SCI3 selector init 2017-04-23 13:07:25 -05:00
Colin Snover eb9965274d SCI32: Fix race conditions in Audio32 2017-04-23 13:07:25 -05:00
Colin Snover f3db412d6f SCI32: Serialize Robots in SCI3
This is necessary for at least Lighthouse, which maintains the
state of Robots across save games.
2017-04-23 13:07:25 -05:00
Colin Snover a799cb3462 SCI: Fix SCI3 exports
Export functions may be relocated above 64k in SCI3, but exports
that do not have an entry in the relocation table must be handled
the same as SCI1.1-2.1.
2017-04-23 13:07:25 -05:00
Colin Snover fc02b34215 SCI: Deduplicate Object::locateVarSelector code
The variable count returned by Object::getVarCount is populated
by variable 1 in SCI1.1, so specially reading the variable
explicitly for that engine version is not necessary.
2017-04-23 13:07:25 -05:00
Colin Snover eadf5d818f SCI: Fix support for 32-bit SCI3 script offsets 2017-04-23 13:07:25 -05:00
Colin Snover 2906ca9947 SCI: Replace mostly-unused flags property with a single boolean
There does not appear to be any reason to use a bit field instead
of a simple boolean for this one flag, since there are no other
flags that need to be set on Object like this.
2017-04-23 13:07:25 -05:00
Colin Snover cb50682b15 SCI: Improve documentation of Object class 2017-04-23 13:07:25 -05:00
Colin Snover 0394fd44e8 SCI: Fix whitespace errors 2017-04-23 13:07:25 -05:00
Colin Snover 61fba94139 SCI: Remove dead code in Script_Offset disassembler
Script_Offset is only ever used for lofsa/lofss opcodes.
2017-04-23 13:07:25 -05:00
Colin Snover 0676e640db SCI: Fix bad offsets in disassembly for SCI3 lofsa/lofss 2017-04-23 13:07:25 -05:00
Colin Snover 6b95528b49 SCI32: Fix bad relocations of SCI3 objects 2017-04-23 13:07:25 -05:00
Colin Snover 90c6c0580e SCI: Convert Object to use Common::Array for SCI3
In SCI3, index-to-selector tables no longer exist in compiled
object data (instead, the SCI3 VM uses selectors directly and
object data contains a bit map of valid selectors). In ScummVM,
the table is generated by Object::initSelectorsSci3 for
compatibility with the design of the ScummVM SCI VM. For
consistency, _baseVars is converted to use a standard container,
which works for all SCI versions.

The table for SCI3 property offsets is also changed to use a
standard container instead of manually managing the memory with
malloc/free.
2017-04-23 13:07:25 -05:00
Colin Snover 8299460917 SCI32: Hook up mustSetViewVisible for SCI3 2017-04-23 13:07:25 -05:00
Colin Snover d0a143fa87 SCI32: Fix locals offset in SCI3
Locals offset needs to be set even when the script has no exports.
2017-04-23 13:07:25 -05:00
Colin Snover d24f5537be SCI32: Implement SCI3 Script::syncStringHeap 2017-04-23 13:07:25 -05:00