Commit Graph
79 Commits
Author SHA1 Message Date
Donovan Watteau 25842987ef SCI: Fix MSVC C4309 enum sign warning 2022-11-29 01:37:55 +01:00
sluicebox 2fbeecab23 SCI: Prevent script lockers from overflowing
Script::_locker is supposed to track the number of classes and objects
that use a script in order to determine when it can be safely unloaded.
But for system script 999, _locker rapidly increases throughout the game
and eventually overflows. This causes script 999 to unload and crash.
Other scripts may also be affected.

We have been provided QFG1 SCI0 saves where this occurred over the
course of hours within only three days. Logging shows this value
skyrocketing in many games even when they are just polling input or
animating the screen. Alarmingly, this suggests that many SCI games
become unplayable in ScummVM after an achievable amount of game time.

This may be a large and complex problem within the script locker system.
For now, we can mitigate this by making Script::_locker unsigned, which
its callers expected it to be, and by logging overflow attempts and
lowering the locker. This fixes existing save games, even if they have
already overflowed the signed maximum.
2022-11-22 12:37:32 -08:00
Eugene Sandulenko abea37c9bb ALL: Update ScummVM project license to GPLv3+ 2021-12-26 18:48:43 +01:00
sluicebox 1de4c13dfb SCI: Add workaround for SQ3 1.018 vocab bugs
Big thanks to Threepwang for reporting this
2021-12-01 00:02:57 -07:00
Bastien Bouclet 553d2968bb SCI: Add override keywords 2020-02-09 12:43:16 +01:00
Filippos Karapetis 9dd63b12b1 SCI: Add more script patcher checks for games without a selector vocab
Fixes the LSL1 demo
2019-09-14 11:39:35 +03:00
Filippos Karapetis d2f5023ee9 SCI: Do not apply script patches when checking for static selectors
Fixes bug #10969
2019-06-08 13:57:34 +03:00
Colin Snover f83c61fcb6 SCI32: Fix relocation of locals in SCI3
Somehow, up until trying to view an encrypted data cube in RAMA,
the missing relocation of locals did not seem to cause any trouble
in any of the other SCI3 games.
2017-09-23 20:57:03 -05:00
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 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 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 d53f3f6095 SCI32: Exclude SCI3 code from compilation when SCI32 is disabled 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 eadf5d818f SCI: Fix support for 32-bit SCI3 script offsets 2017-04-23 13:07:25 -05:00
Colin Snover a620b6c354 SCI: Fix handling of buggy SCI0 export tables
The previous fix for this bug was incorrect; it only happened
to work because of another bug: the number of exports was being
read incorrectly (reading the byte size of the export block, not
the number of exports), so the validation check for the export
number always passed. Then, the "small" offsets that were seen
were actually either invalid reads into the header of the next
block in the script (KQ4), or reads into the bad first export
table which contained an unfilled offset (Camelot).

Once the incorrect number of exports was fixed, the previous "fix"
broke in KQ4 because the export number validation started to work
correctly and the first export table does not have enough entries
(needs 2, has 1).

This patch fixes the bug by using the last export table in SCI0
scripts instead of the first export table. (This does not affect
most scripts, since only the buggy scripts have more than one
export table.)

Fixes Trac#9731.
2017-04-18 11:47:18 -05:00
Colin Snover 31daa956d6 SCI: Implement bounds-checked reads of game resources 2017-03-27 19:42:31 -05:00
Colin Snover 4814682d5f SCI: Improve disassembly output
1. pushi opcode now displays decimal value and selector value (if
   one exists) in-line
2. lofsa, lofss, and super opcodes now display resolved
   object/class names
3. Opcode arguments are visually aligned
2016-11-20 12:31:44 -06:00
Colin Snover 55222ec06c SCI32: Fix zero-offset exports
Exports with a zero offset are supposed to point to the start of
the code block in the script hunk, but they were being ignored.

