Jump to content
LaunchBox Community Forums

Recommended Posts

Posted

I'm stalled on a plugin I was developing which would ease use of Launchbox with emulators for old computer systems that expect two disks to be loaded with many games (e.g. PC88, x68000, apple II.) The problem I ran into is that it doesn't seem to be possible to intercept an OnBeforeGameLaunching event and either modify the command line arguments (so that LB calls the emulator with my desired args) or cancel it entirely (so I can launch the emu myself with whatever args I like.)

I could only find one other post about this, in an update thread from 2019, so my assumption is that this hasn't been added in the meantime. If I'm wrong, I'd love to know it 😛 and otherwise if there's any way to put this in as a feature request, I think it would be very useful for old computer enthusiasts. Thanks!

Posted
32 minutes ago, cathoderaydude said:

The problem I ran into is that it doesn't seem to be possible to intercept an OnBeforeGameLaunching event and either modify the command line arguments (so that LB calls the emulator with my desired args) or cancel it entirely (so I can launch the emu myself with whatever args I like.)

At this point, the game/emulator/etc. to be used are already committed.  So can't really change any of that.

As for canceling it, I suppose you could OnAfterGameLaunched(), capture the emulators HWND (or similar) and force close the window.  Then use the PlayGame() method to launch the game using whatever args you like.

 

58 minutes ago, cathoderaydude said:

modify the command line arguments (so that LB calls the emulator with my desired args)

Is this something that changes between different launches of the particular game?  Or is this something that could be added to the specific games' Emulation section and using override command line parameters.

Posted
6 hours ago, JoeViking245 said:

As for canceling it, I suppose you could OnAfterGameLaunched(), capture the emulators HWND (or similar) and force close the window.  Then use the PlayGame() method to launch the game using whatever args you like.

Is this something that changes between different launches of the particular game?  Or is this something that could be added to the specific games' Emulation section and using override command line parameters.

Option #1 could work in a pinch, but is there actually a way to find out from OnAfterGameLaunched exactly which PID/hwnd launchbox spawned, or are we talking about using external Windows APIs to search for the emulator by process / window name?

I did look at the custom command line option, but the problem there is that, as far as I can tell, there is no way to stop LB from appending the primary ROM/disk name to the launch command. This is sort of manageable in some cases - for instance, the desired output for e.g. AppleWin would look like this:

applewin.exe -d1 "C:\AppleII\Disks\Airheart Disk 1.img" -d2 "C:\AppleII\Disks\Airheart Disk 2.img"

I could trick this into working by generating a custom command line template that looks like this:

-d2 "C:\AppleII\Disks\Airheart Disk 2.img" -d1 

I can do this automatically by getting the second disk image from GetAllAdditionalApplications, injecting it in the custom command line field, then letting LB fill in the first image at the end of the line. This would probably work for a lot of emulators where the disks can be fed in reverse order, but I'm aware of at least one specific problem case (the emu that got me on this to begin with in fact)

The PC88 emu QUASI88 expects disks 1 and 2 to be passed on the command line in that order, but since LB always appends the primary ROM file to the end of the command, it's always going to wind up in drive 2. There's no way to get it to load into drive 1 other than to to fudge the disk order metadata - tell it disk 2 is disk 1 and vice versa. And while I can't cite examples at the moment I'm pretty sure I've seen other emus with this limitation.

It may be possible to do this automatically (swap the disks in BeforeGameLaunched and then swap them back in After) so I'm gonna look into that, and I know this is a bit of an edge case since it only really affects disk-based home computers, but it'd be great if there were options to override the entire command line so this could be done more cleanly.

Posted

FWIW, I do have a proof of concept working using the above technique. Overriding game.ApplicationPath in OnBeforeGameLaunching does in fact affect the generated command line, it'd just be nice to be able to do this without having to modify and then later restore the fields in the app entry.

Posted

Okay! Turns out I was wrong about many things, haha! I did not know about the variables available in commandline generation; these make it MUCH simpler.

For anyone coming across this thread later, the variables are as follows:

%romfile% - ROM filename with/without quotes as set in emulator settings
%platform% - Game platform
%launchboxorbigboxexepath% - Full path to LaunchBox.exe or BigBox.exe
%gameid% - Game ID from XML
%romfilename% - Filename of the ROM WITHOUT extension
%romextension% - Extension of the ROM file (ie, .rom)
%romlocation_noquotes% - Path to the ROM without quotes
%noromfile% - Replaced with empty string, suppresses rom file being added to end of the command line.

All my plugin has to do is override the commandline to place %romfile% first. This allows me to generate a line like:

-disk1 %romfile% -disk2 "{second-disk-image}"

in my plugin and sub it in during BeforeGameLaunching and hey presto, problem solved. So at this point, y'know, it'd be nice if there was a %disk2% variable... but I'm happy with what I got 😛

Thanks for the reply, wouldn't have figured it out without the pointer to the command line field!@JoeViking245

Posted
1 hour ago, cathoderaydude said:

Option #1 could work in a pinch, but is there actually a way to find out from OnAfterGameLaunched exactly which PID/hwnd launchbox spawned, or are we talking about using external Windows APIs to search for the emulator by process / window name?

Pretty positive there isn't via LB API.  I've used Process.GetProcesses(). Then whittle down to the emulator.  Works well in my application.

1 hour ago, cathoderaydude said:

I did look at the custom command line option, but the problem there is that, as far as I can tell, there is no way to stop LB from appending the primary ROM/disk name to the launch command.

Looks like you've already found "the solution" to this. ;)  Well done.

4 minutes ago, cathoderaydude said:

y'know, it'd be nice if there was a %disk2% variable... 

If your games have consistent file naming conventions, you could super crazy/creative...

Using your OnBeforeGameLaunching() override method and the available IGame game, you can:

  • if (game.GetAllAdditionalApplications().Length > 0)
    • foreach (var g in game.GetAllAdditionalApplications()),
      • if g.ApplicationPath.EndsWith("Disk 2.img")
      • (You've found Disk 2)

Now use game.ApplicationPath and g.ApplicationPath in your override.  (Then restore things OnGameExited())

 

Alternately,

Create "an emulator".  Use C# or even AutoHotkey.

Pass %romfile% to the "emulator".  Do a file = Path.GetFileName.  Search the ROM files' path for a file that starts with file.Split(" Disk")[0] and ends with "Disk 2.img".  If it exists..... and build your command line from there.

Then it's just a matter of Process.Start() blah blah blah WaitForExit() ... return "done".  this.Close().  (or in AHK... RunWait, emu.exe...parameters...)

That should keep the startup/shutdown screens working, as well as work for any multi disk games.

 

 

Personally, I'd just stick with the individual games' command-line override. :) 

 

40 minutes ago, cathoderaydude said:

Thanks for the reply, wouldn't have figured it out without the pointer to the command line field!

Always glad to help.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...