CounterStrike2GSI 1.0.4.2659
dotnet add package CounterStrike2GSI --version 1.0.4.2659
NuGet\Install-Package CounterStrike2GSI -Version 1.0.4.2659
<PackageReference Include="CounterStrike2GSI" Version="1.0.4.2659" />
<PackageVersion Include="CounterStrike2GSI" Version="1.0.4.2659" />
<PackageReference Include="CounterStrike2GSI" />
paket add CounterStrike2GSI --version 1.0.4.2659
#r "nuget: CounterStrike2GSI, 1.0.4.2659"
#:package CounterStrike2GSI@1.0.4.2659
#addin nuget:?package=CounterStrike2GSI&version=1.0.4.2659
#tool nuget:?package=CounterStrike2GSI&version=1.0.4.2659
Counter-Strike 2 GSI (Game State Integration)
A C# library to interface with the Game State Integration found in Counter-Strike 2.
About Counter-Strike 2 GSI
This library provides an easy way to implement Game State Integration from Counter-Strike 2 into C# applications through exposing a number of events.
Underneath the hood, once the library is started, it continuously listens for HTTP POST requests made by the game on a specific address and port. When a request is received, the JSON data is parsed into GameState object and is offered to your C# application through the NewGameState event. The library also subscribes to NewGameState to determine more granular changes to raise more specific events (such as BombStateUpdated, PlayerWeaponsPickedUp, or RoundConcluded to name a few). A full list of exposed Game Events can be found in the Implemented Game Events section.
About Game State Integration
Game State Integration is Valve's implementation for exposing current game state (such as player health, mana, ammo, etc.) and game events without the need to read game memory or risking anti-cheat detection. The information exposed by GSI is limited to what Valve has determined to expose. For example, the game can expose information about all players in the game while spectating a match, but will only expose local player's information when playing a game. While the information is limited, there is enough information to create a live game analysis tool, create custom RGB lighting effects, or create a live streaming plugin to show additional game information. For example, GSI can be seen used during competitive tournament live streams to show currently spectated player's information and in-game statistics.
You can read about Game State Integration for Counter-Strike: Global Offensive here.
Installation
Install from nuget.
Building Counter-Strike 2 GSI
- Make sure you have Visual Studio installed with
.NET desktop developmentworkload and.Net 8.0 Runtimeindividual component. - Make sure you have CMake 3.26 or later installed from https://cmake.org/.
- In the repository root directory run:
cmake -B build/ .to generate the project solution file. - Open the project solution located in
build/CounterStrike2GSI.sln.
How to use
- After installing the CounterStrike2GSI nuget package in your project, create an instance of
GameStateListener, providing a custom port or custom URI.
GameStateListener gsl = new GameStateListener(3000); //http://localhost:3000/
or
GameStateListener gsl = new GameStateListener("http://127.0.0.1:1234/");
Please note: If your application needs to listen to a URI other than
http://localhost:*/(for examplehttp://192.168.0.2:100/), you will need to run your application with administrator privileges.
- Create a Game State Integration configuration file. This can either be done manually by creating a file
<PATH TO GAME DIRECTORY>/game/csgo/cfg/gamestate_integration_<CUSTOM NAME>.cfgwhere<CUSTOM NAME>should be the name of your application (it can be anything). Or you can use the built-in functionGenerateGSIConfigFile()to automatically locate the game directory and generate the file. The function will automatically take into consideration the URI specified when aGameStateListenerinstance was created in the previous step.
if (!gsl.GenerateGSIConfigFile("Example"))
{
Console.WriteLine("Could not generate GSI configuration file.");
}
The function GenerateGSIConfigFile takes a string name as the parameter. This is the <CUSTOM NAME> mentioned earlier. The function will also return True when file generation was successful, and False otherwise. The resulting file from the above code should look like this:
"Example Integration Configuration"
{
"uri" "http://localhost:3000/"
"timeout" "5.0"
"buffer" "0.1"
"throttle" "0.1"
"heartbeat" "10.0"
"data"
{
"provider" "1"
"tournamentdraft" "1"
"map" "1"
"map_round_wins" "1"
"round" "1"
"player_id" "1"
"player_state" "1"
"player_weapons" "1"
"player_match_stats" "1"
"player_position" "1"
"phase_countdowns" "1"
"allplayers_id" "1"
"allplayers_state" "1"
"allplayers_match_stats" "1"
"allplayers_weapons" "1"
"allplayers_position" "1"
"allgrenades" "1"
"bomb" "1"
}
}
- Create handlers and subscribe for events your application will be using. (A full list of exposed Game Events can be found in the Implemented Game Events section.)
If your application just needs
GameStateinformation, this is done by subscribing toNewGameStateevent and creating a handler for it:
...
gsl.NewGameState += OnNewGameState;
...
void OnNewGameState(GameState gs)
{
// Read information from the game state.
}
If you would like to utilize Game Events in your application, this is done by subscribing to an event from the Implemented Game Events list and creating a handler for it:
...
gsl.GameEvent += OnGameEvent; // Will fire on every GameEvent
gsl.BombStateUpdated += OnBombStateUpdated; // Will only fire on BombStateUpdated events.
gsl.PlayerWeaponsPickedUp += OnPlayerWeaponsPickedUp; // Will only fire on PlayerWeaponsPickedUp events.
gsl.RoundConcluded += OnRoundConcluded; // Will only fire on RoundConcluded events.
...
void OnGameEvent(CS2GameEvent game_event)
{
// Read information from the game event.
if (game_event is PlayerTookDamage player_took_damage)
{
Console.WriteLine($"The player {player_took_damage.Player.Name} took {player_took_damage.Previous - player_took_damage.New} damage!");
}
else if (game_event is PlayerActiveWeaponChanged active_weapon_changed)
{
Console.WriteLine($"The player {active_weapon_changed.Player.Name} changed their active weapon to {active_weapon_changed.New.Name} from {active_weapon_changed.Previous.Name}.");
}
}
void OnBombStateUpdated(BombStateUpdated game_event)
{
Console.WriteLine($"The bomb is now {game_event.New}.");
}
void OnPlayerWeaponsPickedUp(PlayerWeaponsPickedUp game_event)
{
Console.WriteLine($"The player {game_event.Player.Name} picked up the following weapons:");
foreach (var weapon in game_event.Weapons)
{
Console.WriteLine($"\t{weapon.Name}");
}
}
void OnRoundConcluded(RoundConcluded game_event)
{
Console.WriteLine($"Round {game_event.Round} concluded by {game_event.WinningTeam} for reason: {game_event.RoundConclusionReason}");
}
Both NewGameState and Game Events can be used alongside one another. The Game Events are generated based on the GameState, and are there to provide ease of use.
- Finally you want to start the
GameStateListenerto begin capturing HTTP POST requests. This is done by calling theStart()method ofGameStateListener. The method will returnTrueif started successfully, orFalsewhen failed to start. Often the failure to start is due to insufficient permissions or another application is already using the same port.
if (!gsl.Start())
{
// GameStateListener could not start.
}
// GameStateListener started and is listening for Game State requests.
Implemented Game Events
GameEventThe base game event, will fire for all other listed events.
AllGrenades Events
AllGrenadesUpdatedGrenadeUpdatedNewGrenadeExpiredGrenade
AllPlayers Events
AllPlayersUpdatedPlayerConnectedPlayerDisconnected
Auth Events
AuthUpdated
Bomb Events
BombUpdatedBombPlantingBombPlantedBombDefusedBombDefusingBombDroppedBombPickedupBombExploded
Killfeed Events
KillFeed
Map Events
MapUpdatedGamemodeChangedTeamStatisticsUpdatedTeamScoreChangedTeamRemainingTimeoutsChangedRoundChangedRoundConcludedRoundStartedLevelChangedMapPhaseChangedWarmupStartedWarmupOverIntermissionStartedIntermissionOverFreezetimeStartedFreezetimeOverPauseStartedPauseOverTimeoutStartedTimeoutOverMatchStartedGameover
PhaseCountdown Events
PhaseCountdownsUpdated
Player Events
PlayerUpdatedPlayerTeamChangedPlayerActivityChangedPlayerStateChangedPlayerHealthChangedPlayerDiedPlayerRespawnedPlayerTookDamagePlayerArmorChangedPlayerHelmetChangedPlayerFlashAmountChangedPlayerSmokedAmountChangedPlayerBurningAmountChangedPlayerMoneyAmountChangedPlayerRoundKillsChangedPlayerRoundHeadshotKillsChangedPlayerRoundTotalDamageChangedPlayerEquipmentValueChangedPlayerDefusekitChangedPlayerWeaponChangedPlayerActiveWeaponChangedPlayerWeaponsPickedUpPlayerStatsChangedPlayerKillsChangedPlayerGotKillPlayerAssistsChangedPlayerDeathsChangedPlayerMVPsChangedPlayerScoreChanged
Provider Events
ProviderUpdated
Round Events
RoundUpdatedRoundPhaseUpdatedBombStateUpdatedTeamRoundVictoryTeamRoundLoss
Game State Structure
GameState
+-- Auth
| +-- ...
+-- Provider
| +-- Name
| +-- AppID
| +-- Version
| +-- SteamID
+-- Map
| +-- Mode
| +-- Name
| +-- Phase
| +-- Round
| +-- CTStatistics
| | +-- Score
| | +-- Name
| | +-- Flag
| | +-- ConsecutiveRoundLosses
| | +-- RemainingTimeouts
| | +-- MatchesWonThisSeries
| +-- TStatistics
| | +-- ...
| +-- NumberOfMatchesToWinSeries
| +-- RoundWins
+-- Round
| +-- Phase
| +-- BombState
| +-- WinningTeam
+-- Player
| +-- SteamID
| +-- Name
| +-- Clan
| +-- ObserverSlot
| +-- Team
| +-- Activity
| +-- State
| | +-- Health
| | +-- Armor
| | +-- HasHelmet
| | +-- FlashAmount
| | +-- SmokedAmount
| | +-- BurningAmount
| | +-- Money
| | +-- RoundKills
| | +-- RoundHSKills
| | +-- RoundTotalDamage
| | +-- EquipmentValue
| | +-- HasDefuseKit
| +-- Weapons[]
| | +-- Name
| | +-- PaintKit
| | +-- Type
| | +-- AmmoClip
| | +-- AmmoClipMax
| | +-- AmmoReserve
| | +-- State
| +-- MatchStats
| | +-- Kills
| | +-- Assists
| | +-- Deaths
| | +-- MVPs
| | +-- Score
| +-- SpectationTarget
| +-- Position
| +-- ForwardDirection
| +-- GetActiveWeapon()
+-- PhaseCountdowns
| +-- Phase
| +-- PhaseEndTime
+-- AllPlayers
| \
| (Map of player ID to Player structure)
| ...
+-- AllGrenades
| \
| (Map of grenade ID to Grenade structure)
| +-- Owner
| +-- Position
| +-- Velocity
| +-- Lifetime
| +-- Type
| +-- Flames
| +-- EffectTime
+-- Bomb
| +-- State
| +-- Position
| +-- Player
| +-- Countdown
+-- TournamentDraft
| +-- State
| +-- EventID
| +-- StageID
| +-- FirstTeamID
| +-- SecondTeamID
| +-- Event
| +-- Stage
| +-- FirstTeamName
| +-- SecondTeamName
+-- Previously (Previous information from Game State)
Null value handling
In the event that the game state is missing information, a default value will be returned:
| Type | Default value |
|---|---|
bool |
False |
int |
-1 |
long |
-1 |
float |
-1 |
string |
String.Empty |
enum |
Undefined |
Weapon names
A full list of weapon names can be found here.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.3)
- System.Data.DataSetExtensions (>= 4.5.0)
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.0.4.2659 | 137 | 3/21/2026 |
| 1.0.3.8403 | 1,431 | 2/7/2024 |
| 1.0.2.759 | 195 | 1/20/2024 |
| 1.0.1.5245 | 179 | 1/17/2024 |
| 1.0.0.7118 | 200 | 1/17/2024 |