Jump to content
LaunchBox Community Forums

How do I close an Additional App (UCR) after a game quits?


bradbradbrad

Recommended Posts

I just added a Steam game and downloaded UCR to get it the Xbox controller support to work.

  • I set up a profile and was able to add it to the "Additional Apps" section of the specific game I'm trying to play
  • Whenever I exit the game, and I am back in Launchbox/Bigbox, it doesn't close UCR, so it is still emulating the Xbox controls instead of my keyboard mappings

2 Quick questions:

  1. Is there a way to have it automatically close after the game exits?
  2. Is there a way to utilize UCR and have it load/exit for all steam games, so I don't need to do it for each one in case I want to add more in the future?

Thanks

Capture.PNG

Edited by bradbradbrad
added screenshot
Link to comment
Share on other sites

20 hours ago, bradbradbrad said:

I just added a Steam game and downloaded UCR to get it the Xbox controller support to work.

  • I set up a profile and was able to add it to the "Additional Apps" section of the specific game I'm trying to play
  • Whenever I exit the game, and I am back in Launchbox/Bigbox, it doesn't close UCR, so it is still emulating the Xbox controls instead of my keyboard mappings

2 Quick questions:

  1. Is there a way to have it automatically close after the game exits?
  2. Is there a way to utilize UCR and have it load/exit for all steam games, so I don't need to do it for each one in case I want to add more in the future?

Thanks

Capture.PNG

  

if this is for Steam games, do you really need to resort to remapping the controller with a 3rd party program? Could you explain your use case with more details? Without knowing more I would first think Steam's native remapping feature would be the better option.

Link to comment
Share on other sites

8 hours ago, bradbradbrad said:

I forgot to mention that I have 4 players on my arcade cab. The Steam remapping feature only seems to work with 1 player, unless I'm missing something?

My gut says you're missing something because Steam's remapper is by far the most intricate, detailed and expansive remap tool I've ever seen. Granted I don't use it basically at all myself I have checked it out multiple times just to know what is available and each time I dove down that rabbit hole it was overwhelming lol. All the different types of button press (normal, long, soft, combos, chords, etc) alone is nuts. If you can think it up, they have already thought it up it seems. So my gut thought there is no way the internet wouldn't have been up in arms if Valve dropped the ball and did not include the ability to remap multiple controllers or devices. But since I didn't ever try that before I had to see what is up, and it def can. Screen shot below shows two devices which both happen to be Xbox Series X style controllers. To be specific the first one on the left is a PowerA model, and the 2nd on the right is an OEM Microsoft model. As soon as I turned on the 2nd one it appeared here so it automatically detects what devices are connected. You can select which device to edit and can do this per game.

 

image.thumb.png.d655b2aa15c220ef39b0b17c5fbd8e61.png

 

Now if you are using a keyboard encoder I assume your PC sees that as a single device. I see no keyboard option available here on Steam and makes some sense given this feature is called controller remap. So I wonder if this feature is even usable for yourself given your hardware and situation. Do you get any devices to show up when you try to remap a game? Check on the same screen that I posted (check with any of your Steam games)

So leads me to next question...or perhaps guess....are you using UCR to create a emulated/virtualized xinput controller? Normally when you for ex, push P1B1 on your cab it would output a keyboard key from your encoder for example "left shift". But you instead want when you push P1B1 it outputs xinput ala Xbox 360 style controller for ex "button A" ?

 

Link to comment
Share on other sites

15 hours ago, skizzosjt said:

Do you get any devices to show up when you try to remap a game? Check on the same screen that I posted (check with any of your Steam games)

I don't, unfortunately.

15 hours ago, skizzosjt said:

But you instead want when you push P1B1 it outputs xinput ala Xbox 360 style controller for ex "button A" ?

That's correct. Right now I just have 4 player joysticks & buttons mapped via 2 Ipac ultimate IOs. Each input results in a keyboard stroke. I am using the UCR program to convert those keyboard strokes into xbox 360 controller inputs for steam. I have gotten it working great on startup through my original screenshot. When I open TMNT - Shredder's Revenge, for e.g., it pre-loads UCR, imitates that I have 4 360 controllers plugged into the PC, and automatically runs my profile which I named "Steam." Then it opens up Steam & the game.

The only issue is that when I exit, it is still converting my keyboard strokes to xbox 360 inputs so if I wanted to switch to a MAME arcade game, it would not register properly.

I have tried to create a windows shortcut that has a command-line script to close UCR after it exits, and put that as a new application as "Automatically Run after Main Application," but it runs this script once Steam loads and thus immediately closes UCR before the game is loaded up.

So either I need some sort of fully integrated keyboard-to-360 controller remapping built into Steam, or I need a way to figure out how to have UCR unload my profile (or completely exit the application) after I exit the game and come back into Launchbox.

Link to comment
Share on other sites

2 hours ago, bradbradbrad said:

I don't, unfortunately.

That's correct. Right now I just have 4 player joysticks & buttons mapped via 2 Ipac ultimate IOs. Each input results in a keyboard stroke. I am using the UCR program to convert those keyboard strokes into xbox 360 controller inputs for steam. I have gotten it working great on startup through my original screenshot. When I open TMNT - Shredder's Revenge, for e.g., it pre-loads UCR, imitates that I have 4 360 controllers plugged into the PC, and automatically runs my profile which I named "Steam." Then it opens up Steam & the game.

The only issue is that when I exit, it is still converting my keyboard strokes to xbox 360 inputs so if I wanted to switch to a MAME arcade game, it would not register properly.

I have tried to create a windows shortcut that has a command-line script to close UCR after it exits, and put that as a new application as "Automatically Run after Main Application," but it runs this script once Steam loads and thus immediately closes UCR before the game is loaded up.

So either I need some sort of fully integrated keyboard-to-360 controller remapping built into Steam, or I need a way to figure out how to have UCR unload my profile (or completely exit the application) after I exit the game and come back into Launchbox.

Those are the details I was hoping for! Thank you for sharing! I was wondering if there was not an easier method to execute your goal, but now knowing everything as a whole you def need a 3rd party remapper. Bummer Steam can really only use controllers for input, because you can remap controllers to keyboard keys....just not the other way around....now we know! I can try and help with your dilemma....one part is easy....the other part can get a bit more complicated

 

For the first challenge, that being to close UCR automatically once the game closes you need to use a script to do that. I'm more familiar with AHK so I tend to use that over batch files. What needs to happen is an AHK script needs to also be added as an additional app that also launches prior to the game. It will wait for the game to exist, then wait for the game to not exist....at that point it triggers UCR to close. Put this into a script file and add it as another additional app, and check the checkbox to launch prior to game launching. I am going one step further to combine all this in one....you can also launch the remap program within the same script. I looked at the screenshot you posted earlier for the path and choosing profile syntax....please double check for accuracy. EDIT:  actually on 2nd thought you should use an absolute path instead of relative path to launch UCR. The relative path will only work right if you place the script file in the proper folder location (same spot as LaunchBox/BigBox exe) or declare the proper working directory within the script....so for ease of use (unless you already know how to deal with all this stuff) I'd say change that to an absolute path. If you know how to deal with relative paths fine then you may need to adjust it depending on where you put it or run it from

Run, ..\..\Program Files (x86)\UCR_v0.9.0\URC.exe -p "Steam"
WinWait, ahk_exe gameEXEname.exe
WinWaitClose, ahk_exe gameEXEname.exe
WinClose, ahk_exe UCR.exe

Please notice you will need to enter in the name of the individual game's exe file where "gameEXEname" has been put as a placeholder. So for TMNT Shredders Revenge.....I have that game too and I think its exe is "TMNT". We just need to use any "WinTitle" format here and in this example I am showing the ahk_exe variant. if the "ahk_exe" part was removed we could instead have the game's window title entered here. There are more variants....for more on that....https://www.autohotkey.com/docs/v1/misc/WinTitle.htm

 

 

So that is the easy part.....the hard part is doing this for all Steam games as you have noticed the quirk of launching Steam games with LB/BB. There is always a window that pops up first when the launching/bootstrapping happens. "Launching...." So LB/BB perceives this window as the game and since it closes just moments later LB/BB thinks the game has closed and will in turn close any additional apps that were launched. This is why you notice things getting closed so quickly or why it looks like they never launched at all. To get around this you need to use scripts to tell LB/BB to wait and that is what the above script is doing.....but you cannot copy/paste that for all your games since you need something to be specific to that game.....catch 22 territory here. I'll outline a couple ways to do this in order of bad to best, but will need to come back at a later time to get into any details and provide actual scripts.

 

#1 = make individual scripts for each game (good for a smaller library....bad idea for a large library due to lots of busy work)

