-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support installation of game state integration configuration from
- Loading branch information
Showing
11 changed files
with
221 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ | |
} | ||
], | ||
"source": "dagger", | ||
"engineVersion": "v0.13.3" | ||
"engineVersion": "v0.13.5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"Dota 2 Integration Configuration" | ||
{ | ||
"uri" "http://localhost:4001/" | ||
"timeout" "5.0" | ||
"buffer" "0.1" | ||
"throttle" "0.1" | ||
"heartbeat" "1.0" | ||
"data" | ||
{ | ||
"provider" "0" | ||
"map" "1" | ||
"player" "0" | ||
"hero" "0" | ||
"abilities" "0" | ||
"items" "0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Win32; | ||
|
||
namespace Dota2Helper.Core.Gsi; | ||
|
||
public partial class SteamLibraryService(ILogger<SteamLibraryService> logger) | ||
{ | ||
const string ConfigFile = "gamestate_integration_timers.cfg"; | ||
|
||
string? FindGameStateIntegrationPath() | ||
{ | ||
var dota2FolderPath = FindDota2InstallationPath(); | ||
|
||
if (dota2FolderPath == null) return null; | ||
|
||
var gameStateIntegrationPath = Path.Combine(dota2FolderPath, "game", "dota", "cfg", "gamestate_integration"); | ||
return Directory.Exists(gameStateIntegrationPath) ? gameStateIntegrationPath : null; | ||
} | ||
|
||
public bool IsIntegrationInstalled() | ||
{ | ||
var gameStateIntegrationPath = FindGameStateIntegrationPath(); | ||
|
||
if (gameStateIntegrationPath == null) return false; | ||
|
||
var configFileFullPath = Path.Combine(gameStateIntegrationPath, ConfigFile); | ||
return File.Exists(configFileFullPath); | ||
} | ||
|
||
string? FindDota2InstallationPath() | ||
{ | ||
var libraryFoldersPath = GetLibraryFoldersPath(); | ||
|
||
if (string.IsNullOrEmpty(libraryFoldersPath) || !File.Exists(libraryFoldersPath)) | ||
{ | ||
logger.LogError("libraryfolders.vdf not found"); | ||
return null; | ||
} | ||
|
||
var steamInstallPath = GetSteamInstallationPath(); | ||
|
||
if (string.IsNullOrEmpty(steamInstallPath)) | ||
{ | ||
logger.LogError("Steam installation path not found"); | ||
return null; | ||
} | ||
|
||
var steamLibraryPaths = GetSteamLibraryPaths(libraryFoldersPath); | ||
|
||
foreach (var steamLibraryPath in steamLibraryPaths) | ||
{ | ||
var dota2FolderPath = Path.Combine(steamLibraryPath, "steamapps", "common", "dota 2 beta"); | ||
|
||
if (Directory.Exists(dota2FolderPath)) return dota2FolderPath; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
string? GetSteamInstallationPath() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? GetWindowsInstall() : | ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? GetMacInstall() : null; | ||
|
||
string? GetLibraryFoldersPath() | ||
{ | ||
var steamInstallPath = GetSteamInstallationPath(); | ||
return steamInstallPath == null ? null : Path.Combine(steamInstallPath, "steamapps", "libraryfolders.vdf"); | ||
} | ||
|
||
[SupportedOSPlatform("windows")] | ||
string? GetWindowsInstall() | ||
{ | ||
const string steamRegistryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam"; | ||
const string steamRegistryValue = "InstallPath"; | ||
|
||
try | ||
{ | ||
var installPath = Registry.GetValue(steamRegistryKey, steamRegistryValue, null); | ||
|
||
if (installPath != null) return installPath.ToString(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(ex, "Failed to read Steam installation path from registry"); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
[SupportedOSPlatform("macos")] | ||
string? GetMacInstall() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "Steam"); | ||
|
||
string[] GetSteamLibraryPaths(string libraryFoldersVdfPath) | ||
{ | ||
var pathRegex = LibraryLocations(); | ||
var fileContent = File.ReadAllText(libraryFoldersVdfPath); | ||
var matches = pathRegex.Matches(fileContent); | ||
var libraryPaths = matches.Select(m => m.Groups[1].Value.Replace("\\\\", "\\")).ToList(); | ||
return libraryPaths.Where(Directory.Exists).ToArray(); | ||
} | ||
|
||
public void InstallIntegration() | ||
{ | ||
var gameStateIntegrationPath = FindGameStateIntegrationPath(); | ||
|
||
if (gameStateIntegrationPath == null) | ||
{ | ||
logger.LogError("gamestate_integration folder not found"); | ||
return; | ||
} | ||
|
||
var configFileFullPath = Path.Combine(gameStateIntegrationPath, ConfigFile); | ||
var configFileSourcePath = Path.Combine(Directory.GetCurrentDirectory(), ConfigFile); | ||
|
||
if (File.Exists(configFileFullPath)) File.Delete(configFileFullPath); | ||
|
||
File.Copy(configFileSourcePath, configFileFullPath); | ||
} | ||
|
||
[GeneratedRegex(@"\s*\""path\""\s*\""(.+?)\""", RegexOptions.Compiled)] | ||
private static partial Regex LibraryLocations(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.