All Projects → rakijah → CSGSI

rakijah / CSGSI

Licence: other
A simple C# library to interface with Counter-Strike: Global Offensive's Game State Integration

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to CSGSI

CSGO-Offset-Scanner
Java Based Cross-Platform CSGO Offset and Netvar Scanner
Stars: ✭ 28 (-77.42%)
Mutual labels:  counter, global, offensive, strike
csgo richpresence
Discord Rich Presence support for Counter-Strike: Global Offensive!
Stars: ✭ 16 (-87.1%)
Mutual labels:  counter, global, offensive, strike
react-globally
Gives you setGlobalState, so you can set state globally
Stars: ✭ 22 (-82.26%)
Mutual labels:  state, global
Java-Memory-Manipulation
User friendly, Garbage-free, and cross-platform process, module and memory interfacing via the power of Java
Stars: ✭ 51 (-58.87%)
Mutual labels:  global, offensive
csgo-gsi
A Java library for Counter-Strike: Global Offensive's game state integration
Stars: ✭ 23 (-81.45%)
Mutual labels:  integration, state
API
API for SQLMatches.
Stars: ✭ 48 (-61.29%)
Mutual labels:  counter, strike
React Native Slot Machine
Text slot machine for react-native
Stars: ✭ 109 (-12.1%)
Mutual labels:  counter
React Native Countdown Component
React Native CountDown
Stars: ✭ 193 (+55.65%)
Mutual labels:  counter
Dipstick
Configurable metrics toolkit for Rust applications
Stars: ✭ 92 (-25.81%)
Mutual labels:  counter
Xena
Lightweight, lighting-fast Java Based Cross-Platform CSGO Cheat
Stars: ✭ 69 (-44.35%)
Mutual labels:  counter
covid-19-usa-by-state
CSV files of COVID-19 total daily confirmed cases and deaths in the USA by state and county. All data from Johns Hopkins & NYT..
Stars: ✭ 35 (-71.77%)
Mutual labels:  state
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (-39.52%)
Mutual labels:  state
Mongoose Sequence
Sequence and autoincrement handling for mongoose
Stars: ✭ 178 (+43.55%)
Mutual labels:  counter
Phoenix Liveview Counter Tutorial
🤯 beginners tutorial building a real time counter in Phoenix 1.5.5 + LiveView 0.14.7 ⚡️
Stars: ✭ 115 (-7.26%)
Mutual labels:  counter
You Dont Need Javascript
CSS is powerful, you can do a lot of things without JS.
Stars: ✭ 16,514 (+13217.74%)
Mutual labels:  counter
Hit Counter
Easily count hits 📈 on a website by requesting a SVG displaying hit count 🎯
Stars: ✭ 103 (-16.94%)
Mutual labels:  counter
validstate
Seamless and easy Redux state Validation
Stars: ✭ 16 (-87.1%)
Mutual labels:  state
Social Links
Simple library to count shares and generate share buttons
Stars: ✭ 91 (-26.61%)
Mutual labels:  counter
Redux Data Structures
Reducer factory functions for common data structures: counters, maps, lists (queues, stacks), sets, etc.
Stars: ✭ 157 (+26.61%)
Mutual labels:  counter
trello-habitica
Keep in sync your Trello cards with Habitica
Stars: ✭ 32 (-74.19%)
Mutual labels:  integration

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

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:

  1. Get the latest binaries
  2. Get the JSON Framework .dll by Newtonsoft
  3. Extract Newtonsoft.Json.dll from Bin\Net45\Newtonsoft.Json.dll
  4. 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

  1. 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:*/.

  1. Create a handler:
void OnNewGameState(GameState gs)
{
    //do stuff
}
  1. Subscribe to the NewGameState event:
gsl.NewGameState += OnNewGameState;
  1. Use GameStateListener.Start() to start listening for HTTP POST requests from the game client. This method will return false 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:

  • 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
float -1
string String.Empty
Vector3 (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 void OnNewGameState(GameState gs)
        {
            if(gs.Round.Phase == RoundPhase.Live &&
               gs.Bomb.State == BombState.Planted &&
               gs.Previously.Bomb.State == BombState.Planting)
            {
                Console.WriteLine("Bomb has been planted.");
                IsPlanted = true;
            }
        }
    }
}

Note that you can now also use events provided by the GameStateListener to achieve this:

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.BombPlanted += BombPlanted;
            gsl.EnableRaisingIntricateEvents = true;
            if (!gsl.Start())
            {
                Environment.Exit(0);
            }
            Console.WriteLine("Listening...");
        }

        private static void BombPlanted(CSGSI.Events.BombPlantedEventArgs e)
        {
            Console.WriteLine("Bomb has been planted.");
        }
    }
}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].