#2 = single script that waits to detect steam or steam's overlay exists, wait for it to exit, and then exit UCR.

#3 = single script using AHK as a pseudo emulator which receives an argument from the command line parameters. this is how I do things. it can give more control to not only make sure the games launch, but also allows Startup/Shutdown screens to operate properly. If you want to use Startup/Shutdown screens this is the only method to use. I would recommend this route if you have a larger library and don't want to make an individualized script for each Steam game

 

Sorry for not being able to help more right now but when I find the time whether later tonight or over the weekend I can come back with more details and the scripts themselves. I'm on my work laptop rather than my desktop where all those files are stored.


 

Edited by skizzosjt
realtive path note
  • Like 1
Link to comment
Share on other sites

I am following this thread with great interest. I too have some scenarios where I need an application for certain games, but not anymore after that. I also use gamepads and a 4 player arcade board with an I-PAC Ultimate I/O. In my case, when Joytokey is constantly running in the background, the applications, understandably, get confused. This can probably only be solved for the time being with an ahk script, but I haven't really looked into that intensively yet.

In the depths of this forum I found the following about SumatraPDF, this preconfigured script is awesome and has relieved me of the problems for my magazine category. It may help the experienced user to create something similar.
 

In combination with the super plugin from @JoeViking245 I was able to set a lot in one go.

 

  • Like 1
Link to comment
Share on other sites

On 6/16/2023 at 5:04 PM, bradbradbrad said:

Thanks for the script, but for some reason it's not loading UCR. I'm not sure if I'm doing something wrong.

Does it need to be a .ahk file or .exe?

you need to put that script into a text file and then save as .ahk file extension.

did you leave it as a relative path like what is shown in your last screenshots?! if so that explains why it does nothing. change it to an absolute path. this means include the whole path so start with the drive letter for ex C:\Path\to\something\UCR.exe

image.thumb.png.adb2c91ffb35932451098a3c9f6e432c.png

because you're using relative path for ex ..\..\Path\to\something\UCR.exe it is looking in the wrong folder.

image.thumb.png.9c57a7535cd6fcfc05a357ff094afd65.png

change that script file to .ahk extension.

the rest looks right! you just need to fix the path to the program in the script and make sure to save the script as .ahk. let me know if that fixes it

 

Edited by skizzosjt
Link to comment
Share on other sites

Thanks,

I added the absolute path per your recommendation. I then made sure to save it as a .ahk extension, but it didn't load UCR at all still for some reason.

image.png.c069ba1360e4947113d6e64e242a023b.png

image.thumb.png.4c01f07b4f15c573b0346ab57772bc04.png

image.thumb.png.6db4336007829364497ea5153b6496cd.png

