GSI Config-File Installer

This commit is contained in:
glax 2024-01-15 19:30:22 +01:00
parent 8d2e64b7be
commit 5d05ccb329
6 changed files with 212 additions and 5 deletions

View File

@ -6,4 +6,19 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@ -1,5 +0,0 @@
namespace CS2GSI;
public class Class1
{
}

57
GSIConfigInstaller.cs Normal file
View File

@ -0,0 +1,57 @@
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Microsoft.Win32;
namespace CS2GSI;
public class GsiConfigInstaller
{
internal static void InstallGsi()
{
string installLocation = Path.Combine(GetInstallDirectory(), "game\\csgo\\cfg\\gamestate_integration_cs2gsi.cfg");
File.WriteAllText(installLocation, Resources.GSI_CFG_Content);
}
private static string GetInstallDirectory(int appId = 730)
{
string libraryFolderFilepath = GetLibraryFoldersFilePath();
string? libraryPath = null;
string? appManifestFolderPath = null;
foreach (string line in File.ReadAllLines(libraryFolderFilepath))
if (line.Contains("path"))
libraryPath = line.Split("\"").Last(split => split.Length > 0);
else if (line.Contains($"\"{appId}\""))
appManifestFolderPath = Path.Combine(libraryPath!, $"steamapps\\appmanifest_{appId}.acf");
string installationPath = "";
if (appManifestFolderPath is null)
throw new DirectoryNotFoundException($"No {appId} Installation found.");
foreach(string line in File.ReadAllLines(appManifestFolderPath))
if (line.Contains("installdir"))
installationPath = Path.Combine(libraryPath!, "steamapps\\common", line.Split("\"").Last(split => split.Length > 0));
return installationPath;
}
private static string GetLibraryFoldersFilePath()
{
string? path = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
path = GetLibraryFoldersFilePathWindows();
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
path = "~/.local/share/Steam/steamapps/libraryfolders.vdf";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = "~/Library/Application Support/Steam/steamapps/libraryfolders.vdf";
else throw new Exception("Could not get Installation FolderPath");
return path ?? throw new FileNotFoundException("No libraryfolders.vdf found");
}
[SupportedOSPlatform("windows")]
private static string GetLibraryFoldersFilePathWindows()
{
string steamInstallation =
(string)(Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam", "SteamPath", null) ??
throw new DirectoryNotFoundException("No Steam Installation found."));
return Path.Combine(steamInstallation, "steamapps\\libraryfolders.vdf");
}
}

93
Resources.Designer.cs generated Normal file
View File

@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CS2GSI {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CS2GSI.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to &quot;CS2GSI&quot;
///{
/// &quot;uri&quot; &quot;http://127.0.0.1:3000&quot;
/// &quot;timeout&quot; &quot;2.0&quot;
/// &quot;buffer&quot; &quot;0.0&quot;
/// &quot;throttle&quot; &quot;0.1&quot;
/// &quot;heartbeat&quot; &quot;60.0&quot;
/// &quot;output&quot;
/// {
/// &quot;precision_time&quot; &quot;3&quot;
/// &quot;precision_position&quot; &quot;1&quot;
/// &quot;precision_vector&quot; &quot;3&quot;
/// }
/// &quot;data&quot;
/// {
/// &quot;provider&quot; &quot;1&quot;
/// &quot;map&quot; &quot;1&quot;
/// &quot;round&quot; &quot;1&quot;
/// &quot;player_id&quot; &quot;1&quot;
/// &quot;player_state&quot; &quot;1&quot;
/// &quot;player_match_stats&quot; &quot;1&quot;
/// }
///}.
/// </summary>
internal static string GSI_CFG_Content {
get {
return ResourceManager.GetString("GSI_CFG_Content", resourceCulture);
}
}
}
}

24
Resources.resx Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="GSI_CFG_Content" type="System.Resources.ResXFileRef">
<value>gamestate_integration_cs2gsi.cfg;System.String, mscorlib, Version=4.0.0.0, Culture=neutral</value>
</data>
</root>

View File

@ -0,0 +1,23 @@
"CS2GSI"
{
"uri" "http://127.0.0.1:3000"
"timeout" "2.0"
"buffer" "0.0"
"throttle" "0.1"
"heartbeat" "60.0"
"output"
{
"precision_time" "3"
"precision_position" "1"
"precision_vector" "3"
}
"data"
{
"provider" "1"
"map" "1"
"round" "1"
"player_id" "1"
"player_state" "1"
"player_match_stats" "1"
}
}