Community

AGI Programming => AGI Development Tools => Topic started by: NewRisingSun on November 04, 2016, 02:23:32 AM

Title: AGI v1 resource extractor and sound converter
Post by: NewRisingSun on November 04, 2016, 02:23:32 AM
I have written a little extracting utility for AGI v1/v2.001 PC disk images (as well as the usual v2 and v3 volume files), and a converter that converts both GAL, AGI v1 and AGI v2/v3 sound files to VGM format for convenient listening. For later v2 and v3 games, you need to specify the --envelopes2 or --envelopes3 command line option to get the same result as in the games, as AGIsnd2vgm has no way of knowing whether envelopes should be applied (AGI v2.9xx) or not (AGI v2.4xx/v2.272/v2.089), and which shape the envelopes should have. Run AGIsnd2vgm without options or file names to see a list of supported options. The "stuck notes" option can best be seen action in King's Quest II's SND.1, which is the wedding music.

I have noticed that AGI v1 files that were converted by Sierra to v2 format sound faster when played back in the latter format. For example, the music in The Black Cauldron versions 2.0 and 2.10 sounds faster than in v1.1J/K/M. The reason is that the playback routine for the v1 format used the PC's default 18.2 MHz timer, while AGI v2 uses a 60 Hz timer, and Sierra's CNVRTSND.EXE multiplies all time values only by three instead of the correct 3.2967. CNVRTSND.EXE is Sierra's utility to convert v1 to v2 format files and what accidently included on the Space Quest I version 1.1A disk #1.
Title: Re: AGI v1 resource extractor and sound converter
Post by: lance.ewing on November 04, 2016, 03:03:28 PM
I'm going to take a look at this this evening.

I find it interesting that the CNVRTSND.EXE utility was on a Space Quest 1 disk. Does it appear as an undeleted file?

If so, it makes me wonder if Space Quest 1 began life as an AGI v1 game but was converted to AGI v2 at some point prior to release.
Title: Re: AGI v1 resource extractor and sound converter
Post by: lskovlun on November 04, 2016, 03:27:09 PM
If so, it makes me wonder if Space Quest 1 began life as an AGI v1 game but was converted to AGI v2 at some point prior to release.
Certainly, this occurred on other (later) occasions. LSL7 Demo is SCI2.1, while the final game is SCI3, suggesting it was made in SCI2.1. I recall getting quite far in KQ1 SCI with pre-Glutton FreeSCI (which had the same heap limits as SCI0), suggesting they weren't deliberately taking advantage of the extra memory provided in SCI01. There may be other instances that I'm forgetting.

In both of these cases, porting may have been a simple matter of recompiling the source.
Title: Re: AGI v1 resource extractor and sound converter
Post by: Collector on November 04, 2016, 09:43:52 PM
Other demos with earlier interpreters than the finished game are GK1 demo SCI1.1, finished game is SCI2. PQ4 demo SCI1.1, finished game is SCI2. RAMA Demo 2.1, finished game is SCI3. Shivers Demo SCI2.1, finished game is SCI3. Lighthouse Demo SCI2.1, finished game is SCI3.
Title: AGI v1/v2 logic decompiler, resource extractor and sound converter
Post by: NewRisingSun on November 07, 2016, 03:14:45 PM
Updated my AGI tools (edit: updated again!):I have successfuly extracted, decompiled, then recompiled and repackaged the game PC KQ2 v2.2. The source codes of these utilities have become a bit messy. I will clean them up (possibly rewrite in C++?) once I know what the final functionality will be and once more knowledge about AGIv1 in particular has been acquired.
Title: Re: AGI v1 resource extractor and sound converter
Post by: OmerMor on November 08, 2016, 02:44:28 AM
Well done!!!

When you decompile and recompile, do you get exactly the same bytecode?
Title: Re: AGI v1 resource extractor and sound converter
Post by: NewRisingSun on November 08, 2016, 12:01:21 PM
There are two systematic differences:There are eight logics in KQ2 v2.2 with other differences that I still need to investigate. When I decompile these recompiled logics again, the sources are completely identical, for what it's worth.

Also, CG does not compile a few sources at all but exits with an "output buffer overflow", notably PQ's rm0. That happens exclusively with late 1987 games, while my CG.EXE has a late 1986 time stamp. Either I need to specify a command-line option that enlarges the "output buffer", or the later games need a newer CG.EXE. I don't think that's the fault of the decompiler though.
Title: Re: AGI v1 resource extractor and sound converter
Post by: NewRisingSun on November 11, 2016, 02:17:20 PM
After having rewritten the ELSE/GOTO handling at least five times, AGIdecompile now produces sources that when fed to CG now yield 100% identical byte codes. I have tried this successfully with KQ3 v2.14, SQ v1.0X, KQ2 v2.2., and Donald Duck's Playground v1.0Q. SQ v1.0x (AGI v2.089) and DP require modifying SYSDEFS so that quit() has no argument, and DP v1.0Q (AGI v2.001) additionally requires set.game.id to have a NUM instead of a MSGNUM argument.

The version of CG that I have (v3.14) so far refuses to compile AGI v1 scripts at all; complaining that it does not know the "==" etc. operators. How strange.
Title: Re: AGI v1 resource extractor and sound converter
Post by: Kawa on November 11, 2016, 03:01:52 PM
100% identical byte codes
Quoting this for well-earned emphasis.
Title: Re: AGI v1 resource extractor and sound converter
Post by: NewRisingSun on November 11, 2016, 04:40:13 PM
Figured out how to prevent CG from giving the "output buffer overflow" error. I had used the -b parameter before, but with values that were too high or too low. CG likes values between 4096 and 8192, and the value might not be the same for every script.

With that in mind, I have managed to decompile and recompile AGI v3 logics as well. I had never noticed that AGI v3 games usually do not encrypt the message strings with "Avis Durgan", probably because the LZW compression makes it unnecessary. Most logics don't have encrypted messages, a few do, probably the ones that are so small that LZW compression isn't used. I had to modify CG.EXE by replacing "Avis Durgan" with a zero string so I could compare the original and recompiled bytecode properly. Added support for non-encrypted messages to AGIdecompile. Also added the additional AGI v3 commands to SYSDEFS.v2.

Therefore, I managed to decompile and recompile with identical results:Now, to figure out what's going on with CG and AGIv1 sources.
Title: Re: AGI v1 resource extractor and sound converter
Post by: Collector on November 11, 2016, 10:33:18 PM
Did CG.EXE ever get posted here?
Title: Re: AGI v1 resource extractor and sound converter
Post by: OmerMor on November 12, 2016, 05:16:17 AM
Now it has.
Title: Re: AGI v1 resource extractor and sound converter
Post by: Collector on November 12, 2016, 12:16:28 PM
Thanks.