I also tried using the AHK compiler and converting it to an .exe, but that didn't seem to work either. The game loads up, but UCR doesn't appear to load (or if it does it closes so fast that I don't notice it).

I've tried it also without the profile parameters at the end (-p "Steam, .e.g.) and still nothing.

I appreciate your help thus far.

  • Like 1
Link to comment
Share on other sites

34 minutes ago, bradbradbrad said:

I added the absolute path per your recommendation. I then made sure to save it as a .ahk extension, but it didn't load UCR at all still for some reason.

Line 1 in the script is missing some quotation marks.  Because the path to UCR.exe has spaces in it, that whole part needs to be encapsulated.

Run, "C:\Program Files (x86)\UCR_v0.9.0\UCR.exe" -p "Steam"

 

Edited by JoeViking245
Fixed path to UCR
  • Thanks 1
Link to comment
Share on other sites

5 hours ago, JoeViking245 said:

Line 1 in the script is missing some quotation marks.  Because the path to UCR.exe has spaces in it, that whole part needs to be encapsulated.

Run, "C:\Program Files (x86)\UCR_v0.9.0\UCR.exe" -p "Steam"

 

thanks Joe! I'd like to think that would take care of it. My curiosity got the best of me though so I redownloaded UCR just now to actually test hands on. I haven't used this program in over a year.

 

So after playing around for a bit now, UCR seems to have a quirk that requires the working directory to be set to the folder that the main exe is in. I couldn't get UCR to launch with the Run command until I set the working directory to the same folder it is located in. I can launch it without quotes, but Joe's advice is still good. Using quotes does no harm here

Here's my test that got it working. I put a folder called "UCR Path With Space" on my desktop and unzipped the UCR zip file there. The script was located directly on the desktop (C:\Users\Scott\Desktop)

SetWorkingDir C:\Users\Scott\Desktop\UCR Path With Space
Run, C:\Users\Scott\Desktop\UCR Path With Space\UCR.exe

This worked! But if I altered the working directory or omitted setting it, then nothing happens.

 

Since I'm forced to set work directory to same directory as the main exe, this means I don't need to write out the whole path again on the Run line.  So for this example I can shorten it like this. I also created a profile for testing of loading that automatically

SetWorkingDir C:\Users\Scott\Desktop\UCR Path With Space
Run, UCR.exe -p "Test Case"

 

Quotes around the file path are fine and in reality are likely better to use than to omit. ie this below is also acceptable and working. notice the quotes around the file path, even though it's technically just the file name here

SetWorkingDir C:\Users\Scott\Desktop\UCR Path With Space
Run, "UCR.exe" -p "Test Case"

@bradbradbrad hopefully now you too can get it working. Even though I got it to work that is an odd ball situation that even an absolute path doesn't work without setting the work directory. I recalled this program had it's quirks but this one I don't remember. I think this may be UCR's fault due to AHK would throw an error if it really couldn't find the file that is being told to run. When I try to tell it to run in such a location where the file doesn't exist I get the proper error reflecting that. I find this same issue when trying to run UCR with a batch file. Either the bat file needs to be in the same folder as UCR.exe, making that the working directory, or I need to set the working directory before telling it to open. If the work directory isn't set and even using a full absolute path when launching the bat file from a different location than UCR.exe, it results in the same big cup of nothing like what is going on with AHK too.

 

So going off previous posts the script below would work for TMNT Shredder's Revenge. The way this is written you are allowed to put the script file (what you named "TMNT Launcher.ahk") in any location you want.

SetWorkingDir C:\Program Files (x86)\UCR_v0.9.0
Run, "UCR.exe" -p "Steam"
WinWait, ahk_exe TMNT.exe
WinWaitClose, ahk_exe TMNT.exe
WinClose, ahk_exe UCR.exe

 

 

To make this so it is not game specific, but is instead just Steam specific, you can do this. Just tested this one too since it's been a long time since I did this method, it still worked fine! So this acts like a nifty way to tell only when a game is running

SetWorkingDir C:\Program Files (x86)\UCR_v0.9.0
Run, "UCR.exe" -p "Steam"
Process, Wait, gameoverlayui.exe
Process, WaitClose, gameoverlayui.exe
WinClose, ahk_exe UCR.exe

 

 

How to set this up so it can work with all your Steam games and other native Windows games can change depending if you want to use Startup/Shutdown screens for these games. Is that something you're interested in or would you rather set this up without them?

 

Let us know how you make out!

Edited by skizzosjt
typo - testing update
  • Like 2
Link to comment
Share on other sites

Thanks! I'm starting to see things work finally. I am having a few lingering issues, however:

  1. I was not able to get anything at all to work if I ended it with .ahk extension. When I used the ahk compiler and converted it to .exe, that's when things looked like I was starting to make progress. I could hear the windows "ding" that a new "device" was connected and saw the UCR program load up. That's not really a problem now that I've learned how to use the compiler, just something I noted.
  2. Unfortunately, it doesn't load my "Steam" profile at all the way it does when I launch it via Launchbox. It simply loads up UCR and doesn't select anything. Even though it shows "Steam" at the top of UCR like it's pre-loaded, it's only giving me keyboard controls whenever I'm in game. I'm not quite sure why.
  3. The UCR UI overlays on top of the game. Is there a way to launch it minimized or behind the game itself?

image.thumb.png.fb3f82af921719eb1612490deeab07c0.png

Those issues not withstanding, when I closed the game, I heard the windows "ding" again and it did appear to close out properly! So Thank you for that. I tested using the following code you provided:

SetWorkingDir C:\Program Files (x86)\UCR_v0.9.0
Run, "UCR.exe" -p "Steam"
Process, Wait, gameoverlayui.exe
Process, WaitClose, gameoverlayui.exe
WinClose, ahk_exe UCR.exe

Lastly, I do have a startup screen currently implemented as part of the "Slipstream" theme I have running. I'd like to keep that if possible. Is that affecting it somehow as you mentioned?

image.thumb.png.f877ac8131bbd4f7de47dd59483a1824.png

If this can work properly, I'd love to "set it and forget it" for all Steam games if that's possible too. If I add a new game in the future, I'd like to not have to remember this process of adding additional apps, locating the exe file, etc. etc. It's not that it's that difficult to go back and figure out, but any up-front work I can do now, my future self will thank me for. :)

Link to comment
Share on other sites

10 hours ago, bradbradbrad said:

was not able to get anything at all to work if I ended it with .ahk extension

this would suggest you don't have a default application assigned to open .ahk extension files. do the following to set that

  • right click on an .ahk file
  • go to "Open With"
  • from the Open With menu select "Choose another app"
  • then select one of the AHK executables from your AutoHotkey folder (I normally use "AutoHotkeyU64.exe") - you will likely need to click on "More apps", then scroll to bottom of the list and click "Look for another app on this PC" in order to find that file
  • Edit: Just dawned on me you likely don't have AHK installed on your PC. LaunchBox bundles one of the exes with it though. So if you don't have AHK installed by downloading it from their official website you would instead need to navigate to "LaunchBox\ThirdParty\AutoHotkey" and select the file in there called "AutoHotkey.exe"
  • be sure you have also ticked the checkbox "Always use this app to open .ahk files" (or it may instead show buttons like "Always" and "Just this one time" and if that is the case you want to click on the "Always" button)

The above process will now make it possible for you to run AHK scripts by simply opening the .ahk file. This is my preferred way of doing things since you will be able to run them by double clicking on the icon or using a shortcut link, using AHK or CMD line to open the file etc. If you prefer compiling scripts I recommend to do that once they are set in stone. Compiling while still in a setup or troubleshooting phase can be a bit annoying I think due to needing to recompile each time you make an adjustment and then test run it.

 

 

10 hours ago, bradbradbrad said:

Unfortunately, it doesn't load my "Steam" profile at all the way it does when I launch it via Launchbox. It simply loads up UCR and doesn't select anything. Even though it shows "Steam" at the top of UCR like it's pre-loaded, it's only giving me keyboard controls whenever I'm in game. I'm not quite sure why.

So this is weird! Your UCR screen looks the same as mine would when I had my "Test Case" profile load which all I had it do was remap a handful of keyboard keys like f is now b and a is now k sort of remaps.  It was working as intended. You're right it looks like the profile is activated, the profile is in the window title and shows the stop button as selectable while the play button is not selectable, so the remapping should be doing its thing. I only tested the keyboard and didn't try to remap things in the same requirement as you need, going to the virtualized xinput controllers, so there might be more funny business to get around when those are in use. I'd have to test more myself to see what is going on

 

 

10 hours ago, bradbradbrad said:

The UCR UI overlays on top of the game. Is there a way to launch it minimized or behind the game itself?

Worst case scenario would be you see it for a blip of a nano sec and then it minimizes. Done so by waiting for window to exist and then minimize it. Otherwise the best case scenario would be there should be some method to launch it minimized from the get go. Try that by changing the run line to this below. This doesn't always work, some programs cannot be controlled like this by AHK, but what it will try to do is launch the program in a minimized state so it is never seen

Run, "UCR.exe" -p "Steam", , Min

 

 

10 hours ago, bradbradbrad said:

Lastly, I do have a startup screen currently implemented as part of the "Slipstream" theme I have running. I'd like to keep that if possible. Is that affecting it somehow as you mentioned?

I don't think it would impact what is going on with UCR not remapping things right for you, if that is what you meant. But I've seen weirder things so give it a test run with Startup/Shutdown screens checked off just to make sure. But thanks for the update. I will share the script I use since I use it for the same thing. Launching the games can be relatively simple with the script consisting of just a handful of lines that you said also worked for you! It doesn't need to get too complex when not using Startup/Shutdown screens. But when Startup/Shutdown screens get into the mix we need make things game specific since we need to manipulate the individual windows. Those being both the game window and the "LaunchBox Game Startup" window. I'll have to come back with directions/screen shots on setting this up. I would consider this a set it and forget it type of solution, I've been using it for a year now and adding new games after the fact is simple/straight forward too

 

 

So I'm sorry to throw you a bit of a curve ball since I'm sure it didn't take just 1 min to remap all your controls in UCR, but would you be willing to try another remapper instead? The downside here would be you would need to reconfigure those remaps on another program. I used UCR for a while a couple years ago and eventually deleted it because I thought it was so poor compared to other remappers. Do you notice how long it takes for this program to start up for example? It also used to crash on me, and all these other quirks that are coming up, etc, are what drove me away.  I instead would use a program called "virtual controller" to do what you need. To give you a sales pitch I find this program opens up instantaneously and has less overhead. It does everything UCR can and just my opinion a little easier to navigate and setup your remaps. It can open with or without loading the profile, I know it can be launched minimized, and it plays nice with AHK.  If you figured out how to use UCR I'd bet figuring out virtual controller would be more of the same, but since I'm more familiar with virtual controller and actually still use virtual controller I can give better help on virtual controller.

Edited by skizzosjt
adding alternative method to set default app
  • Like 1
Link to comment
Share on other sites

2 hours ago, skizzosjt said:

this would suggest you don't have a default application assigned to open .ahk extension files. do the following to set that

  • right click on an .ahk file
  • go to "Open With"
  • from the Open With menu select "Choose another app"
  • then select one of the AHK executables from your AutoHotkey folder (I normally use "AutoHotkeyU64.exe") - you will likely need to click on "More apps", then scroll to bottom of the list and click "Look for another app on this PC" in order to find that file
  • be sure you have also ticked the checkbox "Always use this app to open .ahk files" (or it may instead show buttons like "Always" and "Just this one time" and if that is the case you want to click on the "Always" button)

The above process will now make it possible for you to run AHK scripts by simply opening the .ahk file. This is my preferred way of doing things since you will be able to run them by double clicking on the icon or using a shortcut link, using AHK or CMD line to open the file etc. If you prefer compiling scripts I recommend to do that once they are set in stone. Compiling while still in a setup or troubleshooting phase can be a bit annoying I think due to needing to recompile each time you make an adjustment and then test run it.

Thanks, this worked for me. I didn't install ahk separately or anything, just what Launchbox came with, so it must have never associated the files. After reassociating them, it worked and I don't need the .exe's anymore.

Unfortunately, the minimizing didn't work:

Run, "UCR.exe" -p "Steam",,Min

 

After some trial-and-error, and a small bit of research, I found WinWait and WinMinimize which did the trick:

WinWait, ahk_exe UCR.exe
WinMinimize

Initially it still didn't load my profile, but I tested it with the "gameplay startup" turned off and it worked, so that is definitely affecting the profile loading.

2 hours ago, skizzosjt said:

It doesn't need to get too complex when not using Startup/Shutdown screens. But when Startup/Shutdown screens get into the mix we need make things game specific since we need to manipulate the individual windows. Those being both the game window and the "LaunchBox Game Startup" window.

Here is the timing of my startup screen:

image.thumb.png.ddd0d1f3ca6b2c626051317d2c0a9472.png

I have it set to 2 seconds, so I though perhaps I could just delay the loading of UCR for about 5 seconds to see if it would work with this wait code I also found:

Process, Wait, gameoverlayui.exe, 5

Sure enough it seems to be ok! Here is my final code that appears to be fully working now:

SetWorkingDir C:\Program Files (x86)\UCR_v0.9.0
Process, Wait, gameoverlayui.exe, 5
Run, UCR.exe -p "Steam"
WinWait, ahk_exe UCR.exe
WinMinimize
Process, Wait, gameoverlayui.exe
Process, WaitClose, gameoverlayui.exe
WinClose, ahk_exe UCR.exe

 

2 hours ago, skizzosjt said:

I instead would use a program called "virtual controller" to do what you need.

I would not mind giving this a try at all. It was a little time consuming to set up all the keys, but nothing too terrible to redo. Anything that improves the speed of loading and has less probability of crashing, I am all too happy to implement in my cabinet. What is the link to the app? I googled it but seemed to come up with a few things that I wasn't 100% sure was the same application you're mentioning here.

Link to comment
Share on other sites

So now that I have that working, I noticed that my LED blinky configuration isn't. When I preselect TMNT while in Launchbox, it shows the controls I have configured, but as soon as I launch the game, it reverts back to the default lighting scheme for the launchbox UI. I'm wondering if this ahk file and setup that I'm now using is causing the same issues. I'm thinking that LED blinky is looking at the UCR file now instead of launchbox, perhaps? Do you know if there is a way around that?

Link to comment
Share on other sites

6 hours ago, bradbradbrad said:
SetWorkingDir C:\Program Files (x86)\UCR_v0.9.0
Sleep, 5000
Run, UCR.exe -p "Steam"
WinWait, ahk_exe UCR.exe
WinMinimize
Process, Wait, gameoverlayui.exe
Process, WaitClose, gameoverlayui.exe
WinClose, ahk_exe UCR.exe

 

I recommend to change the line "Process, Wait, gameoverlayui.exe, 5" line to instead "Sleep, 5000"

What Process, Wait does with that timeout is wait until it's true or times out, exceeds 5secs in this case. So if the Steam overlay was to load quicker for one reason or another it will mess up timing by continuing the script prior to 5 secs passing. Since it's dynamic (can be different each time) it potentially could mess up loading that profile properly. Using sleep instead, it's a static value and it will always wait that exact duration each time

 

6 hours ago, bradbradbrad said:

I would not mind giving this a try at all. It was a little time consuming to set up all the keys, but nothing too terrible to redo. Anything that improves the speed of loading and has less probability of crashing, I am all too happy to implement in my cabinet. What is the link to the app? I googled it but seemed to come up with a few things that I wasn't 100% sure was the same application you're mentioning here.

So my thoughts here were maybe we would get stuck on loading the profile thing (you did end up resolving this though)....I don't recall that being an issue when I used to run UCR but it's been a long time. I must have not used Startup screens at that point or found some workaround like you have detailed. If you are interested in giving it a shot it is on sourceforge.net and here is a direct link to the page. I get that it might look sketchy, but it's all clean, no virus type stuff to worry about here!

https://sourceforge.net/projects/vjoy-controller/

 

Basics on how to use - example of using keyboard input being translated into xinput output

Inputs can be selected here - Settings > IO Devices. On next screen make sure you are on tab Physical and then click Setup > Keyboard. On the next screen make sure it is enabled and I tend to use the LLHook API. Note your encoder may show up as something else, but this is where you would need to setup what device is the physical input.

image.png.d54abbac4175244df6f5ed1c00d04eb1.pngimage.png.7212cdbaceca3f2b57cf7656a156a47d.pngimage.png.545743b6ab208e7c4735ee53f383e3ef.png

 

Once we have made sure our physical input device is selected and enabled we can move on to our virtual outputs. We want to make four separate Xbox 360 controllers. Return to the IO Devices screen and this time move over to tab Virtual. You likely will only see "Keyboard" listed here the first time. We need to setup the virtual controllers first. Click Setup > Xbox 360 Gamepad (vXbox). Next screen titled vXbox will need the checkbox Enabled checked. Also you will first likely need to install a driver to get this feature working. If the "Install" is not grayed out you will need to click Install to do that. Make sure to restart your PC when it says driver installation complete. Return to this screen when done doing the reboot. Now with it enabled, and driver installed, we can click on Configurate to setup the qty of controllers needed. On next screen also called vXbox you will have a device drop down with four different virtualized Xbox 360 controllers. Click on the ones you want to "plug in" and then click the plug in button. You will likely hear the "beep-boop" chime from Windows detecting an USB device was plugged/unplugged. Give Windows a moment to setup your new device. Rinse and repeat as needed. As you can see this is also where you can unplug a virtualized controller too. Important note that these settings are also saved per profile. As in you create a profile "A" that has 4 Xbox controllers plugged in, but then load profile "B" that doesn't have any Xbox controllers plugged in per its settings, it will act like they are all getting unplugged when profile "B" loads. This is actually pretty handy if you have games than need different type of devices or qty of devices plugged in

image.png.00cc1880f15dd5cda4aca51834a2a671.pngimage.png.cbed4a75f74cdfaee369075e28ed6e9f.pngimage.png.4ce72a80b28de4415cbf676e5fd12d05.png

 

When you close out of the windows and get back to IO devices you should now see the added virtualized controller(s). Here I added just a single controller

image.png.4b48992646a01dddcdec5fc753937400.png

 

Now lets actually remap stuff! Close the IO Devices window to return to the main Virtual Controller window. Go to Settings > Controls. From the Control window go to Tools > Quick Binding. On the Quick Binding window make sure you have selected the intended Output Device in the drop down menu at the top. In this example I made sure to use vXbox1 which is the first instance of a virtualized Xbox 360 controller. Then scroll through the list of the available outputs for this device, click on the associated Assign button for that input, and it will wait for input from the physical device. You can see in my example I made the space bar on my keyboard the input button which is translated into the virtualized controller's Y button

image.png.f9af4eef3beb968b57b53307aa2c071f.pngimage.png.9a240628e6be8bce7a538d9c2c9057ae.pngimage.thumb.png.ecfc29cc11afe00bea0464f8d0170394.png

 

You can get into much more detailed controls by exploring the Bind > Create window but for the majority of use cases the Quick Binding menu is that exactly, a quick and easy way to set things up. You can click on the individual lines to edit them further after being created through the Quick Binding too.

When you close this window you will now see the Controls window has populated with all your remaps. Things will look like they doubled, this is due to the program detects between down press and up release, etc.

This program auto saves whatever you have entered into the Controls window. So if you close right now and reopen, the same stuff will be there and is saved under the appropriately named profile "AutoSave.vcd" in the "Profile" folder. To save a profile return to the main Virtual Controller window and go to Settings > Save. Keep all your profiles in the designated Profile folder since it seems this is the only spot the program can properly load profiles when using AHK or launching with command lines. If you use the Settings > Load method to load a profile they can be stored anywhere though.....but that isn't very practical for our use case since we are trying to automate all this stuff!

 

Let me know if you run into any headaches. I hope this program works out a little smoother compared to UCR if you do give it a shot! I know I like it better than UCR at the very least!

 

Lastly here is an example of using AHK to run this and wait for a game to close to also close virtual controller at the same time. You can apply the stuff you learned in this thread for detecting when the game exists and then closes since as you are likely picking up on there are multiple ways to do that.

SetWorkingDir, ..\Controller Remap\Virtual Controller

Run, VirtualController.exe /load HOTD-Remake.vcd /run, , Min

WinWait, ahk_exe The House of the Dead Remake.exe
WinWaitClose, ahk_exe The House of the Dead Remake.exe
WinClose, ahk_exe VirtualController.exe

I found I also needed to set the work directory to the same directory that VirtualController.exe is in because this way the /load switch which is used to load the specific remap profile (same thing as the "-p" parameter for UCR) can just call out the profile name. Whenever I have tried it another way, as in not setting the workdir and using full paths, it DOES launch the program and DOES put it into run mode, but it never actually loads the profile.....whomp whomp

You will also notice the /run switch. This makes the remapper "run" when it is opened, which is the equivalent of the profile being "activated" on UCR. Without the /run switch it would open the program, load the profile, but your controls wouldn't really be reamapped. Lastly is the Min option for the Run command and it does work properly on Virtual Controller! This means the program will launch totally minimized and you will never see it. Unless you restore it through it's button on the task bar.

There is a ReadMe PDF included in the main folder of the program. The last page has good example of the syntax for command line which is basically same syntax we had to use in AHK too. There is even a "/minimize" switch built into this program but it actually puts it to the system tray, as in just a tray icon and no button on the task bar. Once you click on the tray icon it will be restored and the button reappears on the task bar.....if you minimize it again the task bar button again disappears and the tray icon reappears. This is just my personal preference to keep its task bar button present so I instead use AHK's Min option rather than Virtual Controller's built in /minimize switch.

 

 

5 hours ago, bradbradbrad said:

So now that I have that working, I noticed that my LED blinky configuration isn't. When I preselect TMNT while in Launchbox, it shows the controls I have configured, but as soon as I launch the game, it reverts back to the default lighting scheme for the launchbox UI. I'm wondering if this ahk file and setup that I'm now using is causing the same issues. I'm thinking that LED blinky is looking at the UCR file now instead of launchbox, perhaps? Do you know if there is a way around that?

oh geeze....stuff just snowballs doesn't it!? lol well I don't have that program because I only use LB/BB for having a nice couch gaming setup.....someday.....someday, I will build a cabinet though! So I'm not much use here. The author of LED Blinky is on this forum (username = arzoo) so if my stab in the dark gets you nowhere and no one else chimes in I would see if he wouldn't mind giving you some help!

Check out this thread....it's quite long but might suggest there were at least at one point known issues or quirks with Steam and/or Windows platform games. Page 4 and 5 talk about it.

Did you ever adjust TMNT Shredder's Revenge applicationpath field? Or what did you actually adjust, probably just adding the additional app script "TMNT Launcher.ahk" ? To prove if that is the culprit I would remove it as an additional app and see if the problem goes away. You can always add it back again to see if the problem returns again, further reassuring yourself you found the issue. If that is found to be the smoking gun of your LED Blinky issue I'm sure that would help someone who knows more than me guide you to a solution.

 

Let me know how that all works out for you and hopefully next time I post I can go over setting things up to use a single script for all your Steam games which enables Startup/Shutdown screens to work properly!

  • Like 1
Link to comment
Share on other sites

@bradbradbrad I'm coming back with two different scripts for you. The first one was the brain child of fellow user @JoeViking245 and his script is very elegant and to the point. It allows for startup and shutdowns screens to work just fine since we will be using a pseudo emulator using a script as the emulator. It also has a neat feature to incorporate running other programs before and/or after the game exits.
First we need to setup a new "emulator" that will actually be running the script. Here is the setup you will need to do to get this to work. To detail this you need the application path to point to an AHK executable. You can find the one included in LaunchBox in "LaunchBox\ThirdParty\AutoHotkey\AutoHotkey.exe". Next you need to set the default command line parameter to the actual script (.ahk file). It must have quotes around it! Be sure to check "Remove Quotes" and "Remove file extension and folder path" also. Also enable Startup screen and Shutdown Screen in the Startup Screen tab. You also need to enable the option "Hide all windows that are not in Exclusive Fullscreen mode". Lastly make sure you go into Associated Platforms tab and list the platform(s) you want it to be used (associated) with. Now we need to make games use this pseudo emulator. Do a bulk edit of the games you want to use it by selecting them, and then right clicking on them and go to edit, or use the hotkey Ctrl + E. Select the emulator field, and the value will the name of the pseudo emulator you just created. If you do it by one at a time you go to the Emulation tab and select the emulator from that drop down

image.thumb.png.563d0239c60c62c22fb48324802a88a6.png

 


Joes Steam Launching Script

Spoiler

 

;==========================================================
;      Launch before and after a Steam game
;==========================================================
; (1) If using Run Before and Run After, setup the programs/paths below.  
;        ("Edit These Paths")
;     i.e.  UCR.exe -p "Test Case", C:\Users\Scott\Desktop\UCR Path With Space, Min
;     Save this file file somewhere.  (i.e. "D:\Misc\SteamLaunch.ahk")
;
; (2) Create/Add a new Emulator in LaunchBox
;
; Under Emulator Name:, give it a name.  Something like "SteamLaunch".
; Where it says Emulator Application Path: click Browse and select  
;      ../LaunchBox/ThirdParty/AutoHotkey/AutoHotkey.exe 
; Where it says Default Command-Line Parameters:, type in the full path 
;      to where you saved this file. Put quotes around it!!
;      example:  "D:\Misc\SteamLaunch.ahk"
; Check both boxes:
;       (no quotes, filename only)
; Save this new 'emulator'
;
; (3) Tell the Steam game(s) to Lauch using this Emulator
;       Edit game. Under "Emulation", check "Use an emulator..."
;       Choose the emulator you ceated above
;  (Or make this the Default Emulator for you Steam Platform)
;==========================================================
;==========================================================


;===========================================================
;  Edit These Paths
;===========================================================
runBefore = D:\MyFolder\Utilities\myBeforeApp.exe
runAfter = D:\MyFolder\Utilities\myAfterApp.exe


;===========================================================
; *************** Do Not Edit Below Here ******************
; (except to uncomment the Run Befoe and/or Run After lines)
;===========================================================

;gets the path to Steam.exe
RegRead, steamLocation, HKCU\Software\Valve\Steam, SteamExe

; Program that runs before starting the Steam game
;Run, %runBefore%

Run, "%steamLocation%" -applaunch %1%

isRunning := "0"
While (isRunning = "0") ; Wait until the game is launched
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

Sleep, 15000

While (isRunning = "1") ; Wait until the game is closed
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500


; Program that runs after the Steam game has exited 
;Run, %runAfter%

 

 

 

 

 

If you have more games you want to use this with beyond Steam this script would be better suited for the job. Here is something I put together. What happens different here is it needs to specifically manipulate the game window and the LaunchBox Game Startup window, pushing/pulling them to the front/back of the window stack. I have found some games will be hidden behind a black screen unless they get a "AlwaysOnTop" option added too, and FYI, TMNT Shredders Revenge is one of these games.

I created a GUI to use in perhaps an attempt to make it easier for people to use....I wrote this like a year ago and was mainly a learning project on how to use GUIs for me. So I've been using it for a while and it works well, but I hope if you try it, that it also works well for you. If there are issues, please let me know and I'll do my best to figure out what's going on to fix.

This is going to work a little different to initially setup. First thing is you would need to take this script below and just run it. It will open up the GUI and will detect it's the very first time running so prompt you to navigate to your LaunchBox\Data\Platforms folder and select your Windows.xml file. I would assume you also have imported Steam games and other Windows games to a platform called Windows. If it is named something different native games that don't launch via a URL link like Steam, Uplay and Epic may not work depending on where you store them - but it would only take like 1 line of code change to fix so let me know if you run into troubles. To clarify Steam, Uplay, and Epic games will work fine even if platform is named something different, just other games may or may not work without a tweak to code. It will detect all the games in your platform and knows if they are Steam, Uplay, Epic, or other native games that may launch via various file types like .exe, .ahk, .bat, .lnk (shortcut links), and .url (Steam shortcut links). It will create two files in the same folder where the script is located. One is an ini file named "WPL Database.ini" that stores all the data related to each individual game and uses what I have defined as defaults initially. The 2nd file it will create is the actual script that does the launching which will be called "Windows Platform Launcher.ahk". I do it like this because it creates the Windows Platform Launch.ahk file with a path specific to your system. Use the GUI to edit any of the values for each game. Select the game via the drop down menu and then edit the desired fields and then click the edit button. You can remove and add games through this also. Whenever anything is changed via the GUI it will create another ini file called "WPL Database (Custom Entries).ini" which stores just the ones you have edited from default. I found this to be handy due to if you made a bunch of edits and then accidentally ran the setup again it would get rid of all your custom edits by returning them to defaults. So the handy part with this custom entry file is you can run the setup again as another method to add new games and it will retain all your previous custom edits by pulling in info from the custom entry ini to overwrite the default values that would normally be applied. Below I'm putting an example of what I used for TMNT Shredders Revenge. I customized the delay time to show the game window, and also needed to use the force window to always be on top checkbox. The "Title" field is the actual title it scrapes from what your game entry is named in LaunchBox. The "WinTitle" field will need to be some form of an AHK WinTitle variant of the game window. This is what the script waits for at the start, and waits for to exit. TMNT Shredders Revenge can use the same for both which is the default setting. But other games will need this WinTitle adjusted if their game window title doesn't match the title in LaunchBox. For example here is Doom Eternal. It's game window has no space and is instead "DoomEternal". One more example of using a different WinTitle type being the ahk_exe variant (the file being run). I found Mortal Kombat worked best using its exe instead. I also adjust the delay time to 0 since it must have been causing issues otherwise.

image.png.e31d0325810d119255186521ad061421.pngimage.png.a23892ab6fd8b2c731948a53ee479bb8.pngimage.png.01859b2f394ebae1d7f1c4847b2ff2ef.png

 

Here's setup for the emulator. The application path needs to be to the AHK exe  in "LaunchBox\ThirdParty\AutoHotkey\AutoHotkey.exe". Default Command line parameters need to be path to the actual launching script which gets automatically named "Windows Platform Launcher.ahk" when you run the setup button on the script below. Make sure to put that in quotes! Then make sure to check just "remove file extension and folder path". On the Startup Screen tab check "Enable Game Startup Screen", "Enable Game Shutdown Screen", "Hide Mouse Cursor" is optional but recommended, and this is the important one, need to check "Hide All Windows that are not in Exclusive Fullscreen Mode". I also like to move up the Startup Load delay a bit and use 10sec since the majority of games will load prior to that and take over with exclusive fullscreen anyways. But some games take a little longer to load and this usually is enough for them too. One last thing to do in this area is to go into Associated Platforms tab and list the platform(s) you want it to be used (associated) with. Very last step is assigning the games you want to use this pseudo emulator. Do a bulk edit of the games you want to use it by selecting them, and then right clicking on them and go to edit, or use the hotkey Ctrl + E. Select the emulator field, and the value will be the name of the pseudo emulator you just created. If you do it by one at a time you go to the Emulation tab and select the emulator from that drop down

image.thumb.png.634d6bf67493b25a80b1b59e643ae160.pngimage.thumb.png.32b7dec1bfda9a4ddd178db23f893382.png

 

 

So my script is something I spent a handful of weeks tweaking just for my needs and as a result is as you can see a little more difficult to explain. Hopefully I got my point across but if you use this and need any help or have issues with it please let me know! If mine just sounds like a bunch of rambling nonsense I wouldn't hold it against anyone lol - Joes is easier to understand by far!

 

skizzosjt's script - I call this "WPL Manager" - short for Windows Platform Launcher Manager. When this is run for first time or the setup button used it will create "Windows Platform Launcher.ahk" which is the actual script you put into the pseudo emulators Default Command line parameters field.
 

Spoiler

 

;///////////////////////////////////////////////////////////////// 
;Windows Plattform Launcher Manager
;AHK Version: 1.1.343.03
;Author: skizzosjt
;/////////////////////////////////////////////////////////////////

FileEncoding, UTF-16
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
ScriptBeginning:

GameIDArray := []
GameNameArray := []
CombinedSorted := []
GameIDSorted := []
GameNameSorted := []

;/////////////////////////////////////////////////////////////////
;Read the INI file to get just the section names
;Then parse the names into an array
;Combine IDs and names, sort them, and put into an array
;Parse them back into individual arrays
;Put names into a drop down list
;/////////////////////////////////////////////////////////////////
CustomIniFile := "WPL Database (Custom Entries).ini"
IniFile := "WPL Database.ini"
IniRead, SectionTitle, %IniFile%
Loop, Parse, SectionTitle, `n
	 GameIDArray.Push(A_LoopField)
GameIDArray.RemoveAt(1) ;this removes the first section entry which is "config" for the "WorkDir". this way it doesn't show up as an error in the DDL
RollingSort :=
Loop, % GameIDArray.Count()
	{
	 IniRead, GameName, %IniFile%, % GameIDArray[A_Index], GameName
	 GameNameArray.Push(GameName)
	 RollingSort .= GameNameArray[A_Index] . "|" . GameIDArray[A_Index] . "`n"
	}