This may also apply to SCI1.1 games, but until that can be
verified, this fixes the zero-offset in only SCI32 games for now.
2016-10-20 11:33:08 -05:00
Martin Kiewitz 3b092e5d60 SCI: identifyOffsets() counter variables 2015-05-17 18:51:22 +02:00
Martin Kiewitz 3183ef0854 SCI: add said-details to script_said debug cmd 2015-05-14 20:41:21 +02:00
Martin Kiewitz bfab4c4cbe SCI: debug commands scro, scrs and script_said
implement string collecting for SCI3
implement object offset collecting for SCI0-SCI2
implement said-str offset collecting for SCI0-SCI1
add new debug command scro / script_objects
add new debug command script_said
string without terminating NUL now a warning
the latter happens in qfg2 for amiga room 84
2015-05-14 20:33:21 +02:00
Martin Kiewitz ed7007162a SCI: Scripts: identify strings + debug command
debug command is called "script_strings" / "scrs"
2015-05-04 21:19:05 +02:00
Johannes Schickel 8fc7d60feb SCI: Make GPL headers consistent in themselves. 2014-02-18 02:39:37 +01:00
Martin Kiewitz 8bdffcb2fb SCI: script patcher is now a separate class 2013-12-04 20:42:16 +01:00
Martin Kiewitz 4e2b1f0200 SCI: script patch for laura bow 2 for audio+text
at the same time
needs indepth testing
2013-11-20 23:31:36 +01:00
Martin Kiewitz 3fbbdbc2da SCI: improved script patcher
Gabriel Knight + King's Quest 6 patches now also work for Mac versions of those games
added support for selectors instead of using hardcoded values
2013-11-03 23:49:31 +01:00
Martin Kiewitz f1abc0c302 SCI: improved patcher, inventory patch for kq6/mac
Also added new debug flag for script patcher
2013-11-01 13:25:31 +01:00
Filippos Karapetis 7e66cbd468 SCI: Rename a parameter in validateExportFunc()
This ensures that it won't be confused with a function with the same name
2012-06-26 11:13:14 +03:00
Filippos Karapetis 20b6770808 SCI: Change the program counter (PC) to be a 32-bit variable
This is needed for future support of large SCI3 scripts. The program
counter is isolated and does not interfere with other parts of the VM,
plus it does not get stored in saved games, so it's pretty straightforward
to convert
2012-06-23 21:45:26 +03:00
Filippos Karapetis c1eb93bc5a SCI: Clean up validateExportFunc() and related functions
Also renamed some SCI3 related code to indicate when it's SCI3 specific
2012-06-23 21:45:24 +03:00
Filippos Karapetis 041b1447c0 SCI: Replace RAW_IS_OBJECT with a method 2012-06-15 22:32:15 +03:00
Filippos Karapetis 160732b2f7 Revert "SCI: Change Script::getObject() to accept a reg_t"
This reverts commit 577d7e41c9.
2012-06-15 22:32:14 +03:00
Filippos Karapetis 562a8a980c SCI: Further cleanup of the script code
Merge the init() and load() Script methods and reset the script when
necessary
2012-06-15 12:53:17 +03:00
Filippos Karapetis 577d7e41c9 SCI: Change Script::getObject() to accept a reg_t
This is needed for upcoming changes to the Script class
2012-06-15 12:24:14 +03:00
Filippos Karapetis 27f2b6e4dd SCI: Change the script buffer size to be a size_t as well
This will be needed in the future to load large SCI3 scripts
2012-06-14 12:20:43 +03:00
Willem Jan Palenstijn 8c57e4bf43 SCI: Fix const cast 2011-11-11 00:07:27 +01:00
Filippos Karapetis 5969c6bd2e SCI: Updated Script::getObjectMap()
It now returns a reference to the object list instead of copying it
2011-11-05 13:08:42 +02:00
Filippos Karapetis 58190c36b4 SCI: Made the object map hashmap of the Script class private 2011-11-05 10:07:03 +02:00
Filippos Karapetis 267c6f1756 SCI: Made more fields of the Script class private. Some cleanup. 2011-11-05 03:00:42 +02:00
Matthew Hoops 9539017ee3 ALL: initialise -> initialize 2011-05-25 11:17:11 -04:00
strangerke 69b1485a22 GIT: Clean up: Suppress SVN tags, now useless 2011-05-12 01:16:22 +02:00
Filippos Karapetis 3485d433c5 SCI: Fixed bug #3034713 - "ICEMAN Demo: Fails to find base object"
This could happen because objects in scripts can be in the wrong order.
Same thing happens in the French and German version of KQ5 (bug #3035396).
Removed the scriptObjRemove() method, which is in fact a hack.

svn-id: r54510
2010-11-27 18:08:47 +00:00
Lars Skovlund c5252071db SCI3: Add proper support for the calle instruction
svn-id: r54327
2010-11-18 17:04:00 +00:00
Lars Skovlund 5ab823b16a SCI3: relocate operand of the lofsa opcode
svn-id: r54301
2010-11-17 20:29:10 +00:00
Filippos Karapetis b707d6e7dc SCI: More work on SCI3, based on a patch by lskovlun
- Added SCI3 equivalents for access to object selectors
- Added SCI3 implementation of object relocation
- Added SCI3 implementation of Script::initialiseClasses()

svn-id: r54283
2010-11-17 11:15:52 +00:00
Filippos Karapetis 59ad5085bc SCI: Some more work on SCI3, based on a patch by lskovlun
- Added a SCI3 implementation of Script::load()
- Added a SCI3 implementation of Script::initialiseClasses()
- Removed some duplicate code

svn-id: r54282
2010-11-17 09:28:04 +00:00
Filippos Karapetis e4c967a301 SCI: Added the SCI3 equivalent of initialiseObjects(), from a patch by lskovlun
svn-id: r54281
2010-11-17 09:10:43 +00:00
Filippos Karapetis 5de2668939 SCI: Some changes regarding the string heap in saved games
- Maintain the state of the string heap space in saved games
- Merged SegManager::reconstructScripts() inside SegManager::saveLoadWithSerializer()
- Disabled a now unnecessary script patch for the cipher puzzle in Castle of Dr. Brain, and performed some cleanup for another disabled patch
- Removed direct access to the _baseObj variable of objects

svn-id: r54133
2010-11-08 00:18:34 +00:00
Filippos Karapetis 7d71d07075 SCI: Renamed findBlock() to findBlockSCI0()
svn-id: r54077
2010-11-04 23:19:23 +00:00