Community

SCI Programming => SCI Syntax Help => Topic started by: doomlazer on September 22, 2021, 05:24:54 PM

Title: Script patch files
Post by: doomlazer on September 22, 2021, 05:24:54 PM
I'm having trouble exporting a modified room script as a patch file.

If I start with a fresh copy of a game in SCICompanion and only decompile the room script I need, I can edit the script easy enough. I then compile that single script and rebuild the resources. Finally I try exporting the script number as a patch.

Unfortunately, when I import the new script patch (or put it in a game folder) I'm still getting the original code.

Am I trying to do something that's not possible here? If I want to distribute a mod with changes to just one room, should I instead be distributing the SRC folder with just the .sc and .sco for that room?

This ties into a larger question about distributing mod files for the original games. I believe even modified VIEW patches would technically be a copyright violation as derivative work are prohibited under copyright. I'm trying to decide if, on larger mods with many changes, I'll need to distribute all the VIEW patches and the SCR folder or if it's best to just rebuild resource.001 and distribute that (which seems to work fairly well)?

For a single room mod that requires script changes, distributing a modded RESOURCE.001 seems wasteful, I'd much prefer to use a script patch instead if possible.

Any thoughts? 
Title: Re: Script patch files
Post by: doomlazer on September 22, 2021, 07:36:52 PM
After some more testing, I believe distributing the src folder wouldn't do much good unless the endusers were compiling and rebuilding for themselves in SCICompanion. I was mistakenly thinking the SCI engine would load the contents of the scr folder like patch files.

Also, I'm starting to think the idea of exporting a single modified script patch to change a room's code is never going to work. Is that because the decompiler is imperfect? I see that a new decompile wont recompile without a lot of work - which is what led me to EO's archive in the first place, now that I think about it.

Maybe distributing a rebuilt RESOURCE.001 is the only real option for any mods that change code?

I'd like to distribute mods in the most law abiding way possible, but end users often struggle to get stuff like this working if it's too complicated. On the other hand, distributing a zip with the full game pre-patched, even if the copy protection was left intact, seems like a really sketchy thing to do.

Speaking of RESOURCE files. Are there any utilities that would allow me to split things up to fit on physical 3.5 disks? If anyone has experience with any companies that print disks and boxes, please let me know.
Title: Re: Script patch files
Post by: MusicallyInspired on September 23, 2021, 12:32:41 AM
What I've done to create script patch files is backup my RESOURCE files, compile the altered script, extract it in the game directory, and then copy the backed up RESOURCE files back into the game folder. Obviously this doesn't work for everything (like SCRIPT.000 which would break the entire game by doing this method because many scripts require being recompiled together with others to function), but it works for smaller incidental scripts.

Alternatively, you could create an IPS binary differential patch, which is what NRS's SQ4CD patch does.

As for splitting up RESOURCE files, you can do that when you save a resource. It asks you the resource number and then the resource file number to save it in. This is usually left as 0 but you can put any number in there. Each number would be for a different disk. There's no automatic way to handle this unfortunately or track how large the files are becoming like Sierra probably were able to do (outside of just checking it in Explorer) but with a little trial and error it's possible. There's also 7zip and Winrar which can natively split compressed archives into separate smaller files and they even have presets for floppy disks.
Title: Re: Script patch files
Post by: doomlazer on September 23, 2021, 02:39:40 AM
Thank you, that helped me adjust my workflow enough to get things working. I was doing a few things wrong.

Attached below is the result: KQIV Whale Tongue Accessibility Patch

As for the splitting up the resources files into 3.5 floppies, that points me in the right direction. I'll probably shelve the idea for the time being.

Title: Re: Script patch files
Post by: Kawa on September 23, 2021, 06:38:56 AM
This ties into a larger question about distributing mod files for the original games. I believe even modified VIEW patches would technically be a copyright violation as derivative work are prohibited under copyright. I'm trying to decide if, on larger mods with many changes, I'll need to distribute all the VIEW patches and the SCR folder or if it's best to just rebuild resource.001 and distribute that (which seems to work fairly well)?
I am not a lawyer... nor am I someone who gives a frick, considering I have patches to turn LSL2's Polyester Patty in Passionate Patti, and play DOS PQ2 with the Japanese sprites and have no qualms putting them in a publicly accessible place (https://helmet.kafuka.org/sci/dumb/).
Title: Re: Script patch files
Post by: Collector on September 23, 2021, 08:20:02 AM
What I've done to create script patch files is backup my RESOURCE files, compile the altered script, extract it in the game directory, and then copy the backed up RESOURCE files back into the game folder.

I would also think you'd also need to backup the map file.
Title: Re: Script patch files
Post by: doomlazer on September 23, 2021, 11:42:04 AM
Yes, resource.map should be backed up too. I've been making copies of the folder and they are multiplying like rabbits!

@Kawa, I guess I don't really care about copyright either, but I do see the potential for Activision (or the current license holder) to send out cease and desist letters. Maybe they don't care as long as I'm not disabling the CopyProtect.
Title: Re: Script patch files
Post by: doomlazer on September 23, 2021, 11:59:14 AM
DOS PQ2 with the Japanese sprites

I'll have to check this out later. Looks cool.
Title: Re: Script patch files
Post by: MusicallyInspired on September 23, 2021, 12:13:34 PM
Yes, I was lumping the MAP file in mentally with the RESOURCE files I mentioned. Sorry if that wasn't clear.

@Kawa, I guess I don't really care about copyright either, but I do see the potential for Activision (or the current license holder) to send out cease and desist letters. Maybe they don't care as long as I'm not disabling the CopyProtect.

