Skip to content

Commit

Permalink
Fix game launching
Browse files Browse the repository at this point in the history
At some point Relic broke launch arguments via URI
  • Loading branch information
SavageCore committed Apr 10, 2023
1 parent e4da8ec commit 673dc3f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
21 changes: 18 additions & 3 deletions modules/replay/play.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package replay

import (
"coh3-replay-manager-go/modules/utils"
"fmt"
"os/exec"
"strings"

"github.com/gen2brain/beeep"
"github.com/skratchdot/open-golang/open"
)

// Launch the game
// Sample command:
// C:\Program Files (x86)\Steam\steam.exe -applaunch 1677280 -replay playback:file.rec
func Play(fileName string) {
url := fmt.Sprintf("steam://run/1677280//-replay playback:%s", fileName)
// Get Steam path
steamPath := utils.GetSteamPath()
launchOptions := fmt.Sprintf(`-applaunch 1677280 -replay playback:%s`, fileName)

open.Run(url)
args := strings.Split(launchOptions, " ")

cmd := exec.Command(steamPath, args...)

_, cmdErr := cmd.Output()

if cmdErr != nil {
fmt.Println(cmdErr.Error())
}

title := "Replay launched 🚀"
message := "⚠️ Look out for a confirmation window from Steam, allowing you to launch the game. ⚠️"
Expand Down
22 changes: 22 additions & 0 deletions modules/utils/steam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package utils

import "golang.org/x/sys/windows/registry"

func GetSteamPath() string {
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1677280`, registry.QUERY_VALUE)
if err != nil {
panic(err)
}
defer key.Close()

value, _, err := key.GetStringValue("UninstallString")
if err != nil {
panic(err)
}

// Sample UninstallString value:
// "C:\Program Files (x86)\Steam\steam.exe" steam://uninstall/1677280

// Return the path to the Steam executable
return value[1 : len(value)-len("\" steam://uninstall/1677280")]
}

0 comments on commit 673dc3f

Please sign in to comment.