Sort, RollingSort
Loop, Parse, RollingSort, `n
	CombinedSorted.Push(A_LoopField)

Loop, % CombinedSorted.Count()
	{
	 Loop, Parse, % CombinedSorted[A_Index], |
		{
		 If (Mod(A_Index, 2) = 0)
			 GameIDSorted.Push(A_LoopField)
		 Else
			 GameNameSorted.Push(A_LoopField)
		}
	}
GameNameSortedDDL :=
GameNameSorted.InsertAt(1, "------------------NEW ENTRY------------------`n")
Loop, % GameNameSorted.Count() 
	GameNameSortedDDL .= GameNameSorted[A_Index] . "`n"
GameIDSorted.InsertAt(1, "")

If (RefreshDDLFlag = 1)
	{
	 RefreshDDLFlag :=
	 GuiControl, , SelectedGame, `n%GameNameSortedDDL%
	 Loop, % GameNameSorted.Count()
		{
	 	 If (InStr(GameNameSorted[A_Index], Title))
			{
			 StoredIndex := A_Index
		 	 Break
			}
		}
	 If (DeleteGameFlag = 1 or StoredIndex = 1)
		{
		 DeleteGameFlag :=
		 GuiControl, Choose, SelectedGame, %StoredIndex%
		 GuiControl, , Title
		 GuiControl, , WinTitle
		 GuiControl, , Delay
		 GuiControl, , GameID
		 GuiControl, , GameFile
		 GuiControl, Disable, DeleteButton
		 GuiControl, , EditButton, Add
		}
	 Else
		{
		 GuiControl, Choose, SelectedGame, %StoredIndex%
	 	 GuiControl, Enable, DeleteButton
		 GuiControl, , EditButton, Edit
		}
	 Return
	}

;/////////////////////////////////////////////////////////////////
;Creating the GUI
;/////////////////////////////////////////////////////////////////
Gui, Main:New, , Windows Platfrom Launcher

Gui, Main:Add, Button, x124 y5 w70 gFileSelect, Setup

Gui, Main:Add, Text, x20 y25, Title:
Gui, Main:Add, Edit, x20 y40 w275 vTitle

Gui, Main:Add, Text, x20 y70, WinTitle:
Gui, Main:Add, Edit, x20 y85 w275 vWinTitle

Gui, Main:Add, Text, x20 y115, Delay:
Gui, Main:Add, Edit, x20 y130 w70
Gui, Main:Add, UpDown, vDelay Range0-30000

Gui, Main:Add, Text, x100 y115, Launcher:
Gui, Main:Add, DropDownList, x100 y130 w85 vLauncher gLauncherRoutine +Choose1, Steam|Uplay|Epic|PC

Gui, Main:Add, Text, x195 y115, Game ID:
Gui, Main:Add, Edit, x195 y130 w100 vGameID

Gui, Main:Add, Text, x20 y160, Game File:
Gui, Main:Add, Edit, x20 y175 w200 vGameFile
GuiControl, Disable, GameFile
Gui, Main:Add, Button, x225 y174 w70 gGameFileSelect vGameFileSelectButton, Browse
GuiControl, Disable, GameFileSelectButton

Gui +Delimiter`n
Gui, Main:Add, DropDownList, x20 w200 y212 vSelectedGame gSelectGame +AltSubmit +Choose1, %GameNameSortedDDL%
Gui, Main:Add, Button, x225 y211 w70 vEditButton gEditGame, Add
Gui, Main:Add, Button, x225 y245 w70 vDeleteButton gDeleteGame, Delete
GuiControl, Disable, DeleteButton

Gui, Main:Add, CheckBox, x20 y250 vAOT, Force window to always be on top?

Gui, Main:Show, w318 h290

If (!FileExist("Windows Platform Launcher.ahk"))
	{
	 MsgBox, 8256, Welcome to WPL, First launch detected, setup will begin
	 Goto, FileSelect
	}
Return

MainGuiClose:
ExitApp

;/////////////////////////////////////////////////////////////////
;Setup process - selecting XML file and generating list/data
;Creating launching script and ini database files
;with appropriate relative addresses when required
;/////////////////////////////////////////////////////////////////
FileSelect:
FileSelectFile, WindowsXML, , , Select your Windows.xml file - Found in LaunchBox/Data/Platforms, XML (*.xml)
WorkDir := StrReplace(WindowsXML, "\Data\Platforms\Windows.xml", "")
If (ErrorLevel = 1)
	Return
GoSub, SetVars
FileDelete, Windows Platform Launcher.ahk
FileAppend, %WPLContentsA%%WPLContentsLBDir%%WPLContentsB%, Windows Platform Launcher.ahk
FileDelete, %IniFile%
FileAppend, %Header%`n`n%HeaderB%, %IniFile%

FileEncoding, UTF-8
Loop, Read, %WindowsXML%
	{
	 If (InStr(A_LoopReadLine, "<ApplicationPath>steam"))
		{
		 GameID := StrSplit(A_LoopReadLine, "/", "<")
		 GameID := GameID[4]
		 Launcher := "Steam"
		}
	 Else If (InStr(A_LoopReadLine, "<ApplicationPath>uplay"))
		{
		 GameID := StrSplit(A_LoopReadLine, "/", "<")
		 GameID := GameID[4]
		 Launcher := "Uplay"
		}
	 Else If (InStr(A_LoopReadLine, "<ApplicationPath>com.epicgames"))
		{
		 GameID := StrSplit(A_LoopReadLine, ["/", "?"])
		 GameID := GameID[4] . "?action=launch&silent=true"
		 Launcher := "Epic"
		}
	 Else If (InStr(A_LoopReadLine, ".exe</ApplicationPath>") or InStr(A_LoopReadLine, ".ahk</ApplicationPath>") or InStr(A_LoopReadLine, ".bat</ApplicationPath>") or InStr(A_LoopReadLine, ".lnk</ApplicationPath>") or InStr(A_LoopReadLine, ".url</ApplicationPath>"))
		{
		 Loop, Parse, A_LoopReadLine, \
			 ParseIndex++
		 Loop, Parse, A_LoopReadLine, \
			{
			 If (A_Index = ParseIndex)
				{
				 PCGameFile := SubStr(A_LoopField, 1, -18)
				 ParseIndex := 0			
				}
			} 
		 GameID := SubStr(PCGameFile, 1, -4)
		 PCGamePath := SubStr(A_LoopReadLine, 1, -18)
		 PCGamePath := SubStr(PCGamePath, 22)
		 PCGamePath := StrReplace(PCGamePath, PCGameFile, "")
		 Launcher := "PC"
		}
	 If (InStr(A_LoopReadLine, "<Title>"))
		{
		 GameTitle := StrSplit(A_LoopReadLine, ">", "</")
		 GameTitle := SubStr(GameTitle[2], 1, -7)
		 If (InStr(GameTitle, "&amp;"))
			GameTitle := StrReplace(GameTitle, "&amp;", "&")
		 WinTitle := GameTitle
		 WinActivateDelay := 5000
		 AOT := 0
		 IniRead, GameNameINI, %CustomIniFile%, %GameID%, GameName, %A_Space%
		 IniRead, WinTitleINI, %CustomIniFile%, %GameID%, WinTitle, %A_Space%
		 IniRead, LauncherINI, %CustomIniFile%, %GameID%, Launcher, %A_Space%
		 IniRead, DelayINI, %CustomIniFile%, %GameID%, WinActivateDelay, %A_Space%
		 IniRead, AOTINI, %CustomIniFile%, %GameID%, AOT, %A_Space%
		 IniRead, GamePathINI, %CustomIniFile%, %GameID%, GamePath, %A_Space%
		 IniRead, GameFileINI, %CustomIniFile%, %GameID%, GameFile, %A_Space%
		 If (GameNameINI != "")
			 GameTitle := GameNameINI
		 If (WinTitleINI != "")
			 WinTitle := WinTitleINI
		 If (LauncherINI != "")
			 Launcher := LauncherINI
		 If (DelayINI != "")
			 WinActivateDelay := DelayINI
		 If (AOTINI != "")
			 AOT := AOTINI
		 If (GamePathINI != "")
			 PCGamePath := GamePathINI
		 If (GameFileINI != "")
			 PCGameFile := GameFileINI
		 If (Launcher = "Steam" or Launcher = "Uplay" or Launcher = "Epic")
			FileAppend, [%GameID%]`nGameName = %GameTitle%`nWinTitle = %WinTitle%`nLauncher = %Launcher%`nWinActivateDelay = %WinActivateDelay%`nAOT = %AOT%`n`n, %IniFile%
		 Else If (Launcher = "PC")
			FileAppend, [%GameID%]`nGameName = %GameTitle%`nLauncher = %Launcher%`nWinActivateDelay = %WinActivateDelay%`nAOT = %AOT%`nGamePath = %PCGamePath%`nGameFile = %PCGameFile%`n`n, %IniFile%
		 Launcher :=
		}
	}
FileEncoding, UTF-16
RefreshDDLFlag := "1"
Goto, ScriptBeginning

SetVars:
WPLContentsA := "
(
;##################################
;Windows Plattform Launcher
;Author: skizzosjt
;AHK Version: 1.1.343.03
;##################################

SetWorkingDir %A_ScriptDir%
GameID := A_Args[1]
IniFile := ""WPL Database.ini""
IniRead, WinTitle, %IniFile%, %GameID%, WinTitle
IniRead, Launcher, %IniFile%, %GameID%, Launcher
IniRead, WinActivateDelay, %IniFile%, %GameID%, WinActivateDelay
IniRead, AOT, %IniFile%, %GameID%, AOT
IniRead, GamePath, %IniFile%, %GameID%, GamePath
IniRead, GameFile, %IniFile%, %GameID%, GameFile
If (Launcher = ""Steam"")
	{
	 LaunchCommand := ""steam://rungameid/"" . GameID
	 IgnoreWinTitle := ""Steam""
	}
Else If (Launcher = ""Uplay"")
	{
	 LaunchCommand := ""uplay://launch/"" . GameID
	 IgnoreWinTitle := ""Ubisoft""
	}
Else If (Launcher = ""Epic"")
	 LaunchCommand := ""com.epicgames.launcher://apps/"" . GameID
Else If (Launcher = ""PC"")
	{
	 SetWorkingDir 
)"

WPLContentsLBDir := " " . StrReplace(WindowsXML, "\Data\Platforms\Windows.xml", "") . "`n"

WPLContentsB := "
(
	 SetWorkingDir %GamePath%
	 LaunchCommand := GameFile
	 WinTitle := ""ahk_exe "" . GameFile
	}

Run, %LaunchCommand%
SetTitleMatchMode, 2 
WinWait, %WinTitle%, , , %IgnoreWinTitle%
Sleep, %WinActivateDelay%
WinActivate, %WinTitle%
If (AOT = ""1"")
	WinSet, AlwaysOnTop, on, %WinTitle%
Else
	{
	 SetTitleMatchMode, 3
	 WinSet, Bottom, , LaunchBox Game Startup
	 WinSet, Bottom, , LaunchBox Big Box
	 WinSet, Bottom, , LaunchBox
	 SetTitleMatchMode, 2
	}
WinWaitClose, %WinTitle%
SetTitleMatchMode, 3
SetWinDelay, -1
WinActivate, LaunchBox Game Startup
WinSet, AlwaysOnTop, on, LaunchBox Game Startup
WinWaitClose, LaunchBox Game Startup
WinActivate, LaunchBox Big Box
ExitApp
)"

Header := "
(
;######################################################################################
;Windows Platform Launcher Database
;Author: skizzosjt
;WinTitles are case sensitive and need to be at least a partial match to window's title
;or be another AHK WinTitle type (https://www.autohotkey.com/docs/misc/WinTitle.htm)
;WinActivateDealy is the amount of time between detecting window and activating it
;Unit of measurement for delay is 1000 = 1 second
;AOT = Always on top / 1 = ON / 0 = OFF
;######################################################################################
)"

HeaderB := "[config]`nWorkDir = " . WorkDir . "`n`n"
Return

;/////////////////////////////////////////////////////////////////
;Selecting PC file with file browser
;/////////////////////////////////////////////////////////////////
GameFileSelect:
FileSelectFile, GameFile, , , Select file
Splitpath, GameFile, GameFileUI, GameDir
GameFileNoExt := SubStr(GameFileUI, 1, -4)
GuiControl, , GameFile, %GameFileUI%
GuiControl, , GameID, %GameFileNoExt%
Goto, RelativePath

;/////////////////////////////////////////////////////////////////
;Selecting a game or a new entry
;/////////////////////////////////////////////////////////////////
SelectGame:
Gui, Submit, NoHide
IniRead, GameTitle, %IniFile%, % GameIDSorted[SelectedGame], GameName, %A_Space%
IniRead, WinTitle, %IniFile%, % GameIDSorted[SelectedGame], WinTitle, %A_Space%
IniRead, Launcher, %IniFile%, % GameIDSorted[SelectedGame], Launcher, %A_Space%
IniRead, Delay, %IniFile%, % GameIDSorted[SelectedGame], WinActivateDelay, %A_Space%
IniRead, AOT, %IniFile%, % GameIDSorted[SelectedGame], AOT, %A_Space%
IniRead, GamePath, %IniFile%, % GameIDSorted[SelectedGame], GamePath, %A_Space%
IniRead, GameFileINI, %IniFile%, % GameIDSorted[SelectedGame], GameFile, %A_Space%
If (Launcher = "Steam")
	LauncherSelection := "1"
If (Launcher = "Uplay")
	LauncherSelection := "2"
If (Launcher = "Epic")
	LauncherSelection := "3"
If (Launcher = "PC")
	LauncherSelection := "4"
If (SelectedGame = 1)
	{
	 GuiControl, Disable, DeleteButton
	 GuiControl, , EditButton, Add
	}
Else
	{
	 GuiControl, Enable, DeleteButton
	 GuiControl, , EditButton, Edit
	}
GuiControl, , Title, %GameTitle%
GuiControl, , WinTitle, %WinTitle%
GuiControl, Choose, Launcher, %LauncherSelection%
GuiControl, , Delay, %Delay%
GuiControl, , GameID, % GameIDSorted[SelectedGame]
GuiControl, , GameFile, %GameFileINI%
If (AOT = "1")
	GuiControl, , AOT, 1
Else
	GuiControl, , AOT, 0

;/////////////////////////////////////////////////////////////////
;Routine to update GUI when launcher DDL is changed
;/////////////////////////////////////////////////////////////////
LauncherRoutine:
Gui, Submit, NoHide
If (Launcher = "PC")
	{
	 GuiControl, Disable, WinTitle
	 GuiControl, Enable, GameFile
	 GuiControl, Enable, GameFileSelectButton
	}
Else If (Launcher != "PC")
	{
	 GuiControl, Enable, WinTitle
	 GuiControl, Disable, GameFile
	 GuiControl, Disable, GameFileSelectButton
	}
Return

;/////////////////////////////////////////////////////////////////
;Editing any existing game. Diverts to new game entry if needed
;/////////////////////////////////////////////////////////////////
EditGame:
Gui, Submit, NoHide
ErrorTitle :=
ErrorWinTitle :=
ErrorGameID :=
ErrorFileIDMismatch :=
ErrorGameFile :=
If (Title = "")
	ErrorTitle := "`n-Title cannot be blank"
If (GameID = "")
	ErrorGameID := "`n-Game ID cannot be blank"
If (Launcher = "PC")
	{
	 If (GameDir = "")
		GameDir := GamePath
	 GameFileNoExt := SubStr(GameFile, 1, -4)
	 If (GameFileNoExt != GameID)
		ErrorFileIDMismatch := "`n`nGame ID and Game File must match`nPlease select file with the Browse button`n"
	 If (GameFile = "")
		ErrorGameFile := "`n-Game File cannot be blank"
	 If (Title = "" or GameID = "" or GameFile = "" or GameFileNoExt != GameID)
		{
	 	 MsgBox, 8240, ERROR , The following errors occured for a PC game:`n%ErrorTitle%%ErrorGameID%%ErrorGameFile%%ErrorFileIDMismatch%
	 	 Return
		}
	 If (Selected Game = "1" or GameID != GameIDSorted[SelectedGame] or GameIDArray[GameIDArray.Count()] = GameIDSorted[SelectedGame])
		Goto, NewGameEntryPC
	 Else
		{
	 	 IniWrite, GameName = %Title%`nLauncher = %Launcher%`nWinActivateDelay = %Delay%`nAOT = %AOT%`nGamePath = %GameDir%`nGameFile = %GameFile%`n, %IniFile%, % GameIDSorted[SelectedGame]
		 IniDelete, %CustomIniFile%, % GameIDSorted[SelectedGame]
		 FileAppend, % "[" . GameID . "]`nGameName = " . Title . "`nLauncher = " . Launcher . "`nWinActivateDelay = " . Delay . "`nAOT = " . AOT . "`nGamePath = " . GameDir . "`nGameFile = " . GameFile . "`n`n", %CustomIniFile%
		 If (Title != GameTitle)
			{
			 RefreshDDLFlag := "1"
			 Goto, ScriptBeginning
			}
		}
	}
Else If (Launcher != "PC")
	{
	 If (WinTitle = "")
		ErrorWinTitle := "`n-Win Title cannot be blank"
 	 If (Title = "" or WinTitle = "" or GameID = "")
		{
	 	 MsgBox, 8240, ERROR , The following errors occured for a %Launcher% game:`n%ErrorTitle%%ErrorWinTitle%%ErrorGameID%
	 	 Return
		}
	 If (SelectedGame = "1" or GameID != GameIDSorted[SelectedGame] or GameIDArray[GameIDArray.Count()] = GameIDSorted[SelectedGame])
		Goto, NewGameEntryNonPC
	 Else
		{
		 IniWrite, GameName = %Title%`nWinTitle = %WinTitle%`nLauncher = %Launcher%`nWinActivateDelay = %Delay%`nAOT = %AOT%`n, %IniFile%, % GameIDSorted[SelectedGame]
		 IniDelete, %CustomIniFile%, % GameIDSorted[SelectedGame]
		 FileAppend, % "[" . GameID . "]`nGameName = " . Title . "`nWinTitle = " . WinTitle . "`nLauncher = " . Launcher . "`nWinActivateDelay = " . Delay . "`nAOT = " . AOT . "`n`n", %CustomIniFile%
		 If (Title != GameTitle)
			{
			 RefreshDDLFlag := "1"
			 Goto, ScriptBeginning
			}
		}
	}
Return

;/////////////////////////////////////////////////////////////////
;New entry for a PC game
;/////////////////////////////////////////////////////////////////
NewGameEntryPC:
IniDelete, %IniFile%, % GameIDSorted[SelectedGame]
IniDelete, %CustomIniFile%, % GameIDSorted[SelectedGame]
FileAppend, % "[" . GameID . "]`nGameName = " . Title . "`nLauncher = " . Launcher . "`nWinActivateDelay = " . Delay . "`nAOT = " . AOT . "`nGamePath = " . GameDir . "`nGameFile = " . GameFile . "`n`n", %IniFile%
FileAppend, % "[" . GameID . "]`nGameName = " . Title . "`nLauncher = " . Launcher . "`nWinActivateDelay = " . Delay . "`nAOT = " . AOT . "`nGamePath = " . GameDir . "`nGameFile = " . GameFile . "`n`n", %CustomIniFile%
Goto, BlankLineRemoval

;/////////////////////////////////////////////////////////////////
;New entry for a non-PC game
;/////////////////////////////////////////////////////////////////
NewGameEntryNonPC:
IniDelete, %IniFile%, % GameIDSorted[SelectedGame]
IniDelete, %CustomIniFile%, % GameIDSorted[SelectedGame]
FileAppend, % "[" . GameID . "]`nGameName = " . Title . "`nWinTitle = " . WinTitle . "`nLauncher = " . Launcher . "`nWinActivateDelay = " . Delay . "`nAOT = " . AOT . "`n`n", %IniFile%
FileAppend, % "[" . GameID . "]`nGameName = " . Title . "`nWinTitle = " . WinTitle . "`nLauncher = " . Launcher . "`nWinActivateDelay = " . Delay . "`nAOT = " . AOT . "`n`n", %CustomIniFile%
Goto, BlankLineRemoval

;/////////////////////////////////////////////////////////////////
;Delete selected game
;/////////////////////////////////////////////////////////////////
DeleteGame:
Gui, Submit, NoHide ;had to add so you can immediately delete a newly created entry without having to select back and forth between an existing game to populate the SelectedGame variable
DeleteGameFlag := "1"
IniDelete, %IniFile%, % GameIDSorted[SelectedGame]
IniDelete, %CustomIniFile%, % GameIDSorted[SelectedGame]
Goto, BlankLineRemoval

;/////////////////////////////////////////////////////////////////
;Parse loop to remove any extra blank lines before writing changes
;/////////////////////////////////////////////////////////////////
BlankLineRemoval:
BLR(IniFile)
BLR(CustomIniFile)
BLR(Ini)
	{
	 ParseOutput :=
	 IniParsedOutput :=
	 FileRead, IniRead, %Ini%
	 Loop, Parse, IniRead, `n, `r
		ParseOutput .= A_LoopField . "^"
	 If (InStr(ParseOutput, "^^^"))
		ParseOutput := StrReplace(ParseOutput, "^^^", "^^")
	 ParseOutput := SubStr(ParseOutput, 1, -1)
	 Loop, Parse, ParseOutput, ^
		IniParsedOutput .= A_LoopField . "`n"
	 FileDelete, %Ini%
	 FileAppend, %IniParsedOutput%, %Ini%
	}
RefreshDDLFlag := "1"
Goto, ScriptBeginning

;/////////////////////////////////////////////////////////////////
;Relative path generator
;/////////////////////////////////////////////////////////////////
RelativePath:
If (WindowsXML = "")
	IniRead, WorkDir, %CustomIniFile%, config, WorkDir
Else
	WorkDir := StrReplace(WindowsXML, "\Data\Platforms\Windows.xml", "")
TargetDir := GameDir

SplitWorkDir := []
SplitTargetDir := []

WorkDir := StrSplit(WorkDir, "\")
Loop, % WorkDir.Count()
	SplitWorkDir.Push(WorkDir[A_Index])

FullPathTargetDir := TargetDir
TargetDir := StrSplit(TargetDir, "\")
Loop, % TargetDir.Count()
	SplitTargetDir.Push(TargetDir[A_Index])

If (WorkDir.Count() <= TargetDir.Count())
	{
	 LowerCount := WorkDir.Count()
	 HigherCount := TargetDir.Count()
	 CompareVar := "Option1"
	}
Else
	{
	 LowerCount := TargetDir.Count()
	 HigherCount := WorkDir.Count()
	 CompareVar := "Option2"
	}

MatchCount :=
CombinedWorkDir :=
Loop, %LowerCount%
	{
	 If (SplitWorkDir[A_Index] == SplitTargetDir[A_Index])
		{
		 MatchCount++
		 CombinedWorkDir .= SplitWorkDir[A_Index] . "\"
		}
	 Else
		 Break
	}
RelPath := StrReplace(FullPathTargetDir, CombinedWorkDir, "")

If (CompareVar = "Option1")
	 Delta := (LowerCount - MatchCount)
Else
	 Delta := (HigherCount - MatchCount)

SemiFinalRelPath :=
If (Delta = 0)
	SemiFinalRelPath := ".\"
Else
	{
	 Loop, %Delta%
		SemiFinalRelPath .= "..\"
	}
If (LowerCount = MatchCount and Delta != 0)
	RelPath :=

FinalRelPath := SemiFinalRelPath . RelPath . "\"
GameDir := FinalRelPath
Return 

 

 

 

 

Edited by skizzosjt
Correcting wrong info
  • Like 2
Link to comment
Share on other sites

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...