Honestly I'd doubt they'd know you exist. This kind of stuff is just not on their radar.
Title: Re: Script patch files
Post by: doomlazer on September 23, 2021, 12:29:11 PM
Ok, I won't worry about it then. If they haven't complained about the fan remakes it sounds like a non-issue.
Title: Re: Script patch files
Post by: Kawa on September 23, 2021, 02:20:49 PM
Honestly I'd doubt they'd know you exist. This kind of stuff is just not on their radar.
I know Al Lowe knew I exist... though I think I might've still gone by my old handle back then.
Title: Re: Script patch files
Post by: MusicallyInspired on September 24, 2021, 11:20:49 AM
Ok, I won't worry about it then. If they haven't complained about the fan remakes it sounds like a non-issue.

When Vivendi was the sole owners, they contacted AGDI and an official license was negotiated. They also negotiated with The Silver Lining a couple times (after a couple shutdowns) and have permission for that too with a license. When ActiVision bought Vivendi however, they allowed the existing contracts to be honoured (obviously) but explicitly stated they didn't want any more licensed remakes. IA's SQ2VGA and KQ3VGA went ignored however. I think ActiVision is just willing to turn a blind eye as long as it doesn't get too big and would have done the same with AGDI's games had they not already been under contract, but since they were they had to take a stance and address it. IA's games still remain ignored, however. I just really think they're happy to ignore it even if they DO notice it.
Title: Re: Script patch files
Post by: doomlazer on September 26, 2021, 11:53:59 PM
Ok, another script patch question. This one specifically relates to this thread about SQIV easter eggs (http://sciprogramming.com/community/index.php?topic=1994.msg14438#msg14438).

I thought it was interesting that the two SQIV easter eggs caused a lock up and were removed altogether down the road. Looking at the code, the conflict is fixed with a (curRoom script?) check. Restoring both eggs in the CD version should only require rm397 .src and .view patch files.

I plugged the code from the floppy versions into the SCIDArchive's SQ4CD source and updated the variables where needed. The problem is, while a patch with no egg code works fine, if I try to add a feature to the room I get interpreter error 4 (couldn't find info of these error codes). Even if I try adding a 3rd shelf as a sq4Feature it breaks, so I don't understand what I'm doing wrong. I thought it might be a version stamp check problem, but I can get narrator say: calls to work in the .src patch.

Until today, I've focused on SCI0, so it's probably something stupid, but after reading the relevant documentation and two different SCI1.1 tutorials I don't see why I can't lick the wall.

I've attached the rm397.sc file if anyone would like to take a look at the code. All the egg additions are currently block commented out.

Edit: technically if I got the .src patch working the rm397.view patch is optional. The CD version only erases the middle finger from the cel, so you could restore both easter eggs while keeping things PG.

