Skip to content

Commit

Permalink
Bug fix: Steam shortcut not opening game
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelo420 committed Dec 12, 2024
1 parent 9ea5318 commit cd0d317
Showing 1 changed file with 9 additions and 38 deletions.
47 changes: 9 additions & 38 deletions gamevault/Helper/Integrations/SteamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ await Task.Run(async () =>
shortcutFileMap = VdfUtilities.ReadVdf(File.ReadAllBytes(Path.Combine(shortcutsDirectory, "shortcuts.vdf")));
shortcutFileMap = TrimFirstOffsetEntry(shortcutFileMap);//Making sure to have a clean game list
shortcutFileMap = RemoveUninstalledGames(shortcutFileMap, games, out steamGridImageIDsToRemove);//Checks for gamevault games and compares them to the current installed game list. Extracts also the steam grid image ids for clean removal later on
shortcutFileMap = EnsureAssemblyPath(shortcutFileMap);//Checks if paths are up to date. Can change because of a manual move or a MC Store update
games = TrimExistingGames(games, shortcutFileMap);//No need for double entries. So they will be removed
}
catch { }
Expand All @@ -268,7 +267,7 @@ await Task.Run(async () =>
root.Add("shortcuts", shortcutFileMap);//Adds back the first offset entry a vdf file needs to work

File.WriteAllBytes(shortcutFile, VdfUtilities.WriteVdf(root));
//The steam grid image is only processed after it has been written.Because if it did not work to manipulate the VDF file, there is no point in changing anything in the images
//The steam grid image is only processed after it has been written. Because if it did not work to manipulate the VDF file, there is no point in changing anything in the images
string steamGridDirectory = Path.Combine(shortcutsDirectory, "grid");
if (!Directory.Exists(steamGridDirectory))
{
Expand Down Expand Up @@ -306,13 +305,12 @@ internal static void RemoveGameVaultGamesFromSteamShortcuts()
VdfMap shortcutFileMap = VdfUtilities.ReadVdf(File.ReadAllBytes(shortcutFile));
shortcutFileMap = TrimFirstOffsetEntry(shortcutFileMap);//Making sure to have a clean game list
List<string> steamGridImageIDsToRemove = new List<string>();
//string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;
for (int count = 0; count < shortcutFileMap.Count; count++)
{
string currentGameExe = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(2).Value.ToString();
string currentGameTitle = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(1).Value.ToString();
//Check for gamevault exe instead of the path because MC store changes app directory on updates
if (currentGameExe.Contains("gamevault.exe", StringComparison.OrdinalIgnoreCase))
//Check for gamevault protocol
if (currentGameExe.Contains("gamevault://", StringComparison.OrdinalIgnoreCase))
{
steamGridImageIDsToRemove.Add(((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(0).Value.ToString());
shortcutFileMap.Remove(shortcutFileMap.ElementAt(count).Key);
Expand Down Expand Up @@ -358,40 +356,15 @@ private static void SetSteamGridImages(string steamGridDirectory, Game game, uin
File.Copy(imageCache["gbg"], Path.Combine(steamGridDirectory, $"{steamGridID}_hero.png"));
}
}
private static VdfMap EnsureAssemblyPath(VdfMap shortcutFileMap)
{
string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;
for (int count = 0; count < shortcutFileMap.Count; count++)
{
string currentGameExe = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(2).Value.ToString();
//string currentGameStartDir = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(3).Value.ToString();
if (currentGameExe.Contains("gamevault.exe", StringComparison.OrdinalIgnoreCase) && currentGameExe != exeFullPath)
{
string workingDirectory = AppDomain.CurrentDomain.BaseDirectory;

//Set updated exe
var exeOuterKey = shortcutFileMap.Keys.ElementAt(count);
VdfMap exeInnerDictionary = (VdfMap)shortcutFileMap[exeOuterKey];
var exeInnerKey = exeInnerDictionary.Keys.ElementAt(2);
exeInnerDictionary[exeInnerKey] = exeFullPath;
//Set updated working dir
var workDirOuterKey = shortcutFileMap.Keys.ElementAt(count);
VdfMap workDirInnerDictionary = (VdfMap)shortcutFileMap[workDirOuterKey];
var workDirInnerKey = workDirInnerDictionary.Keys.ElementAt(3);
workDirInnerDictionary[workDirInnerKey] = workingDirectory;
}
}
return shortcutFileMap;
}
private static VdfMap RemoveUninstalledGames(VdfMap shortcutFileMap, Dictionary<Game, string> games, out List<string> steamGridImagesToRemove)
{
steamGridImagesToRemove = new List<string>();
for (int count = 0; count < shortcutFileMap.Count; count++)
{
string currentGameExe = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(2).Value.ToString();
string currentGameTitle = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(1).Value.ToString();
//Check for gamevault exe instead of the path because MC store changes app directory on updates
if (currentGameExe.Contains("gamevault.exe", StringComparison.OrdinalIgnoreCase) && !games.Keys.Any(g => g?.Title == currentGameTitle))
//Check for gamevault protocol
if (currentGameExe.Contains("gamevault://", StringComparison.OrdinalIgnoreCase) && !games.Keys.Any(g => g?.Title == currentGameTitle))
{
steamGridImagesToRemove.Add(((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(0).Value.ToString());
shortcutFileMap.Remove(shortcutFileMap.ElementAt(count).Key);
Expand Down Expand Up @@ -420,18 +393,16 @@ private static VdfMap GenerateVdfShortcutEntryFromGame(Game game, string shortcu
string idInput = game.Title + game.ID;
uint steamGridId = VdfUtilities.GenerateSteamGridID(idInput);
string steamGridIconPath = Path.Combine(shortcutDir, "grid", $"{steamGridId}p.png");
string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;//Let GameVault handle the game startup
string workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
string launchOptions = $"start --gameid={game.ID}";
string launchUrl = $"gamevault://start?gameid={game.ID}";
var newGame = new VdfMap
{
{ "appid", steamGridId },
{ "AppName", game.Title },
{ "Exe", exeFullPath },
{ "StartDir", workingDirectory },
{ "Exe", launchUrl },
{ "StartDir","" },
{ "icon", steamGridIconPath },
{ "ShortcutPath", "" },
{ "LaunchOptions", launchOptions },
{ "LaunchOptions", "" },
{ "IsHidden", 0 },
{ "AllowDesktopConfig", 1 },
{ "AllowOverlay", 1 },
Expand Down

0 comments on commit cd0d317

Please sign in to comment.