JosefNemec / PlayniteExtensions

Extensions for Playnite game launcher and manager.
MIT License
162 stars 39 forks source link

Launch itch games through the itch.io client #98

Open lbacud opened 5 years ago

lbacud commented 5 years ago

Is there a way to launch an itch.io game through the client's launch command, similar to GOG Galaxy? The client features a sandboxing security system that saves games in a different location than the where the executable would save by default. This means I don't get the same game save files if I launched through Playnite, than if I were to launch them through the itch.io client.

When an HTML-based game launches through itch.io it opens in an uncluttered webview window, where opening it currently in playnite opens it in the default browser.

JosefNemec commented 5 years ago

It will be possible once the support is added to Itch client: https://github.com/itchio/itch/issues/2233

For HTML-based game I could do something better then just launch it via browser. Do you have some examples of games that I could test it on?

lbacud commented 5 years ago
piber20 commented 2 years ago

Seconding this. It would be nice to be able to launch the games through Playnite with ease, having it launch with the itch.io client, keeping my saves. I was playing "MANIC MINERS" and was disappointed that when I tried it didn't keep my saves.

Ryonez commented 1 year ago

Is there a way for Playnite to implement things on this side? I'm not confident that this is something they are going to sort out.

Looking into this, the sandbox account credentials are stored at Computer\HKEY_CURRENT_USER\Software\itch\Sandbox. Could we use this to run the already known executables as the sandbox user, adding a toggle in the integration config to enable it?

Played around with it and made a PowerShell script that kinda does this:

# References:
# Start-Process: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.3
# Get-ItemPropertyValue: https://adamtheautomator.com/powershell-to-get-a-registry-value/
# Pull username and password of sandbox from registry
$user = Get-ItemPropertyValue -Path 'HKCU:\Software\itch\Sandbox' -Name username
$pass = Get-ItemPropertyValue -Path 'HKCU:\Software\itch\Sandbox' -Name password | convertto-securestring -asplaintext -force

# Create args for Start-Process
$processOptions = @{
    # Path to exe
    FilePath = "Path to process"
    # Start-Process has trouble without a working dir set.
    WorkingDirectory = "Working dir of process"
    # Form and use a credential set.
    Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $pass
    # And this is a sandbox process, so make sure the env isn't inherited (by default it's inherited).
    UseNewEnvironment = $true
}
Start-Process @processOptions
Ryonez commented 1 year ago

Been working on this more, trying to make a global script. Stuck on the point where I need to get the file path from the library integration. Even then, I'd also have to put a blank play action in so there's no error popups when I run the game, as the global script kinda does it... What I have so far:

# Access the Playnite database
$database = $PlayniteApi.Database

# Retrieve the last opened game
$lastOpenedGame = $database.Games | Sort-Object -Property LastActivity -Descending | Select-Object -First 1

#Sandbox itch.io games.
if($lastOpenedGame.PluginId -eq ("00000001-ebb2-4eec-abcb-7c89937a42bb")) {
    # Get and parse sandbox credentials.
    $registryPath = "HKCU:\Software\itch\Sandbox"
    $username = (Get-ItemProperty -Path $registryPath).username
    $password = (Get-ItemProperty -Path $registryPath).password
    $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
    $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $securePassword
    $gameExecutable = $lastOpenedGame.GameActions[0].Path #This currently doesn't work. Have to use this as a play Action script and point to the actual file.

    $gameStartParams = @{
        FilePath = $gameExecutable
        WorkingDirectory = (Split-Path -Path $gameExecutable)
        Credential = $credential
        #NoNewWindow = $true
    }
    Start-Process @gameStartParams
}