PoPRuns / SandsTrilogyKiller

Quits and restarts games of the Prince of Persia Sands Trilogy for consistency in speedruns
4 stars 2 forks source link

Auto-find the game executable location by looking it up in the Windows Registry #12

Open Swyter opened 1 year ago

Swyter commented 1 year ago

I commented this back in January, but I'll leave it here so that it doesn't get lost, in case someone wants to look into it: https://discord.com/channels/83365709064699904/760854217509830676/1067540740281991218

Swyter — 01/24/2023 9:25 PM I can also probably help you guys out with a way to automatically find the game executables. I have done that before. Maybe it would also be interesting to mod the profiles to natively launch the games windowed without using dxwnd. It should be pretty easy.

Swyter — 01/24/2023 9:33 PM You can see that at least on the Steam install script (the installscript.vdf file) it creates some nifty Windows Registry keys under HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Prince of Persia Warrior Within\1.00.999, HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Prince of Persia The Two Thrones\1.00.999, the most interesting one being Product_Path, with the game path.

Swyter — 01/24/2023 9:41 PM Then, for Uplay/Ubisoft Connect there is HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs\111 with the InstallDir key pointing to whatever the user chose during install. Here the 111 ID is for Sands of Time. You can see the other IDs here: https://github.com/Haoose/UPLAY_GAME_ID#prince-of-persia-franchise It should be easy to retrieve and universal. Then, for Steam, the gist of it is finding out where the Steam directory is, with HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam, using the InstallPath key. You then open <steam-folder>\steamapps\libraryfolders.vdf, find the paths to the libraries/drives where the games can be installed. You can find if the game is installed in that library by searching for a appmanifest_13500.acf (WW), appmanifest_13530.acf (TT), appmanifest_13600.acf (SoT) file in the root.

Swyter — 01/24/2023 9:49 PM In that .ACF file there's an installdir line with the folder name, but I guess you could even hardcode it to search under <steam-library>\steamapps\common\Prince of Persia The Warrior Within directly, and so on. That's mostly it, it looks harder than it really is. And it's a very nice feature to have. Go through the list of found paths and test if the POP.exe / POP2.exe / POP3.exe files are inside. There's your game.

Swyter — 01/24/2023 10:05 PM This is how you open the 32-bit hive of the Registry in C Sharp: https://stackoverflow.com/a/18772256/674685

Swyter commented 1 year ago

CC: @GMPranav, @kugelrund.

GMPranav commented 1 year ago

This is a good idea. Perhaps something that can be run when the program is run first time and then user can change it as per their wish.

kugelrund commented 1 year ago

I appreciate the suggestions and understand the intent, but I don't think this is a good idea. Resorting to the mess of the Windows Registry and relying on hardcoded keys for the tiny benefit of not having to set the path once in the lifetime of your PC does not seem like a good tradeoff to me. Just introduces unnecessary legacy code for something that users can do manually in seconds.

If you really desperately want this and implement it cleanly, clearly separated from everything else, I'm fine with merging it, but I wouldn't want to encourage you to spend the time.

Swyter commented 1 year ago

This is the opposite of hardcoding; the Windows Registry is how programs detect and find each other. Every installer and Steam itself uses the steps above every time you launch your games, it's how default programs are set.

I have worked with Win32 APIs for more than ten years. There's nothing messy about it.

Swyter commented 1 year ago

By the way, all the auto-finder magic can be implemented in less than twenty lines. It will find the games instantly, no matter where you bought them or how exotic your drive layout is. This will work from Windows 2000 to the day Windows stops being relevant.

The detailed explanation with three alternatives makes it look more involved than what it really is. The first two methods are one-liners. Steam Libraries just make it hard to the point of reading a configuration file with a format so simple it can be done in Batch.

Just trying to be helpful and make it work out of the box, I don't speedrun.

GMPranav commented 1 year ago

Both sides have valid points. I am also on the side that if this is implemented, there wouldn't be anything particularly wrong or messy with it. But on the other hand, this is meant to be a simple program and as Sphere mentioned its just a one time setup. There is honestly something good about doing that first time setup, it let's the user understand exactly what the program is doing and gives a feeling of control.

In my previous comment, I mentioned this can be run during startup, but after hearing these points I think it's better to have auto-fetch as a separate button.

At the end of the day, whether this will be implemented or not depends on how high it's in the priority list of hobbies for me, Jaka or anyone else looking to contribute to this project. Nothing can change that.