-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is used by Code Analysis to maintain SuppressMessage | ||
// attributes that are applied to this project. | ||
// Project-level suppressions either have no target or are given | ||
// a specific target and scoped to a namespace, type, member, etc. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: SuppressMessage( "Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:CSGODiscordRP.ApplicationSetup.GetCSGODir~System.String" )] |
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,97 @@ | ||
using Microsoft.Win32; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace CSGODiscordRP; | ||
|
||
public static class ApplicationSetup | ||
{ | ||
public static readonly string configFileName = "gamestate_integration_discord-rp.cfg"; | ||
|
||
public static void Configure() | ||
{ | ||
string gamePath = GetCSGODir(); | ||
if ( gamePath == null ) | ||
Console.WriteLine( "[SETUP] CS:GO installation path not found! Aborting..." ); | ||
else | ||
{ | ||
Console.WriteLine( $"[SETUP] Found CS:GO installation path...\n|--- {gamePath}" ); | ||
|
||
string configFile = Path.Combine( gamePath, "cfg", configFileName ); | ||
// Delete the file if it already exists and make a clean one. | ||
if ( File.Exists( configFile ) ) | ||
{ | ||
File.Delete( configFile ); | ||
Console.WriteLine( "[SETUP] Deleted existing config file." ); | ||
} | ||
|
||
Console.WriteLine( $"[SETUP] Writing \"{configFileName}\" config file..." ); | ||
using ( StreamWriter sw = File.CreateText( configFile ) ) | ||
{ | ||
sw.WriteLine( "\"CSGO-Discord-RP\"" ); | ||
sw.WriteLine( "{" ); | ||
sw.WriteLine( " \"uri\" \"http://localhost:3000\"" ); | ||
sw.WriteLine( " \"timeout\" \"5.0\"" ); | ||
sw.WriteLine( " \"buffer\" \"1\"" ); | ||
sw.WriteLine( " \"throttle\" \"5\"" ); | ||
sw.WriteLine( " \"heartbeat\" \"15\"" ); | ||
sw.WriteLine( " \"data\"" ); | ||
sw.WriteLine( " {" ); | ||
sw.WriteLine( " \"provider\" \"1\"" ); | ||
sw.WriteLine( " \"map\" \"1\"" ); | ||
sw.WriteLine( " \"round\" \"1\"" ); | ||
sw.WriteLine( " \"player_id\" \"1\"" ); | ||
sw.WriteLine( " \"player_match_stats\" \"1\"" ); | ||
sw.WriteLine( " \"player_state\" \"1\"" ); | ||
sw.WriteLine( " }" ); | ||
sw.WriteLine( "}" ); | ||
} | ||
Console.WriteLine( "[SETUP] Done!" ); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns the location of the CS:GO installation, or null if it's unable to find it. | ||
/// </summary> | ||
/// <returns></returns> | ||
private static string GetCSGODir() | ||
{ | ||
// Credit to moritzuehling for this code snippet | ||
// https://gist.github.com/moritzuehling/7f1c512871e193c0222f | ||
|
||
string steamPath = (string)Registry.GetValue( "HKEY_CURRENT_USER\\Software\\Valve\\Steam", "SteamPath", "" ); | ||
string pathsFile = Path.Combine( steamPath, "steamapps", "libraryfolders.vdf" ); | ||
|
||
if ( !File.Exists( pathsFile ) ) | ||
return null; | ||
|
||
List<string> libraries = new() | ||
{ | ||
Path.Combine( steamPath ) | ||
}; | ||
|
||
var pathVDF = File.ReadAllLines( pathsFile ); | ||
|
||
Regex pathRegex = new( @"\""(([^\""]*):\\([^\""]*))\""" ); | ||
foreach ( var line in pathVDF ) | ||
{ | ||
if ( pathRegex.IsMatch( line ) ) | ||
{ | ||
string match = pathRegex.Matches( line )[0].Groups[1].Value; | ||
|
||
// De-Escape vdf. | ||
libraries.Add( match.Replace( "\\\\", "\\" ) ); | ||
} | ||
} | ||
|
||
foreach ( var library in libraries ) | ||
{ | ||
string csgoPath = Path.Combine( library, "steamapps\\common\\Counter-Strike Global Offensive\\csgo" ); | ||
if ( Directory.Exists( csgoPath ) ) | ||
{ | ||
return csgoPath; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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