Skip to content

Commit

Permalink
Merge pull request #2 from Retr0-01/cs2-update
Browse files Browse the repository at this point in the history
CS2 Update
  • Loading branch information
Retr0-01 authored Oct 5, 2023
2 parents f079e16 + f90881b commit d040c3b
Show file tree
Hide file tree
Showing 33 changed files with 212 additions and 83 deletions.
Binary file added .github/images/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/discord_showcase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Retr0-01
Copyright (c) 2023 Giannis "Retr0" Kepas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
# CS:GO Discord Rich Presence
<p align="center">
<img src="./.github/images/banner.png" title="SRCDS Discord Bot">
</p>

# CS2 Discord Rich Presence
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/Retr0-01/CSGO-Discord-RP?sort=semver)
![GitHub release (latest by SemVer)](https://img.shields.io/github/downloads/Retr0-01/CSGO-Discord-RP/latest/total?sort=semver)
A Rich Presence application for showing custom status of your active Counter-Strike:Global Offensive game.

- [CS:GO Discord Rich Presence](#csgo-discord-rich-presence)
- [CS2 Discord Rich Presence](#cs2-discord-rich-presence)
- [How It Works](#how-it-works)
- [Showcase](#showcase)
- [Install](#install)
- [Troubleshooting](#troubleshooting)
- [Credits](#credits)
- [Licensing](#licensing)

## How It Works
This application uses the [Counter-Strike: Global Offensive Game State Integration](https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Game_State_Integration) to fetch the data of your active game. It creates a local server (port 3000) which listens for the data and then applies it to your Discord client.
This application uses the [Counter-Strike Game State Integration](https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Game_State_Integration) to fetch the data of your active game. It creates a local server (port 3000) which listens for the data and then applies it to your Discord client.

## Showcase
<p align="center">
<img src="./.github/images/discord_showcase.png" title="SRCDS Discord Bot">
</p>

## 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``.
Go to the [latest release](https://github.com/Retr0-01/CSGO-Discord-RP/releases/latest), download the ``CS2-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``.
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`
**[SETUP] CS2 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 CS2 installation.
> Example path: `C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\game\csgo\cfg`
>
## Credits
Huge thanks to the following devs/teams for creating some of the packages/tools used.
Expand Down
Binary file added assets/casual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/competitive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cs_italy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cs_office.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ct_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_ancient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_anubis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_dust2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_inferno.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_mirage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_nuke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_overpass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/de_vertigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/deathmatch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/invite_cover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/overwatch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/scrimcomp2v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/t_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions src/CS2-Discord-RP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>True</UseWindowsForms>
<RootNamespace>RichPresenceApp</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>annotations</Nullable>
<IsPublishable>True</IsPublishable>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<DebugType>none</DebugType>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<StartupObject>RichPresenceApp.Program</StartupObject>
<IncludeAllContentForSelfExtract>True</IncludeAllContentForSelfExtract>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />

<ItemGroup>
<None Remove=".gitattributes" />
<None Remove=".gitignore" />
<None Remove="CODE_OF_CONDUCT.md" />
<None Remove="favicon.ico" />
<None Remove="gamestate_integration_discord-rp.cfg" />
<None Remove="LICENSE.md" />
<None Remove="README.md" />
</ItemGroup>

<ItemGroup>
<Content Include="favicon.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/CSGO-Discord-RP.sln → src/CS2-Discord-RP.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSGO-Discord-RP", "CSGO-Discord-RP.csproj", "{3A8BB5BD-AD13-4221-A708-6F3611C232AA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CS2-Discord-RP", "CS2-Discord-RP.csproj", "{62F59BDD-E612-4524-A6FA-0CB6EB4D3972}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3A8BB5BD-AD13-4221-A708-6F3611C232AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A8BB5BD-AD13-4221-A708-6F3611C232AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A8BB5BD-AD13-4221-A708-6F3611C232AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A8BB5BD-AD13-4221-A708-6F3611C232AA}.Release|Any CPU.Build.0 = Release|Any CPU
{62F59BDD-E612-4524-A6FA-0CB6EB4D3972}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62F59BDD-E612-4524-A6FA-0CB6EB4D3972}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62F59BDD-E612-4524-A6FA-0CB6EB4D3972}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62F59BDD-E612-4524-A6FA-0CB6EB4D3972}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 0 additions & 39 deletions src/CSGO-Discord-RP.csproj

This file was deleted.

24 changes: 12 additions & 12 deletions src/Classes/ApplicationSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@

namespace RichPresenceApp;

public static class ApplicationSetup
public class ApplicationSetup
{
public static readonly string configFileName = "gamestate_integration_discord-rp.cfg";
private const string configFileName = "gamestate_integration_discord-rp.cfg";

public static void Configure()
{
string gamePath = GetCSGODir();
string gamePath = GetGameDir();
if ( gamePath == null )
Console.WriteLine( "[SETUP] CS:GO installation path not found! Aborting..." );
Console.WriteLine( "[SETUP] CS2 installation path not found! Aborting..." );
else
{
Console.WriteLine( $"[SETUP] Found CS:GO installation path...\n|--- {gamePath}" );
Console.WriteLine( $"[SETUP] Found CS2 installation path...\n|--- {gamePath}" );

string configFile = Path.Combine( gamePath, "cfg", configFileName );
string configFile = Path.Combine( gamePath, "game", "csgo", "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..." );
Console.WriteLine( $"[SETUP] Writing \"{configFileName}\" config file...\n|--- {configFile}" );
using ( StreamWriter sw = File.CreateText( configFile ) )
{
sw.WriteLine( "\"CSGO-Discord-RP\"" );
sw.WriteLine( "\"CS2-Discord-RP\"" );
sw.WriteLine( "{" );
sw.WriteLine( " \"uri\" \"http://localhost:3000\"" );
sw.WriteLine( " \"timeout\" \"5.0\"" );
Expand All @@ -53,7 +53,7 @@ public static void Configure()
/// Returns the location of the CS:GO installation, or null if it's unable to find it.
/// </summary>
/// <returns></returns>
private static string GetCSGODir()
private static string GetGameDir()
{
// Credit to moritzuehling for this code snippet
// https://gist.github.com/moritzuehling/7f1c512871e193c0222f
Expand Down Expand Up @@ -85,10 +85,10 @@ private static string GetCSGODir()

foreach ( var library in libraries )
{
string csgoPath = Path.Combine( library, "steamapps\\common\\Counter-Strike Global Offensive\\csgo" );
if ( Directory.Exists( csgoPath ) )
string csGamePath = Path.Combine( library, "steamapps\\common\\Counter-Strike Global Offensive" );
if ( Directory.Exists( csGamePath ) )
{
return csgoPath;
return csGamePath;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Classes/DiscordManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RichPresenceApp;

public static class DiscordManager
public class DiscordManager
{
public static DiscordRpcClient Client;

Expand All @@ -19,12 +19,12 @@ public static void Initialize()
// Subscribe to events.
Client.OnReady += ( sender, args ) =>
{
Console.WriteLine( "[DISCORD] - Received 'ready' from user {0}", args.User.Username );
Console.WriteLine( "[DISCORD] Received 'ready' from user {0}", args.User.Username );
};

Client.OnPresenceUpdate += ( sender, args ) =>
{
Console.WriteLine( "[DISCORD] - Presence updated!" );
Console.WriteLine( "[DISCORD] Presence updated!" );
};

// Connect to the RPC.
Expand Down
12 changes: 8 additions & 4 deletions src/Classes/GameState.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Globalization;
//
// Originally auto-generated from https://app.quicktype.io/
//

namespace GameState;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Globalization;

public partial class TopLevel
{
[JsonProperty( "provider" )]
Expand Down Expand Up @@ -178,7 +182,7 @@ public static class Serialize

internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
public static readonly JsonSerializerSettings Settings = new()
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Expand Down
17 changes: 12 additions & 5 deletions src/Classes/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace RichPresenceApp;

public class HttpServer
{
public static HttpListener Listener = new();
public static readonly string Url = "http://localhost:3000/";
public static readonly HttpListener Listener = new();
private const string Url = "http://localhost:3000/";

public static void Start()
{
Listener.Prefixes.Add( Url );
Listener.Start();
Console.WriteLine( $"[SERVER] - Listening for data on {Url}" );
Console.WriteLine( $"[SERVER] Listening for data on {Url}" );

// Handle requests.
Task ListenTask = HandleRequests();
Expand All @@ -23,7 +23,7 @@ public static void Start()
Listener.Close();
}

public static async Task HandleRequests()
private static async Task HandleRequests()
{
bool IsRunning = true;

Expand All @@ -50,7 +50,7 @@ public static async Task HandleRequests()

if ( Request.HttpMethod == "POST" )
{
Console.WriteLine( "[SERVER] - Incoming data..." );
Console.WriteLine( "[SERVER] Incoming data..." );
using ( var Reader = new StreamReader( Request.InputStream, Request.ContentEncoding ) )
{
RawData = Reader.ReadToEnd();
Expand All @@ -68,6 +68,13 @@ public static async Task HandleRequests()
// Write out the data. We need to do this regardless if it's used or not.
await Response.OutputStream.WriteAsync( Data );

// In case we failed to parse our data for whatever reason, close early.
if ( topLevel == null )
{
Response.Close();
return;
}

// Let's start building our rich presence.
// First check if we are really playing.
if ( topLevel.Player.Activity == "playing" )
Expand Down
58 changes: 58 additions & 0 deletions src/Classes/SystemTray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace RichPresenceApp;

public class SystemTray
{
public static NotifyIcon NotifyIcon;
static ContextMenuStrip ContextMenu;

public static void Setup()
{
Thread trayThread = new( delegate ()
{
Icon csIcon = Icon.ExtractAssociatedIcon( Application.ExecutablePath );
NotifyIcon = new();
NotifyIcon.Icon = csIcon;
NotifyIcon.Text = "CS2 Discord Rich Presence";

ContextMenu = new();
ToolStripMenuItem statusMenuItem = new( "Status: Active", SystemIcons.Information.ToBitmap(), Click_Handler );
statusMenuItem.Enabled = false;
ToolStripMenuItem openConsoleMenuItem = new( "Open Console", csIcon.ToBitmap(), Click_Handler );
ToolStripMenuItem exitMenuItem = new( "Quit App", SystemIcons.Hand.ToBitmap(), Click_Handler );
ContextMenu.Items.AddRange( new ToolStripItem[] { statusMenuItem, openConsoleMenuItem, exitMenuItem } );
NotifyIcon.ContextMenuStrip = ContextMenu;

NotifyIcon.BalloonTipIcon = ToolTipIcon.Info;
NotifyIcon.BalloonTipTitle = "No Distractions ;)";
NotifyIcon.BalloonTipText = "The CS2 Discord Rich Presence application will run in the background.";

NotifyIcon.Visible = true;
NotifyIcon.ShowBalloonTip( 10000 );

Application.Run();
} );

trayThread.Name = "System Tray Thread";
trayThread.IsBackground = true;
trayThread.SetApartmentState( ApartmentState.STA );
trayThread.Start();
}

private static void Click_Handler( object sender, EventArgs e )
{
ToolStripItem item = (ToolStripItem)sender;

if ( item.Text == "Open Console" )
{
ConsoleManager.SetConsoleWindowVisibility( true );
item.Text = "Close Console";
}
else if ( item.Text == "Close Console" )
{
ConsoleManager.SetConsoleWindowVisibility( false );
item.Text = "Open Console";
}
else if ( item.Text == "Quit App" )
Environment.Exit( Environment.ExitCode );
}
}
Loading

0 comments on commit d040c3b

Please sign in to comment.