CSGSI 1.2.2
See the version list below for details.
dotnet add package CSGSI --version 1.2.2
NuGet\Install-Package CSGSI -Version 1.2.2
<PackageReference Include="CSGSI" Version="1.2.2" />
paket add CSGSI --version 1.2.2
#r "nuget: CSGSI, 1.2.2"
// Install CSGSI as a Cake Addin #addin nuget:?package=CSGSI&version=1.2.2 // Install CSGSI as a Cake Tool #tool nuget:?package=CSGSI&version=1.2.2
CSGSI
A simple C# library to interface with Counter-Strike: Global Offensive Game State Integration
Table of Contents
What is Game State Integration
About CSGSI
Installation
Usage
Events
Null value handling
Example program
<br>
What is Game State Integration
This wiki page by Valve explains the concept of GSI.
About CSGSI
This library provides means to listen to a specific port for the game clients HTTP POST request. Once a request is received, the game state is parsed and can then be analyzed.
CSGSI uses Newtonsoft's JSON.Net Framework to parse JSON.
Once a GameStateListener
instance is running, it continuously listens for incoming HTTP requests.
Every time a request is received, it's JSON content is used to construct a new GameState
object.
The GameState
class represents the entire game state as it was sent by the client.
It also provides access to all rootnodes (see Usage).
Installation
Via NuGet:
Install-Package CSGSI
Manual installation:
- Get the latest binaries
- Get the JSON Framework .dll by Newtonsoft
- Extract Newtonsoft.Json.dll from
Bin\Net45\Newtonsoft.Json.dll
- Add a reference to both CSGSI.dll and Newtonsoft.Json.dll in your project
Hint: The NuGet package will always be up to date with the latest commit, but I will only publish a new binary release every major update.
Usage
- Create a
GameStateListener
instance by providing a port or passing a specific URI:
GameStateListener gsl = new GameStateListener(3000); //http://localhost:3000/
GameStateListener gsl = new GameStateListener("http://127.0.0.1:81/");
Please note: If your application needs to listen to a URI other than http://localhost:*/
(for example http://192.168.2.2:100/
), you need to ensure that it is run with administrator privileges.
In this case, http://127.0.0.1:*/
is not equivalent to http://localhost:*/
.
- Create a handler:
void OnNewGameState(GameState gs)
{
//do stuff
}
- Subscribe to the
NewGameState
event:
gsl.NewGameState += new NewGameStateHandler(OnNewGameState);
- Use
GameStateListener.Start()
to start listening for HTTP POST requests from the game client. This method will returnfalse
if starting the listener fails (most likely due to insufficient privileges).
Examples:
int Health = gs.Player.State.Health;
//100
string activeWep = gs.Player.Weapons.ActiveWeapon.JSON
//{
// "name": "weapon_knife",
// "paintkit": ...
// ...
//}
Events
CSGSI provides a few helpful events that you can subscribe to avoid having to implement the logic yourself. These events are experimental and not entirely reliable (mostly because CSGO's Game State Integration itself sends inconsistent data).
Raising these events is disabled by default. To enable this feature, set GameStateListener.EnableRaisingIntricateEvents = true
.
Available events:
PlayerGotKill
- Is raised when a player gets a kill.RoundPhaseChanged
- Is raised when the round phase changes (for example "Live", "FreezeTime" etc.).PlayerFlashed
- Is raised when a player is flashed. Includes information about how much the player was flashed (0 - 255).BombPlanted
- Is raised when the bomb is planted.BombDefused
- Is raised when the bomb is defused.BombExploded
- Is raised when the bomb explodes.RoundEnd
- Is raised when the round ends.RoundBegin
- Is raised when a round begins (i.e. exits FreezeTime).
Null value handling
In case the JSON did not contain the requested information or parsing the node failed, these values will be returned instead:
Type | Default value |
---|---|
int | -1 |
string | String.Empty |
Position (from Player.Position) | (X: 0, Y: 0, Z: 0) |
All Enums have a value enum.Undefined
that serves the same purpose.
Example program
Prints "Bomb has been planted", every time you plant the bomb:
using System;
using CSGSI;
using CSGSI.Nodes;
namespace CSGSI_Test
{
class Program
{
static GameStateListener gsl;
static void Main(string[] args)
{
gsl = new GameStateListener(3000);
gsl.NewGameState += new NewGameStateHandler(OnNewGameState);
if (!gsl.Start())
{
Environment.Exit(0);
}
Console.WriteLine("Listening...");
}
static bool IsPlanted = false;
static void OnNewGameState(GameState gs)
{
if(!IsPlanted &&
gs.Round.Phase == RoundPhase.Live &&
gs.Round.Bomb == BombState.Planted &&
gs.Previously.Round.Bomb == BombState.Undefined)
{
Console.WriteLine("Bomb has been planted.");
IsPlanted = true;
}else if(IsPlanted && gs.Round.Phase == RoundPhase.FreezeTime)
{
IsPlanted = false;
}
}
}
}
You will also need to create a custom gamestate_integration_*.cfg
in /csgo/cfg
, for example:
gamestate_integration_test.cfg
:
"CSGSI Example"
{
"uri" "http://localhost:3000"
"timeout" "5.0"
"auth"
{
"token" "CSGSI Test"
}
"data"
{
"provider" "1"
"map" "1"
"round" "1"
"player_id" "1"
"player_weapons" "1"
"player_match_stats" "1"
"player_state" "1"
"allplayers_id" "1"
"allplayers_state" "1"
"allplayers_match_stats" "1"
}
}
Please note: In order to run this test application without explicit administrator privileges, you need to use the URI http://localhost:<port>
in this configuration file.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- Newtonsoft.Json (>= 11.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.1 | 15,905 | 2/15/2019 |
1.3.0 | 1,363 | 12/11/2018 |
1.2.2 | 1,660 | 3/1/2018 |
1.2.1 | 1,600 | 11/20/2017 |
1.2.0 | 1,633 | 8/11/2017 |
1.1.8 | 1,605 | 5/20/2017 |
1.1.7 | 1,922 | 8/15/2016 |
1.1.6 | 2,083 | 2/22/2016 |
1.1.5 | 1,843 | 2/5/2016 |
1.1.4 | 1,852 | 2/2/2016 |
1.1.3 | 2,082 | 1/13/2016 |
1.1.2 | 1,859 | 12/19/2015 |
1.1.1 | 1,792 | 12/18/2015 |
1.1.0 | 1,868 | 12/17/2015 |