Author Topic: SQ5 preliminary decompiled source  (Read 29456 times)

0 Members and 1 Guest are viewing this topic.

Offline troflip

SQ5 preliminary decompiled source
« on: April 30, 2015, 02:11:54 AM »
I've gotten to an important milestone I think  :D

I've attached a zip file with 210 decompiled script files from SQ5. I renamed the extensions to .txt (instead of .sc) just to make it easier to browse them in Windows.

A few notes:
- I've made no attempt at compiling these files (in fact the code that generates SCI1.1 script resources (with the separate heap/scr) is still not implemented). So you may see stuff that certainly looks like it won't compile. An example is having strings in a script's local vars. SCIStudio doesn't allow this, but it's required for decompiling scripts, really. So I'll need to add this syntax support.

- Almost all the variable naming (and all the file naming) was done automatically, with no interaction from me. So it is pretty much just "click and go" to get the results you see. Of course, you'll see that exported procedures have nonsense names, so there will need to be some interaction from the user to supply names to these functions based on what it looks like they do (and then the next recompile will pick up those changes).

- I did a quick search for ERROR in these files, and I found a handful of places where this appears. This is indicative of some problem with resolving symbols, so I need to look at those cases

- There are still lots of issues with detecting the higher level control flow structures, and making sense out of some code. So I often have to fall back to asm. So you'll see some asm in there, but not *too* much. I put in some stats calculations, and the result of decompiling the entire game (which took 9 minutes) was:
Quote
Decompiled 3079 of 3121 functions successfully (98%).
Overall bytecount success rate: 96%.

So that's really not too bad, I can "successfully" decompile roughly 95% of the code. I say "successfully", because the only validation I can do now is when my decompiler logic runs into things it doesn't know how to handle. In the 95% "successful" code, there still may be a lot of it that is incorrect. So there's still lots of work to do.

- There are a few turds leftover from previous compilation attempts (for example you'll see n000.txt, which was an old version of main.txt (before I wrote the code to auto-detect script filenames), and it's full of asm). I'm too lazy to re-upload the zip.

- I still have bugs in the formatting of the code output, so parentheses may be in weird places.
« Last Edit: April 30, 2015, 02:18:24 AM by troflip »


Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Collector

Re: SQ5 preliminary decompiled source
« Reply #1 on: April 30, 2015, 02:32:26 AM »
Nice. Is that all of them?
KQII Remake Pic

Offline troflip

Re: SQ5 preliminary decompiled source
« Reply #2 on: April 30, 2015, 04:40:37 AM »
Yup.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline MusicallyInspired

Re: SQ5 preliminary decompiled source
« Reply #3 on: April 30, 2015, 07:54:24 AM »
This is just too cool. I'll be mulling over all of this for sure! Great work, troflip! This is exciting!!

I have a request, if it's not too much trouble. Is it possible you could provide the complete source for SQ4 or at least the room script for the Time Pod (script 531)? (either CD or disk, it doesn't matter) There's a long-standing easter egg mystery in the time pod room that has stumped a lot of SQ fans for a long time on the SQ.net forums. Having the source would really shed a lot of light. Specifically, we were wondering if the "Blue frogs on my shoulder make me hap-py" line is actually triggerable in the game and if so how.
« Last Edit: April 30, 2015, 09:28:28 AM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Cloudee1

Re: SQ5 preliminary decompiled source
« Reply #4 on: April 30, 2015, 07:55:16 AM »
I notice that the obj script, as well as dcicon both "use" themselves... There are a few that do that and some that don't.

Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: SQ5 preliminary decompiled source
« Reply #5 on: April 30, 2015, 03:40:45 PM »
I notice that the obj script, as well as dcicon both "use" themselves... There are a few that do that and some that don't.

Cool, I've fixed that. Thanks for any bug reports!

I have a request, if it's not too much trouble. Is it possible you could provide the complete source for SQ4 or at least the room script for the Time Pod (script 531)?

Attached... have at it!

Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline MusicallyInspired

Re: SQ5 preliminary decompiled source
« Reply #6 on: April 30, 2015, 04:22:36 PM »
Thank you so much!
Brass Lantern Prop Competition

Offline lskovlun

