Dota2GSI 2.0.1.687
See the version list below for details.
dotnet add package Dota2GSI --version 2.0.1.687
NuGet\Install-Package Dota2GSI -Version 2.0.1.687
<PackageReference Include="Dota2GSI" Version="2.0.1.687" />
paket add Dota2GSI --version 2.0.1.687
#r "nuget: Dota2GSI, 2.0.1.687"
// Install Dota2GSI as a Cake Addin
#addin nuget:?package=Dota2GSI&version=2.0.1.687
// Install Dota2GSI as a Cake Tool
#tool nuget:?package=Dota2GSI&version=2.0.1.687
Dota 2 GSI (Game State Integration)
A C# library to interface with the Game State Integration found in Dota 2.
What is Game State Integration
You can read about Game State Integration for Counter-Strike: Global Offensive here.
About Dota 2 GSI
This library provides easy means of implementing Game State Integration from Dota 2 into C# applications. Library listens for HTTP POST requests made by the game on a specific address and port. Upon receiving a request, the game state is parsed and can be used.
JSON parsing is done though help of Newtonsoft's JSON.Net Framework.
After starting the GameStateListener
instance, it will continuously listen for incoming HTTP requests. Upon a received request, the contents will be parsed into a GameState
object.
Installation
Install from nuget.
Manual installation:
- Get the latest binaries
- Get the JSON Framework .dll by Newtonsoft
- Extract Newtonsoft.Json.dll from
Bin\Net80\Newtonsoft.Json.dll
- Add a reference to both Dota2GSI.dll and Newtonsoft.Json.dll in your project
Build Dota 2 GSI
- Make sure you have Visual Studio installed with
.NET desktop development
workload and.Net 8.0 Runtime
individual 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/Dota2GSI.sln
.
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).
Layout
GameState
+-- Auth
| +-- Token
+-- Provider
| +-- Name
| +-- AppID
| +-- Version
| +-- TimeStamp
+-- Map
| +-- Name
| +-- MatchID
| +-- GameTime
| +-- ClockTime
| +-- IsDaytime
| +-- IsNightstalkerNight
| +-- RadiantScore
| +-- DireScore
| +-- GameState
| +-- IsPaused
| +-- Winningteam
| +-- CustomGameName
| +-- RadiantWardPurchaseCooldown
| +-- DireWardPurchaseCooldown
| +-- RoshanState
| +-- RoshanStateEndTime
| +-- WardPurchaseCooldown
+-- Player
| +-- LocalPlayer
| | +-- SteamID
| | +-- AccountID
| | +-- Name
| | +-- Activity
| | +-- Kills
| | +-- Deaths
| | +-- Assists
| | +-- LastHits
| | +-- Denies
| | +-- KillStreak
| | +-- CommandsIssued
| | +-- KillList
| | +-- Team
| | +-- PlayerSlot
| | +-- PlayerTeamSlot
| | +-- Gold
| | +-- GoldReliable
| | +-- GoldUnreliable
| | +-- GoldFromHeroKills
| | +-- GoldFromCreepKills
| | +-- GoldFromIncome
| | +-- GoldFromShared
| | +-- GoldPerMinute
| | +-- ExperiencePerMinute
| | +-- OnstageSeat
| | +-- NetWorth
| | +-- HeroDamage
| | +-- HeroHealing
| | +-- TowerDamage
| | +-- WardsPurchased
| | +-- WardsPlaced
| | +-- WardsDestroyed
| | +-- RunesActivated
| | +-- CampsStacked
| | +-- SupportGoldSpent
| | +-- ConsumableGoldSpent
| | +-- ItemGoldSpent
| | +-- GoldLostToDeath
| | +-- GoldSpentOnBuybacks
| +-- Teams
| | ...
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Hero
| +-- LocalPlayer
| | +-- Location
| | +-- ID
| | +-- Name
| | +-- Level
| | +-- Experience
| | +-- IsAlive
| | +-- SecondsToRespawn
| | +-- BuybackCost
| | +-- BuybackCooldown
| | +-- Health
| | +-- MaxHealth
| | +-- HealthPercent
| | +-- Mana
| | +-- MaxMana
| | +-- ManaPercent
| | +-- IsSilenced
| | +-- IsStunned
| | +-- IsDisarmed
| | +-- IsMagicImmune
| | +-- IsHexed
| | +-- IsMuted
| | +-- IsBreak
| | +-- HasAghanimsScepterUpgrade
| | +-- HasAghanimsShardUpgrade
| | +-- IsSmoked
| | +-- HasDebuff
| | +-- SelectedUnit
| | +-- TalentTree[]
| | +-- AttributesLevel
| +-- Teams
| | ...
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Abilities
| +-- LocalPlayer
| | +-- Count
| | +-- Ability[]
| | | \
| | | +-- Name
| | | +-- Level
| | | +-- CanCast
| | | +-- IsPassive
| | | +-- IsActive
| | | +-- Cooldown
| | | +-- IsUltimate
| | | +-- Charges
| | | +-- MaxCharges
| | | +-- ChargeCooldown
| +-- Teams
| | ...
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Items
| +-- LocalPlayer
| | +-- Inventory
| | +-- Stash
| | +-- CountInventory
| | +-- CountStash
| | +-- Teleport
| | +-- Neutral
| | +-- GetInventoryAt( index )
| | +-- GetInventoryItem( item_name )
| | +-- InventoryContains( item_name )
| | +-- InventoryIndexOf( item_name )
| | +-- GetStashAt( index )
| | +-- GetStashItem( item_name )
| | +-- StashContains( item_name )
| | +-- StashIndexOf( item_name )
| +-- Teams
| | ...
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Events[]
| | \
| | +-- GameTime
| | +-- EventType
| | +-- Team
| | +-- KillerPlayerID
| | +-- PlayerID
| | +-- WasSnatched
| | +-- TipReceiverPlayerID
| | +-- TipAmount
| | +-- BountyValue
| | +-- TeamGold
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Buildings
| +-- RadiantBuildings
| | +-- TopTowers
| | +-- MiddleTowers
| | +-- BottomTowers
| | +-- TopRacks
| | +-- MiddleRacks
| | +-- BottomRacks
| | +-- Ancient
| | +-- OtherBuildings
| +-- DireBuildings
| | ...
| +-- AllBuildings
| | ...
| +-- GetForTeam( team )
+-- League
| +-- SeriesType
| +-- SelectionPriority
| +-- LeagueID
| +-- MatchID
| +-- Name
| +-- Tier
| +-- Region
| +-- Url
| +-- Description
| +-- Notes
| +-- StartTimestamp
| +-- EndTimestamp
| +-- ProCircuitPoints
| +-- ImageBits
| +-- Status
| +-- MostRecentActivity
| +-- RegistrationPeriod
| +-- BasePrizePool
| +-- TotalPrizePool
| +-- LeagueNoteID
| +-- RadiantTeam
| | +-- TeamID
| | +-- TeamTag
| | +-- TeamName
| | +-- SeriesWins
| +-- DireTeam
| | ...
| +-- SeriesID
| +-- StartTime
| +-- FirstTeamID
| +-- SecondTeamID
| +-- Stream[]
| | \
| | +-- StreamID
| | +-- Language
| | +-- Name
| | +-- BroadcastProvider
| | +-- StreamURL
| | +-- VodURL
+-- Draft
| +-- ActiveTeam
| +-- Pick
| +-- ActiveTeamRemainingTime
| +-- RadiantBonusTime
| +-- DireBonusTime
| +-- Teams
| | +-- IsHomeTeam
| | +-- PickIDs
| | +-- PickHeroIDs
| +-- GetForTeam( team )
+-- Wearables
| +-- LocalPlayer
| | +-- Wearables
| | | +-- ID
| | | +-- Style
| +-- Teams
| | ...
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Minimap
| +-- Elements
| | +-- Location
| | +-- RemainingTime
| | +-- EventDuration
| | +-- Image
| | +-- Team
| | +-- Name
| | +-- Rotation
| | +-- UnitName
| | +-- VisionRange
| +-- GetForTeam( team )
| +-- GetForPlayer( player_id )
+-- Roshan
| +-- Location
| +-- Health
| +-- MaxHealth
| +-- IsAlive
| +-- SpawnPhase
| +-- PhaseTimeRemaining
| +-- Rotation
| +-- Drops
| | +-- Items
+-- Couriers
| +-- CouriersMap
| | +-- Health
| | +-- MaxHealth
| | +-- IsAlive
| | +-- RemainingRespawnTime
| | +-- Location
| | +-- Rotation
| | +-- OwnerID
| | +-- HasFlyingUpgrade
| | +-- IsShielded
| | +-- IsBoosted
| | +-- Items
| | | +-- OwnerID
| | | +-- Name
| +-- GetForPlayer( player_id )
+-- NeutralItems
| +-- TierInfos
| | +-- Tier
| | +-- MaxCount
| | +-- DropAfterTime
| +-- TeamItems
| | +-- ItemsFound
| | +-- TeamItems
| | | +-- Name
| | | +-- Tier
| | | +-- Charges
| | | +-- State
| | | +-- PlayerID
| +-- GetForTeam( team )
+-- Previously (Previous information from Game State)
+-- LocalPlayer
| +-- Details
| +-- Hero
| +-- Abilities
| +-- Items
| +-- Wearables
| +-- Courier
| +-- MinimapElements
+-- RadiantTeamDetails
| +-- Team
| +-- Players
| +-- Draft
| +-- NeutralItems
| +-- Buildings
| +-- MinimapElements
| +-- Events
| +-- IsWinner
+-- DireTeamDetails
| ...
+-- NeutralTeamDetails
| ...
+-- IsSpectating
+-- IsLocalPlayer
Item, and Hero names
Item and hero names are presented in their "internal name" format. A full list of item names can be found here and a full list of heroes can be located here.
Examples:
int Health = gs.Hero.LocalPlayer.Health; // 560
int MaxHealth = gs.Hero.LocalPlayer.MaxHealth; // 560
string HeroName = gs.Hero.LocalPlayer.Name; //npc_dota_hero_omniknight
int Level = gs.Hero.LocalPlayer.Level; //1
Console.WriteLine("You are playing as " + HeroName + " with " + Health + "/" + MaxHealth + " health and level " + Level);
//You are playing as npc_dota_hero_omniknight with 560/560 health and level 1
Null value handling
In case the JSON did not contain the requested information, these values will be returned:
Type | Default value |
---|---|
bool | false |
int | -1 |
long | -1 |
float | -1 |
string | String.Empty |
All Enums have a value enum.Undefined
that serves the same purpose.
Example program
A user, judge2020, has created an example program to demonstrate Dota2GSI functionalities. It can be found in the "Dota2GSI Example program" folder.
Example implementation
Prints "You bought an item" when you buy an item, and "It is night time" when it is night time.
using Dota2GSI;
using System;
namespace DOTA2GSI_sample
{
static class Program
{
GameStateListener gsl;
static void Main(string[] args)
{
gsl = new GameStateListener(4000);
gsl.NewGameState += new NewGameStateHandler(OnNewGameState);
if (!gsl.Start())
{
System.Windows.MessageBox.Show("GameStateListener could not start. Try running this program as Administrator.\r\nExiting.");
Environment.Exit(0);
}
Console.WriteLine("Listening for game integration calls...");
}
static void OnNewGameState(GameState gs)
{
if(gs.Map.GameState == DOTA_GameState.DOTA_GAMERULES_STATE_GAME_IN_PROGRESS)
{
if(gs.Previously.Items.LocalPlayer.CountInventory > gs.Items.LocalPlayer.CountInventory)
{
Console.WriteLine("You bought an item");
}
if(!gs.Map.IsDaytime || gs.Map.IsNightstalkerNight)
{
Console.WriteLine("It is night time");
}
}
}
}
}
You will also need to create a custom gamestate_integration_*.cfg
in game/dota/cfg/gamestate_integration/
, for example:
gamestate_integration_test.cfg
:
"Dota 2 Integration Configuration"
{
"uri" "http://localhost:4000/"
"timeout" "5.0"
"buffer" "0.1"
"throttle" "0.1"
"heartbeat" "30.0"
"data"
{
"auth" "1"
"provider" "1"
"map" "1"
"player" "1"
"hero" "1"
"abilities" "1"
"items" "1"
"events" "1"
"buildings" "1"
"league" "1"
"draft" "1"
"wearables" "1"
"minimap" "1"
"roshan" "1"
"couriers" "1"
"neutralitems" "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.
Credits
Special thanks to rakijah for his CSGO Game State Integration library.
Thanks to judge2020 for providing an example program.
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. |
-
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 |
---|---|---|
2.1.1.8897 | 145 | 2/7/2024 |
2.1.0.8306 | 102 | 1/19/2024 |
2.0.1.687 | 102 | 1/13/2024 |
2.0.0 | 86 | 1/12/2024 |
1.0.4 | 1,984 | 9/18/2016 |
1.0.3 | 1,266 | 2/13/2016 |
1.0.2 | 1,047 | 2/11/2016 |
1.0.1 | 1,080 | 2/2/2016 |
1.0.0 | 1,104 | 2/2/2016 |