I've checked to see if this easter egg has already been restored, but I don't see it listed here (https://www.spacequest.net/sq4/patches/). Please let me know if this has already been patched.
Title: Re: Script patch files
Post by: Kawa on September 27, 2021, 07:56:53 AM
Oops #4 means that a given object pointer did not in fact point to an object. It's like a null pointer exception but it doesn't have to be 0. The CD version of Space Quest 4 has separate Heap and Script resources, so if you change a SCR file, depending on the exact changes you will need a matching HEP file. Adding a Feature counts, as these would be defined in the HEP.

SCI0 has only SCR files, containing both the code and data, which is actually a good way to run out of heap space. That's what the split was for.
Title: Re: Script patch files
Post by: doomlazer on September 27, 2021, 11:19:53 AM
It was that easy? I spent hours stuck on that! At least now I know. Thank you.
 
Title: Re: Script patch files
Post by: Collector on September 28, 2021, 02:00:21 AM
Oops #4 means that a given object pointer did not in fact point to an object. It's like a null pointer exception but it doesn't have to be 0.

Do we have a list of the interpreter exception ID numbers anywhere?
Title: Re: Script patch files
Post by: OmerMor on September 28, 2021, 05:26:08 AM
Oops #4 means that a given object pointer did not in fact point to an object. It's like a null pointer exception but it doesn't have to be 0.

Do we have a list of the interpreter exception ID numbers anywhere?

Here they are: https://github.com/OmerMor/SCI16/blob/master/INTERP/PMACHINE.H#L17-L32
Code: [Select]
#define E_BAD_DISPATCH        0
#define E_BAD_OPCODE          1
#define E_BAD_KERNAL          2
#define E_LOAD_CLASS          3
#define E_NOT_OBJECT          4
#define E_BAD_SELECTOR        5
#define E_CANT_FIXUP          6
#define E_ZERO_DIVIDE         7
#define E_STACK_BLOWN         8
#define E_ZERO_MODULO         9
#define E_LEFT_CLONE          10
//unused                      11
#define E_PACKHANDLE_HEAP     12
#define E_PACKHANDLE_HUNK     13
#define E_PACKHANDLE_FAILURE  14
#define E_ODD_HEAP_RETURNED   15

And their messages: https://github.com/OmerMor/SCI16/blob/master/INTERP/DEBUG.C#L864-L916
Code: [Select]
E_BAD_DISPATCH        "Dispatch number too large: %d"
E_BAD_OPCODE          "Bad opcode: $%x"
E_BAD_KERNAL          "Kernal entry # too large: %d"
E_LOAD_CLASS          "Can't load class %d"
E_NOT_OBJECT          "Not an object: $%x"
E_ZERO_DIVIDE         "Attempt to divide by zero."
E_BAD_SELECTOR        "'%s' is not a selector for %s."
E_STACK_BLOWN         "Stack overflow."
E_ZERO_MODULO         "Zero modulo."
E_LEFT_CLONE          "Clone without script--> %d"
E_VER_STAMP_MISMATCH  "The interpreter and game version stamps are mismatched."
E_PACKHANDLE_HEAP     "PackHandle failure, duplicate table error at $%x in heap"
E_PACKHANDLE_HUNK     "PackHandle failure, checksum error in loadlink at segment $%x"
E_PACKHANDLE_FAILURE  "PackHandle failure, missing handle is for $%x segment"
E_ODD_HEAP_RETURNED   "Heap failure, attempt to return heap at odd address. Address given is $%x "
E_INVALID_PROPERTY    "Invalid property %d"
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 03:33:28 PM
Thank you, very helpful!

Quick question. I'm trying to track down KQIV AGI ver. 2.0 because it's the only game version with several easter eggs. Does anyone know if it is available anywhere for purchase or was it part of any collection? The only KQIV AGI versions I can find don't have the eggs :(
Title: Re: Script patch files
Post by: Collector on September 28, 2021, 03:52:37 PM
No, none of the collections included any of the AGI versions. The likes of eBay are the most likely to have it.
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 04:13:08 PM
Which eggs eggsackly? I have a copy here that seems to include the pirate, beam-up, and rap eggs if that's the one you mean.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 04:22:34 PM
That's the one! I'm interested in looking at porting those eggs to the SCI version.
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 04:27:05 PM
I had the same thought, actually.
Title: Re: Script patch files
Post by: MusicallyInspired on September 28, 2021, 04:31:23 PM
Didn't NRS already do that for his Ultimate KQ4 Patch?
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 04:33:23 PM
That shouldn't be a reason for doomlazer to not do it and at the very least gain zetta experience. How many others before me have disabled the copy protection on these games, after all?
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 04:58:23 PM
I wasn't aware of the KQIV Ultimate patch because it was listed on the wiki under installers and not patches. Looking at the readme, it does include the "Beam Me" egg, which is the largest of the 3. I'll have to verify if "Pirate" and "Rap" are also included, but it seems likely.

I'm wavering on the value of converting these to standalone patch files. Yes, it would be helpful personally in learning AGIStudio, but I'd rather spend my time on something that isn't replicating existing solutions.
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 05:17:17 PM
So... I can remove the copy of KQ4 AGI I uploaded for you? :3
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 05:20:08 PM
weird, I installed the KQIV ultimate patch, but I'm not finding any of the egg assets and the game doesn't understand the word Beam. Strangely it disables the copyprotect. Looking at the readme, it mentions "beam me" but doesn't explicitly state it's been included in the patch and the forum link they include is dead. The eggs might not have been ported yet.

I would be interested in the AGI version you have, Kawa.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 05:30:12 PM
This little guy was in the KQIV Ultimate patch. Not sure who he his.

(https://i.imgur.com/6EcY3j5.png)
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 05:36:06 PM
I would be interested in the AGI version you have, Kawa.
Check your PMs :3
Title: Re: Script patch files
Post by: Collector on September 28, 2021, 05:39:22 PM
No, my ultimate installer does not include anything from the AGI version. The eggs are the only thing worth importing. If you do manage to convert the eggs to SCI I'll certainly consider adding them to the installer
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 05:45:43 PM
Great, I'll let you know if I can get something put together.

I've been working on some other accessibility patches for KQIV as well that alter the whale tongue climb and remove fall death if those are of any interest.
Title: Re: Script patch files
Post by: Collector on September 28, 2021, 05:50:25 PM
This little guy was in the KQIV Ultimate patch. Not sure who he his.

(https://i.imgur.com/6EcY3j5.png)

A scarab?
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 05:59:42 PM
Well... yes, but I've never seen it before. Must be visiting from the amiga version, but I don't see anything in the scripts that references view: 990
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 06:16:58 PM
That happens sometimes.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 06:53:46 PM
Is there a tool for converting exported AGI views to SCI? It wouldn't be too bad redrawing the views if need be.

Since I can't search for words across all scripts in AGIStudio, is there a tool to just dump them all as text files? I'd to avoid combing through 246 logic files. I did look through the utilities, but I'm hoping there is something I'm not seeing.

Also, the AGI pirate easter egg is activated by entering the debugger and entering "pirate" at the prompt. This seems like it might not be possible with the SCI debugger or is it? Just responding to user input for the word in-game would be easy, but feels like a poor compromise.
Title: Re: Script patch files
Post by: Kawa on September 28, 2021, 07:59:22 PM
I'm not currently in a position to check but with luck SV can export AGI views as sprite sheets. You can't import them as such in SCI Companion, but it's at least a bit of help.

For scripts I found when I checked if all three eggs were there that importing the game in WinAGI automatically decompiles the lot to a folder full of LGC files.

I haven't played the AGI version but it came with a readme file that claimed the pirate egg was activated in another way... if I remember correctly. I might not. Again, not in a position to check.

Personally I'd be tempted to make the Bobalu copy protection bypass trigger the pirate egg instead.
Title: Re: Script patch files
Post by: Collector on September 28, 2021, 08:35:39 PM
By all means do so.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 08:37:42 PM
Great, that points me in the right direction.

I looked at the readme and I understand the egg better now. The instruction Alt+D to open the debugger is to bypass the copy protection! If you type "marble" it launches the game, "pirate" shows the egg. The online easter egg descriptions didn't make it clear you were supposed to be using the debugger to bypass CP.

I like your suggestion about bobalu. Does allowing bobalu and marble to bypass CP, but pirate to produce the egg seem like a good compromise?
Title: Re: Script patch files
Post by: EricOakford on September 28, 2021, 08:46:22 PM
Great, that points me in the right direction.

I looked at the readme and I understand the egg better now. The instruction Alt+D to open the debugger is to bypass the copy protection! If you type "marble" it launches the game, "pirate" shows the egg. The online easter egg descriptions didn't make it clear you were supposed to be using the debugger to bypass CP.

I like your suggestion about bobalu. Does allowing bobalu and marble to bypass CP, but pirate to produce the egg seem like a good compromise?

"Marble" works in version 2.0. In version 2.2, the command was changed to "wave anchor".

On another note, I have actually completed my KQ4 system upgrade. It involved major code rewrites that take advantage of the procedures introduced since the game's initial release.
One thing I did was make the various objects into instances rather than new: objects. This gives the advantage of specifying their individual properties, freeing up a lot of heap space.
Another thing I did was replace much of the Load commands with the LoadMany procedure, freeing up some more heap.
Also, I restored the inventory item descriptions, lifted directly from the AGI version.
Finally, Lolotte's dialog sequences were moved into their own room, numbered 192, since room 92 used WAY too much heap space.

Feel free to PM me if you'd like to test it. The LSL2 upgrade is up next on my agenda, and it should be much easier, since Sierra already did the major code rewrites for the Amiga version.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 08:59:42 PM
Great! I've been hoping to put everything back into that throne room!

Do the changes require an updated interpreter or is the 0.000.502 version still compatible?
Title: Re: Script patch files
Post by: Collector on September 28, 2021, 09:10:28 PM
Is there a tool for converting exported AGI views to SCI? It wouldn't be too bad redrawing the views if need be.

Try this.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 09:54:34 PM
I was doing it by hand with SV and SC, which works well, but slowly.

VEW2VEW.exe is the trick for converting AGI to SCI views, thank you! A bit strange there were no spaces between the flags and the arguments and you have to manually fix mirror views, but that's a huge time saver for something like this. 
Title: Re: Script patch files
Post by: EricOakford on September 28, 2021, 11:09:21 PM
Great! I've been hoping to put everything back into that throne room!

Do the changes require an updated interpreter or is the 0.000.502 version still compatible?

The game was completely rebuilt. The changes will require updating the interpreter to 0.000.685 (the newest SCI0 interpreter), since that is the interpreter version I've been focusing on. I've already got that covered, using the interpreter and drivers from the Iceman demo.

And I've just fixed a last-minute bug relating to the new room 192. It seemed like the castle region was not being disposed when leaving. That's fixed.
Title: Re: Script patch files
Post by: doomlazer on September 28, 2021, 11:45:33 PM
How will you handle the interpreter in regards to the archive? Just add the 0.000.685 requirement to the readme or would you include the interpreter in the KQIV folder?

A general question. Why are StrCmp and StrLen terminating at whitespaces? The SC docs show it using strings with spaces, but I can't get it to match {wave anchor} and StrLen thinks that's a 4 character string.
Title: Re: Script patch files
Post by: Kawa on September 29, 2021, 03:42:00 AM
Great, that points me in the right direction.

I looked at the readme and I understand the egg better now. The instruction Alt+D to open the debugger is to bypass the copy protection! If you type "marble" it launches the game, "pirate" shows the egg. The online easter egg descriptions didn't make it clear you were supposed to be using the debugger to bypass CP.

I like your suggestion about bobalu. Does allowing bobalu and marble to bypass CP, but pirate to produce the egg seem like a good compromise?

"Marble" works in version 2.0. In version 2.2, the command was changed to "wave anchor".

On another note, I have actually completed my KQ4 system upgrade. It involved major code rewrites that take advantage of the procedures introduced since the game's initial release.
One thing I did was make the various objects into instances rather than new: objects. This gives the advantage of specifying their individual properties, freeing up a lot of heap space.
Another thing I did was replace much of the Load commands with the LoadMany procedure, freeing up some more heap.
Also, I restored the inventory item descriptions, lifted directly from the AGI version.
Finally, Lolotte's dialog sequences were moved into their own room, numbered 192, since room 92 used WAY too much heap space.

Feel free to PM me if you'd like to test it. The LSL2 upgrade is up next on my agenda, and it should be much easier, since Sierra already did the major code rewrites for the Amiga version.
It's kinda wild that this is a thing we can do.
Title: Re: Script patch files
Post by: Kawa on September 29, 2021, 03:47:17 AM
How will you handle the interpreter in regards to the archive? Just add the 0.000.685 requirement to the readme or would you include the interpreter in the KQIV folder?

A general question. Why are StrCmp and StrLen terminating at whitespaces? The SC docs show it using strings with spaces, but I can't get it to match {wave anchor} and StrLen thinks that's a 4 character string.
If this is about the copy protection screen might I suggest using the hashes instead of the actual string?

Code: [Select]
; Sierra's version
((not (StrCmp @userInput {BOBALU})) (gRoom newRoom: 700))

; My suggestion:
((== inputSum 437) (gRoom newRoom: 700)) ;bobalu
((== inputSum 782) (do the pirate egg thing)) ;wave anchor

(hashes for both answers created with https://helmet.kafuka.org/sci/kq4_cp.html because why not)



Edit: (FormatPrint {StrLen of %s is %d} {wave anchor} (StrLen {wave anchor})) says it's 11?
Title: Re: Script patch files
Post by: Collector on September 29, 2021, 09:38:24 AM
"Marble" works in version 2.0. In version 2.2, the command was changed to "wave anchor".
Are you sure? I just tried this with the 5.25" and 3.5" versions of 2.2 as well as my copy of 2.3. The input at that point does not accept a space. It fails with waveanchor.
Title: Re: Script patch files
Post by: EricOakford on September 29, 2021, 10:35:29 AM
How will you handle the interpreter in regards to the archive? Just add the 0.000.685 requirement to the readme or would you include the interpreter in the KQIV folder?

The required drivers and interpreter are already in the folder. I see no issue with that, since they're from a game demo.

"Marble" works in version 2.0. In version 2.2, the command was changed to "wave anchor".
Are you sure? I just tried this with the 5.25" and 3.5" versions of 2.2 as well as my copy of 2.3. The input at that point does not accept a space. It fails with waveanchor.

You have to press ALT-D first to clear the copy protection prompt and use the regular parser. THEN you input "pirate" to bring up the pirate easter egg, or "wave anchor" to go to the title.

It's kinda wild that this is a thing we can do.

It's a lot like BG1Tutu, which ported the content of the first Baldur's Gate game into its sequel's engine, complete with all of its new features.
Title: Re: Script patch files
Post by: doomlazer on September 29, 2021, 12:23:14 PM
Edit: (FormatPrint {StrLen of %s is %d} {wave anchor} (StrLen {wave anchor})) says it's 11?

Edit: I wasn't being clear here. In the CopyProtect source StrLen for @userInput stops at the whitespace.



I like this hash solution. I'll do some testing with "wave anchor" to see if it works, but it's sounding like the space is going to be a problem.. Can't get "wave anchor" to match using the hash. Anything without a space works as expected, of course.

If we can confirm or deny that wave anchor is working on a specific version we could probably check the code to see how they deal with the whitespace.
Title: Re: Script patch files
Post by: doomlazer on September 29, 2021, 12:33:07 PM
Also, EO's decompile archive is amazing in my opinion. It will open up the ability for casual devs to start easily modding the retail games without having to do all the work fixing decompiles for the entire game first - which was very daunting when I first looked into SCICompanion. I see some really exciting possibilities for not only bug patches, egg restoration, etc., but large scale mods and conversions.

The required drivers and interpreter are already in the folder. I see no issue with that, since they're from a game demo.

I was assuming you'd need to include sierra.com or some other binary for the interpreter change. I guess that's not the case.
Title: Re: Script patch files
Post by: Kawa on September 29, 2021, 03:47:41 PM
I like this hash solution. I'll do some testing with "wave anchor" to see if it works, but it's sounding like the space is going to be a problem.. Can't get "wave anchor" to match using the hash. Anything without a space works as expected, of course.
Eric's KQ4 decompile uses my work for the copy protect screen.
Code: [Select]
(for ((= i 0)) (< i (StrLen @userInput)) ((++ i))
(= ch (& (= ch (StrAt @userInput i)) $005f)) ;ch = userInput[i] & 0x5F -- get uppercased ch
(StrAt @userInput i ch) ;put that uppercase character back so we can detect BOBALU later on
(+= inputSum ch)
)
I think I see the problem. Space is 0x20, and 0x20 & 0x5F is null. This superfluous uppercasing thus tricks StrLen into thinking the word ends after "wave". My simulator doesn't do that. And the only reason it does that second StrAt call to put the character back is to compare it to "BOBALU"... which we can just do with a hash.

Solution:
Code: [Select]
(for ((= i 0)) (< i (StrLen @userInput)) ((++ i))
(= ch (& (= ch (StrAt @userInput i)) $005f)) ;ch = userInput[i] & 0x5F -- get uppercased ch
;;; (StrAt @userInput i ch) ;DON'T put that uppercase character back!
(+= inputSum ch)
)
Title: Re: Script patch files
Post by: doomlazer on September 29, 2021, 04:36:41 PM
That does it. Obviously I need to learn more about text encoding.

I've attached a draft of the pirate egg if anyone wants to critique an early version. It's mostly there - needs better centering and the midi I exported/imported from AGI is using a weird instrument, but I'll go through the sound editor documentation.

Is the AGI system font available? I'm not seeing the one they use on the wiki SV didn't have any font files. Also, if it's possible to emulate the red line around the AGI text box without patching system files, please let me know. It might be easier to fake the text prompt with a view.
Title: Re: Script patch files
Post by: Kawa on September 29, 2021, 05:11:21 PM
That does it. Obviously I need to learn more about text encoding.

I've attached a draft of the pirate egg if anyone wants to critique an early version. It's mostly there - needs better centering and the midi I exported/imported from AGI is using a weird instrument, but I'll go through the sound editor documentation.

Is the AGI system font available? I'm not seeing the one they use on the wiki SV didn't have any font files. Also, if it's possible to emulate the red line around the AGI text box without patching system files, please let me know. It might be easier to fake the text prompt with a view.
The AGI system font is basically just whatever the IBM PC (or PCJr I guess) itself used, specifically the 8x8 version. https://int10h.org/oldschool-pc-fonts/ may help here.

As for simulating the AGI text boxes, this was actually attempted in Space Quest 4. (https://helmet.kafuka.org/logopending/2020/07/30/space-quest-4-roger-wilco-and-the-failed-attempt-at-being-cute/)
Title: Re: Script patch files
Post by: doomlazer on September 29, 2021, 07:07:40 PM
Does the Graph procedure exist in SCI0? I can get sq1Window to compile without it.
Title: Re: Script patch files
Post by: EricOakford on September 29, 2021, 07:31:28 PM
Does the Graph procedure exist in SCI0? I can get sq1Window to compile without it.

Yes, it does. And it's a kernel function, so it's all in the interpreter.
However, the vocab.999 (kernel function list) tends to be out of date for each game. This leads to things like kernel_112 for games that use the Graph function, but don't have it listed in vocab.999, since the decompiler relies on that list if it's there.
Title: Re: Script patch files
Post by: doomlazer on September 29, 2021, 09:01:57 PM
I should have made the connection to use kernel_112 because I did see that in sci.sc. Oh well, I'm still learning.

I'm getting very close on the software pirate (alignment is still off). I've already corrected the text boarder color to 4, not 5. I tried several fonts, including an "AGI" font I found that was too large, even imported at 8pt. I'll keep searching for something closer.

(https://i.imgur.com/cLFbKvt.png)
(https://i.imgur.com/kTAftXt.png)

I've already done a lot of the leg work on the other two eggs. I've reviewed the AGI scripts and don't anticipate too much trouble translating them to SCI. 

I'm going to have to redraw the teleportation cels for SCI, because it's smaller than SCI Rosella, but once it switches rooms I'm going to reuse the AGI graphics. They look a bit different than the SCI, but I think that's the best option.

The rap "dancing" mostly re-uses Rosella's existing views, except for these two loops - might have to redraw those.

(https://i.imgur.com/Uom3avk.png)

I appreciate all the help from this forum! It's been invaluable with so many idiosyncrasies to learn between versions and still being a green at coding in general.
Title: Re: Script patch files
Post by: Collector on September 29, 2021, 10:26:36 PM
You have to press ALT-D first to clear the copy protection prompt and use the regular parser. THEN you input "pirate" to bring up the pirate easter egg, or "wave anchor" to go to the title.

I never did that. I guess that marble and pirate worked without ALT-D because no space was required.
Title: Re: Script patch files
Post by: doomlazer on September 30, 2021, 10:46:26 AM
Just to clarify, Alt-D is required for marble and pirate as well in the AGI version. I don't believe it's technically possible to hide bobalu behind the debugger in the SCI version.

A few updates:

I think I'm going to use font 0 (if it matches SQ4's font 0) for the AGI-style text instead of trying to match the AGI system font. If that's how sierra did it in SQIV, then it's good enough for me. Isn't the pixel aspect ratio different between AGI and SCI? Probably why sierra didn't create a custom font for sq4.

I was wrong about the rap reusing views. KQ4AGI view 167 contains all the dance moves. One of the loops looks almost identical to the falling animation which threw me off at firsts. Instead of redrawing this view in SCI I've come up with what I think is a good compromise:

I recall in the SCI version that the castle cell is inaccessible after murdering Lolotte, which is the only time you can trigger the egg in the AGI version. Therefore I'm going to just unlock the cell door in the hallway post-game. I have to patch the hall anyway because you "beam me" from that location. When the player enters the cell it will transition to a new room with the AGI background and Rosella's AGI walking views. This best preserves the original egg in my opinion, but I'm also open to criticism.

Unfortunately, I'm going to have to include a vocab.000 patch since the rap is triggers with "rap kq" and kq isn't included in SCI. Rap is a synonym of Knock, so it's already there. I could trigger it with just "rap", but that doesn't feel right.



Title: Re: Script patch files
Post by: MusicallyInspired on September 30, 2021, 02:01:33 PM
That shouldn't be a reason for doomlazer to not do it and at the very least gain zetta experience. How many others before me have disabled the copy protection on these games, after all?

Wasn't my intention. Sorry for the confusion. Just thought maybe he could reference how he did it.

Also, regarding converting AGI Views to SCI, you can just copy and paste cel frames between AGI Studio and SCI Companion. That's how I did it with placeholder AGI Views for KQ2SCI. But the tool Collector provided would be easier if it works. You could just batch-process it for multiple resources.
Title: Re: Script patch files
Post by: Kawa on September 30, 2021, 05:13:45 PM
I think I'm going to use font 0 (if it matches SQ4's font 0) for the AGI-style text instead of trying to match the AGI system font.
Or you could use my work. https://helmet.kafuka.org/sci/fonts/PxPlus%20CGA.fon
(https://helmet.kafuka.org/sci/fonts/.pxpluscga.png), as an SCI font resource that you can import.
Quote
If that's how sierra did it in SQIV, then it's good enough for me. Isn't the pixel aspect ratio different between AGI and SCI? Probably why sierra didn't create a custom font for sq4.
The AGI font is actually drawn in 1:1 pixels -- the graphics (including the window frame) are only 2:1 because of its PCJr origins. On the other hand there's technically no reason you can't have a 2:1 font in SCI, and the only reason AGI's is 1:1 is because that's the 8x8 font from CGA text mode, which may be different on certain systems. It's only in Hercules mode that AGI uses its own font.

(Fun fact: on a CGA video card, there's only 8x8 fonts. In 25-line mode, it doubles up the font graphics into 8x16.)
Title: Re: Script patch files
Post by: doomlazer on September 30, 2021, 06:41:52 PM
Or you could use my work. https://helmet.kafuka.org/sci/fonts/PxPlus%20CGA.fon

Works perfectly, thank you! I actually checked your font page yesterday, but I was reading the file names and missed the example text message on that one.


you can just copy and paste cel frames between AGI Studio and SCI Companion.

Great tip! VEW2VEW had a few issues, so I went back to doing things manually from SV to SC. I was exporting .bmp one at a time, so hopefully this speeds things up a bit in the future.
Title: Re: Script patch files
Post by: doomlazer on October 01, 2021, 02:05:39 PM
Is there a way to override the font for unexpected player input on a per room basis? It's a bit jarring for text to be in AGI font, then switch to the default font for messages like, "That isn't understood."
Title: Re: Script patch files
Post by: doomlazer on October 01, 2021, 03:16:28 PM
Why does looping within a script overflow the stack?

Code: [Select]
(1
  (if (< localVar 20)
    ;do something
    (self cue:)
  )
  (2
    (++ localVar)
    (self changeState: 1) ;stack overflow after several loops
  )
)
Title: Re: Script patch files
Post by: Kawa on October 01, 2021, 03:30:16 PM
Your stack pops because you're calling changeState from within changeState.

The proper way to go back to the previous state is to do (= state X) (= cycles Y) where X is the target state - 1, and Y is something nice and small but not zero. A single cycle will do for a near instant kick back to that earlier state.

Oh, and self cue: is Bad Form for the same reason, that just indirectly calls changeState from within changeState.

Also, your parenthesis seem to be broken.
Code: [Select]
(1
   ....
)
(2
   ....
)
Title: Re: Script patch files
Post by: doomlazer on October 01, 2021, 04:17:23 PM
The parenthesis was just sloppy typing, but thank you for the correct way to loop. I'll have to go back and change all my (self cue:) calls to cycles! It appears several times decompiling KQ4, so I learned that bad habit from Sierra.


Is there a way to override the font for unexpected player input on a per room basis? It's a bit jarring for text to be in AGI font, then switch to the default font for messages like, "That isn't understood."

I'm thinking the way to handle this is to write my said spec, then claim anything that it didn't catch and print my own "not expected" message. Would that be right?

Edit: This works unless the parser doesn't recognize a word, then I'm unable to catch the event. Might just have to live with that.

Trivia: the skeleton in Lolotte's cell in the AGI version is named James
Title: Re: Script patch files
Post by: Kawa on October 01, 2021, 06:59:48 PM
Trivia: the skeleton in Lolotte's cell in the AGI version is named James
Not necessarily! Unless James has his own dedicated word group, the decompiler has very little choice but to use the alphabetically-first item in a group when converting a saidspec back to plain text: https://helmet.kafuka.org/logopending/2020/03/26/ball-road/
Title: Re: Script patch files
Post by: doomlazer on October 01, 2021, 07:40:27 PM
Your blog has some great stuff. Is the LSL2 source code in EO's archive?

I went back into SV and James is word group 92 with the only synonyms being skeleton/s. There are one and a half skeletons in the room, so which one is James we may never know.

Edit: the skeleton in the whales mouth is called James in SCI version. This is why it works in the cell.
Title: Re: Script patch files
Post by: EricOakford on October 01, 2021, 08:05:34 PM
Your blog has some great stuff. Is the LSL2 source code in EO's archive?

No, just the decompilation, which I think is close enough anyway. The only undecompilable code in that game was dyingScript, and I figured that out. I didn't feel it was necessary to change the said specs unless they didn't decompile properly, and I figured out the correct specs using SCI Viewer.

On another note, I found that KQ4 doesn't properly support the newer Avoider. This causes serious problems in the witches' cave. So it's back to the older Avoider, which not only works properly, it uses less heap space.
Title: Re: Script patch files
Post by: doomlazer on October 01, 2021, 11:55:40 PM
That's great. Did you mention you needed testing? I can get through the game pretty quick now.
Title: Re: Script patch files
Post by: EricOakford on October 02, 2021, 07:21:44 PM
That's great. Did you mention you needed testing? I can get through the game pretty quick now.

Sure! I'll send you the link.

Also, I just got rid of the Timer class. It's not needed, since you can just set the seconds directly in each script state. This will free up more heap.

So far so good...
Title: Re: Script patch files
Post by: doomlazer on October 03, 2021, 12:38:00 PM
Also, I just got rid of the Timer class. It's not needed, since you can just set the seconds directly in each script state. This will free up more heap.

In addition to the frog issues I pm'd, firing the bow at nothing will lock up the game.

This was most likely a sound driver issue on my end. I have a save game about 3 seconds before the game seizes up completely for some reason. I had left the lamp lit for about 20-30 minutes, because I couldn't remember if the lamp runs out of oil or not. In the save file, it will always lock up after a few seconds, even if I extinguish the lamp. It's too early for nightfall, but it might be a timer related issue of some kind. I'm going to start a new game and let it run without doing anything to see if it freezes. 
Edit: just letting the game run for 40 minutes didn't freeze, so I'll have to retrace my steps and see if it happens again. It's possible it's something else. I switched to the general midi driver and music doesn't loop in certain areas like the mine and dwarf house, but that happens in the vanilla version too. I'm switching back to sndblaster.DRV for the rest of testing since I'm not sure GM.DRV is officially supported in SCI0.
Title: Re: Script patch files
Post by: Collector on October 03, 2021, 03:31:56 PM
I'm switching back to sndblaster.DRV for the rest of testing since I'm not sure GM.DRV is officially supported in SCI0.

No, it is not. There is not even a MIDI track. And mismatched drivers can cause lockups. There is a fan made aftermarket GM driver by Ravi Iyengar, but it includes a few of the required game specific patches, none of which are for KQ4. The results are less than stellar. The soundtrack was written for Roland MT-32. You are far better off using the MT32.DRV with a Munt enabled build of DOSBox.
Title: Re: Script patch files
Post by: doomlazer on October 03, 2021, 05:08:10 PM
Thank you for clarifying. I was using GM.DVR since it switched to munt if available, but it's just causing problems.

I believe ADL.DRV (which ships with steam and GoG versions) is mono, so I'm assuming sndblast.drv or mt32.drv would be the two best choices for KQ4?

Title: Re: Script patch files
Post by: EricOakford on October 03, 2021, 07:39:43 PM
Also, I just got rid of the Timer class. It's not needed, since you can just set the seconds directly in each script state. This will free up more heap.

In addition to the frog issues I pm'd, firing the bow at nothing will lock up the game.

Oops, looks like the Timer class was needed after all. I brought it back, and tested firing arrows and wearing the crown. They work properly again. I also fixed a bug where Rosella would fall into the pool again after she's already fallen in.

I believe ADL.DRV (which ships with steam and GoG versions) is mono, so I'm assuming sndblast.drv or mt32.drv would be the two best choices for KQ4?

That's right. SNDBLAST.DRV not only has stereo sound, but digital audio as well, which I've added from the Amiga version. MTBLAST.DRV allows for both MT-32 music and digital audio.
LSL2 also has Amiga-specific sound effects.
Title: Re: Script patch files
Post by: Kawa on October 03, 2021, 08:03:29 PM
There is not even a MIDI track.
I assume you meant to say there's no General MIDI tracks.
Title: Re: Script patch files
Post by: doomlazer on October 03, 2021, 09:56:37 PM
That's right. SNDBLAST.DRV not only has stereo sound, but digital audio as well, which I've added from the Amiga version.

I see 607 & 608 are day/night additions to the forest below the ogre's house. That's pretty cool. Do the digital sounds require the 0.000.685 interpreter or is that also supported on .502 with the adlib drivers?

If you want to send a link to a new build I'll test some more. I didn't finish the first run because of the timer.
Title: Re: Script patch files
Post by: Collector on October 04, 2021, 12:05:34 AM
Of course.
Title: Re: Script patch files
Post by: doomlazer on October 04, 2021, 02:01:38 AM
So... would a short speech sample be possible in KQIV? I couldn't find a way to import a .wav into a SCI0 game.

Unrelated, I'm running into a problem testing the AGI Easter port and SCUMMVM. Scumm doesn't like me using the sq1Window class. The attached pic shows that the box correctly positioned, but the text doesn't seem to get the Print's #at posn. Everything works as expected with dosbox.
Title: Re: Script patch files
Post by: Kawa on October 04, 2021, 04:02:42 AM
Wrong port -- the Dialog class that Print ends up using expects that the current port is whatever window it's supposed to draw to. sq1Window switches from the window port to the screen port so it can freely draw the border, but then doesn't switch back, so the Dialog ends up drawing on the screen port as well. This is actually one of the effects described in my blog post about sq1Window:
(https://helmet.kafuka.org/logopending/wp-content/uploads/2020/07/sierra_010.png)

Speech samples are technically possible, after all SQ4 is an SCI0 game (if it's not the multi-language release) and it has samples ("Where am I?") but you'll need a third party tool to create a Sound resource with a "digital" track, as opposed to an Audio resource.
Title: Re: Script patch files
Post by: doomlazer on October 04, 2021, 07:45:27 AM
Hmm, I followed your blog post pretty closely, but I'm still missing something. I'll sleep on it, but it still seems weird it's working perfectly in dosbox, just not scummvm. Here is my sq1Window class incase anything obvious jumps out.

Code: [Select]
(class Sq1Window of SysWindow
  (properties
    underBits 0
    pUnderBits 0
    bordWid 3
  )
 
  (method (dispose)
    (SetPort 0)
    (kernel_112 grRESTORE_BOX underBits)
    (kernel_112 grRESTORE_BOX pUnderBits)
    (kernel_112 grREDRAW_BOX lsTop lsLeft lsBottom lsRight)
    (super dispose:)
  )
 
  (method (open &tmp port temp1)
    (= color 0) ;gColor)
    (= back 15) ;gBack)
    (= type 128)
 
  ` (super open:)
    (= port (SetPort 0))
 
    (= temp1 1)
    (if (!= priority -1) (= temp1 (| temp1 $0002)))
    (= lsTop (- top bordWid))
    (= lsLeft (- left bordWid))
    (= lsRight (+ right bordWid))
    (= lsBottom (+ bottom bordWid))
    (= underBits (kernel_112 grSAVE_BOX lsTop lsLeft lsBottom lsRight 1))
    (if (!= priority -1)
      (= pUnderBits (kernel_112 grSAVE_BOX lsTop lsLeft lsBottom lsRight 2))
    )
    ; Draw the background
    (kernel_112 grFILL_BOX lsTop lsLeft lsBottom lsRight temp1 back priority)
    ; Draw the border
    (kernel_112 grDRAW_LINE (+ lsTop 1) (+ lsLeft 1) (+ lsTop 1) (- lsRight 2) 4 priority) ;global131 priority)
    (kernel_112 grDRAW_LINE (- lsBottom 2) (+ lsLeft 1) (- lsBottom 2) (- lsRight 2) 4 priority)
    (kernel_112 grDRAW_LINE (+ lsTop 1) (+ lsLeft 1) (- lsBottom 2) (+ lsLeft 1) 4 priority)
    (kernel_112 grDRAW_LINE (+ lsTop 1) (- lsRight 2) (- lsBottom 2) (- lsRight 2) 4 priority)
    (kernel_112 grUPDATE_BOX lsTop lsLeft lsBottom lsRight 1)
   
    (SetPort port)
  )
)
Title: Re: Script patch files
Post by: Kawa on October 04, 2021, 08:58:14 AM
Why is there a ` in front of your (super open:) call?
Title: Re: Script patch files
Post by: doomlazer on October 04, 2021, 11:52:22 AM
I don't know how that got in there, but it's not in any of the compiled code.

I replaced my sq1Window code with sierra's version and it display's the text in the correct location through SCUMMVM, but with all the issues outlined in your blog post. I'll spend some time later testing to see if I can make SCUMMVM happy with your improved version of sq1Window somehow. Worst case, I guess I could use sierras dirty version of the windows, but it definitely doesn't looks as good as your fix. 
Title: Re: Script patch files
Post by: doomlazer on October 05, 2021, 08:05:19 PM
Just in case anyone uses the sq1Window class again, (= port (SetPort 0)) needs to be changed to work correctly in SCUMMVM:

Code: [Select]
(= port (GetPort))
(SetPort 0)

Here is the complete sq1Window class with Kawa's fix (https://helmet.kafuka.org/logopending/2020/07/30/space-quest-4-roger-wilco-and-the-failed-attempt-at-being-cute/) and the SCUMMVM fix:

Code: [Select]
(class Sq1Window of SysWindow
  (properties
    underBits 0
    pUnderBits 0
    bordWid 3
  )
 
  (method (dispose)
    (SetPort 0)
    (kernel_112 grRESTORE_BOX underBits)
    (kernel_112 grRESTORE_BOX pUnderBits)
    (kernel_112 grREDRAW_BOX lsTop lsLeft lsBottom lsRight)
    (super dispose:)
  )
 
  (method (open &tmp port temp1)
    (= color 0)
    (= back 15)
    (= type 128)
    (super open:)
    ;(= port (SetPort 0))
    (= port (GetPort))
    (SetPort 0)
    (= temp1 1)
    (if (!= priority -1) (= temp1 (| temp1 $0002)))
    (= lsTop (- top bordWid))
    (= lsLeft (- left bordWid))
    (= lsRight (+ right bordWid))
    (= lsBottom (+ bottom bordWid))
    (= underBits (kernel_112 grSAVE_BOX lsTop lsLeft lsBottom lsRight 1))
    (if (!= priority -1)
      (= pUnderBits (kernel_112 grSAVE_BOX lsTop lsLeft lsBottom lsRight 2))
    )
    ; Draw the background
    (kernel_112 grFILL_BOX lsTop lsLeft lsBottom lsRight temp1 back priority)
    ; Draw the border
    (kernel_112 grDRAW_LINE (+ lsTop 1) (+ lsLeft 1) (+ lsTop 1) (- lsRight 2) 4 priority) ;4 was global131 linecolor
    (kernel_112 grDRAW_LINE (- lsBottom 2) (+ lsLeft 1) (- lsBottom 2) (- lsRight 2) 4 priority)
    (kernel_112 grDRAW_LINE (+ lsTop 1) (+ lsLeft 1) (- lsBottom 2) (+ lsLeft 1) 4 priority)
    (kernel_112 grDRAW_LINE (+ lsTop 1) (- lsRight 2) (- lsBottom 2) (- lsRight 2) 4 priority)
    (kernel_112 grUPDATE_BOX lsTop lsLeft lsBottom lsRight 1)

(SetPort port)
  )
)