Author Topic: C# AGILE  (Read 83317 times)

0 Members and 1 Guest are viewing this topic.

Offline lance.ewing

Re: C# AGI Interpreter
« Reply #225 on: November 19, 2022, 05:57:16 PM »
One other glitch I noticed is that when the main form is first shown, the "Loading... Please wait" message flashes briefly before the folder dialog is displayed. It would look better if no message is shown until a game is actually being loaded.

This one will be a bit involved it seems. The problem is that it starts be seeing if it can load a game from the current directory, and if there happens to be a game in there, then we would want to show the Loading message. That is where we're getting that message flash up, i.e. while it is trying to load a game from the current directory. If there is no game in the currently directory, then it pops up the dialog.

The problem is that the AGILibrary is trying to load the game, i.e. fully decode the game, which can take a few seconds for some games. For example, if you happened to run AGILE in a directory containing KQ4 (as KQ4 is an example of a long to load one), or if you launched AGILE from WinAGI when editing KQ4, then we would want the Loading message to be displayed at that point. So AGILE displays the Loading message before it calls the AGILibrary to decode the game.

In order to stop it being displayed in the scenario where the directory doesn't contain a game, I'll need to change the AGILibrary to provide a "test directory to see if there is an AGI game" method. Sounds fairly straight forward though, so I'll give it a go later on. I'd then call that first, and that would do a quick check for the standard data files (perhaps looking for WORDS.TOK is enough to recognise a game dir; it doesn't have to be full proof) and only then would it show the message before decoding the game.

Offline lance.ewing

Re: C# AGI Interpreter
« Reply #226 on: November 19, 2022, 06:01:06 PM »
I just noticed that the number of Stars for the agile project in github went down by 1. I'm sure it was 5 over the past few weeks. Did somebody accidentally unstar it? Or was that deliberate?  ;D

Actually, while I've mentioned it, it would be cool for everyone with a github account to Star the project. That might give it a bit more visibility.

Offline lance.ewing

Re: C# AGI Interpreter
« Reply #227 on: November 19, 2022, 06:37:34 PM »
In order to stop it being displayed in the scenario where the directory doesn't contain a game, I'll need to change the AGILibrary to provide a "test directory to see if there is an AGI game" method. Sounds fairly straight forward though, so I'll give it a go later on. I'd then call that first, and that would do a quick check for the standard data files (perhaps looking for WORDS.TOK is enough to recognise a game dir; it doesn't have to be full proof) and only then would it show the message before decoding the game.

It was much quicker to implement than I thought. No need to change the AGILibrary, as testing for a single file's existence, e.g. WORDS.TOK, is a one liner. So that is now fixed and pushed to my repo.

Offline Collector

Re: C# AGI Interpreter
« Reply #228 on: November 19, 2022, 09:29:34 PM »
Yeah, that's the one. Setting to folderDialog.RootFolder = 0; does make it use the desktop as root. Although with modern Windows' Libraries being placed above the hard drives Desktop is repeated a couple down besides the actual folder in the user's space.
KQII Remake Pic

Offline Collector

Re: C# AGI Interpreter
« Reply #229 on: November 19, 2022, 09:37:22 PM »
I got an idea that some may find handy. I added a "Create Shortcut to Game" item to the context menu. Once a game is loaded clicking this item will  create an Agile shortcut to the desktop with an argument of the current game's folder. This shortcut will start the game in Agile by double clicking the shortcut. If there is interest I will polish it up and do a pull request.
KQII Remake Pic

Offline AGKorson

Re: C# AGI Interpreter
« Reply #230 on: November 20, 2022, 12:33:12 AM »
I just noticed that the number of Stars for the agile project in github went down by 1. I'm sure it was 5 over the past few weeks. Did somebody accidentally unstar it? Or was that deliberate?  ;D

This might have been me.   :-[
I'm pretty sure I starred it in the past, but it wasn't when I checked just now. I have remedied the situation.

Offline AGKorson

Re: C# AGI Interpreter
« Reply #231 on: November 20, 2022, 02:13:11 AM »
I didn't completely follow what you were saying with this one but I'll take your word for it. Currently it is setting the RootFolder to MyComputer. I have tried commenting that line out, and it changes to have Desktop at the root, rather than "This PC". Given that, I couldn't work out what you meant by the second bit regarding the original code that sets root to Desktop, or in what scenario the starting folder is always the root.
I didn't explain that very well. Let me try again.

When I run AGILE with the current code, I get this:

It always shows the 'This PC' as the starting directory, no matter what the SelectedPath property is set to. Stepping through the code, I find that in the callback function, when the BFFM_SELCHANGED message is sent during dialog initialization, the SHGetPathFromIDList call does not return a valid path.

After the dialog loads, selecting a directories by clicking also sends BFFM_SELCHANGED message. The SHGetPathFromIDList does return valid paths for these changes.

If you don't set a root directory, which means making sure the pidlRoot member of browseInfo is set to zero (by doing that explicitly, or by deleting these lines
Code: [Select]
            if (_rootFolderLocation == IntPtr.Zero) {
                PInvoke.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int)this._rootFolder, ref _rootFolderLocation);
                if (_rootFolderLocation == IntPtr.Zero) {
                    PInvoke.Shell32.SHGetSpecialFolderLocation(hWndOwner, 0, ref _rootFolderLocation);
                    if (_rootFolderLocation == IntPtr.Zero) {
                        throw new InvalidOperationException("FolderBrowserDialogNoRootFolder");
                    }
                }
            }

from the RunDialog method), then the browser uses the default root (the user's Desktop) giving this:

With this change, stepping through the code in the BFFM_SELCHANGED message handler shows that the SHGetPathFromIDList call returns valid paths for the startup directory, which results in it being selected/displayed on startup, as shown above.

I don't know why the SHGetPathFromIDList doesn't return valid paths during startup in the first case, but does in the latter. A quick check of the Microsoft reference page for SHGetPathFromIDList shows that it's no longer supported, and links to other APIs that should be used instead. I didn't bother trying to figure that all out, since it's simpler to just use the browser's default root instead of trying to force a root.

But in summary, is this the line you are saying should be removed, from the AgileForm class:

Code: [Select]
folderDialog.RootFolder = Environment.SpecialFolder.MyComputer;
No, that by itself doesn't do the trick. If you do that you do get the Desktop be the root, but the code I mention above still runs, which forces the root to the Desktop instead of defaulting to the Desktop, giving this result:

This gives just the actual file folders in Desktop; not all the 'special folders' that are also usually accessible from the Desktop. So you can't browse to folders that are outside the Desktop folder hierarchy.  And it also fails to set the starting directory (same glitch/bug as when setting This PC to be root.)

In summary, to go with the default root, delete the code I showed above. You can also delete line you referenced, and code for setting the RootFolder. And in the RunDialog method, change this line
Code: [Select]
browseInfo.pidlRoot = _rootFolderLocation;to
Code: [Select]
browseInfo.pidlRoot = IntPtr.Zero;

Offline lance.ewing

Re: C# AGI Interpreter
« Reply #232 on: November 20, 2022, 04:27:00 AM »
@AGKorson, thanks for the explanation, and also for the pull request with the changes. I have merged it and tested it locally. All is working well.


Offline vafada

Re: C# AGI Interpreter
« Reply #233 on: November 20, 2022, 11:52:04 AM »
I seem to be hitting that Gold Rush bug when its patched by AGILE:

On the Steam Version of Gold Rush:

https://store.steampowered.com/app/308000/Gold_Rush_Classic/

When AGILE patches the game, changing the game speed to `Fast` or `Fastest`  prevents the elapsed time from moving

The patch mod in AGILE for gold rush, `Changes the new.room(129) to be new.room(73)` In Logic 0

I checked Logic 129 on my game and here's what I have:

Code: [Select]
if (isset(newRoom))
  {
  set(f150);
  animationInterval = 0;
  prevent.input();
  program.control();
  status.line.off();
  v220 = 33;
  v164 = elapsedSeconds;
  ++v164;
  }
if (v164 == elapsedSeconds)
  {
  ++v221;
  if (v221 == 2)
    {
    v221 = 0;
    if (v222 < 240)
      {
      ++v222;
      }
    if (v222 == 240 &&
        v172 < 240)
      {
      ++v172;
      }
    }
  }
if (elapsedSeconds > v164)
  {
  v167 = v222;
  v167 /= 3;
  v165 = v222;
  v165 /= 4;
  if (v165 > 20)
    {
    v165 = 20;
    }
  v152 = 0;
  if (isset(f158))
    {
    animationInterval = 2;
    new.room(Logic1);
    }
  else
    {
    new.room(Logic73);
    }
  }
return();

I still can't figure out why `normal` and `slow` increments the time (seconds) but not for `Fast` and `Fastest`

Might not be worth fixing also since this seems to me a version with no copy protection?

Offline vafada

Re: C# AGI Interpreter
« Reply #234 on: November 20, 2022, 12:28:14 PM »
Ok, I believe I found the issue.

Logic 129 contains this block of code

Code: [Select]
  v167 = v222;
  v167 /= 3;
  v165 = v222;
  v165 /= 4;

Logic 0 uses those two vars (167, 165) when changing game speed:

Code: [Select]
if (animationInterval == 0) // fastest
    {
    v166 = v167;
    }
  if (animationInterval == 1) //fast
    {
    v166 = v165;
    }


with Logic 129 skipped v167 and v165 will be 0 so this block of code in Logic 0 which increments to seconds variable will never be executed

Code: [Select]
if (v156 == v166)
    {
    v156 = 0;
    ++v152; // v152 contains the elapsed seconds variable
    }

and as @collector mentioned...

Quote
haven't had a chance to see if the house buyer shows up in Gold Rush!.

The house buyer did not show up after i sold the house... this is at the beginning of the game


I played thru the steam version and no issues... Seconds was incrementing on all game speed.... i guess for the Steam version they just removed the code in the LOGIC file that does copy protection instead if skipping Logic
« Last Edit: November 20, 2022, 01:33:27 PM by vafada »

Offline Collector

Re: C# AGI Interpreter
« Reply #235 on: November 20, 2022, 05:30:42 PM »
The steam version is version 3.0, which is the Software Farm (O'Neill Bros) published version. It is the one that i worked with Sunlight Games to release. It never had copy protection and does not need to be patched. All of the earlier versions were published by Sierra with the manual check copy protection and is subject to the buyer not showing bug.
KQII Remake Pic

Offline MusicallyInspired

Re: C# AGI Interpreter
« Reply #236 on: November 20, 2022, 05:40:34 PM »
I believe the bug only took place if you put the game in any speed except Normal?

I made my own LOGIC patch with AGI Studio years back that skipped the copy protection. It's my goto now when I want to play it. I think I even patched the Apple IIgs version this way. But I still like keeping the original around so I can do my "last words" at the gallows.  ;D

EDIT: Never mind, I had tried to patch the IIGS version but it must not have worked or I ran into too much trouble at the time.
« Last Edit: November 20, 2022, 05:49:10 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline vafada

Re: C# AGI Interpreter
« Reply #237 on: November 20, 2022, 05:49:59 PM »
The steam version is version 3.0, which is the Software Farm (O'Neill Bros) published version. It is the one that i worked with Sunlight Games to release. It never had copy protection and does not need to be patched. All of the earlier versions were published by Sierra with the manual check copy protection and is subject to the buyer not showing bug.

The problem is, AGILE doesn't distinguish between steam and earlier versions and just patches the LOGIC file and skips LOGIC 129.

There must be some way for AGILE to check if the Gold Rush that's being ran needs to be patched or not to skip copy protection.


Edit: Opened a PR for version 3.0: https://github.com/lanceewing/agile/pull/62/files
« Last Edit: November 20, 2022, 07:02:36 PM by vafada »

Offline AGKorson

Re: C# AGI Interpreter
« Reply #238 on: November 20, 2022, 07:10:37 PM »
I have fully decompiled the Goldrush logics. You can find that here:
https://sciprogramming.com/community/index.php?topic=1942.msg13926#msg13926

Logic 129 is the main startup logic (named "lgc.Start" in the decompile) and is the first logic called when the game begins. After it does the timer check (details on exactly what it's doing are included in the comments of lgc.Start), it then calls new.room(rm.MainStreet) [rm.MainStreet is Logic 1] if restarting, or new.room(lgc.InitQuiz) [lgc.InitQuiz is Logic 125], which begins the copy protection question sequence. If the correct answer is entered, the copy protection calls new.room(rm.Title) [rm.Title is Logic 73], which begins the game's opening title sequence.

If you want to bypass the copy protection without breaking gameplay, the easiest way is to change the "new.room(lgc.InitQuiz);" line in lgc.Start to "new.room(rm.Title);"

In logic numbers, that's change the "new.room(125);" line in Logic 129 to "new.room(73);".


Offline lance.ewing

Re: C# AGI Interpreter
« Reply #239 on: November 20, 2022, 08:24:31 PM »
Cool, thanks @AGKorson. I'll give that a go in about 4 hours, when I'm back home...  unless someone else submits the PR in the meantime  ;D


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

Page created in 0.037 seconds with 22 queries.