Re: SQ5 preliminary decompiled source
« Reply #7 on: April 30, 2015, 05:21:47 PM »
About the blue frog stuff, it is not possible to trigger that response. The frog object is a Feature, that is to say, a part of the pic that responds to commands (without being a view). A Feature usually has some sort of graphical representation, but in other cases one must resort to pixel hunting (there's a debug feature in LSL5 as welll). In this case, the Feature is placed on Roger's left shoulder, as the text implies (or rather, it is his shoulder).
Now, the reasons why you can't get the message in the released version:

  • The frog feature is not initialized at room start-up, so the game system doesn't know it's there
  • Even if the frog feature was initialized, another feature (restOfPod) takes precedence over it, so the game system doesn't care it's there
  • The doVerb method of the feature disregards which icon was used - and doesn't call its superclass - so the default handler for the "look" cursor isn't run.

A little ScummVM-fu can solve the first two problems and enable the teleport code (indeed, I've done so). A hex-editor might solve the third and cause the message to be displayed.

EDIT: QfG2 used  "suck blue frog" to enable the debug mode. I wonder what it is with Sierra and blue frogs...

EDIT2: There's a bug in the decompiler at the Print statement in that doVerb handler. There's supposed to be buttons with it, described via extra arguments to Print.
« Last Edit: April 30, 2015, 05:26:56 PM by lskovlun »

Offline MusicallyInspired

Re: SQ5 preliminary decompiled source
« Reply #8 on: April 30, 2015, 05:28:40 PM »
Well, I can't say that's not disappointing :(. However, apparently in NRS's SQ4 patch he re-enabled the "Time-O-Matic" which is attached to the frog instance. But I can't get it to work...care to take a look at his script with your decompiler?

EDIT: I guess attaching the script would have been helpful...I don't know if you need the HEP file as well, but here it is.
« Last Edit: April 30, 2015, 05:36:29 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline troflip

Re: SQ5 preliminary decompiled source
« Reply #9 on: April 30, 2015, 05:35:34 PM »
EDIT2: There's a bug in the decompiler at the Print statement in that doVerb handler. There's supposed to be buttons with it, described via extra arguments to Print.

Ugh... that's old code that I had to automatically pull stuff from text resources when I did my first stab at the decompiler back when... it special-cases the Print procedure... Thanks for pointing that out! So most of the Print statements in the decompiled scripts I provided will be wrong :P

Here's the corrected doVerb;
Code: [Select]
    (method (doVerb)
        (var temp0)
        = local2 Print(531 16 30 1 80 "Time-O-Matic" 81 "Estros" 6 81 "Mall" 12 81 "Xenon" 18 81 "Ulence" 24 81 "Ortega" 0)
        (if ((< global128 2) and (== local2 6))
            Print(531 17)
        )(else
            (if ((< global128 2) and (== local2 12))
                Print(531 18)
            )(else
                = temp0 0
                (while (<= temp0 5)
                    (send newDisplay[temp0]:
                        loop(2)
                        cel(theGNewDisplayCel_2[+ local2 temp0])
                    )
                    ++temp0
                )
                (hand:posn(180 180))
                (send global2:setScript(timeToTimeWarpS))
            )
        )
    )

To make for nice decompilation, I'll stlll need to provide some special casing for Print calls to interpret the selectors correctly. But these will presumably be different for each game, since it depends on the code in the Print procedure. From what I recall seeing, I think SCI1.1 games use a Print class that has more "strongly-typed" options for printing.
« Last Edit: April 30, 2015, 05:43:28 PM by troflip »
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline lance.ewing

Re: SQ5 preliminary decompiled source
« Reply #10 on: May 04, 2015, 12:29:35 PM »
Is it possible you could provide the complete source for SQ4 or at least the room script for the Time Pod (script 531)? (either CD or disk, it doesn't matter)

If we're taking requests, I'd like to request KQ4 if that's possible yet. I know it's early SCI, but if its possible, that would be great. I've been keen to see Room 7 in KQ4 for a while. It's the one that is discussed in The Official Book of King's Quest.

I've been wondering for a long time whether they used conversion tools to convert between the AGI and SCI version of KQ4. Maybe comparing the two sources would answer this question. If migration tools were used, then we'd expect the KQ4 source to take on more of an AGI sequential script layout and not take much advantage of the OO capabilities of SCI. AGI didn't have loops, so a dramatically reduced number of loops might be a clue. Obviously they would have tidied it up after conversion, but there should still be some evidence in there.

Does anyone know if the AGI version of KQ4 pre-dated the SCI? What I mean is do we know if they wrote the AGI version first and then the SCI? I realise they were probably released at the same time, but what I was wondering is if the development phase of KQ4 started with the AGI version and then whether they migrated that to the SCI? Or did it happen in the other direction?

Maybe the KQ4 source would answer some of this.

Offline troflip

Re: SQ5 preliminary decompiled source
« Reply #11 on: May 04, 2015, 01:38:47 PM »
Here's the KQ4 source. The decompiler had a hard time with the big functions in Main.

I'll see if I can get that SQ4 531 patch decompiled, but currently the decompiler is not looking at patch files (the way I had it set up, there was a chance it could grab the .hep file from the original package, but the .scr from a patch (which is disastrous), and disabling patch files was a (temporary) easy way to get the decompiler working on a full game).
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline lance.ewing

Re: SQ5 preliminary decompiled source
« Reply #12 on: May 04, 2015, 04:49:29 PM »
Thanks for that. At first glance looking over the room 7 scripts, it doesn't look all that similar in structure to the AGI version. If they did use some sort of conversion tool, they must have done a lot of post clean up and refactoring afterwards.

Offline Collector

Re: SQ5 preliminary decompiled source
« Reply #13 on: May 04, 2015, 09:24:58 PM »
Would they have been doing a lot of conversion/refactoring for the first SCI game? I may be wrong, but I thought that KQ4 was purposely written for SCI and the AGI was co-developed.
KQII Remake Pic

Offline troflip

Re: SQ5 preliminary decompiled source
« Reply #14 on: May 05, 2015, 02:02:00 AM »
Well, I can't say that's not disappointing :(. However, apparently in NRS's SQ4 patch he re-enabled the "Time-O-Matic" which is attached to the frog instance. But I can't get it to work...care to take a look at his script with your decompiler?

EDIT: I guess attaching the script would have been helpful...I don't know if you need the HEP file as well, but here it is.

Hmm, I'm unclear how to use these. SQ4 is not a SCI1.1 game, so there aren't separate heap/script resources - and the naming is wrong (i.e. .scr instead of script.531). I tried sticking it in SQ5, and was able to decompile it, but it looks a bit messed up.
Check out my website: http://icefallgames.com
Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.046 seconds with 22 queries.