Community

General and Everything Else => The Games and other Sierra Adventure stuff => Topic started by: Kawa on October 13, 2015, 08:13:38 AM

Title: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 13, 2015, 08:13:38 AM
I've been following the development of a certain SNES emulator up close, and earlier today I was reminded of something from a while back. It was a SNES ROM that could identify with a high degree of certainty which emulator or console revision it ran on. The challenge for this certain emulator whose author strives for accuracy was to foil the detection without resorting to blatant lies.

How this ended is ultimately irrevelant.

What is, is that this in turn reminded me of a certain difference between Sierra's SCI terps and ScummVM: the latter supports everything at once, while the former has somewhat game-specific terps. For example, King's Quest 6 has its SEQ videos, while Larry 6 has the old SCI01 menu bar, and there are at least two "magnifying glass" effects that only work in their own respective games. If you run LSL6 on the SIERRA.EXE from KQ6, it outright says AddMenu is not supported.

On the other hand, ScummVM does not seem to care as much, as long as the kernel functions are basically all uniquely numbered. There doesn't seem to be anything stopping you from using SetCursor subop 10, the magnifying glass effect in Freddy Pharkas, and the menu bar code doesn't seem to care at all. Thus, theoretically, one should be able to play videos (both SEQ and AVI?) as well as do a magnification effect, color remapping (thanks QFG4 Demo), and a menu bar to bind them all together... if you run in ScummVM.

Now imagine an SCI11 game that actually does all these things. No single SSCI terp would be able to run it, of course; only ScummVM could. But imagine you want to let those who try it anyway down gently, like a Gameboy Color game in a classic mono Gameboy. Of course, where the GBC actually lets the game ROM know outright that it's a GBC (A=11h from the get-go, easy to check), I can't think of a way for an SCI11 script to tell if it's running on ScummVM or SSCI without deliberately crashing. The first idea I had was to check for a driver file, since ScummVM doesn't use those, but that wouldn't work as well considering they can still be present...

So what method, if any, is there to detect that you're running in ScummVM so that if you're not, you can show a gentle error message and quit again. Showing the message in SCI proper would be preferred, but that's a bit out of scope.

Of course, if all of the above is wrong and I've been misinterpreting the source code all along, that's a valid answer as well ;)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 13, 2015, 01:04:40 PM
Well, given we know that you can't play two digital audio sounds at once, you could try playing a looping digital sound (its handle property will then become non-zero), and then invoke a call to DoAudio(audPlay etc.....) and check if the sound's handle becomes 0 (indicating it has stopped playing). I just verified that it becomes zero in Sierra's interpreters (well, the one with the template game).

Presumably it stays non-zero in ScummVM (since the first sound keeps playing), though I haven't checked.

So... that's my idea for a hacky way to do this.


Another way would be to detect if certain commonly-used selectors on commonly-used object are being set by index (Sierra's interpreter) or by name (ScummVM). For instance, make a class that has the same properties as Prop (except with a pair of key properties swapped), add it to the scene and wait for some call that the interpreter makes to set values on this object (you'll have to figure that part out), then see if the values are what you expect.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 13, 2015, 02:16:44 PM
Both are excellent ideas, but I think I must've messed on the audio thing cos the handle stays 1 in SSCI.

Given two audio resources, a tone and some noise:
Code: [Select]
(case 1
DebugPrint("sound test go! detectorSound handle is %d." (detectorSound:handle))
(detectorSound:play())
DebugPrint("playing! detectorSound handle is %d." (detectorSound:handle))
= seconds 1 //Sounds are two seconds long.
)
(case 2
DebugPrint("about to DoAudio! detectorSound handle is %d." (detectorSound:handle))
DoAudio(2 43)
DebugPrint("playing! detectorSound handle is %d." (detectorSound:handle))
= cycles 1
)
It plays the tone for ~1 second, then replaces it with noise. The debug output is 0, 1, 1, 1.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 13, 2015, 03:26:04 PM
And detectorSound only has a digital effect, no midi-version that would be playing instead?

