Skip to content

Commit

Permalink
Automatically install the cfg file
Browse files Browse the repository at this point in the history
  • Loading branch information
Retr0-01 committed May 21, 2022
1 parent d1daebf commit 5900620
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
8 changes: 8 additions & 0 deletions GlobalSuppressions.cs
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" )]
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A Rich Presence application for showing custom status of your active Counter-Str
- [CS:GO Discord Rich Presence](#csgo-discord-rich-presence)
- [How It Works](#how-it-works)
- [Install](#install)
- [Troubleshooting](#troubleshooting)
- [Credits](#credits)
- [Licensing](#licensing)

Expand All @@ -14,10 +15,12 @@ This application uses the [Counter-Strike: Global Offensive Game State Integrati

## Install
Go to the [latest release](https://github.com/Retr0-01/CSGO-Discord-RP/releases/latest), download the ``CSGO-Discord-RP.zip`` file from the Assets section and then extract it to the location of your choosing. Now you should have the exe and a file called ``gamestate_integration_discord-rp.cfg``.
Cut the cfg file and paste it inside the "cfg" folder of your CS:GO installation.
For example ``C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg`` is where I will have to put it.
Once you have done that just run the exe file and you should be good to go!
All you have to do now is run the exe and you should be good to go!

## Troubleshooting
**[SETUP] CS:GO installation path not found! Aborting...**
> If for whatever reason the application couldn't find your game installation path or write the config file needed, you need to manually copy the ``gamestate_integration_discord-rp.cfg`` file and paste it *inside* the ``cfg`` folder of your CS:GO installation.
> Example path: `C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg`
## Credits
Huge thanks to the following devs/teams for creating some of the packages/tools used.
- [Newtonsoft](https://www.newtonsoft.com/json) for Json.NET
Expand Down
97 changes: 97 additions & 0 deletions src/Classes/ApplicationSetup.cs
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;
}
}
1 change: 1 addition & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void Main( string[] args )
Console.WriteLine( "Source Code: https://github.com/Retr0-01/CSGO-Discord-RP" );
Console.WriteLine();

ApplicationSetup.Configure();
DiscordManager.Initialize();
HttpServer.Start();
}
Expand Down

0 comments on commit 5900620

Please sign in to comment.