Author Topic: Restoring EcoQuest 2's debug functionality  (Read 8823 times)

0 Members and 1 Guest are viewing this topic.

Offline lwc

Restoring EcoQuest 2's debug functionality
« on: September 09, 2023, 09:11:03 AM »
Both Sluicebox' eco2 and EricOakford' eco2demo have debug scripts but it seems they're just like the game's built-in 98.scr and 98.hep files which do nothing but an initial WhereTo? dialog at boot (whereas leaving the room or doing any actions gets the game stuck!).
That was also the case with QFG1VGA and QFG3, yet EricOakford somehow managed to restore their full debug functionality on his own. Since both archives might never get another update, can anyone here do the same here like what was done with QFG1VGA and QFG3?



Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #1 on: September 09, 2023, 03:23:24 PM »
If I export the script 98 in version 1.000.000 I get the 'Where to?' dialog and I seem to be able to change screens and perform actions without freezing.

You are correct that none of the other debug commands work. That's because keyboard and mouse events aren't passed to the debug script. That's easily fixed by adding the following to the event handler in main:

Code: [Select]
(method (handleEvent pEvent)
(if (pEvent claimed?) (return 1))
((ScriptID 98) handleEvent: pEvent)  ;send events to debug
                ...

I've attached the modified 0.scr below, but it looks like there are still some issues with the script 98 heap in the game resources - the text strings are garbled. That can be fixed by recompiling script 98 in SCICompanion. The zip includes 0.scr, 98.hep and 98.scr which seems to fully restore debugging.

This is extremely untested so there could still be issues.

edit: removed outdated attachement
« Last Edit: September 11, 2023, 06:08:09 PM by doomlazer »

Offline lwc

Re: Restoring EcoQuest 2's debug functionality
« Reply #2 on: September 09, 2023, 06:55:52 PM »
Nice! But can anything be done about the following:
  • Teleporting is still practically broken because every action you pull turns the icon to an Earth symbol and it's impossible to continue playing that way (e.g. you can't exit the screen because it doesn't get changed to an exit icon).
  • It still gets frozen sometimes (I can't reproduce it but it happened when I teleported to Cibola and chose the walk icon).
  • Manual teleporting is glitched, teleport to room 501 (again Cibola) and see how Adam turns to a hidden ghost...at least he comes back after you pull an action.
  • If you touched neither 98.scr nor 98.hep, why does re-compiling them fix the texts you've mentioned?
?

Offline Collector

Re: Restoring EcoQuest 2's debug functionality
« Reply #3 on: September 09, 2023, 08:33:37 PM »
I've tried it. Almost every location starts with a bit of a cut scene that you have to wait to have control passed back to the player, but the cursor will change back after it. Two notes beyond that. While initially you can change cursors, at some point it stops changing as you switch between functions, though it seems to do the function you change to. When this happens you have to change by the top bar rather than right click to be sure of what you have selected. Second, sometimes if you open the control panel it crashes with an error 4.
KQII Remake Pic

Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #4 on: September 10, 2023, 12:05:15 AM »
Well this is weird. The cursor will freeze up anytime you score points. Collector is right, you can still change the cursor, but visually it's frozen. This can be tested from 'Where to?' by visiting the jungle or Cibola. The jungle automatically gives 1 point and you get five points by freeing the bat in Cibola. If (gGame points: 5) is commented out of the script, everything works as expected.

So here is the cause of the problem. The points method in main can take a second parameter used to set flags so that points are not repeatedly awarded for the same action. The command (gGame points: 3 888) would award three points and set flag number 888.

Code: [Select]
(method (points param1 param2)
(if (and (> argc 1) (proc0_2 param2)) (return))
(if param1
(gGame changeScore: param1)
(if param2 (proc0_3 param2)) ;set flag if param2 is passed
(if (and (> param1 0) pointSound)
(pointSound play:)
(statusCode doit:)
)
)
)

For some reason that param2 two check is non-zero even when we're not sending a 2nd param and it's passing a value of 1 to proc0_3, which is SetFlag. Well, guess what? Flag 1 is a condition checked in the game's Rain::setCursor method and if it is set the cursor will not change!

Why or how (gGame points: x) is sending a second parameter value I have no idea. But what's the quick and dirty workaround for this problem? My solution was to add a new debug command for Alt+D that clears flag 1. That way you can unstick the cursor after scoring points.

I've attached the 98.scr patch with the Alt+D command below, but ideally I'd like to figure out why the param2 value isn't 0 when there is no flag passed.



Moving on, Ghost Adam when TPing to Cibola is caused by the room you're teleporting from. Script 501's init method includes the following code:

Code: [Select]
(if (proc999_5 gGNumber 530 560 440 0 10)
(gEgo init: normalize: 510)
else
(gEgo init: normalize: 0)
)

gGNumber is the previous room variable. The procedure is checking if you came from rooms 530, 560, 440, 0 or 10 and setting the view of Adam tied to the chair (510) or his normal walk view (0).

This type of issue is common when teleporting with debug commands as most rooms have different initial actions based on the previous room. Further down in 501's init is this switch statement:

Code: [Select]
(switch gGNumber
((proc999_5 gGNumber 530 560)
(= local3 1)
(Cibola timesCaptured: (+ (Cibola timesCaptured?) 1))
(gGameSound1 number: 523 loop: -1 play: 127)
(self setScript: sAdamCaught)
)
(440
(carrot init:)
(gGameSound1 number: 521 loop: -1 play: 127)
(self setScript: sOpenSeq)
)
(500
(if (not (== (gGameSound1 number?) 522))
(gGameSound1 number: 522 loop: -1 play: 127)
)
(self setScript: sFromShackBedroom)
)
(else
(carrot init:)
(gGameSound1 number: 521 loop: -1 play: 127)
(self setScript: sOpenSeq)
)
)

Teleporting from most rooms is going to be caught by the 'else' case and run the sOpenSeq script with Mr Slaughter, but you can see there are different behaviors coming from those other room numbers. Fixing this type of issue is possible, but isn't really feasible because they need to be addressed on a room by room basis.



Finally, I think the problem with the 98.hep might be that it just doesn't exist in the resource files. If it does, the script is pointing to the wrong locations for the strings it needs in the debug text. Either way, recompiling and exporting the 98.hep allows the script to access the correct strings.

edit: removed outdated attachment
« Last Edit: September 10, 2023, 11:52:07 AM by doomlazer »

Offline lwc

Re: Restoring EcoQuest 2's debug functionality
« Reply #5 on: September 10, 2023, 03:06:18 AM »
I don't understand why would Sierra code that "else". I mean it's not like it's possible to come from any other room anyway.

But to be honest, I can live with Adam being a ghost for 2 minutes, but the Earth icon is dead end. You can choose to walk inside a room but you can never leave, since there's no white arrow. Until param2 is figured out, can you code flag 1 to clear automatically after teleporting?

As for 98.hep, last I checked it did exist in the resource files.

Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #6 on: September 10, 2023, 03:37:51 AM »
I don't actually know EQ2 very well so I can't really speak to those other room numbers, but you'll see an 'else' case in a lot of prevRoom switch statements.

Try downloading that 98.scr patch attached to my last post. It includes a command ALT+D that will unstick the globe icon allowing you to leave the room.

It's not ideal, but I'll have to figure out what's causing the param2 bug to create a better fix.

Offline lwc

Re: Restoring EcoQuest 2's debug functionality
« Reply #7 on: September 10, 2023, 03:43:30 AM »
I trust you it works, but can you make it automatic after a teleport?

Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #8 on: September 10, 2023, 11:43:15 AM »
I came up with a better solution. I test the number of args instead of the param2 value and it sidesteps the issue entirely without any user intervention needed:

Code: [Select]
(method (points param1 param2)
(if (and (> argc 1) (proc0_2 param2)) (return))
(if param1
(gGame changeScore: param1)
;(if param2 (proc0_3 param2))
(if (> argc 1) (proc0_3 param2)) ;check num of args instead
(if (and (> param1 0) pointSound)
(pointSound play:)
(statusCode doit:)
)
)
)

Replace the 0.scr with the one below and let me know if you run into any other glitches.

edit: removed bad attachment
« Last Edit: September 10, 2023, 02:54:08 PM by doomlazer »

Offline lwc

Re: Restoring EcoQuest 2's debug functionality
« Reply #9 on: September 10, 2023, 02:05:01 PM »
Wow, that fixed the teleport, thanks!
But now every other debug command fails. Even shift+/ (i.e. shortcut help) fails, any idea what's going on?

Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #10 on: September 10, 2023, 02:55:29 PM »
Yeah, there was a problem with the 0.scr I exported. I've attached the complete working patch below.

Edit: removed outdated attachment.
« Last Edit: September 11, 2023, 06:06:51 PM by doomlazer »

Offline lwc

Re: Restoring EcoQuest 2's debug functionality
« Reply #11 on: September 10, 2023, 04:09:28 PM »
Works, thanks!

Do you think you can also add what some SCI games offer in their debug - Alt+Left Mouse Button for instant movement/placement?
« Last Edit: September 10, 2023, 05:40:27 PM by lwc »

Offline OmerMor

Re: Restoring EcoQuest 2's debug functionality
« Reply #12 on: September 10, 2023, 04:20:30 PM »
Cool thread :-)

May I suggest using SluiceBox's excellent decompilation archive? For example, here's his version of the points method (link):
Code: [Select]
(method (points param1 param2)
(if (and (> argc 1) (IsFlag param2))
(return)
)
(if param1
(gGame changeScore: param1)
(if param2
(SetFlag param2)
)
(if (and (> param1 0) pointSound)
(pointSound play:)
(statusCode doit:)
)
)
)

Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #13 on: September 10, 2023, 06:22:36 PM »
May I suggest using SluiceBox's excellent decompilation archive?

Yes, I do use it; especially when SCICompanion can't decompile ASM. It's a huge timesaver.

Unfortunately, in this case his code still has the same bug that's setting flag 1 when param2 isn't passed. Checking the number of arguments instead of param2 fixes the problem and probably should have been the test in the original source.

Do you think you can also add what some SCI games offer in their debug - Alt+Left Mouse Button for instant movement/placement?

Edit: I read your post before the edit and thought you wanted Shift-ALT-Click. I've changed the 'warp' command to CRTL click because ALT by itself gets swallowed somewhere and I don't want to track it down.

The attached zip adds the following two mouse debugging commands:

CTRL - Click: Instantly move Adam to mouse x/y
CTRL - ALT - Click: Print mouse x/y

Tested working in DOSBox and ScummVM, but CTRL is used for toggling between walk and the last used icon, so both these commands still toggle the cursor. I can either disable the toggle or just know to double click when placing Adam with Ctrl Click to keep the walk icon.

Edit: Removed outdated attachment
« Last Edit: September 11, 2023, 06:06:21 PM by doomlazer »

Offline doomlazer

Re: Restoring EcoQuest 2's debug functionality
« Reply #14 on: September 11, 2023, 02:09:14 AM »
The points bug had me wondering why it only showed up after recompiling 0.scr, so I did some more investigating.

First, I verified that if you export 98.scr and use 'where to?' with an unmodified EQ2 game, earning points does not freeze the cursor. It works fine.

So as a test, I added a new procedure to script 501 that writes the first 500 flag values to a file:
Code: [Select]
(procedure (recordFlags fName &tmp temp0 file [str 50])
(= temp0 0)
(Format @str {%s.txt} fName)
(= file (File new:))
(if (file name: @str open: 0) ;fOPENCREATE
(while (< temp0 500)
(file writeString: (Format @str {flag %d: %s\n} temp0 (if (proc0_2 temp0) {True} else {False})))
(++ temp0)
)
(file close: dispose:)
else
(Print addText: {file error} init:)
)
)

Then I generated separate files before and after awarding points in 501's sAdamPaqutiaFreed script:
Code: [Select]
(3
(sLocalSound stop:)
(recordFlags {PrePoints})
(gGame points: 5)
(recordFlags {PostPoints})
...

Finally, I exported my new 501.scr, 501.hep & 98.scr and used them with an clean version of EQ2. Sure enough, when I compared the two files flag 370 had been set by awarding points.

Searching the decompiled code I see EQ2 uses less than 20 flags (some games use hundreds of flags), so this isn't a problem for the unmodified retail version. The bug never manifests because so few flags are actually used.

It's just bad luck that the changes I made in 0.scr happen to make the bug set flag 1; which is never actually set by the game, but is tested and causes the cursor to become visually locked on whatever it's using when the flag is set.

I'm guessing a lot of people already knew this, but what I proved to myself is that you should never expect unpassed parameters to be 0. They are probably some random garbage value. Instead, always check the number of arguments with 'argc' to verify that a parameter has been passed before testing it's value.

« Last Edit: September 11, 2023, 02:15:42 AM by doomlazer »


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

Page created in 0.03 seconds with 22 queries.