Maybe you need to wait a game cycle in order for its handle to be reset. I think the Sound::check method would need to be called in order for SCI to set the handle to 0 after detecting the sound is no longer playing.

At any rate, it worked for me (I was also using audio36 resources for DoAudio).
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: MusicallyInspired on October 13, 2015, 07:41:33 PM
Obviously I can see the merit in doing an auto-detect for this, but is there anything wrong with simply asking the user which interpreter he's playing on and going from there? (ie- "Are you playing in DOS/DOSBox or ScummVM?")
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 13, 2015, 07:51:23 PM
is there anything wrong with simply asking the user which interpreter he's playing on and going from there?
As a great man used to say, "everybody lies." 8)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: MusicallyInspired on October 13, 2015, 09:48:50 PM
I'd say that's their own problem. :P But it's a fair point. And if you can make it auto-choose all the better.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 13, 2015, 10:07:31 PM
Well then. I can't seem to reproduce the sound-based method (sauce plz?) and I'm not leet enough to do the other one.

I might as well experiment with those features I mentioned in the OP... after sleep.


Edit: hold on a moment there. What was that about DebugPrint in the other thread?
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 14, 2015, 12:03:08 AM
Edit: hold on a moment there. What was that about DebugPrint in the other thread?

Oh yeah... you can write a file. Then try to read it back. If there's nothing there, then you must be running in ScummVM (or it could be that you don't have write privileges in the directory the game is in)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 14, 2015, 05:43:24 AM
Oh yeah... you can write a file. Then try to read it back. If there's nothing there, then you must be running in ScummVM (or it could be that you don't have write privileges in the directory the game is in)
I don't understand this, because the games manage to read and write files just fine. Are you doing something very differently?
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 14, 2015, 07:41:40 AM
Oh yeah... you can write a file. Then try to read it back. If there's nothing there, then you must be running in ScummVM (or it could be that you don't have write privileges in the directory the game is in)
I don't understand this, because the games manage to read and write files just fine. Are you doing something very differently?
Well, I've had my sleep. Time to test what Phil implied:
I wish I could get the DebugPrint working in ScummVM. But the FileIO functions seem to work differently...
[edit: ah, ScummVM doesn't support writing arbitrary files... only save game files]
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 14, 2015, 08:30:39 AM
Oh yeah... you can write a file. Then try to read it back. If there's nothing there, then you must be running in ScummVM (or it could be that you don't have write privileges in the directory the game is in)
Right, so I went back and looked. The issue is not with FileIO, it is with the entire concept behind DebugPrint. You create a file and expect it to be stored in the game folder. The SCI engine in ScummVM uses the ScummVM filesystem abstraction. This means that any files created by the games (by saving or otherwise) go into a different directory than the game files. This makes sense, because under Windows, program directories are ostensibly read-only anyway (and similar, but stricter, requirements exist on other platforms that ScummVM supports, such as smartphones). Another problem is that the FS routines implicitly compress the files when creating them.

All of this is transparent as long as the files are only accessed from a single game (no sharing!) from within SCI. Thus, it can't be used for detection purposes. It breaks down when you try to use files as a portable IPC mechanism.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 14, 2015, 08:35:12 AM
Yeah, I just found that out myself. Shit sucks.

(no really it kinda does when a four-byte check string is saved as 24 bytes.)

New detection idea! SCIAudio! One of the first things ScummVM's kFileIOWriteString does is check if the string starts with "(sciAudio", and it doesn't actually write anything to the file then. Try to write "(sciAudio" to a file, read it back. What do you get?

Edit: wait shit no what the hell is this handle -1 stuff how is that supposed to work?
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 14, 2015, 12:31:07 PM
All of this is transparent as long as the files are only accessed from a single game (no sharing!) from within SCI. Thus, it can't be used for detection purposes. It breaks down when you try to use files as a portable IPC mechanism.

Can you think of another way to have that kind of communication in ScummVM?

Or is there a way the game can do something to cause debug spew to go into Scumm's console? (which would kind of be achieving the same thing)

