upload
This commit is contained in:
commit
1c7a8cf25f
579 files changed
+83196
No files matched your search
@@ -0,0 +1,3 @@
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public sealed record DetectedGame(SupportedGame Game, string InstallDir);
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public static class EpicLocator
|
||||
{
|
||||
public static string? ParseInstallLocation(string manifestJson, string appName)
|
||||
{
|
||||
try
|
||||
{
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(manifestJson);
|
||||
if (!jsonDocument.RootElement.TryGetProperty("AppName", out var value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!string.Equals(value.GetString(), appName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
JsonElement value2;
|
||||
return jsonDocument.RootElement.TryGetProperty("InstallLocation", out value2) ? value2.GetString() : null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static string? FindGameInstall(string appName)
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Epic", "EpicGamesLauncher", "Data", "Manifests");
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (string item in Directory.EnumerateFiles(path, "*.item"))
|
||||
{
|
||||
string text = ParseInstallLocation(File.ReadAllText(item), appName);
|
||||
if (text != null && Directory.Exists(text))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public static class GameDetection
|
||||
{
|
||||
public static IReadOnlyList<DetectedGame> DetectInstalled(IEnumerable<string> libraryPaths, IEnumerable<SupportedGame> games, Func<string, bool> fileExists)
|
||||
{
|
||||
List<string> list = libraryPaths.ToList();
|
||||
List<DetectedGame> list2 = new List<DetectedGame>();
|
||||
foreach (SupportedGame game in games)
|
||||
{
|
||||
foreach (string item in list)
|
||||
{
|
||||
string arg = Path.Combine(item, "steamapps", $"appmanifest_{game.SteamAppId}.acf");
|
||||
if (fileExists(arg))
|
||||
{
|
||||
string installDir = Path.Combine(item, "steamapps", "common", game.InstallFolder);
|
||||
list2.Add(new DetectedGame(game, installDir));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return list2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public static class GameLibrary
|
||||
{
|
||||
public static IReadOnlyList<DetectedGame> DetectInstalled()
|
||||
{
|
||||
List<DetectedGame> list = new List<DetectedGame>();
|
||||
list.AddRange(DetectSteam());
|
||||
list.AddRange(DetectEpic());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<(SupportedGame Game, DetectedGame? Detected)> OrderForHub(IReadOnlyList<DetectedGame> detected)
|
||||
{
|
||||
Dictionary<SupportedGame, DetectedGame> byGame = detected.ToDictionary((DetectedGame d) => d.Game);
|
||||
return (from g in SupportedGames.All
|
||||
select (Game: g, Detected: byGame.TryGetValue(g, out var value) ? value : null) into x
|
||||
orderby x.Detected == null
|
||||
select x).ToList();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<DetectedGame> DetectSteam()
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = SteamLocator.FindSteamPath();
|
||||
if (text == null)
|
||||
{
|
||||
return Array.Empty<DetectedGame>();
|
||||
}
|
||||
IReadOnlyList<string> libraries = SteamLocator.GetLibraries(text);
|
||||
IEnumerable<SupportedGame> games = SupportedGames.All.Where((SupportedGame g) => g.SteamAppId > 0);
|
||||
return GameDetection.DetectInstalled(libraries, games, File.Exists);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<DetectedGame>();
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<DetectedGame> DetectEpic()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<DetectedGame> list = new List<DetectedGame>();
|
||||
foreach (SupportedGame item in SupportedGames.All.Where((SupportedGame g) => g.EpicAppName != null))
|
||||
{
|
||||
string text = EpicLocator.FindGameInstall(item.EpicAppName);
|
||||
if (text != null)
|
||||
{
|
||||
list.Add(new DetectedGame(item, text));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<DetectedGame>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
internal static class GameLookJoin
|
||||
{
|
||||
private static readonly IReadOnlyDictionary<string, string> Map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["rust"] = "Rust",
|
||||
["cs2"] = "CS2",
|
||||
["fortnite"] = "Fortnite",
|
||||
["valorant"] = "Valorant",
|
||||
["r6"] = "Rainbow Six Siege"
|
||||
};
|
||||
|
||||
internal static IReadOnlyCollection<string> JoinedIds => Map.Keys.ToList();
|
||||
|
||||
internal static string? LookGameFor(string gameId)
|
||||
{
|
||||
if (gameId == null || !Map.TryGetValue(gameId, out string value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
internal static DisplayPreset? StartingLookFor(string gameId)
|
||||
{
|
||||
string text = LookGameFor(gameId);
|
||||
if (text == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ScenePresetSet scenePresetSet = ServedLooks.ForGame(text);
|
||||
if (scenePresetSet.Presets.Count <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return scenePresetSet.Presets[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public sealed class GameSelection
|
||||
{
|
||||
private readonly AppSettings _settings;
|
||||
|
||||
private readonly SettingsStore _store;
|
||||
|
||||
private readonly Func<IReadOnlyList<DetectedGame>> _detect;
|
||||
|
||||
private List<DetectedGame> _installed = new List<DetectedGame>();
|
||||
|
||||
private string? _currentId;
|
||||
|
||||
public IReadOnlyList<DetectedGame> Installed => _installed;
|
||||
|
||||
public string? CurrentId => _currentId;
|
||||
|
||||
public SupportedGame? Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentId != null)
|
||||
{
|
||||
return SupportedGames.All.FirstOrDefault((SupportedGame g) => g.Id == _currentId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public DetectedGame? Detected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentId != null)
|
||||
{
|
||||
return _installed.FirstOrDefault((DetectedGame d) => d.Game.Id == _currentId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool NothingInstalled => _installed.Count == 0;
|
||||
|
||||
public event EventHandler? Changed;
|
||||
|
||||
public GameSelection(AppSettings settings, SettingsStore store, Func<IReadOnlyList<DetectedGame>>? detect = null)
|
||||
{
|
||||
_settings = settings;
|
||||
_store = store;
|
||||
_detect = detect ?? new Func<IReadOnlyList<DetectedGame>>(GameLibrary.DetectInstalled);
|
||||
Refresh();
|
||||
_currentId = Resolve(_settings.CurrentGameId);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
try
|
||||
{
|
||||
_installed = _detect().ToList();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_installed = new List<DetectedGame>();
|
||||
}
|
||||
if (_currentId != null && Resolve(_currentId) == null)
|
||||
{
|
||||
_currentId = null;
|
||||
Persist();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void Select(string? gameId)
|
||||
{
|
||||
string text = Resolve(gameId);
|
||||
if (!(text == _currentId))
|
||||
{
|
||||
_currentId = text;
|
||||
Persist();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private string? Resolve(string? gameId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(gameId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!SupportedGames.All.Any((SupportedGame g) => g.Id == gameId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!_installed.Any((DetectedGame d) => d.Game.Id == gameId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return gameId;
|
||||
}
|
||||
|
||||
private void Persist()
|
||||
{
|
||||
_settings.CurrentGameId = _currentId ?? "";
|
||||
_store.Save(_settings);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
internal static class GameSetupOffer
|
||||
{
|
||||
internal static bool ShouldOffer(string gameId, bool profileExists, IEnumerable<string> declined, string alreadyPending)
|
||||
{
|
||||
if (string.IsNullOrEmpty(gameId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (GameLookJoin.LookGameFor(gameId) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (profileExists)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(alreadyPending))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return !(declined ?? Enumerable.Empty<string>()).Any((string d) => string.Equals(d, gameId, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
internal static string Sentence(string gameId)
|
||||
{
|
||||
string value = GameLookJoin.LookGameFor(gameId) ?? gameId;
|
||||
return $"Playing {value}? PlexusX can use the {value} look every time you launch it.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public static class SteamLocator
|
||||
{
|
||||
public static string? FindSteamPath()
|
||||
{
|
||||
string[] array = new string[3]
|
||||
{
|
||||
Registry.GetValue("HKEY_CURRENT_USER\\Software\\Valve\\Steam", "SteamPath", null) as string,
|
||||
Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Valve\\Steam", "InstallPath", null) as string,
|
||||
Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam", "InstallPath", null) as string
|
||||
};
|
||||
foreach (string text in array)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(text) && Directory.Exists(text))
|
||||
{
|
||||
return Path.GetFullPath(text);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> GetLibraries(string steamPath)
|
||||
{
|
||||
List<string> list = new List<string> { steamPath };
|
||||
string[] array = new string[2] { "steamapps\\libraryfolders.vdf", "config\\libraryfolders.vdf" };
|
||||
foreach (string path in array)
|
||||
{
|
||||
string path2 = Path.Combine(steamPath, path);
|
||||
if (File.Exists(path2))
|
||||
{
|
||||
list.AddRange(SteamVdf.ParseLibraryPaths(File.ReadAllText(path2)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
List<string> list2 = new List<string>();
|
||||
foreach (string item in list)
|
||||
{
|
||||
if (Directory.Exists(item))
|
||||
{
|
||||
string fullPath = Path.GetFullPath(item);
|
||||
if (hashSet.Add(fullPath))
|
||||
{
|
||||
list2.Add(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public static class SteamVdf
|
||||
{
|
||||
private static readonly Regex KeyValue = new Regex("^\\s*\"([^\"]+)\"\\s+\"(.+?)\"\\s*$", RegexOptions.Compiled);
|
||||
|
||||
public static IReadOnlyList<string> ParseLibraryPaths(string vdfContent)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
if (string.IsNullOrEmpty(vdfContent))
|
||||
{
|
||||
return list;
|
||||
}
|
||||
HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
string[] array = vdfContent.Split('\n');
|
||||
foreach (string input in array)
|
||||
{
|
||||
Match match = KeyValue.Match(input);
|
||||
if (!match.Success)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string value = match.Groups[1].Value;
|
||||
string value2 = match.Groups[2].Value;
|
||||
if ((value.Equals("path", StringComparison.OrdinalIgnoreCase) || IsAllDigits(value)) && (value2.Contains('\\') || value2.Contains('/')))
|
||||
{
|
||||
string item = value2.Replace("\\\\", "\\").Trim();
|
||||
if (hashSet.Add(item))
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static bool IsAllDigits(string s)
|
||||
{
|
||||
if (s.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
if (!char.IsDigit(s[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public sealed record SupportedGame(string Id, string DisplayName, int SteamAppId, string InstallFolder, string ProcessName, string? EpicAppName = null, IReadOnlyList<string>? AlsoProcessNames = null)
|
||||
{
|
||||
public IReadOnlyList<string> AllProcessNames
|
||||
{
|
||||
get
|
||||
{
|
||||
if (AlsoProcessNames == null || AlsoProcessNames.Count == 0)
|
||||
{
|
||||
return new string[1] { ProcessName };
|
||||
}
|
||||
return new string[1] { ProcessName }.Concat(AlsoProcessNames).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Games;
|
||||
|
||||
public static class SupportedGames
|
||||
{
|
||||
public static readonly SupportedGame Rust = new SupportedGame("rust", "Rust", 252490, "Rust", "RustClient");
|
||||
|
||||
public static readonly SupportedGame Cs2 = new SupportedGame("cs2", "Counter-Strike 2", 730, "Counter-Strike Global Offensive", "cs2");
|
||||
|
||||
public static readonly SupportedGame Apex = new SupportedGame("apex", "Apex Legends", 1172470, "Apex Legends", "r5apex", null, new string[1] { "r5apex_dx12" });
|
||||
|
||||
public static readonly SupportedGame Fortnite = new SupportedGame("fortnite", "Fortnite", 0, "Fortnite", "FortniteClient-Win64-Shipping", "Fortnite");
|
||||
|
||||
public static readonly SupportedGame Valorant = new SupportedGame("valorant", "VALORANT", 0, "VALORANT", "VALORANT-Win64-Shipping");
|
||||
|
||||
public static readonly SupportedGame Siege = new SupportedGame("r6", "Rainbow Six Siege", 359550, "Tom Clancy's Rainbow Six Siege", "RainbowSix", null, new string[2] { "RainbowSix_Vulkan", "RainbowSix_BE" });
|
||||
|
||||
public static readonly IReadOnlyList<SupportedGame> All = new SupportedGame[6] { Rust, Cs2, Apex, Fortnite, Valorant, Siege };
|
||||
|
||||
public static IReadOnlyDictionary<string, string> ProcessNames => All.ToDictionary((SupportedGame g) => g.Id, (SupportedGame g) => g.ProcessName, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static IEnumerable<string> AllProcessNames => All.SelectMany((SupportedGame g) => g.AllProcessNames);
|
||||
|
||||
public static SupportedGame? ById(string? id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
return All.FirstOrDefault((SupportedGame g) => g.Id == id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SupportedGame? CurrentlyRunning()
|
||||
{
|
||||
return All.FirstOrDefault((SupportedGame g) => g.AllProcessNames.Any((string n) => Process.GetProcessesByName(n).Length != 0));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user