Oh, also... is there a way to have ScummVM run a game directly, without going through the game-choosing menu? I couldn't find any cmd line option that does this. It would be nice to be able to hit the "run" button in SCI Companion and have it go right into the game in Scumm.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: MusicallyInspired on October 14, 2015, 12:44:09 PM
Yes, there is. You add the game's id (visible when you go to Edit Game... in ScummVM) to the command line. Every game has (needs) a unique game ID, and you can set it manually, I think.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 14, 2015, 01:32:13 PM
troflip, what was the code you used for that thing with the two sounds and the handle?

Yes, there is. You add the game's id (visible when you go to Edit Game... in ScummVM) to the command line. Every game has (needs) a unique game ID, and you can set it manually, I think.
Actually, I recall a thing in a TODO list where it was suggested that putting ScummVM in a game's folder (like their own terps) and starting it there should do the obvious thing, without necessarily putting the game in ScummVM's library.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 14, 2015, 01:42:04 PM
troflip, what was the code you used for that thing with the two sounds and the handle?

I forget...

Anyway I *think* I've coded up something that detects the interpreter, but I can't test it because I can't seem to get ScummVM to recognize SCI 1.1 template games anymore. It somehow doesn't recognize it as a fan made game, and won't run it. I'm not sure what changed. Sigh.... [shaking fist at ScummVM]

Anyway, here's the script (hard-coded to script 19 right now). Replace 996 with some other view in your game that is at least 3 pixels high. The code basically uses an object with property positions swapped, and then sees what properties the kernel BaseSetter sets. It should set the wrong ones in Sierra, and the right ones in ScummVM.

Code: [Select]
/******************************************************************************/
(version 2)
(script 19)
/******************************************************************************/
(include "sci.sh")
(use "obj")
(use "main")

(exports
0 IsSierraInterpreter
)

(class FakeView of Obj
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle $6789
        actions 0
        onMeCheck omcDISABLE
        state $0000
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 2
        view -1
        loop 0
        cel 0
        priority 0
        underBits 0
        signal $0101
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        scaleSignal $0000
        scaleX 128
        scaleY 128
        maxScale 128
        // The last 4 props have been swapped with the previous 4 (compared to the View class)
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
    )
)

(instance dummy of FakeView
(properties)
)

(procedure public (IsSierraInterpreter)
(FakeView:view(996))
BaseSetter(FakeView)
DebugPrint("brTop is %d brBottom is %d " (FakeView:brTop) (FakeView:brBottom))
return (== (FakeView:brTop) 0)
)

Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 14, 2015, 02:33:13 PM
Or is there a way the game can do something to cause debug spew to go into Scumm's console? (which would kind of be achieving the same thing)
There is a slot in the kernel table reserved for a function called DbugStr, which in SSCI prints to an attached monochrome monitor. I suppose we could use that (it's not currently implemented in ScummVM though, so that will have to be done - but it should be easy). I managed to make the monochrome screen work in DosBox a while ago, but it's a bit of a pain - it requires applying a patch and compiling manually. Of course, you can keep supporting the old method if you like.

My original thread on the topic is here: http://sciprogramming.com/community/index.php?topic=1419.0
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 14, 2015, 02:35:36 PM
Anyway, here's the script (hard-coded to script 19 right now). Replace 996 with some other view in your game that is at least 3 pixels high. The code basically uses an object with property positions swapped, and then sees what properties the kernel BaseSetter sets. It should set the wrong ones in Sierra, and the right ones in ScummVM.
I see what you did there. Sneaky.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 14, 2015, 02:50:43 PM
I can't seem to get ScummVM to recognize SCI 1.1 template games anymore. It somehow doesn't recognize it as a fan made game, and won't run it. I'm not sure what changed. Sigh.... [shaking fist at ScummVM]
I've found that it's the game's class name or something. Script 0 export 0's name matters, it seems.

Also, the name/number thing works perfectly. (http://i.imgur.com/qIPNiEw.png)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 14, 2015, 06:19:24 PM
Ooo yeah, you're right. Guess I'll have to leave the template game name as SQ5.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 14, 2015, 08:00:02 PM
I got too excited. Turns out RemapColors is only available in QfG4 Demo, because it replaces StrSplit.

Still, I managed to build a copy of ScummVM that maps it to SetSynonyms (empty in SCI11) instead, just for testing. As far as I can tell, the other things plus playing two digital sounds at once are still on the table as valid reasons to do this whole detection dance.

(http://i.imgur.com/ZaUeHBI.png)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Collector on October 14, 2015, 11:08:05 PM
Oh, also... is there a way to have ScummVM run a game directly, without going through the game-choosing menu? I couldn't find any cmd line option that does this. It would be nice to be able to hit the "run" button in SCI Companion and have it go right into the game in Scumm.

You can start games from the command line.

http://wiki.scummvm.org/index.php/User_Manual/Running_and_Using_ScummVM#Command_line_options

You can do it exactly the same as you are with DOSBox, but may need a couple of extra options. Note that ScummVM IDs the template game as "sq5-demo".

You can also start a game in ScummVM with a custom ini file i.e.:

Code: [Select]
"C:\Program Files (x86)\ScummVM\scummvm.exe" --config=scummvm.ini sq5-demo
And in the ini file it points to something like:

Code: [Select]
[scummvm]
lastselectedgame=sq5-demo
browser_lastpath=C:\Games\New Game\

[kq6-win]
description=Space Quest V: The Next Mutation (Demo/DOS/English)
savepath=C:\Games\New Game\
gfx_mode=2x
path=C:\Games\New Game\
fullscreen=false
gameid=sci
prefer_digitalsfx=true
language=en

The description could be named to the given game's name.

Now one possible problem is that ScummVM IDs games by the hash of a given file. In the case of SCI games I believe this is the MAP file. Not sure what it will do when it does not recognize the hash. It may just throw a message of unknown fan SCI game. I'll have to test it this weekend.

Edit, I posted this before I realized that this had gone onto another page.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 15, 2015, 03:16:02 AM
Thanks Collector, that works. I saw that before, but didn't realize you had to specify the path *and* the id (in this case sq5 works).

So while the debug spew functionality doesn't work, at least the "start the game in this room" functionality works, which is pretty useful.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 15, 2015, 08:35:04 AM
I got too excited. Turns out RemapColors is only available in QfG4 Demo, because it replaces StrSplit.
And in SCI32. So it will be made, eventually.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 15, 2015, 08:56:02 AM
And in SCI32. So it will be made, eventually.
Ah, but only SCI32 games get the full RemapColors, no?
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 15, 2015, 09:20:42 AM
And in SCI32. So it will be made, eventually.
Ah, but only SCI32 games get the full RemapColors, no?
That depends. I think if the full SCI32 interface is just a superset of the SCI1.1 one, there is no reason to go out of our way to prevent SCI1.1 games from using it.  I'm not sure if this is the case exactly, but if you look at the source code for FileIO, it is shared with the older file API. SaveGame and friends, too.

There's a new guy on the ScummVM team who was working on some palette code a while ago. I guess it also depends on what kind of changes the full support would require. If they end up architecting a whole new palette manager for SCI32 then we might be in trouble. In that case, it's possible that the QfG4 demo will not be supported at all.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 15, 2015, 10:11:30 AM
That depends. I think if the full SCI32 interface is just a superset of the SCI1.1 one, there is no reason to go out of our way to prevent SCI1.1 games from using it.  I'm not sure if this is the case exactly, but if you look at the source code for FileIO, it is shared with the older file API. SaveGame and friends, too.
Tisn't quite. Comparing s_defaultKernelNames[] and sci2_default_knames[], if those numbers are supposed to be right... for example SCI0/SCI11 has Clone as function 4, but it's function 7 in the other list. DrawCel of all things seems to be missing entirely.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 15, 2015, 10:25:47 AM
That depends. I think if the full SCI32 interface is just a superset of the SCI1.1 one, there is no reason to go out of our way to prevent SCI1.1 games from using it.  I'm not sure if this is the case exactly, but if you look at the source code for FileIO, it is shared with the older file API. SaveGame and friends, too.
Tisn't quite. Comparing s_defaultKernelNames[] and sci2_default_knames[], if those numbers are supposed to be right... for example SCI0/SCI11 has Clone as function 4, but it's function 7 in the other list. DrawCel of all things seems to be missing entirely.
I'm not talking about the order of kernel functions, I'm talking about the order of subfunctions of RemapColors. Where it gets mapped to in the kernel table doesn't matter (there's a bunch of things going on for SCI2/2.1 in that regard, too)...
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 15, 2015, 11:19:44 AM
I'm not talking about the order of kernel functions, I'm talking about the order of subfunctions of RemapColors. Where it gets mapped to in the kernel table doesn't matter (there's a bunch of things going on for SCI2/2.1 in that regard, too)...
In that case, it still wouldn't work out:
Code: [Select]
RemapColors(0 percent)
RemapColors(1 from to base)
RemapColors(2) //turn off

RemapColors32(0) //turn off
RemapColors32(1 color from to base)
RemapColors32(2 color percent)
RemapColors32(3 color percent) //remap to gray
RemapColors32(4 color percent) //remap to % gray?
So that's subop 0 and 2 reversed, plus of course the part where the demo version doesn't have a color parameter and just uses 254 instead.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 15, 2015, 11:41:35 AM
which is what I was trying to say. If the order of the subfunctions is different, then it won't work. I wasn't sure, and now you've told me.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: troflip on October 15, 2015, 12:02:36 PM
What does remapcolors do? How is it different than just setting a palette entry?
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 15, 2015, 01:00:00 PM
What does remapcolors do? How is it different than just setting a palette entry?
Among other things, it allows dynamic-like shadows.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 15, 2015, 01:03:42 PM
There are a few really good examples in GK1, such as the sunbeam in the Schloss Ritter entry hall.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 16, 2015, 09:49:49 AM
What does remapcolors do? How is it different than just setting a palette entry?
More concretely, the colors between 236 and 254 are treated specially (actually, that range is divided in two for reasons that I don't fully understand). When a view contains these colors, they affect things that are drawn on top and below (by altering their brightness, by displaying them in black & white, etc.). The desired effect of each color in that range is set with an initial call to RemapColors (typically in the room init) and the system takes care of the rest. This is in contrast to setting palette entries manually, where the script must do something on each game cycle.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: MusicallyInspired on October 16, 2015, 10:49:14 AM
Fascinating. I love the tricks that programmers and designers came up with to accomplish things with 256 colour limitations.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 16, 2015, 10:59:29 AM
Except in the QFG4 Demo, which assumes color 254 and doesn't accept anything else~

Demo versionPresumed full version equivalentUsed for
StrSplit(0 50)RemapColors(2 254 50)50% shaded shadow
StrSplit(1 112 175 62)RemapColors(1 254 112 175 62)Torch effect in starting cave
StrSplit(2)RemapColors(0)Unused in demo
Other subops are only in the full version that I can't decompile.

SCIence! (http://pastebin.com/R7Ujypwq)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 16, 2015, 11:51:18 AM
Except in the QFG4 Demo, which assumes color 254 and doesn't accept anything else~
(I was talking about SCI32)
My current thinking on the "divided in two" thing is that this may be platform specific. The 236 displayable colors are a limit set by Windows in an 8-bit graphics mode, so it makes sense to use the remaining colors for something else. I'm not sure what a Macintosh running in 8-bit graphics mode would allow, but it's possible that the Mac version allows 246 displayable colors and sets aside fewer for remapping. The division in two would then allow games to run on Mac with no code changes, but with slightly higher color fidelity.
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: Kawa on October 16, 2015, 11:57:10 AM
(I was talking about SCI32)
And I was talking about the different parameters for RemapColors between versions. There is no conflict here. :)
Title: Re: Interpreter Detection: SSCI or ScummVM?
Post by: lskovlun on October 17, 2015, 01:08:49 AM
The full game has the following

Demo versionFull version equivalentUsed for
StrSplit(0 50)RemapColors(2 254 60)50/60% shaded shadow
StrSplit(1 112 175 62)RemapColors(1 253 112 175 62)Torch effect in starting cave
/td]
RemapColors(0)Cancels the current remapping settings